handleCxData.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <?php
  2. namespace app\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\Exception;
  7. use think\facade\Db;
  8. use think\facade\Cache;
  9. //将cfp_caixiao_data里面的数据,分别处理到cfp_qrd_info,cfp_cgd_info(若未对账),或者cfp_caixiao_wait(已对账)
  10. class handleCxData extends command
  11. {
  12. private $interval = 15000 * 60;//执行间隔,单位:分(每次同步前5分钟的数据)
  13. protected function configure()
  14. {
  15. parent::configure(); // TODO: Change the autogenerated stub
  16. $this->setName('handleCxData')->setDescription('处理中间表的采销数据');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. $date = date('Y-m-d H:i:s');
  21. $goodset =Cache::store("redis")->get("JsHandle");
  22. if($goodset ==1) return;
  23. Cache::store("redis")->set("JsHandle",1,180);
  24. Db::startTrans();
  25. $results = Db::name('caixiao_data')
  26. ->withAttr("data",function ($v){
  27. return json_decode(str_replace(array("\r\n", "\r", "\n"), '', $v),true);
  28. })
  29. ->where("status",1)
  30. ->where("addtime",">=",date("Y-m-d H:i:s",strtotime(time()-1800)))
  31. ->lock(true)
  32. ->limit(100)
  33. ->select()->toArray();
  34. if ($results) {
  35. try {
  36. foreach ($results as $result) {
  37. $data=$result['data'] ?? [];
  38. $qrd_insert_data=$wait_insert_data=$cgd_insert_data=[];
  39. $data['cat_name']=is_array($data['cat_name']) ? $data['cat_name'] : json_decode($data['cat_name'],true);
  40. if ($result['order_type'] == 1) {
  41. $data['total_price']=$data['total_price'] - $data['th_fee'] - $data['diff_fee'];
  42. $exitReport=Db::name("report_code")->where('qrdNo' , $data['orderCode'])->findOrEmpty();
  43. $repostinsert=[
  44. "qrdNo"=>$data['orderCode'] ,
  45. "seller_id"=>$data['apply_id'] ,
  46. "seller"=>$data['apply_name'] ,
  47. "customerName"=>$data['customer_name'] ,
  48. "customerNo"=>$data['customer_code'] ,
  49. "companyNo"=>$data['supplierNo'] ,
  50. "companyName"=>$data['supplier_name'] ,
  51. "cgdNo"=>$data['cgdNo'] ,
  52. ];
  53. if (empty($exitReport)) Db::name("report_code")->insert($repostinsert);
  54. else Db::name("report_code")->where($exitReport)->update($repostinsert);
  55. $exists_qrd=Db::name('qrd_info')
  56. ->whereIn('sequenceNo' , $data['orderCode'])
  57. ->field('id,status')->findOrEmpty();
  58. $all_branch=Db::name('customer_info')
  59. ->whereIn('companyNo' , $data['customer_code'])
  60. ->column('branch,parent' , 'companyNo');
  61. //已存在
  62. if (!empty($exists_qrd)) {
  63. if ($exists_qrd['status'] == 0) {
  64. $report=[
  65. "qrdNo"=>$data['orderCode'] ,
  66. "seller_id"=>$data['apply_id'] ,
  67. "seller"=>$data['apply_name'] ,
  68. "customerName"=>$data['customer_name'] ,
  69. "customerNo"=>$data['customer_code'] ,
  70. "companyNo"=>$data['supplierNo'] ,
  71. "companyName"=>$data['supplier_name'] ,
  72. "cgdNo"=>$data['cgdNo'] ,
  73. ];
  74. $re=Db::name('qrd_info')
  75. ->where('id' , $exists_qrd['id'])
  76. ->update([
  77. 'name'=>$data['orderCode'] ,//确认单名称,
  78. 'sequenceNo'=>$data['orderCode'] ,//确认单编号,
  79. 'ownerName'=>$data['apply_name'] ,//销售员,
  80. 'ownerid'=>$data['apply_id'] ,//销售员id,
  81. 'department'=>$data['depart'] ,//部门,
  82. 'createdTime'=>$data['addtime'] ,//销售单创建时间,
  83. 'qrdType'=>$data['order_type'] ,//销售单类型,
  84. 'qrdSource'=>$data['order_source'] ,//销售单来源,
  85. 'companyNo'=>$data['supplierNo'] ,//业务企业编号,
  86. 'companyName'=>$data['supplier_name'] ,//业务企业名称,
  87. 'customerNo'=>$data['customer_code'] ,//客户编号,
  88. 'customerName'=>$data['customer_name'] ,//客户名称,
  89. 'poCode'=>$data['poNo'] ,//po编号,
  90. 'platName'=>$data['platform_id'] ,//平台名称,
  91. 'platform_type' => $data['platform_type']??'0',//平台名称,
  92. 'workCode'=>$data['workNo'] ,//业务编号,
  93. 'zxCode'=>$data['zxNo'] ,//咨询单编号,
  94. 'goodNo'=>$data['good_code'] ,//商品编号,
  95. 'goodName'=>$data['good_name'] ,//商品名称,
  96. 'goodBrand'=>$data['brand'] ,//商品品牌,
  97. 'firstCat'=>$data['cat_name'][0]['cat_name'] ?? "" ,//一级分类,
  98. 'secCat'=>$data['cat_name'][1]['cat_name'] ?? "" ,//二级分类,
  99. 'thirdCat'=>$data['cat_name'][2]['cat_name'] ?? "" ,//三级分类,
  100. 'catInfo'=>json_encode($data['cat_name'] , JSON_UNESCAPED_UNICODE) ,//分类详情,
  101. 'fundCode'=>$data['cat_name'][2]['fund_code'] ?? "" ,//核算编码,
  102. 'goodMaterial'=>'' ,//商品材质,
  103. 'goodUnit'=>$data['unit'] ,//商品单位,
  104. 'goodDesc'=>$data['cost_desc'] ,//工艺说明,
  105. 'goodType'=>$data['good_type'] ,//商品类型,
  106. 'goodModel'=>'' ,//商品型号,
  107. 'isStock'=>$data['is_stock'] ,//是否库存品,
  108. 'metalsType'=>$data['noble_metal'] ,//贵金属种类,
  109. 'weight'=>$data['good_weight'] ,//商品重量,
  110. 'goldPrice'=>$data['gold_price'] ,//贵金属单价,
  111. 'deliveryDay'=>$data['delivery_day'] ,//物流天数,
  112. 'workDay'=>$data['lead_time'] ,//工期,
  113. 'tax'=>$data['tax'] ,//税率,
  114. 'goodNum'=>$data['good_num'] ,//销售数量,
  115. 'goodPrice'=>$data['sale_price'] ,//产品单价,
  116. 'totalPrice'=>$data['total_price'] ,//货款总额,
  117. 'total_origin_price'=>$data['total_origin_price'] ,//成本总额,
  118. 'total_plan_price'=>$data['total_origin_price_plan'] ,//成本总额,
  119. 'sendNum'=>$data['send_num'] ,//已发货数量,
  120. 'wsendNum'=>$data['wsend_num'] ,//未发货数量,
  121. 'apay_fee'=>0 ,//已付款,
  122. 'pay_fee'=>0 ,//付款中
  123. 'wpay_fee'=>$data['total_price'] ,//未付款,
  124. 'inv_fee'=>0 ,//回票中
  125. 'ainv_fee'=>0 ,//已开票,
  126. 'winv_fee'=>$data['total_price'] ,//未开票,
  127. 'is_diff'=>$data['is_diff'] ,//是否有工差,
  128. 'sendType'=>$data['send_type'] ,//发货方式,
  129. 'sendStatus'=>$data['send_status'] ,//发货状态,
  130. 'pay_status'=>$data['total_price'] == 0 ? 3 : 1 ,//收款状态,1未付,2部分,3完结
  131. 'inv_status'=>$data['total_price'] == 0 ? 3 : 1 ,//开票状态,,1未付,2部分,3完结
  132. 'remark'=>"" ,//备注,
  133. 'cxCode'=>$data['oldCode'] ?? "" ,//备注,
  134. 'diff_weight'=>$data['diff_weight'] ,//工差重量,
  135. 'diff_fee'=>$data['diff_fee'] ,//工差金额,
  136. 'area'=>$data['customer_name'] ,//公司,
  137. 'customerAttr'=>$all_branch[$data['customer_code']]['parent'] ?? '' ,//客户属性,
  138. 'branch'=>$all_branch[$data['customer_code']]['branch'] ?? '' ,//分公司,从客户表中查
  139. 'cgdNo'=>$data['cgdNo'] ,//采购单号,
  140. 'thNum'=>$data['th_num'] ,//退货数量,
  141. 'th_fee'=>$data['th_fee'] ,//退货金额,
  142. 'pay_source'=>$data['pay_source'] ?? "" ,//支付渠道,
  143. 'is_del'=>0 ,//是否删除,
  144. 'addtime'=>$date ,
  145. 'updatetime'=>$date ,
  146. 'inv_tag'=>0 ,//开票标签,
  147. 'pay_tag'=>0 ,//回款标签,
  148. 'inv_tag_fee'=>0 ,//开票票标签金额,
  149. 'pay_tag_fee'=>0 ,//回款标签金额,
  150. ]
  151. );
  152. } else {
  153. $wait_insert_data=[
  154. "order_type"=>$result['order_type'] ,
  155. "data"=>json_encode($result['data'] , JSON_UNESCAPED_UNICODE) ,
  156. "orderCode"=>$data['orderCode'] ,
  157. "status"=>1 ,
  158. ];
  159. $re=Db::name('qrd_info')
  160. ->where('id' , $exists_qrd['id'])
  161. ->update([
  162. 'poCode'=>$data['poNo'] ,//po编号,
  163. 'workCode'=>$data['workNo'] ,//业务编号,
  164. 'zxCode'=>$data['zxNo'] ,//咨询单编号,
  165. 'goodMaterial'=>'' ,//商品材质,
  166. 'goodUnit'=>$data['unit'] ,//商品单位,
  167. 'goodDesc'=>$data['cost_desc'] ,//工艺说明,
  168. 'goodType'=>$data['good_type'] ,//商品类型,
  169. 'goodModel'=>'' ,//商品型号,
  170. 'metalsType'=>$data['noble_metal'] ,//贵金属种类,
  171. 'weight'=>$data['good_weight'] ,//商品重量,
  172. 'deliveryDay'=>$data['delivery_day'] ,//物流天数,
  173. 'workDay'=>$data['lead_time'] ,//工期,
  174. 'tax'=>$data['tax'] ,//税率,
  175. 'total_origin_price'=>$data['total_origin_price'] ,//成本总额,
  176. 'total_plan_price'=>$data['total_origin_price_plan'] ,//成本总额,
  177. 'sendNum'=>$data['send_num'] ,//已发货数量,
  178. 'wsendNum'=>$data['wsend_num'] ,//未发货数量,
  179. 'sendType'=>$data['send_type'] ,//发货方式
  180. 'sendStatus'=>$data['send_status'] ,//发货状态,
  181. 'remark'=>"" ,//备注,
  182. 'area'=>$data['customer_name'] ,//公司,
  183. 'customerAttr'=>$all_branch[$data['customer_code']]['parent'] ?? '' ,//客户属性,
  184. 'branch'=>$all_branch[$data['customer_code']]['branch'] ?? '' ,//分公司,从客户表中查
  185. 'pay_source'=>$data['pay_source'] ?? "" ,//支付渠道,
  186. 'updatetime'=>$date
  187. ]
  188. );
  189. }
  190. } else {
  191. //新增
  192. $qrd_insert_data[]=[
  193. 'name'=>$data['orderCode'] ,//确认单名称,
  194. 'sequenceNo'=>$data['orderCode'] ,//确认单编号,
  195. 'ownerName'=>$data['apply_name'] ,//销售员,
  196. 'ownerid'=>$data['apply_id'] ,//销售员id,
  197. 'department'=>$data['depart'] ,//部门,
  198. 'createdTime'=>$data['addtime'] ,//销售单创建时间,
  199. 'qrdType'=>$data['order_type'] ,//销售单类型,
  200. 'qrdSource'=>$data['order_source'] ,//销售单来源,
  201. 'companyNo'=>$data['supplierNo'] ,//业务企业编号,
  202. 'companyName'=>$data['supplier_name'] ,//业务企业名称,
  203. 'customerNo'=>$data['customer_code'] ,//客户编号,
  204. 'customerName'=>$data['customer_name'] ,//客户名称,
  205. 'poCode'=>$data['poNo'] ,//po编号,
  206. 'platName'=>$data['platform_id'] ,//平台名称,
  207. 'platform_type' => $data['platform_type']??'0',//平台名称,
  208. 'workCode'=>$data['workNo'] ,//业务编号,
  209. 'zxCode'=>$data['zxNo'] ,//咨询单编号,
  210. 'goodNo'=>$data['good_code'] ,//商品编号,
  211. 'goodName'=>$data['good_name'] ,//商品名称,
  212. 'goodBrand'=>$data['brand'] ,//商品品牌,
  213. 'firstCat'=>$data['cat_name'][0]['cat_name'] ?? "" ,//一级分类,
  214. 'secCat'=>$data['cat_name'][1]['cat_name'] ?? "" ,//二级分类,
  215. 'thirdCat'=>$data['cat_name'][2]['cat_name'] ?? "" ,//三级分类,
  216. 'catInfo'=>json_encode($data['cat_name'] , JSON_UNESCAPED_UNICODE) ,//分类详情,
  217. 'fundCode'=>$data['cat_name'][2]['fund_code'] ?? "" ,//核算编码,
  218. 'goodMaterial'=>'' ,//商品材质,
  219. 'goodUnit'=>$data['unit'] ,//商品单位,
  220. 'goodDesc'=>$data['cost_desc'] ,//工艺说明,
  221. 'goodType'=>$data['good_type'] ,//商品类型,
  222. 'goodModel'=>'' ,//商品型号,
  223. 'isStock'=>$data['is_stock'] ,//是否库存品,
  224. 'metalsType'=>$data['noble_metal'] ,//贵金属种类,
  225. 'weight'=>$data['good_weight'] ,//商品重量,
  226. 'goldPrice'=>$data['gold_price'] ,//贵金属单价,
  227. 'deliveryDay'=>$data['delivery_day'] ,//物流天数,
  228. 'workDay'=>$data['lead_time'] ,//工期,
  229. 'tax'=>$data['tax'] ,//税率,
  230. 'goodNum'=>$data['good_num'] ,//销售数量,
  231. 'goodPrice'=>$data['sale_price'] ,//产品单价,
  232. 'totalPrice'=>$data['total_price'] ,//货款总额,
  233. 'total_origin_price'=>$data['total_origin_price'] ,//成本总额,
  234. 'total_plan_price'=>$data['total_origin_price_plan'] ,//成本总额,
  235. 'sendNum'=>$data['send_num'] ,//已发货数量,
  236. 'wsendNum'=>$data['wsend_num'] ,//未发货数量,
  237. 'apay_fee'=>0 ,//已付款,
  238. 'pay_fee'=>0 ,//付款中
  239. 'wpay_fee'=>$data['total_price'] ,//未付款,
  240. 'inv_fee'=>0 ,//回票中
  241. 'ainv_fee'=>0 ,//已开票,
  242. 'winv_fee'=>$data['total_price'] ,//未开票,
  243. 'is_diff'=>$data['is_diff'] ,//是否有工差,
  244. 'sendType'=>$data['send_type'] ,//发货方式,
  245. 'sendStatus'=>$data['send_status'] ,//发货状态,
  246. 'pay_status'=>$data['total_price'] == 0 ? 3 : 1 ,//收款状态,1未付,2部分,3完结
  247. 'inv_status'=>$data['total_price'] == 0 ? 3 : 1 ,//开票状态,,1未付,2部分,3完结
  248. 'remark'=>"" ,//备注,
  249. 'cxCode'=>$data['oldCode'] ?? "" ,//备注,
  250. 'diff_weight'=>$data['diff_weight'] ,//工差重量,
  251. 'diff_fee'=>$data['diff_fee'] ,//工差金额,
  252. 'area'=>$data['customer_name'] ,//公司,
  253. 'customerAttr'=>$all_branch[$data['customer_code']]['parent'] ,//客户属性,
  254. 'branch'=>$all_branch[$data['customer_code']]['branch'] ?? '' ,//分公司,从客户表中查
  255. 'cgdNo'=>$data['cgdNo'] ,//采购单号,
  256. 'thNum'=>$data['th_num'] ,//退货数量,
  257. 'th_fee'=>$data['th_fee'] ,//退货金额,
  258. 'pay_source'=>$data['pay_source'] ?? "" ,//支付渠道,
  259. 'is_del'=>0 ,//是否删除,
  260. 'addtime'=>$date ,
  261. 'updatetime'=>$date ,
  262. 'inv_tag'=>0 ,//开票标签,
  263. 'pay_tag'=>0 ,//回款标签,
  264. 'inv_tag_fee'=>0 ,//开票票标签金额,
  265. 'pay_tag_fee'=>0 ,//回款标签金额,
  266. ];
  267. }
  268. } else {
  269. //已存在
  270. $data['total_fee']=$data['total_fee'] - $data['th_fee'] - $data['diff_fee'];
  271. $exitReport=Db::name("report_code")->where('cgdNo' , $data['cgdNo'])->findOrEmpty();
  272. $repostinsert=[
  273. "qrdNo"=>$data['qrdNo'] ,
  274. "cgder_id"=>$data['cgder_id'] ,
  275. "cgder"=>$data['cgder'] ,
  276. "supplierName"=>$data['supplier_name'] ,
  277. "supplierNo"=>$data['supplierNo'] ,
  278. "companyNo"=>$data['companyNo'] ,
  279. "companyName"=>$data['companyName'] ,
  280. "cgdNo"=>$data['cgdNo'] ,
  281. ];
  282. if (empty($exitReport)) Db::name("report_code")->insert($repostinsert);
  283. else Db::name("report_code")->where($exitReport)->update($repostinsert);
  284. $exists_cgd=Db::name('cgd_info')
  285. ->whereIn('sequenceNo' , $data['cgdNo'])
  286. ->field('id,status')->findOrEmpty();
  287. if (!empty($exists_cgd)) {
  288. //未对账,更新
  289. if ($exists_cgd['status'] == 0) {
  290. Db::name('cgd_info')
  291. ->where('id' , $exists_cgd['id'])
  292. ->update([
  293. 'name'=>$data['cgdNo'] ,//采购单名称',
  294. 'sequenceNo'=>$data['cgdNo'] ,//采购单编号',
  295. 'ownerName'=>$data['cgder'] ,//采购员名称',
  296. 'ownerid'=>$data['cgder_id'] ,//采购员id',
  297. 'department'=>$data['depart'] ,//部门名称',
  298. 'createdTime'=>$data['addtime'] ,//订单创建时间',
  299. 'cgdType'=>$data['order_type'] ,//采购单类型',
  300. 'cgdSource'=>$data['order_source'] ,//采购单来源',
  301. 'companyNo'=>$data['companyNo'] ,//业务公司编号',
  302. 'companyName'=>$data['companyName'] ,//业务公司',
  303. 'cgdTime'=>$data['addtime'] ,//采购下单时间',
  304. 'bkCode'=>$data['bkcode'] ,//备库单编号',
  305. 'qrdCode'=>$data['qrdNo'] ,//确认单编号',
  306. 'goodNo'=>$data['spuCode'] ,//商品编号',
  307. 'goodName'=>$data['good_name'] ,//商品名称',
  308. 'goodType'=>$data['good_type'] ,//商品类型',
  309. 'goodBrand'=>$data['brand'] ,//商品品牌',
  310. 'goodModel'=>'' ,//商品型号',
  311. 'firstCat'=>$data['cat_name'][0]['cat_name'] ,//商品一级分类',
  312. 'secCat'=>$data['cat_name'][1]['cat_name'] ,//二级分类',
  313. 'thirdCat'=>$data['cat_name'][2]['cat_name'] ,//三级分类',
  314. 'catInfo'=>json_encode($data['cat_name'] , JSON_UNESCAPED_UNICODE) ,//分类明细',
  315. 'fundCode'=>$data['cat_name'][2]['fund_code'] ,//NOT NULL,
  316. 'goodMaterial'=>'' ,//商品材质',
  317. 'goodUnit'=>$data['unit'] ,//商品单位',
  318. 'goodDesc'=>$data['cost_desc'] ,//工艺说明',
  319. 'metalsType'=>$data['noble_metal'] ,//贵金属种类',
  320. 'weight'=>$data['weight'] ,//商品重量',
  321. 'goldPrice'=>$data['gold_price'] ,//贵金属实时金价',
  322. 'is_diff'=>$data['is_diff'] ,//是否有工差',
  323. 'deliveryDay'=>$data['delivery_day'] ,//物流天数',
  324. 'workDay'=>$data['lead_time'] ,//产品工期',
  325. 'tax'=>$data['tax'] ,//税点',
  326. 'barePrice'=>$data['nake_fee'] ,//裸价',
  327. 'markPrice'=>$data['mark_fee'] ,//加标费',
  328. 'packPrice'=>$data['pakage_fee'] ,//包装费',
  329. 'certPrice'=>$data['cert_fee'] ,//证书费',
  330. 'openPrice'=>$data['open_fee'] ,//开模费',
  331. 'costPrice'=>$data['teach_fee'] ,//工艺费',
  332. 'deliveryPrice'=>$data['delivery_fee'] ,//物流费',
  333. 'goodPrice'=>$data['good_price'] ,//成本合计/单价',
  334. 'isStock'=>$data['is_stock'] ,//是否库存品',
  335. 'goodNum'=>$data['good_num'] ,//下单数量',
  336. 'totalPrice'=>$data['total_fee'] ,//采购总货款',
  337. 'supplierNo'=>$data['supplierNo'] ,//供应商编号',
  338. 'supplierName'=>$data['supplier_name'] ,//供应商名称',
  339. 'apay_fee'=>0 ,//已付款金额',
  340. 'wpay_fee'=>$data['total_fee'] ,//未付款金额',
  341. 'ainv_fee'=>0 ,//已开票金额',
  342. 'winv_fee'=>$data['total_fee'] ,//未开票金额',
  343. 'sendType'=>$data['send_type'] ,//发货方式',
  344. 'bkCreater'=>$data['bkcreater'] ,//备库申请人',
  345. 'sendStatus'=>$data['send_status'] ,//发货状态',
  346. 'wsendNum'=>$data['wsend_num'] ,//未发货数量',
  347. 'sendNum'=>$data['send_num'] ,//已发货数量',
  348. 'wareHouse'=>$data['wsm_code'] ,//仓库名称',
  349. 'wsmCode'=>$data['wsm_code'] ,//仓库编号',
  350. 'remark'=>'' ,//备注',
  351. 'cxCode'=>$data['oldCode'] ?? "" ,//备注,
  352. 'pay_status'=>$data['total_fee'] == 0 ? 3 : 1 ,//付款情况',
  353. 'inv_status'=>$data['total_fee'] == 0 ? 3 : 1 ,//开票情况',
  354. 'diff_weight'=>$data['diff_weight'] ,//工差重量',
  355. 'diff_fee'=>$data['diff_fee'] ,//工差金额',
  356. 'thNum'=>$data['th_num'] ,//退货数量',
  357. 'th_fee'=>$data['th_fee'] ,//退货金额',
  358. 'check_rate'=>'' ,//修正后的税率',
  359. 'is_del'=>0 ,
  360. 'addtime'=>$date ,
  361. 'updatetime'=>$date ,
  362. ]
  363. );
  364. } else {
  365. $wait_insert_data=[
  366. "order_type"=>$result['order_type'] ,
  367. "data"=>json_encode($result['data'] , JSON_UNESCAPED_UNICODE) ,
  368. "orderCode"=>$data['cgdNo'] ,
  369. "status"=>1 ,
  370. ];
  371. Db::name('cgd_info')
  372. ->where('id' , $exists_cgd['id'])
  373. ->update([
  374. 'bkCode'=>$data['bkcode'] ,//备库单编号',
  375. 'qrdCode'=>$data['qrdNo'] ,//确认单编号',
  376. 'goodType'=>$data['good_type'] ,//商品类型',
  377. 'goodBrand'=>$data['brand'] ,//商品品牌',
  378. 'goodModel'=>'' ,//商品型号',
  379. 'goodMaterial'=>'' ,//商品材质',
  380. 'goodUnit'=>$data['unit'] ,//商品单位',
  381. 'goodDesc'=>$data['cost_desc'] ,//工艺说明',
  382. 'metalsType'=>$data['noble_metal'] ,//贵金属种类',
  383. 'weight'=>$data['weight'] ,//商品重量',
  384. 'is_diff'=>$data['is_diff'] ,//是否有工差',
  385. 'deliveryDay'=>$data['delivery_day'] ,//物流天数',
  386. 'workDay'=>$data['lead_time'] ,//产品工期',
  387. 'tax'=>$data['tax'] ,//税点',
  388. 'barePrice'=>$data['nake_fee'] ,//裸价',
  389. 'markPrice'=>$data['mark_fee'] ,//加标费',
  390. 'packPrice'=>$data['pakage_fee'] ,//包装费',
  391. 'certPrice'=>$data['cert_fee'] ,//证书费',
  392. 'openPrice'=>$data['open_fee'] ,//开模费',
  393. 'costPrice'=>$data['teach_fee'] ,//工艺费',
  394. 'deliveryPrice'=>$data['delivery_fee'] ,//物流费',
  395. 'sendType'=>$data['send_type'] ,//发货方式',
  396. 'bkCreater'=>$data['bkcreater'] ,//备库申请人',
  397. 'sendStatus'=>$data['send_status'] ,//发货状态',
  398. 'wsendNum'=>$data['wsend_num'] ,//未发货数量',
  399. 'sendNum'=>$data['send_num'] ,//已发货数量',
  400. 'wareHouse'=>$data['wsm_code'] ,//仓库名称',
  401. 'wsmCode'=>$data['wsm_code'] ,//仓库编号',
  402. 'remark'=>'' ,//备注',
  403. 'cxCode'=>$data['oldCode'] ?? "" ,//备注,
  404. 'check_rate'=>'' ,//修正后的税率',
  405. 'updatetime'=>$date ,
  406. ]
  407. );
  408. }
  409. } else {
  410. //新增
  411. $cgd_insert_data[]=[
  412. 'name'=>$data['cgdNo'] ,//采购单名称',
  413. 'sequenceNo'=>$data['cgdNo'] ,//采购单编号',
  414. 'ownerName'=>$data['cgder'] ,//采购员名称',
  415. 'ownerid'=>$data['cgder_id'] ,//采购员id',
  416. 'department'=>$data['depart'] ,//部门名称',
  417. 'createdTime'=>$data['addtime'] ,//订单创建时间',
  418. 'cgdType'=>$data['order_type'] ,//采购单类型',
  419. 'cgdSource'=>$data['order_source'] ,//采购单来源',
  420. 'companyNo'=>$data['companyNo'] ,//业务公司编号',
  421. 'companyName'=>$data['companyName'] ,//业务公司',
  422. 'cgdTime'=>$data['addtime'] ,//采购下单时间',
  423. 'bkCode'=>$data['bkcode'] ,//备库单编号',
  424. 'qrdCode'=>$data['qrdNo'] ,//确认单编号',
  425. 'goodNo'=>$data['spuCode'] ,//商品编号',
  426. 'goodName'=>$data['good_name'] ,//商品名称',
  427. 'goodType'=>$data['good_type'] ,//商品类型',
  428. 'goodBrand'=>$data['brand'] ,//商品品牌',
  429. 'goodModel'=>'' ,//商品型号',
  430. 'firstCat'=>$data['cat_name'][0]['cat_name'] ?? "" ,//商品一级分类',
  431. 'secCat'=>$data['cat_name'][1]['cat_name'] ,//二级分类',
  432. 'thirdCat'=>$data['cat_name'][2]['cat_name'] ,//三级分类',
  433. 'catInfo'=>json_encode($data['cat_name'] , JSON_UNESCAPED_UNICODE) ,//分类明细',
  434. 'fundCode'=>$data['cat_name'][2]['fund_code'] ,//NOT NULL,
  435. 'goodMaterial'=>'' ,//商品材质',
  436. 'goodUnit'=>$data['unit'] ,//商品单位',
  437. 'goodDesc'=>$data['cost_desc'] ,//工艺说明',
  438. 'metalsType'=>$data['noble_metal'] ,//贵金属种类',
  439. 'weight'=>$data['weight'] ,//商品重量',
  440. 'goldPrice'=>$data['gold_price'] ,//贵金属实时金价',
  441. 'is_diff'=>$data['is_diff'] ,//是否有工差',
  442. 'deliveryDay'=>$data['delivery_day'] ,//物流天数',
  443. 'workDay'=>$data['lead_time'] ,//产品工期',
  444. 'tax'=>$data['tax'] ,//税点',
  445. 'barePrice'=>$data['nake_fee'] ,//裸价',
  446. 'markPrice'=>$data['mark_fee'] ,//加标费',
  447. 'packPrice'=>$data['pakage_fee'] ,//包装费',
  448. 'certPrice'=>$data['cert_fee'] ,//证书费',
  449. 'openPrice'=>$data['open_fee'] ,//开模费',
  450. 'costPrice'=>$data['teach_fee'] ,//工艺费',
  451. 'deliveryPrice'=>$data['delivery_fee'] ,//物流费',
  452. 'goodPrice'=>$data['good_price'] ,//成本合计/单价',
  453. 'isStock'=>$data['is_stock'] ,//是否库存品',
  454. 'goodNum'=>$data['good_num'] ,//下单数量',
  455. 'totalPrice'=>$data['total_fee'] ,//采购总货款',
  456. 'supplierNo'=>$data['supplierNo'] ,//供应商编号',
  457. 'supplierName'=>$data['supplier_name'] ,//供应商名称',
  458. 'apay_fee'=>0 ,//已付款金额',
  459. 'wpay_fee'=>$data['total_fee'] ,//未付款金额',
  460. 'ainv_fee'=>0 ,//已开票金额',
  461. 'winv_fee'=>$data['total_fee'] ,//未开票金额',
  462. 'sendType'=>$data['send_type'] ,//发货方式',
  463. 'bkCreater'=>$data['bkcreater'] ,//备库申请人',
  464. 'sendStatus'=>$data['send_status'] ,//发货状态',
  465. 'wsendNum'=>$data['wsend_num'] ,//未发货数量',
  466. 'sendNum'=>$data['send_num'] ,//已发货数量',
  467. 'wareHouse'=>$data['wsm_code'] ,//仓库名称',
  468. 'wsmCode'=>$data['wsm_code'] ,//仓库编号',
  469. 'remark'=>'' ,//备注',
  470. 'pay_status'=>$data['total_fee'] == 0 ? 3 : 1 ,//付款情况',
  471. 'inv_status'=>$data['total_fee'] == 0 ? 3 : 1 ,//开票情况',
  472. 'diff_weight'=>$data['diff_weight'] ,//工差重量',
  473. 'diff_fee'=>$data['diff_fee'] ,//工差金额',
  474. 'thNum'=>$data['th_num'] ,//退货数量',
  475. 'th_fee'=>$data['th_fee'] ,//退货金额',
  476. 'check_rate'=>'' ,//修正后的税率',
  477. 'cxCode'=>$data['oldCode'] ?? "" ,//备注,
  478. 'is_del'=>0 ,
  479. 'addtime'=>$date ,
  480. 'updatetime'=>$date ,
  481. ];
  482. }
  483. }
  484. if ($qrd_insert_data) Db::name('qrd_info')->insertAll($qrd_insert_data);
  485. if ($cgd_insert_data) Db::name('cgd_info')->insertAll($cgd_insert_data);
  486. if ($wait_insert_data) Db::name('caixiao_wait')->insert($wait_insert_data);
  487. Db::name("caixiao_data")->where('uniqkey' , $result['uniqkey'])->update(['status'=>0]);
  488. $output->writeln("[$date]:{$result['id']}处理成功");
  489. } Cache::store("redis")->set("JsHandle",0,180);
  490. Db::commit();
  491. } catch (Exception $exception) {
  492. Cache::store("redis")->set("JsHandle",0,180);
  493. Db::rollback();
  494. $output->writeln($exception->getMessage());
  495. }
  496. }
  497. Cache::store("redis")->set("JsHandle",0,180);
  498. Db::rollback();
  499. }
  500. }