<?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;
|
}
|
}
|
|
}
|