|
@@ -4,7 +4,7 @@ declare (strict_types = 1);
|
|
namespace app\admin\controller;
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
|
|
-use app\admin\model\CgdInfo;use app\admin\model\FhdChild;use app\admin\model\GoodCombind;use app\admin\model\InvoicePay;use app\admin\model\InvoicePool;use app\admin\model\OrderCategory;use app\admin\model\Pay;use app\admin\model\PayInfo;use app\admin\model\ReportCode;
|
|
|
|
|
|
+use app\admin\model\CgdInfo;use app\admin\model\FhdChild;use app\admin\model\GoodCombind;use app\admin\model\InvoiceOrder;use app\admin\model\InvoicePay;use app\admin\model\InvoicePool;use app\admin\model\OrderCategory;use app\admin\model\Pay;use app\admin\model\PayInfo;use app\admin\model\PayInvoice;use app\admin\model\ReportCode;
|
|
use think\App;use think\Exception;
|
|
use think\App;use think\Exception;
|
|
use think\facade\Config;
|
|
use think\facade\Config;
|
|
use think\facade\Db;
|
|
use think\facade\Db;
|
|
@@ -1462,96 +1462,133 @@ class Payment extends Base
|
|
|
|
|
|
/**
|
|
/**
|
|
* 发票审核状态 //发票验证通过 才会扣减待开票金额 失败的开票申请不用处理
|
|
* 发票审核状态 //发票验证通过 才会扣减待开票金额 失败的开票申请不用处理
|
|
- * 0 发票图片识别中 1待系统验证 2 买方公司审核3带买方公司认证 4 认证成功 5验证失败 6买方审核驳回 7 认证失败 8 回票流程终止 9 验证超次数 10 回票已退
|
|
|
|
- * @return \think\response\Json|void
|
|
|
|
|
|
+ * // 1待系统验证 2 买方公司审核 3带买方公司认证 4 认证成功 5验证失败 6买方审核驳回 7 认证失败 8 回票流程终止 9 验证超次数 10 回票已退
|
|
|
|
+ * 11 待关联订单 12 订单关联完毕待财务审核 13 订单关联完毕财务驳回
|
|
|
|
+ * @return \think\response\Json|void
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
*/
|
|
public function invStatus(){
|
|
public function invStatus(){
|
|
- $post = $this->post;
|
|
|
|
- $hpNo = isset($post['hpNo'])&& $post['hpNo']!="" ? trim($post['hpNo']) :"";
|
|
|
|
- if($hpNo==""){
|
|
|
|
- return error_show(1004,"参数 hpNo 不能为空");
|
|
|
|
- }
|
|
|
|
- $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
|
|
|
|
- if($status==""){
|
|
|
|
- return error_show(1004,"参数status 不能为空");
|
|
|
|
- }
|
|
|
|
-// if(!in_array($status,[0,1,2,3,4,5,6,7,8,9,10,11,12])){
|
|
|
|
-// return error_show(1004,"参数status 无效值");
|
|
|
|
-// }
|
|
|
|
- if(!in_array($status,[0,1,2,3,4,5,6,7])){
|
|
|
|
- return error_show(1004,"参数status 无效值");
|
|
|
|
- }
|
|
|
|
- $payment= Db::name("pay_invoice")->where([['hpNo',"=",$hpNo],['is_del',"=",0]])->find();
|
|
|
|
-
|
|
|
|
- if($payment==false){
|
|
|
|
- return error_show(1005,"未找到回票申请信息");
|
|
|
|
- }
|
|
|
|
- $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
|
|
|
|
-
|
|
|
|
- if($payinfo==false){
|
|
|
|
- return error_show(1005,"未找到对账信息");
|
|
|
|
- }
|
|
|
|
- if($payinfo['status']!=2){
|
|
|
|
- return error_show(1005,"对账信息未完成审核");
|
|
|
|
- }
|
|
|
|
- $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
|
|
|
|
- if(empty($cgdNo)) return error_show(1004,"未找到对账数据信息");
|
|
|
|
- if($payinfo['inv_fee']< $payment['inv_fee'])return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
|
|
|
|
- $remark = $post['remark']??'';
|
|
|
|
|
|
+ $param = $this->request->param(["hpNo"=>"","status"=>"","remark"=>""],"post","trim");
|
|
|
|
+ $valid = Validate::rule(["hpNo|回票申请编号"=>"require|max:255","status"=>"require|number|in:1,2,3,4,6,13"]);
|
|
|
|
+ if(!$valid->check($param))$this->error($valid->getError());
|
|
|
|
+ $info = PayInvoice::where(["hpNo"=>$param['hpNo'],"is_del"=>0])->findOrEmpty();
|
|
|
|
+ if ($info->isEmpty())$this->error("未找到回票申请信息");
|
|
|
|
+ $payinfo = Pay::where(['payNo'=>$info['payNo'],"is_del"=>0])->findOrEmpty();
|
|
|
|
+ if ($payinfo->isEmpty())$this->error("未找到对账单信息");
|
|
|
|
+ if($payinfo['status']!=2)$this->error("对账信息未完成审核");
|
|
|
|
+ if($payinfo['inv_fee']< $info['inv_fee']) $this->error("回票金额不能大于对账单回票金额");
|
|
|
|
+ $invup =['remark'=>$param['remark'],'updatetime'=>date('Y-m-d H:i:s')];
|
|
|
|
+ if($param['status']==3) $invup['check_time']=date("Y-m-d H:i:s");
|
|
|
|
+ if(in_array($info['invoiceType'],['normal','electronic','toll','roll']) && $param['status']==3){
|
|
|
|
+ $param['status']=4; //普票无需认证
|
|
|
|
+ }
|
|
|
|
+ $invup['status']=$param['status'];
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
try {
|
|
try {
|
|
- Db::name('pay_invoice')->where([['hpNo','=',$hpNo],['is_del','=',0]])->lock(true)->find();
|
|
|
|
- $invup =["remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
|
- if($status==3) $invup['check_time']=date("Y-m-d H:i:s");
|
|
|
|
- if(in_array($payment['invoiceType'],['normal','electronic','toll','roll']) && $status==3){
|
|
|
|
- $status=4; //普票无需认证
|
|
|
|
- }
|
|
|
|
- $invup['status']=$status;
|
|
|
|
- $inv =Db::name("pay_invoice")->where($payment)->update($invup);
|
|
|
|
- if($inv){
|
|
|
|
- if($status==4){
|
|
|
|
- $payupdate =[
|
|
|
|
- "ainv_fee"=>$payinfo['ainv_fee']+$payment['inv_fee'],
|
|
|
|
- "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
|
|
|
|
- "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['winv_fee']==0?3:2,
|
|
|
|
- "updatetime" => date("Y-m-d H:i:s")
|
|
|
|
- ];
|
|
|
|
- $pay =Db::name("pay")->where($payinfo)->update($payupdate);
|
|
|
|
- if($pay==false){
|
|
|
|
- Db::rollback();
|
|
|
|
- return error_show(1003,"回票申请状态更新失败");
|
|
|
|
- }
|
|
|
|
|
|
+ $save=$info->save($invup);
|
|
|
|
+ if($save){
|
|
|
|
+ if($param['status']==4){
|
|
|
|
+ Pay::addAinv($param['hpNo'],$info->inv_fee);
|
|
}
|
|
}
|
|
- if($status==6 || $status==5|| $status==7){
|
|
|
|
- $payupdate =[
|
|
|
|
- "winv_fee"=>$payinfo['winv_fee']+$payment['inv_fee'],
|
|
|
|
- "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
|
|
|
|
- "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['ainv_fee']==0?1:2,
|
|
|
|
- "updatetime" => date("Y-m-d H:i:s")
|
|
|
|
- ];
|
|
|
|
- $pay =Db::name("pay")->where($payinfo)->update($payupdate);
|
|
|
|
- if($pay==false){
|
|
|
|
- Db::rollback();
|
|
|
|
- return error_show(1003,"回票申请状态更新失败");
|
|
|
|
- }
|
|
|
|
- foreach ($cgdNo as $value){
|
|
|
|
- $report=ReportCode::where(["cgdNo"=>$value])->find();
|
|
|
|
- if($report)$report->rmField("hpNo",$hpNo);
|
|
|
|
- }
|
|
|
|
|
|
+ if(in_array($param['status'],[5,6,7])){
|
|
|
|
+ Pay::subInv($param['hpNo'],$info->inv_fee);
|
|
|
|
+ event("reportCode",["param"=>["key"=>"hpNo","value"=>$param['hpNo']],"type"=>"sub"]);
|
|
}
|
|
}
|
|
- Db::commit();
|
|
|
|
- return app_show(0,"回票申请更新成功");
|
|
|
|
- }throw new \Exception("回票申请状态更新失败");
|
|
|
|
|
|
+ }else throw new \Exception("回票审核失败");
|
|
|
|
+ Db::commit();
|
|
|
|
+
|
|
}catch (\Exception $e){
|
|
}catch (\Exception $e){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
- return error_show(1004,$e->getMessage());
|
|
|
|
|
|
+ $this->error($e->getMessage());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ $this->success("回票审核成功");
|
|
}
|
|
}
|
|
|
|
+// public function invStatus(){
|
|
|
|
+// $post = $this->post;
|
|
|
|
+// $hpNo = isset($post['hpNo'])&& $post['hpNo']!="" ? trim($post['hpNo']) :"";
|
|
|
|
+// if($hpNo==""){
|
|
|
|
+// return error_show(1004,"参数 hpNo 不能为空");
|
|
|
|
+// }
|
|
|
|
+// $status = isset($post['status'])&& $post['status']!="" ? intval($post['status']) :"";
|
|
|
|
+// if($status==""){
|
|
|
|
+// return error_show(1004,"参数status 不能为空");
|
|
|
|
+// }
|
|
|
|
+//// if(!in_array($status,[0,1,2,3,4,5,6,7,8,9,10,11,12])){
|
|
|
|
+//// return error_show(1004,"参数status 无效值");
|
|
|
|
+//// }
|
|
|
|
+// if(!in_array($status,[0,1,2,3,4,5,6,7])){
|
|
|
|
+// return error_show(1004,"参数status 无效值");
|
|
|
|
+// }
|
|
|
|
+// $payment= Db::name("pay_invoice")->where([['hpNo',"=",$hpNo],['is_del',"=",0]])->find();
|
|
|
|
+//
|
|
|
|
+// if($payment==false){
|
|
|
|
+// return error_show(1005,"未找到回票申请信息");
|
|
|
|
+// }
|
|
|
|
+// $payinfo= Db::name("pay")->where([['payNo',"=",$payment['payNo']],['is_del',"=",0]])->find();
|
|
|
|
+//
|
|
|
|
+// if($payinfo==false){
|
|
|
|
+// return error_show(1005,"未找到对账信息");
|
|
|
|
+// }
|
|
|
|
+// if($payinfo['status']!=2){
|
|
|
|
+// return error_show(1005,"对账信息未完成审核");
|
|
|
|
+// }
|
|
|
|
+// $cgdNo =Db::name("pay_info")->where(["payNo"=>$payment['payNo'],"is_del"=>0])->column("cgdNo");
|
|
|
|
+// if(empty($cgdNo)) return error_show(1004,"未找到对账数据信息");
|
|
|
|
+// if($payinfo['inv_fee']< $payment['inv_fee'])return error_show(1005,"对账回票申请金额有误,请确认回票申请金额");
|
|
|
|
+// $remark = $post['remark']??'';
|
|
|
|
+// Db::startTrans();
|
|
|
|
+// try {
|
|
|
|
+// Db::name('pay_invoice')->where([['hpNo','=',$hpNo],['is_del','=',0]])->lock(true)->find();
|
|
|
|
+// $invup =["remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
|
+// if($status==3) $invup['check_time']=date("Y-m-d H:i:s");
|
|
|
|
+// if(in_array($payment['invoiceType'],['normal','electronic','toll','roll']) && $status==3){
|
|
|
|
+// $status=4; //普票无需认证
|
|
|
|
+// }
|
|
|
|
+// $invup['status']=$status;
|
|
|
|
+// $inv =Db::name("pay_invoice")->where($payment)->update($invup);
|
|
|
|
+// if($inv){
|
|
|
|
+// if($status==4){
|
|
|
|
+// $payupdate =[
|
|
|
|
+// "ainv_fee"=>$payinfo['ainv_fee']+$payment['inv_fee'],
|
|
|
|
+// "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
|
|
|
|
+// "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['winv_fee']==0?3:2,
|
|
|
|
+// "updatetime" => date("Y-m-d H:i:s")
|
|
|
|
+// ];
|
|
|
|
+// $pay =Db::name("pay")->where($payinfo)->update($payupdate);
|
|
|
|
+// if($pay==false){
|
|
|
|
+// Db::rollback();
|
|
|
|
+// return error_show(1003,"回票申请状态更新失败");
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// if($status==6 || $status==5|| $status==7){
|
|
|
|
+// $payupdate =[
|
|
|
|
+// "winv_fee"=>$payinfo['winv_fee']+$payment['inv_fee'],
|
|
|
|
+// "inv_fee"=>$payinfo['inv_fee']-$payment['inv_fee'],
|
|
|
|
+// "inv_status" => ($payinfo['inv_fee']-$payment['inv_fee'])==0 && $payinfo['ainv_fee']==0?1:2,
|
|
|
|
+// "updatetime" => date("Y-m-d H:i:s")
|
|
|
|
+// ];
|
|
|
|
+// $pay =Db::name("pay")->where($payinfo)->update($payupdate);
|
|
|
|
+// if($pay==false){
|
|
|
|
+// Db::rollback();
|
|
|
|
+// return error_show(1003,"回票申请状态更新失败");
|
|
|
|
+// }
|
|
|
|
+// foreach ($cgdNo as $value){
|
|
|
|
+// $report=ReportCode::where(["cgdNo"=>$value])->find();
|
|
|
|
+// if($report)$report->rmField("hpNo",$hpNo);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// Db::commit();
|
|
|
|
+// return app_show(0,"回票申请更新成功");
|
|
|
|
+// }throw new \Exception("回票申请状态更新失败");
|
|
|
|
+// }catch (\Exception $e){
|
|
|
|
+// Db::rollback();
|
|
|
|
+// return error_show(1004,$e->getMessage());
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1978,24 +2015,6 @@ class Payment extends Base
|
|
if(empty($returninfo))return error_show(1004,"退票详情未找到");
|
|
if(empty($returninfo))return error_show(1004,"退票详情未找到");
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
try{
|
|
try{
|
|
- if($param['status']==2){
|
|
|
|
- $invinfo =Db::name("pay_invoice")->where(["hpNo"=>$returninfo['orderCode'],"is_del"=>0])->findOrEmpty();
|
|
|
|
- if(empty($invinfo))throw new Exception("回票详情未找到");
|
|
|
|
- $pay =Db::name("pay")->where(["payNo"=>$returninfo['payNo'],"is_del"=>0])->findOrEmpty();
|
|
|
|
- if(empty($pay))throw new Exception("对账详情未找到");
|
|
|
|
- $invup =Db::name("pay_invoice")->where($invinfo)->update(["status"=>10,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
|
- if($invup==false)throw new Exception("回票更新失败");
|
|
|
|
-
|
|
|
|
- $paydata=[
|
|
|
|
- "ainv_fee"=>$pay['ainv_fee']-$invinfo['inv_fee'],
|
|
|
|
- "winv_fee"=>$pay['winv_fee']+$invinfo['inv_fee'],
|
|
|
|
- "inv_status" => $pay['inv_fee']==0 &&($pay['ainv_fee']-$invinfo['inv_fee'])==0?1:2,
|
|
|
|
- "updatetime" => date("Y-m-d H:i:s")
|
|
|
|
- ];
|
|
|
|
- $oayup =Db::name("pay")->where($pay)->update($paydata);
|
|
|
|
- if($oayup==false)throw new Exception("对账更新失败");
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
$update=[
|
|
$update=[
|
|
"status"=>$param['status'],
|
|
"status"=>$param['status'],
|
|
"remark"=>$param['remark'],
|
|
"remark"=>$param['remark'],
|
|
@@ -2004,12 +2023,22 @@ class Payment extends Base
|
|
];
|
|
];
|
|
$up =Db::name("pay_return")->where($returninfo)->update($update);
|
|
$up =Db::name("pay_return")->where($returninfo)->update($update);
|
|
if($up==false)throw new Exception("退票申请审核失败");
|
|
if($up==false)throw new Exception("退票申请审核失败");
|
|
|
|
+ if($param['status']==2){
|
|
|
|
+ $invinfo =Db::name('pay_invoice')->where(['hpNo'=>$returninfo['orderCode'],'is_del'=>0])->findOrEmpty();
|
|
|
|
+ if(empty($invinfo))throw new Exception('回票详情未找到');
|
|
|
|
+ $pay =Db::name('pay')->where(['payNo'=>$returninfo['payNo'],'is_del'=>0])->findOrEmpty();
|
|
|
|
+ if(empty($pay))throw new Exception('对账详情未找到');
|
|
|
|
+ $invup =Db::name('pay_invoice')->where($invinfo)->update(['status'=>10,'updatetime'=>date('Y-m-d H:i:s')]);
|
|
|
|
+ if($invup==false)throw new Exception('回票更新失败');
|
|
|
|
+ Pay::subAinv($returninfo['payNo'],$invinfo['inv_fee']);
|
|
|
|
+ \app\admin\model\InvoiceItem::rmInvoice($returninfo['orderCode'],2);
|
|
|
|
+ }
|
|
Db::commit();
|
|
Db::commit();
|
|
- return app_show(0,"退票申请审核成功");
|
|
|
|
}catch (\Exception $e){
|
|
}catch (\Exception $e){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
return error_show(1005,$e->getMessage());
|
|
return error_show(1005,$e->getMessage());
|
|
}
|
|
}
|
|
|
|
+ $this->success("退票申请审核成功");
|
|
}
|
|
}
|
|
|
|
|
|
public function hpinvReturnInfo(){
|
|
public function hpinvReturnInfo(){
|
|
@@ -2295,7 +2324,7 @@ class Payment extends Base
|
|
->where(["a.payNo"=>$param['payNo'],"a.status"=>1,"a.is_del"=>0])
|
|
->where(["a.payNo"=>$param['payNo'],"a.status"=>1,"a.is_del"=>0])
|
|
->field("a.payNo'对账单号',b.sequenceNo '采购单编号',b.qrdCode '销售单编号',b.supplierName '供货商',b.companyName '业务公司',
|
|
->field("a.payNo'对账单号',b.sequenceNo '采购单编号',b.qrdCode '销售单编号',b.supplierName '供货商',b.companyName '业务公司',
|
|
b.goodUnit '单位',(b.goodNum-b.thNum) '商品数量',b.goodPrice'商品单价',b.totalPrice'总货款',
|
|
b.goodUnit '单位',(b.goodNum-b.thNum) '商品数量',b.goodPrice'商品单价',b.totalPrice'总货款',
|
|
- if(b.cxCode='',b.qrdCode,b.cxCode) 销售主单号,c.spuCode 商品编码,d.good_name 商品名称,c.cat_name 货物和劳务名称,c.merge_code 商品开票类目,c.short_name 商品和服务分类简称,
|
|
|
|
|
|
+ if(b.cxCode='',b.qrdCode,b.cxCode) 销售主单号,b.goodNo 商品编码,b.goodName 商品名称,c.cat_name 货物和劳务名称,c.merge_code 商品开票类目,c.short_name 商品和服务分类简称,
|
|
c.tax/100 开票税率,c.inv_good_name 开票商品名称,if(b.open_type =1,'原商品开票',if(b.open_type =2,'子商品开票','')) 开票类型")
|
|
c.tax/100 开票税率,c.inv_good_name 开票商品名称,if(b.open_type =1,'原商品开票',if(b.open_type =2,'子商品开票','')) 开票类型")
|
|
->select()
|
|
->select()
|
|
->toArray();
|
|
->toArray();
|