quanwei
2025-11-15 6f12eadd25c8f5335fd9eccf373bf9835bf3e4c6
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
<?php
 
namespace app\common\model\takeout;
 
use app\common\model\BaseModel;
 
 
/**
 * 用户模型
 */
class Commander extends BaseModel
{
    protected $name = 'takeout_commander';
    protected $pk = 'commander_id';
 
    /**
     * 关联会员记录表
     * @return \think\model\relation\BelongsTo
     */
    public function user()
    {
        return $this->belongsTo('app\\common\\model\\user\\User','user_id','user_id');
    }
 
    /**
     * 关联学校记录表
     * @return \think\model\relation\BelongsTo
     */
    public function school()
    {
        return $this->belongsTo('app\\common\\model\\takeout\\School','school_id','school_id');
    }
 
 
    /**
     * 详情
     */
    public static function detail($commander_id, $with = ['user','school'])
    {
        return (new static())->with($with)->where("is_delete","=",0)->find($commander_id);
    }
 
    /**
     * 详情
     */
    public static function getDetail($user_id, $with = ['user','school'])
    {
        return (new static())->with($with)->where("is_delete","=",0)->where("user_id","=",$user_id)->find();
    }
 
    /**
     * 是否为团长
     */
    public static function isCommander($user_id)
    {
        $user = self::getDetail($user_id);
        return !!$user && !$user['is_delete'];
    }
 
    /**
     * 新增记录
     * @param $user_id
     * @param $data
     * @return bool
     */
    public static function add($user_id, $data)
    {
        $model = new static;
         $model->save(array_merge([
            'user_id' => $user_id,
            'is_delete' => 0,
            'app_id' => $model::$app_id,
        ], $data));
        return true;
    }
}