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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
 
namespace app\common\model\agent;
 
use app\common\exception\BaseException;
use think\facade\Cache;
use app\common\model\BaseModel;
 
/**
 * 应用模型
 */
class Client extends BaseModel
{
    protected $name = 'dl_client';
    protected $pk = 'client_id';
 
    /**
     * 获取应用信息
     */
    public static function detail($client_id)
    {
        return (new static())->with(['app','shopuser','role','roleaccess'])->find($client_id);
    }
 
    /**
     * 从缓存中获取app信息
     */
    public static function getClientCache($client_id = null)
    {
        if (is_null($client_id)) {
            $self = new static();
            $client_id = $self::$client_id;
        }
        if (!$data = Cache::get('agent_' . $client_id)) {
            $data = self::detail($client_id);
            if (empty($data)) throw new BaseException(['msg' => '未找到当前应用信息']);
            Cache::tag('cache')->set('agent_' . $client_id, $data);
        }
        return $data;
    }
 
    /**
     * 启用商城
     * @return bool
     */
    public function updateStatus()
    {
        return $this->save([
            'status' => !$this['status'],
        ]);
    }
 
    /**
     * 所有商城
     */
    public static function getAll(){
        return (new self())->where('is_delete', '=', 0)
            ->where('is_recycle', '=', 0)
            ->select();
    }
    /**
     * 关联应用
     * @return \think\model\relation\BelongsTo
     */
    public function applic(){
        return $this->belongsTo('app\\common\\model\\agent\\Client_applic', 'client_id', 'client_id');
    }
    /**
     * 关联商城----客户下的商城
     * @return \think\model\relation\BelongsTo
     */
    public function app(){
        return $this->belongsTo('app\\common\\model\\app\\App', 'app_id', 'app_id');
    }
    public function shopuser(){
        return $this->belongsTo('app\\common\\model\\shop\\User', 'client_id', 'client_id');
    }
    public function role(){
        return $this->belongsTo('app\\common\\model\\shop\\Role', 'client_id', 'client_id');
    }
    public function roleaccess(){
        return $this->hasMany('app\\common\\model\\agent\\RoleAccess', 'client_id', 'client_id');
    }
    /**
     * 关联门店----客户下的门店
     * @return \think\model\relation\BelongsTo
     */
    public function store(){
        return $this->hasMany('app\\common\\model\\agent\\Store', 'client_id', 'client_id');
    }
}