123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace App\Http\Controllers\AdminApi;
- use App\Http\Controllers\AdminController;
- use App\Models\UserModels\WxSignup;
- use App\Models\UserModels\WxUser;
- class ApplyController extends AdminController
- {
- function getList(){
- $search = request()->input('search','');//搜索内容
- $name = request()->input('name','');//推广人
- $where = [];
- if ($name) $where[] = ['u.name', 'like', "%$name%"];
- $list = WxSignup::from('wx_signups as s')
- ->leftJoin('wx_users as u', 's.p_id', '=', 'u.id')
- ->where($where)
- ->where(function ($q) use ($search){
- if($search){
- $q->where('s.name','like',"%$search%");
- $q->orWhere('s.phone','like',"%$search%");
- }
- })
- ->select(['s.id','s.name','s.phone','s.industry','s.address','s.created_at','u.name as s_name'])
- ->orderBy('id','desc')
- ->paginate(10);
- return $this->apiResponseSuccess('获取信息成功', [
- 'list' => $list->items(),
- 'total' => $list->total(),
- 'limit' => 10
- ]);
- }
- /**
- * 获取推广者列表
- * @return \Illuminate\Http\JsonResponse
- */
- function getApplyList(){
- $search = request()->input('search','');//搜索内容
- $order_by = request()->input('order_by', '');//排序
- $where = [['u.status',1]];
- $sql = "x_u.id,x_u.name,x_u.phone,x_u.pv,x_u.uv,x_u.created_at,
- count(x_s.id) as count";
- $model = WxUser::from('wx_users as u')
- ->leftJoin('wx_signups as s', 's.p_id', '=', 'u.id')
- ->where($where)
- ->where(function ($q) use ($search){
- if($search){
- $q->where('u.name','like',"%$search%");
- $q->orWhere('u.phone','like',"%$search%");
- }
- })
- ->groupBy('u.id')
- ->selectRaw($sql);
- if ($order_by == 1) {
- $model->orderBy('pv', 'asc');
- } elseif ($order_by == 2) {
- $model->orderBy('pv', 'desc');
- } elseif ($order_by == 3) {
- $model->orderBy('uv', 'asc');
- } elseif ($order_by == 4) {
- $model->orderBy('uv', 'desc');
- } elseif ($order_by == 5) {
- $model->orderBy('count', 'asc');
- } elseif ($order_by == 6) {
- $model->orderBy('count', 'desc');
- } else {
- $model->orderBy('u.id', 'asc');
- }
- $list = $model->paginate(10);
- return $this->apiResponseSuccess('获取信息成功', [
- 'list' => $list->items(),
- 'total' => $list->total(),
- 'limit' => 10
- ]);
- }
- /**
- * 获取下级统计
- * @return \Illuminate\Http\JsonResponse
- */
- function getTotal(){
- $id = request()->input('id','');//用户id
- if (empty($id)) return $this->apiResponseError( '必要参数缺失');
- $where = [['p_id',$id]];
- $list = WxSignup::where($where)
- ->select(['id','name','phone','created_at'])
- ->orderBy('id','desc')
- ->paginate(10);
- return $this->apiResponseSuccess('获取信息成功', [
- 'list' => $list->items(),
- 'total' => $list->total(),
- 'limit' => 10
- ]);
- }
- }
|