quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
 
namespace app\operations\controller\product;
 
use app\common\model\product\ProductCategory as ProductCategoryModel;
 
/**
 * 商品多分类模型
 */
class ProductCategory extends ProductCategoryModel
{
    /**
     * 添加商品分类关系记录
     */
    public function addCategoryList($product_id, $category_ids)
    {
      $data = [];
      $model = new self;
      foreach ($category_ids as $item) {
        $data[] = [
          'product_id' => $product_id,
          'category_id' => $item,
          'app_id' => self::$app_id,
        ];
      }
      count($data) > 0 && $model->saveAll($data);
    }
 
    /**
     * 移除指定商品的所有分类
     */
    public function removeAll($product_id)
    {
      $model = new self;
      return $model->where('product_id','=', $product_id)->delete();
    }
 
}