PurchaseOrderController.php 27 KB

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