123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <?php
- declare (strict_types = 1);
- namespace app\bbc\controller;
- use app\admin\model\GoodNake;use app\admin\model\GoodPlatform;use app\admin\model\GoodZixun;use app\admin\model\OrderAddr;use app\admin\model\OrderOut;use app\admin\model\OrderOutChild;use app\admin\model\Sale;use app\bbc\model\BbcFill;
- use app\model\Headquarters;use app\model\Supplier;use app\report\model\ConsultBids;use think\App;
- use think\Exception;use think\facade\Validate;use think\Request;
- class Fill extends Base
- {
- protected $model=null;
- public function __construct(App $app) {
- parent::__construct($app);
- $this->model=new BbcFill();
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function list()
- {
- $param=$this->request->param(["cat_id"=>"","start"=>"",'end'=>'',"fillCode"=>"","status"=>"","good_name"=>"",
- "spuCode"=>"","companyNo"=>"","customerCode"=>"","is_compliance"=>"","page"=>1,"size"=>15],"post","trim");
- $where=[];
- $param['companyNo']==""??$where[]=["companyNo","like","%{$param['companyNo']}%"];
- $param['customerCode']==""??$where[]=["customerCode","like","%{$param['customerCode']}%"];
- $param['fillCode']==""??$where[]=["fillCode","like","%{$param['fillCode']}%"];
- $param['good_name']==""??$where[]=["good_name","like","%{$param['good_name']}%"];
- $param['spuCode']==""??$where[]=["spuCode","like","%{$param['spuCode']}%"];
- $param['is_compliance']===""??$where[]=["is_compliance","=",$param['is_compliance']];
- $param['cat_id']===""??$where[]=["cat_id","=",$param['cat_id']];
- $param['status']===""??$where[]=["status","=",$param['status']];
- $list=$this->model->with(["unit","cat","brand"])
- ->where($where)
- ->order("id desc")
- ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
- $this->success("获取成功",["list"=>$list->items(),"count"=>$list->items()]);
-
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- $param = $this->request->param([
- "companyNo"=>"",
- "customerCode"=>"",
- "platform_id"=>"",
- "good_num"=>"",
- "good_price"=>"",
- // "spuCode"=>"",
- "skuCode"=>"",
- "manager"=>"",
- "managerid"=>"",
- "fill_remark"=>""
- ],"post","trim");
- $valid=Validate::rule([
- "companyNo|业务公司"=>"require|max255",
- "customerCode|客户公司"=>'require|max255',
- "platform_id|平台"=>'require|number',
- "good_num|商品数量"=>'require|number|gt:0',
- "good_price|商品单价"=>'require|float',
- "skuCode|商品编号"=>'require|max255',
- // "spuCode|商品上线编号"=>'require|max255',
- 'manager|业务经理'=>'require',
- 'managerid|业务经理id'=>'require',
- 'fill_remark|订单备注'=>'require'
- ]);
- if($valid->check($param)==false) $this->error($valid->getError());
- $head=new Headquarters();
- $company = $head->where(["code"=>[$param['companyNo'],$param['customerCode']]])->column("name","code");
- if(empty($company))$this->error("未找到相关业务公司/客户名称信息");
- $goodinfo = (new GoodPlatform())->alias("a")->leftJoin("good b","a.spuCode=b.spuCode")
- ->where("skuCode",$param['skuCode'])
- ->field("skuCode,b.spuCode,platform_code platform_id,is_compliance,compliance_remark,plat_code,good_name,
- cat_id,exam_status,brand_id,good_unit unit_id,supplierNo,supplierName,if(is_stock=1,1,2) fill_type")
- ->findOrEmpty();
- if($goodinfo->isEmpty()) $this->error("商品信息未找到");
- if($goodinfo->exam_status!=3) $this->error("商品未上线");
- $origin_price=0;
- if($goodinfo->fill_type==2){
- $origin =(new GoodNake())->where([['spuCode', '=', $goodinfo->spuCode], ['min_num', '<=', $param['good_num']],
- ['is_del', '=', 0]])->order('min_num desc')->findOrEmpty();
- if ($origin->isEmpty()) $this->error('未找到商品相关阶梯成本价格');
- $origin_price = $origin->nake_total;
- }
- $data=[
- "fillCode"=>makeNo("BF"),
- "total_price"=>bcmul($param['good_num'],$param['good_price'],4),
- "origin_price"=>$origin_price,
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "status"=>2,
- "companyName"=>$company[$param['companyNo']]??"",
- "customerName"=>$company[$param['customerCode']]??"",
- ];
- $create= array_merge($data,$param,$goodinfo->toArray());
- BbcFill::create($create);
- $this->success("业务报备信息创建成功");
- }
- /**
- * 是否合规审核
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function compliance()
- {
- $param=$this->request->param(["id"=>"","is_compliance"=>"","plat_code"=>"","compliance_remark"=>""],"post","trim");
- $valid =Validate::rule([
- "id|主键id"=>"require|number|gt:0",
- "is_compliance|是否合规"=>"require|number|in:1,2",
- "compliance_remark|合规备注"=>"requireIf:is_compliance,2",
- "plat_code|BBC平台商品编号"=>"requireIf:is_compliance,1"
- ]);
- if($valid->check($param)==false) $this->error($valid->getError());
- $info= $this->model->findOrEmpty($param['id']);
- if($info->isEmpty())$this->error("未找到报备单数据");
- $info->is_compliance = $param['is_compliance'];
- $info->compliance_remark = $param['compliance_remark'];
- $info->plat_code = $param['plat_code'];
- // $info->status=2;
- $up =$info->save();
- $up?$this->success("报备单更新成功"):$this->error("报备单更新失败");
- }
- /**
- 报备转单
- */
- public function transfer()
- {
-
- $param = $this->request->only([
- 'id'=>"",
- 'addr_list'=>[],
- 'customerCode'=>'',
- "poCode"=>""
- ], 'post',"trim");
- $val = Validate::rule([
- 'id|报备的主键id' => 'require|number|gt:0',
- 'customerCode|客户编号'=>'require|max:255',
- 'addr_list|收货地址' => 'require|array|max:100',
- 'poCode|平台订单号' => 'require|max:255',
- ]);
- if ($val->check($param)==false)$this->error( $val->getError());
- $val2 = Validate::rule([
- 'receipt_quantity|收货数量' => 'require|number|gt:0|max:999999999',
- 'contactor|联系人' => 'require|max:255',
- 'mobile|联系电话' => 'require|mobile',
- 'addr_code|收货省市区编码' => 'array|length:3',
- 'addr|详细地址' => 'require|max:255',
- ]);
- $info = $this->model->findOrEmpty($param['id']);
- if($info->isEmpty()) $this->error("未找到报备单数据");
- if($info->status==3 ||$info->status==4 )$this->error('报备单数据'.BbcFill::$status_cn[$info->status]);
- $head=new Headquarters();
- $company = $head->where(['code'=>$param['customerCode']])->findOrEmpty();
- if($company->isEmpty())$this->error('未找到相关客户名称信息');
- if($info->fill_type!=3) $good =(new \app\admin\model\Good())->where(["spuCode",$info->spuCode])->findOrEmpty();
- else $good=(new GoodZixun())->where(['spuCode',$info->spuCode])->findOrEmpty();
- if($good->isEmpty())$this->error('未找到商品信息');
- $supplier = (new Supplier())->where(["code"=>$info->supplierNo])->findOrEmpty();
- if($supplier->isEmpty())$this->error('未找到供应商信息');
- $orderCode= makeNo("QR");
- $orderArr=[];
- $transNum=0;
- foreach ($param["addr_list"] as $item){
- if ($val2->check($item)==false)$this->error( $val2->getError());
- $temp=['orderCode' => $orderCode,
- 'addr' => $item['addr'],
- 'addr_code' =>empty( $item['addr_code'])?'': implode(',', $item['addr_code']),
- 'contactor' => $item['contactor'],
- 'mobile' => $item['mobile'],
- 'customer_code' => $param['customerCode'],
- 'post_fee' => 0,
- 'receipt_quantity' => $item['receipt_quantity'],
- 'is_del' => 0,
- 'addtime' => date("Y-m-d H:i:s"),
- 'updatetime' => date('Y-m-d H:i:s')
- ];
- $transNum+=$item['receipt_quantity'];
- $orderArr[]=$temp;
- }
- if($info->fill_type==1 && $good->usable_stock< $transNum) $this->error('商品可用库存不足');
- // if($info->fill_type==2){
- // $origin =(new GoodNake())->where([['spuCode', '=', $good->spuCode], ['min_num', '<=', $info->good_num],
- // ['is_del', '=', 0]])->order('min_num desc')->findOrEmpty();
- // if ($origin->isEmpty()) $this->error('未找到商品相关阶梯成本价格');
- // $origin_price = $origin->nake_total;
- // }
- // if($info->fill_type==3){
- // $origin =(new \app\admin\model\ConsultBids())->where([['spuCode', '=', $good->spuCode] ,['is_del', '=',
- // 0]])->findOrEmpty();
- // if ($origin->isEmpty()) $this->error('未找到商品相关成本价格');
- // $origin_price = $origin->total_fee;
- // }
- $orderInfo=[
- 'orderCode' => $orderCode,
- 'apply_id' => $this->uid,
- 'apply_name' => $this->uname,
- 'order_type' => $info->fill_type,//报备商品
- 'order_source' => 11,//业务报备转单
- 'platform_id' => $info->platform_id,
- 'good_code' => $info->spuCode,
- 'skuCode' => $info->skuCode,
- 'cat_id' => $info->cat_id,
- 'good_name' => $info->good_name,
- 'good_num' => $transNum,
- 'good_type' => 1,
- 'origin_price' => $info->origin_price,
- 'sale_price' => round($info->good_price,2),
- 'total_price' => round(bcmul($info->good_price, strval($transNum), 4), 2),
- 'post_fee' => 0,
- 'is_diff' => $good->is_diff,
- 'is_activity' => 0,
- 'activity_code' => '',
- 'is_stock' => 0,
- 'customer_code' => $param['customerCode'],
- 'customerName' => $company['name'],
- 'supplierNo' => $info->companyNo,
- 'supplierName' => $info->companyName,
- 'supNo' =>$info->supplierNo,
- 'supName' => $info->supplierName,
- 'zxNo' => '',
- 'platform_order' =>$param['poCode'],
- 'send_num' => 0,
- 'wsend_num' =>$transNum,
- 'th_num' => 0,
- 'th_fee' => 0,
- 'send_status' => 1,
- 'send_type' => 1,//直接发货
- 'remark' => '',
- 'status' => 0,
- 'is_del' => 0,
- 'proof_id' => 0,
- 'other_orderNo' => $info->filingCode,
- 'workNo' => '',
- 'poNo' => '',
- 'use_order' => 0,
- 'good_weight' => 0,
- 'gold_price' => 0,
- 'cost_price' => $good->cost_fee,
- 'diff_weight' => 0,
- 'diff_fee' => 0,
- 'returnCode' => '',
- 'addtime' => date("Y-m-d H:i:s"),
- 'updatetime' =>date('Y-m-d H:i:s'),
- 'cgderid' => $supplier->personid,
- 'cgder' => $supplier->person,
- 'good_createrid' => $good['createrid'],
- 'good_creater' =>$good['createrid'],
- 'manager'=>$info->manager,
- 'managerid'=>$info->managerid
- ];
- $this->model->startTrans();
- try{
- $order=Sale::create($orderInfo);
- if($order->id==false) throw new \Exception("订单创建失败");
- $Addr=(new OrderAddr())->saveAll($orderArr);
- if($info->fill_type==1){
- $up = (new \app\admin\model\Good())->where(["spuCode"=>$info->spuCode])->lock(true)->findOrEmpty();
- if($up->isEmpty())throw new \Exception('未找到商品信息');
- if($up->usable_stock< $transNum)throw new \Exception('商品可用库存不足');
- $up->usable_stock= $up->usable_stock-$transNum;
- $up->updatetime=date('Y-m-d H:i:s');
- $goodUp=$up->save();
- if($goodUp==false)throw new \Exception('商品库存修改失败');
- foreach ($Addr as $item){
- $outCode= make("DF");
- $out=[
- 'orderCode' => $orderCode,
- 'outCode' => $outCode,
- 'apply_id' => $this->uid,
- 'apply_name' => $this->uname,
- 'addrid' => $item->id,
- 'post_name' => '',
- 'post_code' => '',
- 'post_fee' => 0,
- 'sendtime' => date('Y-m-d H:i:s'),
- 'send_num' => $item->receipt_quantity,
- 'check_num' => 0,
- 'error_num' => 0,
- 'wsm_code' => '',
- 'order_type' =>1,
- 'send_status' => 1,
- 'status' => 1,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s')
- ];
- $outinfo=OrderOut::create($out);
- if($outinfo->isEmpty())throw new \Exception('发货单创建失败');
- OrderOutChild::makeChild($outCode);
- $event=[ 'order_type' => 'CKD',
- 'order_code' =>$outCode,//咨询单详情编号
- 'order_id' => $outinfo->id,
- 'order_status' => 2,
- 'action_process' =>1,
- 'action_status' => 1,
- 'action_uid' => $this->uid,
- 'action_name' => $this->uname,
- ];
- event('ProcessOrder',$event);
- }
- }
- $this->model->commit();
- if($info->fill_type!==1){
- $event=[ 'order_type' => 'XSQRD',
- 'order_code' =>$orderCode,//咨询单详情编号
- 'order_id' => $order->id,
- 'order_status' => 2,
- 'action_process' =>0,
- 'action_status' => 0,
- 'action_uid' => $this->uid,
- 'action_name' => $this->uname,
- ];
- event('ProcessOrder',$event);
- event("CgdCreate",$orderCode);
- }
- }catch (\Exception $exception){
- $this->error($exception->getMessage());
- $this->model->rollback();
- }
- $this->success("转单成功",["orderCode"=>$orderCode]);
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function edit($id)
- {
- //
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- //
- }
- }
|