Эх сурвалжийг харах

修复:优惠券设置为隐藏领券中心会显示

Yahoo 4 жил өмнө
parent
commit
7430629759

+ 11 - 14
app/api/controller/Controller.php

@@ -17,7 +17,7 @@ use cores\BaseController;
 use app\api\model\User as UserModel;
 use app\api\model\User as UserModel;
 use app\api\model\Store as StoreModel;
 use app\api\model\Store as StoreModel;
 use app\api\service\User as UserService;
 use app\api\service\User as UserService;
-use app\common\exception\BaseException;
+use cores\exception\BaseException;
 
 
 /**
 /**
  * API控制器基类
  * API控制器基类
@@ -44,16 +44,14 @@ class Controller extends BaseController
     }
     }
 
 
     /**
     /**
-     * 获取当前商城id
+     * 获取当前商城ID
      * @return int|null
      * @return int|null
      * @throws BaseException
      * @throws BaseException
      */
      */
     protected function getStoreId(): ?int
     protected function getStoreId(): ?int
     {
     {
         $storeId = getStoreId();    // app/api/common.php
         $storeId = getStoreId();    // app/api/common.php
-        if (empty($storeId)) {
-            throwError('缺少必要的参数:storeId');
-        }
+        empty($storeId) && throwError('缺少必要的参数:storeId');
         return $storeId;
         return $storeId;
     }
     }
 
 
@@ -107,9 +105,9 @@ class Controller extends BaseController
      * @param int|null $status 状态码
      * @param int|null $status 状态码
      * @param string $message
      * @param string $message
      * @param array $data
      * @param array $data
-     * @return array|Json
+     * @return Json
      */
      */
-    protected function renderJson(int $status = null, string $message = '', array $data = [])
+    protected function renderJson(int $status = null, string $message = '', array $data = []): Json
     {
     {
         return json(compact('status', 'message', 'data'));
         return json(compact('status', 'message', 'data'));
     }
     }
@@ -118,9 +116,9 @@ class Controller extends BaseController
      * 返回操作成功json
      * 返回操作成功json
      * @param array|string $data
      * @param array|string $data
      * @param string $message
      * @param string $message
-     * @return array
+     * @return Json
      */
      */
-    protected function renderSuccess($data = [], string $message = 'success')
+    protected function renderSuccess($data = [], string $message = 'success'): Json
     {
     {
         if (is_string($data)) {
         if (is_string($data)) {
             $message = $data;
             $message = $data;
@@ -133,9 +131,9 @@ class Controller extends BaseController
      * 返回操作失败json
      * 返回操作失败json
      * @param string $message
      * @param string $message
      * @param array $data
      * @param array $data
-     * @return array
+     * @return Json
      */
      */
-    protected function renderError(string $message = 'error', array $data = [])
+    protected function renderError(string $message = 'error', array $data = []): Json
     {
     {
         return $this->renderJson(config('status.error'), $message, $data);
         return $this->renderJson(config('status.error'), $message, $data);
     }
     }
@@ -152,12 +150,11 @@ class Controller extends BaseController
 
 
     /**
     /**
      * 获取post数据 (数组)
      * 获取post数据 (数组)
-     * @param $key
+     * @param string $key
      * @return mixed
      * @return mixed
      */
      */
-    protected function postForm($key = 'form')
+    protected function postForm(string $key = 'form')
     {
     {
         return $this->postData($key);
         return $this->postData($key);
     }
     }
-
 }
 }

+ 4 - 4
app/api/controller/Coupon.php

@@ -12,6 +12,7 @@ declare (strict_types = 1);
 
 
 namespace app\api\controller;
 namespace app\api\controller;
 
 
+use think\response\Json;
 use app\api\model\Coupon as CouponModel;
 use app\api\model\Coupon as CouponModel;
 
 
 /**
 /**
@@ -23,17 +24,16 @@ class Coupon extends Controller
 {
 {
     /**
     /**
      * 优惠券列表
      * 优惠券列表
-     * @return array
-     * @throws \app\common\exception\BaseException
+     * @return Json
+     * @throws \cores\exception\BaseException
      * @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
      */
      */
-    public function list()
+    public function list(): Json
     {
     {
         $model = new CouponModel;
         $model = new CouponModel;
         $list = $model->getList();
         $list = $model->getList();
         return $this->renderSuccess(compact('list'));
         return $this->renderSuccess(compact('list'));
     }
     }
-
 }
 }

