quanwei
2025-12-31 48d31672b4d88900080093cd1632f9d2eb978d4d
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\common\model\settings;
 
use app\common\model\BaseModel;
 
/**
 * 配送模板模型
 */
class Delivery extends BaseModel
{
    protected $name = 'delivery';
    protected $pk = 'delivery_id';
 
    /**
     * 关联配送模板区域及运费
     */
    public function rule()
    {
        return $this->hasMany('DeliveryRule');
    }
 
    /**
     * 计费方式
     */
    public function getMethodAttr($value)
    {
        $method = [10 => '按件数', 20 => '按重量'];
        return ['text' => $method[$value], 'value' => $value];
    }
 
    /**
     * 获取全部
     */
    public static function getAll($shop_supplier_id = 0)
    {
        $model = new static;
        if($shop_supplier_id > 0){
            $model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
        }
        return $model->order(['sort' => 'asc'])->select();
    }
 
    /**
     * 获取列表
     */
    public function getList($limit = 10,$shop_supplier_id=0)
    {   
        $where = [];
        if($shop_supplier_id){
            $where['shop_supplier_id'] = $shop_supplier_id;
        }
        return $this->with(['rule'])
            ->where($where)
            ->order(['sort' => 'asc'])
            ->paginate($limit);
    }
 
    /**
     * 运费模板详情
     */
    public static function detail($delivery_id)
    {
        return (new static())->find($delivery_id, ['rule']);
    }
 
}