|
@@ -42,7 +42,7 @@ class Invoice extends Base{
|
|
|
if (!is_array($param['list'])) return error("请传入正确参数");
|
|
|
$valid = Validate::rule([
|
|
|
"invoice_code|发票代码"=>"require|max:255",
|
|
|
- "invoice_number|发票号码"=>"require|max:255",
|
|
|
+ "invoice_number|发票号码"=>"require|max:255|unique:app\cxinv\model\Invoice,invoice_number",
|
|
|
"invoice_type|发票类型"=>"require|in:".implode(",",array_keys(\app\cxinv\model\Invoice::$invoiceType)),
|
|
|
"invoice_total|发票税前金额"=>"float",
|
|
|
"open_date|开票日期"=>"require|date|dateFormat:Y-m-d",
|
|
@@ -51,13 +51,9 @@ class Invoice extends Base{
|
|
|
]);
|
|
|
$number= array_column($param['list'],'invoice_number');
|
|
|
if (count($number)!=count(array_unique($number))) return error("发票号码重复");
|
|
|
- $invoice = $this->model
|
|
|
- ->whereIn("invoice_number", $number)
|
|
|
- ->whereIn("status",[0,1,2,3,4])->column("invoice_number");
|
|
|
foreach ($param['list'] as $k=>$v){
|
|
|
if(!$valid->check($v)) return error($valid->getError());
|
|
|
validate_invoice_info($v,$return);
|
|
|
- if(!empty( $invoice) && in_array($v['invoice_number'],$invoice)) return error($v['invoice_number'].":发票已存在");
|
|
|
if($return['code']!=0) return error($v['invoice_number'].":".$return['message']);
|
|
|
$param['list'][$k]['InvCode']=makeNo("FP",str_pad($k,4,"0",STR_PAD_RIGHT));
|
|
|
$param['list'][$k]['apply_id']=$this->uid;
|
|
@@ -66,6 +62,7 @@ class Invoice extends Base{
|
|
|
$this->model->saveAll($param['list']);
|
|
|
return success("添加成功");
|
|
|
}
|
|
|
+ //0待验证 1待确认公司信息 2 待关联数据 3 关联中 4 关联完成;
|
|
|
public function save(){
|
|
|
$param= $this->request->param([
|
|
|
"id"=>"",
|
|
@@ -80,9 +77,9 @@ class Invoice extends Base{
|
|
|
"status"=>0,
|
|
|
"supplierNo"=>""],"post","trim");
|
|
|
$valide=Validate::rule([
|
|
|
- "id|回票编号id"=>"require|max:255",
|
|
|
+ "id|发票编号id"=>"require|max:255",
|
|
|
"invoice_code|发票代码"=>"requireIf:status,0|max:255",
|
|
|
- "invoice_number|发票号码"=>"requireIf:status,0|max:255",
|
|
|
+ "invoice_number|发票号码"=>"requireIf:status,0|max:255|unique:app\cxinv\model\Invoice,invoice_number",
|
|
|
"invoice_type|发票类型"=>"requireIf:status,0|in:".implode(",",array_keys(\app\cxinv\model\Invoice::$invoiceType)),
|
|
|
"invoice_total|发票税前金额"=>"float",
|
|
|
"open_date|开票日期"=>"requireIf:status,0|date|dateFormat:Y-m-d",
|
|
@@ -92,10 +89,10 @@ class Invoice extends Base{
|
|
|
"supplierNo|供应商公司"=>"requireIf:status,1|max:255"
|
|
|
]);
|
|
|
$invoice=$this->model->where("InvCode",$param['InvCode'])->findOrEmpty();
|
|
|
- if($invoice->isEmpty()) return error("回票编号不存在");
|
|
|
+ if($invoice->isEmpty()) return error("发票编号不存在");
|
|
|
$param['status'] = $invoice->status;
|
|
|
if(!$valide->check($param)) return error($valide->getError());
|
|
|
- if ($invoice->status>1) return error("回票已关联订单,无法修改");
|
|
|
+ if ($invoice->status>1) return error("发票当前状态无法修改");
|
|
|
if ($param['status']==0){
|
|
|
$invoice->invoice_code=$param['invoice_code'];
|
|
|
$invoice->invoice_number=$param['invoice_number'];
|
|
@@ -104,67 +101,62 @@ class Invoice extends Base{
|
|
|
$invoice->open_date=$param['open_date'];
|
|
|
$invoice->invoice_subtotal=$param['invoice_subtotal'];
|
|
|
$invoice->check_code=$param['check_code'];
|
|
|
- $bool = $this->model
|
|
|
- ->whereIn('invoice_number', $param['invoice_number'])
|
|
|
- ->whereIn('status',[0,1,2,3,4])
|
|
|
- ->where('id', '<>', $invoice->id)
|
|
|
- ->findOrEmpty();
|
|
|
- if(!$bool->isEmpty()) return error("发票号码与{$bool->InvCode}重复");
|
|
|
}
|
|
|
if($param['status']==1){
|
|
|
$invoice->companyNo=$param['companyNo'];
|
|
|
$invoice->companyName=Business::where("companyNo",$param['companyNo'])->value("company","");
|
|
|
$invoice->supplierNo=$param['supplierNo'];
|
|
|
$invoice->supplierName=Headquarters::where("code",$param['supplierNo'])->value("name","");
|
|
|
+ $invoice->status=2;
|
|
|
}
|
|
|
$invoice->save();
|
|
|
return success("保存成功");
|
|
|
}
|
|
|
- //0待验证1待关联订单2待买方公司审核3待买方公司认证4 认证完成 5 发票取消 6 买方审核驳回 7 认证失败 8 验票失败 9 退票成功
|
|
|
- public function status(){
|
|
|
- $param= $this->request->param(["InvCode"=>"","status"=>"","remark"=>"",'ItemRemark'=>[]],"post","trim");
|
|
|
- $valide=Validate::rule([
|
|
|
- "InvCode|回票编号"=>"require|max:255",
|
|
|
- "status|状态"=>"require|in:3,4,5,6,7,8"
|
|
|
- ]);
|
|
|
- if(!$valide->check($param)) return error($valide->getError());
|
|
|
- $info=$this->model->where("InvCode",$param['InvCode'])->findOrEmpty();
|
|
|
- if($info->isEmpty()) return error("回票编号不存在");
|
|
|
- if($param['status']==3) $info->check_time=date('Y-m-d H:i:s');
|
|
|
- if(in_array($info['invoice_type'],['normal','electronic','toll','roll']) && $param['status']==3){
|
|
|
- $param['status']=4; //普票无需认证
|
|
|
- }
|
|
|
- $info->status=$param['status'];
|
|
|
- $info->remark=$param['remark'];
|
|
|
- $this->model->startTrans();
|
|
|
- try{
|
|
|
- $save=$info->save();
|
|
|
- if(!$save) throw new \Exception("修改失败");
|
|
|
- if($param['status']==3){
|
|
|
- if (!empty($param['ItemRemark'])){
|
|
|
- (new InvoiceOrder)->saveAll($param['ItemRemark']);
|
|
|
- };
|
|
|
- }
|
|
|
- if(in_array($param['status'],[5,6,7])){
|
|
|
- InvoiceItem::rmInvoice($param['hpNo']);
|
|
|
- }
|
|
|
- $this->model->commit();
|
|
|
- }catch (\Exception $e){
|
|
|
- $this->model->rollback();
|
|
|
- return error($e->getMessage());
|
|
|
- }
|
|
|
- return success("修改成功");
|
|
|
- }
|
|
|
+ //0待验证 1待关联订单 2订单部分关联 3订单完全关联
|
|
|
+// public function status(){
|
|
|
+// $param= $this->request->param(["InvCode"=>"","status"=>"","remark"=>"",'ItemRemark'=>[]],"post","trim");
|
|
|
+// $valide=Validate::rule([
|
|
|
+// "InvCode|回票编号"=>"require|max:255",
|
|
|
+// "status|状态"=>"require|in:3,4,5,6,7,8"
|
|
|
+// ]);
|
|
|
+// if(!$valide->check($param)) return error($valide->getError());
|
|
|
+// $info=$this->model->where("InvCode",$param['InvCode'])->findOrEmpty();
|
|
|
+// if($info->isEmpty()) return error("回票编号不存在");
|
|
|
+// if($param['status']==3) $info->check_time=date('Y-m-d H:i:s');
|
|
|
+// if(in_array($info['invoice_type'],['normal','electronic','toll','roll']) && $param['status']==3){
|
|
|
+// $param['status']=4; //普票无需认证
|
|
|
+// }
|
|
|
+// $info->status=$param['status'];
|
|
|
+// $info->remark=$param['remark'];
|
|
|
+// $this->model->startTrans();
|
|
|
+// try{
|
|
|
+// $save=$info->save();
|
|
|
+// if(!$save) throw new \Exception("修改失败");
|
|
|
+// if($param['status']==3){
|
|
|
+// if (!empty($param['ItemRemark'])){
|
|
|
+// (new InvoiceOrder)->saveAll($param['ItemRemark']);
|
|
|
+// };
|
|
|
+// }
|
|
|
+// if(in_array($param['status'],[5,6,7])){
|
|
|
+// InvoiceItem::rmInvoice($param['hpNo']);
|
|
|
+// }
|
|
|
+// $this->model->commit();
|
|
|
+// }catch (\Exception $e){
|
|
|
+// $this->model->rollback();
|
|
|
+// return error($e->getMessage());
|
|
|
+// }
|
|
|
+// return success("修改成功");
|
|
|
+// }
|
|
|
|
|
|
public function delete(){
|
|
|
$param= $this->request->param(["InvCode"=>""],"post","trim");
|
|
|
$valide=Validate::rule([
|
|
|
- "InvCode|回票编号"=>"require|max:255"
|
|
|
+ "InvCode|发票编号"=>"require|max:255"
|
|
|
]);
|
|
|
if(!$valide->check($param)) return error($valide->getError());
|
|
|
$info=$this->model->where("InvCode",$param['InvCode'])->findOrEmpty();
|
|
|
- if($info->isEmpty()) return error("回票编号不存在");
|
|
|
- if($info->status!=3) return error("回票状态不允许删除");
|
|
|
+ if($info->isEmpty()) return error("发票编号不存在");
|
|
|
+ if(!in_array($info->status,[2,3,4])) return error("发票状态不允许删除");
|
|
|
$info->delete();
|
|
|
return success("删除成功");
|
|
|
}
|
|
@@ -172,122 +164,12 @@ class Invoice extends Base{
|
|
|
public function info(){
|
|
|
$param= $this->request->param(["InvCode"=>""],"post","trim");
|
|
|
$valide=Validate::rule([
|
|
|
- "InvCode|回票编号"=>"require|max:255"
|
|
|
+ "InvCode|发票编号"=>"require|max:255"
|
|
|
]);
|
|
|
if(!$valide->check($param)) return error($valide->getError());
|
|
|
- $info=$this->model->with(["items"])->where("InvCode",$param['InvCode'])->findOrEmpty();
|
|
|
- if($info->isEmpty()) return error("回票编号不存在");
|
|
|
+ $info=$this->model->where("InvCode",$param['InvCode'])->findOrEmpty();
|
|
|
+ if($info->isEmpty()) return error("发票编号不存在");
|
|
|
$info['ticket'] = InvoiceInfo::where("hpNo",$param['InvCode'])->findOrEmpty();
|
|
|
return success("获取成功",$info);
|
|
|
}
|
|
|
-
|
|
|
- public function Back(){
|
|
|
- $param= $this->request->param(["InvCode"=>"","reason"=>""],"post","trim");
|
|
|
- $valide=Validate::rule([
|
|
|
- "InvCode|回票编号"=>"require|max:255",
|
|
|
- "reason|备注"=>"require|max:255"
|
|
|
- ]);
|
|
|
- if(!$valide->check($param)) return error($valide->getError());
|
|
|
- $info=$this->model->where("InvCode",$param['InvCode'])->findOrEmpty();
|
|
|
- if($info->isEmpty()) return error("回票编号不存在");
|
|
|
- if ($this->level == 2) {
|
|
|
- //判断是否开通供应商账号
|
|
|
- $rebool= AccountCompany::SupplierHasAcount($info->supplierNo);
|
|
|
- if ($rebool) return error( '该供应商已经开通账号,不允许当前账号操作');
|
|
|
- }
|
|
|
- if ($info->status!=4) return error("回票信息流程未完成");
|
|
|
- $isr = PayReturn::where(['orderCode'=>$param['InvCode'],'status'=>[1,2],'is_del'=>0])->findOrEmpty();
|
|
|
- if (!$isr->isEmpty()) return error("该订单已申请退票,不允许重复申请");
|
|
|
- $returnCode =makeNo('RP');
|
|
|
- $data = [
|
|
|
- 'returnCode'=>$returnCode,
|
|
|
- 'returnType'=>3,
|
|
|
- 'payNo'=>$param['InvCode'],
|
|
|
- 'orderCode'=>$param['hpNo'],
|
|
|
- 'reason'=>$param['reason'],
|
|
|
- 'returnImg'=>'',
|
|
|
- 'remark'=>'',
|
|
|
- 'status'=>1,
|
|
|
- 'apply_id'=>$this->uid,
|
|
|
- 'apply_name'=>$this->uname,
|
|
|
- 'is_del'=>0,
|
|
|
- 'addtime'=>date('Y-m-d H:i:s'),
|
|
|
- 'updatetime'=>date('Y-m-d H:i:s'),
|
|
|
- ];
|
|
|
- $ce= PayReturn::create($data);
|
|
|
- if (!$ce) return error("申请退票创建失败");
|
|
|
- return success("申请退票创建成功");
|
|
|
- }
|
|
|
- public function BackList(){
|
|
|
- $param =$this->request->only(['relaComNo'=>'','companyNo'=>'','supplierNo'=>'','start'=>'','end'=>'','returnCode'=>'',
|
|
|
- 'status'=>'','InvCode'=>'','page'=>1,'size'=>15],'post','trim');
|
|
|
- $condition=[['a.is_del','=',0],['a.returnType','=',3]];
|
|
|
- $check = RoleAction::checkRole($this->roleid,[132,130]);
|
|
|
- if($check) $condition[]=['a.apply_id','=',$this->uid];
|
|
|
- if($param['relaComNo']!='') $condition[]=['b.companyNo|b.supplierNo','=',$param['relaComNo']];
|
|
|
- if($param['companyNo']!='') $condition[]=['b.companyNo','=',$param['companyNo']];
|
|
|
- if($param['supplierNo']!='') $condition[]=['b.supplierNo','=',$param['supplierNo']];
|
|
|
- if($param['start']!='') $condition[]=['a.addtime','>=',date('Y-m-d H:i:s',strtotime($param['start']))];
|
|
|
- if($param['end']!='') $condition[]=['a.addtime','<=',date('Y-m-d 23:59:59',strtotime($param['end']))];
|
|
|
- if($param['status']!='') $condition[]=['a.status','=',$param['status']];
|
|
|
- if($param['InvCode']!='') $condition[]=['b.InvCode','=',$param['InvCode']];
|
|
|
- if($param['returnCode']!='') $condition[]=['a.returnCode','=',$param['returnCode']];
|
|
|
- $list= PayReturn::alias('a')
|
|
|
- ->join('invoice b','a.orderCode=b.InvCode','left')
|
|
|
- ->where($condition)
|
|
|
- ->field('a.*,b.InvCode,b.supplierNo,b.supplierName,b.companyNo,b.companyName,b.invoice_total,b.invoice_subtotal,b.open_date,b.invoice_code,b.invoice_number')
|
|
|
- ->order('a.id desc')
|
|
|
- ->paginate(["list_row"=>$param['size'],"page"=>$param['page']]);
|
|
|
- foreach ($list as $k=>&$v){
|
|
|
- $v['has_account'] = AccountCompany::SupplierHasAcount($v['supplierNo']);
|
|
|
- }
|
|
|
- return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
|
|
|
- }
|
|
|
-
|
|
|
- public function BackInfo(){
|
|
|
- $param =$this->request->only(['returnCode'=>''],'post','trim');
|
|
|
- $valide=Validate::rule([
|
|
|
- 'returnCode|退票申请编号'=>'require|max:255',
|
|
|
- ]);
|
|
|
- if(!$valide->check($param))return error($valide->getError());
|
|
|
- $info= PayReturn::where(['returnCode'=>$param['returnCode'],"returnType"=>3,'is_del'=>0])->findOrEmpty();
|
|
|
- if($info->isEmpty()) return error("退票申请编号不存在");
|
|
|
- $info['invoice'] = $this->model->with(["items"])->where(["InvCode"=>$info->orderCode])->findOrEmpty();
|
|
|
- return success("获取成功",$info);
|
|
|
- }
|
|
|
-
|
|
|
- public function BackStatus(){
|
|
|
- $param =$this->request->only(['returnCode'=>'','status'=>'','remark'=>'','returnImg'=>''],'post','trim');
|
|
|
- $valide=Validate::rule([
|
|
|
- 'returnCode|退票申请编号'=>'require|max:255',
|
|
|
- 'status|状态'=>'require|number|in:1,2,3',
|
|
|
- ]);
|
|
|
- if(!$valide->check($param))return error($valide->getError());
|
|
|
- $info= PayReturn::where(['returnCode'=>$param['returnCode'],"returnType"=>3,'is_del'=>0])->findOrEmpty();
|
|
|
- if($info->isEmpty()) return error("退票申请编号不存在");
|
|
|
- $invoice = $this->model->where(['InvCode'=>$info['orderCode'],'is_del'=>0])->findOrEmpty();
|
|
|
- if($invoice->isEmpty()) return error("发票信息不存在");
|
|
|
- if($invoice->status!=4) return error("发票申请状态不允许退票");
|
|
|
- $info->status=2;
|
|
|
- $info->remark=$param['remark'];
|
|
|
- $info->returnImg=$param['returnImg'];
|
|
|
- $info->updatetime=date('Y-m-d H:i:s');
|
|
|
- $this->model->startTrans();
|
|
|
- try{
|
|
|
- $up=$info->save();
|
|
|
- if(!$up) throw new \Exception("审批失败");
|
|
|
- if($param['status']==2){
|
|
|
- $invoice->status=9;
|
|
|
- $invoice->updatetime=date('Y-m-d H:i:s');
|
|
|
- $up2=$invoice->save();
|
|
|
- if(!$up2) throw new \Exception("审批失败");
|
|
|
- }
|
|
|
- $this->model->commit();
|
|
|
- }catch (\Exception $e){
|
|
|
- $this->model->rollback();
|
|
|
- return error("审批失败");
|
|
|
- }
|
|
|
- return success('审批成功');
|
|
|
- }
|
|
|
-
|
|
|
}
|