ソースを参照

过期红包作废 和 过期红包不显示 问题

shish 6 ヶ月 前
コミット
aa9be3b5cc

+ 31 - 21
app-hd/controllers/HbController.php

@@ -51,26 +51,28 @@ class HbController extends BaseController
      */
     public function actionHbList()
     {
+        $get = Yii::$app->request->get();
         $where = ['shopId' => $this->shopId];
-        $customId = Yii::$app->request->get('customId', '');
+        $customId = $get['customId'] ?? 0;
         if (!empty($customId)) {
             $where['customId'] = $customId;
         }
-        $status = Yii::$app->request->get('status', '');
-        if (isset($status) && $status != '') {
-            if ($status == -1) { // 已失效包含:1作废 与 过期(0未使用但endTime<当前时间) --- 所以当操作作废时,status改为-1,同时将endTime改为当前时间
-                $where['endTime<'] = time();
-            } else {
-                $where['status'] = $status;
-            }
+        $status = $get['status'] ?? '';
+        if ($status != '') {
+            $where['status'] = $status;
         }
-        $list = HbClass::getList('*', $where, 'id desc', 'custom');
-        if (!empty($list['list'])) {
-            foreach ($list['list'] as &$v) {
+        $respond = HbClass::getList('*', $where, 'id desc', 'custom');
+        if (!empty($respond['list'])) {
+            foreach ($respond['list'] as &$v) {
                 $v['customName'] = $v['custom']['name'];
+                if ($v['status'] == 0 && $v['endTime'] < time()) {
+                    //发现红包已过期,需要作废,多有处作废操作,搜索关键词 cancellation_hb
+                    $id = $v['id'];
+                    HbClass::updateById($id, ['status' => -1]);
+                }
             }
         }
-        util::success($list);
+        util::success($respond);
     }
 
     // 单个门店下所有可用红包
@@ -81,9 +83,17 @@ class HbController extends BaseController
         $where = [];
         $where['customId'] = $get['customId'];
         $where['status'] = 0;
-        $where['endTime>'] = time();
-
         $list = HbClass::getAllByCondition($where, 'id DESC');
+        //已经过期的就不再显示,并且作废,多有处作废操作,搜索关键词 cancellation_hb
+        if (!empty($list)) {
+            foreach ($list as $k => $v) {
+                if ($v['endTime'] < time()) {
+                    unset($list[$v]);
+                    $id = $v['id'];
+                    HbClass::updateById($id, ['status' => -1]);
+                }
+            }
+        }
         util::success($list);
     }
 
@@ -178,12 +188,12 @@ class HbController extends BaseController
 
         try {
             //当是退回红包时,必须检测对应订单 actPrice 为0
-            if (isset($form->status) && $form->status == 0){
-                if($hb->status == 1){
+            if (isset($form->status) && $form->status == 0) {
+                if ($hb->status == 1) {
                     //查询订单数据,校验 actPrice,按情况更新
                     $order = OrderClass::getById($form->orderId, true, 'id, hbId, hbAmount, actPrice');
-                    if($order->hbId == $id){
-                        if($order->actPrice == 0.00){
+                    if ($order->hbId == $id) {
+                        if ($order->actPrice == 0.00) {
                             //更新订单数据
                             $order->hbId = -$order->hbId;
                             $order->save();
@@ -191,11 +201,11 @@ class HbController extends BaseController
                             Yii::error('使用红包的订单 actPrice 不等于0,无法执行红包退回。hbId=' . $id);
                             util::fail('使用红包的订单 actPrice 不等于0,无法执行红包退回');
                         }
-                    }else{
+                    } else {
                         Yii::error("订单中的红包id与当前红包不匹配。hbId={$id}, orderId={$form->orderId}");
                         util::fail('订单中的红包id与当前红包不匹配');
                     }
-                }else{
+                } else {
                     Yii::error("当前红包状态不是已使用,不能变更未使用。hbId={$id}");
                     util::fail("当前红包状态不是已使用,不能变更未使用");
                 }
@@ -211,7 +221,7 @@ class HbController extends BaseController
                     $hb->$field = $form->$field;
                 }
             }
-            // 当操作作废时,status改为-1,同时将endTime改为当前时间
+            // 当操作作废时,status改为-1,同时将endTime改为当前时间,多有处作废操作,搜索关键词 cancellation_hb
             if (isset($form->status) && $form->status == -1 && $hb->status != -1) {
                 $hb->endTime = time();
                 //记录作废人

+ 38 - 22
app-mall/controllers/HbController.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace mall\controllers;
 
 use Yii;
@@ -7,35 +8,50 @@ use bizHd\hb\classes\HbClass;
 
 class HbController extends BaseController
 {
-	//优惠券列表 ssh 2019.12.11
-	public function actionList()
-	{
-		$get = Yii::$app->request->get();
+    //优惠券列表 ssh 2019.12.11
+    public function actionList()
+    {
+        $get = Yii::$app->request->get();
         $where = [];
-		$where['t.userId'] = $this->userId;
-		if (isset($get['status'])) {
-			if($get['status'] == 3){
-				// 全部状态
-			}elseif($get['status'] == 2){ // 已失效包含:1作废 与 过期(0未使用但endTime<当前时间) --- 所以当操作作废时,status改为-1,同时将endTime改为当前时间
-				$where['t.endTime<'] = time();
-			} else {
-				$where['t.status'] = $get['status'];
-			}
-		}
-		
-        $list = HbClass::getHbList(['t.*', 's.merchantName', 's.shopName'], $where);
-		util::success($list);
-	}
+        $where['t.userId'] = $this->userId;
+        $status = $get['status'] ?? '';
+        if ($status != '') {
+            $where['t.status'] = $get['status'];
+        }
+        $respond = HbClass::getHbList(['t.*', 's.merchantName', 's.shopName'], $where);
 
-	// 单个门店下所有可用红包
-	public function actionAvailableHb()
+        if (!empty($respond['list'])) {
+            foreach ($respond['list'] as &$v) {
+                $v['customName'] = $v['custom']['name'];
+                if ($v['status'] == 0 && $v['endTime'] < time()) {
+                    //发现红包已过期,需要作废,多有处作废操作,搜索关键词 cancellation_hb
+                    $id = $v['id'];
+                    HbClass::updateById($id, ['status' => -1]);
+                }
+            }
+        }
+
+        util::success($respond);
+    }
+
+    // 单个门店下所有可用红包
+    public function actionAvailableHb()
     {
         $where = [];
         $where['customId'] = $this->customId;
         $where['status'] = 0;
-        $where['endTime>'] = time();
-
         $list = HbClass::getAllByCondition($where, 'id DESC');
+        //已经过期的就不再显示,并且作废,多有处作废操作,搜索关键词 cancellation_hb
+        if (!empty($list)) {
+            foreach ($list as $k => $v) {
+                if ($v['endTime'] < time()) {
+                    unset($list[$v]);
+                    $id = $v['id'];
+                    HbClass::updateById($id, ['status' => -1]);
+                }
+            }
+        }
         util::success($list);
     }
+
 }

+ 2 - 2
biz-hd/hb/classes/HbClass.php

@@ -14,8 +14,8 @@ class HbClass extends BaseClass
     public static function getHbList($select, $where)
     {
         $get = Yii::$app->request->get();
-        $page = isset($get['page']) ? $get['page'] : 1;
-        $pageSize = isset($get['pageSize']) && !empty($get['pageSize']) ? $get['pageSize'] : Yii::$app->params['pageSize'];
+        $page = $get['page'] ?? 1;
+        $pageSize = !empty($get['pageSize']) ? $get['pageSize'] : Yii::$app->params['pageSize'];
         $offset = ($page - 1) * $pageSize;
 
         $model = self::getModel();