quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
<?php
 
namespace app\operations\model\branch;
 
use app\common\model\branch\Activity as ActivityModel;
use app\common\model\user\User as UserModel;
 
/**
 * 活动模型
 */
class Activity extends ActivityModel
{
    /**
     * 获取列表
     */
    public function getList($params)
    {
        return $this->with(['image', 'category', 'branch'])
            ->where('is_delete', '=', 0)
            ->order(['sort' => 'desc', 'create_time' => 'desc'])
            ->paginate($params);
 
    }
 
    /**
     * 新增记录
     */
    public function add($data)
    {
        $data['app_id'] = self::$app_id;
        //报名时间
        $data['register_start_time'] = strtotime($data['reg_date'][0]);
        $data['register_end_time'] = strtotime($data['reg_date'][1]);
        //活动时间
        $data['activity_start_time'] = strtotime($data['act_date'][0]);
        $data['activity_end_time'] = strtotime($data['act_date'][1]);
        // 格式化坐标信息
        $coordinate = explode(',', $data['coordinate']);
        $data['latitude'] = $coordinate[0];
        $data['longitude'] = $coordinate[1];
        return $this->save($data);
    }
 
    /**
     * 更新记录
     */
    public function edit($data)
    {
        //报名时间
        $data['register_start_time'] = strtotime($data['reg_date'][0]);
        $data['register_end_time'] = strtotime($data['reg_date'][1]);
        //活动时间
        $data['activity_start_time'] = strtotime($data['act_date'][0]);
        $data['activity_end_time'] = strtotime($data['act_date'][1]);
        // 格式化坐标信息
        $coordinate = explode(',', $data['coordinate']);
        $data['latitude'] = $coordinate[0];
        $data['longitude'] = $coordinate[1];
        return $this->save($data);
    }
 
    /**
     * 软删除
     */
    public function setDelete()
    {
        return $this->save(['is_delete' => 1]);
    }
 
    /**
     * 获取活动总数量
     */
    public static function getActivityTotal($where)
    {
        $model = new static;
        return $model->where($where)->where('is_delete', '=', 0)->count();
    }
 
    /**
     * 开启禁止
     */
    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;
        }
    }
 
}