ImportOrderFromCHandleData.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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.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. }
  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. $sale_price = $good['sale_price'];
  105. if ($ct['is_gold_price'] == 1) {
  106. $gold = Db::name("gold_price1")
  107. ->field('id,price')
  108. ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
  109. ->order("addtime desc")
  110. ->find();
  111. //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
  112. $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'];
  113. // $order_rate = Db::name("cat")->where(["id" => $ct['cat_id']])->value('order_rate');
  114. // $budget = isset($order_rate) ? $order_rate / 100 : 0;
  115. // $saleprice = $total_fee / (1 - $budget);
  116. }
  117. if ($is_activity == 1) {
  118. $act = Db::name("activity_info")
  119. ->alias("a")
  120. ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  121. ->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])
  122. ->find();
  123. if ($act == false) throw new Exception('未找到相关活动价');
  124. if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
  125. if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
  126. $sale_price = $act['activity_price'];
  127. }
  128. }
  129. $cgd = [
  130. "supplierNo" => $ct['supplierNo'],
  131. "companyNo" => $supplierNo,
  132. "orderCode" => $orderCode,
  133. "spuCode" => $ct['spuCode'],
  134. "skuCode" => $ct['skuCode'],
  135. "good_name" => $ct['good_name'],
  136. "sale_price" => $origin_price,
  137. "total_fee" => $origin_price * $good_num,
  138. "pakge_fee" => $ct['packing_fee'],
  139. "cert_fee" => $ct['cert_fee'],
  140. "open_fee" => $ct['open_fee'],
  141. "cost_fee" => $ct['cost_fee'],
  142. "mark_fee" => $ct['mark_fee'],
  143. "demo_fee" => $ct['demo_fee'],
  144. "good_num" => $good_num,
  145. "good_type" => $goodtype,
  146. "order_type" => $is_stock == 1 ? 1 : 2,
  147. "createrid" => $ct['createrid'],
  148. "creater" => $ct['creater'],
  149. 'send_way' => 2
  150. ];
  151. $send_num = $extend_data['num'];
  152. $remark = $extend_data['order_remark'];
  153. $rm = $c_data['createrid'];
  154. $ri = $c_data['creater'];
  155. $data = [
  156. "orderCode" => $orderCode,
  157. "good_code" => $spuCode,
  158. "skuCode" => $skuCode,
  159. "customer_code" => $customer_code,
  160. "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
  161. "good_num" => $good_num,
  162. "cat_id" => $goodinfo['cat_id'],
  163. "apply_id" => $rm,
  164. "apply_name" => $ri,
  165. "origin_price" => $origin_price,
  166. "sale_price" => $sale_price,
  167. "post_fee" => 0,
  168. "status" => $send_num == 0 ? 3 : ($good_num == $send_num ? 5 : 4),
  169. "send_num" => $send_num,
  170. "wsend_num" => $good_num - $send_num,
  171. "send_status" => $good_num == $send_num ? 3 : ($send_num == 0 ? 1 : 2),
  172. "status" => 0,
  173. "send_num" => 0,
  174. "wsend_num" => $good_num,
  175. "send_status" => 1,
  176. "good_type" => $goodtype,
  177. "send_type" => $sendtype,
  178. "supplierNo" => $extend_data['companyNo'],
  179. "is_del" => 0,
  180. "zxNo" => "",
  181. "platform_order" => $platform_order,
  182. "platform_id" => $platform_id,
  183. "remark" => $remark,
  184. "is_stock" => $is_stock,
  185. "is_activity" => $is_activity === "" ? 0 : $is_activity,
  186. "order_type" => $order_type,
  187. // "poNo"=>$poNo,
  188. 'good_weight' => $ct['weight'],
  189. 'gold_price' => $ct['cgd_gold_price'],
  190. 'cost_price' => $ct['cost_fee'],
  191. 'diff_weight' => 0,
  192. 'diff_fee' => 0,
  193. "workNo" => $workNo,
  194. "addtime" => date("Y-m-d H:i:s"),
  195. "updatetime" => date("Y-m-d H:i:s"),
  196. 'total_price' => round($sale_price * $good_num, 2),
  197. ];
  198. $paytime == "" ? "" : $data['paytime'] = $paytime;
  199. $datainfo = Db::name('sale')->insert($data, true);
  200. if ($datainfo > 0) {
  201. if ($is_activity == 1) {
  202. $actup = [
  203. "activity_stock" => $act['activity_stock'] - $good_num,
  204. "updatetime" => date("Y-m-d H:i:s")
  205. ];
  206. $actupp = Db::name("activity_info")
  207. ->where(["skuCode" => $skuCode, "activity_code" => $extend_data['activity_code'], "is_del" => 0, "status" => 1])
  208. ->save($actup);
  209. if ($actupp == false) throw new Exception('活动库存修改失败');
  210. }
  211. if ($is_stock == 0) {
  212. //非库存品
  213. $bol = $this->createCgd($cgd, $rm, $ri);
  214. if ($bol == false) throw new Exception('订单创建失败');
  215. } else {
  216. //库存品
  217. $bol = $this->RelaCgd(['orderCode' => $orderCode, "good_num" => $good_num, "spuCode" => $spuCode, "companyNo" => $supplierNo]);
  218. if ($bol == false) throw new Exception('库存商品关联采购单失败');
  219. if (isset($stock)) {
  220. $stck = [
  221. "usable_stock" => $stock['usable_stock'] - $good_num,
  222. "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
  223. "updatetime" => date("Y-m-d H:i:s")
  224. ];
  225. $upad = Db::name("good_stock")
  226. ->where($stock)
  227. ->update($stck);
  228. if ($upad == false) throw new Exception('库存商品更新库存失败');
  229. //商品变动日志表,good_log_code字段存储采购单号
  230. $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
  231. $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $datainfo, "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
  232. GoodLog::LogAdd(['id' => $rm, 'nickname' => $ri], $good_data, "XSQRD");
  233. }
  234. }
  235. if ($sendtype == 1) {
  236. $temp = [
  237. 'orderCode' => $orderCode,
  238. 'contactor' => $extend_data['contactor'],
  239. 'mobile' => $extend_data['mobile'],
  240. 'addr' => $extend_data['addr'],
  241. 'addr_code' => $extend_data['addr_code'],
  242. 'customer_code' => $customer_code,
  243. 'receipt_quantity' => $extend_data['num'],//收货数量,
  244. 'post_fee' => 0,
  245. 'is_del' => 0,
  246. 'addtime' => date("Y-m-d H:i:s"),
  247. 'updatetime' => date("Y-m-d H:i:s"),
  248. 'arrive_time' => $arrtime,
  249. ];
  250. $vmp = Db::name('order_addr')->insert($temp, true);
  251. if ($vmp > 0) {
  252. $order = Db::name("order_num")
  253. ->where(["orderCode" => $orderCode, "status" => 1])
  254. ->where([["wsend_num", ">=", 0]])
  255. ->lock(true)
  256. ->find();
  257. if ($order == false) throw new Exception('未找到可以发货得采购单数据');
  258. $num = $extend_data['num'];
  259. $outCode = makeNo("DF");
  260. $order['wsend_num'] -= $num;
  261. $order['send_num'] += $num;
  262. $or = Db::name("order_num")->save($order);
  263. if ($or == false) throw new Exception('发货地址更新失败');
  264. $tep = [
  265. "cgdNo" => $order['cgdNo'],
  266. "outCode" => $outCode,
  267. "send_num" => $num,
  268. "status" => 1,
  269. "addtime" => date("Y-m-d H:i:s"),
  270. "updatetime" => date("Y-m-d H:i:s")
  271. ];
  272. $sen = Db::name("order_send")->save($tep);
  273. if ($sen == false) throw new Exception('发货地址添加创建失败');
  274. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  275. if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
  276. $out = [
  277. "orderCode" => $orderCode,
  278. "outCode" => $outCode,
  279. "apply_id" => $rm,
  280. "apply_name" => $ri,
  281. "addrid" => $vmp,
  282. "post_name" => "",
  283. "post_code" => "",
  284. "post_fee" => 0,
  285. "sendtime" => date("Y-m-d H:i:s"),
  286. "send_num" => $num,
  287. "check_num" => 0,
  288. "error_num" => 0,
  289. "wsm_code" => $cgdinfo['wsm_code'],
  290. "order_type" => 1,
  291. "status" => $is_stock == 1 ? 1 : 0,
  292. "addtime" => date("Y-m-d H:i:s"),
  293. "updatetime" => date("Y-m-d H:i:s")
  294. ];
  295. $ou = Db::name("order_out")->insert($out);
  296. if ($ou == false) throw new Exception('发货地址添加创建失败');
  297. else {
  298. //修改状态,添加待办
  299. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  300. "order_code" => $outCode,//出库单号
  301. "status" => 0,//这里的status是之前的值
  302. "action_remark" => '',//备注
  303. "action_type" => "create"//新建create,编辑edit,更改状态status
  304. ], "CKD", 0, $out);
  305. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  306. "order_type" => 'CKD',
  307. "order_code" => $outCode,//出库单号
  308. "order_id" => 0,
  309. "order_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" => $supplier['person'],
  385. "cgder_id" => $supplier['personid'],
  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. ]);
  432. $rela = [
  433. "orderCode" => $data['orderCode'],
  434. "cgdNo" => $cgdCode,
  435. "spuCode" => $data['spuCode'],
  436. "good_num" => $data['good_num'],
  437. "wsend_num" => $data['good_num'],
  438. "send_num" => 0,
  439. "wait_num" => 0,
  440. "status" => 1,
  441. "source" => 2
  442. ];
  443. $re = Db::name("order_num")->save($rela);
  444. if ($re == false) return false;
  445. else {
  446. $stokc = Db::name("good_stock")
  447. ->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])
  448. ->find();
  449. if ($stokc == false) {
  450. $stokc = [
  451. "spuCode" => $data['spuCode'],
  452. "wsm_code" => $wsm_code,
  453. "wait_in_stock" => 0,
  454. "wait_out_stock" => 0,
  455. "usable_stock" => 0,
  456. "intra_stock" => 0,
  457. "total_stock" => 0,
  458. "status" => 1,
  459. "addtime" => date("Y-m-d H:i:s"),
  460. "updatetime" => date("Y-m-d H:i:s")
  461. ];
  462. $stoc = Db::name("good_stock")->save($stokc);
  463. if ($stoc == false) return false;
  464. }
  465. return true;
  466. }
  467. } else return false;
  468. }
  469. //创建.....
  470. private function RelaCgd(array $outinfo = [])
  471. {
  472. //备库单
  473. $cgd = Db::name("order_bk")
  474. ->where([
  475. ["spuCode", "=", $outinfo['spuCode']],
  476. ["is_del", "=", 0],
  477. ["balance_num", ">=", $outinfo['good_num']],
  478. ['companyNo', "=", $outinfo['companyNo']]
  479. ])
  480. ->lock(true)
  481. ->find();
  482. if ($cgd == false) return false;
  483. $cgdinfo = Db::name("purchease_order")
  484. ->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])
  485. ->find();
  486. if ($cgdinfo == false) return false;
  487. $QrdCgd = [
  488. "cgdNo" => makeNo("CG"),
  489. "bkcode" => $cgdinfo['bkcode'],
  490. 'wsm_code' => $cgdinfo['wsm_code'],
  491. "cgder_id" => $cgdinfo['cgder_id'],
  492. "cgder" => $cgdinfo['cgder'],
  493. "spuCode" => $cgdinfo['spuCode'],
  494. "good_name" => $cgdinfo['good_name'],
  495. "good_num" => $cgdinfo['good_num'],
  496. "good_price" => $cgdinfo['good_price'],
  497. "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
  498. "pakge_fee" => $cgdinfo['pakge_fee'],
  499. "cert_fee" => $cgdinfo['cert_fee'],
  500. "open_fee" => $cgdinfo['open_fee'],
  501. "delivery_fee" => $cgdinfo['delivery_fee'],
  502. "mark_fee" => $cgdinfo['mark_fee'],
  503. "teach_fee" => $cgdinfo['teach_fee'],
  504. "nake_fee" => $cgdinfo['nake_fee'],
  505. "demo_fee" => $cgdinfo['demo_fee'],
  506. "weight" => $cgdinfo['weight'],
  507. "diff_weight" => $cgdinfo['diff_weight'],
  508. "diff_fee" => $cgdinfo['diff_fee'],
  509. "gold_price" => $cgdinfo['gold_price'],
  510. "supplierNo" => $cgdinfo['supplierNo'],
  511. "supplier_name" => $cgdinfo['supplier_name'],
  512. "companyNo" => $cgdinfo['companyNo'],
  513. "send_status" => 3,
  514. "send_num" => $outinfo['good_num'],
  515. "wsend_num" => 0,
  516. "remark" => $cgdinfo['remark'],
  517. "status" => 3,//入库完成
  518. "lasttime" => $cgdinfo['lasttime'],
  519. "is_del" => 0,
  520. "order_type" => 5,
  521. "good_type" => $cgdinfo['good_type'],
  522. "addtime" => date("Y-m-d H:i:s"),
  523. "updatetime" => date("Y-m-d H:i:s")
  524. ];
  525. $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
  526. if ($insetrCgd == false) return false;
  527. $merge_num = Db::name("purchease_order")
  528. ->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => 5, "is_del" => 0])
  529. ->field("sum(send_num)-sum(th_num) as num")
  530. ->find();
  531. $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
  532. $cgd['merge_num'] = $merge_num['num'];
  533. $cgd['updatetime'] = date("Y-m-d H:i:s");
  534. $up = Db::name("order_bk")->save($cgd);
  535. if ($up == false) return false;
  536. $data = [
  537. "orderCode" => $outinfo['orderCode'],
  538. "cgdNo" => $QrdCgd['cgdNo'],
  539. "spuCode" => $outinfo['spuCode'],
  540. "companyNo" => $outinfo['companyNo'],
  541. "good_num" => $outinfo['good_num'],
  542. "wsend_num" => $outinfo['good_num'],
  543. "send_num" => 0,
  544. "wait_num" => $outinfo['good_num'],
  545. "status" => 1,
  546. "source" => 1,
  547. ];
  548. $order = Db::name("order_num")->save($data);
  549. if ($order == false) return false;
  550. return true;
  551. }
  552. }