|
|
@@ -9,10 +9,8 @@ use bizHd\member\classes\MemberLevelClass;
|
|
|
use bizHd\shop\classes\ShopClass;
|
|
|
use bizHd\shop\classes\ShopExtClass;
|
|
|
use common\components\noticeUtil;
|
|
|
-use common\components\orderSn;
|
|
|
use common\components\printUtil;
|
|
|
use common\components\ChuanglanSmsApi;
|
|
|
-use common\components\stringUtil;
|
|
|
use common\components\util;
|
|
|
use PhpAmqpLib\Wire\AMQPTable;
|
|
|
use Yii;
|
|
|
@@ -26,10 +24,9 @@ class BirthdayGiftClass extends BaseClass
|
|
|
const STATUS_NO_BIRTHDAY = 0; // 0未填写
|
|
|
const STATUS_PENDING_NOTIFY = 1; // 1待通知
|
|
|
const STATUS_PENDING_CLAIM = 2; // 2待领取
|
|
|
- const STATUS_COLLECTED = 3; // 3已领取
|
|
|
- const STATUS_EXPIRED = 4; // 4超时放弃
|
|
|
-
|
|
|
- const EXPIRE_SECONDS = 86400;
|
|
|
+ const STATUS_PICKING_UP = 3; // 3领取中
|
|
|
+ const STATUS_COLLECTED = 4; // 4已领取
|
|
|
+ const STATUS_EXPIRED = 5; // 5超时放弃
|
|
|
|
|
|
public static function getStatusMap()
|
|
|
{
|
|
|
@@ -37,6 +34,7 @@ class BirthdayGiftClass extends BaseClass
|
|
|
self::STATUS_NO_BIRTHDAY => '未填写',
|
|
|
self::STATUS_PENDING_NOTIFY => '待通知',
|
|
|
self::STATUS_PENDING_CLAIM => '待领取',
|
|
|
+ self::STATUS_PICKING_UP => '领取中',
|
|
|
self::STATUS_COLLECTED => '已领取',
|
|
|
self::STATUS_EXPIRED => '超时放弃',
|
|
|
];
|
|
|
@@ -326,6 +324,23 @@ class BirthdayGiftClass extends BaseClass
|
|
|
return $gift;
|
|
|
}
|
|
|
|
|
|
+ public static function modifyBirthday($shop, $params)
|
|
|
+ {
|
|
|
+ $customId = intval($params['customId'] ?? 0);
|
|
|
+ $connection = Yii::$app->db;
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ $custom = CustomClass::modifyBirthday($customId, $shop->id, $params);
|
|
|
+ $levelMap = self::getLevelBenefitMap($shop->mainId, $shop->id);
|
|
|
+ $gift = self::getOrCreateYearRecord($shop, $custom, $levelMap);
|
|
|
+ $transaction->commit();
|
|
|
+ return $gift;
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ throw $exception;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 确保每年都有记录
|
|
|
* @param $shop
|
|
|
@@ -412,20 +427,29 @@ class BirthdayGiftClass extends BaseClass
|
|
|
continue;
|
|
|
}
|
|
|
$custom = $customMap[$customId];
|
|
|
- if ($statusFilter >= 0 && intval($gift->status) != $statusFilter) {
|
|
|
- continue;
|
|
|
+ // 兼容前端"待领取" 映射后端"待领取"与"领取中"两个状态
|
|
|
+ if ($statusFilter >= 0) {
|
|
|
+ if ($statusFilter == self::STATUS_PENDING_CLAIM) {
|
|
|
+ // "待领取"tab,需要包含“待领取”与“领取中”两个状态
|
|
|
+ if (intval($gift->status) != self::STATUS_PENDING_CLAIM && intval($gift->status) != self::STATUS_PICKING_UP) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (intval($gift->status) != $statusFilter) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if ($statusFilter < 0 && intval($gift->status) == self::STATUS_NO_BIRTHDAY) {
|
|
|
// 全部 Tab 也展示未填写
|
|
|
}
|
|
|
if (intval($gift->status) != self::STATUS_NO_BIRTHDAY && !self::matchesPeriod($custom, $period, $params)) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (intval($gift->status) == self::STATUS_NO_BIRTHDAY && $period != 'week') {
|
|
|
- // 未填写仅在较宽范围展示:近一周仍显示
|
|
|
- if ($period != 'week') {
|
|
|
- continue;
|
|
|
- }
|
|
|
+ // 未填写生日仅在选择"全部"选项时显示
|
|
|
+ if (intval($gift->status) == self::STATUS_NO_BIRTHDAY && $period != 'all') {
|
|
|
+ continue;
|
|
|
}
|
|
|
if (!empty($searchText)) {
|
|
|
$name = $custom->name ?? '';
|
|
|
@@ -480,13 +504,14 @@ class BirthdayGiftClass extends BaseClass
|
|
|
if ($st != self::STATUS_NO_BIRTHDAY && !self::matchesPeriod($custom, $period, $params)) {
|
|
|
continue;
|
|
|
}
|
|
|
- if ($st == self::STATUS_NO_BIRTHDAY && $period != 'week') {
|
|
|
+ // 未填写生日仅在选择"全部"选项时显示
|
|
|
+ if ($st == self::STATUS_NO_BIRTHDAY && $period != 'all') {
|
|
|
continue;
|
|
|
}
|
|
|
$counts['all']++;
|
|
|
if ($st == self::STATUS_PENDING_NOTIFY) {
|
|
|
$counts['pendingNotify']++;
|
|
|
- } elseif ($st == self::STATUS_PENDING_CLAIM) {
|
|
|
+ } elseif ($st == self::STATUS_PENDING_CLAIM || $st == self::STATUS_PICKING_UP) { // 前端的"待领取"是由后端的 待领取与领取中 组合而来
|
|
|
$counts['pendingClaim']++;
|
|
|
} elseif ($st == self::STATUS_COLLECTED) {
|
|
|
$counts['collected']++;
|
|
|
@@ -528,7 +553,7 @@ class BirthdayGiftClass extends BaseClass
|
|
|
$st = intval($gift->status);
|
|
|
if ($st == self::STATUS_PENDING_NOTIFY) {
|
|
|
$pending[$name] = ($pending[$name] ?? 0) + 1;
|
|
|
- } elseif ($st == self::STATUS_PENDING_CLAIM || $st == self::STATUS_COLLECTED) {
|
|
|
+ } elseif (in_array($st, [self::STATUS_PENDING_CLAIM, self::STATUS_PENDING_CLAIM, self::STATUS_COLLECTED])) {
|
|
|
$collected[$name] = ($collected[$name] ?? 0) + 1;
|
|
|
}
|
|
|
}
|
|
|
@@ -854,11 +879,11 @@ class BirthdayGiftClass extends BaseClass
|
|
|
util::fail('请选择领取时间');
|
|
|
}
|
|
|
$status = intval($gift->status);
|
|
|
- if ($status == self::STATUS_COLLECTED) {
|
|
|
+ if ($status == self::STATUS_PICKING_UP) {
|
|
|
if ($idempotent) {
|
|
|
return $gift;
|
|
|
}
|
|
|
- util::fail('已领取,请勿重复操作');
|
|
|
+ util::fail('已在领取中,请勿重复操作');
|
|
|
}
|
|
|
if ($status == self::STATUS_EXPIRED) {
|
|
|
util::fail('领取时间已过,已自动放弃权益');
|
|
|
@@ -872,7 +897,7 @@ class BirthdayGiftClass extends BaseClass
|
|
|
}
|
|
|
$gift->pickupTime = $pickupTime;
|
|
|
$gift->collectTime = date('Y-m-d H:i:s');
|
|
|
- $gift->status = self::STATUS_COLLECTED;
|
|
|
+ $gift->status = self::STATUS_PICKING_UP;
|
|
|
$gift->save();
|
|
|
self::printReceipt($gift);
|
|
|
return $gift;
|