GiftApply.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use think\Request;
  5. class GiftApply extends Admin
  6. {
  7. public function _initialize()
  8. {
  9. parent::_initialize(); // TODO: Change the autogenerated stub
  10. }
  11. public function index(Request $request)
  12. {
  13. $param = $request->get();
  14. $query = Db::table("cy_props")->alias("a");
  15. if (!empty($param['game_id'])) {
  16. $query->where("a.game_id", $param['game_id']);
  17. }
  18. $query->field("a.id,b.name as game_name,a.prop_id,a.name as gift_name,a.create_time,a.content,c.name as channel_name")
  19. ->join("cy_game b", "b.id = a.game_id")
  20. ->join("nw_channel c", "c.id = a.admin_id");
  21. $list = $query->where("a.type", 0)->order("a.id desc")->paginate(20);
  22. $game_list = $this->getGameList();
  23. $this->assign("game_list", $game_list);
  24. $this->assign("list", $list);
  25. $this->assign("page", $list->render());
  26. return $this->fetch();
  27. }
  28. /**
  29. * 获取所有游戏
  30. */
  31. public function getGameList()
  32. {
  33. $game_list = Db::table("cy_game")->where("status", 1)->order("id desc")->field("name,id")->select();
  34. $result = [];
  35. foreach ($game_list as $game) {
  36. $result[$game["id"]] = $game;
  37. }
  38. return $result ?: [];
  39. }
  40. /**
  41. * 编辑页面
  42. */
  43. public function edit()
  44. {
  45. if ($this->request->isPost()) {
  46. $id = $this->request->post("id");
  47. $prop_id = $this->request->post("prop_id");
  48. if (empty($prop_id)) {
  49. $this->error("礼包编号不能为空");
  50. }
  51. $li = [
  52. "prop_id" => $prop_id,
  53. "update_time" => time()
  54. ];
  55. $update_id = Db::table("cy_props")->where("id", $id)->update($li);
  56. if ($update_id) {
  57. $this->success("操作成功", url("index"));
  58. } else {
  59. $this->error("操作失败");
  60. }
  61. } else {
  62. $this->assign("id", $this->request->param("id", 0));
  63. return $this->fetch();
  64. }
  65. }
  66. /***
  67. * 删除
  68. */
  69. public function del($id)
  70. {
  71. if (empty($id)) {
  72. $this->error("参数错误");
  73. }
  74. $del_id = Db::table("cy_props")->where("id", $id)->delete();
  75. if ($del_id) {
  76. $this->success("删除成功");
  77. } else {
  78. $this->error("删除失败");
  79. }
  80. }
  81. }