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
<?php
 
namespace app\branch\model\position;
 
use app\common\model\branch\Position as PositionModel;
use app\common\model\branch\Member as MemberModel;
 
/**
 * 职务模型
 */
class Position extends PositionModel
{
    
    /**
     * 添加新记录
     */
    public function add($data)
    {
        $data['app_id'] = self::$app_id;
        return $this->save($data);
    }
 
    /**
     * 编辑记录
     */
    public function edit($data)
    {
      
        $data['update_time'] = time();
        return $this->save($data);
    }
 
    /**
     * 删除
     */
    public function remove()
    {
        // 判断是否存在
        $Count = (new MemberModel())->where('position_id','=' ,$this['position_id'])->where('is_delete','=', 0)->count();
        if ($Count > 0) {
            $this->error = '该职务使用中,不允许删除';
            return false;
        }
        return $this->delete();
    }
 
    /**
     * 开启禁止
     */
    public function setStatus($status)
    {   
        // 开启事务
        $this->startTrans();
        try {
            //更改分会状态
            $this->save(['status' => $status]); 
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
}