ProductController.php 48 KB

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