Active.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\store\controller\apps\sharp;
  3. use app\store\controller\Controller;
  4. use app\store\model\sharp\Active as ActiveModel;
  5. /**
  6. * 秒杀活动会场管理
  7. * Class Active
  8. * @package app\store\controller\apps\sharp
  9. */
  10. class Active extends Controller
  11. {
  12. /**
  13. * 活动会场列表
  14. * @return mixed
  15. * @throws \think\exception\DbException
  16. */
  17. public function index()
  18. {
  19. $model = new ActiveModel;
  20. $list = $model->getList();
  21. return $this->fetch('index', compact('list'));
  22. }
  23. /**
  24. * 新增活动会场
  25. * @return array|bool|mixed
  26. * @throws \Exception
  27. */
  28. public function add()
  29. {
  30. if (!$this->request->isAjax()) {
  31. return $this->fetch('add');
  32. }
  33. $model = new ActiveModel;
  34. // 新增记录
  35. if ($model->add($this->postData('active'))) {
  36. return $this->renderSuccess('添加成功', url('apps.sharp.active/index'));
  37. }
  38. return $this->renderError($model->getError() ?: '添加失败');
  39. }
  40. /**
  41. * 修改活动状态
  42. * @param $active_id
  43. * @param $state
  44. * @return array|bool
  45. * @throws \think\exception\DbException
  46. */
  47. public function state($active_id, $state)
  48. {
  49. // 活动详情
  50. $model = ActiveModel::detail($active_id);
  51. if (!$model->setStatus($state)) {
  52. return $this->renderError('操作失败');
  53. }
  54. return $this->renderSuccess('操作成功');
  55. }
  56. /**
  57. * 删除活动会场
  58. * @param $active_id
  59. * @return array
  60. * @throws \think\exception\DbException
  61. */
  62. public function delete($active_id)
  63. {
  64. // 活动会场详情
  65. $model = ActiveModel::detail($active_id);
  66. if (!$model->setDelete()) {
  67. return $this->renderError($model->getError() ?: '删除失败');
  68. }
  69. return $this->renderSuccess('删除成功');
  70. }
  71. }