ProductController.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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\ItemClassClass;
  11. use bizGhs\merchant\classes\ShopClass;
  12. use bizGhs\order\classes\PurchaseOrderClass;
  13. use bizGhs\product\classes\ProductClass;
  14. use bizGhs\product\models\Product;
  15. use bizGhs\product\services\ProductService;
  16. use bizGhs\shop\classes\ShopAdminClass;
  17. use bizGhs\stock\classes\StockInDayClass;
  18. use common\components\printUtil;
  19. use common\components\stringUtil;
  20. use common\components\util;
  21. use Yii;
  22. class ProductController extends BaseController
  23. {
  24. public $guestAccess = ['index'];
  25. //停止预售 ssh 20230224
  26. public function actionCancelPreSell()
  27. {
  28. $get = Yii::$app->request->get();
  29. $id = $get['id'] ?? 0;
  30. $info = ProductClass::getById($id, true);
  31. ProductClass::check($info, $this->mainId);
  32. if ($info->stock > 0) {
  33. util::fail('没有库存才能停止预售');
  34. }
  35. $info->presell = 0;
  36. $info->presellDate = '';
  37. $info->save();
  38. util::complete();
  39. }
  40. //修改预售 ssh 20221214
  41. public function actionChangePresell()
  42. {
  43. $post = Yii::$app->request->post();
  44. $id = $post['id'] ?? 0;
  45. $info = ProductClass::getById($id, true);
  46. ProductClass::check($info, $this->mainId);
  47. $str = $post['date'] ?? '';
  48. $presell = $post['presell'] ?? 0;
  49. $newStr = '';
  50. if ($presell == 1) {
  51. if (empty($str)) {
  52. util::fail('请填写预售日期');
  53. }
  54. $arr = json_decode($str, true);
  55. if (empty($arr)) {
  56. util::fail('请填写预售日期');
  57. }
  58. $new = [];
  59. foreach ($arr as $date) {
  60. $new[] = strtotime($date);
  61. }
  62. $new = array_unique(array_filter($new));
  63. asort($new);
  64. $newStr = implode(',', $new);
  65. }
  66. $info->presell = $presell;
  67. $info->presellDate = $newStr;
  68. $info->discountPrice = 0;
  69. $info->save();
  70. util::complete();
  71. }
  72. //取消特价 ssh 20220901
  73. public function actionCancelDiscount()
  74. {
  75. $get = Yii::$app->request->get();
  76. $id = $get['id'] ?? 0;
  77. $info = ProductClass::getById($id, true);
  78. ProductClass::check($info, $this->mainId);
  79. $info->discountPrice = 0;
  80. $info->save();
  81. util::complete();
  82. }
  83. //打印花材的标签 ssh 20220602
  84. public function actionPrint()
  85. {
  86. $get = Yii::$app->request->get();
  87. $id = $get['id'] ?? 0;
  88. $num = $get['num'] ?? 1;
  89. $info = ProductClass::getById($id, true);
  90. if (empty($info)) {
  91. util::fail('没有找到花材');
  92. }
  93. $name = $info->name ?? '';
  94. $ptItemId = $info->itemId ?? 0;
  95. $mainId = $info->mainId ?? 0;
  96. $ext = $this->shopExt;
  97. $printLabelSn = $ext->printLabelSn ?? '';
  98. if (empty($printLabelSn)) {
  99. util::fail('请设置标签打印机');
  100. }
  101. $p = new printUtil($printLabelSn);
  102. $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
  103. $p->times = $num;
  104. $content = '<TEXT x="360" y="30" font="12" w="2" h="2" r="90">' . $name . '</TEXT>';
  105. $content .= '<BC128 x="260" y="30" h="70" s="1" r="90" n="4" w="11">' . $ptItemId . '</BC128>';
  106. if (in_array($mainId, [52, 1459])) {
  107. $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">惠雅鲜花</TEXT>';
  108. } else {
  109. $content .= '<TEXT x="80" y="30" font="12" w="2" h="2" r="90">' . $unit . '</TEXT>';
  110. }
  111. //$content .= '<QR x="30" y="390" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  112. //$content .= '<TEXT x="220" y="400" font="12" w="1" h="1" r="90">扫码看价格</TEXT>';
  113. $p->printLabelMsg($content);
  114. util::complete();
  115. }
  116. //取出今天有入库的花材 ssh 20221024
  117. public function actionStockIn()
  118. {
  119. $py = Yii::$app->request->get('py', '');
  120. $version = Yii::$app->request->get('version', 0);
  121. if ($version == 0) {
  122. util::fail('请先升级版本到1.0.70以上');
  123. }
  124. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  125. $mainId = $this->mainId ?? 0;
  126. $where['mainId'] = $mainId;
  127. if ($py) {
  128. $pyName = strtolower($py);
  129. $where['py'] = $pyName;
  130. }
  131. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  132. if (empty($arr)) {
  133. util::fail('没有花材需要盘点');
  134. }
  135. $ids = array_column($arr, 'itemId');
  136. $ids = array_unique($ids);
  137. $where['id'] = ['in', $ids];
  138. $level = 1;
  139. $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';
  140. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  141. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  142. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  143. util::success($data);
  144. }
  145. //按分类列出所有花材
  146. public function actionShow()
  147. {
  148. $py = Yii::$app->request->get('py', '');
  149. $requestType = Yii::$app->request->get('requestType', 'common');
  150. //默认显示上架商品
  151. $status = Yii::$app->request->get('status', 1);
  152. //默认显示未删除商品
  153. $delStatus = Yii::$app->request->get('delStatus', 0);
  154. //获取所有当前供货商的分类 (全部、常用)
  155. //根据分类组装分类下的花材信息
  156. //中央ID
  157. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  158. $where['mainId'] = $this->mainId;
  159. if ($py) {
  160. $pyName = strtolower($py);
  161. $where['py'] = $pyName;
  162. }
  163. //改价和全部有库存花材列表
  164. if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
  165. $where['stock>'] = 0;
  166. }
  167. if (!empty($status)) {
  168. $where['status'] = $status;
  169. }
  170. $where['delStatus'] = $delStatus;
  171. //客户等级
  172. $customId = Yii::$app->request->get('customId', 0);
  173. $level = 1;
  174. if (!empty($customId)) {
  175. $custom = CustomClass::getById($customId, true);
  176. $level = $custom->level ?? 1;
  177. }
  178. $itemInfoData = [];
  179. if ($requestType == 'hasStockList') {
  180. //有库存的花材列表
  181. $field = 'id,py,name,classId,itemId,price,skPrice,stock';
  182. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  183. } elseif ($requestType == 'changePrice') {
  184. //修改价格列表
  185. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,presell';
  186. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  187. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  188. } elseif ($requestType == 'kd') {
  189. //开单的花材列表
  190. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio';
  191. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  192. $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level);
  193. } elseif ($requestType == 'itemList') {
  194. //花材列表
  195. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,skMore,stock,actualSold,stockWarning,status,presell';
  196. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  197. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  198. } elseif ($requestType == 'outList') {
  199. //下架花材列表
  200. $where['status'] = 2;
  201. $where['delStatus'] = 0;
  202. $where['removeStatus'] = 0;
  203. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,presell,status';
  204. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  205. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  206. } elseif ($requestType == 'stopList') {
  207. //停用花材列表
  208. $where['status'] = 2;
  209. $where['delStatus'] = 1;
  210. $where['removeStatus'] = 0;
  211. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,presell,status';
  212. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  213. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  214. } elseif ($requestType == 'removeList') {
  215. //删除花材列表
  216. $where['status'] = 2;
  217. $where['delStatus'] = 1;
  218. $where['removeStatus'] = 1;
  219. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,presell,status';
  220. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  221. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  222. } elseif ($requestType == 'check') {
  223. //盘点花材列表
  224. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  225. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  226. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  227. } elseif ($requestType == 'break') {
  228. //报损花材
  229. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  230. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  231. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  232. } elseif ($requestType == 'part') {
  233. //报损花材
  234. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  235. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  236. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  237. } elseif ($requestType == 'stockOut') {
  238. //出库花材
  239. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio';
  240. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  241. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  242. } elseif ($requestType == 'cg') {
  243. //采购花材
  244. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight';
  245. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  246. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  247. } elseif ($requestType == 'warning') {
  248. //库存预警
  249. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,actualSold,presell,bigUnit,stockWarning,status';
  250. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  251. ->andWhere('`stock`<`stockWarning`')
  252. ->andWhere("delStatus=0")
  253. ->select($field)->asArray()->all();
  254. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  255. } else {
  256. util::fail('没有数据');
  257. }
  258. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  259. util::success($data);
  260. }
  261. //取出今天有入库的花材 ssh 20221224
  262. public function actionGetStockIn()
  263. {
  264. $py = Yii::$app->request->get('py', '');
  265. $version = Yii::$app->request->get('version', 0);
  266. if ($version == 0) {
  267. util::fail('请先升级版本到1.0.70以上');
  268. }
  269. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  270. $mainId = $this->mainId ?? 0;
  271. $where['mainId'] = $mainId;
  272. if ($py) {
  273. $pyName = strtolower($py);
  274. $where['py'] = $pyName;
  275. }
  276. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  277. if (empty($arr)) {
  278. util::fail('没有花材需要盘点');
  279. }
  280. $ids = array_column($arr, 'itemId');
  281. $ids = array_unique($ids);
  282. $where['id'] = ['in', $ids];
  283. $level = 1;
  284. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  285. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  286. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  287. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  288. util::success($data);
  289. }
  290. //按分类列出所有花材
  291. public function actionIndex()
  292. {
  293. $py = Yii::$app->request->get('py', '');
  294. $requestType = Yii::$app->request->get('requestType', 'common');
  295. //默认显示上架商品
  296. $status = Yii::$app->request->get('status', 1);
  297. //默认显示未删除商品
  298. $delStatus = Yii::$app->request->get('delStatus', 0);
  299. $warning = Yii::$app->request->get('warning', 0);
  300. //获取所有当前供货商的分类 (全部、常用)
  301. //根据分类组装分类下的花材信息
  302. //中央ID
  303. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  304. $where['mainId'] = $this->mainId;
  305. if ($py) {
  306. $pyName = strtolower($py);
  307. $where['py'] = $pyName;
  308. }
  309. if ($requestType == 'hasStock') {
  310. //改价只显示库存大于0的
  311. $where['stock>'] = 0;
  312. }
  313. if (!empty($status)) {
  314. $where['status'] = $status;
  315. }
  316. $where['delStatus'] = $delStatus;
  317. //客户等级
  318. $customId = Yii::$app->request->get('customId', 0);
  319. $level = 1;
  320. if (!empty($customId)) {
  321. $custom = CustomClass::getById($customId, true);
  322. $level = $custom->level ?? 1;
  323. }
  324. if ($warning == 1) {
  325. //库存预警
  326. $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';
  327. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  328. ->andWhere('`stock`<`stockWarning`')
  329. ->andWhere("delStatus=0")
  330. ->select($field)->asArray()->all();
  331. } else {
  332. $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';
  333. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  334. }
  335. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  336. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  337. util::success($data);
  338. }
  339. //所有花材分页和不分页
  340. public function actionList()
  341. {
  342. $where = [];
  343. $classId = Yii::$app->request->get('classId', 0);
  344. if (!empty($classId)) {
  345. $where['classId'] = $classId;
  346. }
  347. $name = Yii::$app->request->get('name', '');
  348. if (empty($name)) {
  349. $py = Yii::$app->request->get('py', '');
  350. $name = !empty($py) ? $py : '';
  351. }
  352. if (!empty($name)) {
  353. if (stringUtil::isLetter($name)) {
  354. $where['py'] = ['like', $name];
  355. } else {
  356. $where['name'] = ['like', $name];
  357. }
  358. }
  359. $status = Yii::$app->request->get('status', 0);
  360. if (!empty($status)) {
  361. $where['status'] = $status;
  362. }
  363. $delStatus = Yii::$app->request->get('delStatus', 0);
  364. if ($delStatus != 2) {
  365. $where['delStatus'] = $delStatus;
  366. }
  367. $where['mainId'] = $this->mainId;
  368. $productIds = Yii::$app->request->get('ids', '');
  369. if (!empty($productIds)) {
  370. $productIdArr = explode(',', $productIds);
  371. if (!empty($productIdArr)) {
  372. $where['id'] = ['in', $productIdArr];
  373. }
  374. }
  375. //输出标准会员价,即花店价,默认显示的是花店价
  376. $level = 1;
  377. $type = Yii::$app->request->get('type', '');
  378. $showPage = Yii::$app->request->get('showPage', 0);
  379. if ($showPage) {
  380. if ($type == 'waring') {
  381. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  382. $lackIds = array_column($pro, 'id');
  383. if (empty($lackIds)) {
  384. util::success([]);
  385. }
  386. $lackIds = array_filter(array_unique($lackIds));
  387. $where['id'] = ['in', $lackIds];
  388. $respond = ProductClass::getList("*", $where, "actualSold desc");
  389. } else {
  390. $respond = ProductClass::getList("*", $where, "inTurn desc");
  391. }
  392. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  393. $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
  394. util::success($respond);
  395. } else {
  396. if ($type == 'waring') {
  397. //库存预警 按库存从小到大排序
  398. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  399. } else {
  400. if (!empty($productIds)) {
  401. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  402. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  403. } else {
  404. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  405. }
  406. }
  407. $data = ProductClass::groupProductInfo($data, $level);
  408. $data = ProductClass::groupClassName($this->sjId, $data);
  409. if ($type == 'waring') {
  410. //库存预警
  411. $newData = [];
  412. foreach ($data as $v) {
  413. if ($v['stock'] <= $v['stockWarning']) {
  414. $newData[] = $v;
  415. }
  416. }
  417. util::success(['list' => $newData]);
  418. }
  419. util::success(['list' => $data]);
  420. }
  421. }
  422. //所有花材
  423. public function actionAll()
  424. {
  425. $where = [];
  426. $where['mainId'] = $this->mainId;
  427. $classId = Yii::$app->request->get('classId', 0);
  428. if (!empty($classId)) {
  429. $where['classId'] = $classId;
  430. }
  431. $status = Yii::$app->request->get('status', 0);
  432. if (!empty($status)) {
  433. $where['status'] = $status;
  434. }
  435. $delStatus = Yii::$app->request->get('delStatus', 0);
  436. if ($delStatus != 2) {
  437. $where['delStatus'] = $delStatus;
  438. }
  439. //输出标准会员价,即花店价,默认显示的是花店价
  440. $level = 1;
  441. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  442. $data = ProductClass::groupProductInfo($data, $level);
  443. util::success(['list' => $data]);
  444. }
  445. //批量改价
  446. public function actionBatchChangePrice()
  447. {
  448. $shop = $this->shop;
  449. $join = $shop->join ?? 0;
  450. $default = $shop->default ?? 0;
  451. if ($join == 0 && $default == 0) {
  452. util::fail('请在默认门店修改');
  453. }
  454. $shopAdmin = $this->shopAdmin;
  455. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  456. util::fail('超管才能修改');
  457. }
  458. $shop = $this->shop;
  459. $default = $shop->default ?? 0;
  460. $adminId = $this->adminId ?? 0;
  461. //normal常规改价,cg采购改价
  462. $changeType = Yii::$app->request->post('changeType', 'normal');
  463. $targetId = Yii::$app->request->post('targetId', 0);
  464. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  465. $data = Yii::$app->request->post('data', '');
  466. if (empty($data)) {
  467. util::fail('没有修改');
  468. }
  469. $arr = json_decode($data, true);
  470. if (empty($arr)) {
  471. util::fail('没有修改哦');
  472. }
  473. $connection = Yii::$app->db;
  474. $transaction = $connection->beginTransaction();
  475. try {
  476. $cg = PurchaseOrderClass::getLockById($targetId);
  477. if (!empty($cg)) {
  478. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  479. util::fail('不是您的采购单');
  480. }
  481. //批量改价同时入库
  482. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  483. $staff = $this->shopAdmin;
  484. $data = [];
  485. $data['staffId'] = $staff->id ?? 0;
  486. $data['staffName'] = $staff->name ?? '';
  487. $data['adminId'] = $this->adminId ?? 0;
  488. PurchaseOrderClass::putIn($cg, $data);
  489. }
  490. }
  491. $ids = array_column($arr, 'id');
  492. $ids = array_unique(array_filter($ids));
  493. if (empty($ids)) {
  494. util::fail('请选择花材');
  495. }
  496. $sjId = $shop->sjId ?? 0;
  497. $chainShopList = [];
  498. if ($default == 1) {
  499. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  500. }
  501. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  502. foreach ($arr as $product) {
  503. $productId = $product['id'];
  504. $productInfo = $productList[$productId] ?? [];
  505. if (empty($productInfo)) {
  506. util::fail('没有找到花材');
  507. }
  508. $productName = $productInfo->name ?? '';
  509. if (isset($product['id']) == false) {
  510. util::fail('没有花材');
  511. }
  512. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  513. util::fail('请填写' . $productName . '的花店价');
  514. }
  515. $price = $product['price'];
  516. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  517. util::fail('请填写' . $productName . '的散客价');
  518. }
  519. $skPrice = $product['skPrice'];
  520. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  521. util::fail('没有权限访问');
  522. }
  523. if (empty($price)) {
  524. continue;
  525. }
  526. $ptItemId = $productInfo->itemId;
  527. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $changeParams);
  528. //在首店修改需要同步到所有直营店
  529. if ($default == 1) {
  530. foreach ($chainShopList as $chain) {
  531. if ($chain->id == $shop->id) {
  532. continue;
  533. }
  534. $chainMainId = $chain->mainId ?? 0;
  535. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  536. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  537. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $changeParams2);
  538. }
  539. }
  540. }
  541. $mainId = $shop->mainId ?? 0;
  542. if (!empty($mainId)) {
  543. //提醒零售收银台界面要刷新
  544. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  545. if (!empty($staffList)) {
  546. foreach ($staffList as $staff) {
  547. $staffId = $staff->id ?? 0;
  548. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  549. }
  550. }
  551. }
  552. $transaction->commit();
  553. util::complete('操作成功');
  554. } catch (\Exception $e) {
  555. $transaction->rollBack();
  556. Yii::info("修改失败原因:" . $e->getMessage());
  557. util::fail('修改失败');
  558. }
  559. }
  560. //改价
  561. public function actionChangePrice()
  562. {
  563. $shopAdmin = $this->shopAdmin;
  564. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  565. util::fail('超管才能修改');
  566. }
  567. $productId = Yii::$app->request->post('productId', 0);
  568. $productInfo = ProductClass::getById($productId, true);
  569. if (empty($productInfo)) {
  570. util::fail("花材不存在");
  571. }
  572. if ($productInfo->mainId != $this->mainId) {
  573. util::fail('没有权限');
  574. }
  575. $price = Yii::$app->request->post('price', '');
  576. if (is_numeric($price) && $price > 0) {
  577. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  578. } else {
  579. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  580. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  581. }
  582. util::success(['price' => $price]);
  583. }
  584. //恢复自动调价
  585. public function actionAutoPrice()
  586. {
  587. $productId = Yii::$app->request->post('productId', 0);
  588. $productData = ProductClass::getById($productId);
  589. if (!$productData) {
  590. util::fail("花材不存在");
  591. }
  592. //2021.04.06改为用product中的成本价+加价
  593. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  594. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  595. util::complete("操作成功");
  596. }
  597. //修改加价
  598. public function actionChangeAddPrice()
  599. {
  600. $productId = Yii::$app->request->post('productId', 0);
  601. $addPrice = Yii::$app->request->post('addPrice', '');
  602. if ($addPrice < 0) {
  603. util::fail("加价不能小于0");
  604. }
  605. $productData = ProductClass::getProductData($productId, $this->mainId);
  606. if (!$productData) {
  607. util::fail("花材不存在");
  608. }
  609. ProductClass::changeAddPrice($productId, $addPrice);
  610. util::complete();
  611. }
  612. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  613. public function actionBatchChangeMore()
  614. {
  615. $shop = $this->shop;
  616. $default = $shop->default ?? 0;
  617. if ($default == 0) {
  618. util::fail('请在首店修改');
  619. }
  620. $shopAdmin = $this->shopAdmin;
  621. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  622. util::fail('超管才能操作');
  623. }
  624. $addData = Yii::$app->request->post('addData', '');
  625. if (empty($addData)) {
  626. util::fail('没有花材');
  627. }
  628. $itemData = json_decode($addData, true);
  629. if (is_array($itemData) == false) {
  630. util::fail('没有花材...');
  631. }
  632. $ids = array_column($itemData, 'id');
  633. $infoList = ProductClass::getByIds($ids, null, 'id');
  634. if (empty($infoList)) {
  635. util::fail('没有花材');
  636. }
  637. foreach ($infoList as $info) {
  638. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  639. util::fail('不是你的花材不能修改');
  640. }
  641. }
  642. //首店修改同步到所有直营店
  643. $sjId = $shop->sjId ?? 0;
  644. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  645. foreach ($itemData as $key => $data) {
  646. $id = $data['id'] ?? 0;
  647. unset($data['id']);
  648. ProductClass::updateById($id, $data);
  649. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  650. if (empty($ptItemId)) {
  651. continue;
  652. }
  653. if (isset($shop->default) && $shop->default == 1) {
  654. foreach ($chainShopList as $chainShop) {
  655. $currentMainId = $chainShop->mainId ?? 0;
  656. if ($currentMainId == $shop->mainId) {
  657. //前面已经修改过了,不需要重复修改
  658. continue;
  659. }
  660. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  661. }
  662. }
  663. }
  664. util::complete('修改成功');
  665. }
  666. //批量修改加价 ssh 20211211
  667. public function actionBatchChangeAddPrice()
  668. {
  669. $shop = $this->shop;
  670. $join = $shop->join ?? 0;
  671. $default = $shop->default ?? 0;
  672. if ($join == 0 && $default == 0) {
  673. util::fail('请在首店操作');
  674. }
  675. $shopAdmin = $this->shopAdmin;
  676. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  677. util::fail('超管才能操作');
  678. }
  679. $addData = Yii::$app->request->post('addData', '');
  680. if (empty($addData)) {
  681. util::fail('没有花材');
  682. }
  683. $itemData = json_decode($addData, true);
  684. if (is_array($itemData) == false) {
  685. util::fail('没有花材...');
  686. }
  687. $ids = array_column($itemData, 'id');
  688. $infoList = ProductClass::getByIds($ids, null, 'id');
  689. if (empty($infoList)) {
  690. util::fail('没有花材');
  691. }
  692. foreach ($infoList as $info) {
  693. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  694. util::fail('不能修改别人的花材');
  695. }
  696. }
  697. //首店修改同步到所有直营店
  698. $sjId = $shop->sjId ?? 0;
  699. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  700. foreach ($itemData as $key => $data) {
  701. $id = $data['id'] ?? 0;
  702. unset($data['id']);
  703. ProductClass::updateById($id, $data);
  704. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  705. if (empty($ptItemId)) {
  706. continue;
  707. }
  708. if (isset($shop->default) && $shop->default == 1) {
  709. foreach ($chainShopList as $chainShop) {
  710. if (isset($chainShop->join) && $chainShop->join == 1) {
  711. continue;
  712. }
  713. $currentMainId = $chainShop->mainId ?? 0;
  714. if ($currentMainId == $shop->mainId) {
  715. //前面已经修改过了,不需要重复修改
  716. continue;
  717. }
  718. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  719. }
  720. }
  721. }
  722. util::complete('修改成功');
  723. }
  724. public function actionUpdate()
  725. {
  726. $shopAdmin = $this->shopAdmin;
  727. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  728. util::fail('超管才能操作');
  729. }
  730. $shop = $this->shop;
  731. $join = $shop->join ?? 0;
  732. $default = $shop->default ?? 0;
  733. if ($join == 0 && $default == 0) {
  734. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  735. if ($shopAdmin->super != 1) {
  736. util::fail('请先开通超管权限');
  737. }
  738. }
  739. $post = Yii::$app->request->post();
  740. $post['adminId'] = $this->adminId;
  741. $post['staffId'] = $this->shopAdmin->id;
  742. $post['staffName'] = $this->shopAdmin->name;
  743. ProductClass::updateProduct($post, $this->shop);
  744. util::complete();
  745. }
  746. //上下架状态控制 ssh 20210713
  747. public function actionStatusUpdate()
  748. {
  749. $post = Yii::$app->request->post();
  750. $shopAdmin = $this->shopAdmin;
  751. $roleId = $shopAdmin['roleId'] ?? 0;
  752. $role = AdminRoleClass::getById($roleId);
  753. $roleName = $role['roleName'] ?? '';
  754. if ($roleName == '员工') {
  755. util::fail('没有权限操作哦');
  756. }
  757. $id = $post['id'] ?? 0;
  758. $status = $post['status'] ?? 1;
  759. $product = ProductClass::getById($id, true);
  760. if ($product->mainId != $this->mainId) {
  761. util::fail('没有权限操作');
  762. }
  763. $product->status = $status;
  764. if ($status == 2) {
  765. $product->discountPrice = 0;
  766. }
  767. $product->save();
  768. util::complete();
  769. }
  770. //花材展示状态控制 ssh 20210804
  771. public function actionDelStatusUpdate()
  772. {
  773. $post = Yii::$app->request->post();
  774. $shop = $this->shop;
  775. $join = $shop->join ?? 0;
  776. $default = $shop->default ?? 0;
  777. if ($join == 0 && $default == 0) {
  778. util::fail('请在首店操作');
  779. }
  780. $shopAdmin = $this->shopAdmin;
  781. $roleId = $shopAdmin['roleId'] ?? 0;
  782. $role = AdminRoleClass::getById($roleId);
  783. $roleName = $role['roleName'] ?? '';
  784. if ($roleName == '员工') {
  785. util::fail('没有权限操作');
  786. }
  787. $id = $post['id'] ?? 0;
  788. $delStatus = $post['delStatus'] ?? 0;
  789. $product = ProductClass::getById($id, true);
  790. if ($product->mainId != $this->mainId) {
  791. util::fail('没有权限操作');
  792. }
  793. $product->delStatus = $delStatus;
  794. $product->save();
  795. $ptItemId = $product->itemId ?? 0;
  796. if (isset($shop->default) && $shop->default == 1) {
  797. //首店修改同步到所有直营店
  798. $sjId = $shop->sjId ?? 0;
  799. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  800. foreach ($chainShopList as $chainShop) {
  801. $chainShopId = $chainShop->id ?? 0;
  802. if (isset($chainShop->join) && $chainShop->join == 1) {
  803. continue;
  804. }
  805. if ($chainShopId == $shop->id) {
  806. continue;
  807. }
  808. $chainMainId = $chainShop->mainId ?? 0;
  809. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  810. if (!empty($chainProduct)) {
  811. $chainProduct->delStatus = $delStatus;
  812. $chainProduct->save();
  813. }
  814. }
  815. }
  816. util::complete();
  817. }
  818. //详情 ruidian 2021.5.3
  819. public function actionDetail()
  820. {
  821. $id = Yii::$app->request->get('id', 0);
  822. $respond = ProductClass::getItemInfo($id);
  823. $ptItemId = $respond['itemId'] ?? 0;
  824. $ptItemInfo = PtItemClass::getById($ptItemId);
  825. $respond['ptItemInfo'] = $ptItemInfo;
  826. util::success($respond);
  827. }
  828. //新增花材 2021.6.21
  829. public function actionAdd()
  830. {
  831. $post = Yii::$app->request->post();
  832. $shop = $this->shop;
  833. $default = $shop->default ?? 0;
  834. if ($default == 0) {
  835. util::fail('请在默认门店添加花材,分店只能修改花材');
  836. }
  837. $shopAdmin = $this->shopAdmin;
  838. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  839. util::fail('管理员才能添加花材');
  840. }
  841. $post['sjId'] = $this->sjId;
  842. $post['adminId'] = $this->adminId;
  843. $post['mainId'] = $this->mainId;
  844. $price = $post['price'] ?? 0;
  845. $addPrice = $post['addPrice'] ?? 0;
  846. if ($addPrice > $price) {
  847. util::fail('加价不能大于售价');
  848. }
  849. $post['staffName'] = $shopAdmin->name ?? '';
  850. ProductClass::addProduct($post, $this->shop);
  851. util::complete('添加成功');
  852. }
  853. //获取拼音缩写 ssh 20210707
  854. public function actionPy()
  855. {
  856. $name = Yii::$app->request->get('name');
  857. $py = stringUtil::py($name);
  858. util::success(['py' => $py]);
  859. }
  860. //(客户端-批发商)复制花材
  861. public function actionClone()
  862. {
  863. $post = Yii::$app->request->post();
  864. $shop = $this->shop;
  865. $join = $shop->join ?? 0;
  866. $default = $shop->default ?? 0;
  867. if ($join == 0 && $default == 0) {
  868. util::fail('请在首店操作');
  869. }
  870. $shopAdmin = $this->shopAdmin;
  871. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  872. util::fail('管理员才能添加花材');
  873. }
  874. $shop = $this->shop;
  875. $default = $shop->default ?? 0;
  876. if ($default != 1) {
  877. util::fail('请在总店添加');
  878. }
  879. $post['sjId'] = $this->sjId;
  880. $post['adminId'] = $this->adminId;
  881. $post['mainId'] = $this->mainId;
  882. $post['staffName'] = $shopAdmin->name ?? '';
  883. $price = $post['price'] ?? 0;
  884. $addPrice = $post['addPrice'] ?? 0;
  885. if ($addPrice > $price) {
  886. util::fail('加价不能大于售价');
  887. }
  888. //复制标识
  889. $post['copy'] = 1;
  890. //去除无用的字段
  891. unset($post['viewNum']);
  892. unset($post['actualSold']);
  893. unset($post['itemId']);
  894. unset($post['id']);
  895. unset($post['delStatus']);
  896. ProductClass::addProduct($post, $this->shop);
  897. util::complete('复制成功');
  898. }
  899. //下载价格表 ssh 20210922
  900. public function actionGeneratePriceTable()
  901. {
  902. $level = Yii::$app->request->get('level', 0);
  903. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  904. $file = $respond['file'] ?? '';
  905. $shortFile = $respond['shortFile'] ?? '';
  906. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  907. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  908. }
  909. public function actionGenerateItemTable()
  910. {
  911. $level = Yii::$app->request->get('level', 0);
  912. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  913. $file = $respond['file'] ?? '';
  914. $shortFile = $respond['shortFile'] ?? '';
  915. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  916. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  917. }
  918. //下载条形码 lqh 20211227
  919. public function actionGenerateBarcodeTable()
  920. {
  921. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  922. $file = $respond['file'] ?? '';
  923. $shortFile = $respond['shortFile'] ?? '';
  924. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  925. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  926. }
  927. }