PurchaseOrderController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use bizGhs\order\classes\PurchaseOrderClass;
  5. use bizGhs\order\classes\PurchaseOrderItemClass;
  6. use bizGhs\product\classes\ProductClass;
  7. use bizHd\purchase\classes\PurchaseClass;
  8. use common\components\dict;
  9. use common\components\noticeUtil;
  10. use common\components\printUtil;
  11. use common\components\stringUtil;
  12. use common\components\util;
  13. use biz\shop\classes\ShopExtClass;
  14. use Yii;
  15. class PurchaseOrderController extends BaseController
  16. {
  17. //打印多联 ssh 2024509
  18. public function actionPrintPaper()
  19. {
  20. $get = Yii::$app->request->get();
  21. $id = $get['id'] ?? 0;
  22. $cg = PurchaseOrderClass::getById($id, true);
  23. if (empty($cg)) {
  24. util::fail('没有找到采购信息');
  25. }
  26. if ($cg->mainId != $this->mainId) {
  27. util::fail('不是你的采购单哦');
  28. }
  29. $orderSn = $cg->orderSn ?? '';
  30. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  31. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":16,"lineHeight":30,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":188.91632245461145,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":105.15171514242958,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":103.08801880877742,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":140.84394359418155,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":93.32065807548679,"title":"日期","field":"shortTime","checked":false,"columnId":"shortTime","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.09275968851016,"title":"库存","field":"stock","checked":false,"columnId":"stock","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":276,"title":"金额\n","field":"amount","checked":false,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"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":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":392.5,"top":785,"height":13,"width":199,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":590.74609375,"bottom":801.25,"vCenter":491.24609375,"hCenter":794.75},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":335,"top":12.5,"height":44,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":12.5,"height":46,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":20,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":95,"top":17.5,"height":35,"width":373,"title":"文本","right":469,"bottom":52.49609375,"vCenter":282.5,"hCenter":34.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":377.5,"height":200,"width":535,"title":"备注","right":571.4921875,"bottom":550.25,"vCenter":303.9921875,"hCenter":450.25,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":302.5,"height":70,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"fontSize":18,"fontWeight":"bold","qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":200,"height":50,"width":400,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":36,"qrCodeLevel":0,"right":430,"bottom":284.99609375,"vCenter":230,"hCenter":259.99609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":257.5,"height":39,"width":240,"title":"运费","field":"sendCost","testData":"0","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":28.5,"qrCodeLevel":0,"right":526.7421875,"bottom":415.74609375,"vCenter":276.7421875,"hCenter":400.74609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":295,"top":202.5,"height":43,"width":270,"title":"德邦物流","right":565.74609375,"bottom":280.99609375,"vCenter":430.74609375,"hCenter":259.49609375,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":20,"lineHeight":36,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":260,"height":41,"width":260,"title":"打包费","field":"packCost","testData":"30","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":24,"qrCodeLevel":0,"right":555.74609375,"bottom":332.99609375,"vCenter":425.74609375,"hCenter":312.49609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":160,"height":36,"width":189,"title":"花材数量","field":"totalItemNum","testData":"20","coordinateSync":false,"widthHeightSync":false,"fontFamily":"cursive","fontSize":24,"fontWeight":"bold","lineHeight":32.25,"qrCodeLevel":0,"right":219,"bottom":158.49609375,"vCenter":124.5,"hCenter":140.49609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":295,"top":160,"height":36,"width":189,"title":"支数","field":"totalSmallItemNum","testData":"600","coordinateSync":false,"widthHeightSync":false,"fontFamily":"cursive","fontSize":24,"fontWeight":"bold","lineHeight":32.25,"qrCodeLevel":0,"right":482.25,"bottom":195.24609375,"vCenter":387.75,"hCenter":177.24609375},"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":{}}]}';
  32. $table = [];
  33. $totalItemNum = 0;
  34. if (!empty($itemList)) {
  35. foreach ($itemList as $key => $val) {
  36. $currentName = $val['name'] ?? '';
  37. $num = $val['itemNum'] ?? 0;
  38. $refundNum = $val['refundNum'] ?? 0;
  39. $num = bcsub($num, $refundNum);
  40. $totalItemNum = bcadd($totalItemNum, $num);
  41. $table[] = [
  42. 'name' => $currentName,
  43. 'num' => $num,
  44. 'confirmNum' => '',
  45. 'remark' => '',
  46. ];
  47. }
  48. }
  49. $printData = [
  50. 'customName' => '111',
  51. 'seatSn' => 12,
  52. 'shortSendTimeWant' => '',
  53. 'table' => $table,
  54. 'remark' => '999',
  55. 'fullAddress' => '中国',
  56. 'sendNum' => 13,
  57. 'sendCost' => 12,
  58. 'ysName' => 999,
  59. 'packCost' => '7',
  60. 'totalItemNum' => $totalItemNum,
  61. 'totalSmallItemNum' => 0,
  62. ];
  63. util::success(['template' => $template, 'printData' => $printData]);
  64. }
  65. //修改货位号 ssh 20240410
  66. public function actionModifySeatSn()
  67. {
  68. $get = Yii::$app->request->get();
  69. $id = $get['id'] ?? 0;
  70. $seatSn = $get['seatSn'] ?? '';
  71. $cg = PurchaseOrderClass::getById($id, true);
  72. if (empty($cg)) {
  73. util::fail('没有找到采购单');
  74. }
  75. if ($cg->mainId != $this->mainId) {
  76. util::fail('没有权限');
  77. }
  78. $cg->seatSn = $seatSn;
  79. $cg->save();
  80. }
  81. //获取零售端在进行中的订单 ssh 20231201
  82. public function actionGetLsRunningOrderNum()
  83. {
  84. $lsFhNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 2]);
  85. $lsShNum = PurchaseClass::getCount(['mainId' => $this->mainId, 'status' => 3]);
  86. util::success(['lsFhNum' => $lsFhNum, 'lsShNum' => $lsShNum]);
  87. }
  88. //打印小票 ssh 20230608
  89. public function actionPrintBill()
  90. {
  91. $get = Yii::$app->request->get();
  92. $id = $get['id'] ?? 0;
  93. $order = $get['order'] ?? 1;
  94. $cg = PurchaseOrderClass::getById($id, true);
  95. if (empty($cg)) {
  96. util::fail('没有找到采购单');
  97. }
  98. if ($cg->mainId != $this->mainId) {
  99. util::fail('没有权限');
  100. }
  101. if (getenv('YII_ENV') == 'production') {
  102. //小向的采购单要打印二张
  103. if ($this->mainId == 23390) {
  104. PurchaseOrderClass::printTicket($cg, false, $order);
  105. }
  106. }
  107. PurchaseOrderClass::printTicket($cg, false, $order);
  108. util::complete();
  109. }
  110. //打印全部 ssh 20220602
  111. public function actionPrintAll()
  112. {
  113. $get = Yii::$app->request->get();
  114. $orderSn = $get['orderSn'] ?? 0;
  115. $type = $get['type'] ?? 0;
  116. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  117. if (empty($itemList)) {
  118. util::fail('没有商品');
  119. }
  120. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  121. $mainId = $order->mainId ?? 0;
  122. $ext = $this->shopExt;
  123. $printLabelSn = $ext->printLabelSn ?? '';
  124. if (empty($printLabelSn)) {
  125. util::fail('请设置标签打印机');
  126. }
  127. $p = new printUtil($printLabelSn);
  128. foreach ($itemList as $key => $item) {
  129. $name = $item->name ?? '';
  130. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  131. if (empty($num)) {
  132. util::fail('没有花材数量');
  133. }
  134. $ptItemId = $item->itemId ?? '';
  135. $productId = $item->productId ?? 0;
  136. $p->times = $num;
  137. $smallUnit = $item->smallUnit ?? '';
  138. $bigUnit = $item->bigUnit ?? '';
  139. $ratio = $item->ratio ?? 0;
  140. $unit = $ratio . $smallUnit . '/' . $bigUnit;
  141. if (isset($item->ratioType) && $item->ratioType == 1) {
  142. $unit = '若干' . $smallUnit . '/' . $bigUnit;
  143. }
  144. if (stringUtil::getWordNum($name) > 7) {
  145. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  146. } else {
  147. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  148. }
  149. if ($key % 2 == 1) {
  150. $content .= '<TEXT x="415" y="20" font="12" w="2" h="2" r="0">.</TEXT>';
  151. }
  152. if ($type == 0) {
  153. $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $ptItemId . '</BC128>';
  154. if (in_array($mainId, [52, 1459])) {
  155. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  156. } else {
  157. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  158. }
  159. } else {
  160. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
  161. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  162. }
  163. $p->printLabelMsg($content);
  164. }
  165. util::complete();
  166. }
  167. //打印全部 ssh 20220
  168. public function actionPrintItem()
  169. {
  170. $get = Yii::$app->request->get();
  171. $id = $get['id'] ?? 0;
  172. $type = $get['type'] ?? 0;
  173. $item = PurchaseOrderItemClass::getById($id, true);
  174. if (empty($item)) {
  175. util::fail('没有找到花材');
  176. }
  177. $name = $item->name ?? '';
  178. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  179. if (empty($num)) {
  180. util::fail('没有花材数量');
  181. }
  182. $orderSn = $item->orderSn ?? '';
  183. $order = PurchaseOrderClass::getByCondition(['orderSn' => $orderSn], true);
  184. $mainId = $order->mainId ?? 0;
  185. $ext = $this->shopExt;
  186. $printLabelSn = $ext->printLabelSn ?? '';
  187. if (empty($printLabelSn)) {
  188. util::fail('请设置标签打印机');
  189. }
  190. $p = new printUtil($printLabelSn);
  191. $productId = $item->productId ?? 0;
  192. $product = ProductClass::getById($productId, true);
  193. $smallUnit = $product->smallUnit ?? '';
  194. $bigUnit = $product->bigUnit ?? '';
  195. $ratio = $product->ratio ?? 20;
  196. $ratioType = $product->ratioType ?? 0;
  197. if ($ratioType == 1) {
  198. $unit = '若干' . $smallUnit . '/' . $bigUnit;
  199. } else {
  200. $unit = $ratio . $smallUnit . '/' . $bigUnit;
  201. }
  202. $ptItemId = $item->itemId ?? '';
  203. $p->times = $num;
  204. if (stringUtil::getWordNum($name) > 7) {
  205. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  206. } else {
  207. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  208. }
  209. if ($type == 0) {
  210. $content .= '<BC128 x="30" y="100" h="70" s="1" r="0" n="4" w="11">' . $ptItemId . '</BC128>';
  211. if (in_array($mainId, [52, 1459])) {
  212. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  213. } else {
  214. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  215. }
  216. } else {
  217. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $productId . '</QR>';
  218. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  219. }
  220. $p->printLabelMsg($content);
  221. util::complete();
  222. }
  223. //取消入库单 ssh 20221211
  224. public function actionCancel()
  225. {
  226. $get = Yii::$app->request->get();
  227. $id = $get['id'] ?? 0;
  228. $cg = PurchaseOrderClass::getLockById($id);
  229. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  230. util::fail('请确认是否您的采购单');
  231. }
  232. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_CANCEL) {
  233. util::fail('已取消过了');
  234. }
  235. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
  236. util::fail('已入库,无法取消');
  237. }
  238. PurchaseOrderClass::cancel($cg);
  239. util::complete();
  240. }
  241. //确认入库 sssh 20221211
  242. public function actionConfirmPutIn()
  243. {
  244. ini_set('memory_limit', '2045M');
  245. set_time_limit(0);
  246. $shopAdmin = $this->shopAdmin;
  247. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  248. util::fail('超管才能修改');
  249. }
  250. $connection = Yii::$app->db;
  251. $transaction = $connection->beginTransaction();
  252. try {
  253. $get = Yii::$app->request->get();
  254. $id = $get['id'] ?? 0;
  255. $cg = PurchaseOrderClass::getLockById($id);
  256. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  257. util::fail('请确认是否您的采购单');
  258. }
  259. $staff = $this->shopAdmin;
  260. $data = [];
  261. $data['staffId'] = $staff->id ?? 0;
  262. $data['staffName'] = $staff->name ?? '';
  263. $data['adminId'] = $this->adminId ?? 0;
  264. $return = PurchaseOrderClass::putIn($cg, $data);
  265. $transaction->commit();
  266. util::success($return);
  267. } catch (\Exception $e) {
  268. $transaction->rollBack();
  269. noticeUtil::push('确认入库失败,原因:' . $e->getMessage(), '15280215347');
  270. Yii::error("确认入库失败,原因:" . $e->getMessage());
  271. util::fail('确认失败');
  272. }
  273. }
  274. //新增采购订单
  275. public function actionCreateOrder()
  276. {
  277. ini_set('memory_limit', '2045M');
  278. set_time_limit(0);
  279. $post = Yii::$app->request->post();
  280. $post['sjId'] = $this->sjId;
  281. $post['shopId'] = $this->shopId;
  282. $post['adminId'] = $this->adminId;
  283. $post['mainId'] = $this->mainId;
  284. $staff = $this->shopAdmin;
  285. //以下二个都需要保留
  286. $post['staffId'] = $staff->id ?? 0;
  287. $post['staffName'] = $staff->name ?? '';
  288. $post['shopAdminId'] = $staff->id ?? 0;
  289. $post['shopAdminName'] = $staff->name ?? '';
  290. $shopAdmin = $this->shopAdmin;
  291. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  292. util::fail('超管才能修改');
  293. }
  294. if (getenv('YII_ENV') == 'production') {
  295. //小向花卉采购控制
  296. if ($this->mainId == 23390) {
  297. if (!in_array($this->adminId, [24586, 24115, 24759])) {
  298. util::fail('你不能采购哦');
  299. }
  300. }
  301. } else {
  302. if ($this->mainId == 644) {
  303. // if (!in_array($this->adminId, [919])) {
  304. // util::fail('你不能采购哈');
  305. // }
  306. }
  307. }
  308. $shop = $this->shop;
  309. $carSale = $shop->carSale ?? 0;
  310. if ($carSale == 1) {
  311. util::fail('车销不能采购');
  312. }
  313. $connection = Yii::$app->db;
  314. $transaction = $connection->beginTransaction();
  315. try {
  316. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  317. $ghsItemInfo = $post['itemInfo'] ?? '';
  318. if (empty($ghsItemInfo)) {
  319. util::fail('请选择花材');
  320. }
  321. $ghsItemInfo = json_decode($ghsItemInfo, true);
  322. if (!is_array($ghsItemInfo)) {
  323. util::fail('花材格式不正确');
  324. }
  325. //合并
  326. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  327. //判断花材格式,是否属于当前门店
  328. ProductClass::valid($ghsItemInfo, $this->mainId);
  329. $cgStaffId = $post['cgStaffId'] ?? 0;
  330. if (empty($cgStaffId)) {
  331. $mainId = $this->mainId;
  332. if (getenv('YII_ENV') == 'production') {
  333. //花大苪、鹏诚康乃馨 采购入库必须选择采购人
  334. if (in_array($mainId, [8164, 19606])) {
  335. util::fail('请选择采购人');
  336. }
  337. } else {
  338. if (in_array($mainId, [])) {
  339. util::fail('请选择采购人');
  340. }
  341. }
  342. }
  343. //获取供货商信息
  344. $ghsId = $post['ghsId'];
  345. if (empty($ghsId)) {
  346. util::fail("请选择供货商");
  347. }
  348. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  349. GhsClass::valid($ghsInfo, $this->shopId);
  350. $post['ghsInfo'] = json_encode($ghsInfo);
  351. $post['ghsName'] = $ghsInfo['name'] ?? '';
  352. $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
  353. //判断花材里的信息
  354. foreach ($ghsItemInfo as $v) {
  355. $bigNum = $v['bigNum'] ?? 0;
  356. $productId = $v['productId'] ?? 0;
  357. $smallNum = $v['smallNum'] ?? 0;
  358. if (!isset($v['itemPrice'])) {
  359. util::fail('采购价格不能为空');
  360. }
  361. if (!$productId) {
  362. util::fail('花材不存在');
  363. }
  364. if ($bigNum <= 0 && $smallNum <= 0) {
  365. util::fail('花材数量不能为0');
  366. }
  367. }
  368. $post['itemInfo'] = $ghsItemInfo;
  369. //0稍后入库 1直接入库
  370. $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
  371. $debtStatus = $inType == 1 ? PurchaseOrderClass::DEBT_YES : PurchaseOrderClass::DEBT_UNKNOWN;
  372. $post['debt'] = $debtStatus;
  373. $order = PurchaseOrderClass::addOrder($post);
  374. //如果是附近供货商,则采购单标记为外采单
  375. if (isset($ghsInfo['location']) && $ghsInfo['location'] == 1) {
  376. $order->location = 1;
  377. $order->save();
  378. }
  379. if (isset($order->needPrint) && $order->needPrint == 1) {
  380. PurchaseOrderClass::printTicket($order);
  381. }
  382. $transaction->commit();
  383. util::success($order);
  384. } catch (\Exception $e) {
  385. $transaction->rollBack();
  386. noticeUtil::push('批发店采购入库失败,原因:' . $e->getMessage(), '15280215347');
  387. Yii::error("操作失败原因:" . $e->getMessage());
  388. util::fail('操作失败');
  389. }
  390. }
  391. //订单列表
  392. public function actionList()
  393. {
  394. $where = [];
  395. $get = Yii::$app->request->get();
  396. $where['shopId'] = $this->shopId;
  397. $orderStatus = $get['status'] ?? '';
  398. if ($orderStatus) {
  399. $where['status'] = $orderStatus;
  400. }
  401. $ghsId = $get['ghsId'] ?? 0;
  402. if (!empty($ghsId)) {
  403. $where['ghsId'] = $ghsId;
  404. }
  405. $location = $get['location'] ?? '';
  406. if (is_numeric($location)) {
  407. $where['location'] = $location;
  408. }
  409. $data = PurchaseOrderClass::getOrderList($where);
  410. //状态统计,很慢,暂时隐藏
  411. //$statData = PurchaseOrderClass::statNum($this->shopId);
  412. $statData = [
  413. 'allNum' => 0,
  414. 'unPayNum' => 0,
  415. 'unSendNum' => 0,
  416. 'sendingNum' => 0,
  417. 'finishNum' => 0,
  418. ];
  419. $data = array_merge($data, $statData);
  420. util::success($data);
  421. }
  422. //订单详情
  423. public function actionDetail()
  424. {
  425. $orderSn = Yii::$app->request->get('orderSn', '');
  426. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  427. util::success($orderData);
  428. }
  429. //修改备注
  430. public function actionUpdateRemark()
  431. {
  432. $remark = Yii::$app->request->post('remark', '');
  433. $id = Yii::$app->request->post('id', '');
  434. $cg = PurchaseOrderClass::getById($id, true);
  435. if (empty($cg)) {
  436. util::fail('没有找到订单');
  437. }
  438. if ($cg->shopId != $this->shopId) {
  439. util::fail('没有权限修改');
  440. }
  441. $cg->remark = $remark;
  442. $cg->save();
  443. util::complete('修改成功');
  444. }
  445. }