PurchaseOrderController.php 25 KB

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