ProductController.php 41 KB

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