Coach.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller;
  3. use app\agent\BaseController;
  4. use app\common\model\Coach as CoachModel;
  5. use app\common\model\Agent as AgentModel;
  6. class Coach extends BaseController
  7. {
  8. // 删除
  9. public function delCoach()
  10. {
  11. $idarr = input('idarr/a');
  12. CoachModel::whereIn('id', $idarr)->where('status', 1)->delete();
  13. exit(json_encode([
  14. 'code' => 0,
  15. 'msg' => "",
  16. ]));
  17. }
  18. // 编辑&添加
  19. public function editCoach()
  20. {
  21. $id = input('id/d');
  22. if (empty($id)) {
  23. exit(json_encode([
  24. 'code' => 1,
  25. 'msg' => '数据异常',
  26. ]));
  27. } else {
  28. $coach = CoachModel::find($id);
  29. if (empty($coach)) {
  30. exit(json_encode([
  31. 'code' => 1,
  32. 'msg' => '数据异常',
  33. ]));
  34. }
  35. CoachModel::update([
  36. 'id' => $id,
  37. 'title' => input('title/s'),
  38. 'content' => input('content/s'),
  39. 'num' => input('num/d'),
  40. 'status' => input('status/d'),
  41. 'coachtime' => input('coachtime/s'),
  42. ]);
  43. }
  44. exit(json_encode([
  45. 'code' => 0,
  46. ]));
  47. }
  48. // 列表
  49. public function index()
  50. {
  51. $statuslist = CoachModel::$status;
  52. $agentlist = AgentModel::order(['id' => 'desc'])->where('status',1)->select();
  53. return view('coach/coachlist', [
  54. 'statuslist' => $statuslist,
  55. 'agentlist' => $agentlist,
  56. ]);
  57. }
  58. public function coachForm()
  59. {
  60. $id = input('id/d, 0');
  61. $coach = CoachModel::findOrEmpty($id);
  62. $statuslist = CoachModel::$status;
  63. return view('coach/coachform', [
  64. 'coach' => $coach,
  65. 'statuslist' => $statuslist,
  66. ]);
  67. }
  68. public function listCoach()
  69. {
  70. $limit = input('limit');
  71. $page = input('page');
  72. $map = [];
  73. $keywords = input('keywords/s');
  74. if (!empty($keywords)) {
  75. $map[] = ['title', 'like', '%' . $keywords . '%'];
  76. }
  77. $status = input('status/d');
  78. if (!empty($status)) {
  79. $map[] = ['status', '=', $status];
  80. }
  81. $agentid = input('agentid/d');
  82. if (!empty($agentid)) {
  83. $map[] = ['agentid', '=', $agentid];
  84. }
  85. $list = CoachModel::with('agent')->where($map)->order(['id' => 'desc'])->limit($limit)->page($page)->append(['status_text'])->select();
  86. $count = CoachModel::where($map)->count();
  87. if ($count == 0) {
  88. exit(json_encode([
  89. 'code' => 1,
  90. 'msg' => "未查询到数据",
  91. ]));
  92. }
  93. exit(json_encode([
  94. 'code' => 0,
  95. 'msg' => "",
  96. 'count' => $count,
  97. 'data' => $list,
  98. ]));
  99. }
  100. }