ActiveTime.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. use app\store\model\sharp\ActiveTime as ActiveTimeModel;
  13. use app\store\model\sharp\ActiveGoods as ActiveGoodsModel;
  14. /**
  15. * 秒杀活动会场-场次管理
  16. * Class ActiveTime
  17. * @package app\store\controller\apps\sharp
  18. */
  19. class ActiveTime extends Controller
  20. {
  21. /**
  22. * 活动会场-场次列表
  23. * @param $active_id
  24. * @return mixed
  25. * @throws \think\exception\DbException
  26. */
  27. public function index($active_id)
  28. {
  29. $model = new ActiveTimeModel;
  30. $list = $model->getList($active_id);
  31. return $this->fetch('index', compact('list'));
  32. }
  33. /**
  34. * 新增活动会场
  35. * @param $active_id
  36. * @return array|bool|mixed
  37. * @throws \think\exception\DbException
  38. */
  39. /**
  40. * 新增活动会场
  41. * @param $active_id
  42. * @return array|bool|mixed
  43. * @throws \think\exception\DbException
  44. */
  45. public function add($active_id)
  46. {
  47. // 活动详情
  48. $active = ActiveModel::detail($active_id);
  49. // 已存在的场次
  50. $model = new ActiveTimeModel;
  51. $existTimes = $model->getActiveTimeData($active_id);
  52. if (!$this->request->isAjax()) {
  53. return $this->fetch('add', compact('active', 'existTimes'));
  54. }
  55. // 新增记录
  56. if ($model->add($active_id, $this->postData('active'))) {
  57. $url = url('apps.sharp.active_time/index', ['active_id' => $active_id]);
  58. return $this->renderSuccess('添加成功', $url);
  59. }
  60. return $this->renderError($model->getError() ?: '添加失败');
  61. }
  62. /**
  63. * 编辑活动会场
  64. * @param $id
  65. * @return array|bool|mixed
  66. * @throws \think\exception\DbException
  67. * @throws \Exception
  68. */
  69. public function edit($id)
  70. {
  71. // 场次详情
  72. $model = ActiveTimeModel::detail($id, ['active']);
  73. // 当前场次关联的商品
  74. $goodsList = $model->getGoodsListByActiveTimeId($id);
  75. if (!$this->request->isAjax()) {
  76. return $this->fetch('edit', compact('model', 'goodsList'));
  77. }
  78. // 新增记录
  79. if ($model->edit($this->postData('active'))) {
  80. $url = url('apps.sharp.active_time/index', ['active_id' => $model['active_id']]);
  81. return $this->renderSuccess('更新成功', $url);
  82. }
  83. return $this->renderError($model->getError() ?: '更新失败');
  84. }
  85. /**
  86. * 修改场次状态
  87. * @param $id
  88. * @param $state
  89. * @return array|bool
  90. * @throws \think\exception\DbException
  91. */
  92. public function state($id, $state)
  93. {
  94. // 场次详情
  95. $model = ActiveTimeModel::detail($id);
  96. if (!$model->setStatus($state)) {
  97. return $this->renderError('操作失败');
  98. }
  99. return $this->renderSuccess('操作成功');
  100. }
  101. /**
  102. * 删除活动场次
  103. * @param $id
  104. * @return array|bool
  105. * @throws \think\Exception
  106. * @throws \think\exception\DbException
  107. * @throws \think\exception\PDOException
  108. */
  109. public function delete($id)
  110. {
  111. // 场次详情
  112. $model = ActiveTimeModel::detail($id);
  113. if (!$model->onDelete()) {
  114. return $this->renderError($model->getError() ?: '删除失败');
  115. }
  116. return $this->renderSuccess('删除成功');
  117. }
  118. }