admin/app/shop/model/product/Product.php
@@ -3,6 +3,7 @@
namespace app\shop\model\product;
use app\common\model\product\Product as ProductModel;
use app\shop\controller\product\ProductCategory;
use app\shop\service\ProductService;
use app\common\library\helper;
/**
@@ -34,6 +35,9 @@
      
        $data['grade_ids'] = implode(',', $data['grade_ids']);
        $data['app_id'] = $data['sku']['app_id'] = self::$app_id;
        if ($data['category_ids']) {
            $data['category_id'] = $data['category_ids'][0]; // 从商品多分类中获取第一个作为主分类 by lyzflash
        }
        // 开启事务
        $this->startTrans();
        try {
@@ -47,6 +51,8 @@
            if($data['is_picture'] == 1){
                $this->addProductContentImages($data['contentImage']);
            }
            // 保存商品多分类
            $data['category_ids'] && $this->saveProductCategorys($data['category_ids']);
            $this->commit();
            return true;
        } catch (\Exception $e) {
@@ -54,6 +60,16 @@
            $this->rollback();
            return false;
        }
    }
    /**
     * 添加商品多分类 by lzyflash 2023.06.15
     */
    private function saveProductCategorys($data)
    {
        // 先删除所有分类
        $model = new ProductCategory;
        $model->removeAll($this['product_id']);
        $model->addCategoryList($this['product_id'], $data);
    }
    /**
@@ -104,12 +120,16 @@
        $data['grade_ids'] = implode(',', $data['grade_ids']);
        $data['app_id'] = $data['sku']['app_id'] = self::$app_id;
        $productSkuIdList = helper::getArrayColumn(($this['sku']), 'product_sku_id');
        // 获取分类 by lyzflash 2023.06.15
        if ($data['category_ids']) {
            $data['category_id'] = $data['category_ids'][0]; // 从商品多分类中获取第一个作为主分类 by lyzflash
        }
        return $this->transaction(function () use ($data, $productSkuIdList) {
            // 审核商品
            if($data['submit_type'] == 'edit'){
                unset($data['audit_status']);
            }
            $this->save($data);
            // 商品规格
            $this->addProductSpec($data, true, $productSkuIdList);
@@ -121,6 +141,8 @@
            }
            // 店铺商品总销量
            $this->reSupplierTotalSales($this['shop_supplier_id']);
            // 保存商品多分类
            $data['category_ids'] && $this->saveProductCategorys($data['category_ids']);
            return true;
        });
    }
@@ -248,7 +270,8 @@
        }
        return $model
            ->alias('product')
            ->join('supplier supplier', 'product.shop_supplier_id = supplier.shop_supplier_id','left')->where('supplier.is_delete', '=', 0)->where('product.is_delete', '=', 0)
            ->join('supplier supplier', 'product.shop_supplier_id = supplier.shop_supplier_id','left')
            ->where('supplier.is_delete', '=', 0)->where('product.is_delete', '=', 0)->where('supplier.status',0)
            ->count();
    }