ProductController.php 49 KB

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