SplitSale.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <?php
  2. namespace app\command;
  3. use app\admin\common\User;
  4. use app\admin\model\Platform;use app\model\ComonOrder;use think\console\Command;
  5. use think\console\Input;
  6. use think\console\Output;
  7. use think\Exception;
  8. use think\facade\Cache;
  9. use think\facade\Db;
  10. class SplitSale extends Command
  11. {
  12. private $i = 0;//各种编码的自增变量
  13. private $sale_insert = [];//wsm_sale_caixiao的新增数据
  14. private $cgd_insert = [];//wsm_cgd_caixiao的新增数据
  15. private $noble_metal = [1 => '18K', 2 => '24K', 3 => '白银'];//贵金属种类对应文本
  16. private $cgd_key = 0;//新增到wsm_cgd_caixiao的数组下标,从0开始
  17. private $order_source = 8;//支付渠道
  18. private $Tcode = '';
  19. private $comOrder=null;
  20. protected function configure()
  21. {
  22. $this->setName('split_sale')->setDescription('销售订单拆分');
  23. parent::configure();
  24. }
  25. protected function execute(Input $input, Output $output)
  26. {
  27. $key = 'split_sale_';
  28. $rs = Cache::store('redis')->inc($key);
  29. if ($rs!=1){
  30. Cache::store('redis')->dec($key);
  31. return true;
  32. }
  33. try {
  34. $this->comOrder=new ComonOrder();
  35. Db::startTrans();
  36. try {
  37. $data = Db::name('sale')
  38. ->alias('a')
  39. ->leftJoin('platform b', 'b.id=a.platform_id')
  40. ->leftJoin('good_proof c', 'c.id=a.proof_id')
  41. ->field('a.*,b.platform_name,b.use_type,c.proof_url')
  42. ->where([
  43. ['a.is_del', '=', 0],
  44. ['a.updatetime', '>=', date('Y-m-d H:i:s', time() - 30 * 60)],
  45. ['a.pay_id', '<>', 0]
  46. ])->cursor();
  47. $userCommon = User::getIns();
  48. $commonOrder=[];//处理采购销售同一数据
  49. foreach ($data as $sale) {
  50. //处理采购销售同一数据
  51. $tempOrder=[
  52. "cxCode"=>$sale["orderCode"],
  53. "tyCode"=>makeNo("TY"),
  54. "orderCode"=>"",
  55. "cgdNo"=>"",
  56. "order_type"=>$sale['order_type'],
  57. "order_source"=>$sale['order_source'],
  58. "platform_type"=>Platform::where("id",$sale['platform_id'])->value("use_type",0),
  59. "goodNo"=>$sale['good_code'],
  60. "goodName"=>$sale['good_name'],
  61. "apply_id"=>$sale['apply_id'],
  62. "apply_name"=>$sale['apply_name'],
  63. "customerName"=>"",
  64. "customerNo"=>"",
  65. "supplierNo"=>'',
  66. "supplierName"=>'',
  67. "status"=>$sale['th_num']==$sale['good_num']?3:-1,
  68. "companyName"=>$sale['supplierName'],
  69. "companyNo"=>$sale['supplierNo'],
  70. ];
  71. if( strtotime($sale['addtime']) >= strtotime('2023-07-01 00:00:00'))$this->Tcode ='F';
  72. else $this->Tcode ='';
  73. //补充商品信息
  74. if ($sale['order_type'] == 3 ||$sale['order_type'] == 4) {
  75. //咨询相关
  76. $good = Db::name('good_zixun')->alias("b")
  77. ->field('b.noble_metal,c.brand_name brand,d.unit,b.craft_desc cost_desc,b.good_weight noble_weight,b.tax,0 delivery_day,0 lead_time')
  78. ->leftJoin('brand c', 'c.id=b.brand_id')
  79. ->leftJoin('unit d', 'd.id=b.good_unit')
  80. ->where(['b.spuCode' => $sale['good_code']])
  81. ->findOrEmpty();
  82. } else {
  83. $good = Db::name('good')
  84. ->field('b.noble_metal,c.brand_name brand,d.unit,b.craft_desc cost_desc,b.noble_weight,b.tax,b.delivery_day,b.lead_time')
  85. ->alias('b')
  86. ->leftJoin('brand c', 'c.id=b.brand_id')
  87. ->leftJoin('unit d', 'd.id=b.good_unit')
  88. ->where(['b.is_del' => 0, 'b.spuCode' => $sale['good_code']])
  89. ->findOrEmpty();
  90. }
  91. $sale['plan_price'] = Db::name("good_nake")->where(["spuCode"=>$sale['good_code'],"is_del"=>0])
  92. ->order("min_num asc")->value("nake_total",0);
  93. $sale['plan_total'] = round($sale['good_num'] * $sale['plan_price'],2);
  94. //贵金属分类转换文本
  95. $good['noble_metal'] = $this->noble_metal[$good['noble_metal'] ?? 0] ?? '';
  96. //相关数据合并
  97. $sale = array_merge($sale, $good);
  98. //支付渠道相关信息
  99. $pay_rates = Db::name('pay_log')
  100. ->where(['is_del' => 0, 'pay_id' => $sale['pay_id'], 'orderCode' => $sale['orderCode']])
  101. ->where( 'companyNo', 'not in',["KH","GYS"])
  102. ->field(true)
  103. ->order(['weight' => 'desc'])
  104. ->select()
  105. ->toArray();
  106. //关联的采购单信息
  107. $cgd = Db::name('order_num')
  108. ->alias('a')
  109. ->field('b.*,c.addtime bktime,c.apply_id bkcreater')
  110. ->leftJoin('purchease_order b', 'b.cgdNo=a.cgdNo')
  111. ->leftJoin('purchease c', 'c.bk_code=b.bkcode')
  112. ->where('a.orderCode', $sale['orderCode'])
  113. ->findOrEmpty();
  114. //采购总金额和销售总金额
  115. $cgd_total = $sale_total = $sale['total_price'];
  116. //客户
  117. $customer = ['No' => $sale['customer_code'], 'name' => $sale['customerName']];
  118. foreach ($pay_rates as $keys=>$pay_rate) {
  119. //生成新的采购单号和销售单号
  120. $cgdNo = makeNo($this->Tcode.'CG');
  121. $tempOrder['cgdNo'] = $cgdNo ;
  122. $cgdNo = substr($cgdNo, 0, -2) . str_pad($this->i, 2, '0', STR_PAD_LEFT);
  123. $orderCode = makeNo($this->Tcode.'QR');
  124. $orderCode = substr($orderCode, 0, -2) . str_pad($this->i, 2, '0', STR_PAD_LEFT);
  125. $this->i++;
  126. //计算渠道业务公司采购单单价。
  127. $cgd_total = bcsub($cgd_total, bcmul($sale['total_price'] ?? 0, round($pay_rate['rate'] / 100, 4), 5), 5);
  128. //此次销售单业务公司信息
  129. $supplier = ['No' => $pay_rate['companyNo'], 'name' => $pay_rate['companyName'],"pay_name"=>$pay_rate['pay_name']];
  130. $sale['origin_price'] = $sale['good_num'] > 0 ? bcdiv($cgd_total, $sale['good_num'], 5) : 0;
  131. $this->_handle_sale_caixiao($sale, $orderCode, $cgdNo, $sale_total, $customer, $supplier);
  132. $tempOrder['customerName'] = $pay_rate['companyName'];
  133. $tempOrder['customerNo'] = $pay_rate['companyNo'];
  134. $this->_handle_cgd_caixiao($cgd, $sale, $pay_rate, $cgdNo, $orderCode, $cgd_total,$tempOrder);
  135. //下一个渠道公司/原业务公司的 客户信息
  136. $customer= ['No' => $pay_rate['companyNo'], 'name' => $pay_rate['companyName']];
  137. $sale_total =$cgd_total; //下一个渠道公司/原业务公司的 销售价未此次的采购单价
  138. //判断是否是最后一个渠道遍历。最后一次需要额外生成一个销售单给原业务公司;
  139. if($keys == count($pay_rates)-1){
  140. $orderCode = makeNo($this->Tcode.'QR');
  141. $tempOrder['orderCode'] = $orderCode ;
  142. $orderCode = substr($orderCode, 0, -2) . str_pad($this->i, 2, '0', STR_PAD_LEFT);
  143. $supplier = ['No' => $sale['supplierNo'], 'name' => $sale['supplierName'],"pay_name"=>$pay_rate['pay_name']];
  144. if(!isset($cgd['cgdNo']) && $sale['is_stock']==1 ){
  145. $origin_total =Db::name('child_bn')
  146. ->where([['orderCode','=',$sale['orderCode']],['total_bn_num','>',0],['is_del','=',0]])
  147. ->field("sum(origin_price*total_bn_num) total_price,sum(total_bn_num) num")->findOrEmpty();
  148. if(empty($origin_total)==false && $origin_total['num']>0)$sale['origin_price'] = bcdiv($origin_total['total_price'],$origin_total['num'],8);
  149. else $sale['origin_price']=0;
  150. }else{
  151. $sale['origin_price'] = $cgd['good_price'];
  152. }
  153. $this->_handle_sale_caixiao($sale, $orderCode, $cgd['cgdNo'] ?? '', $sale_total,$customer, $supplier,$tempOrder);
  154. }
  155. //把自己覆盖到上一个记录的供应商记录中
  156. if (isset($this->cgd_insert[$this->cgd_key - 1])) {
  157. $temp = $userCommon->handle('hqInfo', ['code' =>$supplier['No']]);
  158. $supplier = $temp['data'] ?? [];
  159. $this->cgd_insert[$this->cgd_key - 1]['supplierNo'] =$supplier['relation_code'];
  160. $this->cgd_insert[$this->cgd_key - 1]['supplier_name'] = $supplier['relation_name'];
  161. //处理采购销售同一数据 业务公司的供应商编号数据
  162. $tempOrder['supplierName'] =$supplier['relation_name'];
  163. $tempOrder['supplierNo'] = $supplier['relation_code'];
  164. $temps = $userCommon->handle('sInfo', ['code' =>$supplier['relation_code']]);
  165. $suppliers = $temps['data'] ?? [];
  166. $this->cgd_insert[$this->cgd_key - 1]['supplier_persion'] = $suppliers['person'] ?? '';
  167. $this->cgd_insert[$this->cgd_key - 1]['supplier_persionid'] = $suppliers['personid'] ?? 0;
  168. }
  169. }
  170. //清空该变量,以防止多个销售单覆盖数据的情况
  171. // $cgd_insert_tmp_data = array_merge($cgd_insert_tmp_data, $this->cgd_insert);
  172. //批量新增改为单次新增
  173. if($this->cgd_insert) Db::name('cgd_caixiao')->insertAll($this->cgd_insert);
  174. $this->cgd_insert = [];
  175. $this->cgd_key = 0;
  176. $date=date('Y-m-d H:i:s');
  177. echo "【{$date}】订单:{$sale['orderCode']}拆单 \r\n";
  178. if(strtotime($sale['addtime']) >= strtotime('2024-02-01 00:00:00'))$commonOrder[]= $tempOrder;
  179. }
  180. // if ($cgd_insert_tmp_data) Db::name('cgd_caixiao')->insertAll($cgd_insert_tmp_data);
  181. if ($this->sale_insert) Db::name('sale_caixiao')->insertAll($this->sale_insert);
  182. Db::commit();
  183. $this->OrderSave($commonOrder);
  184. // $output->writeln('处理完成');
  185. }catch (\Exception $e) {
  186. Db::rollback();
  187. $output->writeln('事务回滚:' . $e->getMessage() . '||' . $e->getFile() . '||' . $e->getLine());
  188. }
  189. } catch (\Exception $exception) {
  190. $output->writeln('脚本执行出错,' . $exception->getMessage() . '||' . $exception->getFile() . '||' . $exception->getLine());
  191. }
  192. Cache::store('redis')->dec($key);
  193. }
  194. //构建销售单
  195. private function _handle_sale_caixiao(array $sale = [], string $orderCode = '', string $cgdNo = '', float $sale_total = 0.00, array $customer = [], array $supplier = [],array &$tempOrder=[])
  196. {
  197. $sale_price = $sale['good_num'] > 0 ? bcdiv($sale_total, $sale['good_num'], 5) : 0;
  198. $origin_total =round($sale['origin_price']*$sale['good_num'],8);
  199. $tmp_sale = [
  200. 'manager'=>$sale['manager'],
  201. 'managerid'=>$sale['managerid'],
  202. 'origin_price' =>round( $sale['origin_price'] ?? 0, 8),
  203. 'origin_plan_price' =>round( $sale['plan_price'] ?? 0, 8),
  204. 'total_origin_price' =>$origin_total,
  205. 'total_origin_price_plan' => $sale['plan_total'],
  206. 'pay_source' => $supplier['pay_name'],
  207. 'sale_price' => round($sale_price, 8),
  208. 'total_price' => $sale_total,
  209. 'post_fee' => $sale['post_fee'] ?? 0,
  210. 'is_diff' => $sale['is_diff'] ?? 0,
  211. 'send_num' => $sale['send_num'] ?? 0,
  212. 'wsend_num' => $sale['wsend_num'] ?? 0,
  213. 'workNo' => $sale['workNo'] ?? '',
  214. 'poNo' => $sale['platform_order'] ?? '',
  215. 'other_orderNo' => $sale['other_orderNo'],
  216. 'th_num' => $sale['th_num'] ?? 0,
  217. 'send_type' => $sale['send_type'] ?? 0,
  218. 'gold_price' => $sale['gold_price'] ?? 0,
  219. 'cost_price' => $sale['cost_price'] ?? 0,
  220. 'status' => $sale['status'] ?? 0,
  221. 'open_type'=>$sale['open_type'],
  222. 'updatetime' => $sale['updatetime'],
  223. 'delivery_day' => $sale['delivery_day'] ?? 0,
  224. 'th_fee' => round(bcmul($sale_price, $sale['th_num'] ?? 0, 3), 2),
  225. 'cost_fee' => $sale['cost_price'] ?? 0,
  226. 'diff_fee' => $sale['diff_fee'] ?? 0,
  227. 'tax' => $sale['tax'] ?? '',
  228. 'diff_weight' => $sale['diff_weight'] ?? 0,
  229. 'send_status' => $sale['send_status'] ?? 0,
  230. ];
  231. $tmp = Db::name('sale_caixiao')
  232. ->field('id,orderCode')
  233. ->where(['oldCode' => $sale['orderCode'], 'supplierNo' =>$supplier['No'] ?? '', 'customer_code' =>$customer['No'] ?? ''])
  234. ->findOrEmpty();
  235. if (!empty($tmp)) {
  236. Db::name('sale_caixiao')
  237. ->where('id', $tmp['id'])
  238. ->update($tmp_sale);
  239. if(isset($tempOrder['orderCode']))$tempOrder['orderCode']= $tmp['orderCode'];
  240. } else {
  241. if(isset($tempOrder['orderCode']))$tempOrder['orderCode']= $orderCode;
  242. $this->sale_insert[] = array_merge($tmp_sale, [
  243. 'orderCode' => $orderCode,
  244. 'apply_id' => $sale['apply_id'] ?? 0,
  245. 'apply_name' => $sale['apply_name'] ?? '',
  246. 'order_type' => $sale['order_type'] ?? 0,
  247. 'order_source' => $this->order_source,
  248. 'platform_id' => $sale['platform_id'] ?? '',
  249. 'platform_type' => $sale['use_type'] ?? '',
  250. "platform_name"=>$sale['platform_name']??"",
  251. 'good_code' => $sale['good_code'] ?? '',
  252. 'cat_id' => $sale['cat_id'] ?? 0,
  253. 'cat_name' => json_encode($this->_get_cat_list($sale['cat_id']), JSON_UNESCAPED_UNICODE),
  254. 'good_name' => $sale['good_name'] ?? '',
  255. 'good_num' => $sale['good_num'] ?? 0,
  256. 'good_type' => $sale['good_type'] ?? 0,
  257. 'is_activity' => $sale['is_activity'] ?? 0,
  258. 'is_stock' => $sale['is_stock'] ?? 0,
  259. 'arrive_time' => $sale['arrive_timefvc'] ?? '',
  260. 'customer_code' => $customer['No'] ?? '',
  261. 'customer_name' => $customer['name'] ?? '',
  262. 'supplierNo' => $supplier['No'] ?? '',
  263. 'supplier_name' => $supplier['name'] ?? '',
  264. 'zxNo' => $sale['zxNo'] ?? '',
  265. 'proof_id' => $sale['proof_id'] ?? 0,
  266. 'proof_url' => $sale['proof_url'] ?? '',
  267. 'other_orderNo' => $sale['other_orderNo'],
  268. 'paytime' => $sale['paytime'] ?? '',
  269. 'workNo' => $sale['workNo'] ?? '',
  270. 'poNo' => $sale['platform_order'] ?? '',
  271. 'use_order' => $sale['use_order'],
  272. 'good_weight' => $sale['good_weight'] ?? 0,
  273. 'addtime' => $sale['addtime'],
  274. 'noble_metal' => $sale['noble_metal'] ?? '',
  275. 'brand' => $sale['brand'] ?? '',
  276. 'unit' => $sale['unit'] ?? '',
  277. 'cost_desc' => $sale['cost_desc'] ?? '',
  278. 'noble_weight' => $sale['noble_weight'] ?? 0,
  279. 'tax' => $sale['tax'] ?? '',
  280. 'lead_time' => $sale['lead_time'] ?? 0,
  281. 'depart' => isset($sale['apply_id']) ? get_company_name_by_uid($sale['apply_id']) : '',
  282. 'cgdNo' => $cgdNo,
  283. 'total_origin_price' => $origin_total,
  284. 'total_origin_price_plan' => $sale['plan_total'],
  285. 'pay_id' => $sale['pay_id'],
  286. 'pay_source' => $supplier['pay_name'],
  287. 'oldCode' => $sale['orderCode'],
  288. ]);
  289. }
  290. }
  291. //构建采购单
  292. private function _handle_cgd_caixiao(array $cgd = [], array $sale = [], array $pay_rate = [], string $cgdNo = '',
  293. string $orderCode = '', float $cgd_total = 0.00,array &$tempOrder=[])
  294. {
  295. $good_price = $sale['good_num'] > 0 ? bcdiv($cgd_total, $sale['good_num'], 8) : 0;
  296. $tmp_cgd = [
  297. 'good_price' => round($good_price, 8),
  298. 'total_fee' => $cgd_total,
  299. 'origin_total' => $cgd_total,
  300. 'pakage_fee' => $cgd['pakge_fee'] ?? 0,
  301. 'open_fee' => $cgd['open_fee'] ?? 0,
  302. 'cert_fee' => $cgd['cert_fee'] ?? 0,
  303. 'delivery_fee' => $cgd['delivery_fee'] ?? 0,
  304. 'mark_fee' => $cgd['mark_fee'] ?? 0,
  305. 'teach_fee' => $cgd['teach_fee'] ?? 0,
  306. 'nake_fee' => $cgd['nake_fee'] ?? 0,
  307. 'demo_fee' => $cgd['demo_fee'] ?? 0,
  308. 'weight' => $cgd['weight'] ?? 0,
  309. 'diff_weight' => $sale['diff_weight'] ?? 0,
  310. 'diff_fee' => $sale['diff_fee'] ?? 0,
  311. 'gold_price' => $sale['gold_price'] ?? 0,
  312. 'send_num' => $sale['send_num'] ?? 0,
  313. 'wsend_num' => $sale['wsend_num'] ?? 0,
  314. 'status' => $cgd['status'] ?? 3,
  315. 'order_type' => $sale['order_type'],
  316. 'order_source' => $this->order_source,
  317. 'good_type' => $sale['good_type'] ?? '',
  318. 'last_time' => $cgd['last_time'] ?? '',
  319. 'send_type' => $sale['send_type'] ?? '',
  320. 'send_status' => $sale['send_status'] ?? '',
  321. "open_type"=>$sale['open_type'],
  322. 'th_num' => $sale['th_num'] ?? 0,
  323. 'th_fee' => round(bcmul($good_price, $sale['th_num'] ?? 0, 3), 2),
  324. 'updatetime' => $sale['updatetime'],
  325. ];
  326. $tmp = Db::name('cgd_caixiao')
  327. ->field('id,cgdNo,supplier_name,supplierNo')
  328. ->where(['oldCode' => $sale['orderCode'], 'companyNo' => $pay_rate['companyNo']])
  329. ->findOrEmpty();
  330. if (!empty($tmp)) {
  331. Db::name('cgd_caixiao')
  332. ->where('id', $tmp['id'])
  333. ->update($tmp_cgd);
  334. if(isset($tempOrder['cgdNo'])){
  335. $tempOrder['cgdNo']= $tmp['cgdNo'];
  336. $tempOrder['supplierName'] =$tmp['supplier_name'];
  337. $tempOrder['supplierNo'] = $tmp['supplierNo'];
  338. }
  339. } else {
  340. if(isset($tempOrder['cgdNo']))$tempOrder['cgdNo']=$cgdNo;
  341. $this->cgd_insert[$this->cgd_key] = array_merge($tmp_cgd, [
  342. 'cgdNo' => $cgdNo,
  343. 'bkcode' => $cgd['bkcode'] ?? '',
  344. 'wsm_code' => $cgd['wsm_code'] ?? '',
  345. 'cgder' => $sale['cgder'] ?? '',
  346. 'cgder_id' => $sale['cgderid'] ?? 0,
  347. 'depart' => isset($sale['cgderid']) ? get_company_name_by_uid($sale['cgderid']) : '',
  348. 'qrdNo' => $orderCode,
  349. 'platform_id' => $sale['platform_id'] ?? '',
  350. 'platform_name'=>$sale['platform_name']??'',
  351. 'spuCode' => $cgd['spuCode'] ?? $sale['good_code'],
  352. 'good_name' => $sale['good_name'],
  353. 'skuCode' => $cgd['skuCode'] ?? '',
  354. 'good_num' => $sale['good_num'] ?? 0,
  355. 'cat_name' => json_encode($this->_get_cat_list($sale['cat_id']), JSON_UNESCAPED_UNICODE),
  356. 'companyNo' => $pay_rate['companyNo'],
  357. 'companyName' => $pay_rate['companyName'],
  358. 'supplierNo' => $sale['supplierNo'],
  359. 'supplier_name' => $sale['supplierName'],
  360. 'bktime' => $cgd['bktime'] ?? '',
  361. 'bkcreater' => $cgd['bkcreater'] ?? '',
  362. 'noble_metal' => $sale['noble_metal'] ?? '',
  363. 'brand' => $sale['brand'] ?? '',
  364. 'unit' => $sale['unit'] ?? '',
  365. 'cost_desc' => $sale['cost_desc'] ?? '',
  366. 'noble_weight' => $sale['noble_weight'] ?? '',
  367. 'tax' => $sale['tax'] ?? '',
  368. 'is_stock' => $sale['is_stock'],
  369. 'delivery_day' => $sale['delivery_day'] ?? 0,
  370. 'lead_time' => $sale['lead_time'] ?? 0,
  371. 'is_diff' => $sale['is_diff'],
  372. 'addtime' => $sale['addtime'],
  373. 'supplier_persion' => '',
  374. 'supplier_persionid' => '',
  375. 'pay_id' => $sale['pay_id'],
  376. 'oldCode' => $sale['orderCode']
  377. ]);
  378. $this->cgd_key++;
  379. }
  380. }
  381. //获取分类层级信息,id、cat_name(分类名称)和fund_code(财务核算码)
  382. private function _get_cat_list($var, $data = [])
  383. {
  384. $str = Db::name('cat')
  385. ->field('id,cat_name,fund_code,pid')
  386. ->where(['id' => $var])
  387. ->findOrEmpty();
  388. if ($str == false) return [];
  389. $vmn = [];
  390. $vmn['id'] = $str['id'];
  391. $vmn['cat_name'] = $str['cat_name'];
  392. $vmn['fund_code'] = $str['fund_code'];
  393. array_unshift($data, $vmn);
  394. if ($str['pid'] == 0) return $data;
  395. else return $this->_get_cat_list($str['pid'], $data);
  396. }
  397. //处理采购销售同一数据 录入结算 统一数据表中
  398. protected function OrderSave($order){
  399. if(empty($order)) return ;
  400. foreach ($order as &$item){
  401. $com = $this->comOrder->where('cxCode',$item['cxCode'])->findOrEmpty();
  402. if($com->isEmpty()==false){
  403. $item['id'] = $com->id;
  404. $item['tyCode'] = $com->tyCode;
  405. if(in_array($com->status,[0,1,2]))$item['status']=$com->status;
  406. }else{
  407. $item['id']=null;
  408. }
  409. }
  410. $this->comOrder->saveAll($order);
  411. }
  412. }