ProductController.php 40 KB

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