Active.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\shop\controller\plus\seckill;
  3. use app\shop\controller\Controller;
  4. use app\shop\model\plus\seckill\Active as ActiveModel;
  5. use app\shop\model\plus\seckill\Product as SeckillProductModel;
  6. /**
  7. * 活动控制器
  8. */
  9. class Active extends Controller
  10. {
  11. /**
  12. * 活动会场列表
  13. */
  14. public function index()
  15. {
  16. $model = new ActiveModel;
  17. $list = $model->getList($this->postData());
  18. return $this->renderSuccess('', compact('list'));
  19. }
  20. /**
  21. * 新增活动会场
  22. */
  23. public function add()
  24. {
  25. $model = new ActiveModel;
  26. // 新增记录
  27. if ($model->add($this->postData())) {
  28. return $this->renderSuccess('添加成功');
  29. }
  30. return $this->renderError($model->getError() ?: '添加失败');
  31. }
  32. /**
  33. * 获取秒杀活动详情
  34. * @param $seckill_activity_id int 秒杀活动id
  35. * @return \think\response\Json
  36. */
  37. public function edit($seckill_activity_id)
  38. {
  39. if($this->request->isGet()){
  40. $detail = ActiveModel::detailWithTrans($seckill_activity_id);
  41. //活动商品
  42. $product_list = SeckillProductModel::getList($seckill_activity_id);
  43. return $this->renderSuccess('', compact('detail', 'product_list'));
  44. }
  45. // 修改
  46. $model = ActiveModel::detail($seckill_activity_id);
  47. if ($model->edit($this->postData())) {
  48. return $this->renderSuccess('修改成功');
  49. }
  50. return $this->renderError($model->getError() ?: '修改失败');
  51. }
  52. /**
  53. * 删除活动
  54. */
  55. public function delete($seckill_activity_id)
  56. {
  57. // 活动会场详情
  58. $model = ActiveModel::detail($seckill_activity_id);
  59. if ($model->del()) {
  60. return $this->renderSuccess('删除成功');
  61. }
  62. return $this->renderError($model->getError() ?: '删除失败');
  63. }
  64. /**
  65. *获取diy秒删商品
  66. */
  67. public function getDiyProduct()
  68. {
  69. $model = new ActiveModel;
  70. $list = $model->getDiyProduct();
  71. return $this->renderSuccess('', compact('list'));
  72. }
  73. }