+ 10 - 9
app/api/model/Coupon.php

@@ -8,13 +8,13 @@
 // +----------------------------------------------------------------------
 // +----------------------------------------------------------------------
 // | Author: 萤火科技 <admin@yiovo.com>
 // | Author: 萤火科技 <admin@yiovo.com>
 // +----------------------------------------------------------------------
 // +----------------------------------------------------------------------
-declare (strict_types = 1);
+declare (strict_types=1);
 
 
 namespace app\api\model;
 namespace app\api\model;
 
 
 use app\api\service\User as UserService;
 use app\api\service\User as UserService;
-use app\common\exception\BaseException;
 use app\common\model\Coupon as CouponModel;
 use app\common\model\Coupon as CouponModel;
+use cores\exception\BaseException;
 
 
 /**
 /**
  * 优惠券模型
  * 优惠券模型
@@ -38,13 +38,13 @@ class Coupon extends CouponModel
      * 获取优惠券列表
      * 获取优惠券列表
      * @param int|null $limit 获取的数量
      * @param int|null $limit 获取的数量
      * @param bool $onlyReceive 只显示可领取
      * @param bool $onlyReceive 只显示可领取
-     * @return \think\Collection
+     * @return array
      * @throws BaseException
      * @throws BaseException
      * @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
      */
      */
-    public function getList(int $limit = null, bool $onlyReceive = false)
+    public function getList(int $limit = null, bool $onlyReceive = false): array
     {
     {
         // 查询构造器
         // 查询构造器
         $query = $this->getNewQuery();
         $query = $this->getNewQuery();
@@ -56,7 +56,8 @@ class Coupon extends CouponModel
         // 查询数量
         // 查询数量
         $limit > 0 && $query->limit($limit);
         $limit > 0 && $query->limit($limit);
         // 优惠券列表
         // 优惠券列表
-        $couponList = $query->where('is_delete', '=', 0)
+        $couponList = $query->where('status', '=', 1)
+            ->where('is_delete', '=', 0)
             ->order(['sort', 'create_time' => 'desc'])
             ->order(['sort', 'create_time' => 'desc'])
             ->select();
             ->select();
         // 获取用户已领取的优惠券
         // 获取用户已领取的优惠券
@@ -66,10 +67,11 @@ class Coupon extends CouponModel
     /**
     /**
      * 获取用户已领取的优惠券
      * 获取用户已领取的优惠券
      * @param $couponList
      * @param $couponList
-     * @return mixed
+     * @return array
      * @throws BaseException
      * @throws BaseException
      */
      */
-    private function setIsReceive($couponList) {
+    private function setIsReceive($couponList): array
+    {
         // 获取用户已领取的优惠券
         // 获取用户已领取的优惠券
         $userInfo = UserService::getCurrentLoginUser();
         $userInfo = UserService::getCurrentLoginUser();
         if ($userInfo !== false) {
         if ($userInfo !== false) {
@@ -86,7 +88,7 @@ class Coupon extends CouponModel
      * 验证优惠券是否可领取
      * 验证优惠券是否可领取
      * @return bool
      * @return bool
      */
      */
-    public function checkReceive()
+    public function checkReceive(): bool
     {
     {
         if ($this['total_num'] > -1 && $this['receive_num'] >= $this['total_num']) {
         if ($this['total_num'] > -1 && $this['receive_num'] >= $this['total_num']) {
             $this->error = '优惠券已发完';
             $this->error = '优惠券已发完';
@@ -107,5 +109,4 @@ class Coupon extends CouponModel
     {
     {
         return $this->setInc($this['coupon_id'], 'receive_num', 1);
         return $this->setInc($this['coupon_id'], 'receive_num', 1);
     }
     }
-
 }
 }