| | |
| | | |
| | | use app\api\controller\Controller; |
| | | use app\api\model\product\Product as ProductModel; |
| | | use app\supplier\service\ProductService; |
| | | use app\api\model\supplier\Supplier as SupplierModel; |
| | | |
| | | /** |
| | | * 供应商产品 |
| | |
| | | } |
| | | return $this->renderSuccess('操作成功'); |
| | | } |
| | | |
| | | /** |
| | | * 获取添加商品所需的基础数据 |
| | | */ |
| | | public function getBaseData() |
| | | { |
| | | $data = ProductService::getEditData(null, 'add', $this->supplierUser['shop_supplier_id']); |
| | | return $this->renderSuccess('', $data); |
| | | } |
| | | |
| | | /** |
| | | * 添加商品 |
| | | */ |
| | | public function add() |
| | | { |
| | | $data = $this->postData(); |
| | | $params = json_decode($data['params'], true); |
| | | $params['shop_supplier_id'] = $this->supplierUser['shop_supplier_id']; |
| | | if ($this->supplierUser['status']==20){ |
| | | return $this->renderError('未缴纳保证金,不能添加商品'); |
| | | } |
| | | $model = new ProductModel; |
| | | $supplier = SupplierModel::detail($this->supplierUser['shop_supplier_id']); |
| | | $params['is_newcomer'] = $supplier['is_newcomer']; |
| | | $params['is_repurchase'] = $supplier['is_repurchase']; |
| | | if ($model->add($params)) { |
| | | return $this->renderSuccess('添加成功'); |
| | | } |
| | | return $this->renderError($model->getError() ?: '添加失败'); |
| | | } |
| | | |
| | | /** |
| | | * 获取编辑商品所需的数据 |
| | | */ |
| | | public function getEditData() |
| | | { |
| | | $data = $this->postData(); |
| | | $product_id = $data['product_id']; |
| | | // 获取商品数据 |
| | | $model = ProductModel::detail($product_id); |
| | | if($this->supplierUser['shop_supplier_id'] != $model['shop_supplier_id']){ |
| | | return $this->renderError('非法请求'); |
| | | } |
| | | |
| | | $result = ProductService::getEditData($model, 'edit', $this->supplierUser['shop_supplier_id']); |
| | | $result['model'] = $model; |
| | | return $this->renderSuccess('', $result); |
| | | } |
| | | |
| | | /** |
| | | * 编辑商品 |
| | | */ |
| | | public function edit() |
| | | { |
| | | $data = $this->postData(); |
| | | $product_id = $data['product_id']; |
| | | $params = json_decode($data['params'], true); |
| | | |
| | | // 获取商品数据 |
| | | $model = ProductModel::detail($product_id); |
| | | if($this->supplierUser['shop_supplier_id'] != $model['shop_supplier_id']){ |
| | | return $this->renderError('非法请求'); |
| | | } |
| | | $supplier = SupplierModel::detail($this->supplierUser['shop_supplier_id']); |
| | | $params['is_newcomer'] = $supplier['is_newcomer']; |
| | | $params['is_repurchase'] = $supplier['is_repurchase']; |
| | | if ($model->edit($params)) { |
| | | return $this->renderSuccess('编辑成功'); |
| | | } |
| | | return $this->renderError($model->getError() ?: '编辑失败'); |
| | | } |
| | | |
| | | } |