wugg преди 6 месеца
родител
ревизия
d6b004c407
променени са 3 файла, в които са добавени 80 реда и са изтрити 14 реда
  1. 64 13
      app/cxinv/controller/Payinv.php
  2. 0 1
      app/cxinv/model/InvoiceOrder.php
  3. 16 0
      app/cxinv/model/PayInvoice.php

+ 64 - 13
app/cxinv/controller/Payinv.php

@@ -5,7 +5,11 @@ namespace app\cxinv\controller;
 
 
 use app\cxinv\model\PayInvoice;
-use app\cxinv\model\PayReturn;use app\cxinv\model\RoleAction;use app\user\model\AccountCompany;use think\App;use think\facade\Validate;
+use app\cxinv\model\PayReturn;
+use app\cxinv\model\RoleAction;
+use app\user\model\AccountCompany;
+use think\App;
+use think\facade\Validate;
 class Payinv extends Base{
     public function __construct(App $app) {
         parent::__construct($app);
@@ -138,18 +142,6 @@ class Payinv extends Base{
         try{
             $save= $info->save();
             if ($save===false) throw new \Exception("修改失败");
-            if ($params['status']==4){
-                $invoice->check_time=date('Y-m-d H:i:s');
-                $invoice->status=4;
-                $res = $invoice->save();
-                if ($res===false) throw new \Exception("发票状态修改失败");
-            }
-            if(in_array($params['status'],[5,6,7,8,13])){
-                $invoice->status=2;
-                $res = $invoice->save();
-                if ($res===false) throw new \Exception('发票状态修改失败');
-                \app\cxinv\model\InvoiceItem::rmInvoice($param['hpNo']);
-            }
             $this->model->commit();
         }catch (\Exception $e){
             $this->model->rollback();
@@ -157,7 +149,66 @@ class Payinv extends Base{
         }
         return success("修改成功");
     }
+        /**批量上传待认证发票
+    * @param hpNo array 回票申请编号集合 必传
+    * @param relaComNo string 业务公司编号  企业账户
+    * @param companyNo string 业务公司编号 超管账户
+	* @return \think\response\Json|void
+	*/
+
+    //回票申请批量认证
+    public function hpBatchImport()
+    {
+        $post = $this->request->only(['list' => [], 'relaComNo' => '', 'companyNo' => ''], 'post');
+        $valid = Validate::rule([
+            'list|回票申请编号集合' => 'require|array|max:100',
+            'relaComNo|关联公司' => 'requireWithout:companyNo|max:255',
+            'companyNo|公司编号' => 'requireWithout:relaComNo|max:255',
+        ]);
+        if ($valid->check($post) == false) return error_show(1004, $valid->getError());
+        $companyNo = $post['relaComNo'] ?: $post['companyNo'];
+        $payArr = $this->model
+            ->alias('a')
+            ->leftJoin('invoice b', 'a.payNo=b.InvCode')
+            ->where(['a.is_del' => 0])
+            ->whereIn('a.hpNo', array_column($post['list'], 'hpNo'))
+            ->column('a.id,a.payNo,a.hpNo,a.invoiceType,a.inv_fee as invoice_fee,a.status,b.companyNo,a.remark', 'a.hpNo');
+
+        $val_hpNo = Validate::rule([
+            'hpNo|回票申请编号' => 'require',
+            'status|审核状态' => 'require|number|in:4,7',
+            'remark|审核备注' => 'requireIf:status,7|max:255'
+        ]);
+		$unique=[];
+        foreach ($post['list'] as $item) {
+            if (!$val_hpNo->check($item)) return error_show(1004, $val_hpNo->getError());
+            if(in_array($item['hpNo'],$unique))return error_show(1004, "{$item['hpNo']} 发票重复提交");
+            $unique[]=$item['hpNo'];
+        }
+        $this->model->startTrans();
+        try {
+            $saveAll=[];
+            foreach ($post['list'] as $val) {
+
+                if (!$val_hpNo->check($val)) throw new \Exception($val_hpNo->getError());
+                if (!isset($payArr[$val['hpNo']])) throw new \Exception("{$val['hpNo']}记录不存在");
 
+                $value = $payArr[$val['hpNo']];
+				$payinfo =Invoice::where(['InvCode'=>$payArr[$val['hpNo']]['payNo'],'status'=>3,'is_del'=>0])->findOrEmpty();
+				if(empty($payinfo)) throw new \Exception("{$value['hpNo']}发票信息有误");
+                if ($payinfo['companyNo'] == '') throw new \Exception("{$value['hpNo']}发票业务公司信息有误");
+                if ($payinfo['companyNo'] != $companyNo) throw new \Exception("{$value['hpNo']}不属于当前业务公司发票");
+                if ($value['status'] != '3') throw new \Exception("{$value['hpNo']}状态有误");
+                $saveAll[]=["id"=>$val['id'],"status"=>$val['status'],"remark"=>$val['status']==4?$value['remark']:$val['remark']];
+            }
+            $this->model->saveAll($saveAll);
+           $this->model->commit();
+         } catch (\Exception $e) {
+           $this->model->rollback();
+            return error_show(1004, $e->getMessage());
+        }
+        return app_show(0, '回票申请认证成功');
+    }
    public function Back(){
          $param= $this->request->param(['hpNo'=>'','reason'=>''],'post','trim');
          $valide=Validate::rule([

+ 0 - 1
app/cxinv/model/InvoiceOrder.php

@@ -76,7 +76,6 @@ class InvoiceOrder extends Base{
       $info = InvoiceOrder::where(['id'=>$id])->findOrEmpty();
       if(!$info->isEmpty())return ;
       if(in_array($info->status,[1,2])) self::orderIn($info->code,bcsub($info->total_amount,$info->balance_amount,2));
-
       if($info->status==3) self::orderOut($info->code,bcsub($info->total_amount,$info->balance_amount,2));
       if($info->status==4) self::orderCancel($info->code,bcsub($info->total_amount,$info->balance_amount,2));
     }

+ 16 - 0
app/cxinv/model/PayInvoice.php

@@ -70,7 +70,12 @@ class PayInvoice extends Base
         if ($model->invType==4){
             $change = $model->getChangedData();
             if (isset($change['status'])){
+             $invocie = Invoice::where("InvCode",$model->payNo)->findOrEmpty();
              if($change['status']==4){
+                 if (!$invocie->isEmpty()){
+                        $invocie->status=4;
+                        $invocie->save();
+                 }
                 $itemid= InvoiceItem::where(['invoiceCode'=>$model->hpNo,'status'=>[1,2]])->column('id');
                  if(!empty($itemid)){
                     $invo= InvoiceOrder::whereIn('itemId',$itemid)->where(['status'=>[1,2]])->column('code,balance_amount,total_amount');
@@ -84,6 +89,17 @@ class PayInvoice extends Base
 
              if($change['status']==9){
                   InvoiceItem::refund($model->hpNo);
+                   if (!$invocie->isEmpty()){
+                        $invocie->status=2;
+                        $invocie->save();
+                 }
+             }
+             if (in_array($change['status'],[5,6,7,8,13])){
+                  InvoiceItem::rmInvoice($model->hpNo);
+                   if (!$invocie->isEmpty()){
+                        $invocie->status=2;
+                        $invocie->save();
+                 }
              }
          }
         }