ImportOrderFromCHandleData.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. $bol = $this->createCgd($cgd, $rm, $ri);
  199. if ($bol == false) throw new Exception('订单创建失败');
  200. } else {
  201. $bol = $this->RelaCgd(['orderCode' => $orderCode, "good_num" => $good_num, "spuCode" => $spuCode, "companyNo" => $supplierNo]);
  202. if ($bol == false) throw new Exception('库存商品关联采购单失败');
  203. if (isset($stock)) {
  204. $stck = [
  205. "usable_stock" => $stock['usable_stock'] - $good_num,
  206. "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
  207. "updatetime" => date("Y-m-d H:i:s")
  208. ];
  209. $upad = Db::name("good_stock")
  210. ->where($stock)
  211. ->update($stck);
  212. if ($upad == false) throw new Exception('库存商品更新库存失败');
  213. //商品变动日志表,good_log_code字段存储采购单号
  214. $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
  215. $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
  216. GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
  217. }
  218. }
  219. if ($sendtype == 1) {
  220. $temp = [
  221. 'orderCode' => $orderCode,
  222. 'contactor' => $extend_data['contactor'],
  223. 'mobile' => $extend_data['mobile'],
  224. 'addr' => $extend_data['addr'],
  225. 'addr_code' => $extend_data['addr_code'],
  226. 'customer_code' => $customer_code,
  227. 'receipt_quantity' => $extend_data['num'],//收货数量,
  228. 'post_fee' => 0,
  229. 'is_del' => 0,
  230. 'addtime' => date("Y-m-d H:i:s"),
  231. 'updatetime' => date("Y-m-d H:i:s"),
  232. 'arrive_time' => $arrtime,
  233. ];
  234. $vmp = Db::name('order_addr')->insert($temp, true);
  235. if ($vmp > 0) {
  236. if ($is_stock == 1) {
  237. $order = Db::name("order_num")
  238. ->where(["orderCode" => $orderCode, "status" => 1])
  239. ->where([["wsend_num", ">=", 0]])
  240. ->lock(true)
  241. ->find();
  242. if ($order == false) throw new Exception('未找到可以发货得采购单数据');
  243. $num = $extend_data['num'];
  244. $outCode = makeNo("DF");
  245. $order['wsend_num'] -= $num;
  246. $order['send_num'] += $num;
  247. $or = Db::name("order_num")->save($order);
  248. if ($or == false) throw new Exception('发货地址更新失败');
  249. $tep = [
  250. "cgdNo" => $order['cgdNo'],
  251. "outCode" => $outCode,
  252. "send_num" => $num,
  253. "status" => 1,
  254. "addtime" => date("Y-m-d H:i:s"),
  255. "updatetime" => date("Y-m-d H:i:s")
  256. ];
  257. $sen = Db::name("order_send")->save($tep);
  258. if ($sen == false) throw new Exception('发货地址添加创建失败');
  259. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  260. if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
  261. $out = [
  262. "orderCode" => $orderCode,
  263. "outCode" => $outCode,
  264. "apply_id" => $rm,
  265. "apply_name" => $ri,
  266. "addrid" => $vmp,
  267. "post_name" => "",
  268. "post_code" => "",
  269. "post_fee" => 0,
  270. "sendtime" => date("Y-m-d H:i:s"),
  271. "send_num" => $num,
  272. "check_num" => 0,
  273. "error_num" => 0,
  274. "wsm_code" => $cgdinfo['wsm_code'],
  275. "order_type" => 1,
  276. "status" => 1,
  277. "addtime" => date("Y-m-d H:i:s"),
  278. "updatetime" => date("Y-m-d H:i:s")
  279. ];
  280. $ou = Db::name("order_out")->insert($out);
  281. if ($ou == false) throw new Exception('发货地址添加创建失败');
  282. else {
  283. //修改状态,添加待办
  284. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  285. "order_code" => $outCode,//出库单号
  286. "status" => 0,//这里的status是之前的值
  287. "action_remark" => '',//备注
  288. "action_type" => "create"//新建create,编辑edit,更改状态status
  289. ], "CKD", 0, $out);
  290. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  291. "order_type" => 'CKD',
  292. "order_code" => $outCode,//出库单号
  293. "order_id" => 0,
  294. "order_status" => 0
  295. ]);
  296. }
  297. }
  298. } else throw new Exception('发货地址添加失败');
  299. }
  300. }
  301. //复用sale::create()方法 -- end
  302. //处理完成
  303. $order_import_from_c_db
  304. ->where('id', $c_data['id'])
  305. ->where('is_del', OIFCModel::$is_del_normal)
  306. ->save([
  307. 'status' => $order_import_from_c_db::$status_success,
  308. 'updatetime' => date('Y-m-d H:i:s'),
  309. 'remark' => '',
  310. 'updateid' => 0,
  311. 'updater' => 'system',
  312. 'orderCode' => $orderCode
  313. ]);
  314. Db::commit();
  315. $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
  316. } catch (\think\Exception $exception) {
  317. Db::rollback();
  318. $order_import_from_c_db
  319. ->where('id', $c_data['id'])
  320. ->save([
  321. 'status' => $order_import_from_c_db::$status_stock_not_enough,
  322. 'updatetime' => date('Y-m-d H:i:s'),
  323. 'remark' => $exception->getMessage(),
  324. 'updateid' => 0,
  325. 'updater' => 'system'
  326. ]);
  327. // 指令输出
  328. $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
  329. }
  330. }
  331. }
  332. //创建采购单
  333. private function createCgd($data = [], $rm = '0', $ri = '')
  334. {
  335. $cgdCode = makeNo("CG");
  336. $supplier = Db::name("supplier")
  337. ->where(["code" => $data['supplierNo'], "is_del" => 0])->find();
  338. if ($supplier == false) return false;
  339. $wsm = Db::name("warehouse_info")
  340. ->where(["supplierNo" => $data["supplierNo"], "companyNo" => $data['companyNo'], "is_del" => 0])
  341. ->find();
  342. if ($wsm == false) {
  343. $wsm_code = makeNo("WSM");
  344. $inwsm = [
  345. "wsm_code" => $wsm_code,
  346. "name" => $supplier['name'],
  347. "wsm_type" => 2,
  348. "supplierNo" => $supplier['code'],
  349. "addr" => "",
  350. "addrs_code" => "",
  351. "contactor" => 0,
  352. "contactor_name" => 0,
  353. "mobile" => "",
  354. "position" => "",
  355. "companyNo" => $data['companyNo'],
  356. "status" => 1,
  357. "is_del" => 0,
  358. "addtime" => date("Y-m-d H:i:s"),
  359. "updatetime" => date("Y-m-d H:i:s")
  360. ];
  361. $in = Db::name("warehouse_info")->insert($inwsm);
  362. if ($in == false) return false;
  363. } else {
  364. $wsm_code = $wsm['wsm_code'];
  365. }
  366. $cg = [
  367. "cgdNo" => $cgdCode,
  368. "bkcode" => "",
  369. "wsm_code" => $wsm_code,
  370. "cgder" => $supplier['person'],
  371. "cgder_id" => $supplier['personid'],
  372. "spuCode" => $data['spuCode'],
  373. "skuCode" => $data['skuCode'],
  374. "good_name" => $data['good_name'],
  375. "good_num" => $data['good_num'],
  376. "good_price" => $data['sale_price'],
  377. "total_fee" => round($data['sale_price'] * $data['good_num'], 2),
  378. "pakge_fee" => $data['pakge_fee'],
  379. "cert_fee" => $data['cert_fee'],
  380. "open_fee" => $data['open_fee'],
  381. "teach_fee" => $data['cost_fee'],
  382. "mark_fee" => $data['mark_fee'],
  383. "demo_fee" => $data['demo_fee'],
  384. #"weight"=>$data['weight'],
  385. "diff_weight" => "0",
  386. "diff_fee" => "0",
  387. "gold_price" => "0",
  388. "supplierNo" => $data['supplierNo'],
  389. "supplier_name" => $supplier['name'],
  390. "companyNo" => $data['companyNo'],
  391. "send_status" => 1,
  392. "send_num" => 0,
  393. "wsend_num" => $data['good_num'],
  394. "remark" => "",
  395. "status" => 0,//0初始化
  396. "lasttime" => date("Y-m-d H:i:s"),
  397. "is_del" => 0,
  398. "order_type" => $data['order_type'],
  399. "good_type" => $data['good_type'],
  400. "addtime" => date("Y-m-d H:i:s"),
  401. "updatetime" => date("Y-m-d H:i:s")
  402. ];
  403. $up = Db::name("purchease_order")->insert($cg, true);
  404. if ($up) {
  405. //修改状态,添加待办
  406. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  407. "order_code" => $cg['cgdNo'],//销售单code
  408. "status" => 0,//这里的status是之前的值
  409. "action_remark" => '',//备注
  410. "action_type" => "create"//新建create,编辑edit,更改状态status
  411. ], "CGD", $cg['status'], $cg);
  412. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  413. "order_type" => 'CGD',
  414. "order_code" => $cg['cgdNo'],//销售单code
  415. "order_id" => $up,
  416. "order_status" => $cg['status']
  417. ]);
  418. $rela = [
  419. "orderCode" => $data['orderCode'],
  420. "cgdNo" => $cgdCode,
  421. "spuCode" => $data['spuCode'],
  422. "good_num" => $data['good_num'],
  423. "wsend_num" => $data['good_num'],
  424. "send_num" => 0,
  425. "wait_num" => 0,
  426. "status" => 1,
  427. "source" => 2
  428. ];
  429. $re = Db::name("order_num")->save($rela);
  430. if ($re == false) return false;
  431. else {
  432. $stokc = Db::name("good_stock")
  433. ->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])
  434. ->find();
  435. if ($stokc == false) {
  436. $stokc = [
  437. "spuCode" => $data['spuCode'],
  438. "wsm_code" => $wsm_code,
  439. "wait_in_stock" => 0,
  440. "wait_out_stock" => 0,
  441. "usable_stock" => 0,
  442. "intra_stock" => 0,
  443. "total_stock" => 0,
  444. "status" => 1,
  445. "addtime" => date("Y-m-d H:i:s"),
  446. "updatetime" => date("Y-m-d H:i:s")
  447. ];
  448. $stoc = Db::name("good_stock")->save($stokc);
  449. if ($stoc == false) return false;
  450. }
  451. return true;
  452. }
  453. } else return false;
  454. }
  455. //创建.....
  456. private function RelaCgd(array $outinfo = [])
  457. {
  458. $cgd = Db::name("order_bk")
  459. ->where([
  460. ["spuCode", "=", $outinfo['spuCode']],
  461. ["is_del", "=", 0],
  462. ["balance_num", ">=", $outinfo['good_num']],
  463. ['companyNo', "=", $outinfo['companyNo']]
  464. ])
  465. ->lock(true)
  466. ->find();
  467. if ($cgd == false) return false;
  468. $cgdinfo = Db::name("purchease_order")
  469. ->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])
  470. ->find();
  471. if ($cgdinfo == false) return false;
  472. $QrdCgd = [
  473. "cgdNo" => makeNo("CG"),
  474. "bkcode" => $cgdinfo['bkcode'],
  475. 'wsm_code' => $cgdinfo['wsm_code'],
  476. "cgder_id" => $cgdinfo['cgder_id'],
  477. "cgder" => $cgdinfo['cgder'],
  478. "spuCode" => $cgdinfo['spuCode'],
  479. "good_name" => $cgdinfo['good_name'],
  480. "good_num" => $cgdinfo['good_num'],
  481. "good_price" => $cgdinfo['good_price'],
  482. "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
  483. "pakge_fee" => $cgdinfo['pakge_fee'],
  484. "cert_fee" => $cgdinfo['cert_fee'],
  485. "open_fee" => $cgdinfo['open_fee'],
  486. "delivery_fee" => $cgdinfo['delivery_fee'],
  487. "mark_fee" => $cgdinfo['mark_fee'],
  488. "teach_fee" => $cgdinfo['teach_fee'],
  489. "nake_fee" => $cgdinfo['nake_fee'],
  490. "demo_fee" => $cgdinfo['demo_fee'],
  491. "weight" => $cgdinfo['weight'],
  492. "diff_weight" => $cgdinfo['diff_weight'],
  493. "diff_fee" => $cgdinfo['diff_fee'],
  494. "gold_price" => $cgdinfo['gold_price'],
  495. "supplierNo" => $cgdinfo['supplierNo'],
  496. "supplier_name" => $cgdinfo['supplier_name'],
  497. "companyNo" => $cgdinfo['companyNo'],
  498. "send_status" => 3,
  499. "send_num" => $outinfo['good_num'],
  500. "wsend_num" => 0,
  501. "remark" => $cgdinfo['remark'],
  502. "status" => 3,
  503. "lasttime" => $cgdinfo['lasttime'],
  504. "is_del" => 0,
  505. "order_type" => 5,
  506. "good_type" => $cgdinfo['good_type'],
  507. "addtime" => date("Y-m-d H:i:s"),
  508. "updatetime" => date("Y-m-d H:i:s")
  509. ];
  510. $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
  511. if ($insetrCgd == false) return false;
  512. $merge_num = Db::name("purchease_order")
  513. ->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => 5, "is_del" => 0])
  514. ->field("sum(send_num)-sum(th_num) as num")
  515. ->find();
  516. $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
  517. $cgd['merge_num'] = $merge_num['num'];
  518. $cgd['updatetime'] = date("Y-m-d H:i:s");
  519. $up = Db::name("order_bk")->save($cgd);
  520. if ($up == false) return false;
  521. $data = [
  522. "orderCode" => $outinfo['orderCode'],
  523. "cgdNo" => $QrdCgd['cgdNo'],
  524. "spuCode" => $outinfo['spuCode'],
  525. "companyNo" => $outinfo['companyNo'],
  526. "good_num" => $outinfo['good_num'],
  527. "wsend_num" => $outinfo['good_num'],
  528. "send_num" => 0,
  529. "wait_num" => $outinfo['good_num'],
  530. "status" => 1,
  531. "source" => 1,
  532. ];
  533. $order = Db::name("order_num")->save($data);
  534. if ($order == false) return false;
  535. return true;
  536. }
  537. }