Commit 53e218f4 authored by clone's avatar clone

获取活动列表

parent e9e5454d
......@@ -44,6 +44,11 @@ class ActivityService
$arr["activity_rule"] = $activity_rule;
$arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s", time());
if ($activity_start_time > time()) {
$arr["status"] = 5;
} else {
$arr["status"] = 0;
}
return $arr;
}
}
......@@ -4,6 +4,7 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\api\service\ActivityService;
use app\model\CActivity;
use think\Request;
/**
......@@ -22,21 +23,25 @@ class Activity extends Basic
$this->activityService = new ActivityService();
}
/**
* 新增活动
* @return \think\Response
*/
public function createActivity()
{
$params = $this->params;
/* $params = array(
'title' => '活动1',
'return_type' => '1',
'money' => '1121',
'return_action' => '0',
'activity_start_time' => time(),
'activity_end_time' => time(),
'use_period' => 30,
'total' => 100,
'available' => 1,
'activity_rule' => '加拉时间的发送去问问人情味',
);*/
$params = $this->params;
/* $params = array(
'title' => '活动1',
'return_type' => '1',
'money' => '1121',
'return_action' => '0',
'activity_start_time' => time(),
'activity_end_time' => time(),
'use_period' => 30,
'total' => 100,
'available' => 1,
'activity_rule' => '加拉时间的发送去问问人情味',
);*/
$checkResult = $this->validate($params, "ActivityValidate.create");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
......@@ -51,16 +56,48 @@ class Activity extends Basic
$total = $params["total"];
$available = $params["available"];
$activity_rule = $params["activity_rule"];
if($activity_start_time <= time() || $activity_end_time < time()){
return $this->response("101","活动开始时间和结束时间不能小于当前时间");
if ($activity_start_time <= time() || $activity_end_time < time()) {
return $this->response("101", "活动开始时间和结束时间不能小于当前时间");
}
$is_ok = $this->activityService->createActivity($title, $return_type, $money, $return_action, $activity_start_time,
$activity_end_time, $use_period, $total, $available, $activity_rule);
if($is_ok > 0){
return $this->response("200","add success");
}else{
return $this->response("101","faild");
if ($is_ok > 0) {
return $this->response("200", "add success");
} else {
return $this->response("101", "faild");
}
}
/**
* 获取活动列表
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getActivityList()
{
$params = $this->params;
/* $params = array(
"title" => "asd",
"pageNo" => 1,
"pageSize" => 15,
);*/
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$activityModel = new CActivity();
$field = 'id,activity_start_time,activity_end_time,available,get_number';
$where_ = [];
if (!empty($params["title"])) {
$where_["title"] = array("like", "%" . trim($params['title']) . "%");
}
$where_["status"] = array("neq", 4);
$list = $activityModel->getActivityList($field, $where_, $pageNo, $pageSize);
return $this->response("200", "success", $list);
}
}
\ No newline at end of file
......@@ -56,6 +56,27 @@ class CActivity extends Model
return $result;
}
/**
* @param $field
* @param $params
* @param $pageNo
* @param $pageSize
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getActivityList($field,$params,$pageNo,$pageSize)
{
$result = $this->db_
->field($field)
->where($params)
->page($pageNo)
->limit($pageSize)
->select();
return $result;
}
/**
* 更新
* @param $activity_id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment