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(["unitT","cat","brand","platform"]) ->where($where) ->order("id desc") ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]); $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]); } /** * 显示创建资源表单页. * * @return \think\Response */ public function create() { $param = $this->request->param([ "companyNo"=>"", "customerCode"=>"", "platform_id"=>"", "good_num"=>"", "good_price"=>"", "skuCode"=>"", "manager"=>"", "managerid"=>"", "fill_remark"=>"" ],"post","trim"); $valid=Validate::rule([ "companyNo|业务公司"=>"require|max:255", "customerCode|客户公司"=>'require|max:255', "platform_id|平台"=>'require|number', "good_num|商品数量"=>'require|number|gt:0', "good_price|商品单价"=>'require|float|gt:0', "skuCode|商品编号"=>'require|max:255', '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,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"=>1, "is_compliance"=>1, "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']; $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 ConsultBids())->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('商品可用库存不足'); $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' =>$good->bidNo?: '', '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->fillCode, '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{ $ist =$this->model->lock(true)->findOrEmpty($param['id']); if($ist->wtrans_num< $transNum)throw new \Exception('报备单可转单数量不足!'); $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('商品库存修改失败'); } $i=0; foreach ($Addr as $item){ $outCode = substr(makeNo('DF'), 0, -2) . str_pad(strval($i), 2, '0', STR_PAD_LEFT); $i++; $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' =>$info->fill_type, 'status' => 0, 'send_status' => $info->fill_type==1?1:0, '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('发货单创建失败'); if($info->fill_type==1)OrderOutChild::makeChild($outCode); } $ist->transfer_num +=$transNum; $ist->status=$ist->transfer_num >= $ist->good_num?3:2; $upd=$ist->save(); if($upd==false)throw new \Exception('报备单更新失败'); $this->model->commit(); //非库存数据需要生成采购单 异步监听事件处理 需要注意采购单生成失败无法回滚 if($info->fill_type!==1){ event("CgdCreate",$orderCode); } $event=[ 'order_type' => 'CKD', 'order_code' =>$outCode,//咨询单详情编号 'order_id' => $outinfo->id, 'order_status' => 2, 'action_process' =>1, 'action_status' => $info->fill_type!==1?0:1, 'action_uid' => $this->uid, 'action_name' => $this->uname, ]; event('ProcessOrder',$event); $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); }catch (\Exception $exception){ $this->model->rollback(); $this->error($exception->getMessage()); } $this->success("转单成功",["orderCode"=>$orderCode]); } /** * 咨询订单转业务报备 */ public function ZixunCreate() { $param=$this->request->param(["bidNo"=>"","sale_price"=>"","manager"=>"","managerid"=>"","good_num"=>"", "proof_type"=>"",'proof_url'=>'',"remark"=>""],"post","trim"); $valid = Validate::rule([ "bidNo|咨询竞价单号"=>"require", "sale_price|商品单价"=>"require|float|gt:0", "manager|业务经理"=>"require|max:255", "managerid|业务经理id"=>"require|number|gt:0", "good_num|商品数量"=>"require|number|gt:0", "proof_type|凭证类型"=>"require|number|in:0,1,2,3", "proof_url|凭证地址"=>"require" ]); if($valid->check($param)==false)$this->error($valid->getError()); $bids=new ConsultBids(); $info = $bids->where(["bidNo"=>$param["bidNo"],"is_del"=>0])->findOrEmpty(); if($info->isEmpty()) $this->error("竞价单信息未找到"); if( $param['sale_price'] < $info['sale_price']) $this->error('修改的销售单价不能低于原来的销售单价'); $coninfo= new ConsultInfo(); $this->model->startTrans(); try{ $zxinfo = $coninfo->with('consult_order')->where(['infoNo' => $info['infoNo'], 'is_del' => 0])->lock(true)->findOrEmpty(); if($zxinfo->isEmpty()) throw new \Exception("未找到咨询单信息"); if($zxinfo->is_project!=2) throw new \Exception("咨询单类型有误"); $data=[ 'fillCode'=>makeNo('BF'), 'fill_type'=>3, 'skuCode'=>'', 'spuCode'=>$info->spuCode, 'good_name'=>$info->good_name, 'unit_id'=>$info->unit_id, 'brand_id'=>$info->brand_id, 'cat_id'=>$info->cat_id, 'good_num'=>$param['good_num'], 'good_price'=>$param['sale_price'], 'platform_id'=>$zxinfo->platform_id, 'total_price'=>bcmul($param['good_num'],$param['sale_price'],4), 'origin_price'=>$info->total_fee, 'apply_id'=>$this->uid, 'apply_name'=>$this->uname, 'status'=>1, 'companyNo'=>$zxinfo->companyNo, 'companyName'=>$zxinfo->companyName, 'customerCode'=>$zxinfo->khNo, 'customerName'=>$zxinfo->khName, 'supplierNo'=>$info->supplierNo, 'supplierName'=>$info->supplierName, 'is_compliance'=>0, 'plat_code'=>'', 'fill_remark'=>$param['remark'], 'manager'=>$param['manager'], 'managerid'=>$param['managerid'], ]; $bbcCre=BbcFill::create($data); if($bbcCre->id==false) throw new \Exception('报备单创建失败'); BargainOrder::update(["status"=>4],['bidsNo' =>$param['bidNo'],'is_del'=>0,'status'=>0]); $info->status=6; $up =$info->save(); if($up==false) throw new \Exception('竞价单状态更新失败'); $zxinfo->status=5; $zxup=$zxinfo->save(); if($zxup==false) throw new \Exception('咨询单状态更新失败'); $limt = [ 'spuCode' => $info['spuCode'], 'good_name' => $info['good_name'], 'brand_id' => $info['brand_id'], 'good_unit' => $info['unit_id'], 'cat_id' => $info['cat_id'], 'good_type' => 0, 'moq' => 1, 'customized' => $info['work_day'], 'tax' => $info['tax'], 'supplierNo' => $info['supplierNo'], 'supplierName' =>$info['supplierName'], 'is_auth' => 0, 'craft_desc' => $info['good_name'], 'good_remark' => '', 'platform_id' => $zxinfo['platform_id'], 'good_img' => $info['good_img'], 'good_thumb_img' => '', 'good_info_img' => '', 'specinfo' => $info['specinfo'], 'work_day' => $info['work_day'], 'noble_metal' => $info['metal_id'], 'is_gold_price' => $info['is_gold_price'], 'config' => $info['config'], 'other_config' => $info['other_config'], 'weight' => $info['weight'], 'good_weight' => $info['good_weight'], 'is_diff' => $info['is_diff'], 'supply_area' => $info['supply_area'], 'pay_way' => $info['pay_way'], 'send_way' => $info['send_way'], 'companyNo' => $zxinfo['companyNo'], 'companyName' =>$zxinfo['companyName'], 'status' => 1, 'is_del' => 0, 'order_type' => 3, 'order_source' => 11, 'createrid' => $zxinfo['createrid'], 'creater' => $zxinfo['creater'], 'order_createrid' => $this->uid, 'order_creater' => $this->uname, 'addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'proof_type' => $param['proof_type'],//凭证类型 'proof_url' => $param['proof_url'],//凭证文件 ]; GoodZixun::create($limt); $this->model->commit(); }catch (\Exception $exception){ $this->model->rollback(); $this->error($exception->getMessage().$exception->getLine()); } $this->success("报备单生成成功",["fillCode"=>$data['fillCode']]); } /** * 保存更新的资源 * * @param \think\Request $request * @param int $id * @return \think\Response */ public function info() { $id = $this->request->post("id"); $info =$this->model->with(['unitT','cat','brand',"platform"])->findOrEmpty($id); if($info->isEmpty()) $this->error("未找到数据"); $this->success("获取成功",$info); } }