UserController.php 3.0 KB

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