Assemble.php 3.0 KB

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