* @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)); } }