ItemController.php 24 KB

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