|
|
@@ -4,63 +4,68 @@ namespace biz\user\services;
|
|
|
|
|
|
|
|
|
use biz\base\services\BaseService;
|
|
|
-use common\components\util;
|
|
|
-
|
|
|
+use biz\merchant\services\MerchantService;
|
|
|
use common\services\xhMerchantExtendService;
|
|
|
use common\services\xhTMessageService;
|
|
|
use common\services\xhUserAssetService;
|
|
|
use common\services\xhUserService;
|
|
|
use Yii;
|
|
|
-use linslin\yii2\curl;
|
|
|
-use common\components\stringUtil;
|
|
|
-use common\components\configDict;
|
|
|
use common\components\weixinUtil;
|
|
|
-use common\models\xhUser;
|
|
|
+
|
|
|
|
|
|
class UserIntegralService extends BaseService
|
|
|
{
|
|
|
- /**
|
|
|
- * 增加积分并升级
|
|
|
- */
|
|
|
- public static function increaseToUpgrade($preIntegral, $integral, $preLevel, $userId, $merchantId, $merchantExtend)
|
|
|
+
|
|
|
+ //增加成长值引导等级增加 shish 2019.12.1
|
|
|
+ public static function increaseToUpgrade($preGrowth, $growth, $preLevel, $userId, $merchantId, $merchantExtend)
|
|
|
{
|
|
|
- if ($integral <= $preIntegral) {
|
|
|
+ if ($growth <= $preGrowth) {
|
|
|
return ['status' => false, 'msg' => '没有增加积分'];
|
|
|
}
|
|
|
- $gradeList = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');//获取会员积分等级关系
|
|
|
+ //获取会员积分等级关系
|
|
|
+ $gradeList = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
|
|
|
if (empty($gradeList)) {
|
|
|
return ['status' => false, 'msg' => '没有会员等级信息'];
|
|
|
}
|
|
|
$gainLevel = 0;
|
|
|
$gainDiscount = 0;
|
|
|
foreach ($gradeList as $key => $val) {
|
|
|
- $gradeLevel = (int)$val['level'];
|
|
|
- $gradePoint = (int)$val['integral'];
|
|
|
+ $currentLevel = (int)$val['level'];
|
|
|
+ $currentGrowth = (int)$val['growth'];
|
|
|
$gradeDiscount = $val['discount'];
|
|
|
- if ($integral >= $gradePoint && $preLevel < $gradeLevel) {
|
|
|
- $gainLevel = $gradeLevel;
|
|
|
+ if ($growth >= $currentGrowth && $preLevel < $currentLevel) {
|
|
|
+ $gainLevel = $currentLevel;
|
|
|
$gainDiscount = $gradeDiscount;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if (!empty($gainLevel)) {//会员积分达到新等级
|
|
|
- xhUserService::updateById($userId, ['isMember' => 1]);
|
|
|
- xhUserAssetService::updateByUserId($userId, ['memberLevel' => $gradeLevel, 'isMember' => 1]);
|
|
|
-
|
|
|
- $allTM = xhTMessageService::getList($merchantId);//积分变动通知
|
|
|
- $shortTempId = 'OPENTM205211943';
|
|
|
- if (isset($allTM[$shortTempId])) {
|
|
|
- $tempId = $allTM[$shortTempId];
|
|
|
- $tmData = ["touser" => $openId, "template_id" => $tempId,
|
|
|
- "url" => Yii::$app->params['frontUrl'] . '/center/right?account=' . $merchant['id'],
|
|
|
- "data" => [
|
|
|
- "first" => ["value" => "恭喜,您已升为{$gainLevel}级会员。购物享{$gainDiscount}折优惠", "color" => "#173177"],
|
|
|
- "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
|
|
|
- "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
|
|
|
- "remark" => ["value" => "祝您生活愉快!", "color" => "#173177"],],];
|
|
|
- //weixinUtil::sendTaskInform($tmData, $merchant);
|
|
|
- }
|
|
|
+ if (empty($gainLevel)) {//会员积分达到新等级
|
|
|
+ return ['status' => false, 'msg' => '没有升级'];
|
|
|
+ }
|
|
|
+ xhUserService::updateById($userId, ['isMember' => 1]);
|
|
|
+ xhUserAssetService::updateByUserId($userId, ['memberLevel' => $gainLevel, 'isMember' => 1]);
|
|
|
+
|
|
|
+ $allTM = xhTMessageService::getList($merchantId);//积分变动通知
|
|
|
+ $shortTempId = 'OPENTM205211943';
|
|
|
+ if (isset($allTM[$shortTempId]) == false) {
|
|
|
+ return ['status' => false, 'msg' => '已升级未通知,没有找到消息系统'];
|
|
|
+ }
|
|
|
+ $merchant = MerchantService::getBYId($merchantId);
|
|
|
+ $user = UserService::getById($userId);
|
|
|
+ $openId = isset($user['openId']) ? $user['openId'] : '';
|
|
|
+ if (empty($openId)) {
|
|
|
+ return ['status' => false, 'msg' => '已升级未通知,客户信息不完整'];
|
|
|
}
|
|
|
+ $tempId = $allTM[$shortTempId];
|
|
|
+ $tmData = ["touser" => $openId, "template_id" => $tempId,
|
|
|
+ "url" => Yii::$app->params['frontUrl'] . '/center/right?account=' . $merchant['id'],
|
|
|
+ "data" => [
|
|
|
+ "first" => ["value" => "恭喜,您已升为{$gainLevel}级会员。购物享{$gainDiscount}折优惠", "color" => "#173177"],
|
|
|
+ "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
|
|
|
+ "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
|
|
|
+ "remark" => ["value" => "祝您生活愉快!", "color" => "#173177"],],];
|
|
|
+ weixinUtil::sendTaskInform($tmData, $merchant);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|