123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\listener;
- use app\admin\model\Good;
- use app\admin\model\GoodLog;use app\admin\model\GoodNake;
- use app\admin\model\GoodStock;use app\admin\model\OrderOut;use app\admin\model\OrderSend;use app\admin\model\PurcheaseOrder;
- use app\admin\model\Sale;
- use app\admin\model\WarehouseInfo;
- use app\bbc\model\BbcFill;
- use app\admin\model\OrderNum;use app\model\AccountCompany;
- class Cgdmake
- {
- /**
- * 非库存品生成cgd
- *
- * @return mixed
- */
- public function handle($event)
- {
- $orderinfo = (new Sale())->where(["orderCode"=>$event])->findOrEmpty();
- if($orderinfo->isEmpty()==false&& $orderinfo->order_type!=1){
- $cgdCode = makeNo('CG');
- $wsm =(new WarehouseInfo())->where(['supplierNo' => $orderinfo->supNo, 'companyNo' =>$orderinfo->supplierNo, 'wsm_type' => 2,
- 'is_del' => 0])->findOrEmpty();
- if($wsm->isEmpty()){
- $wsm_code = makeNo('WSM');
- $inwsm = [
- 'wsm_code' => $wsm_code,
- 'name' => $orderinfo->supName,
- 'wsm_type' => 2,
- 'supplierNo' => $orderinfo->supNo,
- 'supplierName' => $orderinfo->supName,
- 'addr' => '',
- 'addrs_code' => '',
- 'contactor' => $orderinfo->cgderid ,
- 'contactor_name' => $orderinfo->cgder ,
- 'mobile' => '',
- 'position' => '',
- 'companyNo' => $orderinfo->supplierNo,
- 'companyName' => $orderinfo->supplierName,
- 'status' => 1,
- 'is_del' => 0,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s'),
- 'createrid' => $orderinfo->apply_id,
- 'creater' => $orderinfo->apply_name,
- 'updaterid' => $orderinfo->apply_id,
- 'updater' => $orderinfo->apply_name,
- ];
- WarehouseInfo::create($inwsm);
- }else {
- $wsm_code = $wsm['wsm_code'];
- }
- //判断该供应商是否开通了供应商账号
- $from_tag=AccountCompany::IsOpenAccount($orderinfo->supNo);
- $info = (new BbcFill())->where(["fillCode"=>$orderinfo->other_orderNo])->findOrEmpty();
- if($info->isEmpty())return;
- if($info->fill_type==2){
- $origins=(new GoodNake())->where([['spuCode', '=', $orderinfo->good_code], ['min_num', '<=',
- $info->good_num], ['is_del', '=', 0]])->order('min_num desc')->findOrEmpty();
- $good = (new Good())->where(['spuCode'=>$orderinfo->good_code])->findOrEmpty();
- $origin =array_merge($good->toArray(),$origins->toArray());
- }
- if($info->fill_type==3){
- $origin =(new \app\admin\model\ConsultBids())->where([['spuCode', '=', $orderinfo->good_code] ,['is_del', '=',
- 0]])->findOrEmpty()->toArray();
- }
- $cg = [
- 'cgdNo' => $cgdCode,
- 'bkcode' => '',
- 'wsm_code' => $wsm_code,
- 'cgder' => $orderinfo->cgder,
- 'cgder_id' => $orderinfo->cgderid,
- 'spuCode' => $orderinfo->good_code,
- 'skuCode' => $orderinfo->skuCode,
- 'good_name' => $orderinfo->good_name,
- 'good_num' => $orderinfo->good_num,
- 'good_price' => $orderinfo->origin_price,
- 'total_fee' => round(bcmul($orderinfo->origin_price , $orderinfo->good_num,4),2),
- 'pakge_fee' => $origin['pakge_fee']??"0",
- 'cert_fee' => $origin['cert_fee']??'0',
- 'open_fee' => $origin['open_fee']??'0',
- 'teach_fee' => $origin['cost_fee']??'0',
- 'mark_fee' => $origin['mark_fee']??'0',
- 'demo_fee' => $origin['demo_fee']??'0',
- 'nake_fee' => $origin['nake_fee']??'0',
- 'weight' => $origin['weight'],
- 'delivery_fee' => $origin['delivery_fee']??0,
- 'gold_price' =>0,
- 'diff_weight' => '0',
- 'diff_fee' => '0',
- 'supplierNo' => $orderinfo->supNo ,
- 'supplier_name' => $orderinfo->supName,
- 'companyNo' => $orderinfo->supplierNo,
- 'companyName' => $orderinfo->supplierName,
- 'send_status' => 1,
- 'send_num' => 0,
- 'wsend_num' => $orderinfo->good_num,
- 'remark' => '',
- 'status' => 0,//0初始化
- 'lasttime' => date('Y-m-d H:i:s'),
- 'is_del' => 0,
- 'order_type' => $orderinfo->order_type,
- 'order_source' =>11,
- 'good_type' => $orderinfo->good_type,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s'),
- 'good_createrid' => $origin['createrid'],
- 'good_creater' => $origin['creater'],//商品创建人
- 'from_tag' => $from_tag==false ? 2 : 1,//来源标签:1采销(默认),2供应商端
- ];
- $cgd=PurcheaseOrder::create($cg);
- $events=['order_type' => 'CGD',
- 'order_code' =>$cgdCode,//咨询单详情编号
- 'order_id' => $cgd->id,
- 'order_status' => 2,
- 'action_process' =>0,
- 'action_status' => 0,
- 'action_uid' => $orderinfo->apply_id,
- 'action_name' => $orderinfo->apply_name,
- ];
- event('ProcessOrder',$events);
- $orderOut= (new OrderOut())->where(["orderCode"=>$orderinfo->orderCode])
- ->field("outCode,'{$cgdCode}' cgdNo,send_num")->select();
- if($orderOut->isEmpty()==false) (new OrderSend())->saveAll($orderOut->toArray());
- $rela = [
- 'orderCode' => $event,
- 'cgdNo' => $cgdCode,
- 'spuCode' => $orderinfo->good_code,
- 'good_num' => $orderinfo->good_num,
- 'wsend_num' =>$orderinfo->good_num,
- 'send_num' => 0,
- 'wait_num' => 0,
- 'status' => 1,
- 'source' => 2
- ];
- OrderNum::create($rela);
- $goodstock =new GoodStock();
- $stockinfo = $goodstock->where(['spuCode' =>$orderinfo->good_code, 'wsm_code' => $wsm_code, 'is_del' => 0])->findOrEmpty();
- if($stockinfo->isEmpty()){
- $stokc = [
- 'spuCode' => $orderinfo->good_code,
- 'wsm_code' => $wsm_code,
- 'wait_in_stock' => $orderinfo->good_num,
- 'wait_out_stock' => 0,
- 'usable_stock' => 0,
- 'intra_stock' => 0,
- 'total_stock' => 0,
- 'status' => 1,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s')
- ];
- $stockinfo= GoodStock::create($stokc);
- }else{
- $stockinfo->inc( 'wait_in_stock' ,$orderinfo->good_num)->update();
- }
- $good_data[] = ['good_log_code' => $cgdCode, 'stock_id' =>$stockinfo->id, 'type' => 1,'stock' => $orderinfo->good_num, 'stock_name' => 'wait_in_stock'];
- GoodLog::LogAdd(['id'=>$orderinfo->apply_id,'nickname'=>$orderinfo->apply_name], $good_data, 'CGD');
- }
- }
- }
|