|
@@ -0,0 +1,359 @@
|
|
|
+<?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("商品未上线");
|
|
|
+ $data=[
|
|
|
+ "fillCode"=>makeNo("BF"),
|
|
|
+ "total_price"=>bcmul($param['good_num'],$param['good_price'],4),
|
|
|
+ "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;
|
|
|
+ }
|
|
|
+ $origin_price=0;
|
|
|
+ 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' => $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)
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
+}
|