ProductController.php 52 KB

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