Coach.php 3.2 KB

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