AdminActiveController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: Powerless < wzxaini9@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\love\controller;
  12. use app\common\Fun;
  13. use app\love\model\ActiveApplyModel;
  14. use app\love\model\ActiveModel;
  15. use cmf\controller\AdminBaseController;
  16. class AdminActiveController extends AdminBaseController
  17. {
  18. /**
  19. * 列表
  20. */
  21. public function index()
  22. {
  23. $list = ActiveModel::paginate(10);
  24. foreach ($list as $v) {
  25. $v['url'] = urlencode(url('love/Scene/wechat', ['active_id' => $v['id']], true, true));
  26. }
  27. // 获取分页显示
  28. $page = $list->render();
  29. $this->assign('list', $list);
  30. $this->assign('page', $page);
  31. // 渲染模板输出
  32. return $this->fetch();
  33. }
  34. /**
  35. * 添加
  36. */
  37. public function add()
  38. {
  39. return $this->fetch();
  40. }
  41. /**
  42. * 添加提交
  43. */
  44. public function addPost()
  45. {
  46. if ($this->request->isPost()) {
  47. $data = $this->request->param();
  48. $post = $data['post'];
  49. if (empty($post['start_time'])) {
  50. $this->error('请选择开始时间');
  51. }
  52. if (empty($post['end_time'])) {
  53. $this->error('请选择结束时间');
  54. }
  55. $post['create_time'] = $post['update_time'] = time();
  56. $post['start_time'] = strtotime($post['start_time']);
  57. $post['end_time'] = strtotime($post['end_time']);
  58. ActiveModel::create($post);
  59. $this->success('添加成功!', url('index'));
  60. }
  61. }
  62. /**
  63. * 编辑
  64. */
  65. public function edit()
  66. {
  67. $id = $this->request->param('id', 0, 'intval');
  68. $post = ActiveModel::get($id);
  69. $this->assign('post', $post);
  70. return $this->fetch();
  71. }
  72. /**
  73. * 编辑提交
  74. */
  75. public function editPost()
  76. {
  77. if ($this->request->isPost()) {
  78. $data = $this->request->param();
  79. $post = $data['post'];
  80. if (empty($post['start_time'])) {
  81. $this->error('请选择开始时间');
  82. }
  83. if (empty($post['end_time'])) {
  84. $this->error('请选择结束时间');
  85. }
  86. $post['create_time'] = $post['update_time'] = time();
  87. $post['start_time'] = strtotime($post['start_time']);
  88. $post['end_time'] = strtotime($post['end_time']);
  89. ActiveModel::update($post, ['id' => $post['id']]);
  90. $this->success('编辑成功!', url('index'));
  91. }
  92. }
  93. /**
  94. * 审核列表
  95. */
  96. public function applyList()
  97. {
  98. $param = $this->request->param();
  99. $this->assign('id', $param['id']);
  100. $this->assign('check_status', $param['check_status'] ?? 0);
  101. $this->assign('sex', $param['sex'] ?? 0);
  102. $where = [
  103. ['active_id', '=', $param['id']],
  104. ];
  105. if (!empty($param['check_status'])) {
  106. $where[] = ['cmf_active_apply.check_status', '=', $param['check_status']];
  107. }
  108. $sexWhere = [];
  109. if (!empty($param['sex'])) {
  110. $sexWhere = ['sex'=>$param['sex']];
  111. }
  112. $total = ActiveApplyModel::hasWhere('user',$sexWhere)->where($where)->count();
  113. $this->assign('total', $total);
  114. $list = ActiveApplyModel::hasWhere('user',$sexWhere)->with('user')->where($where)->order('check_status asc')->paginate(10);
  115. foreach ($list as $v) {
  116. $v['age'] = Fun::getAgeByBirth($v['user']['birthday']);
  117. }
  118. \think\facade\Log::record('sql为:'.ActiveApplyModel::getLastSql());
  119. $page = $list->render();
  120. $this->assign('list', $list);
  121. $this->assign('page', $page);
  122. return $this->fetch();
  123. }
  124. /**
  125. * 审核
  126. */
  127. public function checkPost()
  128. {
  129. $data = $this->request->post();
  130. ActiveApplyModel::update($data, ['id' => $data['id']]);
  131. $this->success('操作成功');
  132. }
  133. }