Active.php 2.1 KB

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