quanwei
2025-10-28 36cacbaf78e510713002fcd5e3d61cece2e01421
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
92
93
<?php
 
namespace app\common\model\plus\business;
use app\common\model\BaseModel;
 
/**
 * 名片管理模型
 */
class Business extends BaseModel
{
    protected $name='business_card';
 
    public function getSexAttr($value){
        $data=[10=>'未知',20=>'男',30=>'女'];
        return $data[$value];
    }
    /**
     * 关联用户
     * @return \think\model\relation\HasOne
     */
    public function user(){
        $model=self::getCalledModule()?:'common';
        return $this->hasOne("app\\$model\\model\\user\\User",'user_id','user_id');
    }
 
    /**
     * 头像
     * @return \think\model\relation\HasOne
     */
    public function image(){
        $model=self::getCalledModule()?:'common';
        return $this->hasOne("app\\$model\\model\\file\\UploadFile",'file_id','file_id')->bind(['file_path']);
    }
    /**
     * logo
     * @return \think\model\relation\HasOne
     */
    public function logoImage(){
        $model=self::getCalledModule()?:'common';
        return $this->hasOne("app\\$model\\model\\file\\UploadFile",'file_id','logo')->bind(['file_path']);
    }
    /**
     * 添加
     * @param $data
     * @return false|int
     */
    public function add($data){
        $data['app_id']=self::$app_id;
        return $this->save($data);
    }
    public function getUnitAttr($name)
    {
        return json_decode($name);
    }
    public function getDutiesAttr($name)
    {
        return json_decode($name);
    }
    public function getAddressAttr($name)
    {
        return json_decode($name);
    }
    public function getPositionAttr($name)
    {
        return $name?json_decode($name):[];
    }
 
    /**
     * 获取名片列表
     * @param $param
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getList($param=[]){
        $paramr=array_merge(['listRow'=>15],$param);
        $where=[];
        !empty($paramr['name'])&&$where['name']=['like','%'.$paramr['name'].'%'];
        !empty($paramr['search'])&&$where['name|duties|unit']=['like','%'.$paramr['search'].'%'];
        !empty($paramr['user_id'])&&$where['user_id']=$paramr['user_id'];
        if(!empty($paramr['sort'])){
            if($paramr['sort']=='name'){
                $order=['name'=>"asc"];
            }else if($paramr['sort']=='time'){
                $order=['create_time'=>"asc"];
            }else{
                $order=['unit'=>"asc"];
            }
        }else{
            $order=['is_default'=>'desc','create_time'=>'desc'];
        }
        return $this->with(['user','image','logoImage'])->order($order)->where($where)->paginate($paramr);
    }
}