ProductController.php 47 KB

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