ItemController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use bizGhs\custom\classes\CustomClass;
  5. use bizGhs\item\classes\ItemClass;
  6. use common\components\dict;
  7. use common\components\imgUtil;
  8. use common\components\miniUtil;
  9. use common\components\stringUtil;
  10. use common\components\util;
  11. use bizGhs\product\classes\ProductClass;
  12. use bizHd\wx\classes\WxOpenClass;
  13. use Yii;
  14. class ItemController extends BaseController
  15. {
  16. //简单花材的列表
  17. public function actionSimpleList()
  18. {
  19. $get = Yii::$app->request->get();
  20. $name = $get['name'] ?? '';
  21. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  22. if (!empty($name)) {
  23. if (stringUtil::isLetter($name)) {
  24. $where['py'] = ['like', $name];
  25. } else {
  26. $where['name'] = ['like', $name];
  27. }
  28. }
  29. $respond = ItemClass::getSimpleList($where);
  30. util::success($respond);
  31. }
  32. public function actionChangeFrontHide()
  33. {
  34. $get = Yii::$app->request->get();
  35. $id = $get['id'] ?? 0;
  36. $status = $get['status'] ?? '';
  37. if (is_numeric($status) == false) {
  38. util::fail('请选择方式');
  39. }
  40. $info = ItemClass::getById($id, true);
  41. if (empty($info)) {
  42. util::fail('没有找到花材');
  43. }
  44. if ($info->mainId != $this->mainId) {
  45. util::fail('无法操作');
  46. }
  47. $info->frontHide = $status;
  48. $info->save();
  49. util::complete();
  50. }
  51. //检测是否要刷新
  52. public function actionCheckRefresh()
  53. {
  54. $mainId = $this->mainId;
  55. $staffId = $this->shopAdminId;
  56. $respond = Yii::$app->redis->executeCommand('GET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  57. if ($respond == 'yes') {
  58. util::success(['remind' => 1]);
  59. }
  60. util::complete();
  61. }
  62. //批量恢复花材 ssh 20230206
  63. public function actionBatchRecover()
  64. {
  65. $post = Yii::$app->request->post();
  66. $string = $post['ids'] ?? '';
  67. $ids = json_decode($string, true);
  68. $ids = array_unique(array_filter($ids));
  69. if (empty($ids)) {
  70. util::fail('请选择花材');
  71. }
  72. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  73. if (empty($infoList)) {
  74. util::fail('请选择花材哦');
  75. }
  76. foreach ($infoList as $info) {
  77. if ($info->mainId != $this->mainId) {
  78. util::fail('请选择自己的花材');
  79. }
  80. $info->removeStatus = 0;
  81. $info->save();
  82. }
  83. util::complete('操作成功');
  84. }
  85. //批量删除花材 ssh 202302026
  86. public function actionBatchRemove()
  87. {
  88. $post = Yii::$app->request->post();
  89. $string = $post['ids'] ?? '';
  90. $ids = json_decode($string, true);
  91. $ids = array_unique(array_filter($ids));
  92. if (empty($ids)) {
  93. util::fail('请选择花材');
  94. }
  95. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  96. if (empty($infoList)) {
  97. util::fail('请选择花材哦');
  98. }
  99. foreach ($infoList as $info) {
  100. if ($info->mainId != $this->mainId) {
  101. util::fail('请选择自己的花材');
  102. }
  103. $name = $info->name ?? '';
  104. if ($info->delStatus != 1) {
  105. util::fail($name . ' 停用了才能删除');
  106. }
  107. $info->removeStatus = 1;
  108. $info->save();
  109. }
  110. util::complete('操作成功');
  111. }
  112. //批量启用花材 ssh 20230206
  113. public function actionBatchEnable()
  114. {
  115. $post = Yii::$app->request->post();
  116. $string = $post['ids'] ?? '';
  117. $ids = json_decode($string, true);
  118. $ids = array_unique(array_filter($ids));
  119. if (empty($ids)) {
  120. util::fail('请选择花材');
  121. }
  122. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  123. if (empty($infoList)) {
  124. util::fail('请选择花材哦');
  125. }
  126. foreach ($infoList as $info) {
  127. if ($info->mainId != $this->mainId) {
  128. util::fail('请选择自己的花材');
  129. }
  130. $info->delStatus = 0;
  131. $info->save();
  132. }
  133. util::complete('操作成功');
  134. }
  135. //批量停用花材 20230206
  136. public function actionBatchStop()
  137. {
  138. $post = Yii::$app->request->post();
  139. $string = $post['ids'] ?? '';
  140. $ids = json_decode($string, true);
  141. $ids = array_unique(array_filter($ids));
  142. if (empty($ids)) {
  143. util::fail('请选择花材');
  144. }
  145. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  146. if (empty($infoList)) {
  147. util::fail('请选择花材哦');
  148. }
  149. foreach ($infoList as $info) {
  150. if ($info->mainId != $this->mainId) {
  151. util::fail('请选择自己的花材');
  152. }
  153. $name = $info->name ?? '';
  154. if ($info->status != 2) {
  155. util::fail($name . ' 下载了才能停用');
  156. }
  157. $info->delStatus = 1;
  158. $info->save();
  159. }
  160. util::complete('操作成功');
  161. }
  162. //获取给散客下单的花材海报 ssh 20220111
  163. public function actionGetSkPoster()
  164. {
  165. $get = Yii::$app->request->get();
  166. $id = $get['id'] ?? 0;
  167. $item = ItemClass::getById($id, true);
  168. if (empty($item) || $item->mainId != $this->mainId) {
  169. util::fail('获取失败');
  170. }
  171. $cover = $item->cover ?? '';
  172. if (empty($cover)) {
  173. util::fail('获取失败');
  174. }
  175. $merchant = WxOpenClass::getMallWxInfo();
  176. $page = 'pages/item/detail';
  177. $ptStyle = dict::getDict('ptStyle', 'mall');
  178. $shop = $this->shop;
  179. $lsShopId = $shop->lsShopId ?? 0;
  180. //scene不能超过32个字条
  181. $scene = "id=" . $id . '&a=' . $lsShopId;
  182. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  183. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  184. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  185. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  186. $prefix = imgUtil::getPrefix();
  187. $price = $item->skPrice ?? 0;
  188. if ($item->discountPrice > 0) {
  189. $skMore = $item->skMore ?? 0;
  190. $price = bcadd($item->discountPrice, $skMore, 2);
  191. }
  192. $newPrice = '¥' . floatval($price);
  193. $priceBase64 = stringUtil::ossBase64($newPrice);
  194. $name = $item->name ?? '';
  195. $nameBase64 = stringUtil::ossBase64($name);
  196. $staff = $this->shopAdmin;
  197. $staffName = $staff->name ?? '';
  198. $newStaffName = $staffName . ' 为您推荐';
  199. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  200. //花材主图
  201. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  202. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  203. $logoBase64 = '';
  204. if (in_array($this->mainId, [52, 1459,13625])) {
  205. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  206. if ($this->mainId == 1459) {
  207. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  208. }
  209. if ($this->mainId == 13625) {
  210. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  211. }
  212. $logoBase64 = stringUtil::ossBase64($logo);
  213. }
  214. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  215. //花材主图
  216. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  217. //小程序码
  218. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  219. if (!empty($logoBase64)) {
  220. //logo
  221. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  222. }
  223. //为你推荐
  224. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  225. //标题
  226. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  227. //价格
  228. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  229. $respond = ['imgUrl' => $url];
  230. util::success($respond);
  231. }
  232. //获取给花店下单的花材海报 ssh 20220111
  233. public function actionGetHdPoster()
  234. {
  235. $get = Yii::$app->request->get();
  236. $id = $get['id'] ?? 0;
  237. $item = ItemClass::getById($id, true);
  238. if (empty($item) || $item->mainId != $this->mainId) {
  239. util::fail('获取失败');
  240. }
  241. $cover = $item->cover ?? '';
  242. if (empty($cover)) {
  243. util::fail('获取失败');
  244. }
  245. $merchant = WxOpenClass::getWxInfo();
  246. $page = 'admin/ghsProduct/detail';
  247. $ptStyle = dict::getDict('ptStyle', 'hd');
  248. //小程序码,scene不能超过32个字条
  249. $scene = "id=" . $id . '&sId=' . $this->shopId;
  250. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  251. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  252. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  253. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  254. $prefix = imgUtil::getPrefix();
  255. $price = $item->price ?? 0;
  256. if ($item->discountPrice > 0) {
  257. $price = $item->discountPrice;
  258. }
  259. $newPrice = '¥' . floatval($price);
  260. $priceBase64 = stringUtil::ossBase64($newPrice);
  261. $name = $item->name ?? '';
  262. $nameBase64 = stringUtil::ossBase64($name);
  263. $staff = $this->shopAdmin;
  264. $staffName = $staff->name ?? '';
  265. $newStaffName = $staffName . ' 为您推荐';
  266. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  267. //花材主图
  268. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  269. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  270. $logoBase64 = '';
  271. if (in_array($this->mainId, [52, 1459,13625])) {
  272. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  273. if ($this->mainId == 1459) {
  274. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  275. }
  276. if ($this->mainId == 13625) {
  277. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  278. }
  279. $logoBase64 = stringUtil::ossBase64($logo);
  280. }
  281. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  282. //花材主图
  283. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  284. //小程序码
  285. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  286. if (!empty($logoBase64)) {
  287. //logo
  288. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  289. }
  290. //为你推荐
  291. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  292. //标题
  293. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  294. //价格
  295. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  296. $respond = ['imgUrl' => $url];
  297. util::success($respond);
  298. }
  299. //是否有C级价格大于B级的 ssh 20221204
  300. public function actionGetErrorPrice()
  301. {
  302. $shop = $this->shop;
  303. $list = ItemClass::errorPrice($shop);
  304. util::success(['list' => $list]);
  305. }
  306. //列出所有花材,包括特价花材列表 ssh 20220315
  307. public function actionShowList()
  308. {
  309. $get = Yii::$app->request->get();
  310. $customId = $get['customId'] ?? 0;
  311. $custom = CustomClass::getById($customId, true);
  312. $where['mainId'] = $this->mainId;
  313. $where['delStatus'] = 0;
  314. $where['status'] = 1;
  315. $list = ItemClass::getShowList($where, $custom);
  316. $mainId = $this->mainId;
  317. $get = Yii::$app->request->get();
  318. $isCashier = $get['isCashier'] ?? 0;
  319. if ($isCashier == 1) {
  320. //去掉收银台提示价格更新
  321. $staffId = $this->shopAdminId;
  322. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  323. }
  324. util::success(['list' => $list]);
  325. }
  326. public function actionAdd()
  327. {
  328. util::fail('开发中');
  329. }
  330. //批量添加花材
  331. public function actionBatchAdd()
  332. {
  333. $shopAdmin = $this->shopAdmin;
  334. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  335. util::fail('超管才能操作');
  336. }
  337. $post = Yii::$app->request->post();
  338. //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
  339. $data = $post['data'];
  340. if (empty($data)) {
  341. util::fail("请选花材");
  342. }
  343. $data = json_decode($data, true);
  344. if (is_array($data) == false || empty($data)) {
  345. util::fail("请选花材");
  346. }
  347. $shop = $this->shop;
  348. $shopId = $this->shopId;
  349. $mainId = $this->mainId;
  350. $sjId = $this->sjId;
  351. $adminId = $this->adminId;
  352. $ids = array_column($data, 'itemId');
  353. $ids = array_unique(array_filter($ids));
  354. $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
  355. if (!empty($has)) {
  356. $hasName = $has->name ?? '';
  357. util::fail($hasName . " 已经添加过了");
  358. }
  359. $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  360. $connection = Yii::$app->db;
  361. $transaction = $connection->beginTransaction();
  362. try {
  363. foreach ($data as $v) {
  364. $ptItemId = $v['itemId'] ?? 0;
  365. $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
  366. $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
  367. $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
  368. $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
  369. $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
  370. $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
  371. $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
  372. $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
  373. $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
  374. $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
  375. $cover = $ptItemInfo[$ptItemId]['cover'] ?? 'default-img.png';
  376. $v['ratio'] = $ratio;
  377. $v['cover'] = $cover;
  378. $v['shelfLife'] = $shelfLife;
  379. $v['ratioType'] = $ratioType;
  380. $v['variety'] = $variety;
  381. $v['stockWarning'] = $stockWarning;
  382. $v['weight'] = $weight;
  383. $v['bigUnit'] = $bigUnit;
  384. $v['smallUnit'] = $smallUnit;
  385. $v['bigUnitId'] = $bigUnitId;
  386. $v['smallUnitId'] = $smallUnitId;
  387. $v['adminId'] = $adminId;
  388. $v['sjId'] = $sjId;
  389. $v['shopId'] = $shopId;
  390. $v['mainId'] = $mainId;
  391. $v['staffName'] = $shopAdmin->name ?? '';
  392. $name = $v['name'] ?? '';
  393. $price = is_numeric($v['price']) ? $v['price'] : 0;
  394. $skPrice = is_numeric($v['skPrice']) ? $v['skPrice'] : 0;
  395. $cost = is_numeric($v['cost']) ? $v['cost'] : 0;
  396. if ($price <= 0) {
  397. util::fail("请填写{$name}的批发价");
  398. }
  399. if ($skPrice <= 0) {
  400. util::fail("请填写{$name}的零售价");
  401. }
  402. if ($cost <= 0) {
  403. util::fail("请填写{$name}的成本价");
  404. }
  405. if ($price > $skPrice) {
  406. util::fail("{$name}的批发价比零售价还高");
  407. }
  408. if ($cost > $price) {
  409. util::fail("{$name}的成本价比批发价还高");
  410. }
  411. $skMore = bcsub($skPrice, $price, 2);
  412. $addPrice = bcsub($price, $cost, 2);
  413. $v['skMore'] = $skMore;
  414. $v['addPrice'] = $addPrice;
  415. $v['hjAddPrice'] = $addPrice;
  416. $v['hjPrice'] = $price;
  417. ProductClass::addProduct($v, $shop);
  418. }
  419. $transaction->commit();
  420. util::complete('添加成功');
  421. } catch (Exception $e) {
  422. $transaction->rollBack();
  423. util::fail();
  424. }
  425. }
  426. public function actionDelete()
  427. {
  428. util::fail('不能删除哦!');
  429. }
  430. //获取平台里的花材信息
  431. public function actionPlatformItem()
  432. {
  433. $py = Yii::$app->request->get('py', '');
  434. $where = [];
  435. if ($py) {
  436. $where = ['py' => $py];
  437. }
  438. $list = PtItemClass::getItemList($where);
  439. util::success($list);
  440. }
  441. //列出需要进行颜色管理的花材 ssh 20220820
  442. public function actionColorList()
  443. {
  444. $mainId = $this->mainId ?? 0;
  445. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  446. util::success(['list' => $list]);
  447. }
  448. //多颜色管理启用与停用 ssh 20221229
  449. public function actionChangeVariety()
  450. {
  451. $get = Yii::$app->request->get();
  452. $id = $get['id'] ?? 0;
  453. $variety = $get['variety'] ?? 0;
  454. $info = ItemClass::getById($id, true);
  455. if (empty($info) || $info->mainId != $this->mainId) {
  456. util::fail('操作失败');
  457. }
  458. $info->variety = $variety;
  459. $info->save();
  460. util::complete('操作成功');
  461. }
  462. //拆散花材 ssh 20221229
  463. public function actionBreakItem()
  464. {
  465. util::fail('开发中');
  466. util::complete();
  467. }
  468. }