Bargain.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\bargain\Active as ActiveModel;
  6. use app\supplier\model\plus\bargain\Product as BargainProductModel;
  7. /**
  8. * 砍价活动控制器
  9. */
  10. class Bargain extends Controller
  11. {
  12. /**
  13. * 列表
  14. */
  15. public function index()
  16. {
  17. $list = (new ActiveModel())->getList($this->postData());
  18. //排除id
  19. $exclude_ids = (new BargainProductModel())->getExcludeIds($this->getSupplierId());
  20. return $this->renderSuccess('', compact('list', 'exclude_ids'));
  21. }
  22. /**
  23. * 报名
  24. */
  25. public function add($product_id, $bargain_activity_id)
  26. {
  27. if($this->request->isGet()){
  28. //商品详情
  29. $model = ProductModel::detail($product_id);
  30. //活动详情
  31. $active = ActiveModel::detail($bargain_activity_id);
  32. return $this->renderSuccess('', compact('model', 'active'));
  33. }
  34. $data = $this->postData();
  35. // 新增记录
  36. if (!(new BargainProductModel())->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 BargainProductModel())->getList($supplier['shop_supplier_id'], $this->postData());
  52. return $this->renderSuccess('', compact('list'));
  53. }
  54. /**
  55. * 报名
  56. */
  57. public function edit($bargain_product_id)
  58. {
  59. if($this->request->isGet()){
  60. //商品详情
  61. $model = BargainProductModel::detail($bargain_product_id, ['active', 'product' => ['sku','image.file'], 'bargainSku']);
  62. return $this->renderSuccess('', compact('model'));
  63. }
  64. $data = $this->postData();
  65. // 新增记录
  66. $supplier = $this->supplier['user'];
  67. $model = BargainProductModel::detail($bargain_product_id);
  68. if ($model->edit($data)) {
  69. return $this->renderSuccess('添加成功');
  70. }
  71. return $this->renderError($model->getError() ?:'添加失败');
  72. }
  73. /**
  74. * 删除
  75. */
  76. public function del($bargain_product_id)
  77. {
  78. $model = new BargainProductModel();
  79. if ($model->remove($bargain_product_id, $this->getSupplierId())) {
  80. return $this->renderSuccess('删除成功');
  81. }
  82. return $this->renderError($model->getError() ?:'删除失败');
  83. }
  84. }