ItemController.php 24 KB

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