model=new \app\cxinv\model\FinancialManager(); } public function List(){ $param = $this->request->param(["code"=>"","type"=>[],"seller_code"=>"","buyer_code"=>"","orderCode"=>"","cxCode"=>"", "goodNo"=>"","inv_number"=>"","inv_buyer_code"=>"",'inv_seller_code'=>"",'channel'=>[],'status'=>"","start"=>"","end"=>"", "page"=>1,"size"=>15],"post","trim"); $where=[]; if($param['code']!="") $where[]= ["code","=","%{$param['code']}%"]; if(!empty($param['type'])) $where[]= ["type","in",$param['type']]; if(!empty($param['channel'])) $where[]= ["channel","in",$param['channel']]; if($param['status']!="") $where[]= ["status","in",$param['status']]; if($param['start']!="") $where[]= ["create_time",">=",startTime($param['start'])]; if($param['end']!="") $where[]= ["create_time","<=",endTime($param['end'])]; if($param['seller_code']!="") $where[]= ["seller_code","=",$param['seller_code']]; if($param['buyer_code']!="") $where[]= ["buyer_code","=",$param['buyer_code']]; if($param['orderCode']!="") $where[]= ["orderCode","like", "%{$param['orderCode']}%"]; if($param['cxCode']!="") $where[]= ["cxCode","like","%{$param['cxCode']}%"]; if($param['goodNo']!="") $where[]= ["goodNo","like","%{$param['goodNo']}%"]; if($param['inv_number']!="") $where[]= ["inv_number","like","%{$param['inv_number']}%"]; if($param['inv_buyer_code']!="") $where[]= ["inv_buyer_code","=",$param['inv_buyer_code']]; if($param['inv_seller_code']!="") $where[]= ["inv_seller_code","=",$param['inv_seller_code']]; $list = $this->model->with(['ProductRela'=>["product"]]) ->where($where) ->order("id desc") ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]); return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]); } // 'code'=>'string',//订单或记录的唯一标识符 // 'type'=>'int',//记录类型 1入库 2出库 3入库红冲 4出库红冲 // 'source'=>'int',//数据来源,1结算 2 线下订单 // channel=>'int',//渠道,1订单 2 线下订单 3 toC订单 // 'seller_code'=>'string',//卖方代码 // 'seller_name'=>'string',//卖方名称 // 'buyer_code'=>'string',//买方代码 // 'buyer_name'=>'string',//买方名称 // 'orderCode'=>'string',//订单编号 // 'cxCode'=>'string',//客户编号 // 'poCode'=>'string',//采购订单编号 // 'platform_type'=>'int',//平台类型,1ToB 2ToC // 'goodNo'=>'string',//商品编号 // 'goodName'=>'string',//商品名称 // 'unit'=>'string',//商品单位 // 'num'=>'int',//商品数量 // 'goodPrice'=>'decimal',//商品单价 // 'totalPrice'=>'decimal',//商品总价 // 'cat_code'=>'string',//商品分类代码 // 'cat_name'=>'string',//商品分类名称 // 'tax'=>'decimal',//税率或税费 // 'inv_fee'=>'decimal',//发票费用 // 'inv_seller_code'=>'string',//发票卖方代码 // 'inv_seller_name'=>'string',//发票卖方名称 // 'inv_buyer_code'=>'string',//发票买方代码 // 'inv_buyer_name'=>'string',//发票买方名称 // 'inv_number'=>'string',//发票编号 // 'inv_type'=>'string',//发票类型 // 'inv_item_id'=>'int',//发票项目ID // 'inv_good_name'=>'string',//发票商品名称 // 'inv_cat_code'=>'string',//发票商品分类代码 // 'inv_spec'=>'string',//发票商品规格 // 'inv_unit'=>'string',//发票商品单位 // 'inv_num'=>'int',//发票商品数量 // 'inv_subprice'=>'decimal',//发票商品子项单价 // 'inv_subtotal'=>'decimal',//发票商品子项总价 // 'inv_tax'=>'decimal',//发票税额 // 'inv_tax_total'=>'decimal',//发票总税额 // 'inv_price'=>'decimal',//发票单价 // 'inv_total'=>'decimal',//发票总价 // 'cat_diff'=>'int',//分类差异 // 'tax_diff'=>'int',//税费差异 // 'remark'=>'string',//备注或说明 public function create(){ $list=$this->request->post("list",[],"trim"); if(empty($list)) return error("请传入数据"); foreach ($list as $key=>&$item){ $valid = $this->validate($item,[ 'type|单据类型'=>'require|in:1,2,3,4', 'source|单据来源'=>'require|in:1,2', "channel|渠道"=>'require|in:1,2,3', 'invoiceCode|发票代码'=>'max:255', 'seller_code|卖方公司纳税识别号'=>'require|max:255', 'seller_name|卖方公司名称'=>'require|max:255', 'buyer_code|买方公司纳税识别号'=>'require|max:255', 'buyer_name|买方公司名称'=>'require|max:255', 'orderCode|订单号'=>'max:255', 'cxCode|主订单号'=>'max:255', 'poCode|Po订单号'=>'max:255', 'platform_type|平台类型'=>'require|in:1,2', 'goodType|商品类型'=>'require|in:1,2,3', 'goodNo|商品编号'=>'require|max:255', 'goodName|商品名称'=>'require|max:255', 'unit|商品单位'=>'require|max:255', 'num|商品数量'=>'require|integer', 'goodPrice|商品单价'=>'require|float', 'totalPrice|商品总价'=>'require|float', 'cat_code|商品分类代码'=>'require|max:255', 'cat_name|商品分类名称'=>'require|max:255', 'tax|税率或税费'=>'require|float', 'inv_fee|发票关联费用'=>'float', 'inv_seller_code|发票卖方代码'=>'max:255', 'inv_seller_name|发票卖方名称'=>'max:255', 'inv_buyer_code|发票买方代码'=>'max:255', 'inv_buyer_name|发票买方名称'=>'max:255', 'inv_number|发票编号'=>'max:255', 'inv_type|发票类型'=>'max:255', 'inv_open_date|发票开票日期'=>'max:255', 'inv_item_id|发票项目ID'=>'integer', 'inv_good_name|发票商品名称'=>'max:255', 'inv_cat_code|发票商品分类代码'=>'max:255', 'inv_spec|发票商品规格'=>'max:255', 'inv_unit|发票商品单位'=>'max:255', 'inv_num|发票商品数量'=>'float', 'inv_subprice|发票商品税后单价'=>'float', 'inv_subtotal|发票商品税后总价'=>'float', 'inv_tax|发票税额'=>'max:255', 'inv_tax_total|发票总税额'=>'float', 'inv_price|发票单价'=>'float', 'inv_total|发票总价'=>'float', 'cat_diff|分类差异'=>'max:255', 'tax_diff|税费差异'=>'max:255', 'remark|备注'=>'max:255', 'relaArr|关联数据'=>'array', 'fz_date|入账月份'=>'max:255' ]); if($valid!==true)return error($valid); if($item['channel']==1){ $check = $this->model->CheckDatas($item); if(!empty($check)) return error($key+1 ."行数据校验不通过",1004,$check); } if($item['tax']!='' && $item['inv_tax']!=''){ $item['inv_tax'] = str_replace("%","",$item['inv_tax']); $item['tax_diff'] = $item['tax']==$item['inv_tax']?1:2; } if($item['cat_code']!='' && $item['inv_cat_code']!=''){ $item['cat_diff'] = $item['cat_code']==$item['inv_cat_code']?1:2; } $companyCode= in_array($item['type'],['2','4'])?$item['seller_code']:$item['buyer_code']; $fz_date = ProductFz::where(['company_code'=>$companyCode,'fz_date'=>$item['fz_date']])->findOrEmpty(); if($fz_date->isEmpty()) return error($companyCode."--[{$item['fz_date']}]请生成封账单"); if($fz_date->status!=0) return error($companyCode."--{$item['fz_date']}封账状态不可用"); $item['apply_id']=$this->uid; $item['apply_name']=$this->uname; $item['code']= makeNo("PM", count($list)==1?"":str_pad(strval($key),4,0,STR_PAD_LEFT)); } $this->model->startTrans(); try{ foreach ($list as $val){ (new \app\cxinv\model\FinancialManager)->CreateData($val); } $this->model->commit(); }catch (\Exception $e){ $this->model->rollback(); return error($e->getMessage()); } return success("操作成功"); } public function info(){ $id=$this->request->param("id",0,"intval"); $info=$this->model->with(['ProductRela'=>["product"],'FinancialTz'=>["ProductTz"]])->findOrEmpty($id); if($info->isEmpty()) return error("数据不存在"); $ProductMap=[]; if($info['status']==3){ $map = $info->FinancialTz->ProductTz->toArray(); foreach ($map as $k=>$v){ if($v['type']==1) $ProductMap[] = $v['product_id']; } } foreach ($info['ProductRela'] as $key=>$val){ if(in_array($val['product_id'],$ProductMap)){ $info['ProductRela'][$key]['is_check']=1; }else{ $info['ProductRela'][$key]['is_check']=0; } } return success("获取成功",$info); } //处理待确认数据 public function CheckSure(){ $params = $this->request->param(['manager_id'=>'','relaArr'=>[],"fz_date","is_checkOrder"=>0],'post','trim'); $valid = $this->validate($params,[ 'manager_id|出库明细ID'=>'require|integer', 'relaArr|关联数据'=>'require|array', 'fz_date|封账月份'=>'max:255', 'is_checkOrder|是否生成计提单子'=>'require|in:0,1' ]); if($valid!==true) return error($valid); $manager = $this->model->findOrEmpty($params['manager_id']); if($manager->isEmpty()) return error('待确认数据不存在'); if($manager['status']!=1 && $manager['status']!=4) return error('当前待确认数据状态不允许操作'); $manager->relaArr=$params['relaArr']; $manager->fz_date=$params['fz_date']??$manager->fz_date; $companyCode= in_array($manager['type'],['2','4'])?$manager['seller_code']:$manager['buyer_code']; $fz_date = ProductFz::where(['company_code'=>$companyCode,'fz_date'=>$manager['fz_date']])->findOrEmpty(); if($fz_date->isEmpty()) return error("请先生成封账单"); if($fz_date->status!=0) return error("{$manager['fz_date']}封账状态不可用"); $this->model->startTrans(); try{ $manager->cl_uid=$this->uid; //调整单需要创建人 $manager->cl_uname=$this->uname;//调整单需要创建人 if($manager->type==1 || $manager->type==4)$check = $this->model->inProduct($manager); else { if($params['is_checkOrder']==1)$check = $this->model->OutKet($manager); else$check = $this->model->outProduct($manager); } if(empty($check)) return error('待确认数据处理失败'); if($manager->balance_num!=0) return error('待确认数据数量未处理完不可提交'); ManagerProduct::AddProduct($manager->id,$check); $manager->save(); $this->model->commit(); }catch (\Exception $e){ $this->model->rollback(); return error($e->getMessage()); } return success('操作成功'); } //待确认数据 c端订单确认处理 public function CheckSureByOther(){ $params = $this->request->param(['manager_id'=>[],'relaArr'=>[],"fz_date","is_checkOrder"=>0],'post','trim'); $valid = $this->validate($params,[ 'manager_id|出库明细ID'=>'require|array', 'relaArr|关联数据'=>'require|array', 'fz_date|封账月份'=>'max:255', 'is_checkOrder|是否生成计提单子'=>'require|in:0,1' ]); if($valid!==true) return error($valid); $manager = $this->model->whereIn('id',$params['manager_id'])->select(); if($manager->isEmpty()) return error('待确认数据不存在'); $goodNos = array_unique(array_column($manager->toArray(),'goodNo')); if(count($goodNos)!=1) return error('待确认数据商品编码不一致'); if($params['is_checkOrder']==1){ $totalnum = array_sum(array_column($manager->toArray(),'balance_num')); $relaNum = array_sum(array_column($params['relaArr'],'num')); if($totalnum!=$relaNum) return error('待确认数据数量不一致'); } $this->model->startTrans(); try{ foreach ($manager as $item){ $item->relaArr=[]; $relaArr= array_map(function (&$val) use ($item){ $temp=$val; $temp['id']=$val['id']; $temp['num']=$item->balance_num; $val['num']= bcsub($val['num'],$item->balance_num,8); return $temp; },$params['relaArr']); $item->relaArr= $relaArr; $item->fz_date=$params['fz_date']??$item->fz_date; $item->cl_uid=$this->uid; $item->cl_uname=$this->uname; $companyCode= in_array($item['type'],['2','4'])?$item['seller_code']:$item['buyer_code']; $fz_date = ProductFz::where(['company_code'=>$companyCode,'fz_date'=>$item['fz_date']])->findOrEmpty(); if($fz_date->isEmpty()) throw new \Exception("请先生成封账单"); if($fz_date->status!=0) throw new \Exception("{$manager['fz_date']}封账状态不可用"); if($item->type==1 || $item->type==4)$check = $this->model->inProduct($item); else { if($params['is_checkOrder']==1)$check = $this->model->OutKet($item); else$check = $this->model->outProduct($item); } if(empty($check)) throw new \Exception('待确认数据处理失败'); if($item->balance_num!=0) throw new \Exception('待确认数据数量未处理完不可提交'); ManagerProduct::AddProduct($item->id,$check); $item->save(); } $this->model->commit(); }catch (\Exception $e){ $this->model->rollback(); return error($e->getMessage()); } return success('操作成功'); } // 删除待确认数据 public function delete(){ $ids = $this->request->param('id',[]); $info=$this->model->whereIn('id',$ids)->select(); if($info->isEmpty()) return error("数据不存在"); foreach ($info as $item){ if($item->status!=1 && $item->status!=4) return error("当前数据[$item->id]状态不允许删除"); if($item->balance_num!=$item->total_num) return error("数据[$item->id]数量已处理过不可删除"); } $info->delete(); return success("删除成功"); } //调整单列表 public function CheckList(){ $params = $this->request->param(["page"=>1,"size"=>20,"goodType"=>'',"goodNo"=>'',"company_code"=>'',"start_time"=>"","end_time"=>"","keywords"=>""],"post","trim"); $where=[]; if($params['goodType']!='') $where[]=['goodType','=',$params['goodType']]; if($params['goodNo']!='') $where[]=['goodNo','=',$params['goodNo']]; if($params['company_code']!='') $where[]=['company_code','=',$params['company_code']]; if($params['keywords']!="") $where[]=['goodName|goodNo','like',"%".$params['keywords']."%"]; if($params['start_time']!="" && $params['end_time']!=""){ $where[]=['create_time','between',[$params['start_time'],$params['end_time']]]; } $list = FinancialCheck::where($where) ->order('id desc') ->paginate(['page'=>$params['page'],'list_rows'=>$params['size']]); return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]); } //调整单数据删除 public function CheckDelete(){ $ids = $this->request->param('id',[]); if(empty($ids)) return error("请选择数据"); $info=FinancialCheck::whereIn('id',$ids)->select(); if($info->isEmpty()) return error("数据不存在"); $info->delete(); return success("删除成功"); } public function CheckInfo(){ $id = $this->request->param('id',0); $info = FinancialCheck::with(['FinancialTz'=>['ProductTz'=>['Product']],'ProductCheck'=>['Product']])->where('id',$id)->findOrEmpty(); if($info->isEmpty()) return error("数据不存在"); return success("获取成功",$info); } //导出数据manager异常数据 public function export(){ $param = $this->request->param(["code"=>"","type"=>[],"seller_code"=>"","buyer_code"=>"","orderCode"=>"","cxCode"=>"", "goodNo"=>"","inv_number"=>"","inv_buyer_code"=>"",'inv_seller_code'=>"",'channel'=>[1],'status'=>"","start"=>"","end"=>"", "page"=>1,"size"=>15],"post","trim"); $where=[]; $headeIndex =0; if($param['code']!="") $where[]= ["code","=","%{$param['code']}%"]; if(!empty($param['type'])) $where[]= ["type","in",$param['type']]; if(!empty($param['channel'])) { $where[]= ["channel","in",$param['channel']]; if(in_array(3,$param['channel'])) $headeIndex =2; } if($param['status']!="") $where[]= ["status","in",$param['status']]; if($param['start']!="") $where[]= ["create_time",">=",startTime($param['start'])]; if($param['end']!="") $where[]= ["create_time","<=",endTime($param['end'])]; if($param['seller_code']!="") $where[]= ["seller_code","=",$param['seller_code']]; if($param['buyer_code']!="") $where[]= ["buyer_code","=",$param['buyer_code']]; if($param['orderCode']!="") $where[]= ["orderCode","like", "%{$param['orderCode']}%"]; if($param['cxCode']!="") $where[]= ["cxCode","like","%{$param['cxCode']}%"]; if($param['goodNo']!="") $where[]= ["goodNo","like","%{$param['goodNo']}%"]; if($param['inv_number']!="") $where[]= ["inv_number","like","%{$param['inv_number']}%"]; if($param['inv_buyer_code']!="") $where[]= ["inv_buyer_code","=",$param['inv_buyer_code']]; if($param['inv_seller_code']!="") $where[]= ["inv_seller_code","=",$param['inv_seller_code']]; $heade=[ ["业务编号","类型","订单来源","订单购买方纳税号","订单购买方公司名称","订单销售方纳税号","订单销售方公司名称","订单编号","订单主单号", "商品类型","商品编号","商品名称","订单单位","商品数量","商品单价","订单总金额","税目","税目名称","订单税率","关联金额","购买方纳税号", "购买方名称","发票号码","开票日期","发票类型","销售方纳税号","销售方公司","发票明细ID","货物或应税劳务、服务名称","类目编号","规格型号", "单位","数量","税前单价","税前总价","税率","税额","税后单价","税后总额","类目编号状态","税率状态","备注"], ["业务编号","类型","订单来源","购买方公司纳税号","购买方公司","发票号码","开票日期","发票类型","销售方公司纳税号","销售方公司","发票明细ID", "货物或应税劳务、服务名称","类目编号","规格型号","单位","数量","税前单价","税前总价","税率","税额","税后单价","税后总额"], ["业务编号","类型","订单来源","订单购买方纳税号","订单购买方公司名称","订单销售方纳税号","订单销售方公司名称","订单编号","订单主单号", "商品类型","商品编号","商品名称","订单单位","商品数量","商品单价","订单总金额","税目","税目名称","订单税率"] ]; $fields=[ ["invoiceCode","type",'source','seller_code','seller_name','buyer_code','buyer_name','orderCode','cxCode','goodType', 'goodNo','goodName','unit','num','goodPrice','totalPrice','cat_code','cat_name','tax','inv_fee','inv_buyer_code', 'inv_buyer_name','inv_number','inv_open_date','inv_type','inv_seller_code','inv_seller_name','inv_item_id','inv_good_name', 'inv_cat_code','inv_spec','inv_unit','inv_num','inv_subprice','inv_subtotal','inv_tax','inv_tax_total','inv_price','inv_total', 'if(cat_diff=1,"一致",if(cat_diff=2,"不一致","")) cat_diff','if(tax_diff=1,"一致",if(tax_diff=2,"不一致","")) tax_diff','remark'], ["invoiceCode","type",'source','seller_code','seller_name','inv_number','inv_open_date','inv_type','inv_seller_code','inv_seller_name', 'inv_item_id','inv_good_name','inv_cat_code','inv_spec','inv_unit','inv_num','inv_subprice','inv_subtotal','inv_tax','inv_tax_total'], [ "invoiceCode","type",'source','seller_code','seller_name','buyer_code','buyer_name','orderCode','cxCode','goodType', 'goodNo','goodName','unit','num','goodPrice','totalPrice',"cat_code","cat_name","tax"] ]; $list = $this->model ->field($fields[$headeIndex]) ->where($where) ->order("id desc") ->select()->each(function (&$item){ $item['type'] = \app\cxinv\model\FinancialManager::$ManagerType[$item['type']]??""; $item['source'] = \app\cxinv\model\FinancialManager::$ManagerSource[$item['source']]??""; $item['goodType'] = \app\cxinv\model\FinancialManager::$ManagerGoodType[$item['goodType']]??""; if(isset($item['inv_type'])) $item['inv_type'] =\app\cxinv\model\Invoice::$invoiceType[$item['inv_type']]??""; })->toArray(); exportExcel($list,$heade[$headeIndex],"manager"); } }