huangsijun
2025-09-22 a78c011de350b188afb03beb2f26a73f35f71986
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
<?php
 
namespace app\supplier\model\settings;
 
use app\common\model\settings\Stall as StallModel;
use app\common\enum\settings\StallTypeEnum;
 
class Stall extends StallModel
{
    /**
     * 添加新记录
     */
    public function add($data)
    {
        $data['app_id'] = self::$app_id;
        return $this->save($data);
    }
 
    /**
     * 编辑记录
     */
    public function edit($data)
    {
        return $this->save($data);
    }
 
    /**
     * 删除记录
     * @return bool|int
     */
    public function setDelete()
    {
        return $this->save(['is_delete' => 1]);
    }
 
    /**
     * 检查是否有默认档口,没有则添加
     */
    public static function checkDefault($shop_supplier_id)
    {
        $model = (new static);
        $count = $model->where('shop_supplier_id', '=', $shop_supplier_id)->where('is_default', '=', 1)->count();
        if (!$count) {
            $data = [];
            $stallType = StallTypeEnum::data();
            foreach ($stallType as $type) {
                $data[] = [
                    'stall_name' => $type['name'],
                    'stall_type' => $type['value'],
                    'is_default' => 1,
                    'shop_supplier_id' => $shop_supplier_id,
                    'app_id' => self::$app_id,
                ];
            }
            $model->saveAll($data);
        }
        return true;
    }
 
}