Product.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\api\controller\supplier;
  3. use app\api\controller\Controller;
  4. use app\api\model\product\Product as ProductModel;
  5. /**
  6. * 供应商产品
  7. */
  8. class Product extends Controller
  9. {
  10. // user
  11. private $user;
  12. private $supplierUser;
  13. /**
  14. * 构造方法
  15. */
  16. public function initialize()
  17. {
  18. parent::initialize();
  19. $this->user = $this->getUser(); // 用户信息
  20. $this->supplierUser = $this->getSupplierUser($this->user);
  21. }
  22. /**
  23. * 供应商中心主页
  24. */
  25. public function index()
  26. {
  27. $data = $this->postData();
  28. // 获取商品列表数据
  29. $model = new ProductModel;
  30. $data['shop_supplier_id'] = $this->supplierUser['shop_supplier_id'];
  31. $productList = $model->getList($data, $this->user);
  32. return $this->renderSuccess('', compact('productList'));
  33. }
  34. //商品上下架
  35. public function modify(){
  36. $data = $this->postData();
  37. // 获取商品数据
  38. $model = ProductModel::detail($data['product_id']);
  39. if($this->supplierUser['shop_supplier_id'] != $model['shop_supplier_id']){
  40. return $this->renderError('非法请求');
  41. }
  42. if(!$model->editStatus($data)){
  43. return $this->renderError('操作失败');
  44. }
  45. return $this->renderSuccess('操作成功');
  46. }
  47. }