ProductController.php 45 KB

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