Cgdmake.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\listener;
  4. use app\admin\model\Good;
  5. use app\admin\model\GoodLog;use app\admin\model\GoodNake;
  6. use app\admin\model\GoodStock;use app\admin\model\OrderOut;use app\admin\model\OrderSend;use app\admin\model\PurcheaseOrder;
  7. use app\admin\model\Sale;
  8. use app\admin\model\WarehouseInfo;
  9. use app\bbc\model\BbcFill;
  10. use app\admin\model\OrderNum;use app\model\AccountCompany;
  11. class Cgdmake
  12. {
  13. /**
  14. * 非库存品生成cgd
  15. *
  16. * @return mixed
  17. */
  18. public function handle($event)
  19. {
  20. $orderinfo = (new Sale())->where(["orderCode"=>$event])->findOrEmpty();
  21. if($orderinfo->isEmpty()==false&& $orderinfo->order_type!=1){
  22. $cgdCode = makeNo('CG');
  23. $wsm =(new WarehouseInfo())->where(['supplierNo' => $orderinfo->supNo, 'companyNo' =>$orderinfo->supplierNo, 'wsm_type' => 2,
  24. 'is_del' => 0])->findOrEmpty();
  25. if($wsm->isEmpty()){
  26. $wsm_code = makeNo('WSM');
  27. $inwsm = [
  28. 'wsm_code' => $wsm_code,
  29. 'name' => $orderinfo->supName,
  30. 'wsm_type' => 2,
  31. 'supplierNo' => $orderinfo->supNo,
  32. 'supplierName' => $orderinfo->supName,
  33. 'addr' => '',
  34. 'addrs_code' => '',
  35. 'contactor' => $orderinfo->cgderid ,
  36. 'contactor_name' => $orderinfo->cgder ,
  37. 'mobile' => '',
  38. 'position' => '',
  39. 'companyNo' => $orderinfo->supplierNo,
  40. 'companyName' => $orderinfo->supplierName,
  41. 'status' => 1,
  42. 'is_del' => 0,
  43. 'addtime' => date('Y-m-d H:i:s'),
  44. 'updatetime' => date('Y-m-d H:i:s'),
  45. 'createrid' => $orderinfo->apply_id,
  46. 'creater' => $orderinfo->apply_name,
  47. 'updaterid' => $orderinfo->apply_id,
  48. 'updater' => $orderinfo->apply_name,
  49. ];
  50. WarehouseInfo::create($inwsm);
  51. }else {
  52. $wsm_code = $wsm['wsm_code'];
  53. }
  54. //判断该供应商是否开通了供应商账号
  55. $from_tag=AccountCompany::IsOpenAccount($orderinfo->supNo);
  56. $info = (new BbcFill())->where(["fillCode"=>$orderinfo->other_orderNo])->findOrEmpty();
  57. if($info->isEmpty())return;
  58. if($info->fill_type==2){
  59. $origins=(new GoodNake())->where([['spuCode', '=', $orderinfo->good_code], ['min_num', '<=',
  60. $info->good_num], ['is_del', '=', 0]])->order('min_num desc')->findOrEmpty();
  61. $good = (new Good())->where(['spuCode'=>$orderinfo->good_code])->findOrEmpty();
  62. $origin =array_merge($good->toArray(),$origins->toArray());
  63. }
  64. if($info->fill_type==3){
  65. $origin =(new \app\admin\model\ConsultBids())->where([['spuCode', '=', $orderinfo->good_code] ,['is_del', '=',
  66. 0]])->findOrEmpty()->toArray();
  67. }
  68. $cg = [
  69. 'cgdNo' => $cgdCode,
  70. 'bkcode' => '',
  71. 'wsm_code' => $wsm_code,
  72. 'cgder' => $orderinfo->cgder,
  73. 'cgder_id' => $orderinfo->cgderid,
  74. 'spuCode' => $orderinfo->good_code,
  75. 'skuCode' => $orderinfo->skuCode,
  76. 'good_name' => $orderinfo->good_name,
  77. 'good_num' => $orderinfo->good_num,
  78. 'good_price' => $orderinfo->origin_price,
  79. 'total_fee' => round(bcmul($orderinfo->origin_price , $orderinfo->good_num,4),2),
  80. 'pakge_fee' => $origin['pakge_fee']??"0",
  81. 'cert_fee' => $origin['cert_fee']??'0',
  82. 'open_fee' => $origin['open_fee']??'0',
  83. 'teach_fee' => $origin['cost_fee']??'0',
  84. 'mark_fee' => $origin['mark_fee']??'0',
  85. 'demo_fee' => $origin['demo_fee']??'0',
  86. 'nake_fee' => $origin['nake_fee']??'0',
  87. 'weight' => $origin['weight'],
  88. 'delivery_fee' => $origin['delivery_fee']??0,
  89. 'gold_price' =>0,
  90. 'diff_weight' => '0',
  91. 'diff_fee' => '0',
  92. 'supplierNo' => $orderinfo->supNo ,
  93. 'supplier_name' => $orderinfo->supName,
  94. 'companyNo' => $orderinfo->supplierNo,
  95. 'companyName' => $orderinfo->supplierName,
  96. 'send_status' => 1,
  97. 'send_num' => 0,
  98. 'wsend_num' => $orderinfo->good_num,
  99. 'remark' => '',
  100. 'status' => 0,//0初始化
  101. 'lasttime' => date('Y-m-d H:i:s'),
  102. 'is_del' => 0,
  103. 'order_type' => $orderinfo->order_type,
  104. 'order_source' =>11,
  105. 'good_type' => $orderinfo->good_type,
  106. 'addtime' => date('Y-m-d H:i:s'),
  107. 'updatetime' => date('Y-m-d H:i:s'),
  108. 'good_createrid' => $origin['createrid'],
  109. 'good_creater' => $origin['creater'],//商品创建人
  110. 'from_tag' => $from_tag==false ? 2 : 1,//来源标签:1采销(默认),2供应商端
  111. ];
  112. $cgd=PurcheaseOrder::create($cg);
  113. $events=['order_type' => 'CGD',
  114. 'order_code' =>$cgdCode,//咨询单详情编号
  115. 'order_id' => $cgd->id,
  116. 'order_status' => 2,
  117. 'action_process' =>0,
  118. 'action_status' => 0,
  119. 'action_uid' => $orderinfo->apply_id,
  120. 'action_name' => $orderinfo->apply_name,
  121. ];
  122. event('ProcessOrder',$events);
  123. $orderOut= (new OrderOut())->where(["orderCode"=>$orderinfo->orderCode])
  124. ->field("outCode,'{$cgdCode}' cgdNo,send_num")->select();
  125. if($orderOut->isEmpty()==false) (new OrderSend())->saveAll($orderOut->toArray());
  126. $rela = [
  127. 'orderCode' => $event,
  128. 'cgdNo' => $cgdCode,
  129. 'spuCode' => $orderinfo->good_code,
  130. 'good_num' => $orderinfo->good_num,
  131. 'wsend_num' =>$orderinfo->good_num,
  132. 'send_num' => 0,
  133. 'wait_num' => 0,
  134. 'status' => 1,
  135. 'source' => 2
  136. ];
  137. OrderNum::create($rela);
  138. $goodstock =new GoodStock();
  139. $stockinfo = $goodstock->where(['spuCode' =>$orderinfo->good_code, 'wsm_code' => $wsm_code, 'is_del' => 0])->findOrEmpty();
  140. if($stockinfo->isEmpty()){
  141. $stokc = [
  142. 'spuCode' => $orderinfo->good_code,
  143. 'wsm_code' => $wsm_code,
  144. 'wait_in_stock' => $orderinfo->good_num,
  145. 'wait_out_stock' => 0,
  146. 'usable_stock' => 0,
  147. 'intra_stock' => 0,
  148. 'total_stock' => 0,
  149. 'status' => 1,
  150. 'addtime' => date('Y-m-d H:i:s'),
  151. 'updatetime' => date('Y-m-d H:i:s')
  152. ];
  153. $stockinfo= GoodStock::create($stokc);
  154. }else{
  155. $stockinfo->inc( 'wait_in_stock' ,$orderinfo->good_num)->update();
  156. }
  157. $good_data[] = ['good_log_code' => $cgdCode, 'stock_id' =>$stockinfo->id, 'type' => 1,'stock' => $orderinfo->good_num, 'stock_name' => 'wait_in_stock'];
  158. GoodLog::LogAdd(['id'=>$orderinfo->apply_id,'nickname'=>$orderinfo->apply_name], $good_data, 'CGD');
  159. }
  160. }
  161. }