quanwei
2025-11-26 6ae85f8ddbae19f5586f4b0c37680fe21889ef14
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
<?php
 
namespace app\common\model\file;
 
use app\common\model\BaseModel;
use app\shop\model\file\UploadFile;
 
/**
 * 文件库分组模型
 */
class UploadGroup extends BaseModel
{
    protected $name = 'upload_group';
    protected $pk = 'group_id';
 
    /**
     * 分组详情
     */
    public static function detail($group_id, $shop_supplier_id = 0, $branch_id = 0) {
        return (new static())->where('shop_supplier_id', '=', $shop_supplier_id)
        ->where('branch_id', '=', $branch_id) // by lyzflash
        ->find($group_id);
    }
 
    /**
     * 获取列表记录
     */
    public function getList($groupType = '', $shop_supplier_id = 0, $branch_id = 0)
    {
        $model = $this;
        !empty($groupType) && $model = $model->where('group_type', '=', trim($groupType));
        return $model->where('shop_supplier_id', '=', $shop_supplier_id)
            ->where('branch_id', '=', $branch_id)
            ->where('is_delete', '=', 0)
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->select();
    }
 
    /**
     * 添加新记录
     */
    public function add($data)
    {
        return $this->save(array_merge([
            'app_id' => self::$app_id,
            'sort' => 100
        ], $data));
    }
 
    /**
     * 更新记录
     */
    public function edit($data)
    {
        return $this->save($data) !== false;
    }
 
    /**
     * 删除记录
     */
    public function remove()
    {
        // 更新该分组下的所有文件
        (new UploadFile())->where('group_id', '=', $this['group_id'])
            ->update(['group_id' => 0]);
        // 删除分组
        return $this->save(['is_delete' => 1]);
    }
}