model=new \app\admin\model\Track(); } //运费单创建 public function create(){ $param = $this->request->post('list/a', '', 'trim'); if(empty($param))$this->error("参数不能为空"); $rule =Validate::rule([ "outChildCode|发货工单编号"=>"require|max:255", "supplierNo|物流供货商"=>'require|max:255', "companyNo|业务公司"=>'require|max:255', "post_fee|物流费用"=>'require|float', ]); $supplier = (new SupplierInfo())->where(["code"=>array_unique(array_column($param,"supplierNo"))])->column("name","code"); $business = (new CompanyInfo())->where(["companyNo"=>array_unique(array_column($param,"companyNo"))])->column("company_name","companyNo"); $outChild = (new FhdChild())->where(["outChildCode"=>array_unique(array_column($param,'outChildCode'))]) ->column('orderCode','outChildCode'); $cgdArr = (new CgdInfo())->where(["qrdCode"=>array_unique($outChild)])->column("sequenceNo","qrdCode"); $qrdArr = (new QrdInfo())->where(["sequenceNo"=>array_unique($outChild)])->column("ownerName,ownerid","sequenceNo"); $data=[]; foreach ($param as $item){ if($rule->check($item)==false)$this->error($rule->getError()); if(!isset($outChild[$item['outChildCode']]))$this->error("发货工单未找到或未发货"); $temp=[ "TrackCode"=>makeNo("TK"), "orderCode"=>$outChild[$item['outChildCode']], "cgdNo"=>$cgdArr[$outChild[$item['outChildCode']]]??"", "saler"=>$qrdArr[$outChild[$item['outChildCode']]]['ownerName'], "salerid"=>$qrdArr[$outChild[$item['outChildCode']]]['ownerid'], "outChildCode"=>$item['outChildCode'], "supplierNo"=>$item['supplierNo'], "supplierName"=>$supplier[$item['supplierNo']]??"", 'companyNo'=>$item['companyNo'], 'companyName'=>$business[$item['companyNo']]??'', 'post_fee'=>$item['post_fee'], 'apply_name'=>$item['apply_name'], 'apply_id'=>$item['apply_id'] ]; $data[]=$temp; } $this->model->saveAll($data); $this->success("运费单创建成功"); } //***列表 public function list(){ $param=$this->request->param(["outChildCode"=>"","order_type"=>"","order_source"=>"","supplierNo"=>"", "companyNo"=>"","status"=>"","orderCode"=>"","cgdNo"=>"",'page'=>1,'size'=>10],"post","trim"); $where=[]; $param['outChildCode']==''??$where[]=["outChildCode","like","%{$param['outChildCode']}%"]; $param['orderCode']==''??$where[]=["orderCode","like","%{$param['orderCode']}%"]; $param['cgdNo']==''??$where[]=["cgdNo","like","%{$param['cgdNo']}%"]; $param['order_type']==''??$where[]=["order_type","=",$param['order_type']]; $param['order_source']==''??$where[]=["order_source","=",$param['order_source']]; $param['supplierNo']==''??$where[]=["supplierNo","=",$param['supplierNo']]; $param['companyNo']==''??$where[]=["companyNo","=",$param['companyNo']]; $param['status']==''??$where[]=["status","=",$param['status']]; $list=$this->model->with(['fhdChild'])->order("id desc")->paginate(["list_rows"=>$param['size'], "page"=>$param['page']]); $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]); } //***列表 public function info(){ $param=$this->request->param(["id"=>""],'post','trim'); $valid=Validate::rule(["id"=>"require|number|gt:0"]); if($valid->check($param)==false)$this->error($valid->getError()); $list=$this->model->with(['fhdChild'])->order('id desc')->findOrEmpty($param['id']); $this->success('获取成功',$list); } //***列表 public function query(){ $param=$this->request->param(['outChildCode'=>[],'order_type'=>'','order_source'=>'','supplierNo'=>'', 'companyNo'=>'','status'=>'','orderCode'=>[],'cgdNo'=>[],"page"=>1,"size"=>100],'post','trim'); $where=[]; empty($param['outChildCode'])??$where[]=['outChildCode','in',$param['outChildCode']]; empty($param['cgdNo'])??$where[]=['cgdNo','in',$param['cgdNo']]; empty($param['orderCode'])??$where[]=['orderCode','in',$param['orderCode']]; // $param['orderCode']==''??$where[]=['orderCode','like',"%{$param['orderCode']}%"]; // $param['cgdNo']==''??$where[]=['cgdNo','like',"%{$param['cgdNo']}%"]; $param['order_type']==''??$where[]=['order_type','=',$param['order_type']]; $param['order_source']==''??$where[]=['order_source','=',$param['order_source']]; $param['supplierNo']==''??$where[]=['supplierNo','=',$param['supplierNo']]; $param['companyNo']==''??$where[]=['companyNo','=',$param['companyNo']]; $param['status']==''??$where[]=['status','=',$param['status']]; $list=$this->model->with(['fhdChild'])->order('id desc')->paginate(['list_rows'=>$param['size'], 'page'=>$param['page']]); $this->success('获取成功',['list'=>$list->items(),'count'=>$list->total()]); } public function PayAdd(){ $param=$this->request->param(['cids'=>[]],'post','trim'); $valid = Validate::rule(['cids|对账数据集合'=>'require|array']); if($valid->check($param)==false)$this->error($valid->getError()); $PayObject = new \app\admin\model\Track(); $objall= $PayObject->where(['id'=>$param['cids']])->select(); if($objall->isEmpty()) $this->error('对账数据不能为空'); $supplierNo= array_column($objall,'supplierNo'); $supplierName= array_column($objall,'supplierName'); if(count(array_unique($supplierNo))>1){ $this->error('对账数据供应商不唯一'); } $companyNo= array_column($objall,'companyNo'); $companyName= array_column($objall,'companyName'); if(count(array_unique($companyNo))>1){ $this->error('对账数据业务公司不唯一'); } if ($this->level == 2) { //判断是否开通供应商账号 $temp = check_has_account_by_supplierNos([$supplierNo[0]]); if (isset($temp['data'][$supplierNo[0]])) $this->error( '该供应商已经开通账号,不允许当前账号操作'); } $pay= new Pay(); $data = [ 'payNo'=>makeNo('PAY'), 'apply_id'=>$this->uid, 'apply_name'=>$this->uname, 'total_fee'=>'0', 'pay_type'=>2, 'supplierNo'=>$supplierNo[0], 'supplierName'=>$supplierName[0], 'companyNo'=>$companyNo[0], 'companyName'=>$companyName[0], 'wpay_fee'=>'0', 'apay_fee'=>'0', 'ainv_fee'=>'0', 'winv_fee'=>'0', 'remark'=>'', 'status'=>1, ]; $pay->startTrans(); try{ $payinfo=[]; foreach ($objall as $item){ $temp=[]; $temp['cgdNo']=$item['TrackCode']; $temp['total_fee']=$item['post_fee']; $temp['apay_fee']=0; $temp['wpay_fee']=$item['post_fee']; $temp['winv_fee']=0; $temp['ainv_fee']=$item['post_fee']; $temp['payNo']=$data['payNo']; $temp['addtime']=date('Y-m-d H:i:s'); $temp['updatetime']=date('Y-m-d H:i:s'); $payinfo[]=$temp; $data['total_fee']=bcadd($data['total_fee'],$item['post_fee'],2); $data['wpay_fee']= bcadd($data['wpay_fee'],$item['post_fee'],2); $data['winv_fee']= bcadd($data['winv_fee'],$item['post_fee'],2); } $info =(new PayInfo())->saveAll($payinfo); if(empty($info)==false){ $create=$pay->save($data); if($create)$objall->update(['status'=>1]); } $pay->commit(); }catch (\Exception $e){ $pay->rollback(); $this->error($e->getMessage()); } $this->success('对账单添加成功',['payNo'=>$data['payNo']]); } /**对账单未对账前编辑8**/ public function PaySave(){ $param=$this->request->param(['cids'=>[],'payNo'=>''],'post','trim'); $valid = Validate::rule(['cids|对账数据集合'=>'require|array','payNo|对账编号'=>'require']); if($valid->check($param)==false)$this->error($valid->getError()); $PayObject = new \app\admin\model\Track(); $pay= new Pay(); $objall= $PayObject->where(['id'=>$param['cids']])->select(); if($objall->isEmpty()) $this->error('对账数据不能为空'); $PayInfo = $pay->where(['payNo'=>$param['payNo']])->findOrEmpty(); if($PayInfo->isEmpty()) $this->error('未找到对账单数据'); $supplierNo= array_column($objall,'supplierNo'); $supplierName= array_column($objall,'supplierName'); if(count(array_unique($supplierNo))>1){ $this->error('对账数据供应商不唯一'); } $companyNo= array_column($objall,'companyNo'); $companyName= array_column($objall,'companyName'); if(count(array_unique($companyNo))>1){ $this->error('对账数据业务公司不唯一'); } if ($this->level == 2) { //判断是否开通供应商账号 $temp = check_has_account_by_supplierNos([$supplierNo[0]]); if (isset($temp['data'][$supplierNo[0]])) $this->error( '该供应商已经开通账号,不允许当前账号操作'); } $trackArr = PayInfo::where(['payNo'=>$param['payNo'],'is_del'=>0,'status'=>1])->column('cgdNo'); $add=$remove=[]; if(empty($trackArr)==false){ $remove= array_diff($trackArr,array_column($objall,'TrackCode')); $add= array_diff(array_column($objall,'TrackCode'),$trackArr); } $data = [ 'apply_id'=>$this->uid, 'apply_name'=>$this->uname, 'total_fee'=>'0', 'supplierNo'=>$supplierNo[0], 'supplierName'=>$supplierName[0], 'companyNo'=>$companyNo[0], 'companyName'=>$companyName[0], 'wpay_fee'=>'0', 'winv_fee'=>'0', ]; $pay->startTrans(); try{ $payinfo=[]; foreach ($objall as $item){ $data['total_fee']=bcadd($data['total_fee'],$item['post_fee'],2); $data['wpay_fee']= bcadd($data['wpay_fee'],$item['post_fee'],2); $data['winv_fee']= bcadd($data['winv_fee'],$item['post_fee'],2); if(!empty($add)&& in_array($item['TrackCode'],$add)){ $temp=[]; $temp['cgdNo']=$item['TrackCode']; $temp['total_fee']=$item['post_fee']; $temp['apay_fee']=0; $temp['wpay_fee']=$item['post_fee']; $temp['winv_fee']=0; $temp['ainv_fee']=$item['post_fee']; $temp['payNo']=$param['payNo']; $temp['addtime']=date('Y-m-d H:i:s'); $temp['updatetime']=date('Y-m-d H:i:s'); $payinfo[]=$temp; } } if(!empty($payinfo))(new PayInfo())->saveAll($payinfo); $up = $PayInfo->save($data); if($up){ $objall->update(['status'=>1]); if(!empty($remove)){ $PayObject->where(['TrackCode'=>$remove,'status'=>1])->update(['status'=>0]); PayInfo::where(['cgdNo'=>$remove,'status'=>1,'is_del'=>0])->update(['status'=>0,'is_del'=>1]); } } $pay->commit(); }catch (\Exception $exception){ $pay->rollback(); $this->error($exception->getMessage()); } $this->success('更新成功'); } }