Seckill.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\supplier\controller\activity;
  3. use app\common\model\product\Product as ProductModel;
  4. use app\supplier\controller\Controller;
  5. use app\supplier\model\plus\seckill\Active as ActiveModel;
  6. use app\supplier\model\plus\seckill\Product as SeckillProductModel;
  7. /**
  8. * 秒杀活动控制器
  9. */
  10. class Seckill extends Controller
  11. {
  12. /**
  13. * 列表
  14. */
  15. public function index()
  16. {
  17. $list = (new ActiveModel())->getList($this->postData());
  18. //排除id
  19. $exclude_ids = (new SeckillProductModel())->getExcludeIds($this->getSupplierId());
  20. return $this->renderSuccess('', compact('list', 'exclude_ids'));
  21. }
  22. /**
  23. * 报名
  24. */
  25. public function add($product_id, $seckill_activity_id)
  26. {
  27. if($this->request->isGet()){
  28. //商品详情
  29. $model = ProductModel::detail($product_id);
  30. //活动详情
  31. $active = ActiveModel::detail($seckill_activity_id);
  32. return $this->renderSuccess('', compact('model', 'active'));
  33. }
  34. $data = $this->postData();
  35. // 新增记录
  36. if (!(new SeckillProductModel())->checkProduct($product_id, $this->getSupplierId())) {
  37. return $this->renderError('商品已经参加活动了,请勿重复提交');
  38. }
  39. $model = new ActiveModel();
  40. if ($model->add($this->getSupplierId(), $data)) {
  41. return $this->renderSuccess('添加成功');
  42. }
  43. return $this->renderError($model->getError() ?:'添加失败');
  44. }
  45. /**
  46. * 列表
  47. */
  48. public function my()
  49. {
  50. $supplier = $this->supplier['user'];
  51. $list = (new SeckillProductModel())->getList($supplier['shop_supplier_id'], $this->postData());
  52. return $this->renderSuccess('', compact('list'));
  53. }
  54. /**
  55. * 报名
  56. */
  57. public function edit($seckill_product_id)
  58. {
  59. if($this->request->isGet()){
  60. //商品详情
  61. $model = SeckillProductModel::detail($seckill_product_id, ['active', 'product' => ['sku','image.file'], 'seckillSku']);
  62. return $this->renderSuccess('', compact('model'));
  63. }
  64. $data = $this->postData();
  65. // 新增记录
  66. $model = SeckillProductModel::detail($seckill_product_id);
  67. if ($model->edit($data)) {
  68. return $this->renderSuccess('添加成功');
  69. }
  70. return $this->renderError($model->getError() ?:'添加失败');
  71. }
  72. /**
  73. * 删除
  74. */
  75. public function del($seckill_product_id)
  76. {
  77. $model = new SeckillProductModel();
  78. if ($model->remove($seckill_product_id, $this->getSupplierId())) {
  79. return $this->renderSuccess('删除成功');
  80. }
  81. return $this->renderError($model->getError() ?:'删除失败');
  82. }
  83. }