UserIntegralService.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace bizMall\user\services;
  3. use bizMall\base\services\BaseService;
  4. use bizMall\merchant\services\MerchantService;
  5. use common\services\xhMerchantExtendService;
  6. use common\services\xhTMessageService;
  7. use common\services\xhUserAssetService;
  8. use common\services\xhUserService;
  9. use Yii;
  10. use common\components\wxUtil;
  11. class UserIntegralService extends BaseService
  12. {
  13. //增加成长值引导等级增加 ssh 2019.12.1
  14. public static function increaseToUpgrade($preGrowth, $growth, $preLevel, $userId, $sjId, $merchantExtend)
  15. {
  16. if ($growth <= $preGrowth) {
  17. return ['status' => false, 'msg' => '没有增加积分'];
  18. }
  19. //获取会员积分等级关系
  20. $gradeList = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
  21. if (empty($gradeList)) {
  22. return ['status' => false, 'msg' => '没有会员等级信息'];
  23. }
  24. $gainLevel = 0;
  25. $gainDiscount = 1;
  26. foreach ($gradeList as $key => $val) {
  27. $currentLevel = (int)$val['level'];
  28. $currentGrowth = (int)$val['growth'];
  29. $gradeDiscount = $val['discount'];
  30. if ($growth >= $currentGrowth && $preLevel < $currentLevel) {
  31. $gainLevel = $currentLevel;
  32. $gainDiscount = $gradeDiscount;
  33. break;
  34. }
  35. }
  36. if (empty($gainLevel)) {//会员积分达到新等级
  37. return ['status' => false, 'msg' => '没有升级'];
  38. }
  39. xhUserAssetService::updateByUserId($userId, ['member' => $gainLevel,'discount'=>$gainDiscount]);
  40. UserService::updateById($userId, ['member' => $gainLevel]);
  41. $allTM = xhTMessageService::getList($sjId);//积分变动通知
  42. $shortTempId = 'OPENTM205211943';
  43. if (isset($allTM[$shortTempId]) == false) {
  44. return ['status' => false, 'msg' => '已升级未通知,没有找到消息系统'];
  45. }
  46. $merchant = MerchantService::getBYId($sjId);
  47. $user = UserService::getById($userId);
  48. $openId = isset($user['openId']) ? $user['openId'] : '';
  49. if (empty($openId)) {
  50. return ['status' => false, 'msg' => '已升级未通知,客户信息不完整'];
  51. }
  52. $tempId = $allTM[$shortTempId];
  53. $tmData = [
  54. "touser" => $openId,
  55. "template_id" => $tempId,
  56. "url" => Yii::$app->params['mallDomain'] . '/#/pages/home/user?account=' . $merchant['id'],
  57. "data" => [
  58. "first" => ["value" => "恭喜,您已升为{$gainLevel}级会员。购物享{$gainDiscount}折优惠", "color" => "#173177"],
  59. "keyword1" => ["value" => $user['userName'], "color" => "#173177"],
  60. "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
  61. "remark" => ["value" => "祝您生活愉快!", "color" => "#173177"],
  62. ],
  63. ];
  64. wxUtil::sendTaskInform($tmData, $merchant);
  65. }
  66. }