quanwei
2026-01-17 e1e2fe5710a5b5cd9c19bd3aa99c998a1a613ca8
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
 
namespace app\agent\model;
 
use app\common\model\agent\Store as StoreModel;
 
/**
 * 超管后台门店模型
 */
class Store extends StoreModel
{
    /**
     * 获取全部
     */
    public static function getAll()
    {
        $model = new static;
        $agent_id=self::$agent_id;
        
        $data = $model->with('agent')->where('agent_id', '=', $agent_id)->where('is_delete', '=', 0)->select();
        $data->each(function($item,$key){
            $item['expire_status'] = is_expire_status($item['end_date']);
            $item['status_name'] = status($item['status']);
            $item['date_value'] = [$item['register_date'],$item['end_date']];
 
            $item['month_register'] = 0;
        });
        return $data;
    }
    /**
     * 搜索指定数据--搜索
     */
    public static function search($data)
    {
        $agent_id=self::$agent_id;
        $model = new static;
        
        $list = $model->where('is_delete', '=', 0)->where('agent_id', '=', $agent_id)
        ->where('store_name', 'like', '%'.$data[0].'%')
        ->where('store_type', 'like', '%'.$data[1].'%')
        ->where('status', 'like', '%'.$data[2].'%')
        ->where('store_app_name', 'like', '%'.$data[4].'%')
        ->select();
        
        $list->each(function($item,$key){
            $item['expire_status'] = is_expire_status($item['end_date']);
            $item['status_name'] = status($item['status']);
            $item['date_value'] = [$item['register_date'],$item['end_date']];
 
            $item['month_register'] = '预留';
        });
        return $list;
    }
    /**
     * 获取头部数据
     */
    public static function gethead()
    {
        $agent_id=self::$agent_id;
        $model = new static;
        $newtime = strtotime(Date('Y-m-d'));//当日零点时间戳
        $yetime = $newtime - 86400;//strtotime(date('Y-m-d',strtotime('-1 day')))
 
        $list = $model->where('is_delete','=',0)->where('agent_id', '=', $agent_id)->select();//总数
        $list2 = $model->where('is_delete','=',0)->where('agent_id', '=', $agent_id)->where('status','=',1)->select();//通过总数
        $list3 = $model->where('is_delete','=',0)->where('agent_id', '=', $agent_id)
                        ->where('create_time','<=',$newtime)
                        ->where('create_time','>=',$yetime)
                        ->select();//昨日新增总数
        $list4 = $model->where('is_delete','=',0)->where('agent_id', '=', $agent_id)->where('end_date','<',date('Y-m-d H:i:s'))->select();//通过总数
 
        $data = [];
        $data[] = count($list);//总数
        $data[] = count($list2);//正常使用总数
        //$data[] = $date;
        $data[] = count($list3);//昨日新增总数
        $data[] = count($list4);//已过期总数
 
        return $data;
    }
 
    
    /**
     * 获取当前门店总数
     */
    public function getStoreTotal($agent_id,$day = null)
    {
        $model = $this;
        if (!is_null($day)) {
            $startTime = strtotime($day);
            $model = $model->where('create_time', '>=', $startTime)
                ->where('create_time', '<', $startTime + 86400);
        }
        return $model->where('agent_id', '=', $agent_id)->where('is_delete', '=', '0')->count();
    }
 
    /**
     * 新增
     */
    public function add($data)
    {
        $data['agent_id']=self::$agent_id;
        return $this->save($data);
    }
 
 
    /**
     * 软删除
     */
    public function setDelete()
    {
        return $this->save(['is_delete' => 1]);
    }
 
    /**
     * 更新记录
     */
    public function edit($data)
    {
        return $this->save($data);
    }
 
}