| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- <?php
- namespace app\admin\controller\users;
- use app\common\controller\AdminController;
- use app\http\IResponse;
- use think\Db;
- class User extends AdminController
- {
- /**
- * 获取系统会员列表
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/11 14:10
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $where = [];
- //组合搜索
- !empty(input('mobile')) && $where[]
- = ['mobile', 'like', '%' . input('mobile') . '%'];
- !empty(input('card_id')) && $where[]
- = ['card_id', 'like', '%' . input('card_id') . '%'];
- !empty(input('nickname')) && $where[]
- = ['nickname', 'like', '%' . input('nickname') . '%'];
- (!empty(input('is_agent')) || input('is_agent') == '0') &&
- $where[] = ['is_agent', 'eq', input('is_agent')];
- (!empty(input('is_seller')) || input('is_seller') == '0') &&
- $where[] = ['is_seller', 'eq', input('is_seller')];
- (!empty(input('is_verify')) || input('is_verify') == '0') &&
- $where[] = ['is_verify', 'eq', input('is_verify')];
- (!empty(input('gender')) || input('gender') == '0') &&
- $where[] = ['gender', 'eq', input('gender')];
- (!empty(input('status')) || input('status') == '0') &&
- $where[] = ['status', 'eq', input('status')];
- // 时间处理
- if (!empty(input('created_at'))){
- list($start, $end) = str2arr(input('created_at'),'-');
- $where[] = ['created_at', 'between', [strtotime($start), strtotime($end)]];
- }
- return IResponse::paginate(model('common/Users')->where($where)->with(['recommend'])
- ->order(['created_at' => 'desc'])
- ->paginate(input('limit'),false));
- }
- /**
- * 更新数据
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/11 14:20
- *
- * @param $id
- * @return \think\response\Json
- */
- public function update($id)
- {
- // 接收数据
- $params = $this->request->param();
- // 查询用户
- $user = model('common/Users')->findBy($id);
- // 是否更改状态操作
- if (isset($params['status']) && $params['status'] != '') {
- $valid = $this->validate($params, [
- 'status|配置状态' => 'require|integer'
- ]);
- }else {
- // 数据校验
- $valid = $this->validate($params, [
- 'email|账号' => 'require|email',
- 'username|用户名' => 'require|alpha'
- ]);
- }
- // 错误返回
- (true !== $valid) && IResponse::failure($valid);
- // 更新用户信息
- $user->updateBy($id, $params);
- return IResponse::success('更新用户信息成功');
- }
- /**
- * 删除
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/11 14:26
- *
- * @param $id
- * @return \think\response\Json
- */
- public function delete($id)
- {
- model('common/Users')->deleteBy($id);
- return IResponse::success([],'删除用户成功');
- }
- /**
- * 用户批量操作
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/11 14:34
- *
- * @return mixed
- */
- public function plectron(){
- // 收参数
- $params = $this->request->param();
-
-
- foreach (str2arr($params['ids']) as $id){
- $user = model('common/Users')->getBy($id);
- if ($this->request->isDelete()){
- $user->deleteBy($id);
- }
- //表里不存ids这个字段,要把ids改回表对应的字段名:id
-
- //user这个模型没有updateBy这个方法,所以回报错,既然循环,也不可能直接单个id对应
- // $user->allowField(true)->updateBy($id, $params);
- //懒得去补模型的方法了,我直接用原生写法对表操作了。
- //2022-3-3 丘 改动
-
-
- //判断 原状态 和 修改致状态 未交费之前 冻结,启用动作 都忽略;
-
-
- $olduser=Db::table('ins_users_motor_agent')->where('id',$id)->find();
- if(!$olduser){
- return IResponse::failure('用户不存在!');
- }
-
- if( $params['status']==40){
- if($olduser['status']<40){
- //没有通过交费 啥也不做
- }else{
- //做解冻,或冬季操作
- $res=Db::table('ins_users_motor_agent')->update(['status' => $params['status'],'id'=>$id]);
- }
- }
-
- if( $params['status']==50){
- if($olduser['status']<40){
- //没有通过交费 啥也不做
- }else{
- //做解冻,或冬季操作
- $res=Db::table('ins_users_motor_agent')->update(['status' => $params['status'],'id'=>$id]);
- }
- }
-
-
-
-
-
- }
- return IResponse::success([],'操作成功');
- }
- /**
- * 恢复删除用户
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/11 14:46
- *
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function restore($id)
- {
- // 查询数据
- $user = model('common/Users')->onlyTrashed()->find($id);
- if (!$user){
- return IResponse::failure('用户不存在!');
- }
- // 恢复
- return $user->restore() ? IResponse::success('恢复用户成功!')
- : IResponse::failure('恢复用户失败!');
- }
- // 取消用户代理身份
- public function userCancelAgent($id){
- // 读取用户
- $user = model('common/Users')->findBy($id);
- if(!$user){
- return IResponse::failure('用户不存在!');
- }
- // 读取代理
- $agent = model('common/UsersAgent')->getBy(['user_id' => $id]);
- if(!$agent && !$user['is_agent']){
- return IResponse::failure('当前用户不是代理!');
- }
- // 删除当前代理
- model('common/UsersAgent')->deleteBy(['user_id' => $id]);
- // 更改数据
- model('common/Users')->updateBy($id,[
- 'is_agent' => "0"
- ]);
- return IResponse::success('已取消用户代理身份!');
- }
- /**
- * 获取用户资金记录
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/9 11:01
- *
- * @param $id
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function userVerify($id)
- {
- $verify = model('common/UsersVerify')
- ->getBy(['user_id' => $id]);
- if (!$verify){
- return IResponse::failure("查找不到");
- }
- // 更新信息
- if ($this->request->isPost()){
- // 接收参数
- $params = $this->request->param();
- // 参数校验
- $valid = $this->validate($params, [
- 'name|真实姓名' => 'require',
- 'id_card|身份证号' => 'require',
- 'id_card_img|身份证信息' => 'require',
- 'status|状态' => 'require'
- ]);
- // 错误返回
- if(true !== $valid){
- return IResponse::failure($valid);
- }
- // 用户修改
- model('common/Users')->updateBy($verify['user_id'],[
- 'is_verify' => $params['status']
- ]);
- // 用户修改
- model('common/UsersVerify')->updateBy($verify['id'],[
- 'status' => $params['status']
- ]);
-
- return IResponse::success('提交成功');
-
- }
- return IResponse::success($verify);
- }
- /**
- * 代理列表
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/15 11:49
- *
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function getUserAgent()
- {
- return IResponse::paginate(model('common/UsersAgent')->with(['user','area'])
- ->paginate(input('limit'),false));
- }
- /**
- * 用户代理信息
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/14 18:28
- *
- * @param $id
- * @return mixed
- */
- public function userAgent($id)
- {
- $agent = model('common/UsersAgent')
- ->getBy(['user_id' => $id]);
- if (!$agent){
- return IResponse::failure("查找不到");
- }
- // 更新信息
- if ($this->request->isPost()) {
- // 接收参数
- $params = $this->request->param();
- // 参数校验
- $valid = $this->validate($params, [
- 'status|状态' => 'require'
- ]);
- // 错误返回
- if (true !== $valid) {
- return IResponse::failure($valid);
- }
- // 是否已经存在
- $isV = model('common/UsersAgent')->getBy(['area_id' => $agent['area_id'],'status' => 2]);
-
- if($isV){
-
- // 修改申请
- model('common/UsersAgent')::update([
- 'status' => '0',
- 'deleted_at' => time()
- ],['user_id' => $agent['user_id']]);
-
- return IResponse::failure("当前区域已经存在代理!");
- }
- // 更新数据
- $ret = $agent->updateBy($agent['id'], $params);
- // 用户修改
- model('common/Users')->updateBy($agent['user_id'], [
- 'is_agent' => $params['status']
- ]);
- // 修改申请
- model('common/UsersAgent')::update([
- 'status' => $params['status']
- ],['user_id' => $agent['user_id']]);
- // 消息
- if ($ret) {
- return IResponse::success('提交成功');
- }
- return IResponse::failure('数据异常,请稍后再试');
- }
- $agent['area'] = db('china')->where(['id' => $agent['area_id']])->value('name');
- return IResponse::success($agent);
- }
- /**
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/8/10 13:34
- *
- * @return mixed
- */
- public function balanceRecharge()
- {
- // 接收数据
- $params = $this->request->param();
- // 数据校验
- $valid = $this->validate($params, [
- 'user|会员编号/手机号' => 'require',
- 'amount|充值金额' => 'require'
- ]);
- // 错误返回
- (true !== $valid) && IResponse::failure($valid);
- // 查询用户
- $user = model('common/Users')->where(['card_id|mobile' => $params['user']])->find();
- if (!$user || $user['status'] !== 1){
- return IResponse::failure("用户不存在或者已被禁用");
- }
- $result = false;
- Db::startTrans();
- try {
- // 资金
- $amount = round($params['amount'], 2);
- // // 1. 写入交易单
- // model('common/UsersBalanceRecharge')::create([
- // 'user_id' => $user['id'],
- // 'charge_no' => get_order_no(),
- // 'pay_type' => "system",
- // 'amount' => $amount,
- // 'status' => 2
- // ],true);
- // 2. 资金记录
- $result = model('common/Users')->changeBalance(
- $user['id'],
- $amount,
- "系统充值,充值金额【" . $amount . '】',
- true
- );
- $result = true;
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- }
- return $result ? IResponse::success("充值成功") : IResponse::failure("充值失败");
- }
- /**
- * 获取用户资金记录 20201211 添加资产的查询
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/7/9 11:01
- *
- * @param $id
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function balanceRecord($id, $type)
- {
- $model = "UsersBalanceRecord";
- if($type == 'property'){
- $model = 'UsersPropertyRecord';
- }
-
- $withdraw = model('common/' . $model)
- ->where(['user_id' => $id])
- ->order(['id' => 'desc','updated_at'=>'desc']);
- return IResponse::paginate($withdraw->paginate(input('limit'),false));
- }
- }
|