|
|
@@ -27,6 +27,7 @@ class BirthdayGiftClass extends BaseClass
|
|
|
const STATUS_PICKING_UP = 3; // 3领取中
|
|
|
const STATUS_COLLECTED = 4; // 4已领取
|
|
|
const STATUS_EXPIRED = 5; // 5超时放弃
|
|
|
+ const EXPIRE_SECONDS = 86400; // 通知后24小时内回复有效
|
|
|
|
|
|
public static function getStatusMap()
|
|
|
{
|
|
|
@@ -395,6 +396,7 @@ class BirthdayGiftClass extends BaseClass
|
|
|
'birthdayDisplay' => $gift->birthdayDisplay,
|
|
|
'status' => $status,
|
|
|
'statusName' => $statusMap[$status] ?? '',
|
|
|
+ 'canNotify' => $status == self::STATUS_PENDING_NOTIFY && self::matchesBirthdayOffset($custom, 1),
|
|
|
'pickupTime' => $gift->pickupTime ?? '',
|
|
|
'collectTime' => $gift->collectTime ?? '',
|
|
|
'notifyTime' => $gift->notifyTime ?? '',
|
|
|
@@ -411,7 +413,7 @@ class BirthdayGiftClass extends BaseClass
|
|
|
$page = max(1, intval($params['page'] ?? 1));
|
|
|
$pageSize = max(1, min(50, intval($params['pageSize'] ?? 20)));
|
|
|
|
|
|
- list($customs, $levelMap) = self::getEligibleCustoms($shop->id, $shop->mainId);
|
|
|
+ list($customs,) = self::getEligibleCustoms($shop->id, $shop->mainId);
|
|
|
$customMap = [];
|
|
|
foreach ($customs as $c) {
|
|
|
$customMap[$c->id] = $c;
|
|
|
@@ -662,23 +664,12 @@ class BirthdayGiftClass extends BaseClass
|
|
|
if (intval($gift->status) != self::STATUS_PENDING_NOTIFY) {
|
|
|
continue;
|
|
|
}
|
|
|
- list($ok, $err) = self::sendNotifySms($shop, $gift, $custom);
|
|
|
+ list($ok, $err) = self::notifyGift($shop, $gift, $custom);
|
|
|
if (!$ok) {
|
|
|
$fail++;
|
|
|
$messages[] = ($custom->name ?? '') . ':' . $err;
|
|
|
continue;
|
|
|
}
|
|
|
- $now = date('Y-m-d H:i:s');
|
|
|
- $expire = date('Y-m-d H:i:s', time() + self::EXPIRE_SECONDS);
|
|
|
- $gift->status = self::STATUS_PENDING_CLAIM;
|
|
|
- $gift->notifyTime = $now;
|
|
|
- $gift->expireTime = $expire;
|
|
|
- $gift->smsSent = 1;
|
|
|
- if (empty($gift->orderSn)) {
|
|
|
- $gift->orderSn = 'BG' . date('ymdHis') . mt_rand(1000, 9999);
|
|
|
- }
|
|
|
- $gift->save();
|
|
|
- self::scheduleExpireDelay($gift->id, strtotime($expire));
|
|
|
$success++;
|
|
|
}
|
|
|
return [
|
|
|
@@ -688,6 +679,50 @@ class BirthdayGiftClass extends BaseClass
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ public static function notifyGift($shop, $gift, $custom)
|
|
|
+ {
|
|
|
+ list($ok, $err) = self::sendNotifySms($shop, $gift, $custom);
|
|
|
+ if (!$ok) {
|
|
|
+ return [false, $err];
|
|
|
+ }
|
|
|
+ $now = date('Y-m-d H:i:s');
|
|
|
+ $expire = date('Y-m-d H:i:s', time() + self::EXPIRE_SECONDS);
|
|
|
+ $gift->status = self::STATUS_PENDING_CLAIM;
|
|
|
+ $gift->notifyTime = $now;
|
|
|
+ $gift->expireTime = $expire;
|
|
|
+ $gift->smsSent = 1;
|
|
|
+ if (empty($gift->orderSn)) {
|
|
|
+ $gift->orderSn = 'BG' . date('ymdHis') . mt_rand(1000, 9999);
|
|
|
+ }
|
|
|
+ $gift->save();
|
|
|
+ self::scheduleExpireDelay($gift->id, strtotime($expire));
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function notifyOneTomorrow($shop, $giftId)
|
|
|
+ {
|
|
|
+ self::ensureYearRecords($shop);
|
|
|
+ $gift = self::getById($giftId, true);
|
|
|
+ if (empty($gift) || intval($gift->shopId) != intval($shop->id)) {
|
|
|
+ util::fail('记录不存在');
|
|
|
+ }
|
|
|
+ if (intval($gift->status) != self::STATUS_PENDING_NOTIFY) {
|
|
|
+ util::fail('当前状态不可通知');
|
|
|
+ }
|
|
|
+ $custom = CustomClass::getById($gift->customId, true);
|
|
|
+ if (empty($custom) || intval($custom->shopId) != intval($shop->id) || intval($custom->delStatus) != 0) {
|
|
|
+ util::fail('客户信息不存在');
|
|
|
+ }
|
|
|
+ if (!self::matchesBirthdayOffset($custom, 1)) {
|
|
|
+ util::fail('仅明日生日客户可发送通知');
|
|
|
+ }
|
|
|
+ list($ok, $err) = self::notifyGift($shop, $gift, $custom);
|
|
|
+ if (!$ok) {
|
|
|
+ util::fail($err ?: '通知失败');
|
|
|
+ }
|
|
|
+ return $gift;
|
|
|
+ }
|
|
|
+
|
|
|
public static function getInfoByToken($shopId, $token)
|
|
|
{
|
|
|
$gift = self::getByCondition(['shopId' => $shopId, 'claimToken' => $token], true);
|
|
|
@@ -968,4 +1003,22 @@ class BirthdayGiftClass extends BaseClass
|
|
|
self::printReceipt($gift);
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ public static function collectGiftByAdmin($shopId, $giftId)
|
|
|
+ {
|
|
|
+ $gift = self::getById($giftId, true);
|
|
|
+ if (empty($gift) || intval($gift->shopId) != intval($shopId)) {
|
|
|
+ util::fail('记录不存在');
|
|
|
+ }
|
|
|
+ if (intval($gift->status) == self::STATUS_COLLECTED) {
|
|
|
+ return $gift;
|
|
|
+ }
|
|
|
+ if (intval($gift->status) != self::STATUS_PICKING_UP) {
|
|
|
+ util::fail('仅领取中记录可更新为已领取');
|
|
|
+ }
|
|
|
+ $gift->status = self::STATUS_COLLECTED;
|
|
|
+ $gift->collectTime = date('Y-m-d H:i:s');
|
|
|
+ $gift->save();
|
|
|
+ return $gift;
|
|
|
+ }
|
|
|
}
|