ProductController.php 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  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\notify\classes\NotifyClass;
  14. use bizGhs\order\classes\PurchaseOrderClass;
  15. use bizGhs\product\classes\ProductClass;
  16. use bizGhs\product\models\Product;
  17. use bizGhs\product\services\ProductService;
  18. use bizGhs\shop\classes\ShopAdminClass;
  19. use bizGhs\stock\classes\StockInDayClass;
  20. use common\components\printUtil;
  21. use common\components\stringUtil;
  22. use common\components\util;
  23. use Yii;
  24. class ProductController extends BaseController
  25. {
  26. public $guestAccess = ['index'];
  27. //停止预售 ssh 20230224
  28. public function actionCancelPreSell()
  29. {
  30. $get = Yii::$app->request->get();
  31. $id = $get['id'] ?? 0;
  32. $info = ProductClass::getById($id, true);
  33. ProductClass::check($info, $this->mainId);
  34. if ($info->stock > 0) {
  35. util::fail('没有库存才能停止预售');
  36. }
  37. $info->presell = 0;
  38. $info->presellDate = '';
  39. $info->save();
  40. util::complete();
  41. }
  42. //修改预售 ssh 20221214
  43. public function actionChangePresell()
  44. {
  45. $post = Yii::$app->request->post();
  46. $id = $post['id'] ?? 0;
  47. $info = ProductClass::getById($id, true);
  48. ProductClass::check($info, $this->mainId);
  49. $str = $post['date'] ?? '';
  50. $presell = $post['presell'] ?? 0;
  51. $newStr = '';
  52. if ($presell == 1) {
  53. if (empty($str)) {
  54. util::fail('请填写预售日期');
  55. }
  56. $arr = json_decode($str, true);
  57. if (empty($arr)) {
  58. util::fail('请填写预售日期');
  59. }
  60. $new = [];
  61. foreach ($arr as $date) {
  62. $new[] = strtotime($date);
  63. }
  64. $new = array_unique(array_filter($new));
  65. asort($new);
  66. $newStr = implode(',', $new);
  67. }
  68. $info->presell = $presell;
  69. $info->presellDate = $newStr;
  70. $info->discountPrice = 0;
  71. $info->save();
  72. util::complete();
  73. }
  74. //取消满减 ssh 20231216
  75. public function actionCancelFullOff()
  76. {
  77. $get = Yii::$app->request->get();
  78. $id = $get['id'] ?? 0;
  79. $info = ProductClass::getById($id, true);
  80. ProductClass::check($info, $this->mainId);
  81. $info->reachNum = 0;
  82. $info->reachNumDiscount = 0;
  83. $info->save();
  84. util::complete('取消成功');
  85. }
  86. //取消特价 ssh 20220901
  87. public function actionCancelDiscount()
  88. {
  89. $get = Yii::$app->request->get();
  90. $id = $get['id'] ?? 0;
  91. $info = ProductClass::getById($id, true);
  92. ProductClass::check($info, $this->mainId);
  93. $info->discountPrice = 0;
  94. $info->skDiscountPrice = 0;
  95. $info->hjDiscountPrice = 0;
  96. $info->save();
  97. util::complete('取消成功');
  98. }
  99. //打印花材的标签 ssh 20220602
  100. public function actionPrint()
  101. {
  102. $get = Yii::$app->request->get();
  103. $id = $get['id'] ?? 0;
  104. $num = $get['num'] ?? 1;
  105. $type = $get['type'] ?? 0;
  106. $info = ProductClass::getById($id, true);
  107. if (empty($info)) {
  108. util::fail('没有找到花材');
  109. }
  110. $name = $info->name ?? '';
  111. $ptItemId = $info->itemId ?? 0;
  112. $mainId = $info->mainId ?? 0;
  113. $ext = $this->shopExt;
  114. $printLabelSn = $ext->printLabelSn ?? '';
  115. if (empty($printLabelSn)) {
  116. util::fail('请设置标签打印机');
  117. }
  118. $p = new printUtil($printLabelSn);
  119. $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
  120. if (isset($info->ratioType) && $info->ratioType == 1) {
  121. $unit = '若干' . $info->smallUnit . '/' . $info->bigUnit;
  122. }
  123. $p->times = $num;
  124. if (stringUtil::getWordNum($name) > 7) {
  125. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  126. } else {
  127. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  128. }
  129. //杭州斗南批发店
  130. if (isset($get['type']) == false && $this->shopId == 4608) {
  131. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  132. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  133. } else {
  134. if ($type == 0) {
  135. //打标签
  136. $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
  137. if (in_array($mainId, [52, 1459])) {
  138. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  139. } else {
  140. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  141. }
  142. } else {
  143. //打价码
  144. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  145. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  146. }
  147. }
  148. $p->printLabelMsg($content);
  149. util::complete();
  150. }
  151. //取出今天有入库的花材 ssh 20221024
  152. public function actionStockIn()
  153. {
  154. $py = Yii::$app->request->get('py', '');
  155. $version = Yii::$app->request->get('version', 0);
  156. if ($version == 0) {
  157. util::fail('请先升级版本到1.0.70以上');
  158. }
  159. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  160. $mainId = $this->mainId ?? 0;
  161. $where['mainId'] = $mainId;
  162. if ($py) {
  163. $pyName = strtolower($py);
  164. $where['py'] = $pyName;
  165. }
  166. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  167. if (empty($arr)) {
  168. util::fail('没有花材需要盘点');
  169. }
  170. $ids = array_column($arr, 'itemId');
  171. $ids = array_unique($ids);
  172. $where['id'] = ['in', $ids];
  173. $level = 1;
  174. $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';
  175. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  176. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  177. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  178. util::success($data);
  179. }
  180. //按分类列出所有花材
  181. public function actionShow()
  182. {
  183. $py = Yii::$app->request->get('py', '');
  184. $requestType = Yii::$app->request->get('requestType', 'common');
  185. //默认显示上架商品
  186. $status = Yii::$app->request->get('status', 1);
  187. //默认显示未删除商品
  188. $delStatus = Yii::$app->request->get('delStatus', 0);
  189. $book = Yii::$app->request->get('book', 0);
  190. //获取所有当前供货商的分类 (全部、常用)
  191. //根据分类组装分类下的花材信息
  192. //中央ID
  193. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  194. $where['mainId'] = $this->mainId;
  195. if ($py) {
  196. $pyName = strtolower($py);
  197. $where['py'] = $pyName;
  198. }
  199. //改价和全部有库存花材列表
  200. if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
  201. $where['stock>'] = 0;
  202. }
  203. if (!empty($status)) {
  204. $where['status'] = $status;
  205. }
  206. if ($requestType == 'book') {
  207. unset($where['status']);
  208. }
  209. $where['delStatus'] = $delStatus;
  210. //客户等级
  211. $customId = Yii::$app->request->get('customId', 0);
  212. $level = 1;
  213. if (!empty($customId)) {
  214. $custom = CustomClass::getById($customId, true);
  215. $level = $custom->level ?? 1;
  216. }
  217. $itemInfoData = [];
  218. if ($requestType == 'hasStockList') {
  219. //有库存的花材列表
  220. $field = 'id,py,name,classId,itemId,price,skPrice,hjPrice,stock';
  221. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  222. } elseif ($requestType == 'changePrice') {
  223. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,skMore,hjAddPrice,addPrice,variety,price,hjPrice,stock,onStock,presell,frontHide,reachNum,reachNumDiscount';
  224. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  225. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  226. } elseif ($requestType == 'changeStock') {
  227. //修改库存列表
  228. $field = 'id,py,cover,name,cost,itemId,status,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,frontHide';
  229. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  230. $itemInfoData = ProductClass::changeStockGroup($itemInfoData, $level);
  231. } elseif ($requestType == 'kd') {
  232. //开单的花材列表
  233. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide,reachNum,reachNumDiscount';
  234. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  235. $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level);
  236. } elseif ($requestType == 'book') {
  237. //预订花材列表
  238. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide';
  239. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  240. $itemInfoData = ProductClass::bookItemGroup($itemInfoData, $level);
  241. } elseif ($requestType == 'itemList') {
  242. //花材列表
  243. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,onStock,actualSold,status,ratio,ratioType,presell,frontHide,auth,reachNum,reachNumDiscount';
  244. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  245. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  246. } elseif ($requestType == 'outList') {
  247. //下架花材列表
  248. $where['status'] = 2;
  249. $where['delStatus'] = 0;
  250. $where['removeStatus'] = 0;
  251. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  252. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  253. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  254. } elseif ($requestType == 'stopList') {
  255. //停用花材列表
  256. unset($where['status']);
  257. $where['delStatus'] = 1;
  258. $where['removeStatus'] = 0;
  259. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  260. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  261. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  262. } elseif ($requestType == 'removeList') {
  263. //删除花材列表
  264. unset($where['status']);
  265. $where['delStatus'] = 1;
  266. $where['removeStatus'] = 1;
  267. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  268. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  269. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  270. } elseif ($requestType == 'check') {
  271. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  272. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  273. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  274. } elseif ($requestType == 'break') {
  275. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  276. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  277. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  278. } elseif ($requestType == 'part') {
  279. //拆散花材
  280. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  281. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  282. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  283. } elseif ($requestType == 'stockOut') {
  284. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio,frontHide';
  285. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  286. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  287. } elseif ($requestType == 'cg') {
  288. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight,frontHide';
  289. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  290. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  291. } elseif ($requestType == 'warning') {
  292. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,onStock,actualSold,presell,bigUnit,stockWarning,status,frontHide';
  293. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  294. ->andWhere('`stock`+`onStock`<`stockWarning`')
  295. ->andWhere("delStatus=0")
  296. ->select($field)->asArray()->all();
  297. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  298. } else {
  299. util::fail('没有数据');
  300. }
  301. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  302. util::success($data);
  303. }
  304. //取出今天有入库的花材 ssh 20221224
  305. public function actionGetStockIn()
  306. {
  307. $py = Yii::$app->request->get('py', '');
  308. $version = Yii::$app->request->get('version', 0);
  309. if ($version == 0) {
  310. util::fail('请先升级版本到1.0.70以上');
  311. }
  312. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  313. $mainId = $this->mainId ?? 0;
  314. $where['mainId'] = $mainId;
  315. if ($py) {
  316. $pyName = strtolower($py);
  317. $where['py'] = $pyName;
  318. }
  319. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  320. if (empty($arr)) {
  321. util::fail('没有花材需要盘点');
  322. }
  323. $ids = array_column($arr, 'itemId');
  324. $ids = array_unique($ids);
  325. $where['id'] = ['in', $ids];
  326. $level = 1;
  327. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  328. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  329. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  330. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  331. util::success($data);
  332. }
  333. //按分类列出所有花材
  334. public function actionIndex()
  335. {
  336. $py = Yii::$app->request->get('py', '');
  337. $requestType = Yii::$app->request->get('requestType', 'common');
  338. //默认显示上架商品
  339. $status = Yii::$app->request->get('status', 1);
  340. //默认显示未删除商品
  341. $delStatus = Yii::$app->request->get('delStatus', 0);
  342. $warning = Yii::$app->request->get('warning', 0);
  343. //获取所有当前供货商的分类 (全部、常用)
  344. //根据分类组装分类下的花材信息
  345. //中央ID
  346. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  347. $where['mainId'] = $this->mainId;
  348. if ($py) {
  349. $pyName = strtolower($py);
  350. $where['py'] = $pyName;
  351. }
  352. if ($requestType == 'hasStock') {
  353. //改价只显示库存大于0的
  354. $where['stock>'] = 0;
  355. }
  356. if (!empty($status)) {
  357. $where['status'] = $status;
  358. }
  359. $where['delStatus'] = $delStatus;
  360. //客户等级
  361. $customId = Yii::$app->request->get('customId', 0);
  362. $level = 1;
  363. if (!empty($customId)) {
  364. $custom = CustomClass::getById($customId, true);
  365. $level = $custom->level ?? 1;
  366. }
  367. if ($warning == 1) {
  368. //库存预警
  369. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  370. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  371. ->andWhere('`stock`<`stockWarning`')
  372. ->andWhere("delStatus=0")
  373. ->select($field)->asArray()->all();
  374. } else {
  375. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  376. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  377. }
  378. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  379. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  380. util::success($data);
  381. }
  382. //所有花材分页和不分页
  383. public function actionList()
  384. {
  385. $where = [];
  386. $classId = Yii::$app->request->get('classId', 0);
  387. if (!empty($classId)) {
  388. $where['classId'] = $classId;
  389. }
  390. $name = Yii::$app->request->get('name', '');
  391. if (empty($name)) {
  392. $py = Yii::$app->request->get('py', '');
  393. $name = !empty($py) ? $py : '';
  394. }
  395. if (!empty($name)) {
  396. if (stringUtil::isLetter($name)) {
  397. $where['py'] = ['like', $name];
  398. } else {
  399. $where['name'] = ['like', $name];
  400. }
  401. }
  402. $status = Yii::$app->request->get('status', 0);
  403. if (!empty($status)) {
  404. $where['status'] = $status;
  405. }
  406. $delStatus = Yii::$app->request->get('delStatus', 0);
  407. if ($delStatus != 2) {
  408. $where['delStatus'] = $delStatus;
  409. }
  410. $where['mainId'] = $this->mainId;
  411. $productIds = Yii::$app->request->get('ids', '');
  412. if (!empty($productIds)) {
  413. $productIdArr = explode(',', $productIds);
  414. if (!empty($productIdArr)) {
  415. $where['id'] = ['in', $productIdArr];
  416. }
  417. }
  418. //输出标准会员价,即批发价,默认显示的是批发价
  419. $level = 1;
  420. $type = Yii::$app->request->get('type', '');
  421. $showPage = Yii::$app->request->get('showPage', 0);
  422. if ($showPage) {
  423. if ($type == 'waring') {
  424. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  425. $lackIds = array_column($pro, 'id');
  426. if (empty($lackIds)) {
  427. util::success([]);
  428. }
  429. $lackIds = array_filter(array_unique($lackIds));
  430. $where['id'] = ['in', $lackIds];
  431. $respond = ProductClass::getList("*", $where, "actualSold desc");
  432. } else {
  433. $respond = ProductClass::getList("*", $where, "inTurn desc");
  434. }
  435. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  436. $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
  437. util::success($respond);
  438. } else {
  439. if ($type == 'waring') {
  440. //库存预警 按库存从小到大排序
  441. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  442. } else {
  443. if (!empty($productIds)) {
  444. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  445. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  446. } else {
  447. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  448. }
  449. }
  450. $data = ProductClass::groupProductInfo($data, $level);
  451. $data = ProductClass::groupClassName($this->sjId, $data);
  452. if ($type == 'waring') {
  453. //库存预警
  454. $newData = [];
  455. foreach ($data as $v) {
  456. if ($v['stock'] <= $v['stockWarning']) {
  457. $newData[] = $v;
  458. }
  459. }
  460. util::success(['list' => $newData]);
  461. }
  462. util::success(['list' => $data]);
  463. }
  464. }
  465. //所有花材
  466. public function actionAll()
  467. {
  468. $where = [];
  469. $where['mainId'] = $this->mainId;
  470. $classId = Yii::$app->request->get('classId', 0);
  471. if (!empty($classId)) {
  472. $where['classId'] = $classId;
  473. }
  474. $status = Yii::$app->request->get('status', 0);
  475. if (!empty($status)) {
  476. $where['status'] = $status;
  477. }
  478. $delStatus = Yii::$app->request->get('delStatus', 0);
  479. if ($delStatus != 2) {
  480. $where['delStatus'] = $delStatus;
  481. }
  482. //输出标准会员价,即批发价,默认显示的是批发价
  483. $level = 1;
  484. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  485. $data = ProductClass::groupProductInfo($data, $level);
  486. util::success(['list' => $data]);
  487. }
  488. //批量改价
  489. public function actionBatchChangePrice()
  490. {
  491. $shop = $this->shop;
  492. $join = $shop->join ?? 0;
  493. $default = $shop->default ?? 0;
  494. if ($join == 0 && $default == 0) {
  495. util::fail('当前直营分店,只能回总店修改价格');
  496. }
  497. $shopAdmin = $this->shopAdmin;
  498. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  499. util::fail('超管才能修改');
  500. }
  501. $shop = $this->shop;
  502. $default = $shop->default ?? 0;
  503. $adminId = $this->adminId ?? 0;
  504. //normal常规改价,cg采购改价
  505. $changeType = Yii::$app->request->post('changeType', 'normal');
  506. $targetId = Yii::$app->request->post('targetId', 0);
  507. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  508. $post = Yii::$app->request->post();
  509. $data = $post['data'] ?? '';
  510. if (empty($data)) {
  511. util::fail('没有修改');
  512. }
  513. $arr = json_decode($data, true);
  514. if (empty($arr)) {
  515. util::fail('没有修改哦');
  516. }
  517. $appVersion = $post['appVersion'] ?? 0;
  518. if ($appVersion != 1) {
  519. util::fail('请先升级应用');
  520. }
  521. $connection = Yii::$app->db;
  522. $transaction = $connection->beginTransaction();
  523. try {
  524. $cg = PurchaseOrderClass::getLockById($targetId);
  525. if (!empty($cg)) {
  526. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  527. util::fail('不是您的采购单');
  528. }
  529. //批量改价同时入库
  530. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  531. $staff = $this->shopAdmin;
  532. $data = [];
  533. $data['staffId'] = $staff->id ?? 0;
  534. $data['staffName'] = $staff->name ?? '';
  535. $data['adminId'] = $this->adminId ?? 0;
  536. PurchaseOrderClass::putIn($cg, $data);
  537. }
  538. }
  539. $ids = array_column($arr, 'id');
  540. $ids = array_unique(array_filter($ids));
  541. if (empty($ids)) {
  542. util::fail('请选择花材');
  543. }
  544. $sjId = $shop->sjId ?? 0;
  545. $chainShopList = [];
  546. if ($default == 1) {
  547. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  548. }
  549. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  550. foreach ($arr as $product) {
  551. $productId = $product['id'];
  552. $productInfo = $productList[$productId] ?? [];
  553. if (empty($productInfo)) {
  554. util::fail('没有找到花材');
  555. }
  556. $productName = $productInfo->name ?? '';
  557. if (isset($product['id']) == false) {
  558. util::fail('没有花材');
  559. }
  560. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  561. util::fail('请填写' . $productName . '的批发价');
  562. }
  563. $price = $product['price'];
  564. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  565. util::fail('请填写' . $productName . '的零售价');
  566. }
  567. $skPrice = $product['skPrice'];
  568. if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
  569. util::fail('请填写' . $productName . '的会员价');
  570. }
  571. $hjPrice = $product['hjPrice'] ?? 0;
  572. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  573. util::fail('无法访问');
  574. }
  575. if ($hjPrice > $price) {
  576. util::fail($productName . ' 批发价要大于会员价');
  577. }
  578. if ($price > $skPrice) {
  579. util::fail($productName . ' 零售价要大于批发价');
  580. }
  581. $ptItemId = $productInfo->itemId;
  582. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  583. //在首店修改需要同步到所有直营店
  584. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  585. foreach ($chainShopList as $chain) {
  586. if ($chain->id == $shop->id) {
  587. continue;
  588. }
  589. $chainMainId = $chain->mainId ?? 0;
  590. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  591. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  592. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  593. }
  594. }
  595. }
  596. $mainId = $shop->mainId ?? 0;
  597. if (!empty($mainId)) {
  598. //提醒零售收银台界面要刷新
  599. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  600. if (!empty($staffList)) {
  601. foreach ($staffList as $staff) {
  602. $staffId = $staff->id ?? 0;
  603. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  604. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  605. }
  606. }
  607. }
  608. $transaction->commit();
  609. util::complete('操作成功');
  610. } catch (\Exception $e) {
  611. $transaction->rollBack();
  612. Yii::info("修改失败原因:" . $e->getMessage());
  613. util::fail('修改失败');
  614. }
  615. }
  616. //多个花材同时改成一个价 ssh 20231003
  617. public function actionManyItemChangeOnePrice()
  618. {
  619. $shop = $this->shop;
  620. $join = $shop->join ?? 0;
  621. $default = $shop->default ?? 0;
  622. if ($join == 0 && $default == 0) {
  623. util::fail('当前直营分店,只能回总店修改价格');
  624. }
  625. $shopAdmin = $this->shopAdmin;
  626. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  627. util::fail('超管才能修改');
  628. }
  629. $post = Yii::$app->request->post();
  630. $idsList = $post['ids'] ?? '';
  631. $ids = json_decode($idsList, true);
  632. if (empty($ids)) {
  633. util::fail('请选择花材');
  634. }
  635. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  636. if (empty($list)) {
  637. util::fail('请选择花材哦');
  638. }
  639. $mainId = $this->mainId;
  640. $adminId = $this->adminId ?? 0;
  641. $shop = $this->shop;
  642. $default = $shop->default ?? 0;
  643. $shopAdmin = $this->shopAdmin;
  644. $price = $post['price'] ?? 0;
  645. if (is_numeric($price) == false) {
  646. util::fail('批发价填写错误');
  647. }
  648. $skPrice = $post['skPrice'] ?? 0;
  649. if (is_numeric($skPrice) == false) {
  650. util::fail('散客价填写错误');
  651. }
  652. $hjPrice = $post['hjPrice'] ?? 0;
  653. if (is_numeric($hjPrice) == false) {
  654. util::fail('会员价填写错误');
  655. }
  656. if ($hjPrice > $price) {
  657. util::fail('会员价不能大于批发价');
  658. }
  659. if ($price > $skPrice) {
  660. util::fail('批发价不能大于零售价');
  661. }
  662. $sjId = $shop->sjId ?? 0;
  663. $chainShopList = [];
  664. if ($default == 1) {
  665. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  666. }
  667. //normal常规改价,cg采购改价
  668. $changeType = Yii::$app->request->post('changeType', 'normal');
  669. $targetId = 0;
  670. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  671. $connection = Yii::$app->db;
  672. $transaction = $connection->beginTransaction();
  673. try {
  674. foreach ($list as $product) {
  675. if ($product->mainId != $mainId) {
  676. util::fail('修改失败,不是你的花材');
  677. }
  678. $ptItemId = $product->itemId;
  679. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  680. //在首店修改需要同步到所有直营店
  681. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  682. if (!empty($chainShopList)) {
  683. foreach ($chainShopList as $chain) {
  684. if ($chain->id == $shop->id) {
  685. continue;
  686. }
  687. $chainMainId = $chain->mainId ?? 0;
  688. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  689. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  690. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  691. }
  692. }
  693. }
  694. }
  695. if (!empty($mainId)) {
  696. //提醒零售收银台界面要刷新
  697. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  698. if (!empty($staffList)) {
  699. foreach ($staffList as $staff) {
  700. $staffId = $staff->id ?? 0;
  701. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  702. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  703. }
  704. }
  705. }
  706. $transaction->commit();
  707. util::complete('修改成功');
  708. } catch (\Exception $e) {
  709. $transaction->rollBack();
  710. Yii::info("修改失败原因:" . $e->getMessage());
  711. util::fail('修改失败');
  712. }
  713. }
  714. //改价
  715. public function actionChangePrice()
  716. {
  717. $shopAdmin = $this->shopAdmin;
  718. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  719. util::fail('超管才能修改');
  720. }
  721. $productId = Yii::$app->request->post('productId', 0);
  722. $productInfo = ProductClass::getById($productId, true);
  723. if (empty($productInfo)) {
  724. util::fail("花材不存在");
  725. }
  726. if ($productInfo->mainId != $this->mainId) {
  727. util::fail('没有权限');
  728. }
  729. $price = Yii::$app->request->post('price', '');
  730. if (is_numeric($price) && $price > 0) {
  731. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  732. } else {
  733. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  734. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  735. }
  736. util::success(['price' => $price]);
  737. }
  738. //恢复自动调价
  739. public function actionAutoPrice()
  740. {
  741. $productId = Yii::$app->request->post('productId', 0);
  742. $productData = ProductClass::getById($productId);
  743. if (!$productData) {
  744. util::fail("花材不存在");
  745. }
  746. //2021.04.06改为用product中的成本价+加价
  747. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  748. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  749. util::complete("操作成功");
  750. }
  751. //修改加价
  752. public function actionChangeAddPrice()
  753. {
  754. $productId = Yii::$app->request->post('productId', 0);
  755. $addPrice = Yii::$app->request->post('addPrice', '');
  756. if ($addPrice < 0) {
  757. util::fail("加价不能小于0");
  758. }
  759. $productData = ProductClass::getProductData($productId, $this->mainId);
  760. if (!$productData) {
  761. util::fail("花材不存在");
  762. }
  763. ProductClass::changeAddPrice($productId, $addPrice);
  764. util::complete();
  765. }
  766. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  767. public function actionBatchChangeMore()
  768. {
  769. $shop = $this->shop;
  770. $default = $shop->default ?? 0;
  771. if ($default == 0) {
  772. util::fail('当前直营分店,请返回总店修改');
  773. }
  774. $shopAdmin = $this->shopAdmin;
  775. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  776. util::fail('超管才能操作');
  777. }
  778. $addData = Yii::$app->request->post('addData', '');
  779. if (empty($addData)) {
  780. util::fail('没有花材');
  781. }
  782. $itemData = json_decode($addData, true);
  783. if (is_array($itemData) == false) {
  784. util::fail('没有花材...');
  785. }
  786. $ids = array_column($itemData, 'id');
  787. $infoList = ProductClass::getByIds($ids, null, 'id');
  788. if (empty($infoList)) {
  789. util::fail('没有花材');
  790. }
  791. foreach ($infoList as $info) {
  792. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  793. util::fail('不是你的花材不能修改');
  794. }
  795. }
  796. //总店修改同步到所有门店
  797. $sjId = $shop->sjId ?? 0;
  798. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  799. foreach ($itemData as $key => $data) {
  800. $id = $data['id'] ?? 0;
  801. unset($data['id']);
  802. ProductClass::updateById($id, $data);
  803. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  804. if (empty($ptItemId)) {
  805. continue;
  806. }
  807. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  808. foreach ($chainShopList as $chainShop) {
  809. $currentMainId = $chainShop->mainId ?? 0;
  810. if ($currentMainId == $shop->mainId) {
  811. //前面已经修改过了,不需要重复修改
  812. continue;
  813. }
  814. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  815. }
  816. }
  817. }
  818. util::complete('修改成功');
  819. }
  820. //批量修改加价 ssh 20211211
  821. public function actionBatchChangeAddPrice()
  822. {
  823. $shop = $this->shop;
  824. $join = $shop->join ?? 0;
  825. $default = $shop->default ?? 0;
  826. if ($join == 0 && $default == 0) {
  827. util::fail('当前直营分店,请切回总店操作');
  828. }
  829. $shopAdmin = $this->shopAdmin;
  830. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  831. util::fail('超管才能操作');
  832. }
  833. $post = Yii::$app->request->post();
  834. $addData = $post['addData'] ?? '';
  835. if (empty($addData)) {
  836. util::fail('没有花材');
  837. }
  838. $itemData = json_decode($addData, true);
  839. if (is_array($itemData) == false) {
  840. util::fail('没有花材...');
  841. }
  842. $ids = array_column($itemData, 'id');
  843. $infoList = ProductClass::getByIds($ids, null, 'id');
  844. if (empty($infoList)) {
  845. util::fail('没有花材');
  846. }
  847. foreach ($infoList as $info) {
  848. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  849. util::fail('不能修改别人的花材');
  850. }
  851. }
  852. $appVersion = $post['appVersion'] ?? 0;
  853. if ($appVersion != 1) {
  854. util::fail('请先升级应用');
  855. }
  856. //总店修改同步到所有门店
  857. $sjId = $shop->sjId ?? 0;
  858. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  859. foreach ($itemData as $key => $data) {
  860. $id = $data['id'] ?? 0;
  861. unset($data['id']);
  862. ProductClass::updateById($id, $data);
  863. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  864. if (empty($ptItemId)) {
  865. continue;
  866. }
  867. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  868. foreach ($chainShopList as $chainShop) {
  869. if (isset($chainShop->join) && $chainShop->join == 1) {
  870. continue;
  871. }
  872. $currentMainId = $chainShop->mainId ?? 0;
  873. if ($currentMainId == $shop->mainId) {
  874. //前面已经修改过了,不需要重复修改
  875. continue;
  876. }
  877. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  878. }
  879. }
  880. }
  881. util::complete('修改成功');
  882. }
  883. public function actionUpdate()
  884. {
  885. $shopAdmin = $this->shopAdmin;
  886. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  887. util::fail('超管才能操作');
  888. }
  889. $shop = $this->shop;
  890. $join = $shop->join ?? 0;
  891. $default = $shop->default ?? 0;
  892. if ($join == 0 && $default == 0) {
  893. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  894. if ($shopAdmin->super != 1) {
  895. util::fail('请先开通超管权限');
  896. }
  897. }
  898. $post = Yii::$app->request->post();
  899. $discountPrice = $post['discountPrice'] ?? 0;
  900. if ($discountPrice > 0) {
  901. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  902. $addPrice = $post['addPrice'] ?? 0;
  903. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  904. $skMore = $post['skMore'] ?? 0;
  905. $diff = bcsub($addPrice, $hjAddPrice, 2);
  906. if ($diff > 0 && $discountPrice > $diff) {
  907. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  908. } else {
  909. $hjDiscountPrice = $discountPrice;
  910. }
  911. $diff = bcsub($skMore, $addPrice, 2);
  912. if ($diff > 0) {
  913. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  914. } else {
  915. $skDiscountPrice = $discountPrice;
  916. }
  917. $post['skDiscountPrice'] = $skDiscountPrice;
  918. $post['hjDiscountPrice'] = $hjDiscountPrice;
  919. }
  920. $reachNum = $post['reachNum'] ?? 0;
  921. $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
  922. if ($reachNum > 0 && $reachNumDiscount > 0) {
  923. util::fail('特价和满减不能同时进行');
  924. }
  925. }
  926. $post['adminId'] = $this->adminId;
  927. $post['staffId'] = $this->shopAdmin->id;
  928. $post['staffName'] = $this->shopAdmin->name;
  929. ProductClass::updateProduct($post, $this->shop);
  930. util::complete();
  931. }
  932. //上下架状态控制 ssh 20210713
  933. public function actionStatusUpdate()
  934. {
  935. $post = Yii::$app->request->post();
  936. $shopAdmin = $this->shopAdmin;
  937. $roleId = $shopAdmin['roleId'] ?? 0;
  938. $role = AdminRoleClass::getById($roleId);
  939. $roleName = $role['roleName'] ?? '';
  940. if ($roleName == '员工') {
  941. util::fail('无法操作哦');
  942. }
  943. $id = $post['id'] ?? 0;
  944. $status = $post['status'] ?? 1;
  945. $product = ProductClass::getById($id, true);
  946. if ($product->mainId != $this->mainId) {
  947. util::fail('无法操作');
  948. }
  949. $product->status = $status;
  950. if ($status == 2) {
  951. $product->discountPrice = 0;
  952. }
  953. $product->save();
  954. util::complete();
  955. }
  956. //花材展示状态控制 ssh 20231113
  957. public function actionDelStatusUpdate()
  958. {
  959. $post = Yii::$app->request->post();
  960. $shop = $this->shop;
  961. $join = $shop->join ?? 0;
  962. $default = $shop->default ?? 0;
  963. if ($join == 0 && $default == 0) {
  964. util::fail('请在首店操作');
  965. }
  966. $id = $post['id'] ?? 0;
  967. $delStatus = $post['delStatus'] ?? 0;
  968. $product = ProductClass::getById($id, true);
  969. if ($product->mainId != $this->mainId) {
  970. util::fail('不是你的花材哦!!');
  971. }
  972. $product->delStatus = $delStatus;
  973. if ($delStatus == 1) {
  974. $product->stock = 0;
  975. $product->status = 2;
  976. }
  977. $product->save();
  978. $ptItemId = $product->itemId ?? 0;
  979. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  980. //总店修改同步到所有门店
  981. $sjId = $shop->sjId ?? 0;
  982. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  983. foreach ($chainShopList as $chainShop) {
  984. $chainShopId = $chainShop->id ?? 0;
  985. if (isset($chainShop->join) && $chainShop->join == 1) {
  986. continue;
  987. }
  988. if ($chainShopId == $shop->id) {
  989. continue;
  990. }
  991. $chainMainId = $chainShop->mainId ?? 0;
  992. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  993. if (!empty($chainProduct)) {
  994. $chainProduct->delStatus = $delStatus;
  995. if ($delStatus == 1) {
  996. $chainProduct->stock = 0;
  997. $chainProduct->status = 2;
  998. }
  999. $chainProduct->save();
  1000. }
  1001. }
  1002. }
  1003. util::complete();
  1004. }
  1005. //详情 ruidian 2021.5.3
  1006. public function actionDetail()
  1007. {
  1008. $id = Yii::$app->request->get('id', 0);
  1009. $source = Yii::$app->request->get('source', '');
  1010. $respond = ProductClass::getItemInfo($id);
  1011. $ptItemId = $respond['itemId'] ?? 0;
  1012. $ptItemInfo = PtItemClass::getById($ptItemId);
  1013. $respond['ptItemInfo'] = $ptItemInfo;
  1014. if ($source == 'notify' && $respond['mainId'] == $this->mainId) {
  1015. $staff = $this->shopAdmin;
  1016. $staffId = $this->shopAdminId;
  1017. $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 1, 'targetId' => $id], true);
  1018. if (!empty($notify)) {
  1019. if ($notify->read == 0) {
  1020. $notify->read = 1;
  1021. $notify->save();
  1022. $notifyNum = $staff->notifyNum;
  1023. if ($notifyNum > 0) {
  1024. $notifyNum--;
  1025. $staff->notifyNum = $notifyNum;
  1026. $staff->save();
  1027. }
  1028. }
  1029. }
  1030. }
  1031. util::success($respond);
  1032. }
  1033. //新增花材 2021.6.21
  1034. public function actionAdd()
  1035. {
  1036. $post = Yii::$app->request->post();
  1037. //临时兼容,2023.7.1后可以删除
  1038. $appVersion = $post['appVersion'] ?? 0;
  1039. if ($appVersion != 1) {
  1040. util::fail('请先升级应用');
  1041. }
  1042. $discountPrice = $post['discountPrice'] ?? 0;
  1043. if ($discountPrice > 0) {
  1044. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1045. $addPrice = $post['addPrice'] ?? 0;
  1046. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1047. $skMore = $post['skMore'] ?? 0;
  1048. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1049. if ($diff > 0 && $discountPrice > $diff) {
  1050. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1051. } else {
  1052. $hjDiscountPrice = $discountPrice;
  1053. }
  1054. $diff = bcsub($skMore, $addPrice, 2);
  1055. if ($diff > 0) {
  1056. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1057. } else {
  1058. $skDiscountPrice = $discountPrice;
  1059. }
  1060. $post['skDiscountPrice'] = $skDiscountPrice;
  1061. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1062. }
  1063. }
  1064. $shop = $this->shop;
  1065. $join = $shop->join ?? 0;
  1066. $default = $shop->default ?? 0;
  1067. if ($join == 0 && $default == 0) {
  1068. util::fail('当前直营分店,请切回总店添加花材');
  1069. }
  1070. $shopAdmin = $this->shopAdmin;
  1071. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1072. util::fail('管理员才能添加花材');
  1073. }
  1074. $post['sjId'] = $this->sjId;
  1075. $post['adminId'] = $this->adminId;
  1076. $post['mainId'] = $this->mainId;
  1077. $price = $post['price'] ?? 0;
  1078. $addPrice = $post['addPrice'] ?? 0;
  1079. if ($addPrice > $price) {
  1080. util::fail('加价不能大于售价');
  1081. }
  1082. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  1083. if ($weight <= 0) {
  1084. util::fail('请填写重量,最小0.1');
  1085. }
  1086. $post['staffName'] = $shopAdmin->name ?? '';
  1087. ProductClass::addProduct($post, $this->shop);
  1088. util::complete('添加成功');
  1089. }
  1090. //获取拼音缩写 ssh 20210707
  1091. public function actionPy()
  1092. {
  1093. $name = Yii::$app->request->get('name');
  1094. $py = stringUtil::py($name);
  1095. util::success(['py' => $py]);
  1096. }
  1097. //(客户端-批发商)复制花材
  1098. public function actionClone()
  1099. {
  1100. $post = Yii::$app->request->post();
  1101. $appVersion = $post['appVersion'] ?? 0;
  1102. if ($appVersion != 1) {
  1103. util::fail('请先升级应用');
  1104. }
  1105. $discountPrice = $post['discountPrice'] ?? 0;
  1106. if ($discountPrice > 0) {
  1107. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1108. $addPrice = $post['addPrice'] ?? 0;
  1109. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1110. $skMore = $post['skMore'] ?? 0;
  1111. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1112. if ($diff > 0 && $discountPrice > $diff) {
  1113. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1114. } else {
  1115. $hjDiscountPrice = $discountPrice;
  1116. }
  1117. $diff = bcsub($skMore, $addPrice, 2);
  1118. if ($diff > 0) {
  1119. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1120. } else {
  1121. $skDiscountPrice = $discountPrice;
  1122. }
  1123. $post['skDiscountPrice'] = $skDiscountPrice;
  1124. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1125. }
  1126. }
  1127. $shop = $this->shop;
  1128. $join = $shop->join ?? 0;
  1129. $default = $shop->default ?? 0;
  1130. if ($join == 0 && $default == 0) {
  1131. util::fail('请在首店操作');
  1132. }
  1133. $shopAdmin = $this->shopAdmin;
  1134. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1135. util::fail('管理员才能添加花材');
  1136. }
  1137. $post['sjId'] = $this->sjId;
  1138. $post['adminId'] = $this->adminId;
  1139. $post['mainId'] = $this->mainId;
  1140. $post['staffName'] = $shopAdmin->name ?? '';
  1141. $price = $post['price'] ?? 0;
  1142. if (empty($price) || $price <= 0) {
  1143. util::fail('请填写批发价');
  1144. }
  1145. $skPrice = $post['skPrice'] ?? 0;
  1146. if (empty($skPrice) || $skPrice <= 0) {
  1147. util::fail('请填写零售价');
  1148. }
  1149. $hjPrice = $post['hjPrice'] ?? 0;
  1150. if (empty($hjPrice) || $hjPrice <= 0) {
  1151. util::fail('请填写会员价');
  1152. }
  1153. $addPrice = $post['addPrice'] ?? 0;
  1154. if ($addPrice > $price) {
  1155. util::fail('批发价的加价不能大于售价');
  1156. }
  1157. //复制标识
  1158. $post['copy'] = 1;
  1159. //去除无用的字段
  1160. unset($post['viewNum']);
  1161. unset($post['actualSold']);
  1162. unset($post['itemId']);
  1163. unset($post['id']);
  1164. unset($post['delStatus']);
  1165. ProductClass::addProduct($post, $this->shop);
  1166. util::complete('复制成功');
  1167. }
  1168. //下载价格表 ssh 20210922
  1169. public function actionGeneratePriceTable()
  1170. {
  1171. $level = Yii::$app->request->get('level', 0);
  1172. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1173. $file = $respond['file'] ?? '';
  1174. $shortFile = $respond['shortFile'] ?? '';
  1175. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1176. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1177. }
  1178. public function actionGenerateItemTable()
  1179. {
  1180. $level = Yii::$app->request->get('level', 0);
  1181. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  1182. $file = $respond['file'] ?? '';
  1183. $shortFile = $respond['shortFile'] ?? '';
  1184. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1185. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1186. }
  1187. //下载条形码 lqh 20211227
  1188. public function actionGenerateBarcodeTable()
  1189. {
  1190. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1191. $file = $respond['file'] ?? '';
  1192. $shortFile = $respond['shortFile'] ?? '';
  1193. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1194. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1195. }
  1196. //批量修改花材的分类 ssh 20230405
  1197. public function actionBatchModifyClass()
  1198. {
  1199. $post = Yii::$app->request->post();
  1200. $shop = $this->shop;
  1201. $join = $shop->join ?? 0;
  1202. $default = $shop->default ?? 0;
  1203. if ($join == 0 && $default == 0) {
  1204. util::fail('当前直营分店,请切回总店操作');
  1205. }
  1206. $classId = $post['classId'] ?? 0;
  1207. $class = ItemClassClass::getById($classId, true);
  1208. if (empty($class) || $class->mainId != $this->mainId) {
  1209. util::fail('请选择您自己的分类');
  1210. }
  1211. $connection = Yii::$app->db;
  1212. $transaction = $connection->beginTransaction();
  1213. try {
  1214. $className = $class->name ?? '';
  1215. $idsList = $post['ids'] ?? '';
  1216. $ids = json_decode($idsList, true);
  1217. if (empty($ids)) {
  1218. util::fail('请选择花材');
  1219. }
  1220. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1221. if (empty($list)) {
  1222. util::fail('请选择花材');
  1223. }
  1224. $ptItemList = [];
  1225. foreach ($list as $item) {
  1226. $name = $item->name ?? '';
  1227. if ($item->mainId != $this->mainId) {
  1228. util::fail($name . '不是您的花材');
  1229. }
  1230. $item->classId = $classId;
  1231. $item->save();
  1232. $ptItemId = $item->itemId ?? 0;
  1233. $ptItemList[] = $ptItemId;
  1234. }
  1235. $shop = $this->shop;
  1236. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1237. //总店修改同步到所有门店
  1238. $sjId = $shop->sjId ?? 0;
  1239. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1240. foreach ($chainShopList as $chainShop) {
  1241. $chainShopId = $chainShop->id ?? 0;
  1242. if ($chainShopId == $shop->id) {
  1243. continue;
  1244. }
  1245. $chainManId = $chainShop->mainId ?? 0;
  1246. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1247. if (!empty($chainAllClassList)) {
  1248. foreach ($chainAllClassList as $chainClass) {
  1249. $chainName = $chainClass->name ?? '';
  1250. $chainClassId = $chainClass->id ?? 0;
  1251. if ($chainName == $className) {
  1252. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1253. if (!empty($chainProductList)) {
  1254. foreach ($chainProductList as $currentProduct) {
  1255. $currentProduct->classId = $chainClassId;
  1256. $currentProduct->save();
  1257. }
  1258. }
  1259. }
  1260. }
  1261. }
  1262. }
  1263. }
  1264. $transaction->commit();
  1265. util::complete('修改成功');
  1266. } catch (\Exception $e) {
  1267. $transaction->rollBack();
  1268. Yii::info("修改失败原因:" . $e->getMessage());
  1269. util::fail('修改失败');
  1270. }
  1271. }
  1272. }