ProductController.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/1/15 20:36
  5. */
  6. namespace ghs\controllers;
  7. use biz\admin\classes\AdminRoleClass;
  8. use biz\item\classes\PtItemClass;
  9. use bizGhs\custom\classes\CustomClass;
  10. use bizGhs\item\classes\ItemClass;
  11. use bizGhs\item\classes\ItemClassClass;
  12. use bizGhs\merchant\classes\ShopClass;
  13. use bizGhs\order\classes\PurchaseOrderClass;
  14. use bizGhs\product\classes\ProductClass;
  15. use bizGhs\product\models\Product;
  16. use bizGhs\product\services\ProductService;
  17. use bizGhs\shop\classes\ShopAdminClass;
  18. use bizGhs\stock\classes\StockInDayClass;
  19. use common\components\printUtil;
  20. use common\components\stringUtil;
  21. use common\components\util;
  22. use Yii;
  23. class ProductController extends BaseController
  24. {
  25. public $guestAccess = ['index'];
  26. //停止预售 ssh 20230224
  27. public function actionCancelPreSell()
  28. {
  29. $get = Yii::$app->request->get();
  30. $id = $get['id'] ?? 0;
  31. $info = ProductClass::getById($id, true);
  32. ProductClass::check($info, $this->mainId);
  33. if ($info->stock > 0) {
  34. util::fail('没有库存才能停止预售');
  35. }
  36. $info->presell = 0;
  37. $info->presellDate = '';
  38. $info->save();
  39. util::complete();
  40. }
  41. //修改预售 ssh 20221214
  42. public function actionChangePresell()
  43. {
  44. $post = Yii::$app->request->post();
  45. $id = $post['id'] ?? 0;
  46. $info = ProductClass::getById($id, true);
  47. ProductClass::check($info, $this->mainId);
  48. $str = $post['date'] ?? '';
  49. $presell = $post['presell'] ?? 0;
  50. $newStr = '';
  51. if ($presell == 1) {
  52. if (empty($str)) {
  53. util::fail('请填写预售日期');
  54. }
  55. $arr = json_decode($str, true);
  56. if (empty($arr)) {
  57. util::fail('请填写预售日期');
  58. }
  59. $new = [];
  60. foreach ($arr as $date) {
  61. $new[] = strtotime($date);
  62. }
  63. $new = array_unique(array_filter($new));
  64. asort($new);
  65. $newStr = implode(',', $new);
  66. }
  67. $info->presell = $presell;
  68. $info->presellDate = $newStr;
  69. $info->discountPrice = 0;
  70. $info->save();
  71. util::complete();
  72. }
  73. //取消特价 ssh 20220901
  74. public function actionCancelDiscount()
  75. {
  76. $get = Yii::$app->request->get();
  77. $id = $get['id'] ?? 0;
  78. $info = ProductClass::getById($id, true);
  79. ProductClass::check($info, $this->mainId);
  80. $info->discountPrice = 0;
  81. $info->save();
  82. util::complete();
  83. }
  84. //打印花材的标签 ssh 20220602
  85. public function actionPrint()
  86. {
  87. $get = Yii::$app->request->get();
  88. $id = $get['id'] ?? 0;
  89. $num = $get['num'] ?? 1;
  90. $type = $get['type'] ?? 0;
  91. $info = ProductClass::getById($id, true);
  92. if (empty($info)) {
  93. util::fail('没有找到花材');
  94. }
  95. $name = $info->name ?? '';
  96. $ptItemId = $info->itemId ?? 0;
  97. $mainId = $info->mainId ?? 0;
  98. $ext = $this->shopExt;
  99. $printLabelSn = $ext->printLabelSn ?? '';
  100. if (empty($printLabelSn)) {
  101. util::fail('请设置标签打印机');
  102. }
  103. $p = new printUtil($printLabelSn);
  104. $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
  105. if (isset($info->ratioType) && $info->ratioType == 1) {
  106. $unit = '若干' . $info->smallUnit . '/' . $info->bigUnit;
  107. }
  108. $p->times = $num;
  109. if (stringUtil::getWordNum($name) > 7) {
  110. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  111. } else {
  112. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  113. }
  114. //杭州斗南批发店
  115. if (isset($get['type']) == false && $this->shopId == 4608) {
  116. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  117. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  118. } else {
  119. if ($type == 0) {
  120. //打标签
  121. $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
  122. if (in_array($mainId, [52, 1459])) {
  123. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  124. } else {
  125. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  126. }
  127. } else {
  128. //打价码
  129. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  130. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  131. }
  132. }
  133. $p->printLabelMsg($content);
  134. util::complete();
  135. }
  136. //取出今天有入库的花材 ssh 20221024
  137. public function actionStockIn()
  138. {
  139. $py = Yii::$app->request->get('py', '');
  140. $version = Yii::$app->request->get('version', 0);
  141. if ($version == 0) {
  142. util::fail('请先升级版本到1.0.70以上');
  143. }
  144. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  145. $mainId = $this->mainId ?? 0;
  146. $where['mainId'] = $mainId;
  147. if ($py) {
  148. $pyName = strtolower($py);
  149. $where['py'] = $pyName;
  150. }
  151. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  152. if (empty($arr)) {
  153. util::fail('没有花材需要盘点');
  154. }
  155. $ids = array_column($arr, 'itemId');
  156. $ids = array_unique($ids);
  157. $where['id'] = ['in', $ids];
  158. $level = 1;
  159. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
  160. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  161. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  162. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  163. util::success($data);
  164. }
  165. //按分类列出所有花材
  166. public function actionShow()
  167. {
  168. $py = Yii::$app->request->get('py', '');
  169. $requestType = Yii::$app->request->get('requestType', 'common');
  170. //默认显示上架商品
  171. $status = Yii::$app->request->get('status', 1);
  172. //默认显示未删除商品
  173. $delStatus = Yii::$app->request->get('delStatus', 0);
  174. //获取所有当前供货商的分类 (全部、常用)
  175. //根据分类组装分类下的花材信息
  176. //中央ID
  177. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  178. $where['mainId'] = $this->mainId;
  179. if ($py) {
  180. $pyName = strtolower($py);
  181. $where['py'] = $pyName;
  182. }
  183. //改价和全部有库存花材列表
  184. if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
  185. $where['stock>'] = 0;
  186. }
  187. if (!empty($status)) {
  188. $where['status'] = $status;
  189. }
  190. $where['delStatus'] = $delStatus;
  191. //客户等级
  192. $customId = Yii::$app->request->get('customId', 0);
  193. $level = 1;
  194. if (!empty($customId)) {
  195. $custom = CustomClass::getById($customId, true);
  196. $level = $custom->level ?? 1;
  197. }
  198. $itemInfoData = [];
  199. if ($requestType == 'hasStockList') {
  200. //有库存的花材列表
  201. $field = 'id,py,name,classId,itemId,price,skPrice,stock';
  202. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  203. } elseif ($requestType == 'changePrice') {
  204. //修改价格列表
  205. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,presell,frontHide';
  206. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  207. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  208. } elseif ($requestType == 'changeStock') {
  209. //修改库存列表
  210. $field = 'id,py,cover,name,cost,itemId,status,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,frontHide';
  211. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  212. $itemInfoData = ProductClass::changeStockGroup($itemInfoData, $level);
  213. } elseif ($requestType == 'kd') {
  214. //开单的花材列表
  215. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio';
  216. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  217. $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level);
  218. } elseif ($requestType == 'itemList') {
  219. //花材列表
  220. if (in_array($this->mainId, [52, 1459, 2126, 2128])) {
  221. //惠雅鲜花的不列出frontHide字段,因为他花材太多很慢了
  222. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,bigUnit,smallUnit,ratio,ratioType,variety,price,discountPrice,skMore,stock,actualSold,stockWarning,status,presell';
  223. } else {
  224. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,bigUnit,smallUnit,ratio,ratioType,variety,price,discountPrice,skMore,stock,actualSold,stockWarning,status,presell,frontHide';
  225. }
  226. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  227. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  228. } elseif ($requestType == 'outList') {
  229. //下架花材列表
  230. $where['status'] = 2;
  231. $where['delStatus'] = 0;
  232. $where['removeStatus'] = 0;
  233. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  234. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  235. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  236. } elseif ($requestType == 'stopList') {
  237. //停用花材列表
  238. $where['delStatus'] = 1;
  239. $where['removeStatus'] = 0;
  240. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  241. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  242. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  243. } elseif ($requestType == 'removeList') {
  244. //删除花材列表
  245. $where['delStatus'] = 1;
  246. $where['removeStatus'] = 1;
  247. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  248. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  249. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  250. } elseif ($requestType == 'check') {
  251. //盘点花材列表
  252. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  253. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  254. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  255. } elseif ($requestType == 'break') {
  256. //报损花材
  257. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  258. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  259. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  260. } elseif ($requestType == 'part') {
  261. //报损花材
  262. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  263. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  264. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  265. } elseif ($requestType == 'stockOut') {
  266. //出库花材
  267. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio';
  268. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  269. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  270. } elseif ($requestType == 'cg') {
  271. //采购花材
  272. if (in_array($this->mainId, [52, 1459, 2126, 2128])) {
  273. //惠雅鲜花的不列出frontHide字段,因为他花材太多很慢了
  274. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight';
  275. }else{
  276. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight,frontHide';
  277. }
  278. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  279. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  280. } elseif ($requestType == 'warning') {
  281. //库存预警
  282. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,actualSold,presell,bigUnit,stockWarning,status';
  283. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  284. ->andWhere('`stock`<`stockWarning`')
  285. ->andWhere("delStatus=0")
  286. ->select($field)->asArray()->all();
  287. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  288. } else {
  289. util::fail('没有数据');
  290. }
  291. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  292. util::success($data);
  293. }
  294. //取出今天有入库的花材 ssh 20221224
  295. public function actionGetStockIn()
  296. {
  297. $py = Yii::$app->request->get('py', '');
  298. $version = Yii::$app->request->get('version', 0);
  299. if ($version == 0) {
  300. util::fail('请先升级版本到1.0.70以上');
  301. }
  302. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  303. $mainId = $this->mainId ?? 0;
  304. $where['mainId'] = $mainId;
  305. if ($py) {
  306. $pyName = strtolower($py);
  307. $where['py'] = $pyName;
  308. }
  309. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  310. if (empty($arr)) {
  311. util::fail('没有花材需要盘点');
  312. }
  313. $ids = array_column($arr, 'itemId');
  314. $ids = array_unique($ids);
  315. $where['id'] = ['in', $ids];
  316. $level = 1;
  317. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  318. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  319. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  320. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  321. util::success($data);
  322. }
  323. //按分类列出所有花材
  324. public function actionIndex()
  325. {
  326. $py = Yii::$app->request->get('py', '');
  327. $requestType = Yii::$app->request->get('requestType', 'common');
  328. //默认显示上架商品
  329. $status = Yii::$app->request->get('status', 1);
  330. //默认显示未删除商品
  331. $delStatus = Yii::$app->request->get('delStatus', 0);
  332. $warning = Yii::$app->request->get('warning', 0);
  333. //获取所有当前供货商的分类 (全部、常用)
  334. //根据分类组装分类下的花材信息
  335. //中央ID
  336. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  337. $where['mainId'] = $this->mainId;
  338. if ($py) {
  339. $pyName = strtolower($py);
  340. $where['py'] = $pyName;
  341. }
  342. if ($requestType == 'hasStock') {
  343. //改价只显示库存大于0的
  344. $where['stock>'] = 0;
  345. }
  346. if (!empty($status)) {
  347. $where['status'] = $status;
  348. }
  349. $where['delStatus'] = $delStatus;
  350. //客户等级
  351. $customId = Yii::$app->request->get('customId', 0);
  352. $level = 1;
  353. if (!empty($customId)) {
  354. $custom = CustomClass::getById($customId, true);
  355. $level = $custom->level ?? 1;
  356. }
  357. if ($warning == 1) {
  358. //库存预警
  359. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
  360. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  361. ->andWhere('`stock`<`stockWarning`')
  362. ->andWhere("delStatus=0")
  363. ->select($field)->asArray()->all();
  364. } else {
  365. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
  366. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  367. }
  368. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  369. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  370. util::success($data);
  371. }
  372. //所有花材分页和不分页
  373. public function actionList()
  374. {
  375. $where = [];
  376. $classId = Yii::$app->request->get('classId', 0);
  377. if (!empty($classId)) {
  378. $where['classId'] = $classId;
  379. }
  380. $name = Yii::$app->request->get('name', '');
  381. if (empty($name)) {
  382. $py = Yii::$app->request->get('py', '');
  383. $name = !empty($py) ? $py : '';
  384. }
  385. if (!empty($name)) {
  386. if (stringUtil::isLetter($name)) {
  387. $where['py'] = ['like', $name];
  388. } else {
  389. $where['name'] = ['like', $name];
  390. }
  391. }
  392. $status = Yii::$app->request->get('status', 0);
  393. if (!empty($status)) {
  394. $where['status'] = $status;
  395. }
  396. $delStatus = Yii::$app->request->get('delStatus', 0);
  397. if ($delStatus != 2) {
  398. $where['delStatus'] = $delStatus;
  399. }
  400. $where['mainId'] = $this->mainId;
  401. $productIds = Yii::$app->request->get('ids', '');
  402. if (!empty($productIds)) {
  403. $productIdArr = explode(',', $productIds);
  404. if (!empty($productIdArr)) {
  405. $where['id'] = ['in', $productIdArr];
  406. }
  407. }
  408. //输出标准会员价,即批发价,默认显示的是批发价
  409. $level = 1;
  410. $type = Yii::$app->request->get('type', '');
  411. $showPage = Yii::$app->request->get('showPage', 0);
  412. if ($showPage) {
  413. if ($type == 'waring') {
  414. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  415. $lackIds = array_column($pro, 'id');
  416. if (empty($lackIds)) {
  417. util::success([]);
  418. }
  419. $lackIds = array_filter(array_unique($lackIds));
  420. $where['id'] = ['in', $lackIds];
  421. $respond = ProductClass::getList("*", $where, "actualSold desc");
  422. } else {
  423. $respond = ProductClass::getList("*", $where, "inTurn desc");
  424. }
  425. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  426. $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
  427. util::success($respond);
  428. } else {
  429. if ($type == 'waring') {
  430. //库存预警 按库存从小到大排序
  431. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  432. } else {
  433. if (!empty($productIds)) {
  434. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  435. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  436. } else {
  437. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  438. }
  439. }
  440. $data = ProductClass::groupProductInfo($data, $level);
  441. $data = ProductClass::groupClassName($this->sjId, $data);
  442. if ($type == 'waring') {
  443. //库存预警
  444. $newData = [];
  445. foreach ($data as $v) {
  446. if ($v['stock'] <= $v['stockWarning']) {
  447. $newData[] = $v;
  448. }
  449. }
  450. util::success(['list' => $newData]);
  451. }
  452. util::success(['list' => $data]);
  453. }
  454. }
  455. //所有花材
  456. public function actionAll()
  457. {
  458. $where = [];
  459. $where['mainId'] = $this->mainId;
  460. $classId = Yii::$app->request->get('classId', 0);
  461. if (!empty($classId)) {
  462. $where['classId'] = $classId;
  463. }
  464. $status = Yii::$app->request->get('status', 0);
  465. if (!empty($status)) {
  466. $where['status'] = $status;
  467. }
  468. $delStatus = Yii::$app->request->get('delStatus', 0);
  469. if ($delStatus != 2) {
  470. $where['delStatus'] = $delStatus;
  471. }
  472. //输出标准会员价,即批发价,默认显示的是批发价
  473. $level = 1;
  474. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  475. $data = ProductClass::groupProductInfo($data, $level);
  476. util::success(['list' => $data]);
  477. }
  478. //批量改价
  479. public function actionBatchChangePrice()
  480. {
  481. $shop = $this->shop;
  482. $join = $shop->join ?? 0;
  483. $default = $shop->default ?? 0;
  484. if ($join == 0 && $default == 0) {
  485. util::fail('当前直营分店,只能回总店修改价格');
  486. }
  487. $shopAdmin = $this->shopAdmin;
  488. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  489. util::fail('超管才能修改');
  490. }
  491. $shop = $this->shop;
  492. $default = $shop->default ?? 0;
  493. $adminId = $this->adminId ?? 0;
  494. //normal常规改价,cg采购改价
  495. $changeType = Yii::$app->request->post('changeType', 'normal');
  496. $targetId = Yii::$app->request->post('targetId', 0);
  497. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  498. $data = Yii::$app->request->post('data', '');
  499. if (empty($data)) {
  500. util::fail('没有修改');
  501. }
  502. $arr = json_decode($data, true);
  503. if (empty($arr)) {
  504. util::fail('没有修改哦');
  505. }
  506. $connection = Yii::$app->db;
  507. $transaction = $connection->beginTransaction();
  508. try {
  509. $cg = PurchaseOrderClass::getLockById($targetId);
  510. if (!empty($cg)) {
  511. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  512. util::fail('不是您的采购单');
  513. }
  514. //批量改价同时入库
  515. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  516. $staff = $this->shopAdmin;
  517. $data = [];
  518. $data['staffId'] = $staff->id ?? 0;
  519. $data['staffName'] = $staff->name ?? '';
  520. $data['adminId'] = $this->adminId ?? 0;
  521. PurchaseOrderClass::putIn($cg, $data);
  522. }
  523. }
  524. $ids = array_column($arr, 'id');
  525. $ids = array_unique(array_filter($ids));
  526. if (empty($ids)) {
  527. util::fail('请选择花材');
  528. }
  529. $sjId = $shop->sjId ?? 0;
  530. $chainShopList = [];
  531. if ($default == 1) {
  532. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  533. }
  534. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  535. foreach ($arr as $product) {
  536. $productId = $product['id'];
  537. $productInfo = $productList[$productId] ?? [];
  538. if (empty($productInfo)) {
  539. util::fail('没有找到花材');
  540. }
  541. $productName = $productInfo->name ?? '';
  542. if (isset($product['id']) == false) {
  543. util::fail('没有花材');
  544. }
  545. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  546. util::fail('请填写' . $productName . '的批发价');
  547. }
  548. $price = $product['price'];
  549. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  550. util::fail('请填写' . $productName . '的零售价');
  551. }
  552. $skPrice = $product['skPrice'];
  553. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  554. util::fail('没有权限访问');
  555. }
  556. if (empty($price)) {
  557. continue;
  558. }
  559. $ptItemId = $productInfo->itemId;
  560. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $changeParams);
  561. //在首店修改需要同步到所有直营店
  562. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  563. foreach ($chainShopList as $chain) {
  564. if ($chain->id == $shop->id) {
  565. continue;
  566. }
  567. $chainMainId = $chain->mainId ?? 0;
  568. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  569. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  570. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $changeParams2);
  571. }
  572. }
  573. }
  574. $mainId = $shop->mainId ?? 0;
  575. if (!empty($mainId)) {
  576. //提醒零售收银台界面要刷新
  577. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  578. if (!empty($staffList)) {
  579. foreach ($staffList as $staff) {
  580. $staffId = $staff->id ?? 0;
  581. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  582. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  583. }
  584. }
  585. }
  586. $transaction->commit();
  587. util::complete('操作成功');
  588. } catch (\Exception $e) {
  589. $transaction->rollBack();
  590. Yii::info("修改失败原因:" . $e->getMessage());
  591. util::fail('修改失败');
  592. }
  593. }
  594. //改价
  595. public function actionChangePrice()
  596. {
  597. $shopAdmin = $this->shopAdmin;
  598. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  599. util::fail('超管才能修改');
  600. }
  601. $productId = Yii::$app->request->post('productId', 0);
  602. $productInfo = ProductClass::getById($productId, true);
  603. if (empty($productInfo)) {
  604. util::fail("花材不存在");
  605. }
  606. if ($productInfo->mainId != $this->mainId) {
  607. util::fail('没有权限');
  608. }
  609. $price = Yii::$app->request->post('price', '');
  610. if (is_numeric($price) && $price > 0) {
  611. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  612. } else {
  613. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  614. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  615. }
  616. util::success(['price' => $price]);
  617. }
  618. //恢复自动调价
  619. public function actionAutoPrice()
  620. {
  621. $productId = Yii::$app->request->post('productId', 0);
  622. $productData = ProductClass::getById($productId);
  623. if (!$productData) {
  624. util::fail("花材不存在");
  625. }
  626. //2021.04.06改为用product中的成本价+加价
  627. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  628. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  629. util::complete("操作成功");
  630. }
  631. //修改加价
  632. public function actionChangeAddPrice()
  633. {
  634. $productId = Yii::$app->request->post('productId', 0);
  635. $addPrice = Yii::$app->request->post('addPrice', '');
  636. if ($addPrice < 0) {
  637. util::fail("加价不能小于0");
  638. }
  639. $productData = ProductClass::getProductData($productId, $this->mainId);
  640. if (!$productData) {
  641. util::fail("花材不存在");
  642. }
  643. ProductClass::changeAddPrice($productId, $addPrice);
  644. util::complete();
  645. }
  646. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  647. public function actionBatchChangeMore()
  648. {
  649. $shop = $this->shop;
  650. $default = $shop->default ?? 0;
  651. if ($default == 0) {
  652. util::fail('当前直营分店,只能回总店修改');
  653. }
  654. $shopAdmin = $this->shopAdmin;
  655. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  656. util::fail('超管才能操作');
  657. }
  658. $addData = Yii::$app->request->post('addData', '');
  659. if (empty($addData)) {
  660. util::fail('没有花材');
  661. }
  662. $itemData = json_decode($addData, true);
  663. if (is_array($itemData) == false) {
  664. util::fail('没有花材...');
  665. }
  666. $ids = array_column($itemData, 'id');
  667. $infoList = ProductClass::getByIds($ids, null, 'id');
  668. if (empty($infoList)) {
  669. util::fail('没有花材');
  670. }
  671. foreach ($infoList as $info) {
  672. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  673. util::fail('不是你的花材不能修改');
  674. }
  675. }
  676. //总店修改同步到所有门店
  677. $sjId = $shop->sjId ?? 0;
  678. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  679. foreach ($itemData as $key => $data) {
  680. $id = $data['id'] ?? 0;
  681. unset($data['id']);
  682. ProductClass::updateById($id, $data);
  683. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  684. if (empty($ptItemId)) {
  685. continue;
  686. }
  687. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  688. foreach ($chainShopList as $chainShop) {
  689. $currentMainId = $chainShop->mainId ?? 0;
  690. if ($currentMainId == $shop->mainId) {
  691. //前面已经修改过了,不需要重复修改
  692. continue;
  693. }
  694. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  695. }
  696. }
  697. }
  698. util::complete('修改成功');
  699. }
  700. //批量修改加价 ssh 20211211
  701. public function actionBatchChangeAddPrice()
  702. {
  703. $shop = $this->shop;
  704. $join = $shop->join ?? 0;
  705. $default = $shop->default ?? 0;
  706. if ($join == 0 && $default == 0) {
  707. util::fail('当前直营分店,请切回总店操作');
  708. }
  709. $shopAdmin = $this->shopAdmin;
  710. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  711. util::fail('超管才能操作');
  712. }
  713. $addData = Yii::$app->request->post('addData', '');
  714. if (empty($addData)) {
  715. util::fail('没有花材');
  716. }
  717. $itemData = json_decode($addData, true);
  718. if (is_array($itemData) == false) {
  719. util::fail('没有花材...');
  720. }
  721. $ids = array_column($itemData, 'id');
  722. $infoList = ProductClass::getByIds($ids, null, 'id');
  723. if (empty($infoList)) {
  724. util::fail('没有花材');
  725. }
  726. foreach ($infoList as $info) {
  727. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  728. util::fail('不能修改别人的花材');
  729. }
  730. }
  731. //总店修改同步到所有门店
  732. $sjId = $shop->sjId ?? 0;
  733. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  734. foreach ($itemData as $key => $data) {
  735. $id = $data['id'] ?? 0;
  736. unset($data['id']);
  737. ProductClass::updateById($id, $data);
  738. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  739. if (empty($ptItemId)) {
  740. continue;
  741. }
  742. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  743. foreach ($chainShopList as $chainShop) {
  744. if (isset($chainShop->join) && $chainShop->join == 1) {
  745. continue;
  746. }
  747. $currentMainId = $chainShop->mainId ?? 0;
  748. if ($currentMainId == $shop->mainId) {
  749. //前面已经修改过了,不需要重复修改
  750. continue;
  751. }
  752. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  753. }
  754. }
  755. }
  756. util::complete('修改成功');
  757. }
  758. public function actionUpdate()
  759. {
  760. $shopAdmin = $this->shopAdmin;
  761. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  762. util::fail('超管才能操作');
  763. }
  764. $shop = $this->shop;
  765. $join = $shop->join ?? 0;
  766. $default = $shop->default ?? 0;
  767. if ($join == 0 && $default == 0) {
  768. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  769. if ($shopAdmin->super != 1) {
  770. util::fail('请先开通超管权限');
  771. }
  772. }
  773. $post = Yii::$app->request->post();
  774. $post['adminId'] = $this->adminId;
  775. $post['staffId'] = $this->shopAdmin->id;
  776. $post['staffName'] = $this->shopAdmin->name;
  777. ProductClass::updateProduct($post, $this->shop);
  778. util::complete();
  779. }
  780. //上下架状态控制 ssh 20210713
  781. public function actionStatusUpdate()
  782. {
  783. $post = Yii::$app->request->post();
  784. $shopAdmin = $this->shopAdmin;
  785. $roleId = $shopAdmin['roleId'] ?? 0;
  786. $role = AdminRoleClass::getById($roleId);
  787. $roleName = $role['roleName'] ?? '';
  788. if ($roleName == '员工') {
  789. util::fail('没有权限操作哦');
  790. }
  791. $id = $post['id'] ?? 0;
  792. $status = $post['status'] ?? 1;
  793. $product = ProductClass::getById($id, true);
  794. if ($product->mainId != $this->mainId) {
  795. util::fail('没有权限操作');
  796. }
  797. $product->status = $status;
  798. if ($status == 2) {
  799. $product->discountPrice = 0;
  800. }
  801. $product->save();
  802. util::complete();
  803. }
  804. //花材展示状态控制 ssh 20210804
  805. public function actionDelStatusUpdate()
  806. {
  807. $post = Yii::$app->request->post();
  808. $shop = $this->shop;
  809. $join = $shop->join ?? 0;
  810. $default = $shop->default ?? 0;
  811. if ($join == 0 && $default == 0) {
  812. util::fail('请在首店操作');
  813. }
  814. $shopAdmin = $this->shopAdmin;
  815. $roleId = $shopAdmin['roleId'] ?? 0;
  816. $role = AdminRoleClass::getById($roleId);
  817. $roleName = $role['roleName'] ?? '';
  818. if ($roleName == '员工') {
  819. util::fail('没有权限操作');
  820. }
  821. $id = $post['id'] ?? 0;
  822. $delStatus = $post['delStatus'] ?? 0;
  823. $product = ProductClass::getById($id, true);
  824. if ($product->mainId != $this->mainId) {
  825. util::fail('没有权限操作');
  826. }
  827. $product->delStatus = $delStatus;
  828. $product->save();
  829. $ptItemId = $product->itemId ?? 0;
  830. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  831. //总店修改同步到所有门店
  832. $sjId = $shop->sjId ?? 0;
  833. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  834. foreach ($chainShopList as $chainShop) {
  835. $chainShopId = $chainShop->id ?? 0;
  836. if (isset($chainShop->join) && $chainShop->join == 1) {
  837. continue;
  838. }
  839. if ($chainShopId == $shop->id) {
  840. continue;
  841. }
  842. $chainMainId = $chainShop->mainId ?? 0;
  843. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  844. if (!empty($chainProduct)) {
  845. $chainProduct->delStatus = $delStatus;
  846. $chainProduct->save();
  847. }
  848. }
  849. }
  850. util::complete();
  851. }
  852. //详情 ruidian 2021.5.3
  853. public function actionDetail()
  854. {
  855. $id = Yii::$app->request->get('id', 0);
  856. $respond = ProductClass::getItemInfo($id);
  857. $ptItemId = $respond['itemId'] ?? 0;
  858. $ptItemInfo = PtItemClass::getById($ptItemId);
  859. $respond['ptItemInfo'] = $ptItemInfo;
  860. util::success($respond);
  861. }
  862. //新增花材 2021.6.21
  863. public function actionAdd()
  864. {
  865. $post = Yii::$app->request->post();
  866. $shop = $this->shop;
  867. $join = $shop->join ?? 0;
  868. $default = $shop->default ?? 0;
  869. if ($join == 0 && $default == 0) {
  870. util::fail('当前直营分店,请切回总店添加花材');
  871. }
  872. $shopAdmin = $this->shopAdmin;
  873. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  874. util::fail('管理员才能添加花材');
  875. }
  876. $post['sjId'] = $this->sjId;
  877. $post['adminId'] = $this->adminId;
  878. $post['mainId'] = $this->mainId;
  879. $price = $post['price'] ?? 0;
  880. $addPrice = $post['addPrice'] ?? 0;
  881. if ($addPrice > $price) {
  882. util::fail('加价不能大于售价');
  883. }
  884. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  885. if ($weight <= 0) {
  886. util::fail('请填写重量,最小0.1');
  887. }
  888. $post['staffName'] = $shopAdmin->name ?? '';
  889. ProductClass::addProduct($post, $this->shop);
  890. util::complete('添加成功');
  891. }
  892. //获取拼音缩写 ssh 20210707
  893. public function actionPy()
  894. {
  895. $name = Yii::$app->request->get('name');
  896. $py = stringUtil::py($name);
  897. util::success(['py' => $py]);
  898. }
  899. //(客户端-批发商)复制花材
  900. public function actionClone()
  901. {
  902. $post = Yii::$app->request->post();
  903. $shop = $this->shop;
  904. $join = $shop->join ?? 0;
  905. $default = $shop->default ?? 0;
  906. if ($join == 0 && $default == 0) {
  907. util::fail('请在首店操作');
  908. }
  909. $shopAdmin = $this->shopAdmin;
  910. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  911. util::fail('管理员才能添加花材');
  912. }
  913. $post['sjId'] = $this->sjId;
  914. $post['adminId'] = $this->adminId;
  915. $post['mainId'] = $this->mainId;
  916. $post['staffName'] = $shopAdmin->name ?? '';
  917. $price = $post['price'] ?? 0;
  918. $addPrice = $post['addPrice'] ?? 0;
  919. if ($addPrice > $price) {
  920. util::fail('加价不能大于售价');
  921. }
  922. //复制标识
  923. $post['copy'] = 1;
  924. //去除无用的字段
  925. unset($post['viewNum']);
  926. unset($post['actualSold']);
  927. unset($post['itemId']);
  928. unset($post['id']);
  929. unset($post['delStatus']);
  930. ProductClass::addProduct($post, $this->shop);
  931. util::complete('复制成功');
  932. }
  933. //下载价格表 ssh 20210922
  934. public function actionGeneratePriceTable()
  935. {
  936. $level = Yii::$app->request->get('level', 0);
  937. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  938. $file = $respond['file'] ?? '';
  939. $shortFile = $respond['shortFile'] ?? '';
  940. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  941. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  942. }
  943. public function actionGenerateItemTable()
  944. {
  945. $level = Yii::$app->request->get('level', 0);
  946. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  947. $file = $respond['file'] ?? '';
  948. $shortFile = $respond['shortFile'] ?? '';
  949. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  950. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  951. }
  952. //下载条形码 lqh 20211227
  953. public function actionGenerateBarcodeTable()
  954. {
  955. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  956. $file = $respond['file'] ?? '';
  957. $shortFile = $respond['shortFile'] ?? '';
  958. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  959. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  960. }
  961. //批量修改花材的分类 ssh 20230405
  962. public function actionBatchModifyClass()
  963. {
  964. $post = Yii::$app->request->post();
  965. $shop = $this->shop;
  966. $join = $shop->join ?? 0;
  967. $default = $shop->default ?? 0;
  968. if ($join == 0 && $default == 0) {
  969. util::fail('当前直营分店,请切回总店操作');
  970. }
  971. $classId = $post['classId'] ?? 0;
  972. $class = ItemClassClass::getById($classId, true);
  973. if (empty($class) || $class->mainId != $this->mainId) {
  974. util::fail('请选择您自己的分类');
  975. }
  976. $connection = Yii::$app->db;
  977. $transaction = $connection->beginTransaction();
  978. try {
  979. $className = $class->name ?? '';
  980. $idsList = $post['ids'] ?? '';
  981. $ids = json_decode($idsList, true);
  982. if (empty($ids)) {
  983. util::fail('请选择花材');
  984. }
  985. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  986. if (empty($list)) {
  987. util::fail('请选择花材');
  988. }
  989. $ptItemList = [];
  990. foreach ($list as $item) {
  991. $name = $item->name ?? '';
  992. if ($item->mainId != $this->mainId) {
  993. util::fail($name . '不是您的花材');
  994. }
  995. $item->classId = $classId;
  996. $item->save();
  997. $ptItemId = $item->itemId ?? 0;
  998. $ptItemList[] = $ptItemId;
  999. }
  1000. $shop = $this->shop;
  1001. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1002. //总店修改同步到所有门店
  1003. $sjId = $shop->sjId ?? 0;
  1004. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1005. foreach ($chainShopList as $chainShop) {
  1006. $chainShopId = $chainShop->id ?? 0;
  1007. if ($chainShopId == $shop->id) {
  1008. continue;
  1009. }
  1010. $chainManId = $chainShop->mainId ?? 0;
  1011. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1012. if (!empty($chainAllClassList)) {
  1013. foreach ($chainAllClassList as $chainClass) {
  1014. $chainName = $chainClass->name ?? '';
  1015. $chainClassId = $chainClass->id ?? 0;
  1016. if ($chainName == $className) {
  1017. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1018. if (!empty($chainProductList)) {
  1019. foreach ($chainProductList as $currentProduct) {
  1020. $currentProduct->classId = $chainClassId;
  1021. $currentProduct->save();
  1022. }
  1023. }
  1024. }
  1025. }
  1026. }
  1027. }
  1028. }
  1029. $transaction->commit();
  1030. util::complete('修改成功');
  1031. } catch (\Exception $e) {
  1032. $transaction->rollBack();
  1033. Yii::info("修改失败原因:" . $e->getMessage());
  1034. util::fail('修改失败');
  1035. }
  1036. }
  1037. }