UserController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Yii;
  10. use common\components\stringUtil;
  11. use common\components\util;
  12. class UserController extends BaseController
  13. {
  14. public $enableCsrfValidation = false;
  15. //客户列表 shish 2019.11.30
  16. public function actionGetList()
  17. {
  18. $get = Yii::$app->request->get();
  19. //组建where
  20. $type = isset($get['type']) ? $get['type'] : 0;
  21. $search = isset($get['search']) ? $get['search'] : '';
  22. $where = ['merchantId' => $this->merchantId];
  23. switch ($type) {
  24. case 1:
  25. //粉丝
  26. $where['subscribe'] = 1;
  27. break;
  28. case 2:
  29. //会员
  30. $where['isMember'] = 1;
  31. break;
  32. default:
  33. }
  34. if (!empty($search)) {
  35. if (stringUtil::isMobieNumber($search)) {
  36. $where['mobile'] = $search;
  37. } else {
  38. $where['userName'] = ['like', $search];
  39. }
  40. }
  41. $list = UserService::getUserList($where);
  42. util::success($list);
  43. }
  44. //获取客户基本和资产信息 shish 2019.11.30
  45. public function actionGetInfo()
  46. {
  47. $userId = Yii::$app->request->get('userId');
  48. $info = UserService::getUserInfo($userId);
  49. if (isset($info['merchantId']) == false || $this->merchantId != $info['merchantId']) {
  50. util::fail('没有权限');
  51. }
  52. util::success($info);
  53. }
  54. //获取客户基本、资产和订单完整信息 2019.11.30
  55. public function actionGetFullInfo()
  56. {
  57. $userId = Yii::$app->request->get('userId');
  58. $info = UserService::getFullUserInfo($userId);
  59. if (isset($info['merchantId']) == false || $this->merchantId != $info['merchantId']) {
  60. util::fail('没有权限');
  61. }
  62. util::success($info);
  63. }
  64. //添加客户,申请会员时会自动同步资产 shish 2019.11.30
  65. public function actionAdd()
  66. {
  67. $post = Yii::$app->request->post();
  68. if ($post['mobile'] != $post['confirmMobile']) {
  69. util::fail('二次输入手机号不一样');
  70. }
  71. $confirmPassword = isset($post['confirmPassword']) ? $post['confirmPassword'] : '';
  72. $verify = AdminService::verifyConfirmPassword($this->adminId, $confirmPassword);
  73. if ($verify == false) {
  74. util::fail('密码错误');
  75. }
  76. $mobile = $post['mobile'];
  77. $user = UserService::getByMobile($mobile);
  78. if (!empty($user)) {
  79. util::fail('手机号已使用,客户已存在');
  80. }
  81. $originalInfo = [];
  82. $merchantId = $this->merchantId;
  83. $originalInfo['merchantId'] = $merchantId;
  84. $originalInfo['mobile'] = $mobile;
  85. $originalInfo['realName'] = $post['realName'];
  86. $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
  87. $source = $userSource['name'];
  88. $user = UserService::replaceUser($originalInfo, $source, $merchantId);
  89. //等级
  90. $memberLevel = isset($post['memberLevel']) ? $post['memberLevel'] : 0;
  91. $extend = MerchantExtendService::getByMerchantId($this->merchantId);
  92. $gradeList = xhMerchantExtendService::getGradeList($extend, 'desc');
  93. $growth = isset($gradeList[$memberLevel]['growth']) ? $gradeList[$memberLevel]['growth'] : 0;
  94. //余额成长值更新
  95. $userId = $user['id'];
  96. $balance = isset($post['balance']) && is_numeric($post['balance']) ? $post['balance'] : 0;
  97. $data = ['balance' => $balance,'growth'=>$growth];
  98. UserAssetService::updateByUserId($userId, $data);
  99. //会员升级
  100. UserIntegralService::increaseToUpgrade(0, $growth, 0, $userId, $merchantId, $extend);
  101. util::ok();
  102. }
  103. }