PurchaseOrderController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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\order\classes\PurchaseOrderClass;
  7. use bizGhs\order\classes\PurchaseOrderItemClass;
  8. use bizGhs\product\classes\ProductClass;
  9. use bizGhs\shop\classes\ShopClass;
  10. use bizHd\purchase\classes\PurchaseClass;
  11. use common\components\dict;
  12. use common\components\noticeUtil;
  13. use common\components\printUtil;
  14. use common\components\stringUtil;
  15. use common\components\util;
  16. use biz\shop\classes\ShopExtClass;
  17. use Yii;
  18. class PurchaseOrderController extends BaseController
  19. {
  20. //打印多联 ssh 2024509
  21. public function actionPrintPaper()
  22. {
  23. $get = Yii::$app->request->get();
  24. $id = $get['id'] ?? 0;
  25. $cg = PurchaseOrderClass::getById($id, true);
  26. if (empty($cg)) {
  27. util::fail('没有找到采购信息');
  28. }
  29. if ($cg->mainId != $this->mainId) {
  30. util::fail('不是你的采购单哦');
  31. }
  32. if ($cg->status != 4) {
  33. util::fail('请先确认入库');
  34. }
  35. $orderSn = $cg->orderSn ?? '';
  36. //增加打印次数
  37. PurchaseOrderClass::addPrintNum($cg);
  38. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  39. $table = [];
  40. $totalItemNum = 0;
  41. $kind = 0;
  42. if (!empty($itemList)) {
  43. foreach ($itemList as $key => $val) {
  44. $kind++;
  45. $currentName = $val['name'] ?? '';
  46. $preNum = $val['itemNum'] ?? 0;
  47. $preNum = floatval($preNum);
  48. $refundNum = $val['refundNum'] ?? 0;
  49. $num = bcsub($preNum, $refundNum);
  50. $totalItemNum = bcadd($totalItemNum, $num);
  51. $unitPrice = $val['bigPrice'] ?? 0;
  52. $unitPrice = floatval($unitPrice);
  53. $orderNum = bcadd($key, 1);
  54. $currentPrice = $val['totalPrice'] ?? 0;
  55. $currentPrice = floatval($currentPrice);
  56. $table[] = [
  57. 'orderNum' => $orderNum,
  58. 'name' => $currentName,
  59. 'num' => $preNum,
  60. 'unitPrice' => '¥' . $unitPrice,
  61. 'refundNum' => $refundNum,
  62. 'remark' => '',
  63. 'price' => '¥' . $currentPrice,
  64. ];
  65. }
  66. }
  67. $shortOrderSn = substr($orderSn, -4);
  68. $ghsName = $cg->ghsName ?? '';
  69. $entryTime = $cg->entryTime ?? '';
  70. $entryTime = substr($entryTime, 0, 16);
  71. $addTime = $cg->addTime ?? '';
  72. $addTime = substr($addTime, 0, 16);
  73. $shopAdminName = $cg->shopAdminName ?? '';
  74. $shopId = $cg->shopId ?? 0;
  75. $shop = ShopClass::getById($shopId, true);
  76. $telephone = $shop->telephone ?? '';
  77. $shopName = $shop->shopName ?? '';
  78. $sjId = $shop->sjId ?? 0;
  79. $sj = SjClass::getById($sjId, true);
  80. $sjName = $sj->name ?? '';
  81. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  82. $prePrice = $cg->prePrice ?? 0;
  83. $prePrice = floatval($prePrice);
  84. $tkPrice = $cg->tkPrice ?? 0;
  85. $tkPrice = floatval($tkPrice);
  86. $realPrice = $cg->realPrice ?? 0;
  87. $realPrice = floatval($realPrice);
  88. $printData = [
  89. 'table' => $table,
  90. 'addTime' => $addTime,
  91. 'entryTime' => $entryTime,
  92. 'ghsName' => $ghsName,
  93. 'clearCode' => $shortOrderSn,
  94. 'staffName' => $shopAdminName,
  95. 'telephone' => $telephone,
  96. 'kind' => $kind,
  97. 'orderSn' => $orderSn,
  98. 'sjShopName' => $sjShopName . ' 采购单',
  99. 'prePrice' => '¥' . $prePrice,
  100. 'tkPrice' => '¥' . $tkPrice,
  101. 'realPrice' => '¥' . $realPrice,
  102. 'totalItemNum' => $totalItemNum,
  103. 'numKind' => "共" . $kind . "种,数量:" . $totalItemNum,
  104. ];
  105. $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}}]}';
  106. util::success(['template' => $template, 'printData' => $printData]);
  107. }
  108. //修改货位号 ssh 20240410
  109. public function actionModifySeatSn()
  110. {
  111. $get = Yii::$app->request->get();
  112. $id = $get['id'] ?? 0;
  113. $seatSn = $get['seatSn'] ?? '';
  114. $cg = PurchaseOrderClass::getById($id, true);
  115. if (empty($cg)) {
  116. util::fail('没有找到采购单');
  117. }
  118. if ($cg->mainId != $this->mainId) {
  119. util::fail('没有权限');
  120. }
  121. $cg->seatSn = $seatSn;
  122. $cg->save();
  123. }
  124. //获取零售端在进行中的订单 ssh 20231201
  125. public function actionGetLsRunningOrderNum()
  126. {
  127. $lsFhNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 2]);
  128. $lsShNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 3]);
  129. util::success(['lsFhNum' => $lsFhNum, 'lsShNum' => $lsShNum]);
  130. }
  131. //打印小票 ssh 20230608
  132. public function actionPrintBill()
  133. {
  134. $get = Yii::$app->request->get();
  135. $id = $get['id'] ?? 0;
  136. $order = $get['order'] ?? 1;
  137. $cg = PurchaseOrderClass::getById($id, true);
  138. if (empty($cg)) {
  139. util::fail('没有找到采购单');
  140. }
  141. if ($cg->mainId != $this->mainId) {
  142. util::fail('没有权限');
  143. }
  144. if (getenv('YII_ENV') == 'production') {
  145. //小向的采购单要打印二张
  146. if ($this->mainId == 23390) {
  147. //PurchaseOrderClass::printTicket($cg, false, $order);
  148. }
  149. }
  150. PurchaseOrderClass::printTicket($cg, false, $order);
  151. util::complete();
  152. }
  153. //增加打印次数 ssh 20240511
  154. public function actionAddPrintNum()
  155. {
  156. util::complete();
  157. }
  158. //打印全部 ssh 20220602
  159. public function actionPrintAll()
  160. {
  161. $get = Yii::$app->request->get();
  162. $orderSn = $get['orderSn'] ?? 0;
  163. $type = $get['type'] ?? 0;
  164. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  165. if (empty($itemList)) {
  166. util::fail('没有商品');
  167. }
  168. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  169. $mainId = $order->mainId ?? 0;
  170. $ext = $this->shopExt;
  171. $printLabelSn = $ext->printLabelSn ?? '';
  172. if (empty($printLabelSn)) {
  173. util::fail('请设置标签打印机');
  174. }
  175. $p = new printUtil($printLabelSn);
  176. foreach ($itemList as $key => $item) {
  177. $name = $item->name ?? '';
  178. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  179. if (empty($num)) {
  180. util::fail('没有花材数量');
  181. }
  182. $ptItemId = $item->itemId ?? '';
  183. $productId = $item->productId ?? 0;
  184. $p->times = $num;
  185. $smallUnit = $item->smallUnit ?? '';
  186. $bigUnit = $item->bigUnit ?? '';
  187. $ratio = $item->ratio ?? 0;
  188. $unit = $ratio . $smallUnit . '/' . $bigUnit;
  189. if (isset($item->ratioType) && $item->ratioType == 1) {
  190. $unit = '若干' . $smallUnit . '/' . $bigUnit;
  191. }
  192. if (stringUtil::getWordNum($name) > 7) {
  193. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  194. } else {
  195. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  196. }
  197. if ($key % 2 == 1) {
  198. $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="0">.</TEXT>';
  199. }
  200. if ($type == 0) {
  201. $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $ptItemId . '</BC128>';
  202. if (in_array($mainId, [52, 1459])) {
  203. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  204. } else {
  205. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  206. }
  207. } else {
  208. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
  209. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  210. }
  211. $p->printLabelMsg($content);
  212. }
  213. util::complete();
  214. }
  215. //打印全部 ssh 20220
  216. public function actionPrintItem()
  217. {
  218. $get = Yii::$app->request->get();
  219. $id = $get['id'] ?? 0;
  220. $type = $get['type'] ?? 0;
  221. $item = PurchaseOrderItemClass::getById($id, true);
  222. if (empty($item)) {
  223. util::fail('没有找到花材');
  224. }
  225. $name = $item->name ?? '';
  226. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  227. if (empty($num)) {
  228. util::fail('没有花材数量');
  229. }
  230. $orderSn = $item->orderSn ?? '';
  231. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  232. $mainId = $order->mainId ?? 0;
  233. $ext = $this->shopExt;
  234. $printLabelSn = $ext->printLabelSn ?? '';
  235. if (empty($printLabelSn)) {
  236. util::fail('请设置标签打印机');
  237. }
  238. $p = new printUtil($printLabelSn);
  239. $productId = $item->productId ?? 0;
  240. $product = ProductClass::getById($productId, true);
  241. $smallUnit = $product->smallUnit ?? '';
  242. $bigUnit = $product->bigUnit ?? '';
  243. $ratio = $product->ratio ?? 20;
  244. $ratioType = $product->ratioType ?? 0;
  245. if ($ratioType == 1) {
  246. $unit = '若干' . $smallUnit . '/' . $bigUnit;
  247. } else {
  248. $unit = $ratio . $smallUnit . '/' . $bigUnit;
  249. }
  250. $ptItemId = $item->itemId ?? '';
  251. $p->times = $num;
  252. if (stringUtil::getWordNum($name) > 7) {
  253. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  254. } else {
  255. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  256. }
  257. if ($type == 0) {
  258. $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $ptItemId . '</BC128>';
  259. if (in_array($mainId, [52, 1459])) {
  260. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  261. } else {
  262. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  263. }
  264. } else {
  265. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
  266. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  267. }
  268. $p->printLabelMsg($content);
  269. util::complete();
  270. }
  271. //取消入库单 ssh 20221211
  272. public function actionCancel()
  273. {
  274. $get = Yii::$app->request->get();
  275. $id = $get['id'] ?? 0;
  276. $cg = PurchaseOrderClass::getLockById($id);
  277. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  278. util::fail('请确认是否您的采购单');
  279. }
  280. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_CANCEL) {
  281. util::fail('已取消过了');
  282. }
  283. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
  284. util::fail('已入库,无法取消');
  285. }
  286. PurchaseOrderClass::cancel($cg);
  287. util::complete();
  288. }
  289. //确认入库 sssh 20221211
  290. public function actionConfirmPutIn()
  291. {
  292. ini_set('memory_limit', '2045M');
  293. set_time_limit(0);
  294. $shopAdmin = $this->shopAdmin;
  295. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  296. util::fail('超管才能修改');
  297. }
  298. $connection = Yii::$app->db;
  299. $transaction = $connection->beginTransaction();
  300. try {
  301. $get = Yii::$app->request->get();
  302. $id = $get['id'] ?? 0;
  303. $cg = PurchaseOrderClass::getLockById($id);
  304. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  305. util::fail('请确认是否您的采购单');
  306. }
  307. //解决重复请求问题
  308. $cacheKey = 'confirm_put_in_action_' . $id;
  309. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  310. if (!empty($has)) {
  311. util::fail('请5秒后操作');
  312. }
  313. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  314. $staff = $this->shopAdmin;
  315. $data = [];
  316. $data['staffId'] = $staff->id ?? 0;
  317. $data['staffName'] = $staff->name ?? '';
  318. $data['adminId'] = $this->adminId ?? 0;
  319. $return = PurchaseOrderClass::putIn($cg, $data);
  320. $transaction->commit();
  321. //入库成功通知相关人员,关键词 put_in_notice
  322. //$shop = $this->shop;
  323. //WxMessageClass::ghsCgEntryInform($shop, $cg);
  324. util::success($return);
  325. } catch (\Exception $e) {
  326. $transaction->rollBack();
  327. noticeUtil::push('确认入库失败,原因:' . $e->getMessage(), '15280215347');
  328. Yii::error("确认入库失败,原因:" . $e->getMessage());
  329. util::fail('确认失败');
  330. }
  331. }
  332. //新增采购订单
  333. public function actionCreateOrder()
  334. {
  335. ini_set('memory_limit', '2045M');
  336. set_time_limit(0);
  337. $post = Yii::$app->request->post();
  338. $post['sjId'] = $this->sjId;
  339. $post['shopId'] = $this->shopId;
  340. $post['adminId'] = $this->adminId;
  341. $post['mainId'] = $this->mainId;
  342. $staff = $this->shopAdmin;
  343. //以下二个都需要保留
  344. $post['staffId'] = $staff->id ?? 0;
  345. $post['staffName'] = $staff->name ?? '';
  346. $post['shopAdminId'] = $staff->id ?? 0;
  347. $post['shopAdminName'] = $staff->name ?? '';
  348. $shopAdmin = $this->shopAdmin;
  349. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  350. util::fail('超管才能修改');
  351. }
  352. if (getenv('YII_ENV') == 'production') {
  353. //小向花卉采购控制
  354. if ($this->mainId == 23390) {
  355. if (!in_array($this->adminId, [24586, 24115, 24759, 26390])) {
  356. util::fail('你不能采购哦');
  357. }
  358. }
  359. } else {
  360. if ($this->mainId == 644) {
  361. // if (!in_array($this->adminId, [919])) {
  362. // util::fail('你不能采购哈');
  363. // }
  364. }
  365. }
  366. $shop = $this->shop;
  367. $carSale = $shop->carSale ?? 0;
  368. if ($carSale == 1) {
  369. util::fail('车销不能采购');
  370. }
  371. $connection = Yii::$app->db;
  372. $transaction = $connection->beginTransaction();
  373. try {
  374. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  375. $ghsItemInfo = $post['itemInfo'] ?? '';
  376. if (empty($ghsItemInfo)) {
  377. util::fail('请选择花材');
  378. }
  379. $ghsItemInfo = json_decode($ghsItemInfo, true);
  380. if (!is_array($ghsItemInfo)) {
  381. util::fail('花材格式不正确');
  382. }
  383. //合并
  384. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  385. //判断花材格式,是否属于当前门店
  386. ProductClass::valid($ghsItemInfo, $this->mainId);
  387. $cgStaffId = $post['cgStaffId'] ?? 0;
  388. if (empty($cgStaffId)) {
  389. $mainId = $this->mainId;
  390. if (getenv('YII_ENV') == 'production') {
  391. //花大苪、鹏诚康乃馨 采购入库必须选择采购人
  392. if (in_array($mainId, [8164, 19606])) {
  393. util::fail('请选择采购人');
  394. }
  395. } else {
  396. if (in_array($mainId, [])) {
  397. util::fail('请选择采购人');
  398. }
  399. }
  400. }
  401. //获取供货商信息
  402. $ghsId = $post['ghsId'];
  403. if (empty($ghsId)) {
  404. util::fail("请选择供货商");
  405. }
  406. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  407. GhsClass::valid($ghsInfo, $this->shopId);
  408. $post['ghsInfo'] = json_encode($ghsInfo);
  409. $post['ghsName'] = $ghsInfo['name'] ?? '';
  410. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  411. //判断花材里的信息
  412. foreach ($ghsItemInfo as $v) {
  413. $bigNum = $v['bigNum'] ?? 0;
  414. $productId = $v['productId'] ?? 0;
  415. $smallNum = $v['smallNum'] ?? 0;
  416. if (!isset($v['itemPrice'])) {
  417. util::fail('采购价格不能为空');
  418. }
  419. if (!$productId) {
  420. util::fail('花材不存在');
  421. }
  422. if ($bigNum <= 0 && $smallNum <= 0) {
  423. util::fail('花材数量不能为0');
  424. }
  425. }
  426. $post['itemInfo'] = $ghsItemInfo;
  427. //0稍后入库 1直接入库
  428. $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
  429. $shop = $this->shop;
  430. $bookSn = $shop->bookSn ?? 0;
  431. if ($inType == 1 && !empty($bookSn)) {
  432. util::fail('开启预订不能直接入库');
  433. }
  434. $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
  435. $post['debt'] = $debtStatus;
  436. $order = PurchaseOrderClass::addOrder($post);
  437. //如果是附近供货商,则采购单标记为外采单
  438. if (isset($ghsInfo['location']) && $ghsInfo['location'] == 1) {
  439. $order->location = 1;
  440. $order->save();
  441. }
  442. $transaction->commit();
  443. if (isset($order->needPrint) && $order->needPrint == 1) {
  444. PurchaseOrderClass::printTicket($order);
  445. }
  446. util::success($order);
  447. } catch (\Exception $e) {
  448. $transaction->rollBack();
  449. noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
  450. Yii::error("操作失败原因:" . $e->getMessage());
  451. util::fail('操作失败');
  452. }
  453. }
  454. //分配货位号 ssh 20240619
  455. public function actionAssignSeat()
  456. {
  457. $get = Yii::$app->request->get();
  458. $id = $get['id'] ?? 0;
  459. $salt = $get['salt'] ?? '';
  460. $cg = PurchaseOrderClass::getById($id, true);
  461. if (empty($cg)) {
  462. util::fail('没有找到采购单');
  463. }
  464. if (!empty($salt)) {
  465. if ($cg->salt != $salt) {
  466. util::fail('您不能访问的采购单');
  467. }
  468. } else {
  469. if ($cg->mainId != $this->mainId) {
  470. util::fail('不是你的采购单呢');
  471. }
  472. }
  473. $shop = $this->shop;
  474. $bookSn = $shop->bookSn ?? 0;
  475. if (empty($bookSn)) {
  476. util::success([]);
  477. }
  478. //不是待入库状态不需要分配
  479. if ($cg->status != 3) {
  480. util::success([]);
  481. }
  482. $connection = Yii::$app->db;
  483. $transaction = $connection->beginTransaction();
  484. try {
  485. PurchaseOrderClass::assign($cg, $bookSn);
  486. $transaction->commit();
  487. util::complete('货位获取成功');
  488. } catch (\Exception $e) {
  489. $transaction->rollBack();
  490. util::fail('获取失败');
  491. }
  492. }
  493. //订单列表
  494. public function actionList()
  495. {
  496. $where = [];
  497. $get = Yii::$app->request->get();
  498. $where['shopId'] = $this->shopId;
  499. $orderStatus = $get['status'] ?? '';
  500. if ($orderStatus) {
  501. $where['status'] = $orderStatus;
  502. }
  503. $ghsId = $get['ghsId'] ?? 0;
  504. if (!empty($ghsId)) {
  505. $where['ghsId'] = $ghsId;
  506. }
  507. $data = PurchaseOrderClass::getOrderList($where);
  508. //状态统计,很慢,暂时隐藏
  509. //$statData = PurchaseOrderClass::statNum($this->shopId);
  510. $statData = [
  511. 'allNum' => 0,
  512. 'unPayNum' => 0,
  513. 'unSendNum' => 0,
  514. 'sendingNum' => 0,
  515. 'finishNum' => 0,
  516. ];
  517. $data = array_merge($data, $statData);
  518. util::success($data);
  519. }
  520. //订单详情
  521. public function actionDetail()
  522. {
  523. $orderSn = Yii::$app->request->get('orderSn', '');
  524. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  525. util::success($orderData);
  526. }
  527. //修改备注
  528. public function actionUpdateRemark()
  529. {
  530. $remark = Yii::$app->request->post('remark', '');
  531. $id = Yii::$app->request->post('id', '');
  532. $cg = PurchaseOrderClass::getById($id, true);
  533. if (empty($cg)) {
  534. util::fail('没有找到订单');
  535. }
  536. if ($cg->shopId != $this->shopId) {
  537. util::fail('没有权限修改');
  538. }
  539. $cg->remark = $remark;
  540. $cg->save();
  541. util::complete('修改成功');
  542. }
  543. }