|
|
@@ -241,23 +241,32 @@ class BirthdayGiftClass extends BaseClass
|
|
|
*/
|
|
|
public static function getEligibleCustoms($shopId, $mainId)
|
|
|
{
|
|
|
+ $errMsgs = '';
|
|
|
$levelMap = self::getLevelBenefitMap($mainId, $shopId);
|
|
|
$list = CustomClass::getAllByCondition([
|
|
|
'shopId' => $shopId,
|
|
|
'member>' => 0,
|
|
|
'delStatus' => 0,
|
|
|
], 'id ASC', '*', null, true);
|
|
|
- $result = [];
|
|
|
+ $customs = [];
|
|
|
if (!empty($list)) {
|
|
|
foreach ($list as $custom) {
|
|
|
if (self::hasBirthdayBenefit($custom, $levelMap)) {
|
|
|
- $result[] = $custom;
|
|
|
+ $customs[] = $custom;
|
|
|
} else {
|
|
|
- noticeUtil::push('客户' . $custom->name . '(' . $custom->member . ')没有生日权益');
|
|
|
+ $errMsgs .= '客户' . $custom->name . '(等级' . $custom->member . ')没有生日权益' . ', ';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return [$result, $levelMap];
|
|
|
+
|
|
|
+ if ($errMsgs != '') {
|
|
|
+ $msg = '门店id='.$shopId.':'.$errMsgs;
|
|
|
+ //noticeUtil::push($msg);
|
|
|
+ Yii::info($msg);
|
|
|
+ return [false, false];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [$customs, $levelMap];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -268,7 +277,7 @@ class BirthdayGiftClass extends BaseClass
|
|
|
*/
|
|
|
public static function getWorkbenchSummary($shopId, $mainId)
|
|
|
{
|
|
|
- $cacheKey = self::getWorkbenchSummaryCacheKey($shopId, $mainId);
|
|
|
+ $cacheKey = self::getWorkbenchSummaryCacheKey($shopId);
|
|
|
try {
|
|
|
$cached = Yii::$app->redis->get($cacheKey);
|
|
|
if ($cached !== false && $cached !== null) {
|
|
|
@@ -286,6 +295,11 @@ class BirthdayGiftClass extends BaseClass
|
|
|
$week = 0;
|
|
|
|
|
|
list($customs,) = self::getEligibleCustoms($shopId, $mainId);
|
|
|
+ if ($customs === false) { //门店的会员等级设置异常,直接返回
|
|
|
+ Yii::error('门店'.$shopId.'--会员等级设置异常');
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
foreach ($customs as $custom) {
|
|
|
if (self::getBirthdayMonthDay($custom) === null) {
|
|
|
continue;
|
|
|
@@ -319,17 +333,16 @@ class BirthdayGiftClass extends BaseClass
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- private static function getWorkbenchSummaryCacheKey($shopId, $mainId)
|
|
|
+ private static function getWorkbenchSummaryCacheKey($shopId)
|
|
|
{
|
|
|
- return 'hd:birthdayGift:workbenchSummary:'
|
|
|
- . intval($mainId) . ':' . intval($shopId) . ':' . date('Ymd');
|
|
|
+ return 'hd_birthdayGift_workbenchSummary:' . '_' . intval($shopId) . ':' . date('Ymd');
|
|
|
}
|
|
|
|
|
|
- private static function clearWorkbenchSummaryCache($shopId, $mainId)
|
|
|
+ public static function clearWorkbenchSummaryCache($shopId)
|
|
|
{
|
|
|
try {
|
|
|
Yii::$app->redis->executeCommand('DEL', [
|
|
|
- self::getWorkbenchSummaryCacheKey($shopId, $mainId),
|
|
|
+ self::getWorkbenchSummaryCacheKey($shopId),
|
|
|
]);
|
|
|
} catch (\Throwable $throwable) {
|
|
|
Yii::warning('清理生日工作台缓存失败:' . $throwable->getMessage(), __METHOD__);
|
|
|
@@ -431,7 +444,7 @@ class BirthdayGiftClass extends BaseClass
|
|
|
$levelMap = self::getLevelBenefitMap($shop->mainId, $shop->id);
|
|
|
$gift = self::createOrUpdateYearRecord($shop, $custom, $levelMap);
|
|
|
$transaction->commit();
|
|
|
- self::clearWorkbenchSummaryCache($shop->id, $shop->mainId);
|
|
|
+ self::clearWorkbenchSummaryCache($shop->id);
|
|
|
return $gift;
|
|
|
} catch (\Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
|
@@ -450,8 +463,9 @@ class BirthdayGiftClass extends BaseClass
|
|
|
$shopId = intval($shop->id);
|
|
|
$year = intval(date('Y')); //今年
|
|
|
list($customs, $levelMap) = self::getEligibleCustoms($shopId, $shop->mainId);
|
|
|
- if (empty($customs)) {
|
|
|
- return true;
|
|
|
+ if ($customs === false) {
|
|
|
+ Yii::error('会员权益配置异常');
|
|
|
+ return false;
|
|
|
}
|
|
|
$existingRows = self::getAllByCondition(['shopId' => $shopId, 'year' => $year], null, 'customId');
|
|
|
$existingIds = [];
|
|
|
@@ -511,7 +525,10 @@ class BirthdayGiftClass extends BaseClass
|
|
|
*/
|
|
|
public static function getBoardList($shop, $params)
|
|
|
{
|
|
|
- self::ensureYearRecords($shop);
|
|
|
+ $re = self::ensureYearRecords($shop);
|
|
|
+ if ($re === false) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
$period = $params['period'] ?? 'week';
|
|
|
$statusFilter = isset($params['status']) ? intval($params['status']) : -1;
|
|
|
$searchText = trim($params['searchText'] ?? $params['keyword'] ?? '');
|
|
|
@@ -519,6 +536,10 @@ class BirthdayGiftClass extends BaseClass
|
|
|
$pageSize = max(1, min(50, intval($params['pageSize'] ?? 20)));
|
|
|
|
|
|
list($customs,) = self::getEligibleCustoms($shop->id, $shop->mainId);
|
|
|
+ if ($customs === false) {
|
|
|
+ Yii::error('会员权益配置异常');
|
|
|
+ return [];
|
|
|
+ }
|
|
|
$customMap = [];
|
|
|
foreach ($customs as $c) {
|
|
|
$customMap[$c->id] = $c;
|
|
|
@@ -583,9 +604,17 @@ class BirthdayGiftClass extends BaseClass
|
|
|
|
|
|
public static function getStatusCounts($shop, $params)
|
|
|
{
|
|
|
- self::ensureYearRecords($shop);
|
|
|
+ $re = self::ensureYearRecords($shop);
|
|
|
+ if ($re === false) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
$period = $params['period'] ?? 'week';
|
|
|
list($customs,) = self::getEligibleCustoms($shop->id, $shop->mainId);
|
|
|
+ if ($customs === false) {
|
|
|
+ Yii::error('会员权益配置异常');
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
$customMap = [];
|
|
|
foreach ($customs as $c) {
|
|
|
$customMap[$c->id] = $c;
|
|
|
@@ -634,8 +663,15 @@ class BirthdayGiftClass extends BaseClass
|
|
|
|
|
|
public static function getGiftStats($shop, $period)
|
|
|
{
|
|
|
- self::ensureYearRecords($shop);
|
|
|
+ $re = self::ensureYearRecords($shop);
|
|
|
+ if ($re === false) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
list($customs,) = self::getEligibleCustoms($shop->id, $shop->mainId);
|
|
|
+ if ($customs === false) {
|
|
|
+ Yii::error('会员权益配置异常');
|
|
|
+ return [];
|
|
|
+ }
|
|
|
$customMap = [];
|
|
|
foreach ($customs as $c) {
|
|
|
$customMap[$c->id] = $c;
|
|
|
@@ -786,8 +822,22 @@ class BirthdayGiftClass extends BaseClass
|
|
|
|
|
|
public static function batchNotifyTomorrow($shop)
|
|
|
{
|
|
|
- self::ensureYearRecords($shop);
|
|
|
+ $re = self::ensureYearRecords($shop);
|
|
|
+ if ($re === false) {
|
|
|
+ return [
|
|
|
+ 'success' => 0,
|
|
|
+ 'fail' => 1,
|
|
|
+ 'messages' => ['会员等级设置异常'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
list($customs, $levelMap) = self::getEligibleCustoms($shop->id, $shop->mainId);
|
|
|
+ if ($customs === false) {
|
|
|
+ return [
|
|
|
+ 'success' => 0,
|
|
|
+ 'fail' => 1,
|
|
|
+ 'messages' => ['会员等级设置异常'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
$success = 0;
|
|
|
$fail = 0;
|
|
|
$messages = [];
|
|
|
@@ -908,7 +958,10 @@ class BirthdayGiftClass extends BaseClass
|
|
|
|
|
|
public static function notifyOneTomorrow($shop, $giftId)
|
|
|
{
|
|
|
- self::ensureYearRecords($shop);
|
|
|
+ $re = self::ensureYearRecords($shop);
|
|
|
+ if ($re === false) {
|
|
|
+ util::fail('会员等级设置异常');
|
|
|
+ }
|
|
|
$gift = self::getById($giftId, true);
|
|
|
if (empty($gift) || intval($gift->shopId) != intval($shop->id)) {
|
|
|
util::fail('记录不存在');
|