PurchaseOrderController.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\sj\classes\SjClass;
  5. use biz\wx\classes\WxMessageClass;
  6. use bizGhs\book\classes\BookItemClass;
  7. use bizGhs\order\classes\PurchaseOrderClass;
  8. use bizGhs\order\classes\PurchaseOrderItemClass;
  9. use bizGhs\product\classes\ProductClass;
  10. use bizGhs\shop\classes\ShopClass;
  11. use bizHd\purchase\classes\PurchaseClass;
  12. use common\components\dict;
  13. use common\components\noticeUtil;
  14. use common\components\printUtil;
  15. use common\components\stringUtil;
  16. use common\components\util;
  17. use biz\shop\classes\ShopExtClass;
  18. use Yii;
  19. class PurchaseOrderController extends BaseController
  20. {
  21. public $guestAccess = ['detail', 'check-seat-update', 'assign-seat'];
  22. //打印多联 ssh 2024509
  23. public function actionPrintPaper()
  24. {
  25. $get = Yii::$app->request->get();
  26. $id = $get['id'] ?? 0;
  27. $cg = PurchaseOrderClass::getById($id, true);
  28. if (empty($cg)) {
  29. util::fail('没有找到采购信息');
  30. }
  31. if ($cg->mainId != $this->mainId) {
  32. util::fail('不是你的采购单哦');
  33. }
  34. if ($cg->status != 4) {
  35. util::fail('请先确认入库');
  36. }
  37. $orderSn = $cg->orderSn ?? '';
  38. //增加打印次数
  39. PurchaseOrderClass::addPrintNum($cg);
  40. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  41. $table = [];
  42. $totalItemNum = 0;
  43. $kind = 0;
  44. if (!empty($itemList)) {
  45. foreach ($itemList as $key => $val) {
  46. $kind++;
  47. $currentName = $val['name'] ?? '';
  48. $preNum = $val['itemNum'] ?? 0;
  49. $preNum = floatval($preNum);
  50. $refundNum = $val['refundNum'] ?? 0;
  51. $num = bcsub($preNum, $refundNum);
  52. $totalItemNum = bcadd($totalItemNum, $num);
  53. $unitPrice = $val['bigPrice'] ?? 0;
  54. $unitPrice = floatval($unitPrice);
  55. $orderNum = bcadd($key, 1);
  56. $currentPrice = $val['totalPrice'] ?? 0;
  57. $currentPrice = floatval($currentPrice);
  58. $table[] = [
  59. 'orderNum' => $orderNum,
  60. 'name' => $currentName,
  61. 'num' => $preNum,
  62. 'unitPrice' => '¥' . $unitPrice,
  63. 'refundNum' => $refundNum,
  64. 'remark' => '',
  65. 'price' => '¥' . $currentPrice,
  66. ];
  67. }
  68. }
  69. $shortOrderSn = substr($orderSn, -4);
  70. $ghsName = $cg->ghsName ?? '';
  71. $entryTime = $cg->entryTime ?? '';
  72. $entryTime = substr($entryTime, 0, 16);
  73. $addTime = $cg->addTime ?? '';
  74. $addTime = substr($addTime, 0, 16);
  75. $shopAdminName = $cg->shopAdminName ?? '';
  76. $shopId = $cg->shopId ?? 0;
  77. $shop = ShopClass::getById($shopId, true);
  78. $telephone = $shop->telephone ?? '';
  79. $shopName = $shop->shopName ?? '';
  80. $sjId = $shop->sjId ?? 0;
  81. $sj = SjClass::getById($sjId, true);
  82. $sjName = $sj->name ?? '';
  83. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  84. $prePrice = $cg->prePrice ?? 0;
  85. $prePrice = floatval($prePrice);
  86. $tkPrice = $cg->tkPrice ?? 0;
  87. $tkPrice = floatval($tkPrice);
  88. $realPrice = $cg->realPrice ?? 0;
  89. $realPrice = floatval($realPrice);
  90. $printData = [
  91. 'table' => $table,
  92. 'addTime' => $addTime,
  93. 'entryTime' => $entryTime,
  94. 'ghsName' => $ghsName,
  95. 'clearCode' => $shortOrderSn,
  96. 'staffName' => $shopAdminName,
  97. 'telephone' => $telephone,
  98. 'kind' => $kind,
  99. 'orderSn' => $orderSn,
  100. 'sjShopName' => $sjShopName . ' 采购单',
  101. 'prePrice' => '¥' . $prePrice,
  102. 'tkPrice' => '¥' . $tkPrice,
  103. 'realPrice' => '¥' . $realPrice,
  104. 'totalItemNum' => $totalItemNum,
  105. 'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
  106. ];
  107. $template = '{"panels":[{"index":0,"name":1,"height":140,"width":210,"paperHeader":49.5,"paperFooter":383.4343434343434,"printElements":[{"options":{"left":115,"top":20,"height":25,"width":374,"title":"文本","right":488.99609375,"bottom":44.9921875,"vCenter":301.99609375,"hCenter":32.4921875,"field":"sjShopName","testData":"小向花卉 采购单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":22.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":148.9921875,"bottom":43.9921875,"vCenter":85.9921875,"hCenter":33.4921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":445,"top":25,"height":22,"width":122,"title":"核销码","field":"clearCode","testData":"3961","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571.25,"bottom":46.75,"vCenter":510.25,"hCenter":35.75,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":55,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"center","tableHeaderFontWeight":"bold","right":572.5,"bottom":90.99609375,"vCenter":297.5,"hCenter":72.99609375,"fontFamily":"SimSun","columns":[[{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":true,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":true,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":true,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":true,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":192.5,"top":120,"height":16,"width":178,"title":"制单时间","field":"addTime","testData":"2024-12-28 11:00","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":359.49609375,"bottom":146.9921875,"vCenter":276.99609375,"hCenter":138.9921875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":365,"top":120,"height":16,"width":178,"title":"供货商","field":"ghsName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":573.49609375,"bottom":145.99609375,"vCenter":484.49609375,"hCenter":137.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":120,"height":16,"width":175,"title":"入库时间","right":141.75,"bottom":139.5,"vCenter":81.75,"hCenter":134.625,"field":"entryTime","testData":"2024-12-29 12:10","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":132.5,"top":145,"height":16,"width":90,"title":"售后","right":262.74609375,"bottom":161.2421875,"vCenter":202.74609375,"hCenter":153.2421875,"field":"tkPrice","testData":"63","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":222.5,"top":145,"height":16,"width":114,"title":"实际金额","field":"realPrice","testData":"23","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":358.9921875,"bottom":160.99609375,"vCenter":301.9921875,"hCenter":152.99609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":347.5,"top":145,"height":16,"width":120,"title":"电话","field":"telephone","testData":"15280215347","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":467.7421875,"bottom":161.2421875,"vCenter":407.7421875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":425,"top":145,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":574.4921875,"bottom":161.2421875,"vCenter":500.4921875,"hCenter":153.2421875,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":27.5,"top":145,"height":16,"width":105,"title":"合计","field":"prePrice","testData":"693","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":144,"bottom":160.24609375,"vCenter":85.5,"hCenter":152.24609375,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":170,"height":16,"width":120,"field":"numKind","testData":"共3种,数量:9","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"textContentVerticalAlign":"middle","qrCodeLevel":0,"title":"文本","fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":389,"paperNumberDisabled":true,"paperNumberContinue":true,"orient":1,"watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  108. util::success(['template' => $template, 'printData' => $printData]);
  109. }
  110. //修改货位号 ssh 20240410
  111. public function actionModifySeatSn()
  112. {
  113. $get = Yii::$app->request->get();
  114. $id = $get['id'] ?? 0;
  115. $seatSn = $get['seatSn'] ?? '';
  116. $cg = PurchaseOrderClass::getById($id, true);
  117. if (empty($cg)) {
  118. util::fail('没有找到采购单');
  119. }
  120. if ($cg->mainId != $this->mainId) {
  121. util::fail('没有权限');
  122. }
  123. $cg->seatSn = $seatSn;
  124. $cg->save();
  125. }
  126. //获取零售端在进行中的订单 ssh 20231201
  127. public function actionGetLsRunningOrderNum()
  128. {
  129. $lsFhNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 2]);
  130. $lsShNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 3]);
  131. util::success(['lsFhNum' => $lsFhNum, 'lsShNum' => $lsShNum]);
  132. }
  133. //打印小票 ssh 20230608
  134. public function actionPrintBill()
  135. {
  136. $get = Yii::$app->request->get();
  137. $id = $get['id'] ?? 0;
  138. $order = $get['order'] ?? 1;
  139. $cg = PurchaseOrderClass::getById($id, true);
  140. if (empty($cg)) {
  141. util::fail('没有找到采购单');
  142. }
  143. if ($cg->mainId != $this->mainId) {
  144. util::fail('没有权限');
  145. }
  146. if (getenv('YII_ENV') == 'production') {
  147. //小向的采购单要打印二张
  148. if ($this->mainId == 23390) {
  149. //PurchaseOrderClass::printTicket($cg, false, $order);
  150. }
  151. }
  152. PurchaseOrderClass::printTicket($cg, false, $order);
  153. util::complete();
  154. }
  155. //增加打印次数 ssh 20240511
  156. public function actionAddPrintNum()
  157. {
  158. util::complete();
  159. }
  160. //打印全部 ssh 20220602
  161. public function actionPrintAll()
  162. {
  163. $get = Yii::$app->request->get();
  164. $orderSn = $get['orderSn'] ?? 0;
  165. $type = $get['type'] ?? 0;
  166. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  167. if (empty($itemList)) {
  168. util::fail('没有商品');
  169. }
  170. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  171. $mainId = $order->mainId ?? 0;
  172. $ext = $this->shopExt;
  173. $printLabelSn = $ext->printLabelSn ?? '';
  174. if (empty($printLabelSn)) {
  175. util::fail('请设置标签打印机');
  176. }
  177. $p = new printUtil($printLabelSn);
  178. foreach ($itemList as $key => $item) {
  179. $name = $item->name ?? '';
  180. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  181. if (empty($num)) {
  182. util::fail('没有花材数量');
  183. }
  184. $ptItemId = $item->itemId ?? '';
  185. $productId = $item->productId ?? 0;
  186. $p->times = $num;
  187. $smallUnit = $item->smallUnit ?? '';
  188. $bigUnit = $item->bigUnit ?? '';
  189. $ratio = $item->ratio ?? 0;
  190. $unit = $ratio . $smallUnit . '/' . $bigUnit;
  191. if (isset($item->ratioType) && $item->ratioType == 1) {
  192. $unit = '若干' . $smallUnit . '/' . $bigUnit;
  193. }
  194. if (stringUtil::getWordNum($name) > 7) {
  195. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  196. } else {
  197. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  198. }
  199. if ($key % 2 == 1) {
  200. $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="0">.</TEXT>';
  201. }
  202. if ($type == 0) {
  203. $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $ptItemId . '</BC128>';
  204. if (in_array($mainId, [52, 1459])) {
  205. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  206. } else {
  207. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  208. }
  209. } else {
  210. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
  211. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  212. }
  213. $p->printLabelMsg($content);
  214. }
  215. util::complete();
  216. }
  217. //打印全部 ssh 20220
  218. public function actionPrintItem()
  219. {
  220. $get = Yii::$app->request->get();
  221. $id = $get['id'] ?? 0;
  222. $type = $get['type'] ?? 0;
  223. $item = PurchaseOrderItemClass::getById($id, true);
  224. if (empty($item)) {
  225. util::fail('没有找到花材');
  226. }
  227. $name = $item->name ?? '';
  228. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  229. if (empty($num)) {
  230. util::fail('没有花材数量');
  231. }
  232. $orderSn = $item->orderSn ?? '';
  233. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  234. $mainId = $order->mainId ?? 0;
  235. $ext = $this->shopExt;
  236. $printLabelSn = $ext->printLabelSn ?? '';
  237. if (empty($printLabelSn)) {
  238. util::fail('请设置标签打印机');
  239. }
  240. $p = new printUtil($printLabelSn);
  241. $productId = $item->productId ?? 0;
  242. $product = ProductClass::getById($productId, true);
  243. $smallUnit = $product->smallUnit ?? '';
  244. $bigUnit = $product->bigUnit ?? '';
  245. $ratio = $product->ratio ?? 20;
  246. $ratioType = $product->ratioType ?? 0;
  247. if ($ratioType == 1) {
  248. $unit = '若干' . $smallUnit . '/' . $bigUnit;
  249. } else {
  250. $unit = $ratio . $smallUnit . '/' . $bigUnit;
  251. }
  252. $ptItemId = $item->itemId ?? '';
  253. $p->times = $num;
  254. if (stringUtil::getWordNum($name) > 7) {
  255. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  256. } else {
  257. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  258. }
  259. if ($type == 0) {
  260. $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $ptItemId . '</BC128>';
  261. if (in_array($mainId, [52, 1459])) {
  262. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  263. } else {
  264. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  265. }
  266. } else {
  267. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
  268. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  269. }
  270. $p->printLabelMsg($content);
  271. util::complete();
  272. }
  273. //取消入库单 ssh 20221211
  274. public function actionCancel()
  275. {
  276. $get = Yii::$app->request->get();
  277. $id = $get['id'] ?? 0;
  278. $cg = PurchaseOrderClass::getLockById($id);
  279. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  280. util::fail('请确认是否您的采购单');
  281. }
  282. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_CANCEL) {
  283. util::fail('已取消过了');
  284. }
  285. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
  286. util::fail('已入库,无法取消');
  287. }
  288. $connection = Yii::$app->db;
  289. $transaction = $connection->beginTransaction();
  290. try {
  291. $shop = $this->shop;
  292. $staff = $this->shopAdmin;
  293. $staffId = $staff->id ?? 0;
  294. $staffName = $staff->name ?? '';
  295. $params = ['staffId' => $staffId, 'staffName' => $staffName, 'staff' => $staff];
  296. PurchaseOrderClass::cancel($cg, $shop, $params);
  297. $transaction->commit();
  298. util::complete();
  299. } catch (\Exception $e) {
  300. util::fail('取消失败');
  301. }
  302. }
  303. //确认入库 sssh 20221211
  304. public function actionConfirmPutIn()
  305. {
  306. ini_set('memory_limit', '2045M');
  307. set_time_limit(0);
  308. $shopAdmin = $this->shopAdmin;
  309. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  310. util::fail('超管才能修改');
  311. }
  312. $connection = Yii::$app->db;
  313. $transaction = $connection->beginTransaction();
  314. try {
  315. $get = Yii::$app->request->get();
  316. $id = $get['id'] ?? 0;
  317. $cg = PurchaseOrderClass::getLockById($id);
  318. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  319. util::fail('请确认是否您的采购单');
  320. }
  321. //解决重复请求问题
  322. $cacheKey = 'confirm_put_in_action_' . $id;
  323. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  324. if (!empty($has)) {
  325. util::fail('请5秒后操作');
  326. }
  327. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  328. $staff = $this->shopAdmin;
  329. $data = [];
  330. $data['staffId'] = $staff->id ?? 0;
  331. $data['staffName'] = $staff->name ?? '';
  332. $data['adminId'] = $this->adminId ?? 0;
  333. $data['shop'] = $this->shop;
  334. $return = PurchaseOrderClass::putIn($cg, $data);
  335. $transaction->commit();
  336. //入库成功通知相关人员,关键词 put_in_notice
  337. //$shop = $this->shop;
  338. //WxMessageClass::ghsCgEntryInform($shop, $cg);
  339. util::success($return);
  340. } catch (\Exception $e) {
  341. $transaction->rollBack();
  342. noticeUtil::push('确认入库失败,原因:' . $e->getMessage(), '15280215347');
  343. Yii::error("确认入库失败,原因:" . $e->getMessage());
  344. util::fail('确认失败');
  345. }
  346. }
  347. //新增采购订单
  348. public function actionCreateOrder()
  349. {
  350. ini_set('memory_limit', '2045M');
  351. set_time_limit(0);
  352. $post = Yii::$app->request->post();
  353. $post['sjId'] = $this->sjId;
  354. $post['shopId'] = $this->shopId;
  355. $post['adminId'] = $this->adminId;
  356. $post['mainId'] = $this->mainId;
  357. $staff = $this->shopAdmin;
  358. //以下二个都需要保留
  359. $post['staffId'] = $staff->id ?? 0;
  360. $post['staffName'] = $staff->name ?? '';
  361. $post['shopAdminId'] = $staff->id ?? 0;
  362. $post['shopAdminName'] = $staff->name ?? '';
  363. $shopAdmin = $this->shopAdmin;
  364. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  365. util::fail('超管才能修改');
  366. }
  367. if (getenv('YII_ENV') == 'production') {
  368. //小向花卉采购控制
  369. if ($this->mainId == 23390) {
  370. if (!in_array($this->adminId, [24586, 24115, 24759, 26390])) {
  371. util::fail('你不能采购哦');
  372. }
  373. }
  374. }
  375. $shop = $this->shop;
  376. $carSale = $shop->carSale ?? 0;
  377. if ($carSale == 1) {
  378. util::fail('车销不能采购');
  379. }
  380. $connection = Yii::$app->db;
  381. $transaction = $connection->beginTransaction();
  382. try {
  383. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  384. $ghsItemInfo = $post['itemInfo'] ?? '';
  385. if (empty($ghsItemInfo)) {
  386. util::fail('请选择花材');
  387. }
  388. $ghsItemInfo = json_decode($ghsItemInfo, true);
  389. if (!is_array($ghsItemInfo)) {
  390. util::fail('花材格式不正确');
  391. }
  392. //合并
  393. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  394. //判断花材格式,是否属于当前门店
  395. ProductClass::valid($ghsItemInfo, $this->mainId);
  396. $cgStaffId = $post['cgStaffId'] ?? 0;
  397. if (empty($cgStaffId)) {
  398. $mainId = $this->mainId;
  399. if (getenv('YII_ENV') == 'production') {
  400. //花大苪、鹏诚康乃馨 采购入库必须选择采购人
  401. if (in_array($mainId, [8164, 19606])) {
  402. util::fail('请选择采购人');
  403. }
  404. } else {
  405. if (in_array($mainId, [])) {
  406. util::fail('请选择采购人');
  407. }
  408. }
  409. }
  410. //获取供货商信息
  411. $ghsId = $post['ghsId'];
  412. if (empty($ghsId)) {
  413. util::fail("请选择供货商");
  414. }
  415. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  416. GhsClass::valid($ghsInfo, $this->shopId);
  417. $post['ghsInfo'] = json_encode($ghsInfo);
  418. $post['ghsName'] = $ghsInfo['name'] ?? '';
  419. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  420. $shop = $this->shop;
  421. $bookSn = $shop->bookSn ?? 0;
  422. //只查我负责的花材
  423. $globalCgMyCharge = $post['globalCgMyCharge'] ?? 0;
  424. $needCgList = [];
  425. if ($globalCgMyCharge == 1) {
  426. $staffId = $staff->id ?? 0;
  427. if (!empty($bookSn)) {
  428. $bList = BookItemClass::getAllByCondition(['bookSn' => $bookSn, 'cgStaffId' => $staffId], null, '*', null, true);
  429. if (!empty($bList)) {
  430. $myIds = [];
  431. foreach ($bList as $bInfo) {
  432. $biProductId = $bInfo->itemId ?? 0;
  433. if ($bInfo->needCgNum > 0) {
  434. $myIds[] = $biProductId;
  435. $needCgList[$biProductId] = $bInfo->needCgNum;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. //判断花材里的信息
  442. foreach ($ghsItemInfo as $v) {
  443. $bigNum = $v['bigNum'] ?? 0;
  444. $productId = $v['productId'] ?? 0;
  445. $smallNum = $v['smallNum'] ?? 0;
  446. $name = $v['name'] ?? '';
  447. if (!isset($v['itemPrice'])) {
  448. util::fail('采购价格不能为空');
  449. }
  450. if (!$productId) {
  451. util::fail('花材不存在');
  452. }
  453. if ($bigNum <= 0 && $smallNum <= 0) {
  454. util::fail('花材数量不能为0');
  455. }
  456. if ($globalCgMyCharge == 1) {
  457. if (isset($needCgList[$productId]) == false) {
  458. util::fail($name . ' 不需要采购');
  459. }
  460. $needNum = $needCgList[$productId];
  461. if ($bigNum > $needNum) {
  462. util::fail($name . ' 只要采' . $needNum . '份');
  463. }
  464. }
  465. }
  466. $post['itemInfo'] = $ghsItemInfo;
  467. //0稍后入库 1直接入库
  468. $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
  469. if ($inType == 1 && !empty($bookSn)) {
  470. util::fail('开启预订不能直接入库');
  471. }
  472. $post['bookSn'] = $bookSn;
  473. $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
  474. $post['debt'] = $debtStatus;
  475. $order = PurchaseOrderClass::addOrder($post);
  476. //如果是附近供货商,则采购单标记为外采单
  477. if (isset($ghsInfo['location']) && $ghsInfo['location'] == 1) {
  478. $order->location = 1;
  479. $order->save();
  480. }
  481. $transaction->commit();
  482. if (isset($order->needPrint) && $order->needPrint == 1) {
  483. PurchaseOrderClass::printTicket($order);
  484. }
  485. if (!empty($bookSn) && $inType == 0) {
  486. //如果是昆明批发,有开启预订则直接分配货位
  487. $key = 'ghs_cg_order_scan_seat_' . $order->id;
  488. $noLock = util::lock($key);
  489. if ($noLock) {
  490. //没有锁定,即没有在分配货位,可以进行货位分配
  491. $params = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name];
  492. PurchaseOrderClass::assign($order, $shop, $params);
  493. util::unlock($key);
  494. }
  495. }
  496. util::success($order);
  497. } catch (\Exception $e) {
  498. $transaction->rollBack();
  499. noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
  500. Yii::error("操作失败原因:" . $e->getMessage());
  501. util::fail('操作失败');
  502. }
  503. }
  504. //分配货位号 ssh 20240619
  505. public function actionAssignSeat()
  506. {
  507. $get = Yii::$app->request->get();
  508. $id = $get['id'] ?? 0;
  509. $salt = $get['salt'] ?? '';
  510. $cg = PurchaseOrderClass::getById($id, true);
  511. if (empty($cg)) {
  512. util::fail('没有找到采购单');
  513. }
  514. //不是待入库状态不需要分配
  515. if ($cg->status != 3) {
  516. util::success(['assign' => 0, 'hint' => 'cg is no wait for entry']);
  517. }
  518. $cgBookSn = $cg->bookSn ?? 0;
  519. if (empty($cgBookSn)) {
  520. util::success(['assign' => 0, 'hint' => 'cg bookSn is empty']);
  521. }
  522. $adminId = $this->adminId;
  523. if (!empty($adminId)) {
  524. if ($cg->mainId != $this->mainId) {
  525. util::success(['assign' => 0, 'hint' => 'cg mainId != this mainId']);
  526. }
  527. $shop = $this->shop;
  528. $bookSn = $shop->bookSn ?? 0;
  529. if ($bookSn != $cgBookSn) {
  530. util::success(['assign' => 0, 'hint' => 'shop bookSn != cg bookSn']);
  531. }
  532. $staff = $this->shopAdmin;
  533. $staffId = $staff->id ?? 0;
  534. $staffName = $staff->name ?? '';
  535. $params = ['staffId' => $staffId, 'staffName' => $staffName];
  536. } else {
  537. if ($cg->salt != $salt) {
  538. util::success(['assign' => 0, 'hint' => 'cg salt != post salt']);
  539. }
  540. $shopId = $cg->shopId ?? 0;
  541. $shop = ShopClass::getById($shopId, true);
  542. if (empty($shop)) {
  543. util::success(['assign' => 0, 'hint' => 'shop empty']);
  544. }
  545. if ($shop->bookSn != $cgBookSn) {
  546. util::success(['assign' => 0, 'hint' => 'shop bookSn != cg bookSn o']);
  547. }
  548. $staffId = $cg->shopAdminId ?? 0;
  549. $staffName = $cg->shopAdminName ?? '';
  550. $params = ['staffId' => $staffId, 'staffName' => $staffName];
  551. }
  552. $connection = Yii::$app->db;
  553. $transaction = $connection->beginTransaction();
  554. try {
  555. PurchaseOrderClass::assign($cg, $shop, $params);
  556. $transaction->commit();
  557. util::success(['assign' => 1]);
  558. } catch (\Exception $e) {
  559. $transaction->rollBack();
  560. util::fail('获取失败');
  561. }
  562. }
  563. //订单列表
  564. public function actionList()
  565. {
  566. $where = [];
  567. $get = Yii::$app->request->get();
  568. $where['shopId'] = $this->shopId;
  569. $orderStatus = $get['status'] ?? '';
  570. if ($orderStatus) {
  571. $where['status'] = $orderStatus;
  572. }
  573. $ghsId = $get['ghsId'] ?? 0;
  574. if (!empty($ghsId)) {
  575. $where['ghsId'] = $ghsId;
  576. }
  577. $data = PurchaseOrderClass::getOrderList($where);
  578. //状态统计,很慢,暂时隐藏
  579. //$statData = PurchaseOrderClass::statNum($this->shopId);
  580. $statData = [
  581. 'allNum' => 0,
  582. 'unPayNum' => 0,
  583. 'unSendNum' => 0,
  584. 'sendingNum' => 0,
  585. 'finishNum' => 0,
  586. ];
  587. $data = array_merge($data, $statData);
  588. util::success($data);
  589. }
  590. //订单详情
  591. public function actionDetail()
  592. {
  593. $get = Yii::$app->request->get();
  594. $orderSn = $get['orderSn'] ?? '';
  595. $salt = $get['salt'] ?? '';
  596. $adminId = $this->adminId ?? 0;
  597. if (!empty($adminId)) {
  598. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  599. } else {
  600. $info = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  601. if (empty($info)) {
  602. util::fail('没有找到采购单');
  603. }
  604. if ($info->salt != $salt) {
  605. util::fail('不是你的采购单');
  606. }
  607. $shopId = $info->shopId ?? 0;
  608. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $shopId);
  609. }
  610. util::success($orderData);
  611. }
  612. //采购页,定时检测货位有没更新 ssh 20240709
  613. public function actionCheckSeatUpdate()
  614. {
  615. $get = Yii::$app->request->get();
  616. $orderSn = $get['orderSn'] ?? '';
  617. $salt = $get['salt'] ?? '';
  618. if (empty($orderSn)) {
  619. util::success(['need' => 0, 'hint' => 'empty orderSn']);
  620. }
  621. $cg = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  622. if (empty($cg)) {
  623. util::success(['need' => 0, 'hint' => 'empty cg info']);
  624. }
  625. $adminId = $this->adminId ?? 0;
  626. $cgId = $cg->id ?? 0;
  627. $cgBookSn = $cg->bookSn ?? 0;
  628. if (!empty($adminId)) {
  629. if ($cg->mainId != $this->mainId) {
  630. util::success(['need' => 0, 'hint' => 'cgMainId != thisMainId']);
  631. }
  632. $shop = $this->shop;
  633. $shopBookSn = $shop->bookSn ?? 0;
  634. if (empty($shopBookSn)) {
  635. util::success(['need' => 0, 'hint' => 'empty shopBookSn']);
  636. }
  637. if ($shopBookSn != $cgBookSn) {
  638. util::success(['need' => 0, 'hint' => 'shopBookSn!=cgBookSn']);
  639. }
  640. $cacheKey = 'ghs_cg_order_staff_refresh_seat_' . $cgBookSn;
  641. $staff = $this->shopAdmin;
  642. $staffId = $staff->id ?? 0;
  643. $element = $cgId . '-' . $staffId;
  644. $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $element]);
  645. if (!empty($exists)) {
  646. Yii::$app->redis->executeCommand('SREM', [$cacheKey, $element]);
  647. util::success(['need' => 1]);
  648. }
  649. } else {
  650. if ($cg->salt != $salt) {
  651. util::success(['need' => 0, 'hint' => 'cg salt != post salt']);
  652. }
  653. $cacheKey = 'ghs_cg_order_guest_refresh_seat_' . $cgBookSn;
  654. $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $cgId]);
  655. if (!empty($exists)) {
  656. Yii::$app->redis->executeCommand('SREM', [$cacheKey, $cgId]);
  657. util::success(['need' => 1]);
  658. }
  659. }
  660. util::success(['need' => 0, 'hint' => 'real no need']);
  661. }
  662. //修改备注
  663. public function actionUpdateRemark()
  664. {
  665. $remark = Yii::$app->request->post('remark', '');
  666. $id = Yii::$app->request->post('id', '');
  667. $cg = PurchaseOrderClass::getById($id, true);
  668. if (empty($cg)) {
  669. util::fail('没有找到订单');
  670. }
  671. if ($cg->shopId != $this->shopId) {
  672. util::fail('没有权限修改');
  673. }
  674. $cg->remark = $remark;
  675. $cg->save();
  676. util::complete('修改成功');
  677. }
  678. }