quanwei
2025-12-05 feda780069d64479c0c20493603717e100655da9
admin/app/supplier/controller/product/Product.php
@@ -43,12 +43,16 @@
     */
    public function add($scene = 'add')
    {
        $supplier = SupplierModel::detail($this->getSupplierId());
        // get请求
        if($this->request->isGet()){
            return $this->getBaseData();
            return $this->getBaseData($supplier);
        }
        //post请求
        $data = json_decode($this->postData()['params'], true);
        $data['is_newcomer'] = $supplier['is_newcomer'];
        $data['is_repurchase'] = $supplier['is_repurchase'];
        // 添加商品
        if($scene == 'copy'){
            unset($data['create_time']);
            unset($data['sku']['product_sku_id']);
@@ -85,9 +89,9 @@
    /**
     * 获取基础数据
     */
    public function getBaseData()
    public function getBaseData($supplier)
    {
        return $this->renderSuccess('', array_merge(ProductService::getEditData(null, 'add', $this->getSupplierId()), []));
        return $this->renderSuccess('', array_merge(ProductService::getEditData(null, 'add', $this->getSupplierId()),['is_newcomer'=>$supplier['is_newcomer'],'is_repurchase'=>$supplier['is_repurchase']]));
    }
    /**
@@ -104,17 +108,28 @@
     */
    public function edit($product_id, $scene = 'edit')
    {
        $supplier = SupplierModel::detail($this->getSupplierId());
        if($this->request->isGet()){
            $model = ProductModel::detail($product_id);
            return $this->renderSuccess('', array_merge(ProductService::getEditData($model, $scene, $this->getSupplierId()), compact('model')));
            $is_newcomer = $supplier['is_newcomer'];
            $is_repurchase = $supplier['is_repurchase'];
            $supplierName='';
            if($model['belonging_shop_supplier_id']){
                $belonging_shop_supplier= SupplierModel::detail($model['belonging_shop_supplier_id']);
                $supplierName=$belonging_shop_supplier['name'];
            }
            return $this->renderSuccess('', array_merge(ProductService::getEditData($model, $scene, $this->getSupplierId()), compact('model','is_newcomer','is_repurchase','supplierName')));
        }
        if ($scene == 'copy') {
            return $this->add($scene);
        }
        // 商品详情
        $model = ProductModel::detail($product_id);
        $data = json_decode($this->postData()['params'], true);
        $data['is_newcomer'] = $supplier['is_newcomer'];
        $data['is_repurchase'] = $supplier['is_repurchase'];
        // 更新记录
        if ($model->edit(json_decode($this->postData()['params'], true),$this->getSupplierId())) {
        if ($model->edit($data,$this->getSupplierId())) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');