ItemController.php 30 KB

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