TuiServerForbid.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use think\Request;
  5. class TuiServerForbid extends Admin
  6. {
  7. protected $channel_list;
  8. public function _initialize()
  9. {
  10. parent::_initialize(); // TODO: Change the autogenerated stub
  11. $this->assign("channel_list", $this->getChannelList());
  12. }
  13. public function index(Request $request)
  14. {
  15. $query = Db::table("nw_channel_view_limit")->alias("a");
  16. if (!empty($request->get("channel_id"))) {
  17. $query->where("a.channel_id", $request->get("channel_id"));
  18. }
  19. $list = $query->join("nw_channel b", "b.id = a.channel_id")
  20. ->field("a.id,a.channel_id,b.name as channel_name,a.create_time")
  21. ->order("create_time desc")
  22. ->paginate(20);
  23. $this->assign('list', $list);
  24. $this->assign('page', $list->render());
  25. $this->assign("channel_list", $this->getSearchChannelList());
  26. return $this->fetch();
  27. }
  28. // 获取推广员渠道id
  29. public function getChannelList()
  30. {
  31. return Db::table("nw_channel")->where(['status' => 1, "level" => ["in",[2,3]]])->field("id,name")->select();
  32. }
  33. // 获取推广员渠道id
  34. public function getSearchChannelList()
  35. {
  36. $list = Db::table("nw_channel")->where(['status' => 1, "level" => ["in",[2,3]]])->field("id,name")->select();
  37. $new_list = [];
  38. foreach ($list as $key => $item) {
  39. $new_list[$key] = $item;
  40. }
  41. return $new_list;
  42. }
  43. public function add(Request $request)
  44. {
  45. if ($request->isPost()) {
  46. $channel_id = $request->post("channel_id", null);
  47. if (empty($channel_id)) {
  48. $this->error("参数错误");
  49. }
  50. if (Db::table("nw_channel_view_limit")->where("channel_id", $channel_id)->value("id")) {
  51. $this->error("记录已经存在");
  52. }
  53. $data = [
  54. "channel_id" => $channel_id,
  55. "create_time" => time(),
  56. "update_time" => time(),
  57. ];
  58. $id = Db::table("nw_channel_view_limit")->insertGetId($data);
  59. if ($id) {
  60. $this->success("操作成功", url("index"));
  61. } else {
  62. $this->error("操作失败");
  63. }
  64. }
  65. return $this->fetch();
  66. }
  67. public function delete($id=0)
  68. {
  69. $id = Db::table("nw_channel_view_limit")->where("id",$id)->delete();
  70. if ($id) {
  71. $this->success("删除成功", url("index"));
  72. } else {
  73. $this->error("删除失败");
  74. }
  75. }
  76. }