123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\adminapi\controller\v1\user;
- use app\services\user\UserServices;
- use app\adminapi\controller\AuthController;
- use think\exception\ValidateException;
- use think\facade\App;
- class User extends AuthController
- {
- /**
- * user constructor.
- * @param App $app
- * @param UserServices $services
- */
- public function __construct(App $app, UserServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
- /**
- * 用户列表
- * @return mixed
- */
- public function index()
- {
- $where = $this->request->getMore([
- ['page', 1],
- ['limit', 20],
- ['nickname', ''],
- ['status', ''],
- ['pay_count', ''],
- ['is_promoter', ''],
- ['order', ''],
- ['data', ''],
- ['user_type', ''],
- ['country', ''],
- ['province', ''],
- ['city', ''],
- ['user_time_type', ''],
- ['user_time', ''],
- ['sex', ''],
- [['level', 0], 0],
- [['group_id', 'd'], 0],
- ['label_id', ''],
- ['now_money', 'normal'],
- ['field_key', ''],
- ['isMember', '']
- ]);
- $where['label_id'] = stringToIntArray($where['label_id']);
- return app('json')->success($this->services->index($where));
- }
- /**
- * 添加用户表单
- * @return mixed
- * @throws \FormBuilder\Exception\FormBuilderException
- */
- public function create()
- {
- return app('json')->success($this->services->saveForm());
- }
- /**
- * 添加编辑用户信息时候的信息
- * @param $uid
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function userSaveInfo($uid = 0)
- {
- $data = $this->services->getUserSaveInfo($uid);
- return app('json')->success($data);
- }
- /**
- * 保存新建用户
- * @return mixed
- * @throws \think\Exception
- */
- public function save()
- {
- $data = $this->request->postMore([
- ['real_name', ''],
- ['phone', 0],
- ['birthday', ''],
- ['card_id', ''],
- ['addres', ''],
- ['mark', ''],
- ['pwd', ''],
- ['true_pwd', ''],
- ['level', 0],
- ['group_id', 0],
- ['label_id', []],
- ['spread_open', 1],
- ['is_promoter', 0],
- ['status', 0]
- ]);
- if (!$data['real_name']) {
- return app('json')->fail(410245);
- }
- if (!$data['phone']) {
- return app('json')->fail(410245);
- }
- if (!check_phone($data['phone'])) {
- return app('json')->fail(400252);
- }
- if ($this->services->count(['phone' => $data['phone'], 'is_del' => 0])) {
- return app('json')->fail(400314);
- }
- $data['nickname'] = $data['real_name'];
- if ($data['card_id']) {
- if (!check_card($data['card_id'])) return app('json')->fail(400315);
- }
- if (!$data['pwd']) {
- return app('json')->fail(400256);
- }
- if (!$data['true_pwd']) {
- return app('json')->fail(400263);
- }
- if ($data['pwd'] != $data['true_pwd']) {
- return app('json')->fail(400264);
- }
- if (strlen($data['pwd']) < 6 || strlen($data['pwd']) > 32) {
- return app('json')->fail(400762);
- }
- $data['pwd'] = md5($data['pwd']);
- unset($data['true_pwd']);
- $data['avatar'] = sys_config('h5_avatar');
- $data['adminId'] = $this->adminId;
- $data['user_type'] = 'h5';
- $label = $data['label_id'];
- unset($data['label_id']);
- foreach ($label as $k => $v) {
- if (!$v) {
- unset($label[$k]);
- }
- }
- $data['birthday'] = empty($data['birthday']) ? 0 : strtotime($data['birthday']);
- $data['add_time'] = time();
- $this->services->transaction(function () use ($data, $label) {
- $res = true;
- $userInfo = $this->services->save($data);
- $this->services->rewardNewUser((int)$userInfo->uid);
- if ($label) {
- $res = $this->services->saveSetLabel([$userInfo->uid], $label);
- }
- if ($data['level']) {
- $res = $this->services->saveGiveLevel((int)$userInfo->uid, (int)$data['level']);
- }
- if (!$res) {
- return app('json')->fail(100006);
- }
- });
- return app('json')->success(100021);
- }
- /**
- * 获取用户账户详情
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function read($id)
- {
- if (is_string($id)) {
- $id = (int)$id;
- }
- return app('json')->success($this->services->read($id));
- }
- /**
- * 赠送会员等级表单
- * @param $id
- * @return mixed
- */
- public function give_level($id)
- {
- if (!$id) return app('json')->fail(100100);
- return app('json')->success($this->services->giveLevel((int)$id));
- }
- /**
- * 执行赠送会员等级
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function save_give_level($id)
- {
- if (!$id) return app('json')->fail(100100);
- list($level_id) = $this->request->postMore([
- ['level_id', 0],
- ], true);
- return app('json')->success($this->services->saveGiveLevel((int)$id, (int)$level_id) ? 400218 : 400219);
- }
- /**
- * 赠送付费会员时长表单
- * @param $id
- * @return mixed
- * @throws \FormBuilder\Exception\FormBuilderException
- */
- public function give_level_time($id)
- {
- if (!$id) return app('json')->fail(100100);
- return app('json')->success($this->services->giveLevelTime((int)$id));
- }
- /**
- * 执行赠送付费会员时长
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function save_give_level_time($id)
- {
- if (!$id) return app('json')->fail(100100);
- list($days) = $this->request->postMore([
- ['days', 0],
- ], true);
- return app('json')->success($this->services->saveGiveLevelTime((int)$id, (int)$days) ? 400218 : 400219);
- }
- /**
- * 清除会员等级
- * @param $id
- * @return mixed
- */
- public function del_level($id)
- {
- if (!$id) return app('json')->fail(100100);
- return app('json')->success($this->services->cleanUpLevel((int)$id) ? 400185 : 400186);
- }
- /**
- * 设置会员分组
- * @return mixed
- */
- public function set_group()
- {
- list($uids) = $this->request->postMore([
- ['uids', []],
- ], true);
- if (!$uids) return app('json')->fail(100100);
- return app('json')->success($this->services->setGroup($uids));
- }
- /**
- * 保存会员分组
- * @return mixed
- */
- public function save_set_group()
- {
- list($group_id, $uids) = $this->request->postMore([
- ['group_id', 0],
- ['uids', ''],
- ], true);
- if (!$uids) return app('json')->fail(100100);
- if (!$group_id) return app('json')->fail(400316);
- $uids = explode(',', $uids);
- return app('json')->success($this->services->saveSetGroup($uids, (int)$group_id) ? 100014 : 100015);
- }
- /**
- * 设置用户标签
- * @return mixed
- */
- public function set_label()
- {
- list($uids) = $this->request->postMore([
- ['uids', []],
- ], true);
- $uid = implode(',', $uids);
- if (!$uid) return app('json')->fail(100100);
- return app('json')->success($this->services->setLabel($uids));
- }
- /**
- * 保存用户标签
- * @return mixed
- */
- public function save_set_label()
- {
- list($lables, $uids) = $this->request->postMore([
- ['label_id', []],
- ['uids', ''],
- ], true);
- if (!$uids) return app('json')->fail(100100);
- if (!$lables) return app('json')->fail(400317);
- $uids = explode(',', $uids);
- return app('json')->success($this->services->saveSetLabel($uids, $lables) ? 100014 : 100015);
- }
- /**
- * 编辑其他
- * @param $id
- * @return mixed
- * @throws \FormBuilder\Exception\FormBuilderException
- */
- public function edit_other($id)
- {
- if (!$id) return app('json')->fail(100026);
- return app('json')->success($this->services->editOther((int)$id));
- }
- /**
- * 执行编辑其他
- * @param $id
- * @return mixed
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function update_other($id)
- {
- $data = $this->request->postMore([
- ['money_status', 0],
- ['money', 0],
- ['integration_status', 0],
- ['integration', 0],
- ]);
- if (!$id) return app('json')->fail(100100);
- $data['adminId'] = $this->adminId;
- $data['money'] = (string)$data['money'];
- $data['integration'] = (string)$data['integration'];
- $data['is_other'] = true;
- return app('json')->success($this->services->updateInfo($id, $data) ? 100001 : 100007);
- }
- /**
- * 编辑会员信息
- * @param $id
- * @return mixed
- * @throws \FormBuilder\Exception\FormBuilderException
- */
- public function edit($id)
- {
- if (!$id) return app('json')->fail(100100);
- return app('json')->success($this->services->edit($id));
- }
- /**
- * 修改用户
- * @param $id
- * @return mixed
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function update($id)
- {
- $data = $this->request->postMore([
- ['money_status', 0],
- ['is_promoter', 0],
- ['real_name', ''],
- ['card_id', ''],
- ['birthday', ''],
- ['mark', ''],
- ['money', 0],
- ['integration_status', 0],
- ['integration', 0],
- ['status', 0],
- ['level', 0],
- ['phone', 0],
- ['addres', ''],
- ['label_id', []],
- ['group_id', 0],
- ['pwd', ''],
- ['true_pwd'],
- ['spread_open', 1]
- ]);
- if (!$id) return app('json')->fail(100100);
- if (!$data['real_name']) {
- return app('json')->fail(410245);
- }
- if (!$data['phone']) {
- return app('json')->fail(410245);
- }
- if ($data['phone']) {
- if (!preg_match("/^1[3456789]\d{9}$/", $data['phone'])) return app('json')->fail(400252);
- }
- if ($this->services->count(['phone' => $data['phone'], 'is_del' => 0, 'not_uid' => $id])) {
- return app('json')->fail(400314);
- }
- if ($data['card_id']) {
- if (!check_card($data['card_id'])) return app('json')->fail(400315);
- }
- if ($data['pwd']) {
- if (!$data['true_pwd']) {
- return app('json')->fail(400263);
- }
- if ($data['pwd'] != $data['true_pwd']) {
- return app('json')->fail(400264);
- }
- if (strlen($data['pwd']) < 6 || strlen($data['pwd']) > 32) {
- return app('json')->fail(400762);
- }
- $data['pwd'] = md5($data['pwd']);
- } else {
- unset($data['pwd']);
- }
- unset($data['true_pwd']);
- $data['adminId'] = $this->adminId;
- $data['money'] = (string)$data['money'];
- $data['integration'] = (string)$data['integration'];
- return app('json')->success($this->services->updateInfo($id, $data) ? 100001 : 100007);
- }
- /**
- * 获取单个用户信息
- * @param $id
- * @return mixed
- */
- public function oneUserInfo($id)
- {
- $data = $this->request->getMore([
- ['type', ''],
- ]);
- $id = (int)$id;
- if ($data['type'] == '') return app('json')->fail(100100);
- return app('json')->success($this->services->oneUserInfo($id, $data['type']));
- }
- /**
- * 同步微信粉丝用户
- * @return mixed
- */
- public function syncWechatUsers()
- {
- $this->services->syncWechatUsers();
- return app('json')->success(400318);
- }
- }
|