ProductController.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  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,hjAddPrice,skPrice,discountPrice,skMore,variety,price,hjPrice,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,hjPrice,hjAddPrice,addPrice,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. $post = Yii::$app->request->post();
  525. $data = $post['data'] ?? '';
  526. if (empty($data)) {
  527. util::fail('没有修改');
  528. }
  529. $arr = json_decode($data, true);
  530. if (empty($arr)) {
  531. util::fail('没有修改哦');
  532. }
  533. $appVersion = $post['appVersion'] ?? 0;
  534. if ($appVersion != 1) {
  535. util::fail('请先升级应用');
  536. }
  537. $connection = Yii::$app->db;
  538. $transaction = $connection->beginTransaction();
  539. try {
  540. $cg = PurchaseOrderClass::getLockById($targetId);
  541. if (!empty($cg)) {
  542. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  543. util::fail('不是您的采购单');
  544. }
  545. //批量改价同时入库
  546. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  547. $staff = $this->shopAdmin;
  548. $data = [];
  549. $data['staffId'] = $staff->id ?? 0;
  550. $data['staffName'] = $staff->name ?? '';
  551. $data['adminId'] = $this->adminId ?? 0;
  552. PurchaseOrderClass::putIn($cg, $data);
  553. }
  554. }
  555. $ids = array_column($arr, 'id');
  556. $ids = array_unique(array_filter($ids));
  557. if (empty($ids)) {
  558. util::fail('请选择花材');
  559. }
  560. $sjId = $shop->sjId ?? 0;
  561. $chainShopList = [];
  562. if ($default == 1) {
  563. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  564. }
  565. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  566. foreach ($arr as $product) {
  567. $productId = $product['id'];
  568. $productInfo = $productList[$productId] ?? [];
  569. if (empty($productInfo)) {
  570. util::fail('没有找到花材');
  571. }
  572. $productName = $productInfo->name ?? '';
  573. if (isset($product['id']) == false) {
  574. util::fail('没有花材');
  575. }
  576. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  577. util::fail('请填写' . $productName . '的批发价');
  578. }
  579. $price = $product['price'];
  580. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  581. util::fail('请填写' . $productName . '的零售价');
  582. }
  583. $skPrice = $product['skPrice'];
  584. if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
  585. util::fail('请填写' . $productName . '的会员价');
  586. }
  587. $hjPrice = $product['hjPrice'] ?? 0;
  588. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  589. util::fail('没有权限访问');
  590. }
  591. if (empty($price)) {
  592. continue;
  593. }
  594. $ptItemId = $productInfo->itemId;
  595. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  596. //在首店修改需要同步到所有直营店
  597. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  598. foreach ($chainShopList as $chain) {
  599. if ($chain->id == $shop->id) {
  600. continue;
  601. }
  602. $chainMainId = $chain->mainId ?? 0;
  603. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  604. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  605. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  606. }
  607. }
  608. }
  609. $mainId = $shop->mainId ?? 0;
  610. if (!empty($mainId)) {
  611. //提醒零售收银台界面要刷新
  612. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  613. if (!empty($staffList)) {
  614. foreach ($staffList as $staff) {
  615. $staffId = $staff->id ?? 0;
  616. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  617. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  618. }
  619. }
  620. }
  621. $transaction->commit();
  622. util::complete('操作成功');
  623. } catch (\Exception $e) {
  624. $transaction->rollBack();
  625. Yii::info("修改失败原因:" . $e->getMessage());
  626. util::fail('修改失败');
  627. }
  628. }
  629. //改价
  630. public function actionChangePrice()
  631. {
  632. $shopAdmin = $this->shopAdmin;
  633. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  634. util::fail('超管才能修改');
  635. }
  636. $productId = Yii::$app->request->post('productId', 0);
  637. $productInfo = ProductClass::getById($productId, true);
  638. if (empty($productInfo)) {
  639. util::fail("花材不存在");
  640. }
  641. if ($productInfo->mainId != $this->mainId) {
  642. util::fail('没有权限');
  643. }
  644. $price = Yii::$app->request->post('price', '');
  645. if (is_numeric($price) && $price > 0) {
  646. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  647. } else {
  648. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  649. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  650. }
  651. util::success(['price' => $price]);
  652. }
  653. //恢复自动调价
  654. public function actionAutoPrice()
  655. {
  656. $productId = Yii::$app->request->post('productId', 0);
  657. $productData = ProductClass::getById($productId);
  658. if (!$productData) {
  659. util::fail("花材不存在");
  660. }
  661. //2021.04.06改为用product中的成本价+加价
  662. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  663. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  664. util::complete("操作成功");
  665. }
  666. //修改加价
  667. public function actionChangeAddPrice()
  668. {
  669. $productId = Yii::$app->request->post('productId', 0);
  670. $addPrice = Yii::$app->request->post('addPrice', '');
  671. if ($addPrice < 0) {
  672. util::fail("加价不能小于0");
  673. }
  674. $productData = ProductClass::getProductData($productId, $this->mainId);
  675. if (!$productData) {
  676. util::fail("花材不存在");
  677. }
  678. ProductClass::changeAddPrice($productId, $addPrice);
  679. util::complete();
  680. }
  681. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  682. public function actionBatchChangeMore()
  683. {
  684. $shop = $this->shop;
  685. $default = $shop->default ?? 0;
  686. if ($default == 0) {
  687. util::fail('当前直营分店,请返回总店修改');
  688. }
  689. $shopAdmin = $this->shopAdmin;
  690. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  691. util::fail('超管才能操作');
  692. }
  693. $addData = Yii::$app->request->post('addData', '');
  694. if (empty($addData)) {
  695. util::fail('没有花材');
  696. }
  697. $itemData = json_decode($addData, true);
  698. if (is_array($itemData) == false) {
  699. util::fail('没有花材...');
  700. }
  701. $ids = array_column($itemData, 'id');
  702. $infoList = ProductClass::getByIds($ids, null, 'id');
  703. if (empty($infoList)) {
  704. util::fail('没有花材');
  705. }
  706. foreach ($infoList as $info) {
  707. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  708. util::fail('不是你的花材不能修改');
  709. }
  710. }
  711. //总店修改同步到所有门店
  712. $sjId = $shop->sjId ?? 0;
  713. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  714. foreach ($itemData as $key => $data) {
  715. $id = $data['id'] ?? 0;
  716. unset($data['id']);
  717. ProductClass::updateById($id, $data);
  718. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  719. if (empty($ptItemId)) {
  720. continue;
  721. }
  722. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  723. foreach ($chainShopList as $chainShop) {
  724. $currentMainId = $chainShop->mainId ?? 0;
  725. if ($currentMainId == $shop->mainId) {
  726. //前面已经修改过了,不需要重复修改
  727. continue;
  728. }
  729. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  730. }
  731. }
  732. }
  733. util::complete('修改成功');
  734. }
  735. //批量修改加价 ssh 20211211
  736. public function actionBatchChangeAddPrice()
  737. {
  738. $shop = $this->shop;
  739. $join = $shop->join ?? 0;
  740. $default = $shop->default ?? 0;
  741. if ($join == 0 && $default == 0) {
  742. util::fail('当前直营分店,请切回总店操作');
  743. }
  744. $shopAdmin = $this->shopAdmin;
  745. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  746. util::fail('超管才能操作');
  747. }
  748. $post = Yii::$app->request->post();
  749. $addData = $post['addData'] ?? '';
  750. if (empty($addData)) {
  751. util::fail('没有花材');
  752. }
  753. $itemData = json_decode($addData, true);
  754. if (is_array($itemData) == false) {
  755. util::fail('没有花材...');
  756. }
  757. $ids = array_column($itemData, 'id');
  758. $infoList = ProductClass::getByIds($ids, null, 'id');
  759. if (empty($infoList)) {
  760. util::fail('没有花材');
  761. }
  762. foreach ($infoList as $info) {
  763. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  764. util::fail('不能修改别人的花材');
  765. }
  766. }
  767. $appVersion = $post['appVersion'] ?? 0;
  768. if ($appVersion != 1) {
  769. util::fail('请先升级应用');
  770. }
  771. //总店修改同步到所有门店
  772. $sjId = $shop->sjId ?? 0;
  773. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  774. foreach ($itemData as $key => $data) {
  775. $id = $data['id'] ?? 0;
  776. unset($data['id']);
  777. ProductClass::updateById($id, $data);
  778. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  779. if (empty($ptItemId)) {
  780. continue;
  781. }
  782. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  783. foreach ($chainShopList as $chainShop) {
  784. if (isset($chainShop->join) && $chainShop->join == 1) {
  785. continue;
  786. }
  787. $currentMainId = $chainShop->mainId ?? 0;
  788. if ($currentMainId == $shop->mainId) {
  789. //前面已经修改过了,不需要重复修改
  790. continue;
  791. }
  792. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  793. }
  794. }
  795. }
  796. util::complete('修改成功');
  797. }
  798. public function actionUpdate()
  799. {
  800. $shopAdmin = $this->shopAdmin;
  801. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  802. util::fail('超管才能操作');
  803. }
  804. $shop = $this->shop;
  805. $join = $shop->join ?? 0;
  806. $default = $shop->default ?? 0;
  807. if ($join == 0 && $default == 0) {
  808. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  809. if ($shopAdmin->super != 1) {
  810. util::fail('请先开通超管权限');
  811. }
  812. }
  813. $post = Yii::$app->request->post();
  814. $appVersion = $post['appVersion'] ?? 0;
  815. if ($appVersion != 1) {
  816. util::fail('请先升级应用');
  817. }
  818. $post['adminId'] = $this->adminId;
  819. $post['staffId'] = $this->shopAdmin->id;
  820. $post['staffName'] = $this->shopAdmin->name;
  821. ProductClass::updateProduct($post, $this->shop);
  822. util::complete();
  823. }
  824. //上下架状态控制 ssh 20210713
  825. public function actionStatusUpdate()
  826. {
  827. $post = Yii::$app->request->post();
  828. $shopAdmin = $this->shopAdmin;
  829. $roleId = $shopAdmin['roleId'] ?? 0;
  830. $role = AdminRoleClass::getById($roleId);
  831. $roleName = $role['roleName'] ?? '';
  832. if ($roleName == '员工') {
  833. util::fail('没有权限操作哦');
  834. }
  835. $id = $post['id'] ?? 0;
  836. $status = $post['status'] ?? 1;
  837. $product = ProductClass::getById($id, true);
  838. if ($product->mainId != $this->mainId) {
  839. util::fail('没有权限操作');
  840. }
  841. $product->status = $status;
  842. if ($status == 2) {
  843. $product->discountPrice = 0;
  844. }
  845. $product->save();
  846. util::complete();
  847. }
  848. //花材展示状态控制 ssh 20210804
  849. public function actionDelStatusUpdate()
  850. {
  851. $post = Yii::$app->request->post();
  852. $shop = $this->shop;
  853. $join = $shop->join ?? 0;
  854. $default = $shop->default ?? 0;
  855. if ($join == 0 && $default == 0) {
  856. util::fail('请在首店操作');
  857. }
  858. $shopAdmin = $this->shopAdmin;
  859. $roleId = $shopAdmin['roleId'] ?? 0;
  860. $role = AdminRoleClass::getById($roleId);
  861. $roleName = $role['roleName'] ?? '';
  862. if ($roleName == '员工') {
  863. util::fail('没有权限操作');
  864. }
  865. $id = $post['id'] ?? 0;
  866. $delStatus = $post['delStatus'] ?? 0;
  867. $product = ProductClass::getById($id, true);
  868. if ($product->mainId != $this->mainId) {
  869. util::fail('没有权限操作');
  870. }
  871. $product->delStatus = $delStatus;
  872. $product->save();
  873. $ptItemId = $product->itemId ?? 0;
  874. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  875. //总店修改同步到所有门店
  876. $sjId = $shop->sjId ?? 0;
  877. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  878. foreach ($chainShopList as $chainShop) {
  879. $chainShopId = $chainShop->id ?? 0;
  880. if (isset($chainShop->join) && $chainShop->join == 1) {
  881. continue;
  882. }
  883. if ($chainShopId == $shop->id) {
  884. continue;
  885. }
  886. $chainMainId = $chainShop->mainId ?? 0;
  887. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  888. if (!empty($chainProduct)) {
  889. $chainProduct->delStatus = $delStatus;
  890. $chainProduct->save();
  891. }
  892. }
  893. }
  894. util::complete();
  895. }
  896. //详情 ruidian 2021.5.3
  897. public function actionDetail()
  898. {
  899. $id = Yii::$app->request->get('id', 0);
  900. $respond = ProductClass::getItemInfo($id);
  901. $ptItemId = $respond['itemId'] ?? 0;
  902. $ptItemInfo = PtItemClass::getById($ptItemId);
  903. $respond['ptItemInfo'] = $ptItemInfo;
  904. util::success($respond);
  905. }
  906. //新增花材 2021.6.21
  907. public function actionAdd()
  908. {
  909. $post = Yii::$app->request->post();
  910. $appVersion = $post['appVersion'] ?? 0;
  911. if ($appVersion != 1) {
  912. util::fail('请先升级应用');
  913. }
  914. $shop = $this->shop;
  915. $join = $shop->join ?? 0;
  916. $default = $shop->default ?? 0;
  917. if ($join == 0 && $default == 0) {
  918. util::fail('当前直营分店,请切回总店添加花材');
  919. }
  920. $shopAdmin = $this->shopAdmin;
  921. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  922. util::fail('管理员才能添加花材');
  923. }
  924. $post['sjId'] = $this->sjId;
  925. $post['adminId'] = $this->adminId;
  926. $post['mainId'] = $this->mainId;
  927. $price = $post['price'] ?? 0;
  928. $addPrice = $post['addPrice'] ?? 0;
  929. if ($addPrice > $price) {
  930. util::fail('加价不能大于售价');
  931. }
  932. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  933. if ($weight <= 0) {
  934. util::fail('请填写重量,最小0.1');
  935. }
  936. $post['staffName'] = $shopAdmin->name ?? '';
  937. ProductClass::addProduct($post, $this->shop);
  938. util::complete('添加成功');
  939. }
  940. //获取拼音缩写 ssh 20210707
  941. public function actionPy()
  942. {
  943. $name = Yii::$app->request->get('name');
  944. $py = stringUtil::py($name);
  945. util::success(['py' => $py]);
  946. }
  947. //(客户端-批发商)复制花材
  948. public function actionClone()
  949. {
  950. $post = Yii::$app->request->post();
  951. $appVersion = $post['appVersion'] ?? 0;
  952. if ($appVersion != 1) {
  953. util::fail('请先升级应用');
  954. }
  955. $shop = $this->shop;
  956. $join = $shop->join ?? 0;
  957. $default = $shop->default ?? 0;
  958. if ($join == 0 && $default == 0) {
  959. util::fail('请在首店操作');
  960. }
  961. $shopAdmin = $this->shopAdmin;
  962. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  963. util::fail('管理员才能添加花材');
  964. }
  965. $post['sjId'] = $this->sjId;
  966. $post['adminId'] = $this->adminId;
  967. $post['mainId'] = $this->mainId;
  968. $post['staffName'] = $shopAdmin->name ?? '';
  969. $price = $post['price'] ?? 0;
  970. if (empty($price) || $price <= 0) {
  971. util::fail('请填写批发价');
  972. }
  973. $skPrice = $post['skPrice'] ?? 0;
  974. if (empty($skPrice) || $skPrice <= 0) {
  975. util::fail('请填写零售价');
  976. }
  977. $hjPrice = $post['hjPrice'] ?? 0;
  978. if (empty($hjPrice) || $hjPrice <= 0) {
  979. util::fail('请填写会员价');
  980. }
  981. $addPrice = $post['addPrice'] ?? 0;
  982. if ($addPrice > $price) {
  983. util::fail('批发价的加价不能大于售价');
  984. }
  985. //复制标识
  986. $post['copy'] = 1;
  987. //去除无用的字段
  988. unset($post['viewNum']);
  989. unset($post['actualSold']);
  990. unset($post['itemId']);
  991. unset($post['id']);
  992. unset($post['delStatus']);
  993. ProductClass::addProduct($post, $this->shop);
  994. util::complete('复制成功');
  995. }
  996. //下载价格表 ssh 20210922
  997. public function actionGeneratePriceTable()
  998. {
  999. $level = Yii::$app->request->get('level', 0);
  1000. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1001. $file = $respond['file'] ?? '';
  1002. $shortFile = $respond['shortFile'] ?? '';
  1003. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1004. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1005. }
  1006. public function actionGenerateItemTable()
  1007. {
  1008. $level = Yii::$app->request->get('level', 0);
  1009. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  1010. $file = $respond['file'] ?? '';
  1011. $shortFile = $respond['shortFile'] ?? '';
  1012. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1013. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1014. }
  1015. //下载条形码 lqh 20211227
  1016. public function actionGenerateBarcodeTable()
  1017. {
  1018. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1019. $file = $respond['file'] ?? '';
  1020. $shortFile = $respond['shortFile'] ?? '';
  1021. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1022. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1023. }
  1024. //批量修改花材的分类 ssh 20230405
  1025. public function actionBatchModifyClass()
  1026. {
  1027. $post = Yii::$app->request->post();
  1028. $shop = $this->shop;
  1029. $join = $shop->join ?? 0;
  1030. $default = $shop->default ?? 0;
  1031. if ($join == 0 && $default == 0) {
  1032. util::fail('当前直营分店,请切回总店操作');
  1033. }
  1034. $classId = $post['classId'] ?? 0;
  1035. $class = ItemClassClass::getById($classId, true);
  1036. if (empty($class) || $class->mainId != $this->mainId) {
  1037. util::fail('请选择您自己的分类');
  1038. }
  1039. $connection = Yii::$app->db;
  1040. $transaction = $connection->beginTransaction();
  1041. try {
  1042. $className = $class->name ?? '';
  1043. $idsList = $post['ids'] ?? '';
  1044. $ids = json_decode($idsList, true);
  1045. if (empty($ids)) {
  1046. util::fail('请选择花材');
  1047. }
  1048. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1049. if (empty($list)) {
  1050. util::fail('请选择花材');
  1051. }
  1052. $ptItemList = [];
  1053. foreach ($list as $item) {
  1054. $name = $item->name ?? '';
  1055. if ($item->mainId != $this->mainId) {
  1056. util::fail($name . '不是您的花材');
  1057. }
  1058. $item->classId = $classId;
  1059. $item->save();
  1060. $ptItemId = $item->itemId ?? 0;
  1061. $ptItemList[] = $ptItemId;
  1062. }
  1063. $shop = $this->shop;
  1064. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1065. //总店修改同步到所有门店
  1066. $sjId = $shop->sjId ?? 0;
  1067. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1068. foreach ($chainShopList as $chainShop) {
  1069. $chainShopId = $chainShop->id ?? 0;
  1070. if ($chainShopId == $shop->id) {
  1071. continue;
  1072. }
  1073. $chainManId = $chainShop->mainId ?? 0;
  1074. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1075. if (!empty($chainAllClassList)) {
  1076. foreach ($chainAllClassList as $chainClass) {
  1077. $chainName = $chainClass->name ?? '';
  1078. $chainClassId = $chainClass->id ?? 0;
  1079. if ($chainName == $className) {
  1080. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1081. if (!empty($chainProductList)) {
  1082. foreach ($chainProductList as $currentProduct) {
  1083. $currentProduct->classId = $chainClassId;
  1084. $currentProduct->save();
  1085. }
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. }
  1092. $transaction->commit();
  1093. util::complete('修改成功');
  1094. } catch (\Exception $e) {
  1095. $transaction->rollBack();
  1096. Yii::info("修改失败原因:" . $e->getMessage());
  1097. util::fail('修改失败');
  1098. }
  1099. }
  1100. }