all(), [ //'mobile' => 'integer|min:4', 'real_name' => 'string' ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } $user = User::select(['id', 'mobile', 'password', 'real_name', 'is_super', 'status']); // 如果是地区管理员,则不显示同等级的用户信息 if (\Auth::user()->is_super == 3) { $user->where('level', '<', \Auth::user()->level); $user = $user->whereIn('id', getIds()); } if (!empty($param['mobile'])) { $user->where('mobile', 'like', "%{$param['mobile']}%"); } if (!empty($param['real_name'])) { $user->where('real_name', 'like', "%{$param['real_name']}%"); } $res = $user->paginate(perPage()); return showJsonSucc(1001, $res); } /** * 代理统计列表 * @author lyh * @date 2019/4/8 * @modify_author lyh * @modify_time 2019-4-26 11:26:31 * @modify 确认已区分系统管理员与地区管理员权限 * @description * 代理ID * 等级 * 昵称 * 手机 * 代理数量 * 代理费总(元) * 广告笔数 * 查询:时间、城区、手机号 */ public function StatProxy(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'mobile' => [ 'integer', ], 'start' => 'date', 'end' => 'date', 'province' => 'exists:area,id', 'city' => 'exists:area,id', 'district' => 'exists:area,id', ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } // if (Admin()->is_super == 3) { if (Admin()->level == 6 && isset($param['district']) && $param['district'] != Admin()->district) { return showJsonErr('抱歉,您不能查看该地区的信息'); } if (Admin()->level == 7 && isset($param['city']) && $param['city'] != Admin()->city) { return showJsonErr('抱歉,您不能查看该城市的信息'); } } $user = User::whereIsFrontend(1)->select([ 'id', 'level', 'nick_name', 'mobile', ]); // 时间查询 if (isset($param['start']) && isset($param['end'])) { $user->whereBetween('created_at', [$param['start'], $param['end']]); } // 手机号码查询 if (!empty($param['mobile'])) { $user->where('mobile', 'like', "%{$param['mobile']}%"); } //管理员查看对应的代理 $district=AdminArea::getAdminArea(); if(!empty($district)){ if(!empty($district['city'])){ $user->whereCity($district['city']); if (!empty($param['district'])) { $user->whereDistrict($param['district']); } }else{ $user->whereDistrict($district['district']); } }else{ if (isset($param['province']) && isset($param['province'])) { $user->where('province', '=',$param['province']); } if (isset($param['city']) && isset($param['city'])) { $user->where('city', '=',$param['city']); } if (isset($param['district']) && isset($param['district'])) { $user->where('district', '=',$param['district']); } } // 区分系统管理员与地区管理员的数据 if (\Auth::user()->is_super == 3) { $user = $user->whereIn('id', getIds()); } $res = $user->paginate(perPage()); if ($res->isNotEmpty()) { collect($res->items())->each(function ($item, $key) { // 代理数量 // 代理费总额 // 广告笔数 $uids = User::getAllInvite($item->id, null, null, true); $item->proxyNum = count($uids); $item->proxyTotalPrice = Upgrade::whereIn('uid', $uids)->whereUpgradeWay(1)->whereStatus(3)->sum('money'); $proxyarea = \DB::table('proxy_area as pa')->join('order as o', 'o.id', '=', 'pa.order_id') ->select(\DB::raw('sum(price) totalprice'))->where('pa.status', '=', 3) ->whereIn('pa.uid', $uids)->first(); $item->proxyTotalPrice=$item->proxyTotalPrice+ $proxyarea->totalprice; $item->adverNum = Advertising::whereIn('uid', $uids)->whereIn('status', [3, 4, 9])->count('id'); }); } return showJsonSucc(1001, $res); } /** * 发送信息 * @author lyh * @date 2019/4/9 * @modify_author lyh * @modify_time 2019-4-26 12:25:21 * @modify 确认已区分系统管理员与地区管理员权限 * @param Request $request * @description */ public function sendMsg(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'id' => 'required|exists:user,id', 'content' => 'required' ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } // 区分系统管理员与地区管理员数据 if (\Auth::user()->is_super == 3 && !in_array($param['id'], getIds())) { return showJsonErr('抱歉,您没有权限查看该用户信息'); } $title=empty($param['title'])?'':$param['title']; $result = UserMsg::SendGetui([ 'uid' => $param['id'], 'content' => $param['content'], 'type' => 1, 'title'=>$title, ]); if (!$result) { return showJsonError('发送私信失败'); } return showJsonSucc('发送私信成功'); } /** * 解除代理 * @author lyh * @date 2019/4/9 * @modify_author lyh * @modify_time 2019-4-26 12:24:51 * @modify 确认已区分系统管理员与地区管理员权限 * @param Request $request * @description */ public function relieve(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'id' => 'required|exists:user,id' ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } // 区分系统管理员与地区管理员数据 if (\Auth::user()->is_super == 3 && !in_array($param['id'], getIds())) { return showJsonErr('抱歉,您没有权限查看该用户信息'); } $user = User::find($param['id']); if (!in_array($user->level, [6, 7])) { return showJsonErr('抱歉,取消代理失败。'); } $result = User::whereId($param['id'])->update([ 'province' => 0, 'city' => 0, 'district' => 0, 'is_super' => 0 ]); if (!$result) { return showJsonError('取消地区代理失败'); } return showJsonSucc('取消地区代理成功'); } /** * 冻结、解冻 * @author lyh * @date 2019/4/9 * @modify_author lyh * @modify_time 2019-4-26 11:26:31 * @modify 确认已区分系统管理员与地区管理员权限 * @param Request $request * @description */ public function updateStatus(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'id' => 'required|exists:user,id', 'status' => 'required|integer|between:1,2' ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } // 区分系统管理员与地区管理员数据 if (\Auth::user()->is_super == 3 && !in_array($param['id'], getIds())) { return showJsonErr('抱歉,您没有权限查看该用户信息'); } $result = User::whereId($param['id'])->update(['status' => $param['status']]); if (!$result) { return showJsonError('修改用户状态失败'); } //添加进入冻结记录 $frozen=Frozen::whereUid($param['id'])->orderBy('id','desc')->first(); if(!empty($frozen->uid)&&empty($frozen->thaw_time)&&$param['status']==1){ //解冻 Frozen::whereId($frozen->id)->update(['thaw_time'=>date('Y-m-d H:i:s')]); }else{ //冻结 if((empty($frozen) && $param['status']==2)||!empty($frozen->thaw_time)){ Frozen::insert(['uid'=>$param['id']]); } } return showJsonSucc('修改用户状态成功'); } /** * 代理列表 * @author lyh * @date 2019/4/9 * @param Request $request * @description * 字段:ID、等级、代理费(元)、姓名、昵称、手机、推荐人手机号、城区、广告笔数、广告总业绩额(元)、广告分佣(%)、下级代理人数、代理分佣(%)、余额(元)、点币 * 查询:所在城区(省市区)、手机号、等级、注册时间 */ public function proxyList(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'province' => 'exists:area,id', 'city' => 'exists:area,id', 'district' => 'exists:area,id', // 'mobile' => 'integer', 'level' => 'integer|between:1,8', 'startTime' => 'date', 'endTime' => 'date', 'sort'=>'in:level,created_at,agentAllmoney,count,allMoney,adverCommission,invite_num,proxyCommission,coin,balance', 'order'=>'in:desc,asc,normal' ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } // zch 2019/08/14 新增排序 if (isset($param['sort'])) { switch ($param['sort']) { case 'agentAllmoney': $param['sort'] = 'agent_all_money'; break; case 'count': $param['sort'] = 'ad_num'; break; case 'allMoney': $param['sort'] = 'ad_all_money'; break; case 'adverCommission': $param['sort'] = 'adver_commission'; break; case 'proxyCommission': $param['sort'] = 'proxy_commission'; break; } $sort = $param['sort']; if (isset($param['order']) && $param['order']!='normal') { $order=$param['order']; }else{ $order = 'desc'; } }else{ $sort = 'id'; $order = 'desc'; } if (isset($param['order']) && $param['order']=='normal') { $sort = 'id'; $order = 'desc'; } // 如果当前管理员是地区管理员 if (Admin()->is_super == 3) { if (Admin()->level == 6 && isset($param['district']) && $param['district'] != Admin()->district) { return showJsonErr('抱歉,您不能查看该地区的信息'); } if (Admin()->level == 7 && isset($param['district']) && $param['city'] != Admin()->city) { return showJsonErr('抱歉,您不能查看该城市的信息'); } } $user = User::select([ 'id', 'level', 'nick_name', 'real_name', 'mobile', 'invitor', 'balance', 'coin', 'status', 'province', 'city', 'district', 'created_at', 'agent_all_money as agentAllmoney', 'ad_num as count', 'ad_all_money as allMoney', 'adver_commission as adverCommission', 'invite_num as invite_num', 'proxy_commission as proxyCommission', ]) ->orderBy($sort,$order) ->whereIsFrontend(1) // ->whereIn('level', [6, 7]) ->where('province', '!=', 0); // 如果是地区管理员,则不显示同等级的用户信息 if (\Auth::user()->is_super == 3) { //$user->where('level', '<', \Auth::user()->level); $user = $user->whereIn('id', getIds()); } else { //管理员查看对应的代理 $district=AdminArea::getAdminArea(); if(!empty($district)){ if(!empty($district['city'])){ $user->whereCity($district['city']); if (!empty($param['district'])) { $user->whereDistrict($param['district']); } }else{ $user->whereDistrict($district['district']); } }else{ // 地区查询 if (!empty($param['province'])) { $user->whereProvince($param['province']); } if (!empty($param['city'])) { $user->whereCity($param['city']); } if (!empty($param['district'])) { $user->whereDistrict($param['district']); } } } if(!empty($param['id']) && $param['id']!='undefined'){ $user->where('id','=',$param['id']); } if(!empty($param['status'])){ $user->where('status','=',$param['status']); } // 时间查询 if (!empty($param['startTime']) && !empty($param['endTime'])) { $user->whereBetween('created_at', [$param['startTime'], $param['endTime']]); } else if (!empty($param['endTime']) && empty($param['startTime'])) { $user->where('created_at', '<', $param['endTime']); } else if (empty($param['endTime']) && !empty($param['startTime'])) { $user->where('created_at', '>', $param['startTime']); } // 手机号码查询 if (!empty($param['mobile'])) { $user->where('mobile', 'like', "%{$param['mobile']}%"); } // 等级查询 if (!empty($param['level'])) { $user->whereLevel($param['level']); } $res = $user->paginate(perPage()); if ($res->isNotEmpty()) { collect($res->items())->each(function ($item, $key) { $item->invitor_mobile = User::find($item->invitor)->mobile ?? 0; $item->area = trim(Area::getName($item->province) . ' ' . Area::getName($item->city) . ' ' . Area::getName($item->district)); /** *@describe zch 为了做筛选已弃用,保留是为了预防有未知的bug,或遗漏的数据,以便恢复使用。 $adver = Advertising::whereUid($item->id) ->whereIn('status', [3, 4, 9]) ->select([ \DB::raw('count(id) count'), \DB::raw('sum(total_price) allMoney') ]) ->first(); $item->count=$adver->count; $item->allMoney=$adver->allMoney; $item->invite_num = count(User::getAllInvite($item->id, null, null, false)); // 邀请人数 $item->proxyCommission = AccountLog::whereIn('type', [20, 21, 22, 23])->whereStatus(1)->whereUid($item->id)->sum('money'); // 代理分佣 $item->adverCommission = AccountLog::whereIn('type', [10, 11, 12, 13])->whereStatus(1)->whereUid($item->id)->sum('money');//广告费分佣 $item->agentAllmoney = AccountLog::whereIn('type',[7,8])->whereStatus(1)->whereUid($item->id)->sum('money');//总的代理费 */ $proxyConfig = Proxy::whereUserLevel($item->level)->whereStatus(1)->whereUid($item->id)->whereAreaType(4)->first();//用户当前配置 $proxyAdverSet = $proxyConfig?$proxyConfig->only(['money', 'min_money','free_num']):''; $item->proxyAdverSet = $proxyAdverSet; //查看用户是否是区域代理,是的话就找出相关代理信息 $item->proxyarea=''; $item->invite_num = count(User::getAllInvite($item->id, null, null, false)); // 邀请人数 if($item->level>5&&!empty($item->province)&&!empty($item->city)&&!empty($item->district)){ $ps=ProxyArea::whereUid($item->id)->whereStatus(3)->get(); $parea=''; if(!empty($ps)){ foreach($ps as $pkey=>$pval){ $parea.=Area::whereId($pval->province)->value('name').' '.Area::whereId($pval->city)->value('name').Area::whereId($pval->district)->value('name').' '; } } $item->proxyarea=$parea; } //下级代理人数 // $allUids = User::getAllChilds($item->id); // $item->agent_num = count($allUids); }); } return showJsonSucc(1001, $res); } //获取后台用户信息wsl 20190726 public function getUerInfo(Request $request){ $user=User::whereId(Admin()->id)->select('id','mobile','nick_name'); $user->with(['roles' => function () { }]); $userarea=AdminArea::where('admin_id','=',Admin()->id)->first(); $data=[]; $u=$user->first(); if(!empty($u)){ $data['id']=Admin()->id; $data['rolename']=$u->roles[0]->name; $data['mobile']=$u->mobile; $data['nick_name']=$u->nick_name; $data['province']=''; $data['city']=''; $data['district']=''; if(!empty($userarea)){ $data['province']=$userarea->province; $data['city']=$userarea->city; $data['district']=$userarea->district; $data['areastr']=Area::whereId($userarea->city)->value('name').Area::whereId($userarea->district)->value('name'); } } return showJsonSucc('1001',$data); } /** * 下级代理人数 * @author lyh * @date 2019/4/9 * @modify_author lyh * @modify_time 2019-4-26 12:26:57 * @modify 确认已区分系统管理员与地区管理员权限 * @param Request $request * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response * @description */ public function getListByInvite(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'id' => 'required|exists:user,id' ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } // 区分系统管理员与地区管理员数据 if (\Auth::user()->is_super == 3 && !in_array($param['id'], getIds())) { return showJsonErr('抱歉,您没有权限查看该用户信息'); } $invitor = User::getAllInvite($param['id'], null, null, false); $res = User::whereIn('id', $invitor) ->orderByDesc('id') ->select([ 'id', 'level', 'nick_name', 'real_name', 'created_at','mobile' ]) ->paginate(perPage()); return showJsonSucc(1001, $res); } /** * [modifyPassword 修改指定用户密码] * @param Request $request [description] * @return [type] [description] */ public function modifyPassword(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'id' => 'required|exists:user,id', 'new_pass' => 'required|min:6', 'comfirm_pass' => 'required|same:new_pass', ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } $result = User::whereId($param['id'])->update(['password' => User::encodePassword($param['new_pass'])]); if (!$result) { return showJsonErr('修改密码失败'); } return showJsonSucc('修改密码成功'); } /** * [modifyPassword 修改当前用户密码] * @param Request $request [description] * @return [type] [description] */ public function modifyCurPassword(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'new_pass' => 'required|min:6', 'comfirm_pass' => 'required|same:new_pass', ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } $result = User::whereId(\Auth::guard(config('permission.guard'))->id())->update(['password' => User::encodePassword($param['new_pass'])]); // dd(\Auth::guard(config('permission.guard'))->id()); if (!$result) { return showJsonErr('修改密码失败'); } return showJsonSucc('修改密码成功'); } /** * [edit 编辑用户] * @author lgs * @DateTime 2019-04-28T15:16:30+0800 * @return [type] [description] */ public function edit(Request $request) { $validator = \Validator::make($param = array_filter($request->all()), [ 'id' => 'required|exists:user,id', 'real_name' => 'sometimes|required', //'mobile' => ['sometimes', 'required', 'string', Rule::unique('user')->ignore($param['id'])], //'password' => 'sometimes|required|min:6', ]); if(!empty($param['mobile'])){ $users=User::whereId($param['mobile'])->where('is_frontend','=',0)->where('id','!=',$param['id'])->count(); if($users)return showJsonErr('手机号已存在'); } if(!empty($param['status'])&&$param['status']==2&&$param['id']==8){ return showJsonErr('超级管理员不能冻结'); } if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } if (isset($param['password']) && !empty($param['password'])) { $param['password'] = User::encodePassword($param['password']); } $result = User::whereId($param['id'])->update($param); if (!$result) { return showJsonErr('编辑用户失败'); } return showJsonSucc('编辑用户成功'); } /** * [detail 代理详情] * @author lgs * @DateTime 2019-06-10T12:32:41+0800 * @param Request $request [description] * @return [type] [description] */ public function detail(Request $request) { $validator = \Validator::make($param = array_filter($request->all()), [ 'id' => 'required|exists:user,id', ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } $item = User::select([ 'id', 'level', 'nick_name', 'real_name', 'id_card', 'mobile', 'invitor', 'balance', 'coin', 'status', 'province', 'city', 'district', 'created_at', 'invite_code' ])->whereId($param['id'])->first(); $item->invitor_mobile = User::find($item->invitor)->mobile ?? 0; $item->area = trim(Area::getName($item->province) . ' ' . Area::getName($item->city) . ' ' . Area::getName($item->district)); $item->adver = Advertising::whereUid($item->id) ->whereIn('status', [3, 4, 9]) ->select([ \DB::raw('count(id) count'), \DB::raw('sum(total_price) allMoney') ]) ->first(); $userWithdrawData = \App\Modes\UserWithdraw::where(['uid'=>$item->id])->orderBy('id','desc')->first(); if(!empty($userWithdrawData)){ $item->bankname = $userWithdrawData->bank_name; $item->bankno = $userWithdrawData->bank_number; }else{ $item->bankname = ''; $item->bankno = ''; } $item->invite_num = count(User::getAllInvite($item->id, null, null, false)); // 邀请人数 $item->proxyCommission = AccountLog::whereIn('type', [20, 21, 22, 23])->whereStatus(1)->whereUid($item->id)->sum('money'); // 代理分佣 $item->adverCommission = AccountLog::whereIn('type', [10, 11, 12, 13])->whereStatus(1)->whereUid($item->id)->sum('money');//广告费分佣 $proxyConfig = Proxy::getConfig($item->id)->only(['invite', 'proxy_invite','adver_invite','coin']);//用户当前配置 $item->proxy_invite = $proxyConfig['proxy_invite'];//代理直推 $item->adver_invite = $proxyConfig['adver_invite'];//广告直推 $item->coin_rate = $proxyConfig['coin'];//点币汇率 $item->invite_image = User::getInviteImage($item->invite_code);//推广二维码 $ad1 = []; $ad2 = []; $agent1 = []; $agent2 = []; foreach ($proxyConfig['invite'] as $key => $v) { if ($v->proxy_type == 1) {//代理 if ($v->type == 1) {//间一 $agent1[] = $v; } if ($v->type == 2) {//间二 $agent2[] = $v; } } if ($v->proxy_type == 2) {//广告 if ($v->type == 1) {//间一 $ad1[] = $v; } if ($v->type == 2) {//间二 $ad2[] = $v; } } } $item->agent_invite1 = $agent1;//代理间一 $item->agent_invite2 = $agent2;//代理间二 $item->adver_invite1 = $ad1;//广告间一 $item->adver_invite2 = $ad2;//广告间二 // $item->proxyConfig = $proxyConfig; return showJsonSucc(1001, $item); } //调整点币 2021/7/21 public function editUserCoin(Request $request) { $validator = \Validator::make($param = $request->all(), [ 'id' => 'required|exists:user,id', 'coin' => 'required|numeric|min:0' ]); if ($validator->fails()) { return showJsonErr($validator->errors()->first()); } // 区分系统管理员与地区管理员数据 if (\Auth::user()->is_super !== 1) { return showJsonErr('抱歉,您没有权限调整点币'); } $user = User::whereId($param['id'])->first(); if(!$user){ return showJsonErr('用户不存在'); } if($user->coin > $param['coin']){ $difference = - bcsub($user->coin,$param['coin'],4); }else{ $difference = bcsub($param['coin'],$user->coin,4); } $result = User::whereId($param['id'])->update(['coin' => $param['coin']]); if (!$result) { return showJsonErr('修改用户状态失败'); } $ss = $difference>0 ? '上调':'下调'; //点币记录 $remark="用户【id:".$param['id']."】,系统".$ss."点币,".$ss."幅度【".$difference."】"; AccountLog::insert([ 'uid' => $param['id'], 'type' => 47, 'status' => 1, 'money_type' => 1, 'money' => $difference, 'current_money' =>$param['coin'], 'remark' => $remark ]); return showJsonSucc('调整用户点币成功'); } }