quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
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
<?php
 
namespace app\common\model\plus\groupbuy;
 
use app\common\library\helper;
use app\common\model\BaseModel;
 
/**
 * 团购活动模型
 */
class Active extends BaseModel
{
    protected $name = 'groupbuy_active';
    protected $pk = 'groupbuy_active_id';
 
    /**
     * 关联文件表
     */
    public function file()
    {
        return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id');
    }
    public function getEndTimeAttr($value)
    {
        return date('Y-m-d H:i:s', $value);
    }
    public function getStartTimeAttr($value)
    {
        return date('Y-m-d H:i:s', $value);
    }
    /**
     * 获取活动详情
     */
    public static function detail($groupbuy_active_id,$with = ['file'])
    {
        return (new static())->with($with)->where('groupbuy_active_id', '=', $groupbuy_active_id)->find();
    }
 
    /**
     * 获取有效的团购活动
     */
    public static function getValidActive()
    {
        return (new static())
            ->where('start_time', '<=', time())
            ->where('end_time', '>', time())
            ->where('status', '=', 1)
            ->where('is_delete', '=', 0)
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->find();
    }
 
    /**
     * 获取活动列表
     */
    public function getList($param)
    {
        $model = $this;
        if (isset($param['status']) && $param['status'] > -1) {
            $model = $model->where('status', '=', $param['status']);
        }
        if (isset($param['title']) && !empty($param['title'])) {
            $model = $model->where('active_name', 'like', '%' . trim($param['title']) . '%');
        }
        $res = $model->with(['file'])
            ->order('create_time', 'desc')
            ->paginate($param);
 
        foreach ($res as $key => $val) {
            $res[$key]['start_time'] = format_time($val['start_time']);
            $res[$key]['end_time'] = format_time($val['end_time']);
        }
        return $res;
    }
}