ItemController.php 17 KB

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