huangsijun
2025-09-22 a78c011de350b188afb03beb2f26a73f35f71986
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
 
namespace app\api\model\plus\live;
 
use app\common\model\plus\live\LiveProduct as LiveProductModel;
use app\common\model\product\Product as ProductModel;
/**
 * 直播模型
 */
class LiveProduct extends LiveProductModel
{
 
    /**
     * 获取商品列表
     */
    public function getList($data)
    {
        $model = new ProductModel();
        return $model->with(['image.file'])
            ->where('shop_supplier_id', '=', $data['shop_supplier_id'])
            ->where('audit_status', '=', 10)
            ->where('product_status', '=', 10)
            ->order(['create_time' => 'asc'])
            ->paginate($data);
    }
 
 
    /**
     * 保存
     */
    public function add($user, $productIds)
    {
        if(!isset($productIds) || $productIds == ''){
            return true;
        }
        $this->startTrans();
        try {
            $productList = [];
            $productIdArr = explode(',', $productIds);
            foreach ($productIdArr as $productId) {
                $productList[] = [
                    'user_id' => $user['user_id'],
                    'shop_supplier_id' => $user['supplierUser']['shop_supplier_id'],
                    'product_id' => $productId,
                    'app_id' => self::$app_id
                ];
            }
            $this->saveAll($productList);
            // 事务提交
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
 
    public function remove($product_id){
        return $this->where('product_id', '=', $product_id)
            ->delete();
    }
    //查询已经添加产品
    public function livProduct($shop_supplier_id){
        return $this->where('shop_supplier_id','=',$shop_supplier_id)->column('product_id');
    }
}