ItemController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use biz\product\models\Product;
  5. use bizGhs\book\classes\BookItemClass;
  6. use bizGhs\custom\classes\CustomClass;
  7. use bizGhs\item\classes\ItemClass;
  8. use bizGhs\shop\classes\ShopAdminClass;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\miniUtil;
  12. use common\components\noticeUtil;
  13. use common\components\stringUtil;
  14. use common\components\util;
  15. use bizGhs\product\classes\ProductClass;
  16. use bizHd\wx\classes\WxOpenClass;
  17. use Yii;
  18. class ItemController extends BaseController
  19. {
  20. //修改一个花材的采购人 ssh 20240719
  21. public function actionModifyCgStaff()
  22. {
  23. $get = Yii::$app->request->get();
  24. $id = $get['id'] ?? 0;
  25. $staffId = $get['staffId'] ?? 0;
  26. $item = ItemClass::getById($id, true);
  27. if (empty($item)) {
  28. util::fail('没有找到花材');
  29. }
  30. if ($item->mainId != $this->mainId) {
  31. util::fail('不是你的花材');
  32. }
  33. $staff = ShopAdminClass::getById($staffId, true);
  34. if (empty($staff) || $staff->mainId != $this->mainId) {
  35. util::fail('不是你的员工');
  36. }
  37. $staffName = $staff->name ?? '';
  38. $item->cgStaffId = $staffId;
  39. $item->cgStaffName = $staffName;
  40. $item->save();
  41. $shop = $this->shop;
  42. $bookSn = $shop->bookSn ?? 0;
  43. if (!empty($bookSn)) {
  44. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'itemId' => $id], ['cgStaffId' => $staffId, 'cgStaffName' => $staffName]);
  45. }
  46. util::complete('修改成功');
  47. }
  48. //获取花材最新信息,库存 ssh 20240318
  49. public function actionGetNewInfo()
  50. {
  51. $post = Yii::$app->request->post();
  52. $str = $post['data'] ?? '';
  53. if (empty($str)) {
  54. util::fail('请传花材信息');
  55. }
  56. $arr = json_decode($str, true);
  57. if (empty($arr)) {
  58. util::fail('请传花材信息哈');
  59. }
  60. $ids = array_column($arr, 'productId');
  61. $list = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,stock,mainId', 'id', true);
  62. if (!empty($list)) {
  63. foreach ($list as $item) {
  64. if ($item->mainId != $this->mainId) {
  65. util::fail('不是你的花材');
  66. }
  67. }
  68. }
  69. util::success(['list' => $list]);
  70. }
  71. //列出所有花材 ssh 20240222
  72. public function actionGetItemList()
  73. {
  74. $get = Yii::$app->request->get();
  75. $search = $get['search'] ?? '';
  76. $requestType = $get['requestType'] ?? 'kd';
  77. $classId = $get['classId'] ?? 0;
  78. $where['mainId'] = $this->mainId;
  79. if ($requestType == 'kd') {
  80. $where['delStatus'] = 0;
  81. $where['status'] = 1;
  82. } elseif ($requestType == 'itemList') {
  83. $where['delStatus'] = 0;
  84. unset($where['status']);
  85. } elseif ($requestType == 'changePrice') {
  86. $where['delStatus'] = 0;
  87. $where['stock>'] = 0;
  88. } elseif ($requestType == 'hasStockList') {
  89. $where['delStatus'] = 0;
  90. $where['stock>'] = 0;
  91. } elseif ($requestType == 'book') {
  92. $where['delStatus'] = 0;
  93. unset($where['status']);
  94. } elseif ($requestType == 'outList') {
  95. $where['delStatus'] = 0;
  96. $where['status'] = 2;
  97. $where['removeStatus'] = 0;
  98. } elseif ($requestType == 'stopList') {
  99. $where['delStatus'] = 1;
  100. unset($where['status']);
  101. $where['removeStatus'] = 0;
  102. } elseif ($requestType == 'removeList') {
  103. $where['delStatus'] = 1;
  104. unset($where['status']);
  105. $where['removeStatus'] = 1;
  106. } elseif ($requestType == 'cg') {
  107. $where['delStatus'] = 0;
  108. unset($where['status']);
  109. } elseif ($requestType == 'changeStock') {
  110. $where['delStatus'] = 0;
  111. unset($where['status']);
  112. } elseif ($requestType == 'check') {
  113. $where['delStatus'] = 0;
  114. unset($where['status']);
  115. } elseif ($requestType == 'stockOut') {
  116. $where['delStatus'] = 0;
  117. $where['status'] = 1;
  118. } elseif ($requestType == 'break') {
  119. $where['delStatus'] = 0;
  120. $where['status'] = 1;
  121. } else {
  122. util::fail('没有定义的请求方式');
  123. }
  124. if (!empty($search)) {
  125. if (stringUtil::isLetter($search)) {
  126. $search = strtolower($search);
  127. $where['py'] = ['like', $search];
  128. } else {
  129. $where['name'] = ['like', $search];
  130. }
  131. } else {
  132. if (!empty($classId)) {
  133. if ($classId == -1) {
  134. $where['discountPrice>'] = 0;
  135. } elseif ($classId == -2) {
  136. $where['reachNum>'] = 0;
  137. } elseif ($classId == -3) {
  138. $where['presell'] = 1;
  139. } else {
  140. $where['classId'] = $classId;
  141. }
  142. }
  143. }
  144. $customId = $get['customId'] ?? 0;
  145. $custom = CustomClass::getById($customId, true);
  146. if (!empty($custom)) {
  147. if ($custom->ownMainId != $this->mainId) {
  148. util::fail('不是你的客户');
  149. }
  150. }
  151. $level = $custom->level ?? 1;
  152. $field = '*';
  153. //只查我负责的花材
  154. $globalCgMyCharge = $get['globalCgMyCharge'] ?? 0;
  155. $needCgList = [];
  156. $shop = $this->shop;
  157. $bookSn = $shop->bookSn ?? 0;
  158. $staff = $this->shopAdmin;
  159. $staffId = $staff->id ?? 0;
  160. if (!empty($bookSn)) {
  161. $biList = BookItemClass::getAllByCondition(['bookSn' => $bookSn, 'cgStaffId' => $staffId], null, '*', null, true);
  162. if (!empty($biList)) {
  163. $myIds = [];
  164. foreach ($biList as $biInfo) {
  165. $biProductId = $biInfo->itemId ?? 0;
  166. if ($biInfo->needCgNum > 0) {
  167. $myIds[] = $biProductId;
  168. $needCgList[$biProductId] = $biInfo->needCgNum;
  169. }
  170. }
  171. if ($globalCgMyCharge == 1 && !empty($myIds)) {
  172. $where['id'] = ['in', $myIds];
  173. }
  174. }
  175. }
  176. $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  177. $list = $result['list'] ?? [];
  178. if ($requestType == 'hasStockList') {
  179. util::fail('无效方式');
  180. } elseif ($requestType == 'changePrice') {
  181. $list = ProductClass::changePriceGroup($list, $level);
  182. } elseif ($requestType == 'changeStock') {
  183. $list = ProductClass::changeStockGroup($list, $level);
  184. } elseif ($requestType == 'kd') {
  185. $list = ProductClass::kdItemGroup($list, $level);
  186. } elseif ($requestType == 'book') {
  187. $list = ProductClass::bookItemGroup($list, $level);
  188. } elseif ($requestType == 'itemList') {
  189. $list = ProductClass::itemListGroup($list, $level);
  190. } elseif ($requestType == 'outList') {
  191. $list = ProductClass::simpleGroup($list, $level);
  192. } elseif ($requestType == 'stopList') {
  193. $list = ProductClass::simpleGroup($list, $level);
  194. } elseif ($requestType == 'removeList') {
  195. $list = ProductClass::simpleGroup($list, $level);
  196. } elseif ($requestType == 'check') {
  197. $list = ProductClass::checkItemGroup($list, $level);
  198. } elseif ($requestType == 'break') {
  199. $list = ProductClass::breakItemGroup($list, $level);
  200. } elseif ($requestType == 'part') {
  201. $list = ProductClass::partItemGroup($list, $level);
  202. } elseif ($requestType == 'stockOut') {
  203. $list = ProductClass::stockOutGroup($list, $level);
  204. } elseif ($requestType == 'cg') {
  205. $list = ProductClass::cgItemGroup($list, $level);
  206. } elseif ($requestType == 'warning') {
  207. util::fail('无效方式');
  208. // $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  209. // ->andWhere('`stock`+`onStock`<`stockWarning`')
  210. // ->andWhere("delStatus=0")
  211. // ->select($field)->asArray()->all();
  212. // $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  213. } else {
  214. util::fail('没有数据');
  215. }
  216. if (!empty($needCgList)) {
  217. //采购人采自己花材需要知道要采多少
  218. if (!empty($list)) {
  219. foreach ($list as $key => $val) {
  220. $productId = $val['id'] ?? 0;
  221. if (isset($needCgList[$productId])) {
  222. $needCgNum = $needCgList[$productId];
  223. $list[$key]['needCgNum'] = $needCgNum;
  224. }
  225. }
  226. }
  227. }
  228. $result['list'] = $list;
  229. util::success($result);
  230. }
  231. //花材申请平台认证 ssh 20231125
  232. public function actionApplyAuth()
  233. {
  234. $get = Yii::$app->request->get();
  235. $id = $get['id'] ?? 0;
  236. $info = ItemClass::getById($id, true);
  237. if (empty($info)) {
  238. util::fail('没有找到花材');
  239. }
  240. if ($info->mainId != $this->mainId) {
  241. util::fail('不是你的花材哦');
  242. }
  243. $shop = $this->shop;
  244. $sjName = $shop->merchantName ?? '';
  245. $shopName = $shop->shopName ?? '';
  246. $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  247. $ptItemId = $info->itemId ?? 0;
  248. $ptItem = PtItemClass::getById($ptItemId, true);
  249. if (empty($ptItem)) {
  250. util::fail('没有找到平台花材');
  251. }
  252. $ptItemName = $ptItem->name ?? '';
  253. noticeUtil::push($name . " 申请将【{$ptItemName}/{$ptItemId}】进行认证", '15280215347');
  254. util::complete();
  255. }
  256. //简单花材的列表
  257. public function actionSimpleList()
  258. {
  259. $get = Yii::$app->request->get();
  260. $name = $get['name'] ?? '';
  261. $num = $get['num'] ?? 0;
  262. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  263. if (!empty($name)) {
  264. if (stringUtil::isLetter($name)) {
  265. $where['py'] = ['like', $name];
  266. } else {
  267. $where['name'] = ['like', $name];
  268. }
  269. }
  270. $respond = ItemClass::getSimpleList($where, $num);
  271. util::success($respond);
  272. }
  273. //可借库存的花材列表 ssh 20240720
  274. public function actionGetLoanList()
  275. {
  276. $get = Yii::$app->request->get();
  277. $name = $get['name'] ?? '';
  278. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  279. if (!empty($name)) {
  280. if (stringUtil::isLetter($name)) {
  281. $where['py'] = ['like', $name];
  282. } else {
  283. $where['name'] = ['like', $name];
  284. }
  285. }
  286. $shop = $this->shop;
  287. $respond = ItemClass::getLoanList($where, $shop);
  288. util::success($respond);
  289. }
  290. public function actionChangeFrontHide()
  291. {
  292. $get = Yii::$app->request->get();
  293. $id = $get['id'] ?? 0;
  294. $status = $get['status'] ?? '';
  295. if (is_numeric($status) == false) {
  296. util::fail('请选择方式');
  297. }
  298. $info = ItemClass::getById($id, true);
  299. if (empty($info)) {
  300. util::fail('没有找到花材');
  301. }
  302. if ($info->mainId != $this->mainId) {
  303. util::fail('无法操作');
  304. }
  305. $info->frontHide = $status;
  306. $info->save();
  307. util::complete();
  308. }
  309. //检测是否要刷新
  310. public function actionCheckRefresh()
  311. {
  312. $mainId = $this->mainId;
  313. $staffId = $this->shopAdminId;
  314. $respond = Yii::$app->redis->executeCommand('GET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  315. if ($respond == 'yes') {
  316. util::success(['remind' => 1]);
  317. }
  318. util::complete();
  319. }
  320. //批量恢复花材 ssh 20230206
  321. public function actionBatchRecover()
  322. {
  323. $post = Yii::$app->request->post();
  324. $string = $post['ids'] ?? '';
  325. $ids = json_decode($string, true);
  326. $ids = array_unique(array_filter($ids));
  327. if (empty($ids)) {
  328. util::fail('请选择花材');
  329. }
  330. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  331. if (empty($infoList)) {
  332. util::fail('请选择花材哦');
  333. }
  334. foreach ($infoList as $info) {
  335. if ($info->mainId != $this->mainId) {
  336. util::fail('请选择自己的花材');
  337. }
  338. $info->removeStatus = 0;
  339. $info->save();
  340. }
  341. util::complete('操作成功');
  342. }
  343. //批量删除花材 ssh 202302026
  344. public function actionBatchRemove()
  345. {
  346. $post = Yii::$app->request->post();
  347. $string = $post['ids'] ?? '';
  348. $ids = json_decode($string, true);
  349. $ids = array_unique(array_filter($ids));
  350. if (empty($ids)) {
  351. util::fail('请选择花材');
  352. }
  353. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  354. if (empty($infoList)) {
  355. util::fail('请选择花材哦');
  356. }
  357. foreach ($infoList as $info) {
  358. if ($info->mainId != $this->mainId) {
  359. util::fail('请选择自己的花材');
  360. }
  361. $name = $info->name ?? '';
  362. if ($info->delStatus != 1) {
  363. util::fail($name . ' 停用了才能删除');
  364. }
  365. $info->removeStatus = 1;
  366. $info->save();
  367. }
  368. util::complete('操作成功');
  369. }
  370. //批量启用花材 ssh 20230206
  371. public function actionBatchEnable()
  372. {
  373. $post = Yii::$app->request->post();
  374. $string = $post['ids'] ?? '';
  375. $ids = json_decode($string, true);
  376. $ids = array_unique(array_filter($ids));
  377. if (empty($ids)) {
  378. util::fail('请选择花材');
  379. }
  380. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  381. if (empty($infoList)) {
  382. util::fail('请选择花材哦');
  383. }
  384. foreach ($infoList as $info) {
  385. if ($info->mainId != $this->mainId) {
  386. util::fail('请选择自己的花材');
  387. }
  388. $info->delStatus = 0;
  389. $info->save();
  390. }
  391. util::complete('操作成功');
  392. }
  393. //批量停用花材 20230206
  394. public function actionBatchStop()
  395. {
  396. $post = Yii::$app->request->post();
  397. $string = $post['ids'] ?? '';
  398. $ids = json_decode($string, true);
  399. $ids = array_unique(array_filter($ids));
  400. if (empty($ids)) {
  401. util::fail('请选择花材');
  402. }
  403. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  404. if (empty($infoList)) {
  405. util::fail('请选择花材哦');
  406. }
  407. foreach ($infoList as $info) {
  408. if ($info->mainId != $this->mainId) {
  409. util::fail('请选择自己的花材');
  410. }
  411. $name = $info->name ?? '';
  412. if ($info->status != 2) {
  413. util::fail($name . ' 下载了才能停用');
  414. }
  415. $info->delStatus = 1;
  416. $info->save();
  417. }
  418. util::complete('操作成功');
  419. }
  420. //获取给散客下单的花材海报 ssh 20220111
  421. public function actionGetSkPoster()
  422. {
  423. $get = Yii::$app->request->get();
  424. $id = $get['id'] ?? 0;
  425. $item = ItemClass::getById($id, true);
  426. if (empty($item) || $item->mainId != $this->mainId) {
  427. util::fail('获取失败');
  428. }
  429. $cover = $item->cover ?? '';
  430. if (empty($cover)) {
  431. util::fail('获取失败');
  432. }
  433. $merchant = WxOpenClass::getMallWxInfo();
  434. $page = 'pages/item/detail';
  435. $ptStyle = dict::getDict('ptStyle', 'mall');
  436. $shop = $this->shop;
  437. $lsShopId = $shop->lsShopId ?? 0;
  438. //scene不能超过32个字条
  439. $scene = "id=" . $id . '&a=' . $lsShopId;
  440. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  441. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  442. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  443. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  444. $prefix = imgUtil::getPrefix();
  445. $price = $item->skPrice ?? 0;
  446. if ($item->discountPrice > 0) {
  447. $skMore = $item->skMore ?? 0;
  448. $price = bcadd($item->discountPrice, $skMore, 2);
  449. }
  450. $newPrice = '¥' . floatval($price);
  451. $priceBase64 = stringUtil::ossBase64($newPrice);
  452. $name = $item->name ?? '';
  453. $nameBase64 = stringUtil::ossBase64($name);
  454. $staff = $this->shopAdmin;
  455. $staffName = $staff->name ?? '';
  456. $newStaffName = $staffName . ' 为您推荐';
  457. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  458. //花材主图
  459. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  460. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  461. $logoBase64 = '';
  462. if (in_array($this->mainId, [52, 1459, 13495])) {
  463. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  464. if ($this->mainId == 1459) {
  465. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  466. }
  467. if ($this->mainId == 13495) {
  468. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  469. }
  470. $logoBase64 = stringUtil::ossBase64($logo);
  471. }
  472. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  473. //花材主图
  474. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  475. //小程序码
  476. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  477. if (!empty($logoBase64)) {
  478. //logo
  479. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  480. }
  481. //为你推荐
  482. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  483. //标题
  484. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  485. //价格
  486. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  487. $respond = ['imgUrl' => $url];
  488. util::success($respond);
  489. }
  490. //获取给花店下单的花材海报 ssh 20220111
  491. public function actionGetHdPoster()
  492. {
  493. $get = Yii::$app->request->get();
  494. $id = $get['id'] ?? 0;
  495. $item = ItemClass::getById($id, true);
  496. if (empty($item) || $item->mainId != $this->mainId) {
  497. util::fail('获取失败');
  498. }
  499. $cover = $item->cover ?? '';
  500. if (empty($cover)) {
  501. util::fail('获取失败');
  502. }
  503. $merchant = WxOpenClass::getWxInfo();
  504. $page = 'admin/ghsProduct/detail';
  505. $ptStyle = dict::getDict('ptStyle', 'hd');
  506. //小程序码,scene不能超过32个字条
  507. $scene = "id=" . $id . '&sId=' . $this->shopId;
  508. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  509. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  510. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  511. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  512. $prefix = imgUtil::getPrefix();
  513. $price = $item->price ?? 0;
  514. if ($item->discountPrice > 0) {
  515. $price = $item->discountPrice;
  516. }
  517. $newPrice = '¥' . floatval($price);
  518. $priceBase64 = stringUtil::ossBase64($newPrice);
  519. $name = $item->name ?? '';
  520. $nameBase64 = stringUtil::ossBase64($name);
  521. $staff = $this->shopAdmin;
  522. $staffName = $staff->name ?? '';
  523. $newStaffName = $staffName . ' 为您推荐';
  524. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  525. //花材主图
  526. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  527. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  528. $logoBase64 = '';
  529. if (in_array($this->mainId, [52, 1459, 13495])) {
  530. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  531. if ($this->mainId == 1459) {
  532. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  533. }
  534. if ($this->mainId == 13495) {
  535. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  536. }
  537. $logoBase64 = stringUtil::ossBase64($logo);
  538. }
  539. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  540. //花材主图
  541. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  542. //小程序码
  543. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  544. if (!empty($logoBase64)) {
  545. //logo
  546. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  547. }
  548. //为你推荐
  549. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  550. //标题
  551. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  552. //价格
  553. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  554. $respond = ['imgUrl' => $url];
  555. util::success($respond);
  556. }
  557. //是否有C级价格大于B级的 ssh 20221204
  558. public function actionGetErrorPrice()
  559. {
  560. $shop = $this->shop;
  561. $list = ItemClass::errorPrice($shop);
  562. util::success(['list' => $list]);
  563. }
  564. //列出所有花材,包括特价花材列表 ssh 20220315
  565. public function actionShowList()
  566. {
  567. $get = Yii::$app->request->get();
  568. $customId = $get['customId'] ?? 0;
  569. $custom = CustomClass::getById($customId, true);
  570. $where['mainId'] = $this->mainId;
  571. $where['delStatus'] = 0;
  572. $where['status'] = 1;
  573. $list = ItemClass::getShowList($where, $custom);
  574. $mainId = $this->mainId;
  575. $get = Yii::$app->request->get();
  576. $isCashier = $get['isCashier'] ?? 0;
  577. if ($isCashier == 1) {
  578. //去掉收银台提示价格更新
  579. $staffId = $this->shopAdminId;
  580. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  581. }
  582. util::success(['list' => $list]);
  583. }
  584. public function actionAdd()
  585. {
  586. util::fail('开发中');
  587. }
  588. //批量添加花材
  589. public function actionBatchAdd()
  590. {
  591. $shopAdmin = $this->shopAdmin;
  592. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  593. util::fail('超管才能操作');
  594. }
  595. $post = Yii::$app->request->post();
  596. //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
  597. $data = $post['data'];
  598. if (empty($data)) {
  599. util::fail("请选花材");
  600. }
  601. $data = json_decode($data, true);
  602. if (is_array($data) == false || empty($data)) {
  603. util::fail("请选花材");
  604. }
  605. $shop = $this->shop;
  606. $shopId = $this->shopId;
  607. $mainId = $this->mainId;
  608. $sjId = $this->sjId;
  609. $adminId = $this->adminId;
  610. $ids = array_column($data, 'itemId');
  611. $ids = array_unique(array_filter($ids));
  612. $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
  613. if (!empty($has)) {
  614. $hasName = $has->name ?? '';
  615. util::fail($hasName . " 已经添加过了");
  616. }
  617. $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  618. $connection = Yii::$app->db;
  619. $transaction = $connection->beginTransaction();
  620. try {
  621. foreach ($data as $v) {
  622. $ptItemId = $v['itemId'] ?? 0;
  623. $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
  624. $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
  625. $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
  626. $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
  627. $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
  628. $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
  629. $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
  630. $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
  631. $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
  632. $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
  633. $cover = $ptItemInfo[$ptItemId]['cover'] ?? 'default-img.png';
  634. $v['ratio'] = $ratio;
  635. $v['cover'] = $cover;
  636. $v['shelfLife'] = $shelfLife;
  637. $v['ratioType'] = $ratioType;
  638. $v['variety'] = $variety;
  639. $v['stockWarning'] = $stockWarning;
  640. $v['weight'] = $weight;
  641. $v['bigUnit'] = $bigUnit;
  642. $v['smallUnit'] = $smallUnit;
  643. $v['bigUnitId'] = $bigUnitId;
  644. $v['smallUnitId'] = $smallUnitId;
  645. $v['adminId'] = $adminId;
  646. $v['sjId'] = $sjId;
  647. $v['shopId'] = $shopId;
  648. $v['mainId'] = $mainId;
  649. $v['staffName'] = $shopAdmin->name ?? '';
  650. $name = $v['name'] ?? '';
  651. $price = is_numeric($v['price']) ? $v['price'] : 0;
  652. $skPrice = is_numeric($v['skPrice']) ? $v['skPrice'] : 0;
  653. $cost = is_numeric($v['cost']) ? $v['cost'] : 0;
  654. if ($price <= 0) {
  655. util::fail("请填写{$name}的批发价");
  656. }
  657. if ($skPrice <= 0) {
  658. util::fail("请填写{$name}的零售价");
  659. }
  660. if ($cost <= 0) {
  661. util::fail("请填写{$name}的成本价");
  662. }
  663. if ($price > $skPrice) {
  664. util::fail("{$name}的批发价比零售价还高");
  665. }
  666. if ($cost > $price) {
  667. util::fail("{$name}的成本价比批发价还高");
  668. }
  669. $skMore = bcsub($skPrice, $price, 2);
  670. $addPrice = bcsub($price, $cost, 2);
  671. $v['skMore'] = $skMore;
  672. $v['addPrice'] = $addPrice;
  673. $v['hjAddPrice'] = $addPrice;
  674. $v['hjPrice'] = $price;
  675. ProductClass::addProduct($v, $shop);
  676. }
  677. $transaction->commit();
  678. util::complete('添加成功');
  679. } catch (Exception $e) {
  680. $transaction->rollBack();
  681. util::fail();
  682. }
  683. }
  684. public function actionDelete()
  685. {
  686. util::fail('不能删除哦!');
  687. }
  688. //获取平台里的花材信息
  689. public function actionPlatformItem()
  690. {
  691. $py = Yii::$app->request->get('py', '');
  692. $where = [];
  693. if ($py) {
  694. $where = ['py' => $py];
  695. }
  696. $list = PtItemClass::getItemList($where);
  697. util::success($list);
  698. }
  699. //列出需要进行颜色管理的花材 ssh 20220820
  700. public function actionColorList()
  701. {
  702. $mainId = $this->mainId ?? 0;
  703. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  704. util::success(['list' => $list]);
  705. }
  706. //多颜色管理启用与停用 ssh 20221229
  707. public function actionChangeVariety()
  708. {
  709. $get = Yii::$app->request->get();
  710. $id = $get['id'] ?? 0;
  711. $variety = $get['variety'] ?? 0;
  712. $info = ItemClass::getById($id, true);
  713. if (empty($info) || $info->mainId != $this->mainId) {
  714. util::fail('操作失败');
  715. }
  716. $info->variety = $variety;
  717. $info->save();
  718. util::complete('操作成功');
  719. }
  720. //拆散花材 ssh 20221229
  721. public function actionBreakItem()
  722. {
  723. util::fail('开发中');
  724. util::complete();
  725. }
  726. //批量修改花材的负责人 ssh 20240718
  727. public function actionChangeCgStaff()
  728. {
  729. $get = Yii::$app->request->get();
  730. $beforeId = $get['beforeId'] ?? 0;
  731. $newId = $get['newId'] ?? 0;
  732. if (empty($beforeId) || empty($newId)) {
  733. util::fail('员工信息有问题');
  734. }
  735. $new = ShopAdminClass::getById($newId, true);
  736. if (empty($new) || $new->mainId != $this->mainId) {
  737. util::fail('错误的员工信息');
  738. }
  739. $before = ShopAdminClass::getById($beforeId, true);
  740. if (empty($before) || $before->mainId != $this->mainId) {
  741. util::fail('错误的员工信息2');
  742. }
  743. $newName = $new->name ?? '';
  744. ItemClass::updateByCondition(['mainId' => $this->mainId, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
  745. $shop = $this->shop;
  746. $bookSn = $shop->bookSn ?? 0;
  747. if (!empty($bookSn)) {
  748. BookItemClass::updateByCondition(['bookSn' => $bookSn, 'cgStaffId' => $beforeId], ['cgStaffId' => $newId, 'cgStaffName' => $newName]);
  749. }
  750. util::complete('修改成功');
  751. }
  752. }