Point.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\point\Product as PointProductModel;
  6. /**
  7. * 积分活动控制器
  8. */
  9. class Point extends Controller
  10. {
  11. /**
  12. * 添加
  13. */
  14. public function add($product_id)
  15. {
  16. if($this->request->isGet()){
  17. $model = ProductModel::detail($product_id);
  18. return $this->renderSuccess('', compact('model'));
  19. }
  20. $model = new PointProductModel();
  21. if ($model->checkProduct($product_id)) {
  22. return $this->renderError('商品已经参加活动了,请勿重复提交');
  23. }
  24. if ($model->saveProduct($this->getSupplierId(), $this->postData())) {
  25. return $this->renderSuccess('添加成功');
  26. }
  27. return $this->renderError($model->getError() ?: '添加失败');
  28. }
  29. /**
  30. * 列表
  31. */
  32. public function my()
  33. {
  34. $supplier = $this->supplier['user'];
  35. $list = (new PointProductModel())->getList($supplier['shop_supplier_id'], $this->postData());
  36. //排除id
  37. $exclude_ids = (new PointProductModel())->getExcludeIds($this->getSupplierId());
  38. return $this->renderSuccess('', compact('list', 'exclude_ids'));
  39. }
  40. /**
  41. * 编辑
  42. */
  43. public function edit($point_product_id)
  44. {
  45. if($this->request->isGet()){
  46. //商品详情
  47. $model = PointProductModel::detail($point_product_id, ['product' => ['image.file'],'sku']);
  48. return $this->renderSuccess('', compact('model'));
  49. }
  50. $data = $this->postData();
  51. $model = PointProductModel::detail($point_product_id);
  52. if ($model->edit($data)) {
  53. return $this->renderSuccess('添加成功');
  54. }
  55. return $this->renderError($model->getError() ?:'添加失败');
  56. }
  57. /**
  58. * 删除
  59. */
  60. public function del($point_product_id)
  61. {
  62. $model = PointProductModel::detail($point_product_id);
  63. if ($model->remove($point_product_id, $this->getSupplierId())) {
  64. return $this->renderSuccess('删除成功');
  65. }
  66. return $this->renderError($model->getError() ?: '删除失败');
  67. }
  68. }