| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace bizMall\user\services;
- use bizMall\base\services\BaseService;
- use bizMall\merchant\services\MerchantService;
- use common\services\xhMerchantExtendService;
- use common\services\xhTMessageService;
- use common\services\xhUserAssetService;
- use common\services\xhUserService;
- use Yii;
- use common\components\wxUtil;
- class UserIntegralService extends BaseService
- {
- //增加成长值引导等级增加 ssh 2019.12.1
- public static function increaseToUpgrade($preGrowth, $growth, $preLevel, $userId, $sjId, $merchantExtend)
- {
- if ($growth <= $preGrowth) {
- return ['status' => false, 'msg' => '没有增加积分'];
- }
- //获取会员积分等级关系
- $gradeList = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
- if (empty($gradeList)) {
- return ['status' => false, 'msg' => '没有会员等级信息'];
- }
- $gainLevel = 0;
- $gainDiscount = 1;
- foreach ($gradeList as $key => $val) {
- $currentLevel = (int)$val['level'];
- $currentGrowth = (int)$val['growth'];
- $gradeDiscount = $val['discount'];
- if ($growth >= $currentGrowth && $preLevel < $currentLevel) {
- $gainLevel = $currentLevel;
- $gainDiscount = $gradeDiscount;
- break;
- }
- }
- if (empty($gainLevel)) {//会员积分达到新等级
- return ['status' => false, 'msg' => '没有升级'];
- }
- xhUserAssetService::updateByUserId($userId, ['member' => $gainLevel,'discount'=>$gainDiscount]);
- UserService::updateById($userId, ['member' => $gainLevel]);
-
- $allTM = xhTMessageService::getList($sjId);//积分变动通知
- $shortTempId = 'OPENTM205211943';
- if (isset($allTM[$shortTempId]) == false) {
- return ['status' => false, 'msg' => '已升级未通知,没有找到消息系统'];
- }
- $merchant = MerchantService::getBYId($sjId);
- $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['mallDomain'] . '/#/pages/home/user?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"],
- ],
- ];
- wxUtil::sendTaskInform($tmData, $merchant);
-
- }
-
- }
|