ApplyController.php 3.3 KB

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