ImportOrderFromCHandleData.php 27 KB

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