whitefang 1 年間 前
コミット
b59bfca08a

+ 0 - 14
app/api/controller/GoodsController.php

@@ -40,18 +40,4 @@ class GoodsController extends BaseApiController
         $result = GoodsLogic::detail($params['id'],'goods');
         $result = GoodsLogic::detail($params['id'],'goods');
         return $this->data($result);
         return $this->data($result);
     }
     }
-
-
-    //商品优惠卷
-    public function categoryCouponList()
-    {
-        $params = (new UserCouponValidate())->goCheck('category',[
-            'user_id'=>$this->userId
-        ]);
-        $result = UserCouponLogic::categoryCouponList($params);
-        if (false === $result) {
-            return $this->fail(UserCouponLogic::getError());
-        }
-        return $this->data($result);
-    }
 }
 }

+ 29 - 1
app/api/controller/UserCouponController.php

@@ -8,11 +8,26 @@ use app\api\validate\UserCouponValidate;
 
 
 class UserCouponController extends BaseApiController
 class UserCouponController extends BaseApiController
 {
 {
+    /**
+     * 我的优惠卷列表
+     * @return \think\response\Json
+     */
     public function lists()
     public function lists()
     {
     {
-        return $this->dataLists(new UserCouponLists());
+        $params = (new UserCouponValidate())->goCheck('voucher',[
+            'user_id'=>$this->userId
+        ]);
+        $result = UserCouponLogic::userCouponList($params);
+        if (false === $result) {
+            return $this->fail(UserCouponLogic::getError());
+        }
+        return $this->data($result);
     }
     }
 
 
+    /**
+     * 一键领取优惠卷
+     * @return \think\response\Json
+     */
     public function add()
     public function add()
     {
     {
         $params = (new UserCouponValidate())->post()->goCheck('add',[
         $params = (new UserCouponValidate())->post()->goCheck('add',[
@@ -24,4 +39,17 @@ class UserCouponController extends BaseApiController
         }
         }
         return $this->fail(UserCouponLogic::getError());
         return $this->fail(UserCouponLogic::getError());
     }
     }
+
+
+    public function CategoryCouponList()
+    {
+        $params = (new UserCouponValidate())->goCheck('category',[
+            'user_id'=>$this->userId
+        ]);
+        $result = UserCouponLogic::categoryCouponList($params);
+        if (false === $result) {
+            return $this->fail(UserCouponLogic::getError());
+        }
+        return $this->data($result);
+    }
 }
 }

+ 0 - 64
app/api/lists/UserCouponLists.php

@@ -1,64 +0,0 @@
-<?php
-namespace app\api\lists;
-
-use app\common\lists\ListsSearchInterface;
-use app\common\model\coupon\UserCoupon;
-use think\db\Query;
-
-class UserCouponLists extends  BaseApiDataLists implements ListsSearchInterface
-{
-    protected $count = 0;
-    public function setSearch(): array
-    {
-        return [
-            '=' => ['user_id'],
-        ];
-    }
-    public function queryWhere(){
-        $where = [];
-        if(isset($this->params['voucher_status']) && is_array($this->params['voucher_status'])){
-            $where[] = ['voucher_status','IN',$this->params['voucher_status']];
-        }
-        $where[] = ['user_id','=',$this->userId];
-        return $where;
-    }
-    public function lists(): array
-    {
-        $data = UserCoupon::with(['couponRules'=>function(Query $query){
-                $query->withoutField(['voucher_status','voucher_count']);
-                $query->with(['couponWithCategory'=>function(Query $query){
-                        $query->field('id,name');
-                }]);
-            }])
-            ->where($this->searchWhere)
-            ->where($this->queryWhere())
-            ->field(['id', 'user_id', 'coupon_id', 'voucher_status','voucher_count'])
-            ->limit($this->limitOffset, $this->limitLength)
-            ->order(['id' => 'desc'])
-            ->select()
-            ->toArray();
-        $couponIds = [];
-        foreach($data as $k => $v){
-            if($v['couponRules']){
-                if($v['voucher_status'] !=2 &&($v['couponRules']['begin_use'] <time() || $data['couponRules']['expire_time'] > time())){
-                    $couponIds[] = $v['coupon_id'];
-                    $v['voucher_status'] = 2;
-                }
-                $v['couponRules']['begin_use'] = date("Y-m-d H:i:s",$v['couponRules']['begin_use'] );
-                $v['couponRules']['expire_time'] = date("Y-m-d H:i:s",$v['couponRules']['expire_time'] );
-                $v['couponRules']['goods_category_ids'] = array_column($v['couponRules']['couponWithCategory'],'id');
-                $data[$k] = $v;
-            }
-        }
-        if(!empty($couponIds)){
-            UserCoupon::whereIn('coupon_id',$couponIds)->update(['voucher_status'=>2]);
-        }
-        $this->count = count($data);
-        return $data;
-    }
-
-    public function count(): int
-    {
-        return $this->count;
-    }
-}

+ 53 - 8
app/api/logic/UserCouponLogic.php

@@ -57,22 +57,45 @@ class UserCouponLogic extends BaseLogic
     }
     }
 
 
     /**
     /**
+     * 我的优惠卷列表
      * @param $params
      * @param $params
      * @return array|false
      * @return array|false
-    */
-    public static function categoryCouponList($params)
+     */
+    public static function userCouponList($params)
     {
     {
         try{
         try{
-            $data =  CouponRules::whereIn('id',CouponCategory::where('goods_category_id',$params['goods_category_id'])->group('coupon_id')->column('coupon_id'))
-                ->where(['coupon_type'=>1])
-                ->field(['id', 'amount', 'coupon_type','amount_require', 'begin_use', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_status', 'voucher_count'])
+            $where = [];
+            if(isset($params['voucher_status']) && is_array($params['voucher_status'])){
+                $where[] = ['voucher_status','IN',$params['voucher_status']];
+            }
+            $where[] = ['user_id','=',$params['user_id']];
+
+            $data = UserCoupon::with(['couponRules'=>function(Query $query){
+                $query->withoutField(['voucher_status','voucher_count']);
+                $query->with(['couponWithCategory'=>function(Query $query){
+                    $query->field('id,name');
+                }]);
+            }])
+                ->where($where)
+                ->field(['id', 'user_id', 'coupon_id', 'voucher_status','voucher_count'])
                 ->order(['id' => 'desc'])
                 ->order(['id' => 'desc'])
                 ->select()
                 ->select()
                 ->toArray();
                 ->toArray();
+            $couponIds = [];
             foreach($data as $k => $v){
             foreach($data as $k => $v){
-                $v['begin_use'] = $v['begin_use'] ? date('Y-m-d H:i:s',$v['begin_use']) :null;
-                $v['expire_time'] =  $v['begin_use'] ?date('Y-m-d H:i:s',$v['expire_time']) :null;
-                $data[$k] = $v;
+                if($v['couponRules']){
+                    if($v['voucher_status'] !=2 &&($v['couponRules']['begin_use'] <time() || $data['couponRules']['expire_time'] > time())){
+                        $couponIds[] = $v['coupon_id'];
+                        $v['voucher_status'] = 2;
+                    }
+                    $v['couponRules']['begin_use'] = date("Y-m-d H:i:s",$v['couponRules']['begin_use'] );
+                    $v['couponRules']['expire_time'] = date("Y-m-d H:i:s",$v['couponRules']['expire_time'] );
+                    $v['couponRules']['goods_category_ids'] = array_column($v['couponRules']['couponWithCategory'],'id');
+                    $data[$k] = $v;
+                }
+            }
+            if(!empty($couponIds)){
+                UserCoupon::whereIn('coupon_id',$couponIds)->update(['voucher_status'=>2]);
             }
             }
             return $data;
             return $data;
         }catch(\Exception $e){
         }catch(\Exception $e){
@@ -81,4 +104,26 @@ class UserCouponLogic extends BaseLogic
             return false;
             return false;
         }
         }
     }
     }
+
+    /**
+     * 商品分类优惠卷领取
+     * @param $params
+     * @return array|false
+    */
+    public static function categoryCouponList($params)
+    {
+        try{
+            $data =  CouponRules::with(['couponWithCategory'=>function(Query $query) use($params){
+                $query->where('goods_category_id',$params['goods_category_id']);
+            }])->field(['id', 'amount', 'coupon_type','amount_require', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_count'])
+                ->order(['id' => 'desc'])
+                ->select()
+                ->toArray();
+            return $data;
+        }catch(\Exception $e){
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }
 }

+ 9 - 2
app/api/validate/UserCouponValidate.php

@@ -9,17 +9,24 @@ use app\common\validate\BaseValidate;
 class UserCouponValidate extends BaseValidate {
 class UserCouponValidate extends BaseValidate {
     protected $rule = [
     protected $rule = [
         'coupon_ids' => 'require',
         'coupon_ids' => 'require',
-        'goods_category_id'=> 'require'
+        'goods_category_id'=> 'require',
+        'voucher_status'=>'require'
     ];
     ];
     protected $field = [
     protected $field = [
         'coupon_ids' => '优惠券ID组',
         'coupon_ids' => '优惠券ID组',
-        'goods_category_id'=>'分类ID'
+        'goods_category_id'=>'分类ID',
+        'voucher_status'=>'参数',
     ];
     ];
     public function sceneAdd()
     public function sceneAdd()
     {
     {
         return $this->only(['coupon_ids']);
         return $this->only(['coupon_ids']);
     }
     }
 
 
+    public function sceneVoucher()
+    {
+        return $this->only(['voucher_status']);
+    }
+
     public function sceneCategory()
     public function sceneCategory()
     {
     {
         return $this->only(['goods_category_id']);
         return $this->only(['goods_category_id']);

+ 0 - 1
app/common/model/coupon/CouponRules.php

@@ -33,5 +33,4 @@ class CouponRules extends BaseModel
     {
     {
         return $this->belongsToMany(GoodsCategory::class,CouponCategory::class,'goods_category_id','coupon_id');
         return $this->belongsToMany(GoodsCategory::class,CouponCategory::class,'goods_category_id','coupon_id');
     }
     }
-    
 }
 }

+ 10 - 0
app/common/model/works/IssueWork.php

@@ -39,5 +39,15 @@ class IssueWork extends BaseModel
     {
     {
         return empty($value)?'':json_encode($value,JSON_UNESCAPED_UNICODE);
         return empty($value)?'':json_encode($value,JSON_UNESCAPED_UNICODE);
     }
     }
+
+    public function getComplaintTypeAttr($value)
+    {
+        return empty($value)?'':json_decode($value,true);
+    }
+
+    public function setComplaintTypeAttr($value)
+    {
+        return empty($value)?'':json_encode($value,JSON_UNESCAPED_UNICODE);
+    }
     
     
 }
 }