ProductController.php 48 KB

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