handleCxData.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <?php
  2. namespace app\command;
  3. use app\admin\model\ComonOrder;use app\admin\model\OrderCategory;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. ->where("status",1)
  27. ->where("addtime",">=",date("Y-m-d H:i:s",time()-1800))
  28. ->lock(true)
  29. ->limit(100)
  30. ->select()->toArray();
  31. if ($results) {
  32. try {
  33. foreach ($results as $result) {
  34. $dataStr=$result['data'];
  35. if($dataStr==''){
  36. $output->writeln("[$date]:{$result['id']}数据解析失败");
  37. continue;
  38. }
  39. $data=json_decode($dataStr,true);
  40. if(is_null($data)){
  41. $output->writeln("[$date]:{$result['id']}数据解析失败");
  42. continue;
  43. }
  44. if(isset($data['inv_cat_info']) && !empty($data['inv_cat_info'])){
  45. $orderCode= $result['order_type']==1?$data['orderCode']:$data['cgdNo'];
  46. OrderCategory::checkInfo($orderCode,$result['order_type'],$data['inv_cat_info']);
  47. }
  48. $qrd_insert_data=$wait_insert_data=$cgd_insert_data=[];
  49. $data['cat_name']=is_array($data['cat_name']) ? $data['cat_name'] : json_decode($data['cat_name'],true);
  50. if ($result['order_type'] == 1) {
  51. $data['total_price']=round($data['total_price'],2) - $data['th_fee'] - $data['diff_fee'];
  52. $exitReport=Db::name('report_code')->where('qrdNo' , $data['orderCode'])->findOrEmpty();
  53. $repostinsert=[
  54. 'qrdNo'=>$data['orderCode'] ,
  55. 'seller_id'=>$data['apply_id'] ,
  56. 'seller'=>$data['apply_name'] ,
  57. 'customerName'=>$data['customer_name'] ,
  58. 'customerNo'=>$data['customer_code'] ,
  59. 'companyNo'=>$data['supplierNo'] ,
  60. 'companyName'=>$data['supplier_name'] ,
  61. 'cgdNo'=>$data['cgdNo'] ,
  62. ];
  63. if (empty($exitReport)) Db::name('report_code')->insert($repostinsert);
  64. else Db::name('report_code')->where($exitReport)->update($repostinsert);
  65. $exists_qrd=Db::name('qrd_info')
  66. ->whereIn('sequenceNo' , $data['orderCode'])
  67. ->field('id,status')->findOrEmpty();
  68. $all_branch=Db::name('customer_info')
  69. ->whereIn('companyNo' , $data['customer_code'])
  70. ->column('branch,parent' , 'companyNo');
  71. //已存在
  72. if (!empty($exists_qrd)) {
  73. if ($exists_qrd['status'] == 0) {
  74. $report=[
  75. 'qrdNo'=>$data['orderCode'] ,
  76. 'seller_id'=>$data['apply_id'] ,
  77. 'seller'=>$data['apply_name'] ,
  78. 'customerName'=>$data['customer_name'] ,
  79. 'customerNo'=>$data['customer_code'] ,
  80. 'companyNo'=>$data['supplierNo'] ,
  81. 'companyName'=>$data['supplier_name'] ,
  82. 'cgdNo'=>$data['cgdNo'] ,
  83. ];
  84. $re=Db::name('qrd_info')
  85. ->where('id' , $exists_qrd['id'])
  86. ->update([
  87. 'name'=>$data['orderCode'] ,//确认单名称,
  88. 'sequenceNo'=>$data['orderCode'] ,//确认单编号,
  89. 'ownerName'=>$data['apply_name'] ,//销售员,
  90. 'ownerid'=>$data['apply_id'] ,//销售员id,
  91. 'department'=>$data['depart'] ,//部门,
  92. 'open_type'=>$data['open_type'] ,//开模类型',
  93. 'manager'=>$data['manager']??'',
  94. 'managerid'=>$data['managerid']??0,
  95. 'createdTime'=>$data['addtime'] ,//销售单创建时间,
  96. 'qrdType'=>$data['order_type'] ,//销售单类型,
  97. 'qrdSource'=>$data['order_source'] ,//销售单来源,
  98. 'companyNo'=>$data['supplierNo'] ,//业务企业编号,
  99. 'companyName'=>$data['supplier_name'] ,//业务企业名称,
  100. 'customerNo'=>$data['customer_code'] ,//客户编号,
  101. 'customerName'=>$data['customer_name'] ,//客户名称,
  102. 'poCode'=>$data['poNo'] ,//po编号,
  103. "is_comon"=>ComonOrder::is_common($data['orderCode']),
  104. 'platName'=>$data['platform_name']??'',//平台名称,
  105. 'platform_type' => $data['platform_type']??'0',//平台名称,
  106. 'platform_id'=>$data['platform_id']??0,//平台id,'
  107. 'workCode'=>$data['workNo'] ,//业务编号,
  108. 'zxCode'=>$data['zxNo'] ,//咨询单编号,
  109. 'goodNo'=>$data['good_code'] ,//商品编号,
  110. 'goodName'=>$data['good_name'] ,//商品名称,
  111. 'goodBrand'=>$data['brand'] ,//商品品牌,
  112. 'firstCat'=>$data['cat_name'][0]['cat_name'] ?? "" ,//一级分类,
  113. 'secCat'=>!isset($data['cat_name'][1]) ? '' : $data['cat_name'][1]['cat_name'] ,//二级分类,
  114. 'thirdCat'=>!isset($data['cat_name'][2]) ? '' : $data['cat_name'][2]['cat_name'] ,
  115. //三级分类,
  116. 'catInfo'=>json_encode($data['cat_name'] , JSON_UNESCAPED_UNICODE) ,//分类详情,
  117. 'fundCode'=>isset($data['cat_name'][2]) ? $data['cat_name'][2]['fund_code'] : '',//核算编码,
  118. 'goodMaterial'=>'' ,//商品材质,
  119. 'goodUnit'=>$data['unit'] ,//商品单位,
  120. 'goodDesc'=>$data['cost_desc'] ,//工艺说明,
  121. 'goodType'=>$data['good_type'] ,//商品类型,
  122. 'goodModel'=>'' ,//商品型号,
  123. 'isStock'=>$data['is_stock'] ,//是否库存品,
  124. 'metalsType'=>$data['noble_metal'] ,//贵金属种类,
  125. 'weight'=>$data['good_weight'] ,//商品重量,
  126. 'goldPrice'=>$data['gold_price'] ,//贵金属单价,
  127. 'deliveryDay'=>$data['delivery_day'] ,//物流天数,
  128. 'workDay'=>$data['lead_time'] ,//工期,
  129. 'tax'=>$data['tax'] ,//税率,
  130. 'goodNum'=>$data['good_num'] ,//销售数量,
  131. 'goodPrice'=>$data['sale_price'] ,//产品单价,
  132. 'totalPrice'=>$data['total_price'] ,//货款总额,
  133. 'total_origin_price'=>$data['total_origin_price'] ,//成本总额,
  134. 'total_plan_price'=>$data['total_origin_price_plan'] ,//成本总额,
  135. 'sendNum'=>$data['send_num'] ,//已发货数量,
  136. 'wsendNum'=>$data['wsend_num'] ,//未发货数量,
  137. 'apay_fee'=>0 ,//已付款,
  138. 'pay_fee'=>0 ,//付款中
  139. 'wpay_fee'=>$data['total_price'] ,//未付款,
  140. 'inv_fee'=>0 ,//回票中
  141. 'ainv_fee'=>0 ,//已开票,
  142. 'winv_fee'=>$data['total_price'] ,//未开票,
  143. 'is_diff'=>$data['is_diff'] ,//是否有工差,
  144. 'sendType'=>$data['send_type'] ,//发货方式,
  145. 'sendStatus'=>$data['send_status'] ,//发货状态,
  146. 'pay_status'=>$data['total_price'] == 0 ? 3 : 1 ,//收款状态,1未付,2部分,3完结
  147. 'inv_status'=>$data['total_price'] == 0 ? 3 : 1 ,//开票状态,,1未付,2部分,3完结
  148. 'remark'=>'' ,//备注,
  149. 'cxCode'=>$data['oldCode'] ?? '' ,//备注,
  150. 'diff_weight'=>$data['diff_weight'] ,//工差重量,
  151. 'diff_fee'=>$data['diff_fee'] ,//工差金额,
  152. 'area'=>$data['customer_name'] ,//公司,
  153. 'customerAttr'=>$all_branch[$data['customer_code']]['parent'] ?? '' ,//客户属性,
  154. 'branch'=>$all_branch[$data['customer_code']]['branch'] ?? '' ,//分公司,从客户表中查
  155. 'cgdNo'=>$data['cgdNo'] ,//采购单号,
  156. 'thNum'=>$data['th_num'] ,//退货数量,
  157. 'th_fee'=>$data['th_fee'] ,//退货金额,
  158. 'pay_source'=>$data['pay_source'] ?? '' ,//支付渠道,
  159. 'is_del'=>0 ,//是否删除,
  160. 'addtime'=>$date ,
  161. 'updatetime'=>$date ,
  162. 'inv_tag'=>0 ,//开票标签,
  163. 'pay_tag'=>0 ,//回款标签,
  164. 'inv_tag_fee'=>0 ,//开票票标签金额,
  165. 'pay_tag_fee'=>0 ,//回款标签金额,
  166. ]
  167. );
  168. }
  169. else {
  170. $wait_insert_data=[
  171. 'order_type'=>$result['order_type'] ,
  172. 'data'=>json_encode($result['data'] , JSON_UNESCAPED_UNICODE) ,
  173. 'orderCode'=>$data['orderCode'] ,
  174. 'status'=>1 ,
  175. ];
  176. $re=Db::name('qrd_info')
  177. ->where('id' , $exists_qrd['id'])
  178. ->update([
  179. 'poCode'=>$data['poNo'] ,//po编号,
  180. 'workCode'=>$data['workNo'] ,//业务编号,
  181. 'zxCode'=>$data['zxNo'] ,//咨询单编号,
  182. 'goodMaterial'=>'' ,//商品材质,
  183. 'open_type'=>$data['open_type'] ,//开模类型',
  184. 'is_comon'=>ComonOrder::is_common($data['orderCode']),
  185. 'goodUnit'=>$data['unit'] ,//商品单位,
  186. 'goodDesc'=>$data['cost_desc'] ,//工艺说明,
  187. 'goodType'=>$data['good_type'] ,//商品类型,
  188. 'goodModel'=>'' ,//商品型号,
  189. 'platName'=>$data['platform_name']??'',//平台名称,
  190. 'platform_type' => $data['platform_type']??'0',//平台名称,
  191. 'platform_id'=>$data['platform_id']??0,//平台id,'
  192. 'companyNo'=>$data['supplierNo'] ,//业务企业编号,
  193. 'companyName'=>$data['supplier_name'] ,//业务企业名称,
  194. 'customerNo'=>$data['customer_code'] ,//客户编号,
  195. 'customerName'=>$data['customer_name'] ,//客户名称,
  196. 'manager'=>$data['manager']??'',
  197. 'managerid'=>$data['managerid']??0,
  198. 'metalsType'=>$data['noble_metal'] ,//贵金属种类,
  199. 'weight'=>$data['good_weight'] ,//商品重量,
  200. 'deliveryDay'=>$data['delivery_day'] ,//物流天数,
  201. 'workDay'=>$data['lead_time'] ,//工期,
  202. 'tax'=>$data['tax'] ,//税率,
  203. 'total_origin_price'=>$data['total_origin_price'] ,//成本总额,
  204. 'total_plan_price'=>$data['total_origin_price_plan'] ,//成本总额,
  205. 'sendNum'=>$data['send_num'] ,//已发货数量,
  206. 'wsendNum'=>$data['wsend_num'] ,//未发货数量,
  207. 'sendType'=>$data['send_type'] ,//发货方式
  208. 'sendStatus'=>$data['send_status'] ,//发货状态,
  209. 'remark'=>'' ,//备注,
  210. 'area'=>$data['customer_name'] ,//公司,
  211. 'customerAttr'=>$all_branch[$data['customer_code']]['parent'] ?? '' ,//客户属性,
  212. 'branch'=>$all_branch[$data['customer_code']]['branch'] ?? '' ,//分公司,从客户表中查
  213. 'pay_source'=>$data['pay_source'] ?? '' ,//支付渠道,
  214. 'updatetime'=>$date
  215. ]
  216. );
  217. }
  218. }
  219. else {
  220. //新增
  221. $qrd_insert_data[]=[
  222. 'name'=>$data['orderCode'] ,//确认单名称,
  223. 'sequenceNo'=>$data['orderCode'] ,//确认单编号,
  224. 'ownerName'=>$data['apply_name'] ,//销售员,
  225. 'ownerid'=>$data['apply_id'] ,//销售员id,
  226. 'is_comon'=>ComonOrder::is_common($data['orderCode']),
  227. 'department'=>$data['depart'] ,//部门,
  228. 'createdTime'=>$data['addtime'] ,//销售单创建时间,
  229. 'manager'=>$data['manager']??'',
  230. 'managerid'=>$data['managerid']??0,
  231. 'qrdType'=>$data['order_type'] ,//销售单类型,
  232. 'qrdSource'=>$data['order_source'] ,//销售单来源,
  233. 'companyNo'=>$data['supplierNo'] ,//业务企业编号,
  234. 'companyName'=>$data['supplier_name'] ,//业务企业名称,
  235. 'customerNo'=>$data['customer_code'] ,//客户编号,
  236. 'customerName'=>$data['customer_name'] ,//客户名称,
  237. 'poCode'=>$data['poNo'] ,//po编号,
  238. 'platName'=>$data['platform_name']??'',//平台名称,
  239. 'platform_type' => $data['platform_type']??'0',//平台名称,
  240. 'platform_id'=>$data['platform_id']??0,//平台id,'
  241. 'workCode'=>$data['workNo'] ,//业务编号,
  242. 'zxCode'=>$data['zxNo'] ,//咨询单编号,
  243. 'goodNo'=>$data['good_code'] ,//商品编号,
  244. 'goodName'=>$data['good_name'] ,//商品名称,
  245. 'goodBrand'=>$data['brand'] ,//商品品牌,
  246. 'firstCat'=>$data['cat_name'][0]['cat_name'] ?? "" ,//一级分类,
  247. 'secCat'=>!isset($data['cat_name'][1]) ? '' : $data['cat_name'][1]['cat_name'] ,//二级分类,
  248. 'thirdCat'=>!isset($data['cat_name'][2]) ? '' : $data['cat_name'][2]['cat_name'] ,
  249. //三级分类,
  250. 'catInfo'=>json_encode($data['cat_name'] , JSON_UNESCAPED_UNICODE) ,//分类详情,
  251. 'fundCode'=>isset($data['cat_name'][2]) ? $data['cat_name'][2]['fund_code'] : '',
  252. 'goodMaterial'=>'' ,//商品材质,
  253. 'goodUnit'=>$data['unit'] ,//商品单位,
  254. 'goodDesc'=>$data['cost_desc'] ,//工艺说明,
  255. 'goodType'=>$data['good_type'] ,//商品类型,
  256. 'goodModel'=>'' ,//商品型号,
  257. 'isStock'=>$data['is_stock'] ,//是否库存品,
  258. 'metalsType'=>$data['noble_metal'] ,//贵金属种类,
  259. 'weight'=>$data['good_weight'] ,//商品重量,
  260. 'goldPrice'=>$data['gold_price'] ,//贵金属单价,
  261. 'deliveryDay'=>$data['delivery_day'] ,//物流天数,
  262. 'workDay'=>$data['lead_time'] ,//工期,
  263. 'tax'=>$data['tax'] ,//税率,
  264. 'goodNum'=>$data['good_num'] ,//销售数量,
  265. 'goodPrice'=>$data['sale_price'] ,//产品单价,
  266. 'totalPrice'=>$data['total_price'] ,//货款总额,
  267. 'total_origin_price'=>$data['total_origin_price'] ,//成本总额,
  268. 'total_plan_price'=>$data['total_origin_price_plan'] ,//成本总额,
  269. 'sendNum'=>$data['send_num'] ,//已发货数量,
  270. 'wsendNum'=>$data['wsend_num'] ,//未发货数量,
  271. 'open_type'=>$data['open_type'] ,//开模类型',
  272. 'apay_fee'=>0 ,//已付款,
  273. 'pay_fee'=>0 ,//付款中
  274. 'wpay_fee'=>$data['total_price'] ,//未付款,
  275. 'inv_fee'=>0 ,//回票中
  276. 'ainv_fee'=>0 ,//已开票,
  277. 'winv_fee'=>$data['total_price'] ,//未开票,
  278. 'is_diff'=>$data['is_diff'] ,//是否有工差,
  279. 'sendType'=>$data['send_type'] ,//发货方式,
  280. 'sendStatus'=>$data['send_status'] ,//发货状态,
  281. 'pay_status'=>$data['total_price'] == 0 ? 3 : 1 ,//收款状态,1未付,2部分,3完结
  282. 'inv_status'=>$data['total_price'] == 0 ? 3 : 1 ,//开票状态,,1未付,2部分,3完结
  283. "status"=>$this->GetStatus($data['platform_id'],$data['order_source'],$data['supplierNo']),
  284. 'remark'=>'' ,//备注,
  285. 'cxCode'=>$data['oldCode'] ?? '' ,//备注,
  286. 'diff_weight'=>$data['diff_weight'] ,//工差重量,
  287. 'diff_fee'=>$data['diff_fee'] ,//工差金额,
  288. 'area'=>$data['customer_name'] ,//公司,
  289. 'customerAttr'=>$all_branch[$data['customer_code']]['parent']??"" ,//客户属性,
  290. 'branch'=>$all_branch[$data['customer_code']]['branch'] ?? '' ,//分公司,从客户表中查
  291. 'cgdNo'=>$data['cgdNo'] ,//采购单号,
  292. 'thNum'=>$data['th_num'] ,//退货数量,
  293. 'th_fee'=>$data['th_fee'] ,//退货金额,
  294. 'pay_source'=>$data['pay_source'] ?? '' ,//支付渠道,
  295. 'is_del'=>0 ,//是否删除,
  296. 'addtime'=>$date ,
  297. 'updatetime'=>$date ,
  298. 'inv_tag'=>0 ,//开票标签,
  299. 'pay_tag'=>0 ,//回款标签,
  300. 'inv_tag_fee'=>0 ,//开票票标签金额,
  301. 'pay_tag_fee'=>0 ,//回款标签金额,
  302. ];
  303. }
  304. if($data['cgdNo']!=''){
  305. Db::name('cgd_info')->where(['sequenceNo'=>$data['cgdNo']])->update
  306. (['qrdSend'=>$data['send_status']]);
  307. }
  308. }
  309. else {
  310. //已存在
  311. $data['total_fee']=round($data['total_fee'],2) - $data['th_fee'] - $data['diff_fee'];
  312. $exitReport=Db::name('report_code')->where('cgdNo' , $data['cgdNo'])->findOrEmpty();
  313. $repostinsert=[
  314. 'qrdNo'=>$data['qrdNo'] ,
  315. 'cgder_id'=>$data['cgder_id'] ,
  316. 'cgder'=>$data['cgder'] ,
  317. 'supplierName'=>$data['supplier_name'] ,
  318. 'supplierNo'=>$data['supplierNo'] ,
  319. 'companyNo'=>$data['companyNo'] ,
  320. 'companyName'=>$data['companyName'] ,
  321. 'cgdNo'=>$data['cgdNo'] ,
  322. ];
  323. if (empty($exitReport)) Db::name('report_code')->insert($repostinsert);
  324. else Db::name('report_code')->where($exitReport)->update($repostinsert);
  325. $exists_cgd=Db::name('cgd_info')
  326. ->whereIn('sequenceNo' , $data['cgdNo'])
  327. ->field('id,status')->findOrEmpty();
  328. $data['qrdSend'] = Db::name('qrd_info')->where(['cgdNo'=>$data['cgdNo']])->value
  329. ('sendStatus',1);
  330. if (!empty($exists_cgd)) {
  331. //未对账,更新
  332. if ($exists_cgd['status'] == 0) {
  333. Db::name('cgd_info')
  334. ->where('id' , $exists_cgd['id'])
  335. ->update([
  336. 'name'=>$data['cgdNo'] ,//采购单名称',
  337. 'sequenceNo'=>$data['cgdNo'] ,//采购单编号',
  338. 'ownerName'=>$data['cgder'] ,//采购员名称',
  339. 'ownerid'=>$data['cgder_id'] ,//采购员id',
  340. 'department'=>$data['depart'] ,//部门名称',
  341. 'createdTime'=>$data['addtime'] ,//订单创建时间',
  342. 'cgdType'=>$data['order_type'] ,//采购单类型',
  343. 'cgdSource'=>$data['order_source'] ,//采购单来源',
  344. 'companyNo'=>$data['companyNo'] ,//业务公司编号',
  345. 'companyName'=>$data['companyName'] ,//业务公司',
  346. 'platform_name'=>$data['platform_name']??'',//平台名称,
  347. 'platform_id'=>$data['platform_id']??0,//平台id,'
  348. 'is_comon'=>isset($data['mainCode'])?2: ComonOrder::is_common($data['cgdNo']),
  349. 'cgdTime'=>$data['addtime'] ,//采购下单时间',
  350. 'bkCode'=>$data['bkcode'] ,//备库单编号',
  351. 'qrdCode'=>$data['qrdNo'] ,//确认单编号',
  352. 'goodNo'=>$data['spuCode'] ,//商品编号',
  353. 'goodName'=>$data['good_name'] ,//商品名称',
  354. 'goodType'=>$data['good_type'] ,//商品类型',
  355. 'goodBrand'=>$data['brand'] ,//商品品牌',
  356. 'goodModel'=>'' ,//商品型号',
  357. 'firstCat'=>$data['cat_name'][0]['cat_name'] ,//商品一级分类',
  358. 'secCat'=>!isset($data['cat_name'][1]) ? '' : $data['cat_name'][1]['cat_name'] ,//二级分类,
  359. 'thirdCat'=>!isset($data['cat_name'][2]) ? '' : $data['cat_name'][2]['cat_name'] ,
  360. //三级分类,
  361. 'catInfo'=>json_encode($data['cat_name'] , JSON_UNESCAPED_UNICODE) ,//分类详情,
  362. 'fundCode'=>isset($data['cat_name'][2]) ? $data['cat_name'][2]['fund_code'] : '',
  363. 'goodMaterial'=>'' ,//商品材质',
  364. 'goodUnit'=>$data['unit'] ,//商品单位',
  365. 'goodDesc'=>$data['cost_desc'] ,//工艺说明',
  366. 'metalsType'=>$data['noble_metal'] ,//贵金属种类',
  367. 'weight'=>$data['weight'] ,//商品重量',
  368. 'goldPrice'=>$data['gold_price'] ,//贵金属实时金价',
  369. 'is_diff'=>$data['is_diff'] ,//是否有工差',
  370. 'deliveryDay'=>$data['delivery_day'] ,//物流天数',
  371. 'workDay'=>$data['lead_time'] ,//产品工期',
  372. 'tax'=>$data['tax'] ,//税点',
  373. 'barePrice'=>$data['nake_fee'] ,//裸价',
  374. 'markPrice'=>$data['mark_fee'] ,//加标费',
  375. 'packPrice'=>$data['pakage_fee'] ,//包装费',
  376. 'certPrice'=>$data['cert_fee'] ,//证书费',
  377. 'openPrice'=>$data['open_fee'] ,//开模费',
  378. 'costPrice'=>$data['teach_fee'] ,//工艺费',
  379. 'deliveryPrice'=>$data['delivery_fee'] ,//物流费',
  380. 'goodPrice'=>$data['good_price'] ,//成本合计/单价',
  381. 'isStock'=>$data['is_stock'] ,//是否库存品',
  382. 'goodNum'=>$data['good_num'] ,//下单数量',
  383. 'totalPrice'=>$data['total_fee'] ,//采购总货款',
  384. 'origin_total'=>$data['origin_total'] ,//采购总货款',
  385. 'supplierNo'=>$data['supplierNo'] ,//供应商编号',
  386. 'supplierName'=>$data['supplier_name'] ,//供应商名称',
  387. 'apay_fee'=>0 ,//已付款金额',
  388. 'wpay_fee'=>$data['total_fee'] ,//未付款金额',
  389. 'ainv_fee'=>0 ,//已开票金额',
  390. 'winv_fee'=>$data['total_fee'] ,//未开票金额',
  391. 'sendType'=>$data['send_type'] ,//发货方式',
  392. 'bkCreater'=>$data['bkcreater'] ,//备库申请人',
  393. 'sendStatus'=>$data['send_status'] ,//发货状态',
  394. 'wsendNum'=>$data['wsend_num'] ,//未发货数量',
  395. 'sendNum'=>$data['send_num'] ,//已发货数量',
  396. 'wareHouse'=>$data['wsm_code'] ,//仓库名称',
  397. 'wsmCode'=>$data['wsm_code'] ,//仓库编号',
  398. 'remark'=>'' ,//备注',
  399. 'cxCode'=>$data['oldCode'] ?? '' ,//备注,
  400. 'mainCode'=>$data['mainCode'] ?? '' ,//备注,
  401. 'cgd_status'=>$data['status'] ?? '0' ,//备注,
  402. 'pay_status'=>$data['total_fee'] == 0 ? 3 : 1 ,//付款情况',
  403. 'inv_status'=>$data['total_fee'] == 0 ? 3 : 1 ,//开票情况',
  404. 'diff_weight'=>$data['diff_weight'] ,//工差重量',
  405. 'diff_fee'=>$data['diff_fee'] ,//工差金额',
  406. 'thNum'=>$data['th_num'] ,//退货数量',
  407. 'th_fee'=>$data['th_fee'] ,//退货金额',
  408. "open_type"=>$data['open_type'] ,//开模类型',
  409. 'check_rate'=>'' ,//修正后的税率',
  410. 'is_del'=>0 ,
  411. 'addtime'=>$date ,
  412. 'updatetime'=>$date ,
  413. 'supplier_origin_price'=>$data['supplier_origin_price'],//供应商采购成本
  414. 'cgd_supplier_code'=>$data['cgd_supplier_code'],//采购供应商编号
  415. 'cgd_supplier_name'=>$data['cgd_supplier_name'],//采购供应商编号
  416. 'cgd_apply_id'=>$data['cgd_apply_id'],//竞单人
  417. 'cgd_apply_name'=>$data['cgd_apply_name'],//竞单人
  418. ]
  419. );
  420. } else {
  421. $wait_insert_data=[
  422. 'order_type'=>$result['order_type'] ,
  423. 'data'=>json_encode($result['data'] , JSON_UNESCAPED_UNICODE) ,
  424. 'orderCode'=>$data['cgdNo'] ,
  425. 'status'=>1 ,
  426. ];
  427. Db::name('cgd_info')
  428. ->where('id' , $exists_cgd['id'])
  429. ->update([
  430. 'bkCode'=>$data['bkcode'] ,//备库单编号',
  431. 'qrdCode'=>$data['qrdNo'] ,//确认单编号',
  432. 'goodType'=>$data['good_type'] ,//商品类型',
  433. 'goodBrand'=>$data['brand'] ,//商品品牌',
  434. 'companyNo'=>$data['companyNo'] ,//业务公司编号',
  435. 'companyName'=>$data['companyName'] ,//业务公司',
  436. 'supplierNo'=>$data['supplierNo'] ,//供应商编号',
  437. 'supplierName'=>$data['supplier_name'] ,//供应商名称',
  438. 'goodModel'=>'' ,//商品型号',
  439. 'is_comon'=>isset($data['mainCode'])?2: ComonOrder::is_common($data['cgdNo']),
  440. 'goodMaterial'=>'' ,//商品材质',
  441. 'open_type'=>$data['open_type'] ,//开模类型',
  442. 'goodUnit'=>$data['unit'] ,//商品单位',
  443. 'goodDesc'=>$data['cost_desc'] ,//工艺说明',
  444. 'metalsType'=>$data['noble_metal'] ,//贵金属种类',
  445. 'weight'=>$data['weight'] ,//商品重量',
  446. 'platform_name'=>$data['platform_name']??'',//平台名称,
  447. 'platform_id'=>$data['platform_id']??0,//平台id,'
  448. 'is_diff'=>$data['is_diff'] ,//是否有工差',
  449. 'deliveryDay'=>$data['delivery_day'] ,//物流天数',
  450. 'workDay'=>$data['lead_time'] ,//产品工期',
  451. 'tax'=>$data['tax'] ,//税点',
  452. 'barePrice'=>$data['nake_fee'] ,//裸价',
  453. 'markPrice'=>$data['mark_fee'] ,//加标费',
  454. 'packPrice'=>$data['pakage_fee'] ,//包装费',
  455. 'certPrice'=>$data['cert_fee'] ,//证书费',
  456. 'openPrice'=>$data['open_fee'] ,//开模费',
  457. 'costPrice'=>$data['teach_fee'] ,//工艺费',
  458. 'deliveryPrice'=>$data['delivery_fee'] ,//物流费',
  459. 'origin_total'=>$data['origin_total'] ,//采购总货款',
  460. 'sendType'=>$data['send_type'] ,//发货方式',
  461. 'bkCreater'=>$data['bkcreater'] ,//备库申请人',
  462. 'sendStatus'=>$data['send_status'] ,//发货状态',
  463. 'qrdSend'=>$data['qrdSend'] ,//发货状态',
  464. 'wsendNum'=>$data['wsend_num'] ,//未发货数量',
  465. 'sendNum'=>$data['send_num'] ,//已发货数量',
  466. 'wareHouse'=>$data['wsm_code'] ,//仓库名称',
  467. 'wsmCode'=>$data['wsm_code'] ,//仓库编号',
  468. 'remark'=>'' ,//备注',
  469. 'cxCode'=>$data['oldCode'] ?? '' ,//备注,
  470. 'mainCode'=>$data['mainCode'] ?? '' ,//备注,
  471. 'cgd_status'=>$data['status'] ?? '0' ,//备注,
  472. 'check_rate'=>'' ,//修正后的税率',
  473. 'updatetime'=>$date ,
  474. 'supplier_origin_price'=>$data['supplier_origin_price'],//供应商采购成本
  475. 'cgd_supplier_code'=>$data['cgd_supplier_code'],//采购供应商编号
  476. 'cgd_supplier_name'=>$data['cgd_supplier_name'],//采购供应商编号
  477. 'cgd_apply_id'=>$data['cgd_apply_id'],//竞单人
  478. 'cgd_apply_name'=>$data['cgd_apply_name'],//竞单人
  479. ]
  480. );
  481. }
  482. }
  483. else {
  484. //新增
  485. $cgd_insert_data[]=[
  486. 'name'=>$data['cgdNo'] ,//采购单名称',
  487. 'sequenceNo'=>$data['cgdNo'] ,//采购单编号',
  488. 'ownerName'=>$data['cgder'] ,//采购员名称',
  489. 'ownerid'=>$data['cgder_id'] ,//采购员id',
  490. 'department'=>$data['depart'] ,//部门名称',
  491. 'createdTime'=>$data['addtime'] ,//订单创建时间',
  492. 'cgdType'=>$data['order_type'] ,//采购单类型',
  493. 'cgdSource'=>$data['order_source'] ,//采购单来源',
  494. 'companyNo'=>$data['companyNo'] ,//业务公司编号',
  495. 'companyName'=>$data['companyName'] ,//业务公司',
  496. 'cgdTime'=>$data['addtime'] ,//采购下单时间',
  497. 'bkCode'=>$data['bkcode'] ,//备库单编号',
  498. 'qrdCode'=>$data['qrdNo'] ,//确认单编号',
  499. 'goodNo'=>$data['spuCode'] ,//商品编号',
  500. 'goodName'=>$data['good_name'] ,//商品名称',
  501. 'goodType'=>$data['good_type'] ,//商品类型',
  502. 'goodBrand'=>$data['brand'] ,//商品品牌',
  503. 'goodModel'=>'' ,//商品型号',
  504. 'open_type'=>$data['open_type'] ,//开模类型',
  505. 'platform_name'=>$data['platform_name']??'',//平台名称,
  506. 'platform_id'=>$data['platform_id']??0,//平台id,'
  507. 'is_comon'=>isset($data['mainCode'])?2: ComonOrder::is_common($data['cgdNo']),
  508. 'firstCat'=>$data['cat_name'][0]['cat_name'] ?? "" ,//商品一级分类',
  509. 'secCat'=>!isset($data['cat_name'][1]) ? '' : $data['cat_name'][1]['cat_name'] ,//二级分类,
  510. 'thirdCat'=>!isset($data['cat_name'][2]) ? '' : $data['cat_name'][2]['cat_name'] ,
  511. //三级分类,
  512. 'catInfo'=>json_encode($data['cat_name'] , JSON_UNESCAPED_UNICODE) ,//分类详情,
  513. 'fundCode'=>isset($data['cat_name'][2]) ? $data['cat_name'][2]['fund_code'] : '',
  514. 'goodMaterial'=>'' ,//商品材质',
  515. 'goodUnit'=>$data['unit'] ,//商品单位',
  516. 'goodDesc'=>$data['cost_desc'] ,//工艺说明',
  517. 'metalsType'=>$data['noble_metal'] ,//贵金属种类',
  518. 'weight'=>$data['weight'] ,//商品重量',
  519. 'goldPrice'=>$data['gold_price'] ,//贵金属实时金价',
  520. 'is_diff'=>$data['is_diff'] ,//是否有工差',
  521. 'deliveryDay'=>$data['delivery_day'] ,//物流天数',
  522. 'workDay'=>$data['lead_time'] ,//产品工期',
  523. 'tax'=>$data['tax'] ,//税点',
  524. 'barePrice'=>$data['nake_fee'] ,//裸价',
  525. 'markPrice'=>$data['mark_fee'] ,//加标费',
  526. 'packPrice'=>$data['pakage_fee'] ,//包装费',
  527. 'certPrice'=>$data['cert_fee'] ,//证书费',
  528. 'openPrice'=>$data['open_fee'] ,//开模费',
  529. 'costPrice'=>$data['teach_fee'] ,//工艺费',
  530. 'deliveryPrice'=>$data['delivery_fee'] ,//物流费',
  531. 'goodPrice'=>$data['good_price'] ,//成本合计/单价',
  532. 'isStock'=>$data['is_stock'] ,//是否库存品',
  533. 'goodNum'=>$data['good_num'] ,//下单数量',
  534. 'totalPrice'=>$data['total_fee'] ,//采购总货款',
  535. 'origin_total'=>$data['origin_total'] ,//采购总货款',
  536. 'supplierNo'=>$data['supplierNo'] ,//供应商编号',
  537. 'supplierName'=>$data['supplier_name'] ,//供应商名称',
  538. 'apay_fee'=>0 ,//已付款金额',
  539. 'wpay_fee'=>$data['total_fee'] ,//未付款金额',
  540. 'ainv_fee'=>0 ,//已开票金额',
  541. 'winv_fee'=>$data['total_fee'] ,//未开票金额',
  542. 'sendType'=>$data['send_type'] ,//发货方式',
  543. 'bkCreater'=>$data['bkcreater'] ,//备库申请人',
  544. 'sendStatus'=>$data['send_status'] ,//发货状态',
  545. 'qrdSend'=>$data['qrdSend'] ,
  546. 'wsendNum'=>$data['wsend_num'] ,//未发货数量',
  547. 'sendNum'=>$data['send_num'] ,//已发货数量',
  548. 'wareHouse'=>$data['wsm_code'] ,//仓库名称',
  549. 'wsmCode'=>$data['wsm_code'] ,//仓库编号',
  550. 'remark'=>'' ,//备注',
  551. 'pay_status'=>$data['total_fee'] == 0 ? 3 : 1 ,//付款情况',
  552. 'inv_status'=>$data['total_fee'] == 0 ? 3 : 1 ,//开票情况',
  553. 'status'=>$this->GetStatus($data['platform_id']??0,$data['order_source'],$data['companyNo']),
  554. 'diff_weight'=>$data['diff_weight'] ,//工差重量',
  555. 'diff_fee'=>$data['diff_fee'] ,//工差金额',
  556. 'thNum'=>$data['th_num'] ,//退货数量',
  557. 'th_fee'=>$data['th_fee'] ,//退货金额',
  558. 'check_rate'=>'' ,//修正后的税率',
  559. 'cgd_status'=>$data['status'] ?? '0' ,//备注,
  560. 'cxCode'=>$data['oldCode'] ?? '' ,//备注,
  561. 'mainCode'=>$data['mainCode'] ?? '' ,//备注,
  562. 'is_del'=>0 ,
  563. 'addtime'=>$date ,
  564. 'updatetime'=>$date ,
  565. 'supplier_origin_price'=>$data['supplier_origin_price'],//供应商采购成本
  566. 'cgd_supplier_code'=>$data['cgd_supplier_code'],//采购供应商编号
  567. 'cgd_supplier_name'=>$data['cgd_supplier_name'],//采购供应商编号
  568. 'cgd_apply_id'=>$data['cgd_apply_id'],//竞单人
  569. 'cgd_apply_name'=>$data['cgd_apply_name'],//竞单人
  570. ];
  571. }
  572. }
  573. if ($qrd_insert_data) Db::name('qrd_info')->insertAll($qrd_insert_data);
  574. if ($cgd_insert_data) Db::name('cgd_info')->insertAll($cgd_insert_data);
  575. if ($wait_insert_data) Db::name('caixiao_wait')->insert($wait_insert_data);
  576. Db::name('caixiao_data')->where('uniqkey' , $result['uniqkey'])->update(['status'=>0]);
  577. $output->writeln("[$date]:{$result['id']}处理成功");
  578. } Cache::store('redis')->set('JsHandle',0,180);
  579. Db::commit();
  580. } catch (Exception $exception) {
  581. Cache::store('redis')->set('JsHandle',0,180);
  582. Db::rollback();
  583. $output->writeln($exception->getMessage());
  584. }
  585. }
  586. Cache::store('redis')->set('JsHandle',0,180);
  587. Db::rollback();
  588. }
  589. private function GetStatus($platform_id,$source,$companyNo){
  590. //元隆 采销导入渠道 结算单E企购 平台数据导入
  591. return ($platform_id == 77 && $source == 9 && $companyNo =='GS2404151642335170')?2:0;
  592. }
  593. }