ProductController.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  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';
  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. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight';
  273. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  274. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  275. } elseif ($requestType == 'warning') {
  276. //库存预警
  277. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,actualSold,presell,bigUnit,stockWarning,status';
  278. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  279. ->andWhere('`stock`<`stockWarning`')
  280. ->andWhere("delStatus=0")
  281. ->select($field)->asArray()->all();
  282. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  283. } else {
  284. util::fail('没有数据');
  285. }
  286. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  287. util::success($data);
  288. }
  289. //取出今天有入库的花材 ssh 20221224
  290. public function actionGetStockIn()
  291. {
  292. $py = Yii::$app->request->get('py', '');
  293. $version = Yii::$app->request->get('version', 0);
  294. if ($version == 0) {
  295. util::fail('请先升级版本到1.0.70以上');
  296. }
  297. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  298. $mainId = $this->mainId ?? 0;
  299. $where['mainId'] = $mainId;
  300. if ($py) {
  301. $pyName = strtolower($py);
  302. $where['py'] = $pyName;
  303. }
  304. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  305. if (empty($arr)) {
  306. util::fail('没有花材需要盘点');
  307. }
  308. $ids = array_column($arr, 'itemId');
  309. $ids = array_unique($ids);
  310. $where['id'] = ['in', $ids];
  311. $level = 1;
  312. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  313. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  314. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  315. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  316. util::success($data);
  317. }
  318. //按分类列出所有花材
  319. public function actionIndex()
  320. {
  321. $py = Yii::$app->request->get('py', '');
  322. $requestType = Yii::$app->request->get('requestType', 'common');
  323. //默认显示上架商品
  324. $status = Yii::$app->request->get('status', 1);
  325. //默认显示未删除商品
  326. $delStatus = Yii::$app->request->get('delStatus', 0);
  327. $warning = Yii::$app->request->get('warning', 0);
  328. //获取所有当前供货商的分类 (全部、常用)
  329. //根据分类组装分类下的花材信息
  330. //中央ID
  331. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  332. $where['mainId'] = $this->mainId;
  333. if ($py) {
  334. $pyName = strtolower($py);
  335. $where['py'] = $pyName;
  336. }
  337. if ($requestType == 'hasStock') {
  338. //改价只显示库存大于0的
  339. $where['stock>'] = 0;
  340. }
  341. if (!empty($status)) {
  342. $where['status'] = $status;
  343. }
  344. $where['delStatus'] = $delStatus;
  345. //客户等级
  346. $customId = Yii::$app->request->get('customId', 0);
  347. $level = 1;
  348. if (!empty($customId)) {
  349. $custom = CustomClass::getById($customId, true);
  350. $level = $custom->level ?? 1;
  351. }
  352. if ($warning == 1) {
  353. //库存预警
  354. $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';
  355. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  356. ->andWhere('`stock`<`stockWarning`')
  357. ->andWhere("delStatus=0")
  358. ->select($field)->asArray()->all();
  359. } else {
  360. $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';
  361. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  362. }
  363. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  364. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  365. util::success($data);
  366. }
  367. //所有花材分页和不分页
  368. public function actionList()
  369. {
  370. $where = [];
  371. $classId = Yii::$app->request->get('classId', 0);
  372. if (!empty($classId)) {
  373. $where['classId'] = $classId;
  374. }
  375. $name = Yii::$app->request->get('name', '');
  376. if (empty($name)) {
  377. $py = Yii::$app->request->get('py', '');
  378. $name = !empty($py) ? $py : '';
  379. }
  380. if (!empty($name)) {
  381. if (stringUtil::isLetter($name)) {
  382. $where['py'] = ['like', $name];
  383. } else {
  384. $where['name'] = ['like', $name];
  385. }
  386. }
  387. $status = Yii::$app->request->get('status', 0);
  388. if (!empty($status)) {
  389. $where['status'] = $status;
  390. }
  391. $delStatus = Yii::$app->request->get('delStatus', 0);
  392. if ($delStatus != 2) {
  393. $where['delStatus'] = $delStatus;
  394. }
  395. $where['mainId'] = $this->mainId;
  396. $productIds = Yii::$app->request->get('ids', '');
  397. if (!empty($productIds)) {
  398. $productIdArr = explode(',', $productIds);
  399. if (!empty($productIdArr)) {
  400. $where['id'] = ['in', $productIdArr];
  401. }
  402. }
  403. //输出标准会员价,即批发价,默认显示的是批发价
  404. $level = 1;
  405. $type = Yii::$app->request->get('type', '');
  406. $showPage = Yii::$app->request->get('showPage', 0);
  407. if ($showPage) {
  408. if ($type == 'waring') {
  409. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  410. $lackIds = array_column($pro, 'id');
  411. if (empty($lackIds)) {
  412. util::success([]);
  413. }
  414. $lackIds = array_filter(array_unique($lackIds));
  415. $where['id'] = ['in', $lackIds];
  416. $respond = ProductClass::getList("*", $where, "actualSold desc");
  417. } else {
  418. $respond = ProductClass::getList("*", $where, "inTurn desc");
  419. }
  420. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  421. $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
  422. util::success($respond);
  423. } else {
  424. if ($type == 'waring') {
  425. //库存预警 按库存从小到大排序
  426. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  427. } else {
  428. if (!empty($productIds)) {
  429. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  430. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  431. } else {
  432. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  433. }
  434. }
  435. $data = ProductClass::groupProductInfo($data, $level);
  436. $data = ProductClass::groupClassName($this->sjId, $data);
  437. if ($type == 'waring') {
  438. //库存预警
  439. $newData = [];
  440. foreach ($data as $v) {
  441. if ($v['stock'] <= $v['stockWarning']) {
  442. $newData[] = $v;
  443. }
  444. }
  445. util::success(['list' => $newData]);
  446. }
  447. util::success(['list' => $data]);
  448. }
  449. }
  450. //所有花材
  451. public function actionAll()
  452. {
  453. $where = [];
  454. $where['mainId'] = $this->mainId;
  455. $classId = Yii::$app->request->get('classId', 0);
  456. if (!empty($classId)) {
  457. $where['classId'] = $classId;
  458. }
  459. $status = Yii::$app->request->get('status', 0);
  460. if (!empty($status)) {
  461. $where['status'] = $status;
  462. }
  463. $delStatus = Yii::$app->request->get('delStatus', 0);
  464. if ($delStatus != 2) {
  465. $where['delStatus'] = $delStatus;
  466. }
  467. //输出标准会员价,即批发价,默认显示的是批发价
  468. $level = 1;
  469. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  470. $data = ProductClass::groupProductInfo($data, $level);
  471. util::success(['list' => $data]);
  472. }
  473. //批量改价
  474. public function actionBatchChangePrice()
  475. {
  476. $shop = $this->shop;
  477. $join = $shop->join ?? 0;
  478. $default = $shop->default ?? 0;
  479. if ($join == 0 && $default == 0) {
  480. util::fail('当前直营分店,只能回总店修改价格');
  481. }
  482. $shopAdmin = $this->shopAdmin;
  483. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  484. util::fail('超管才能修改');
  485. }
  486. $shop = $this->shop;
  487. $default = $shop->default ?? 0;
  488. $adminId = $this->adminId ?? 0;
  489. //normal常规改价,cg采购改价
  490. $changeType = Yii::$app->request->post('changeType', 'normal');
  491. $targetId = Yii::$app->request->post('targetId', 0);
  492. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  493. $data = Yii::$app->request->post('data', '');
  494. if (empty($data)) {
  495. util::fail('没有修改');
  496. }
  497. $arr = json_decode($data, true);
  498. if (empty($arr)) {
  499. util::fail('没有修改哦');
  500. }
  501. $connection = Yii::$app->db;
  502. $transaction = $connection->beginTransaction();
  503. try {
  504. $cg = PurchaseOrderClass::getLockById($targetId);
  505. if (!empty($cg)) {
  506. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  507. util::fail('不是您的采购单');
  508. }
  509. //批量改价同时入库
  510. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  511. $staff = $this->shopAdmin;
  512. $data = [];
  513. $data['staffId'] = $staff->id ?? 0;
  514. $data['staffName'] = $staff->name ?? '';
  515. $data['adminId'] = $this->adminId ?? 0;
  516. PurchaseOrderClass::putIn($cg, $data);
  517. }
  518. }
  519. $ids = array_column($arr, 'id');
  520. $ids = array_unique(array_filter($ids));
  521. if (empty($ids)) {
  522. util::fail('请选择花材');
  523. }
  524. $sjId = $shop->sjId ?? 0;
  525. $chainShopList = [];
  526. if ($default == 1) {
  527. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  528. }
  529. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  530. foreach ($arr as $product) {
  531. $productId = $product['id'];
  532. $productInfo = $productList[$productId] ?? [];
  533. if (empty($productInfo)) {
  534. util::fail('没有找到花材');
  535. }
  536. $productName = $productInfo->name ?? '';
  537. if (isset($product['id']) == false) {
  538. util::fail('没有花材');
  539. }
  540. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  541. util::fail('请填写' . $productName . '的批发价');
  542. }
  543. $price = $product['price'];
  544. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  545. util::fail('请填写' . $productName . '的零售价');
  546. }
  547. $skPrice = $product['skPrice'];
  548. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  549. util::fail('没有权限访问');
  550. }
  551. if (empty($price)) {
  552. continue;
  553. }
  554. $ptItemId = $productInfo->itemId;
  555. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $changeParams);
  556. //在首店修改需要同步到所有直营店
  557. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  558. foreach ($chainShopList as $chain) {
  559. if ($chain->id == $shop->id) {
  560. continue;
  561. }
  562. $chainMainId = $chain->mainId ?? 0;
  563. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  564. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  565. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $changeParams2);
  566. }
  567. }
  568. }
  569. $mainId = $shop->mainId ?? 0;
  570. if (!empty($mainId)) {
  571. //提醒零售收银台界面要刷新
  572. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  573. if (!empty($staffList)) {
  574. foreach ($staffList as $staff) {
  575. $staffId = $staff->id ?? 0;
  576. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  577. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  578. }
  579. }
  580. }
  581. $transaction->commit();
  582. util::complete('操作成功');
  583. } catch (\Exception $e) {
  584. $transaction->rollBack();
  585. Yii::info("修改失败原因:" . $e->getMessage());
  586. util::fail('修改失败');
  587. }
  588. }
  589. //改价
  590. public function actionChangePrice()
  591. {
  592. $shopAdmin = $this->shopAdmin;
  593. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  594. util::fail('超管才能修改');
  595. }
  596. $productId = Yii::$app->request->post('productId', 0);
  597. $productInfo = ProductClass::getById($productId, true);
  598. if (empty($productInfo)) {
  599. util::fail("花材不存在");
  600. }
  601. if ($productInfo->mainId != $this->mainId) {
  602. util::fail('没有权限');
  603. }
  604. $price = Yii::$app->request->post('price', '');
  605. if (is_numeric($price) && $price > 0) {
  606. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  607. } else {
  608. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  609. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  610. }
  611. util::success(['price' => $price]);
  612. }
  613. //恢复自动调价
  614. public function actionAutoPrice()
  615. {
  616. $productId = Yii::$app->request->post('productId', 0);
  617. $productData = ProductClass::getById($productId);
  618. if (!$productData) {
  619. util::fail("花材不存在");
  620. }
  621. //2021.04.06改为用product中的成本价+加价
  622. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  623. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  624. util::complete("操作成功");
  625. }
  626. //修改加价
  627. public function actionChangeAddPrice()
  628. {
  629. $productId = Yii::$app->request->post('productId', 0);
  630. $addPrice = Yii::$app->request->post('addPrice', '');
  631. if ($addPrice < 0) {
  632. util::fail("加价不能小于0");
  633. }
  634. $productData = ProductClass::getProductData($productId, $this->mainId);
  635. if (!$productData) {
  636. util::fail("花材不存在");
  637. }
  638. ProductClass::changeAddPrice($productId, $addPrice);
  639. util::complete();
  640. }
  641. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  642. public function actionBatchChangeMore()
  643. {
  644. $shop = $this->shop;
  645. $default = $shop->default ?? 0;
  646. if ($default == 0) {
  647. util::fail('当前直营分店,只能回总店修改');
  648. }
  649. $shopAdmin = $this->shopAdmin;
  650. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  651. util::fail('超管才能操作');
  652. }
  653. $addData = Yii::$app->request->post('addData', '');
  654. if (empty($addData)) {
  655. util::fail('没有花材');
  656. }
  657. $itemData = json_decode($addData, true);
  658. if (is_array($itemData) == false) {
  659. util::fail('没有花材...');
  660. }
  661. $ids = array_column($itemData, 'id');
  662. $infoList = ProductClass::getByIds($ids, null, 'id');
  663. if (empty($infoList)) {
  664. util::fail('没有花材');
  665. }
  666. foreach ($infoList as $info) {
  667. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  668. util::fail('不是你的花材不能修改');
  669. }
  670. }
  671. //总店修改同步到所有门店
  672. $sjId = $shop->sjId ?? 0;
  673. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  674. foreach ($itemData as $key => $data) {
  675. $id = $data['id'] ?? 0;
  676. unset($data['id']);
  677. ProductClass::updateById($id, $data);
  678. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  679. if (empty($ptItemId)) {
  680. continue;
  681. }
  682. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  683. foreach ($chainShopList as $chainShop) {
  684. $currentMainId = $chainShop->mainId ?? 0;
  685. if ($currentMainId == $shop->mainId) {
  686. //前面已经修改过了,不需要重复修改
  687. continue;
  688. }
  689. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  690. }
  691. }
  692. }
  693. util::complete('修改成功');
  694. }
  695. //批量修改加价 ssh 20211211
  696. public function actionBatchChangeAddPrice()
  697. {
  698. $shop = $this->shop;
  699. $join = $shop->join ?? 0;
  700. $default = $shop->default ?? 0;
  701. if ($join == 0 && $default == 0) {
  702. util::fail('当前直营分店,请切回总店操作');
  703. }
  704. $shopAdmin = $this->shopAdmin;
  705. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  706. util::fail('超管才能操作');
  707. }
  708. $addData = Yii::$app->request->post('addData', '');
  709. if (empty($addData)) {
  710. util::fail('没有花材');
  711. }
  712. $itemData = json_decode($addData, true);
  713. if (is_array($itemData) == false) {
  714. util::fail('没有花材...');
  715. }
  716. $ids = array_column($itemData, 'id');
  717. $infoList = ProductClass::getByIds($ids, null, 'id');
  718. if (empty($infoList)) {
  719. util::fail('没有花材');
  720. }
  721. foreach ($infoList as $info) {
  722. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  723. util::fail('不能修改别人的花材');
  724. }
  725. }
  726. //总店修改同步到所有门店
  727. $sjId = $shop->sjId ?? 0;
  728. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  729. foreach ($itemData as $key => $data) {
  730. $id = $data['id'] ?? 0;
  731. unset($data['id']);
  732. ProductClass::updateById($id, $data);
  733. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  734. if (empty($ptItemId)) {
  735. continue;
  736. }
  737. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  738. foreach ($chainShopList as $chainShop) {
  739. if (isset($chainShop->join) && $chainShop->join == 1) {
  740. continue;
  741. }
  742. $currentMainId = $chainShop->mainId ?? 0;
  743. if ($currentMainId == $shop->mainId) {
  744. //前面已经修改过了,不需要重复修改
  745. continue;
  746. }
  747. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  748. }
  749. }
  750. }
  751. util::complete('修改成功');
  752. }
  753. public function actionUpdate()
  754. {
  755. $shopAdmin = $this->shopAdmin;
  756. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  757. util::fail('超管才能操作');
  758. }
  759. $shop = $this->shop;
  760. $join = $shop->join ?? 0;
  761. $default = $shop->default ?? 0;
  762. if ($join == 0 && $default == 0) {
  763. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  764. if ($shopAdmin->super != 1) {
  765. util::fail('请先开通超管权限');
  766. }
  767. }
  768. $post = Yii::$app->request->post();
  769. $post['adminId'] = $this->adminId;
  770. $post['staffId'] = $this->shopAdmin->id;
  771. $post['staffName'] = $this->shopAdmin->name;
  772. ProductClass::updateProduct($post, $this->shop);
  773. util::complete();
  774. }
  775. //上下架状态控制 ssh 20210713
  776. public function actionStatusUpdate()
  777. {
  778. $post = Yii::$app->request->post();
  779. $shopAdmin = $this->shopAdmin;
  780. $roleId = $shopAdmin['roleId'] ?? 0;
  781. $role = AdminRoleClass::getById($roleId);
  782. $roleName = $role['roleName'] ?? '';
  783. if ($roleName == '员工') {
  784. util::fail('没有权限操作哦');
  785. }
  786. $id = $post['id'] ?? 0;
  787. $status = $post['status'] ?? 1;
  788. $product = ProductClass::getById($id, true);
  789. if ($product->mainId != $this->mainId) {
  790. util::fail('没有权限操作');
  791. }
  792. $product->status = $status;
  793. if ($status == 2) {
  794. $product->discountPrice = 0;
  795. }
  796. $product->save();
  797. util::complete();
  798. }
  799. //花材展示状态控制 ssh 20210804
  800. public function actionDelStatusUpdate()
  801. {
  802. $post = Yii::$app->request->post();
  803. $shop = $this->shop;
  804. $join = $shop->join ?? 0;
  805. $default = $shop->default ?? 0;
  806. if ($join == 0 && $default == 0) {
  807. util::fail('请在首店操作');
  808. }
  809. $shopAdmin = $this->shopAdmin;
  810. $roleId = $shopAdmin['roleId'] ?? 0;
  811. $role = AdminRoleClass::getById($roleId);
  812. $roleName = $role['roleName'] ?? '';
  813. if ($roleName == '员工') {
  814. util::fail('没有权限操作');
  815. }
  816. $id = $post['id'] ?? 0;
  817. $delStatus = $post['delStatus'] ?? 0;
  818. $product = ProductClass::getById($id, true);
  819. if ($product->mainId != $this->mainId) {
  820. util::fail('没有权限操作');
  821. }
  822. $product->delStatus = $delStatus;
  823. $product->save();
  824. $ptItemId = $product->itemId ?? 0;
  825. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  826. //总店修改同步到所有门店
  827. $sjId = $shop->sjId ?? 0;
  828. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  829. foreach ($chainShopList as $chainShop) {
  830. $chainShopId = $chainShop->id ?? 0;
  831. if (isset($chainShop->join) && $chainShop->join == 1) {
  832. continue;
  833. }
  834. if ($chainShopId == $shop->id) {
  835. continue;
  836. }
  837. $chainMainId = $chainShop->mainId ?? 0;
  838. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  839. if (!empty($chainProduct)) {
  840. $chainProduct->delStatus = $delStatus;
  841. $chainProduct->save();
  842. }
  843. }
  844. }
  845. util::complete();
  846. }
  847. //详情 ruidian 2021.5.3
  848. public function actionDetail()
  849. {
  850. $id = Yii::$app->request->get('id', 0);
  851. $respond = ProductClass::getItemInfo($id);
  852. $ptItemId = $respond['itemId'] ?? 0;
  853. $ptItemInfo = PtItemClass::getById($ptItemId);
  854. $respond['ptItemInfo'] = $ptItemInfo;
  855. util::success($respond);
  856. }
  857. //新增花材 2021.6.21
  858. public function actionAdd()
  859. {
  860. $post = Yii::$app->request->post();
  861. $shop = $this->shop;
  862. $join = $shop->join ?? 0;
  863. $default = $shop->default ?? 0;
  864. if ($join == 0 && $default == 0) {
  865. util::fail('当前直营分店,请切回总店添加花材');
  866. }
  867. $shopAdmin = $this->shopAdmin;
  868. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  869. util::fail('管理员才能添加花材');
  870. }
  871. $post['sjId'] = $this->sjId;
  872. $post['adminId'] = $this->adminId;
  873. $post['mainId'] = $this->mainId;
  874. $price = $post['price'] ?? 0;
  875. $addPrice = $post['addPrice'] ?? 0;
  876. if ($addPrice > $price) {
  877. util::fail('加价不能大于售价');
  878. }
  879. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  880. if ($weight <= 0) {
  881. util::fail('请填写重量,最小0.1');
  882. }
  883. $post['staffName'] = $shopAdmin->name ?? '';
  884. ProductClass::addProduct($post, $this->shop);
  885. util::complete('添加成功');
  886. }
  887. //获取拼音缩写 ssh 20210707
  888. public function actionPy()
  889. {
  890. $name = Yii::$app->request->get('name');
  891. $py = stringUtil::py($name);
  892. util::success(['py' => $py]);
  893. }
  894. //(客户端-批发商)复制花材
  895. public function actionClone()
  896. {
  897. $post = Yii::$app->request->post();
  898. $shop = $this->shop;
  899. $join = $shop->join ?? 0;
  900. $default = $shop->default ?? 0;
  901. if ($join == 0 && $default == 0) {
  902. util::fail('请在首店操作');
  903. }
  904. $shopAdmin = $this->shopAdmin;
  905. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  906. util::fail('管理员才能添加花材');
  907. }
  908. $post['sjId'] = $this->sjId;
  909. $post['adminId'] = $this->adminId;
  910. $post['mainId'] = $this->mainId;
  911. $post['staffName'] = $shopAdmin->name ?? '';
  912. $price = $post['price'] ?? 0;
  913. $addPrice = $post['addPrice'] ?? 0;
  914. if ($addPrice > $price) {
  915. util::fail('加价不能大于售价');
  916. }
  917. //复制标识
  918. $post['copy'] = 1;
  919. //去除无用的字段
  920. unset($post['viewNum']);
  921. unset($post['actualSold']);
  922. unset($post['itemId']);
  923. unset($post['id']);
  924. unset($post['delStatus']);
  925. ProductClass::addProduct($post, $this->shop);
  926. util::complete('复制成功');
  927. }
  928. //下载价格表 ssh 20210922
  929. public function actionGeneratePriceTable()
  930. {
  931. $level = Yii::$app->request->get('level', 0);
  932. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  933. $file = $respond['file'] ?? '';
  934. $shortFile = $respond['shortFile'] ?? '';
  935. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  936. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  937. }
  938. public function actionGenerateItemTable()
  939. {
  940. $level = Yii::$app->request->get('level', 0);
  941. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  942. $file = $respond['file'] ?? '';
  943. $shortFile = $respond['shortFile'] ?? '';
  944. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  945. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  946. }
  947. //下载条形码 lqh 20211227
  948. public function actionGenerateBarcodeTable()
  949. {
  950. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  951. $file = $respond['file'] ?? '';
  952. $shortFile = $respond['shortFile'] ?? '';
  953. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  954. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  955. }
  956. //批量修改花材的分类 ssh 20230405
  957. public function actionBatchModifyClass()
  958. {
  959. $post = Yii::$app->request->post();
  960. $shop = $this->shop;
  961. $join = $shop->join ?? 0;
  962. $default = $shop->default ?? 0;
  963. if ($join == 0 && $default == 0) {
  964. util::fail('当前直营分店,请切回总店操作');
  965. }
  966. $classId = $post['classId'] ?? 0;
  967. $class = ItemClassClass::getById($classId, true);
  968. if (empty($class) || $class->mainId != $this->mainId) {
  969. util::fail('请选择您自己的分类');
  970. }
  971. $connection = Yii::$app->db;
  972. $transaction = $connection->beginTransaction();
  973. try {
  974. $className = $class->name ?? '';
  975. $idsList = $post['ids'] ?? '';
  976. $ids = json_decode($idsList, true);
  977. if (empty($ids)) {
  978. util::fail('请选择花材');
  979. }
  980. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  981. if (empty($list)) {
  982. util::fail('请选择花材');
  983. }
  984. $ptItemList = [];
  985. foreach ($list as $item) {
  986. $name = $item->name ?? '';
  987. if ($item->mainId != $this->mainId) {
  988. util::fail($name . '不是您的花材');
  989. }
  990. $item->classId = $classId;
  991. $item->save();
  992. $ptItemId = $item->itemId ?? 0;
  993. $ptItemList[] = $ptItemId;
  994. }
  995. $shop = $this->shop;
  996. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  997. //总店修改同步到所有门店
  998. $sjId = $shop->sjId ?? 0;
  999. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1000. foreach ($chainShopList as $chainShop) {
  1001. $chainShopId = $chainShop->id ?? 0;
  1002. if ($chainShopId == $shop->id) {
  1003. continue;
  1004. }
  1005. $chainManId = $chainShop->mainId ?? 0;
  1006. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1007. if (!empty($chainAllClassList)) {
  1008. foreach ($chainAllClassList as $chainClass) {
  1009. $chainName = $chainClass->name ?? '';
  1010. $chainClassId = $chainClass->id ?? 0;
  1011. if ($chainName == $className) {
  1012. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1013. if (!empty($chainProductList)) {
  1014. foreach ($chainProductList as $currentProduct) {
  1015. $currentProduct->classId = $chainClassId;
  1016. $currentProduct->save();
  1017. }
  1018. }
  1019. }
  1020. }
  1021. }
  1022. }
  1023. }
  1024. $transaction->commit();
  1025. util::complete('修改成功');
  1026. } catch (\Exception $e) {
  1027. $transaction->rollBack();
  1028. Yii::info("修改失败原因:" . $e->getMessage());
  1029. util::fail('修改失败');
  1030. }
  1031. }
  1032. }