xieruidong 2 年之前
父節點
當前提交
666d1f6487

+ 24 - 1
application/api/controller/UserTax.php

@@ -3,13 +3,16 @@
 namespace app\api\controller;
 use app\api\controller\mall\Orders;
 use app\common\controller\Api;
+use app\common\validate\TaxValidate;
+use Yansongda\Supports\Arr;
+
 /**
  * 发票接口
  */
 class UserTax extends Api
 {
     protected $noNeedRight='*';
-
+    use TaxValidate;
     /**
      * 发票列表
      * @ApiParams (name=page,description=分页)
@@ -20,6 +23,7 @@ class UserTax extends Api
         $user=$this->auth->getUser();
         $tax=$user->tax()
             ->with(['orders','orders.info'])
+            ->order('is_default','desc')
             ->order('id','desc')
             ->paginate(input('limit',15));
 
@@ -45,4 +49,23 @@ class UserTax extends Api
         $newList['total']=$tax->total();
         $this->success('',$newList);
     }
+    /**
+     * 创建发票
+     * @ApiMethod (POST)
+     * @ApiParams (name=id,description=如果要修改传ID)
+     * @ApiParams (name=tax,description="发票对象,见注释")
+     * @ApiParams (name=is_default,description="是1否0默认")
+     */
+    public function store(){
+        $data=$this->request->post();
+        $this->validateTaxBody($data);
+        $user=$this->auth->getUser();
+        $needData=Arr::only($data,['tax','is_default']);
+        if(!empty($data['id'])){
+            $tax=$user->tax()->findOrFail($data['id']);
+            $tax->save($needData);
+        }
+        $user->tax()->save($needData);
+        $this->success();
+    }
 }

+ 1 - 0
application/api/controller/object/Index.php

@@ -148,6 +148,7 @@ class Index extends Api
      * @ApiParams (name=tax.reg_phone,description="注册电话")
      * @ApiParams (name=info,description=商品信息同订单详情的info)
      * @ApiParams (name=tax_link,description=发票链接)
+     * @ApiParams (name=is_default,description=是否默认)
      */
     public function tax(){}
     /**

+ 25 - 22
application/common/validate/TaxValidate.php

@@ -14,32 +14,35 @@ trait TaxValidate
             'tax|发票信息'=>['requireIf:is_tax,1'],
         ]);
         if($data['is_tax']==1){
-            $this->validate($data,[
-                'tax.paper_type|发票类型'=>['in:1,2','requireIf:is_tax,1'],
-                'tax.self_type|开票类型'=>['in:1,2','requireIf:is_tax,1'],
-                'tax.u_type|开票用户类型'=>['in:1,2','requireIf:is_tax,1'],
+            $this->validateTaxBody($data);
+        }
+    }
+    protected function validateTaxBody($data){
+        $this->validate($data,[
+            'tax.paper_type|发票类型'=>['in:1,2','requireIf:is_tax,1'],
+            'tax.self_type|开票类型'=>['in:1,2','requireIf:is_tax,1'],
+            'tax.u_type|开票用户类型'=>['in:1,2','requireIf:is_tax,1'],
+        ]);
+        if($data['tax']['u_type']==1){
+            $this->validate($data['tax'],[
+                'name|姓名'=>['require'],
             ]);
-            if($data['tax']['u_type']==1){
+        }else{
+            #如果是普票企业
+            if($data['tax']['self_type']==2){
                 $this->validate($data['tax'],[
-                    'name|姓名'=>['require'],
+                    'com_name|单位名称'=>['require'],
+                    'tax_no|税号'=>['require'],
                 ]);
             }else{
-                #如果是普票企业
-                if($data['tax']['self_type']==2){
-                    $this->validate($data['tax'],[
-                        'com_name|单位名称'=>['require'],
-                        'tax_no|税号'=>['require'],
-                    ]);
-                }else{
-                    $this->validate($data['tax'],[
-                        'com_name|单位名称'=>['require'],
-                        'bank_name|开户行'=>['require'],
-                        'bank_no|开户行账号'=>['require'],
-                        'reg_addr|注册地址'=>['require'],
-                        'reg_phone|注册电话'=>['require'],
-                        'tax_no|税号'=>['require'],
-                    ]);
-                }
+                $this->validate($data['tax'],[
+                    'com_name|单位名称'=>['require'],
+                    'bank_name|开户行'=>['require'],
+                    'bank_no|开户行账号'=>['require'],
+                    'reg_addr|注册地址'=>['require'],
+                    'reg_phone|注册电话'=>['require'],
+                    'tax_no|税号'=>['require'],
+                ]);
             }
         }
     }

File diff suppressed because it is too large
+ 316 - 151
public/api.html


Some files were not shown because too many files changed in this diff