ApplyController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Http\Controllers\AdminApi;
  3. use App\Http\Controllers\AdminController;
  4. use App\Models\UserModels\WxSignup;
  5. use App\Models\UserModels\WxUser;
  6. class ApplyController extends AdminController
  7. {
  8. function getList(){
  9. $search = request()->input('search','');//搜索内容
  10. $name = request()->input('name','');//推广人
  11. $where = [];
  12. if ($name) $where[] = ['u.name', 'like', "%$name%"];
  13. $list = WxSignup::from('wx_signups as s')
  14. ->leftJoin('wx_users as u', 's.p_id', '=', 'u.id')
  15. ->where($where)
  16. ->where(function ($q) use ($search){
  17. if($search){
  18. $q->where('s.name','like',"%$search%");
  19. $q->orWhere('s.phone','like',"%$search%");
  20. }
  21. })
  22. ->select(['s.id','s.name','s.phone','s.industry','s.created_at','u.name as s_name'])
  23. ->paginate(10);
  24. return $this->apiResponseSuccess('获取信息成功', [
  25. 'list' => $list->items(),
  26. 'total' => $list->total(),
  27. 'limit' => 10
  28. ]);
  29. }
  30. /**
  31. * 获取推广者列表
  32. * @return \Illuminate\Http\JsonResponse
  33. */
  34. function getApplyList(){
  35. $search = request()->input('search','');//搜索内容
  36. $order_by = request()->input('order_by', '');//排序
  37. $where = [['u.status',1]];
  38. $sql = "x_u.id,x_u.name,x_u.phone,x_u.pv,x_u.uv,x_u.created_at,
  39. count(x_s.id) as count";
  40. $model = WxUser::from('wx_users as u')
  41. ->leftJoin('wx_signups as s', 's.m_id', '=', 'u.id')
  42. ->where($where)
  43. ->where(function ($q) use ($search){
  44. if($search){
  45. $q->where('u.name','like',"%$search%");
  46. $q->orWhere('u.phone','like',"%$search%");
  47. }
  48. })
  49. ->groupBy('u.id')
  50. ->selectRaw($sql);
  51. if ($order_by == 1) {
  52. $model->orderBy('pv', 'asc');
  53. } elseif ($order_by == 2) {
  54. $model->orderBy('pv', 'desc');
  55. } elseif ($order_by == 3) {
  56. $model->orderBy('uv', 'asc');
  57. } elseif ($order_by == 4) {
  58. $model->orderBy('uv', 'desc');
  59. } elseif ($order_by == 5) {
  60. $model->orderBy('count', 'asc');
  61. } elseif ($order_by == 6) {
  62. $model->orderBy('count', 'desc');
  63. } else {
  64. $model->orderBy('u.id', 'asc');
  65. }
  66. $list = $model->paginate(10);
  67. return $this->apiResponseSuccess('获取信息成功', [
  68. 'list' => $list->items(),
  69. 'total' => $list->total(),
  70. 'limit' => 10
  71. ]);
  72. }
  73. /**
  74. * 获取下级统计
  75. * @return \Illuminate\Http\JsonResponse
  76. */
  77. function getTotal(){
  78. $id = request()->input('id','');//用户id
  79. if (empty($id)) return $this->apiResponseError( '必要参数缺失');
  80. $where = [['m_id',$id]];
  81. $list = WxSignup::where($where)
  82. ->select(['id','name','phone','created_at'])
  83. ->paginate(10);
  84. return $this->apiResponseSuccess('获取信息成功', [
  85. 'list' => $list->items(),
  86. 'total' => $list->total(),
  87. 'limit' => 10
  88. ]);
  89. }
  90. }