ImportOrderFromCHandleData.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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_id'];
  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.skuCode' => $extend_data['skuCode'], 'a.exam_status' => 6])//exam_status==6已上线
  72. ->field("b.*,a.skuCode,a.spuCode,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.wsm_type' => 5, "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. $origin_price = 0;
  90. } else {
  91. $origin = Db::name("good_nake")
  92. ->where([["spuCode", "=", $spuCode], ["min_num", "<=", $good_num], ["is_del", "=", 0]])
  93. ->order("min_num desc")
  94. ->find();
  95. if ($origin == false) throw new Exception('未找到相关成本价格');
  96. $origin_price = $origin['nake_total'];
  97. }
  98. $sale_price = $extend_data['price'];
  99. if ($goodtype == 1) {
  100. $good = Db::name("good_ladder")
  101. ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
  102. ->where([["min_num", "<=", $good_num]])
  103. ->order("min_num desc")
  104. ->find();
  105. if ($good == false) throw new Exception('未找到相关阶梯价格');
  106. $sale_price = $good['sale_price'];
  107. if ($ct['is_gold_price'] == 1 && $is_stock != 1) {
  108. $gold = Db::name("gold_price1")
  109. ->field('id,price')
  110. ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
  111. ->order("addtime desc")
  112. ->find();
  113. //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
  114. $sale_price = $ct['demo_fee'] / $good_num + $ct['open_fee'] / $good_num + $ct['noble_weight'] * $gold["price"] + $good['cost_fee'] * $ct['noble_weight'] + $origin['package_fee'] + $origin['mark_fee'] + $origin['cert_fee'] + $origin['nake_fee'] + $origin['delivery_fee'];
  115. $ct['cgd_gold_price'] = $gold['price'];
  116. // $order_rate = Db::name("cat")->where(["id" => $ct['cat_id']])->value('order_rate');
  117. // $budget = isset($order_rate) ? $order_rate / 100 : 0;
  118. // $saleprice = $total_fee / (1 - $budget);
  119. }
  120. if ($is_activity == 1) {
  121. $act = Db::name("activity_info")
  122. ->alias("a")
  123. ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  124. ->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])
  125. ->find();
  126. if ($act == false) throw new Exception('未找到相关活动价');
  127. if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
  128. if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
  129. $sale_price = $act['activity_price'];
  130. }
  131. }
  132. $cgd = [
  133. "supplierNo" => $ct['supplierNo'],
  134. "companyNo" => $supplierNo,
  135. "orderCode" => $orderCode,
  136. "spuCode" => $ct['spuCode'],
  137. "skuCode" => $ct['skuCode'],
  138. "good_name" => $ct['good_name'],
  139. "sale_price" => $origin_price,
  140. "total_fee" => $origin_price * $good_num,
  141. "pakge_fee" => $ct['packing_fee'],
  142. "cert_fee" => $ct['cert_fee'],
  143. "open_fee" => $ct['open_fee'],
  144. "cost_fee" => $ct['cost_fee'],
  145. "mark_fee" => $ct['mark_fee'],
  146. "demo_fee" => $ct['demo_fee'],
  147. "good_num" => $good_num,
  148. "good_type" => $goodtype,
  149. "order_type" => $is_stock == 1 ? 1 : 2,
  150. "createrid" => $ct['createrid'],
  151. "creater" => $ct['creater'],
  152. 'send_way' => 2
  153. ];
  154. $send_num = $extend_data['num'];
  155. $remark = $extend_data['order_remark'];
  156. $rm = $c_data['createrid'];
  157. $ri = $c_data['creater'];
  158. $data = [
  159. "orderCode" => $orderCode,
  160. "good_code" => $spuCode,
  161. "skuCode" => $skuCode,
  162. "customer_code" => $customer_code,
  163. "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
  164. "good_num" => $good_num,
  165. "cat_id" => $goodinfo['cat_id'],
  166. "apply_id" => $rm,
  167. "apply_name" => $ri,
  168. "origin_price" => $origin_price,
  169. "sale_price" => $sale_price,
  170. "post_fee" => 0,
  171. "status" => 0,
  172. "send_num" => 0,
  173. "wsend_num" => $good_num,
  174. "send_status" => 1,
  175. "good_type" => $goodtype,
  176. "send_type" => $sendtype,
  177. "supplierNo" => $extend_data['companyNo'],
  178. "is_del" => 0,
  179. "zxNo" => "",
  180. "platform_order" => $platform_order,
  181. "platform_id" => $platform_id,
  182. "remark" => $remark,
  183. "is_stock" => $is_stock,
  184. "is_activity" => $is_activity === "" ? 0 : $is_activity,
  185. "order_type" => $order_type,
  186. // "poNo"=>$poNo,
  187. 'good_weight' => $ct['weight'],
  188. 'gold_price' => $ct['cgd_gold_price'],
  189. 'cost_price' => $ct['cost_fee'],
  190. 'diff_weight' => 0,
  191. 'diff_fee' => 0,
  192. "workNo" => $workNo,
  193. "addtime" => date("Y-m-d H:i:s"),
  194. "updatetime" => date("Y-m-d H:i:s"),
  195. 'total_price' => round($sale_price * $good_num, 2),
  196. ];
  197. $paytime == "" ? "" : $data['paytime'] = $paytime;
  198. $datainfo = Db::name('sale')->insert($data, true);
  199. if ($datainfo > 0) {
  200. if ($is_activity == 1) {
  201. $actup = [
  202. "activity_stock" => $act['activity_stock'] - $good_num,
  203. "updatetime" => date("Y-m-d H:i:s")
  204. ];
  205. $actupp = Db::name("activity_info")
  206. ->where(["skuCode" => $skuCode, "activity_code" => $extend_data['activity_code'], "is_del" => 0, "status" => 1])
  207. ->save($actup);
  208. if ($actupp == false) throw new Exception('活动库存修改失败');
  209. }
  210. if ($is_stock == 0) {
  211. //非库存品
  212. $bol = $this->createCgd($cgd, $rm, $ri);
  213. if ($bol == false) throw new Exception('订单创建失败');
  214. } else {
  215. //库存品
  216. $bol = $this->RelaCgd(['orderCode' => $orderCode, "good_num" => $good_num, "spuCode" => $spuCode, "companyNo" => $supplierNo]);
  217. if ($bol == false) throw new Exception('库存商品关联采购单失败');
  218. if (isset($stock)) {
  219. $stck = [
  220. "usable_stock" => $stock['usable_stock'] - $good_num,
  221. "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
  222. "updatetime" => date("Y-m-d H:i:s")
  223. ];
  224. $upad = Db::name("good_stock")
  225. ->where($stock)
  226. ->update($stck);
  227. if ($upad == false) throw new Exception('库存商品更新库存失败');
  228. //商品变动日志表,good_log_code字段存储采购单号
  229. $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
  230. $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
  231. GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
  232. }
  233. }
  234. if ($sendtype == 1) {
  235. $temp = [
  236. 'orderCode' => $orderCode,
  237. 'contactor' => $extend_data['contactor'],
  238. 'mobile' => $extend_data['mobile'],
  239. 'addr' => $extend_data['addr'],
  240. 'addr_code' => $extend_data['addr_code'],
  241. 'customer_code' => $customer_code,
  242. 'receipt_quantity' => $extend_data['num'],//收货数量,
  243. 'post_fee' => 0,
  244. 'is_del' => 0,
  245. 'addtime' => date("Y-m-d H:i:s"),
  246. 'updatetime' => date("Y-m-d H:i:s"),
  247. 'arrive_time' => $arrtime,
  248. ];
  249. $vmp = Db::name('order_addr')->insert($temp, true);
  250. if ($vmp > 0) {
  251. $order = Db::name("order_num")
  252. ->where(["orderCode" => $orderCode, "status" => 1])
  253. ->where([["wsend_num", ">=", 0]])
  254. ->lock(true)
  255. ->find();
  256. if ($order == false) throw new Exception('未找到可以发货得采购单数据');
  257. $num = $extend_data['num'];
  258. $outCode = makeNo("DF");
  259. $order['wsend_num'] -= $num;
  260. $order['send_num'] += $num;
  261. $or = Db::name("order_num")->save($order);
  262. if ($or == false) throw new Exception('发货地址更新失败');
  263. $tep = [
  264. "cgdNo" => $order['cgdNo'],
  265. "outCode" => $outCode,
  266. "send_num" => $num,
  267. "status" => 1,
  268. "addtime" => date("Y-m-d H:i:s"),
  269. "updatetime" => date("Y-m-d H:i:s")
  270. ];
  271. $sen = Db::name("order_send")->save($tep);
  272. if ($sen == false) throw new Exception('发货地址添加创建失败');
  273. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  274. if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
  275. $out = [
  276. "orderCode" => $orderCode,
  277. "outCode" => $outCode,
  278. "apply_id" => $rm,
  279. "apply_name" => $ri,
  280. "addrid" => $vmp,
  281. "post_name" => "",
  282. "post_code" => "",
  283. "post_fee" => 0,
  284. "sendtime" => date("Y-m-d H:i:s"),
  285. "send_num" => $num,
  286. "check_num" => 0,
  287. "error_num" => 0,
  288. "wsm_code" => $cgdinfo['wsm_code'],
  289. "order_type" => 1,
  290. "status" => $is_stock == 1 ? 1 : 0,
  291. "addtime" => date("Y-m-d H:i:s"),
  292. "updatetime" => date("Y-m-d H:i:s")
  293. ];
  294. $ou = Db::name("order_out")->insert($out);
  295. if ($ou == false) throw new Exception('发货地址添加创建失败');
  296. else {
  297. //修改状态,添加待办
  298. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  299. "order_code" => $outCode,//出库单号
  300. "status" => 0,//这里的status是之前的值
  301. "action_remark" => '',//备注
  302. "action_type" => "create"//新建create,编辑edit,更改状态status
  303. ], "CKD", 0, $out);
  304. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  305. "order_type" => 'CKD',
  306. "order_code" => $outCode,//出库单号
  307. "order_id" => 0,
  308. "order_status" => 0,
  309. "before_status" => 0
  310. ]);
  311. }
  312. } else throw new Exception('发货地址添加失败');
  313. }
  314. }
  315. //复用sale::create()方法 -- end
  316. //处理完成
  317. $order_import_from_c_db
  318. ->where('id', $c_data['id'])
  319. ->where('is_del', OIFCModel::$is_del_normal)
  320. ->save([
  321. 'status' => $order_import_from_c_db::$status_success,
  322. 'updatetime' => date('Y-m-d H:i:s'),
  323. 'remark' => '',
  324. 'updateid' => 0,
  325. 'updater' => 'system',
  326. 'orderCode' => $orderCode
  327. ]);
  328. Db::commit();
  329. $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
  330. } catch (\think\Exception $exception) {
  331. Db::rollback();
  332. $order_import_from_c_db
  333. ->where('id', $c_data['id'])
  334. ->save([
  335. 'status' => $order_import_from_c_db::$status_stock_not_enough,
  336. 'updatetime' => date('Y-m-d H:i:s'),
  337. 'remark' => $exception->getMessage(),
  338. 'updateid' => 0,
  339. 'updater' => 'system'
  340. ]);
  341. // 指令输出
  342. $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
  343. }
  344. }
  345. }
  346. //创建采购单
  347. private function createCgd($data = [], $rm = '0', $ri = '')
  348. {
  349. $cgdCode = makeNo("CG");
  350. $supplier = Db::name("supplier")
  351. ->where(["code" => $data['supplierNo'], "is_del" => 0])->find();
  352. if ($supplier == false) return false;
  353. $wsm = Db::name("warehouse_info")
  354. ->where(["supplierNo" => $data["supplierNo"], "companyNo" => $data['companyNo'], "is_del" => 0])
  355. ->find();
  356. if ($wsm == false) {
  357. $wsm_code = makeNo("WSM");
  358. $inwsm = [
  359. "wsm_code" => $wsm_code,
  360. "name" => $supplier['name'],
  361. "wsm_type" => 2,
  362. "supplierNo" => $supplier['code'],
  363. "addr" => "",
  364. "addrs_code" => "",
  365. "contactor" => 0,
  366. "contactor_name" => 0,
  367. "mobile" => "",
  368. "position" => "",
  369. "companyNo" => $data['companyNo'],
  370. "status" => 1,
  371. "is_del" => 0,
  372. "addtime" => date("Y-m-d H:i:s"),
  373. "updatetime" => date("Y-m-d H:i:s")
  374. ];
  375. $in = Db::name("warehouse_info")->insert($inwsm);
  376. if ($in == false) return false;
  377. } else {
  378. $wsm_code = $wsm['wsm_code'];
  379. }
  380. $cg = [
  381. "cgdNo" => $cgdCode,
  382. "bkcode" => "",
  383. "wsm_code" => $wsm_code,
  384. "cgder" => $data['creater'],
  385. "cgder_id" => $data['createrid'],
  386. "spuCode" => $data['spuCode'],
  387. "skuCode" => $data['skuCode'],
  388. "good_name" => $data['good_name'],
  389. "good_num" => $data['good_num'],
  390. "good_price" => $data['sale_price'],
  391. "total_fee" => round($data['sale_price'] * $data['good_num'], 2),
  392. "pakge_fee" => $data['pakge_fee'],
  393. "cert_fee" => $data['cert_fee'],
  394. "open_fee" => $data['open_fee'],
  395. "teach_fee" => $data['cost_fee'],
  396. "mark_fee" => $data['mark_fee'],
  397. "demo_fee" => $data['demo_fee'],
  398. #"weight"=>$data['weight'],
  399. "diff_weight" => "0",
  400. "diff_fee" => "0",
  401. "gold_price" => "0",
  402. "supplierNo" => $data['supplierNo'],
  403. "supplier_name" => $supplier['name'],
  404. "companyNo" => $data['companyNo'],
  405. "send_status" => 1,
  406. "send_num" => 0,
  407. "wsend_num" => $data['good_num'],
  408. "remark" => "",
  409. "status" => 0,//0初始化
  410. "lasttime" => date("Y-m-d H:i:s"),
  411. "is_del" => 0,
  412. "order_type" => $data['order_type'],
  413. "good_type" => $data['good_type'],
  414. "addtime" => date("Y-m-d H:i:s"),
  415. "updatetime" => date("Y-m-d H:i:s")
  416. ];
  417. $up = Db::name("purchease_order")->insert($cg, true);
  418. if ($up) {
  419. //修改状态,添加待办
  420. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  421. "order_code" => $cg['cgdNo'],//销售单code
  422. "status" => 0,//这里的status是之前的值
  423. "action_remark" => '',//备注
  424. "action_type" => "create"//新建create,编辑edit,更改状态status
  425. ], "CGD", $cg['status'], $cg);
  426. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  427. "order_type" => 'CGD',
  428. "order_code" => $cg['cgdNo'],//销售单code
  429. "order_id" => $up,
  430. "order_status" => $cg['status'],
  431. "before_status" => 0
  432. ]);
  433. $rela = [
  434. "orderCode" => $data['orderCode'],
  435. "cgdNo" => $cgdCode,
  436. "spuCode" => $data['spuCode'],
  437. "good_num" => $data['good_num'],
  438. "wsend_num" => $data['good_num'],
  439. "send_num" => 0,
  440. "wait_num" => 0,
  441. "status" => 1,
  442. "source" => 2
  443. ];
  444. $re = Db::name("order_num")->save($rela);
  445. if ($re == false) return false;
  446. else {
  447. $stokc = Db::name("good_stock")
  448. ->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])
  449. ->find();
  450. if ($stokc == false) {
  451. $stokc = [
  452. "spuCode" => $data['spuCode'],
  453. "wsm_code" => $wsm_code,
  454. "wait_in_stock" => 0,
  455. "wait_out_stock" => 0,
  456. "usable_stock" => 0,
  457. "intra_stock" => 0,
  458. "total_stock" => 0,
  459. "status" => 1,
  460. "addtime" => date("Y-m-d H:i:s"),
  461. "updatetime" => date("Y-m-d H:i:s")
  462. ];
  463. $stoc = Db::name("good_stock")->save($stokc);
  464. if ($stoc == false) return false;
  465. }
  466. return true;
  467. }
  468. } else return false;
  469. }
  470. //创建.....
  471. private function RelaCgd(array $outinfo = [])
  472. {
  473. //备库单
  474. $cgd = Db::name("order_bk")
  475. ->where([
  476. ["spuCode", "=", $outinfo['spuCode']],
  477. ["is_del", "=", 0],
  478. ["balance_num", ">=", $outinfo['good_num']],
  479. ['companyNo', "=", $outinfo['companyNo']]
  480. ])
  481. ->lock(true)
  482. ->find();
  483. if ($cgd == false) return false;
  484. $cgdinfo = Db::name("purchease_order")
  485. ->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])
  486. ->find();
  487. if ($cgdinfo == false) return false;
  488. $QrdCgd = [
  489. "cgdNo" => makeNo("CG"),
  490. "bkcode" => $cgdinfo['bkcode'],
  491. 'wsm_code' => $cgdinfo['wsm_code'],
  492. "cgder_id" => $cgdinfo['cgder_id'],
  493. "cgder" => $cgdinfo['cgder'],
  494. "spuCode" => $cgdinfo['spuCode'],
  495. "good_name" => $cgdinfo['good_name'],
  496. "good_num" => $outinfo['good_num'],
  497. "good_price" => $cgdinfo['good_price'],
  498. "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
  499. "pakge_fee" => $cgdinfo['pakge_fee'],
  500. "cert_fee" => $cgdinfo['cert_fee'],
  501. "open_fee" => $cgdinfo['open_fee'],
  502. "delivery_fee" => $cgdinfo['delivery_fee'],
  503. "mark_fee" => $cgdinfo['mark_fee'],
  504. "teach_fee" => $cgdinfo['teach_fee'],
  505. "nake_fee" => $cgdinfo['nake_fee'],
  506. "demo_fee" => $cgdinfo['demo_fee'],
  507. "weight" => $cgdinfo['weight'],
  508. "diff_weight" => $cgdinfo['diff_weight'],
  509. "diff_fee" => $cgdinfo['diff_fee'],
  510. "gold_price" => $cgdinfo['gold_price'],
  511. "supplierNo" => $cgdinfo['supplierNo'],
  512. "supplier_name" => $cgdinfo['supplier_name'],
  513. "companyNo" => $cgdinfo['companyNo'],
  514. "send_status" => 3,
  515. "send_num" => $outinfo['good_num'],
  516. "wsend_num" => 0,
  517. "remark" => $cgdinfo['remark'],
  518. "status" => 3,//入库完成
  519. "lasttime" => $cgdinfo['lasttime'],
  520. "is_del" => 0,
  521. "order_type" => 5,//5平台订单导入
  522. "good_type" => $cgdinfo['good_type'],
  523. "addtime" => date("Y-m-d H:i:s"),
  524. "updatetime" => date("Y-m-d H:i:s")
  525. ];
  526. $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
  527. if ($insetrCgd == false) return false;
  528. $merge_num = Db::name("purchease_order")
  529. ->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => 5, "is_del" => 0])
  530. ->field("sum(send_num)-sum(th_num) as num")
  531. ->find();
  532. $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
  533. $cgd['merge_num'] = $merge_num['num'];
  534. $cgd['updatetime'] = date("Y-m-d H:i:s");
  535. $up = Db::name("order_bk")->save($cgd);
  536. if ($up == false) return false;
  537. $data = [
  538. "orderCode" => $outinfo['orderCode'],
  539. "cgdNo" => $QrdCgd['cgdNo'],
  540. "spuCode" => $outinfo['spuCode'],
  541. "companyNo" => $outinfo['companyNo'],
  542. "good_num" => $outinfo['good_num'],
  543. "wsend_num" => $outinfo['good_num'],
  544. "send_num" => 0,
  545. "wait_num" => $outinfo['good_num'],
  546. "status" => 1,
  547. "source" => 1,
  548. ];
  549. $order = Db::name("order_num")->save($data);
  550. if ($order == false) return false;
  551. return true;
  552. }
  553. }