UserController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace business\controllers;
  3. use biz\admin\services\AdminService;
  4. use biz\merchant\services\MerchantExtendService;
  5. use biz\user\services\UserAssetService;
  6. use biz\user\services\UserIntegralService;
  7. use biz\user\services\UserService;
  8. use common\services\xhMerchantExtendService;
  9. use common\services\xhRechargeService;
  10. use Yii;
  11. use common\components\stringUtil;
  12. use common\components\util;
  13. class UserController extends BaseController
  14. {
  15. public $enableCsrfValidation = false;
  16. //客户列表 shish 2019.11.30
  17. public function actionGetList()
  18. {
  19. $get = Yii::$app->request->get();
  20. //组建where
  21. $type = isset($get['type']) ? $get['type'] : 0;
  22. $search = isset($get['search']) ? $get['search'] : '';
  23. $where = ['merchantId' => $this->merchantId];
  24. switch ($type) {
  25. case 1:
  26. //粉丝
  27. $where['subscribe'] = 1;
  28. break;
  29. case 2:
  30. //会员
  31. $where['isMember'] = 1;
  32. break;
  33. default:
  34. }
  35. if (!empty($search)) {
  36. if (stringUtil::isMobieNumber($search)) {
  37. $where['mobile'] = $search;
  38. } else {
  39. $where['userName'] = ['like', $search];
  40. }
  41. }
  42. $list = UserService::getUserList($where);
  43. util::success($list);
  44. }
  45. //获取客户基本和资产信息 shish 2019.11.30
  46. public function actionGetInfo()
  47. {
  48. $userId = Yii::$app->request->get('userId');
  49. $info = UserService::getUserInfo($userId);
  50. if (isset($info['merchantId']) == false || $this->merchantId != $info['merchantId']) {
  51. util::fail('没有权限');
  52. }
  53. util::success($info);
  54. }
  55. //获取客户基本、资产和订单完整信息 2019.11.30
  56. public function actionGetFullInfo()
  57. {
  58. $userId = Yii::$app->request->get('userId');
  59. $info = UserService::getFullUserInfo($userId);
  60. if (isset($info['merchantId']) == false || $this->merchantId != $info['merchantId']) {
  61. util::fail('没有权限');
  62. }
  63. util::success($info);
  64. }
  65. //添加客户,申请会员时会自动同步资产 shish 2019.11.30
  66. public function actionAdd()
  67. {
  68. $post = Yii::$app->request->post();
  69. if ($post['mobile'] != $post['confirmMobile']) {
  70. util::fail('二次输入手机号不一样');
  71. }
  72. $confirmPassword = isset($post['confirmPassword']) ? $post['confirmPassword'] : '';
  73. $verify = AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
  74. if ($verify == false) {
  75. util::fail('密码错误');
  76. }
  77. $mobile = $post['mobile'];
  78. $user = UserService::getByMobile($mobile);
  79. if (!empty($user)) {
  80. util::fail('手机号已使用,客户已存在');
  81. }
  82. $originalInfo = [];
  83. $merchantId = $this->merchantId;
  84. $originalInfo['merchantId'] = $merchantId;
  85. $originalInfo['mobile'] = $mobile;
  86. $originalInfo['realName'] = $post['realName'];
  87. $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
  88. $source = $userSource['name'];
  89. $user = UserService::replaceUser($originalInfo, $source, $merchantId);
  90. //等级
  91. $memberLevel = isset($post['memberLevel']) ? $post['memberLevel'] : 0;
  92. $extend = MerchantExtendService::getByMerchantId($this->merchantId);
  93. $gradeList = xhMerchantExtendService::getGradeList($extend, 'desc');
  94. $growth = isset($gradeList[$memberLevel]['growth']) ? $gradeList[$memberLevel]['growth'] : 0;
  95. //余额成长值更新
  96. $userId = $user['id'];
  97. $balance = isset($post['balance']) && is_numeric($post['balance']) ? $post['balance'] : 0;
  98. $data = ['balance' => $balance, 'growth' => $growth];
  99. UserAssetService::updateByUserId($userId, $data);
  100. //会员升级
  101. UserIntegralService::increaseToUpgrade(0, $growth, 0, $userId, $merchantId, $extend);
  102. util::ok();
  103. }
  104. //充值 shish 2019.12.1
  105. public function actionRecharge()
  106. {
  107. $post = Yii::$app->request->post();
  108. $confirmPassword = isset($post['confirmPassword']) ? $post['confirmPassword'] : '';
  109. $verify = AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
  110. if ($verify == false) {
  111. util::fail('密码错误');
  112. }
  113. $userId = isset($post['userId']) ? $post['userId'] : 0;
  114. $rechargeAmount = isset($post['rechargeAmount']) ? $post['rechargeAmount'] : 1;
  115. $user = UserService::getById($userId);
  116. if (empty($user)) {
  117. util::fail('找不到客户');
  118. }
  119. if ($user['merchantId'] != $this->merchantId) {
  120. util::fail('您没有权限操作');
  121. }
  122. $userAsset = UserAssetService::getByUserId($userId);
  123. $totalBalance = $userAsset['balance'] + $rechargeAmount;
  124. $totalRecharge = $userAsset['totalRecharge'] + $rechargeAmount;
  125. $upData['balance'] = $totalBalance;
  126. $upData['totalRecharge'] = $totalRecharge;
  127. $return = xhRechargeService::recharge($rechargeAmount, $user, $this->adminId, $this->merchant, $this->merchantExtend, $this->merchantAsset);
  128. if ($return['code'] == 'A0001') {
  129. util::ok();
  130. }
  131. util::fail();
  132. }
  133. }