فهرست منبع

有效期修改校验

ZhouBenXu 4 ماه پیش
والد
کامیت
45ec5231ee
2فایلهای تغییر یافته به همراه35 افزوده شده و 9 حذف شده
  1. 21 1
      app/admin/service/card/CardBatchService.php
  2. 14 8
      app/admin/service/card/CardService.php

+ 21 - 1
app/admin/service/card/CardBatchService.php

@@ -92,11 +92,31 @@ class CardBatchService
             } elseif ($params['validtimes_status'] == 1) {
                 $model->card_batch_validtimes = bcadd($model->card_batch_validtimes, $params['card_batch_validtimes']); // 卡批次有效期 0=永久 天
             } elseif ($params['validtimes_status'] == 2) {
+                $end_date = (string)bcadd(strtotime($model->card_batch_addtimes), (bcsub($model->card_batch_validtimes, $params['card_batch_validtimes']) * 86400));
+                if ($end_date <= time()) {
+                    return json_fail('卡批次有效期必须大于当前时间~');
+                }
                 $model->card_batch_validtimes = bcsub($model->card_batch_validtimes, $params['card_batch_validtimes']); // 卡批次有效期 0=永久 天
             }
             if ($model->save()) {
+                 // 修改卡批次下面的卡信息
+                // CardService::saveCardByCardBatchId($params['card_batch_id'], $params);
                 // 修改卡批次下面的卡信息
-                CardService::saveCardByCardBatchId($params['card_batch_id'], $params);
+                $model = new Card();
+                $data['card_name'] = $params['card_batch_name'];
+
+                $card_status = array_values($model::CARD_STATUS);
+                if (in_array($params['card_batch_status'], $card_status)) {
+                    $data['card_status'] = $params['card_batch_status']; // 卡批次状态
+                }
+                if ($params['validtimes_status'] == 0) { // 卡批次有效期 0 永久天  1 增加 2减少
+                    $data['card_validtimes'] = 0;
+                } elseif ($params['validtimes_status'] == 1) {
+                    $data['card_validtimes'] = Db::raw('card_validtimes+' . $params['card_batch_validtimes'] * 86400);
+                } elseif ($params['validtimes_status'] == 2) {
+                    $data['card_validtimes'] = Db::raw('card_validtimes-' . $params['card_batch_validtimes'] * 86400);;
+                }
+                $model->where('join_card_batch_id', $params['card_batch_id'])->update($data);
             }
             Db::commit();
         } catch (\PDOException $e) {

+ 14 - 8
app/admin/service/card/CardService.php

@@ -76,13 +76,14 @@ class CardService
         return json_success('success');
     }
 
+
     /**
      * Notes: 根据卡批次修改卡信息
      * User: ZhouBenXu
      * DateTime: 2024/6/27 下午5:03
      * @param $join_card_batch_id
      * @param $save
-     * @return \support\Response
+     * @return string|\support\Response|true
      */
     public static function saveCardByCardBatchId($join_card_batch_id, $save)
     {
@@ -101,25 +102,25 @@ class CardService
             } elseif ($save['validtimes_status'] == 1) {
                 $data['card_validtimes'] = Db::raw('card_validtimes+' . $save['card_batch_validtimes'] * 86400);
             } elseif ($save['validtimes_status'] == 2) {
-                $data['card_validtimes'] = Db::raw('card_validtimes-' . $save['card_batch_validtimes'] * 86400);
+                $data['card_validtimes'] = Db::raw('card_validtimes-' . $save['card_batch_validtimes'] * 86400);;
             }
             $model->where('join_card_batch_id', $join_card_batch_id)->update($data);
             Db::commit();
         } catch (\PDOException $e) {
             Db::rollBack();
             dump($e->getFile() . '(' . $e->getLine() . '):' . $e->getMessage());
-            return json_fail('数据写入失败~');
+            return false;
         } catch (BusinessException $e) {
             Db::rollBack();
             dump($e->getFile() . '(' . $e->getLine() . '):' . $e->getMessage());
-            return json_fail($e->getMessage());
+            return $e->getMessage();
         } catch (\Exception $e) {
             Db::rollBack();
             dump($e->getTrace());
-            return json_fail('数据写入失败~');
+            return false;
         }
         _syslog("修改储值卡", "卡批次名称【" . $save['card_batch_name'] . "】");
-        return json_success('success');
+        return true;
     }
 
 
@@ -336,9 +337,14 @@ class CardService
             if ($params['validtimes_status'] == 0) { // 卡批次有效期 0 永久天  1 增加 2减少
                 $model->card_validtimes = 0;
             } elseif ($params['validtimes_status'] == 1) {
-                $model->card_validtimes = Db::raw('card_validtimes+' . $params['card_batch_validtimes'] * 86400);
+                $model->card_validtimes = baadd($model->card_validtimes + $params['card_batch_validtimes'] * 86400);
             } elseif ($params['validtimes_status'] == 2) {
-                $model->card_validtimes = Db::raw('card_validtimes-' . $params['card_batch_validtimes'] * 86400);
+                $card_validtimes = bcsub($model->card_validtimes - $params['card_batch_validtimes'] * 86400);
+                // 修改后的有效期不允许小于当前时间
+                if (!$card_validtimes <= time()) {
+                    return json_fail('储值卡有效期必须大于当前时间~');
+                }
+                $model->card_validtimes = $card_validtimes;
             }
             $model->save();
             Db::commit();