with(['image', 'category']) ->where('branch_id', '=', $branch_id) ->where('is_delete', '=', 0) ->order(['sort' => 'desc', 'create_time' => 'desc']) ->paginate($params); } /** * 新增记录 */ public function add($data, $branch_id) { $data['app_id'] = self::$app_id; $data['branch_id'] = $branch_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; } } public function activityGroupNum($date, $branch_id) { $field = 'count(*) as total,from_unixtime(create_time,\'%m-%d\') as `day`'; if ($date == 'year') { $field = 'count(*) as total,from_unixtime(create_time,\'%m\') as `day`'; } $model = $this->field($field) ->where('is_delete', '=', 0) ->when($date, function ($query, $date) { getModelTime($query, $date, 'create_time'); })->when($branch_id, function ($query, $branch_id) { $query->where('branch_id', $branch_id); }); return $model->order('create_time ASC')->group('day')->select(); } }