ImportOrderFromCHandleData.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\command;
  4. use app\admin\model\ActionLog;
  5. use app\admin\model\GoodLog;
  6. use app\admin\model\OrderImportFromC as OIFCModel;
  7. use app\admin\model\ProcessOrder;
  8. use app\admin\model\Test1;
  9. use think\console\Command;
  10. use think\console\Input;
  11. use think\console\input\Argument;
  12. use think\console\input\Option;
  13. use think\console\Output;
  14. use think\Exception;
  15. use think\facade\Db;
  16. //C端订单导入-处理
  17. class ImportOrderFromCHandleData extends Command
  18. {
  19. protected function configure()
  20. {
  21. // 指令配置
  22. $this->setName('handleData')
  23. ->setDescription('批量处理C端导入的订单数据');
  24. }
  25. //【脚本2】批量处理C端导入的订单数据
  26. protected function execute(Input $input, Output $output)
  27. {
  28. $order_import_from_c_db = new OIFCModel();
  29. $c_data = $order_import_from_c_db
  30. ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_relation])
  31. ->lock(true)
  32. ->field('id,createrid,creater')
  33. ->find();
  34. if (empty($c_data)) $output->writeln('没有符合条件的记录');
  35. else {
  36. Db::startTrans();
  37. try {
  38. //先找用户确认信息
  39. $extend_data = Db::name('order_import_from_c_extend')
  40. ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 2])
  41. ->find();
  42. if (empty($extend_data)) {
  43. $extend_data = Db::name('order_import_from_c_extend')
  44. ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 1])
  45. ->find();
  46. }
  47. if (empty($extend_data)) throw new Exception('没有对应的解析数据');
  48. //复用sale::create()方法 -- start
  49. $orderCode = makeNo("QR");
  50. $customer_code = $extend_data['customer_code'];
  51. $customer = Db::name("customer_info")
  52. ->where(["companyNo" => $customer_code])
  53. ->find();
  54. if ($customer == false) throw new Exception('未找到客户数据');
  55. $supplierNo = $extend_data['companyNo'];
  56. $supplier = Db::name("business")
  57. ->where(["companyNo" => $supplierNo])
  58. ->find();
  59. if ($supplier == false) throw new Exception('未找到平台供应商数据');
  60. $goodtype = 1;//1正常商品
  61. $sendtype = 1;//直接发货
  62. $platform_id = $extend_data['platform_codes'];
  63. $platform_order = $extend_data['platform_code'];
  64. $good_num = $extend_data['num'];
  65. $arrtime = $extend_data['platform_time'];
  66. $paytime = $extend_data['addtime'];
  67. $workNo = $extend_data['po_code'];
  68. $ct = Db::name('good_platform')
  69. ->alias('a')
  70. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  71. ->where(['a.spuCode' => $extend_data['spuCode']])
  72. ->field("b.*,a.skuCode,a.platform_code,a.plat_code")
  73. ->find();
  74. if ($ct == false) throw new Exception('未找到商品数据');
  75. $goodinfo = $ct;
  76. $is_stock = $ct['is_stock'];
  77. $order_type = 5;//1销售2咨询(1备库 2非库存 3咨询采反 4项目采反,5平台部订单销售)
  78. $spuCode = $ct['spuCode'];
  79. $skuCode = $ct['skuCode'];
  80. $is_activity = empty($extend_data['activity_name']) ? 0 : 1;
  81. if ($goodinfo['is_stock'] == 1) {
  82. $stock = Db::name("good_stock")
  83. ->alias("a")
  84. ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
  85. ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.companyNo" => $supplierNo])
  86. ->field("a.id,a.usable_stock,a.wait_out_stock")
  87. ->find();
  88. if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
  89. }
  90. $origin = Db::name("good_nake")
  91. ->where([["spuCode", "=", $spuCode], ["min_num", "<=", $good_num], ["is_del", "=", 0]])
  92. ->order("min_num desc")
  93. ->find();
  94. if ($origin == false) throw new Exception('未找到相关阶梯成本价格');
  95. $origin_price = $origin['nake_total'];
  96. $sale_price = $extend_data['price'];
  97. if ($goodtype == 1) {
  98. // $good = Db::name("good_ladder")
  99. // ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
  100. // ->where([["min_num", "<=", $good_num]])
  101. // ->order("min_num desc")
  102. // ->find();
  103. //// if ($good == false) throw new Exception('未找到相关阶梯价格');
  104. if ($is_activity == 1) {
  105. $act = Db::name("activity_info")
  106. ->alias("a")
  107. ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  108. ->where(["a.skuCode" => $skuCode, "a.activity_code" => $extend_data['activity_code'], "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
  109. ->find();
  110. if ($act == false) throw new Exception('未找到相关活动价');
  111. if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
  112. if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
  113. }
  114. }
  115. $cgd = [
  116. "supplierNo" => $ct['supplierNo'],
  117. "companyNo" => $supplierNo,
  118. "orderCode" => $orderCode,
  119. "spuCode" => $ct['spuCode'],
  120. "skuCode" => $ct['skuCode'],
  121. "good_name" => $ct['good_name'],
  122. "sale_price" => $origin_price,
  123. "total_fee" => $origin_price * $good_num,
  124. "pakge_fee" => $ct['packing_fee'],
  125. "cert_fee" => $ct['cert_fee'],
  126. "open_fee" => $ct['open_fee'],
  127. "cost_fee" => $ct['cost_fee'],
  128. "mark_fee" => $ct['mark_fee'],
  129. "demo_fee" => $ct['demo_fee'],
  130. "good_num" => $good_num,
  131. "good_type" => $goodtype,
  132. "order_type" => $is_stock == 1 ? 1 : 2,
  133. "createrid" => $ct['createrid'],
  134. "creater" => $ct['creater'],
  135. 'send_way' => 2
  136. ];
  137. $send_num = $extend_data['num'];
  138. $remark = $extend_data['order_remark'];
  139. $rm = $c_data['createrid'];
  140. $ri = $c_data['creater'];
  141. $data = [
  142. "orderCode" => $orderCode,
  143. "good_code" => $spuCode,
  144. "skuCode" => $skuCode,
  145. "customer_code" => $customer_code,
  146. "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
  147. "good_num" => $good_num,
  148. "cat_id" => $goodinfo['cat_id'],
  149. "apply_id" => $rm,
  150. "apply_name" => $ri,
  151. "origin_price" => $origin_price,
  152. "sale_price" => $sale_price,
  153. "post_fee" => 0,
  154. "status" => $send_num == 0 ? 3 : ($good_num == $send_num ? 5 : 4),
  155. "send_num" => $send_num,
  156. "wsend_num" => $good_num - $send_num,
  157. "send_status" => $good_num == $send_num ? 3 : ($send_num == 0 ? 1 : 2),
  158. "status" => 0,
  159. "send_num" => 0,
  160. "wsend_num" => $good_num,
  161. "send_status" => 1,
  162. "good_type" => $goodtype,
  163. "send_type" => $sendtype,
  164. "supplierNo" => $extend_data['companyNo'],
  165. "is_del" => 0,
  166. "zxNo" => "",
  167. "platform_order" => $platform_order,
  168. "platform_id" => $platform_id,
  169. "remark" => $remark,
  170. "is_stock" => $is_stock,
  171. "is_activity" => $is_activity === "" ? 0 : $is_activity,
  172. "order_type" => $order_type,
  173. // "poNo"=>$poNo,
  174. 'good_weight' => $ct['weight'],
  175. 'gold_price' => $ct['cgd_gold_price'],
  176. 'cost_price' => $ct['cost_fee'],
  177. 'diff_weight' => 0,
  178. 'diff_fee' => 0,
  179. "workNo" => $workNo,
  180. "addtime" => date("Y-m-d H:i:s"),
  181. "updatetime" => date("Y-m-d H:i:s"),
  182. 'total_price' => round($sale_price * $good_num, 2),
  183. ];
  184. $paytime == "" ? "" : $data['paytime'] = $paytime;
  185. $datainfo = Db::name('sale')->insert($data, true);
  186. if ($datainfo > 0) {
  187. if ($is_activity == 1) {
  188. $actup = [
  189. "activity_stock" => $act['activity_stock'] - $good_num,
  190. "updatetime" => date("Y-m-d H:i:s")
  191. ];
  192. $actupp = Db::name("activity_info")
  193. ->where(["skuCode" => $skuCode, "activity_code" => $extend_data['activity_code'], "is_del" => 0, "status" => 1])
  194. ->save($actup);
  195. if ($actupp == false) throw new Exception('活动库存修改失败');
  196. }
  197. if ($is_stock == 0) {
  198. //非库存品
  199. $bol = $this->createCgd($cgd, $rm, $ri);
  200. if ($bol == false) throw new Exception('订单创建失败');
  201. } else {
  202. //库存品
  203. $bol = $this->RelaCgd(['orderCode' => $orderCode, "good_num" => $good_num, "spuCode" => $spuCode, "companyNo" => $supplierNo]);
  204. if ($bol == false) throw new Exception('库存商品关联采购单失败');
  205. if (isset($stock)) {
  206. $stck = [
  207. "usable_stock" => $stock['usable_stock'] - $good_num,
  208. "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
  209. "updatetime" => date("Y-m-d H:i:s")
  210. ];
  211. $upad = Db::name("good_stock")
  212. ->where($stock)
  213. ->update($stck);
  214. if ($upad == false) throw new Exception('库存商品更新库存失败');
  215. //商品变动日志表,good_log_code字段存储采购单号
  216. $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
  217. $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
  218. GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
  219. }
  220. }
  221. if ($sendtype == 1) {
  222. $temp = [
  223. 'orderCode' => $orderCode,
  224. 'contactor' => $extend_data['contactor'],
  225. 'mobile' => $extend_data['mobile'],
  226. 'addr' => $extend_data['addr'],
  227. 'addr_code' => $extend_data['addr_code'],
  228. 'customer_code' => $customer_code,
  229. 'receipt_quantity' => $extend_data['num'],//收货数量,
  230. 'post_fee' => 0,
  231. 'is_del' => 0,
  232. 'addtime' => date("Y-m-d H:i:s"),
  233. 'updatetime' => date("Y-m-d H:i:s"),
  234. 'arrive_time' => $arrtime,
  235. ];
  236. $vmp = Db::name('order_addr')->insert($temp, true);
  237. if ($vmp > 0) {
  238. if ($is_stock == 1) {
  239. $order = Db::name("order_num")
  240. ->where(["orderCode" => $orderCode, "status" => 1])
  241. ->where([["wsend_num", ">=", 0]])
  242. ->lock(true)
  243. ->find();
  244. if ($order == false) throw new Exception('未找到可以发货得采购单数据');
  245. $num = $extend_data['num'];
  246. $outCode = makeNo("DF");
  247. $order['wsend_num'] -= $num;
  248. $order['send_num'] += $num;
  249. $or = Db::name("order_num")->save($order);
  250. if ($or == false) throw new Exception('发货地址更新失败');
  251. $tep = [
  252. "cgdNo" => $order['cgdNo'],
  253. "outCode" => $outCode,
  254. "send_num" => $num,
  255. "status" => 1,
  256. "addtime" => date("Y-m-d H:i:s"),
  257. "updatetime" => date("Y-m-d H:i:s")
  258. ];
  259. $sen = Db::name("order_send")->save($tep);
  260. if ($sen == false) throw new Exception('发货地址添加创建失败');
  261. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  262. if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
  263. $out = [
  264. "orderCode" => $orderCode,
  265. "outCode" => $outCode,
  266. "apply_id" => $rm,
  267. "apply_name" => $ri,
  268. "addrid" => $vmp,
  269. "post_name" => "",
  270. "post_code" => "",
  271. "post_fee" => 0,
  272. "sendtime" => date("Y-m-d H:i:s"),
  273. "send_num" => $num,
  274. "check_num" => 0,
  275. "error_num" => 0,
  276. "wsm_code" => $cgdinfo['wsm_code'],
  277. "order_type" => 1,
  278. "status" => 1,
  279. "addtime" => date("Y-m-d H:i:s"),
  280. "updatetime" => date("Y-m-d H:i:s")
  281. ];
  282. $ou = Db::name("order_out")->insert($out);
  283. if ($ou == false) throw new Exception('发货地址添加创建失败');
  284. else {
  285. //修改状态,添加待办
  286. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  287. "order_code" => $outCode,//出库单号
  288. "status" => 0,//这里的status是之前的值
  289. "action_remark" => '',//备注
  290. "action_type" => "create"//新建create,编辑edit,更改状态status
  291. ], "CKD", 0, $out);
  292. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  293. "order_type" => 'CKD',
  294. "order_code" => $outCode,//出库单号
  295. "order_id" => 0,
  296. "order_status" => 0
  297. ]);
  298. }
  299. }
  300. } else throw new Exception('发货地址添加失败');
  301. }
  302. }
  303. //复用sale::create()方法 -- end
  304. //处理完成
  305. $order_import_from_c_db
  306. ->where('id', $c_data['id'])
  307. ->where('is_del', OIFCModel::$is_del_normal)
  308. ->save([
  309. 'status' => $order_import_from_c_db::$status_success,
  310. 'updatetime' => date('Y-m-d H:i:s'),
  311. 'remark' => '',
  312. 'updateid' => 0,
  313. 'updater' => 'system',
  314. 'orderCode' => $orderCode
  315. ]);
  316. Db::commit();
  317. $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
  318. } catch (\think\Exception $exception) {
  319. Db::rollback();
  320. $order_import_from_c_db
  321. ->where('id', $c_data['id'])
  322. ->save([
  323. 'status' => $order_import_from_c_db::$status_stock_not_enough,
  324. 'updatetime' => date('Y-m-d H:i:s'),
  325. 'remark' => $exception->getMessage(),
  326. 'updateid' => 0,
  327. 'updater' => 'system'
  328. ]);
  329. // 指令输出
  330. $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
  331. }
  332. }
  333. }
  334. //创建采购单
  335. private function createCgd($data = [], $rm = '0', $ri = '')
  336. {
  337. $cgdCode = makeNo("CG");
  338. $supplier = Db::name("supplier")
  339. ->where(["code" => $data['supplierNo'], "is_del" => 0])->find();
  340. if ($supplier == false) return false;
  341. $wsm = Db::name("warehouse_info")
  342. ->where(["supplierNo" => $data["supplierNo"], "companyNo" => $data['companyNo'], "is_del" => 0])
  343. ->find();
  344. if ($wsm == false) {
  345. $wsm_code = makeNo("WSM");
  346. $inwsm = [
  347. "wsm_code" => $wsm_code,
  348. "name" => $supplier['name'],
  349. "wsm_type" => 2,
  350. "supplierNo" => $supplier['code'],
  351. "addr" => "",
  352. "addrs_code" => "",
  353. "contactor" => 0,
  354. "contactor_name" => 0,
  355. "mobile" => "",
  356. "position" => "",
  357. "companyNo" => $data['companyNo'],
  358. "status" => 1,
  359. "is_del" => 0,
  360. "addtime" => date("Y-m-d H:i:s"),
  361. "updatetime" => date("Y-m-d H:i:s")
  362. ];
  363. $in = Db::name("warehouse_info")->insert($inwsm);
  364. if ($in == false) return false;
  365. } else {
  366. $wsm_code = $wsm['wsm_code'];
  367. }
  368. $cg = [
  369. "cgdNo" => $cgdCode,
  370. "bkcode" => "",
  371. "wsm_code" => $wsm_code,
  372. "cgder" => $supplier['person'],
  373. "cgder_id" => $supplier['personid'],
  374. "spuCode" => $data['spuCode'],
  375. "skuCode" => $data['skuCode'],
  376. "good_name" => $data['good_name'],
  377. "good_num" => $data['good_num'],
  378. "good_price" => $data['sale_price'],
  379. "total_fee" => round($data['sale_price'] * $data['good_num'], 2),
  380. "pakge_fee" => $data['pakge_fee'],
  381. "cert_fee" => $data['cert_fee'],
  382. "open_fee" => $data['open_fee'],
  383. "teach_fee" => $data['cost_fee'],
  384. "mark_fee" => $data['mark_fee'],
  385. "demo_fee" => $data['demo_fee'],
  386. #"weight"=>$data['weight'],
  387. "diff_weight" => "0",
  388. "diff_fee" => "0",
  389. "gold_price" => "0",
  390. "supplierNo" => $data['supplierNo'],
  391. "supplier_name" => $supplier['name'],
  392. "companyNo" => $data['companyNo'],
  393. "send_status" => 1,
  394. "send_num" => 0,
  395. "wsend_num" => $data['good_num'],
  396. "remark" => "",
  397. "status" => 0,//0初始化
  398. "lasttime" => date("Y-m-d H:i:s"),
  399. "is_del" => 0,
  400. "order_type" => $data['order_type'],
  401. "good_type" => $data['good_type'],
  402. "addtime" => date("Y-m-d H:i:s"),
  403. "updatetime" => date("Y-m-d H:i:s")
  404. ];
  405. $up = Db::name("purchease_order")->insert($cg, true);
  406. if ($up) {
  407. //修改状态,添加待办
  408. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  409. "order_code" => $cg['cgdNo'],//销售单code
  410. "status" => 0,//这里的status是之前的值
  411. "action_remark" => '',//备注
  412. "action_type" => "create"//新建create,编辑edit,更改状态status
  413. ], "CGD", $cg['status'], $cg);
  414. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  415. "order_type" => 'CGD',
  416. "order_code" => $cg['cgdNo'],//销售单code
  417. "order_id" => $up,
  418. "order_status" => $cg['status']
  419. ]);
  420. $rela = [
  421. "orderCode" => $data['orderCode'],
  422. "cgdNo" => $cgdCode,
  423. "spuCode" => $data['spuCode'],
  424. "good_num" => $data['good_num'],
  425. "wsend_num" => $data['good_num'],
  426. "send_num" => 0,
  427. "wait_num" => 0,
  428. "status" => 1,
  429. "source" => 2
  430. ];
  431. $re = Db::name("order_num")->save($rela);
  432. if ($re == false) return false;
  433. else {
  434. $stokc = Db::name("good_stock")
  435. ->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])
  436. ->find();
  437. if ($stokc == false) {
  438. $stokc = [
  439. "spuCode" => $data['spuCode'],
  440. "wsm_code" => $wsm_code,
  441. "wait_in_stock" => 0,
  442. "wait_out_stock" => 0,
  443. "usable_stock" => 0,
  444. "intra_stock" => 0,
  445. "total_stock" => 0,
  446. "status" => 1,
  447. "addtime" => date("Y-m-d H:i:s"),
  448. "updatetime" => date("Y-m-d H:i:s")
  449. ];
  450. $stoc = Db::name("good_stock")->save($stokc);
  451. if ($stoc == false) return false;
  452. }
  453. return true;
  454. }
  455. } else return false;
  456. }
  457. //创建.....
  458. private function RelaCgd(array $outinfo = [])
  459. {
  460. //备库单
  461. $cgd = Db::name("order_bk")
  462. ->where([
  463. ["spuCode", "=", $outinfo['spuCode']],
  464. ["is_del", "=", 0],
  465. ["balance_num", ">=", $outinfo['good_num']],
  466. ['companyNo', "=", $outinfo['companyNo']]
  467. ])
  468. ->lock(true)
  469. ->find();
  470. if ($cgd == false) return false;
  471. $cgdinfo = Db::name("purchease_order")
  472. ->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])
  473. ->find();
  474. if ($cgdinfo == false) return false;
  475. $QrdCgd = [
  476. "cgdNo" => makeNo("CG"),
  477. "bkcode" => $cgdinfo['bkcode'],
  478. 'wsm_code' => $cgdinfo['wsm_code'],
  479. "cgder_id" => $cgdinfo['cgder_id'],
  480. "cgder" => $cgdinfo['cgder'],
  481. "spuCode" => $cgdinfo['spuCode'],
  482. "good_name" => $cgdinfo['good_name'],
  483. "good_num" => $cgdinfo['good_num'],
  484. "good_price" => $cgdinfo['good_price'],
  485. "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
  486. "pakge_fee" => $cgdinfo['pakge_fee'],
  487. "cert_fee" => $cgdinfo['cert_fee'],
  488. "open_fee" => $cgdinfo['open_fee'],
  489. "delivery_fee" => $cgdinfo['delivery_fee'],
  490. "mark_fee" => $cgdinfo['mark_fee'],
  491. "teach_fee" => $cgdinfo['teach_fee'],
  492. "nake_fee" => $cgdinfo['nake_fee'],
  493. "demo_fee" => $cgdinfo['demo_fee'],
  494. "weight" => $cgdinfo['weight'],
  495. "diff_weight" => $cgdinfo['diff_weight'],
  496. "diff_fee" => $cgdinfo['diff_fee'],
  497. "gold_price" => $cgdinfo['gold_price'],
  498. "supplierNo" => $cgdinfo['supplierNo'],
  499. "supplier_name" => $cgdinfo['supplier_name'],
  500. "companyNo" => $cgdinfo['companyNo'],
  501. "send_status" => 3,
  502. "send_num" => $outinfo['good_num'],
  503. "wsend_num" => 0,
  504. "remark" => $cgdinfo['remark'],
  505. "status" => 3,//入库完成
  506. "lasttime" => $cgdinfo['lasttime'],
  507. "is_del" => 0,
  508. "order_type" => 5,
  509. "good_type" => $cgdinfo['good_type'],
  510. "addtime" => date("Y-m-d H:i:s"),
  511. "updatetime" => date("Y-m-d H:i:s")
  512. ];
  513. $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
  514. if ($insetrCgd == false) return false;
  515. $merge_num = Db::name("purchease_order")
  516. ->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => 5, "is_del" => 0])
  517. ->field("sum(send_num)-sum(th_num) as num")
  518. ->find();
  519. $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
  520. $cgd['merge_num'] = $merge_num['num'];
  521. $cgd['updatetime'] = date("Y-m-d H:i:s");
  522. $up = Db::name("order_bk")->save($cgd);
  523. if ($up == false) return false;
  524. $data = [
  525. "orderCode" => $outinfo['orderCode'],
  526. "cgdNo" => $QrdCgd['cgdNo'],
  527. "spuCode" => $outinfo['spuCode'],
  528. "companyNo" => $outinfo['companyNo'],
  529. "good_num" => $outinfo['good_num'],
  530. "wsend_num" => $outinfo['good_num'],
  531. "send_num" => 0,
  532. "wait_num" => $outinfo['good_num'],
  533. "status" => 1,
  534. "source" => 1,
  535. ];
  536. $order = Db::name("order_num")->save($data);
  537. if ($order == false) return false;
  538. return true;
  539. }
  540. }