ActiveTime.php 3.5 KB

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