quanwei
2025-11-28 3ea53e61cc23fdb3ddf8b38a199ca60a6da8c407
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
<?php
 
namespace app\common\model\order;
 
use app\common\model\BaseModel;
 
/**
 * 购物车模型模型
 */
class Cart extends BaseModel
{
    protected $pk = 'cart_id';
    protected $name = 'user_cart';
 
    /**
     * 关联商品表
     * @return \think\model\relation\BelongsTo
     */
    public function product()
    {
        return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
    }
 
    /**
     * 关联用户表
     * @return \think\model\relation\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id');
    }
 
    /**
     * 购物车详情
     */
    public static function detail($where, $with = ['user', 'product.image'])
    {
        is_array($where) ? $filter = $where : $filter['cart_id'] = (int)$where;
        return (new static())->with($with)->where($filter)->find();
    }
 
}