ItemController.php 24 KB

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