ProductController.php 58 KB

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