From 12913c1069347ea4b1f6ab87f480da0f8d8c646a Mon Sep 17 00:00:00 2001
From: quanwei <419654421@qq.com>
Date: Thu, 04 Dec 2025 09:24:33 +0800
Subject: [PATCH] 供需求功能
---
admin/app/api/controller/supplier/Product.php | 65 ++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/admin/app/api/controller/supplier/Product.php b/admin/app/api/controller/supplier/Product.php
index e012210..ab5ed98 100644
--- a/admin/app/api/controller/supplier/Product.php
+++ b/admin/app/api/controller/supplier/Product.php
@@ -4,6 +4,7 @@
use app\api\controller\Controller;
use app\api\model\product\Product as ProductModel;
+use app\supplier\service\ProductService;
/**
* 供应商产品
@@ -49,5 +50,69 @@
}
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'];
+
+ $model = new ProductModel;
+ 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('非法请求');
+ }
+
+ if ($model->edit($params)) {
+ return $this->renderSuccess('编辑成功');
+ }
+ return $this->renderError($model->getError() ?: '编辑失败');
+ }
}
\ No newline at end of file
--
Gitblit v1.9.2