ProductController.php 47 KB

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