ItemController.php 24 KB

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