|
@@ -5,21 +5,23 @@ namespace app\admin\controller;
|
|
|
use app\admin\BaseController;
|
|
|
use app\admin\model\ReportCode;
|
|
|
use think\App;
|
|
|
-use think\Exception;use think\facade\Config;
|
|
|
+use think\Exception;
|
|
|
+use think\facade\Config;
|
|
|
use think\facade\Db;
|
|
|
use think\facade\Cache;
|
|
|
|
|
|
class OrderInv extends BaseController{
|
|
|
- private $typename=[
|
|
|
- "004"=>"增值税专用发票",
|
|
|
- '007'=>"增值税普通发票",
|
|
|
- '026'=>'增值税电子普通发票',
|
|
|
- '028'=>'增值税电子专用发票',
|
|
|
- '021'=>"全电专用发票",
|
|
|
- '022'=>"全电普通发票"
|
|
|
- ];
|
|
|
+ protected $typename;
|
|
|
+ protected $invoiceType;
|
|
|
+ protected $invName;
|
|
|
+ protected $kingInvoice;
|
|
|
public function __construct(App $app) {
|
|
|
parent::__construct($app);
|
|
|
+ $invoice =Config::get("invoiceType");
|
|
|
+ $this->invoiceType = $invoice['invoiceName'];
|
|
|
+ $this->invName = $invoice['invoiceType'];
|
|
|
+ $this->typename = $invoice['KingName'];
|
|
|
+ $this->kingInvoice = $invoice['KingInvoice'];
|
|
|
}
|
|
|
/**
|
|
|
* 新建销售单开票申请
|
|
@@ -60,12 +62,13 @@ class OrderInv extends BaseController{
|
|
|
// if($customer==false){
|
|
|
// return error_show(1004,"客户信息未找到");
|
|
|
// }
|
|
|
- $invtype = isset($this->post['invtype'])&&$this->post['invtype']!=='' ? intval($this->post['invtype']):"";
|
|
|
+ $invtype = isset($this->post['invtype'])&&$this->post['invtype']!=='' ? trim($this->post['invtype']):"";
|
|
|
if($invtype==''){
|
|
|
return error_show(1004,"参数 invtype 不能为空");
|
|
|
}
|
|
|
- $email = isset($this->post['email'])&&$this->post['email']!=='' ? trim($this->post['email']):"";
|
|
|
+ if(!in_array($invtype,$this->invName)) return error_show(1004,"发票类型有误");
|
|
|
|
|
|
+ $email = isset($this->post['email'])&&$this->post['email']!=='' ? trim($this->post['email']):"";
|
|
|
$remark = isset($this->post['remark'])&&$this->post['remark']!=='' ? trim($this->post['remark']):"";
|
|
|
$exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!=='' ? trim($this->post['exam_remark']):"";
|
|
|
$orderArr = isset($this->post['orderArr'])&&!empty($this->post['orderArr']) ? $this->post['orderArr']:[];
|
|
@@ -280,19 +283,20 @@ class OrderInv extends BaseController{
|
|
|
if($invCode==='') return error_show(1004,"参数 invCode 不能为空");
|
|
|
if($invNum==='') return error_show(1004,"参数 invNum 不能为空");
|
|
|
if($open_date==='') return error_show(1004,"参数 open_date 不能为空");
|
|
|
- if($invinfo['inv_type']==2 || $invinfo['inv_type']==3){
|
|
|
+ if(in_array($invinfo['inv_type'],['normal','roll',"toll",'electronic'])){
|
|
|
if($checkCode==='') return error_show(1004,"参数 checkCode 不能为空");
|
|
|
}
|
|
|
if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
|
|
|
+ //全电子发票 信息需要全填补充切无法接口识别验真
|
|
|
+ if(in_array($invinfo['inv_type'],['fully_digitalized_special_electronic','fully_digitalized_normal_electronic'])){
|
|
|
+ if($invNum==='') return error_show(1004,"参数 invNum 不能为空");
|
|
|
+ if($open_date==='') return error_show(1004,"参数 open_date 不能为空");
|
|
|
+ if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
|
|
|
+ if($total_fee=='') return error_show(1004,"参数 total_fee 不能为空");
|
|
|
+ $status=3;
|
|
|
+ }
|
|
|
}
|
|
|
- //全电子发票 信息需要全填补充切无法接口识别验真
|
|
|
- if($invinfo['inv_type']==5){
|
|
|
- if($invNum==='') return error_show(1004,"参数 invNum 不能为空");
|
|
|
- if($open_date==='') return error_show(1004,"参数 open_date 不能为空");
|
|
|
- if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
|
|
|
- if($total_fee=='') return error_show(1004,"参数 total_fee 不能为空");
|
|
|
- $status=3;
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
if($status==7){
|
|
@@ -304,10 +308,10 @@ class OrderInv extends BaseController{
|
|
|
|
|
|
$invup =Db::name("invoice_pool")->where($invinfo)->update($update);
|
|
|
if($invup){
|
|
|
- if(($status==2&& $open_type!=1) || ($invinfo['inv_type']==5 &&$status==3 )){
|
|
|
+ if(($status==2&& $open_type!=1) || ($invinfo['inv_type']==5 &&$status==2)){
|
|
|
$invpool=[
|
|
|
"invNo"=>$invinfo['invNo'],
|
|
|
- "inv_type"=>invoiceType($invinfo['inv_type']),
|
|
|
+ "inv_type"=>$this->kingInvoice[$invinfo['inv_type']],
|
|
|
"inv_code"=>$invCode,
|
|
|
"inv_number"=>$invNum,
|
|
|
"check_code"=>$checkCode,
|
|
@@ -398,7 +402,7 @@ class OrderInv extends BaseController{
|
|
|
"HJSE"=>"0",
|
|
|
"BZ"=>$invinfo['remark'],
|
|
|
"DDMXXX"=>$goodinfo,
|
|
|
- "FPLXDM"=>invoiceType($invinfo['inv_type']),
|
|
|
+ "FPLXDM"=>$this->kingInvoice[$invinfo['inv_type']],
|
|
|
"DDQQPCH"=>"",
|
|
|
"DDQQLSH"=>randomkeys(26).date("YmdHis"),
|
|
|
"status"=>"0",
|
|
@@ -586,7 +590,7 @@ class OrderInv extends BaseController{
|
|
|
try{
|
|
|
$invoice=Config::get("invoice");
|
|
|
$tax =new \TaxInvoice($invoice['appKey'],$invoice['appSecret'],$invoice['entCode']);
|
|
|
- $result=$tax->DeprecateInvoices($company['company_license'],invoiceType($invoiceinfo['inv_type']),$invoiceinfo['inv_code'],$invoiceinfo['inv_number'],1);
|
|
|
+ $result=$tax->DeprecateInvoices($company['company_license'],$this->kingInvoice[$invoiceinfo['inv_type']],$invoiceinfo['inv_code'],$invoiceinfo['inv_number'],1);
|
|
|
if(isset($result['ZTDM']) && $result['ZTDM']=='050000'){
|
|
|
$up =Db::name("invoice_pool")->where($invinfo)->update(["status"=>6,"updatetime"=>date("Y-m-d H:i:s")]);
|
|
|
if($up){
|
|
@@ -762,9 +766,9 @@ class OrderInv extends BaseController{
|
|
|
if($invCode==='') return error_show(1004,"参数 invCode 不能为空");
|
|
|
if($invNum==='') return error_show(1004,"参数 invNum 不能为空");
|
|
|
if($open_date==='') return error_show(1004,"参数 open_date 不能为空");
|
|
|
- if($invinfo['inv_type']==2 || $invinfo['inv_type']==3){
|
|
|
- if($checkCode==='') return error_show(1004,"参数 checkCode 不能为空");
|
|
|
- }
|
|
|
+ if(in_array($invinfo['inv_type'],['normal','roll',"toll",'electronic'])){
|
|
|
+ if($checkCode==='') return error_show(1004,"参数 checkCode 不能为空");
|
|
|
+ }
|
|
|
if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
|
|
|
}
|
|
|
}
|
|
@@ -810,7 +814,7 @@ class OrderInv extends BaseController{
|
|
|
"addtime"=>date("Y-m-d H:i:s"),
|
|
|
"updatetime"=>date("Y-m-d H:i:s")
|
|
|
];
|
|
|
- $in = Db::name("invoice_ticket")->insert($invpool);
|
|
|
+ $in = Db::name("invoice_ticket")->insert($invpool);
|
|
|
if($in==false){
|
|
|
Db::rollback();
|
|
|
return error_show(1004,"发票信息添加失败");
|
|
@@ -850,12 +854,6 @@ class OrderInv extends BaseController{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-// $up=Db::name("invoice_pool")->where($invinfo)->update(["status"=>6,"updatetime"=>date("Y-m-d
|
|
|
-// H:i:s")]);
|
|
|
-// if($up==false){
|
|
|
-// Db::rollback();
|
|
|
-// return error_show(1003,"发票信息更新失败");
|
|
|
-// }
|
|
|
}
|
|
|
if($status==3 || $status==4){
|
|
|
foreach ($qrd as $value){
|
|
@@ -1016,7 +1014,7 @@ class OrderInv extends BaseController{
|
|
|
if($status!==""){
|
|
|
$condition[]=["a.status","=",$status];
|
|
|
}
|
|
|
- $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
|
|
|
+ $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? trim($this->post['inv_type']):"";
|
|
|
if($inv_type!==""){
|
|
|
$condition[]=["a.inv_type","=",$inv_type];
|
|
|
}
|
|
@@ -1135,7 +1133,7 @@ class OrderInv extends BaseController{
|
|
|
if($end!=""){
|
|
|
$condition[]=["a.addtime","<=",$end." 23:59:59"];
|
|
|
}
|
|
|
- $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
|
|
|
+ $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? trim($this->post['inv_type']):"";
|
|
|
if($inv_type!==""){
|
|
|
$condition[]=["b.inv_type","=",$inv_type];
|
|
|
}
|
|
@@ -1195,7 +1193,7 @@ class OrderInv extends BaseController{
|
|
|
$redticketArry=[
|
|
|
"SQBSCQQPCH"=>randomkeys(26).date("YmdHis"),
|
|
|
"NSRSBH"=>$company['company_license'],
|
|
|
- "FPLXDM"=>invoiceType($invfo['inv_type']),
|
|
|
+ "FPLXDM"=>$this->kingInvoice[$invfo['inv_type']],
|
|
|
];
|
|
|
$goodinfo =Db::name("invoice_good")
|
|
|
->where(["invNo"=>$invNo,"is_del"=>0])
|
|
@@ -1284,7 +1282,7 @@ class OrderInv extends BaseController{
|
|
|
"XXBTSBS"=>"0",
|
|
|
"DDMXXX"=>json_encode($qdmx,JSON_UNESCAPED_UNICODE),
|
|
|
"SQBSCQQPCH"=>$redticketArry['SQBSCQQPCH'],
|
|
|
- "FPLXDM"=>invoiceType($invfo['inv_type']),
|
|
|
+ "FPLXDM"=>$this->kingInvoice[$invfo['inv_type']],
|
|
|
];
|
|
|
$redticketList[]=["HZSQDTXX"=>$info,"DDMXXX"=>$qdmx];
|
|
|
$result=$Tax->AllocateRedInvoiceApplication($redticketArry,$redticketList);
|
|
@@ -1340,7 +1338,7 @@ class OrderInv extends BaseController{
|
|
|
$redticketArry=[
|
|
|
"SQBSCQQPCH"=>randomkeys(26).date("YmdHis"),
|
|
|
"NSRSBH"=>$company['company_license'],
|
|
|
- "FPLXDM"=>invoiceType($inv_type[0]),
|
|
|
+ "FPLXDM"=>$this->kingInvoice[$inv_type[0]],
|
|
|
];
|
|
|
$redticketList=[];
|
|
|
foreach ($invfo as $value){
|
|
@@ -1437,7 +1435,7 @@ class OrderInv extends BaseController{
|
|
|
"XXBTSBS"=>"0",
|
|
|
"DDMXXX"=>json_encode($qdmx,JSON_UNESCAPED_UNICODE),
|
|
|
"SQBSCQQPCH"=>$redticketArry['SQBSCQQPCH'],
|
|
|
- "FPLXDM"=>invoiceType($value['inv_type']),
|
|
|
+ "FPLXDM"=>$this->kingInvoice[$value['inv_type']],
|
|
|
];
|
|
|
$insertAll[$info['SQBSCQQLSH']]=$data;
|
|
|
}
|
|
@@ -1924,9 +1922,9 @@ class OrderInv extends BaseController{
|
|
|
if($end!=""){
|
|
|
$condition[]=["a.addtime","<=",$end." 23:59:59"];
|
|
|
}
|
|
|
- $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
|
|
|
+ $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? trim($this->post['inv_type']):"";
|
|
|
if($inv_type!==""){
|
|
|
- $condition[]=["b.inv_type","=",$inv_type];
|
|
|
+ $condition[]=["c.inv_type","=",$inv_type];
|
|
|
}
|
|
|
$companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=="" ? trim($this->post['companyNo']):"";
|
|
|
if($companyNo!==""){
|
|
@@ -1995,9 +1993,8 @@ class OrderInv extends BaseController{
|
|
|
->page($page,intval($post['size']))
|
|
|
->order("a.id desc")
|
|
|
->select()->toArray();
|
|
|
- $typename=["004"=>"增值税专用发票",'007'=>"增值税普通发票",'026'=>'增值税电子普通发票','028'=>'增值税电子专用发票'];
|
|
|
foreach ($list as &$value){
|
|
|
- $value['invtype_name'] = $typename[$value['inv_type']]??"";
|
|
|
+ $value['invtype_name'] = $this->typename[$value['inv_type']]??"";
|
|
|
}
|
|
|
return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
|
|
|
}
|
|
@@ -2056,25 +2053,7 @@ class OrderInv extends BaseController{
|
|
|
$temp['num'] =$good['goodNum'];
|
|
|
$temp['price'] =$good['goodPrice'];
|
|
|
$temp['total_fee'] =$good['totalPrice'];
|
|
|
- switch ($value['inv_type']){
|
|
|
- case 1:
|
|
|
- $temp['inv_type'] = "增值税专用发票";
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- $temp['inv_type'] = "增值税普通发票";
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- $temp['inv_type'] = "增值税电子专用发票";
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- $temp['inv_type'] = "增值税电子普通发票";
|
|
|
- break;
|
|
|
- default:
|
|
|
- $temp['inv_type'] = "-";
|
|
|
- break;
|
|
|
- }
|
|
|
- // $temp['inv_type'] = $value['inv_type']==1?"增值税专用发票": "增值税普通发票";
|
|
|
- // $temp['inv_value'] =$value['inv_value'];
|
|
|
+ $temp['inv_type']=$this->invoiceType[$value['inv_type']]?? "-";
|
|
|
$temp['remark'] =$value['remark'];
|
|
|
$temp['kp_companyName'] = $invinfo['seller_title']??"";
|
|
|
$temp['kp_company_address'] = $invinfo['seller_addr']??"";
|
|
@@ -2137,14 +2116,14 @@ class OrderInv extends BaseController{
|
|
|
if($value["inv_type"]===""){
|
|
|
return error_show(1005,"第".($key+1)."行缺少发票类型数据");
|
|
|
}
|
|
|
- $invtype=array_search($value['inv_type'],$this->typename)??"";
|
|
|
- if($value["inv_code"]=="" && $value['inv_type']!=="000"){
|
|
|
+ if(!in_array($value['inv_type'],$this->invName)) return error_show(1005,"第".($key+1)."行发票类型数据有误");
|
|
|
+ if($value["inv_code"]=="" && !in_array($value['inv_type'],[ "fully_digitalized_special_electronic", "fully_digitalized_normal_electronic"])){
|
|
|
return error_show(1005,"第".($key+1)."行缺少发票代码数据");
|
|
|
}
|
|
|
if($value["inv_number"]==""){
|
|
|
return error_show(1005,"第".($key+1)."行缺少发票号码数据");
|
|
|
}
|
|
|
- if($value["inv_total"]==""&& in_array($invtype,["021","022"])){
|
|
|
+ if($value["inv_total"]==""&& in_array($value['inv_type'],["fully_digitalized_special_electronic", "fully_digitalized_normal_electronic"])){
|
|
|
return error_show(1005,"第".($key+1)."行缺少发票金额数据");
|
|
|
}
|
|
|
if($value["inv_subtotal"]==""){
|
|
@@ -2154,7 +2133,7 @@ class OrderInv extends BaseController{
|
|
|
return error_show(1005,"第".($key+1)."行缺少发票开票日期数据");
|
|
|
}
|
|
|
//电子票校验码必传
|
|
|
- if($value["check_code"]=="" && in_array($invtype,["026","028"])){
|
|
|
+ if($value["check_code"]=="" && in_array($value['inv_type'],['normal','roll',"toll",'electronic'])){
|
|
|
return error_show(1005,"第".($key+1)."行缺少发票校验码数据");
|
|
|
}
|
|
|
// if($value['inv_type']==="000"){
|
|
@@ -2177,7 +2156,7 @@ class OrderInv extends BaseController{
|
|
|
$temp=[];
|
|
|
$temp['invNo'] = $value["invNo"];
|
|
|
$temp['type'] = 0;
|
|
|
- $temp['inv_type'] =$invtype ;
|
|
|
+ $temp['inv_type'] =$value['inv_type'];
|
|
|
$temp['inv_code'] = $value['inv_code'];
|
|
|
$temp['inv_number'] = $value['inv_number'];
|
|
|
$temp['inv_subtotal'] = $value['inv_subtotal'];
|
|
@@ -2209,17 +2188,16 @@ class OrderInv extends BaseController{
|
|
|
Db::startTrans();
|
|
|
try{
|
|
|
$keyarr =array_keys($total);
|
|
|
- $invTArr =array_keys($this->typename);
|
|
|
$inpool = Db::name("invoice_pool")->where([["invNo","in",$keyarr],["open_type","in",[0,2,3]],["is_del","=",0],["status","=",0]])->column("winv_fee,invNo,inv_value,inv_type","invNo");
|
|
|
|
|
|
foreach ($total as $key=>$val){
|
|
|
if(!isset($inpool[$key])) continue;
|
|
|
- if(in_array($val['inv_type'],["021","022"]) && $inpool[$key]['winv_fee']!=$val['total']){
|
|
|
+ if(in_array($val['inv_type'],["fully_digitalized_special_electronic", "fully_digitalized_normal_electronic"]) && $inpool[$key]['winv_fee']!=$val['total']){
|
|
|
throw new Exception("{$key}全电发票面金额小于未开票金额");
|
|
|
}
|
|
|
- if($invTArr[$inpool[$key]['inv_type']]!= $val['inv_type'] ) throw new Exception("{$key}发票类型有误");
|
|
|
+ if($inpool[$key]['inv_type']!= $val['inv_type']) throw new Exception("{$key}发票类型有误");
|
|
|
$update=[
|
|
|
- "status"=>in_array($val['inv_type'],["021","022"])?3:2,
|
|
|
+ "status"=>in_array($val['inv_type'],["fully_digitalized_special_electronic", "fully_digitalized_normal_electronic"])?3:2,
|
|
|
"open_type"=>$inpool[$key]['open_type']??3,
|
|
|
"updatetime"=>date("Y-m-d H:i:s")
|
|
|
];
|
|
@@ -2262,9 +2240,11 @@ class OrderInv extends BaseController{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ $val['inv_type'] = $this->kingInvoice[$val['inv_type']];
|
|
|
+ $list[]=$val;
|
|
|
+ }
|
|
|
}
|
|
|
- $inticket =Db::name("invoice_ticket")->insertAll($list);
|
|
|
+ $inticket =Db::name("invoice_ticket")->insertAll($list);
|
|
|
if(!$inticket){
|
|
|
Db::rollback();
|
|
|
return error_show(1005,"发票数据录入失败");
|