MatchController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*比赛管理*/
  3. namespace App\Http\Controllers\Admin;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. class MatchController extends Controller
  8. {
  9. //核销用户列表
  10. public function checkerList(Request $request)
  11. {
  12. $list = Db::table('agent.dbo.agent')
  13. ->select('created_at','name','wx_account','password')
  14. ->where('hexiao',1)
  15. ->paginate(10);
  16. }
  17. //创建核销用户
  18. public function createChecker(Request $request)
  19. {
  20. if(Agent::where('wx_account',$params['wx_account'])->first()){
  21. return ['status'=>false,'message'=>'登录账号不能重复'];
  22. }
  23. $password = bcrypt($params['password']);
  24. $CreatedParentID = Auth::user()->id;
  25. $data = [
  26. 'role_id' => 0,
  27. 'parent_id' => 0,
  28. 'name' => $params['name'],
  29. 'wx_account'=> $params['wx_account'],
  30. 'mobile' => 0,
  31. 'id_card' => 0,
  32. 'status' => 1,
  33. 'password' => $password,
  34. 'num_account' => $this->get_num_account(),
  35. 'CreatedParentID' => $CreatedParentID,
  36. 'hexiao' => 1,
  37. 'channel' => Auth::user()->channel
  38. ];
  39. if($agent = Agent::create($data)){
  40. AgentApp::create([
  41. 'agent_id'=>$agent->id,
  42. 'app_id'=>1
  43. ]);
  44. return ['status'=>true,'message'=>'创建成功'];
  45. }else{
  46. return ['status'=>false,'message'=>'创建失败'];
  47. }
  48. }
  49. public function getlist(Request $request)
  50. {
  51. $params = $request->all();
  52. $match = isset($params['match']) ? $params['match'] : 1;//0 推广员
  53. $status = isset($params['status']) ? $params['status'] : 0;
  54. $searchKey = isset($params['searchKey']) ? $params['searchKey'] : 0;
  55. $YN_Team = new Servers();
  56. $YN_Team->setTable('YN_Team');
  57. //$count = $YN_Team->where('Status',$status)->where('match',$match)->count();
  58. //$data = $YN_Team->orderBy('created','desc')->get();
  59. // $limit = isset($params['limit']) ? intval($params['limit']) : 50;
  60. // $offset = isset($params['offset']) ? intval($params['offset']) : 0;
  61. if($match ==2){
  62. $query = $YN_Team->select('YN_Team.*')->join('YN_TeamCode','YN_Team.TeamID','=','YN_TeamCode.TeamID')->where('YN_TeamCode.Status',1)->where('YN_TeamCode.Match',$match);
  63. if($status != 'all'){
  64. $query = $query->where('YN_Team.Status',$status);
  65. }
  66. }else{
  67. $query = $YN_Team->where('Match',$match);
  68. if($status != 'all'){
  69. $query = $query->where('Status',$status);
  70. }
  71. }
  72. if($searchKey){
  73. $query->where(function ($query) use ($searchKey) {
  74. $query->where('YN_Team.TeamName', 'like', "%{$searchKey}%")->orWhere('YN_Team.TeamID', 'like', "%{$searchKey}%");
  75. });
  76. }
  77. //->skip($offset)->take($limit)
  78. $count = $query->count();
  79. $data = $query->orderBy('YN_Team.created','desc')->get();
  80. return Response::json(['data'=>$data,'count'=>$count,'status'=>true,'searchKey'=>$searchKey],200);
  81. }
  82. }