作者 lihan

若干杂项完善

... ... @@ -33,7 +33,7 @@ class ActivityController extends HomeBaseController
$model = new ActivityModel;
$t_id = request()->param('t_id');
$keyword = request()->param('keyword');
$activity = $model->activityList($t_id, time(), session('user.id'), $keyword);
$activity = $model->activityList($t_id, time(), session('user.id'), $keyword, '', '');
$result = [
'banner' => $banner,
'type' => $type,
... ... @@ -180,4 +180,42 @@ class ActivityController extends HomeBaseController
return $res;
}
/**
* @title Ajax切换批次显示信息
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /activity/Activity/alterSchedule
* @method POST
*
* @param name:schedule_id type:int require:1 default:56 other: desc:批次id
*/
public function alterSchedule()
{
$request = request();
if ($request->isPost()) {
$schedule_id = $request->param('schedule_id');
$data = Db::name('activity_schedule')
->field('id as schedule_id,price,start_time,end_time,real_join_num,addition_join_num,maximum')
->where(['id' => $schedule_id])
->find();
if (!empty($data)) {
$data['start_time'] = date('Y.m.d', $data['start_time']);
$data['end_time'] = date('Y.m.d', $data['end_time']);
$data['sales_num'] = $data['real_join_num'] + $data['addition_join_num'];
$data['residue_num'] = $data['maximum'] - $data['sales_num'];
unset($data['real_join_num']);
unset($data['addition_join_num']);
unset($data['maximum']);
echo json_encode(['data' => $data, 'code' => 20000]);
exit();
} else {
echo json_encode(['msg' => '未知错误', 'code' => 40000]);
exit();
}
} else {
echo json_encode(['msg' => '非法操作', 'code' => 40000]);
exit();
}
}
}
\ No newline at end of file
... ...
... ... @@ -18,12 +18,14 @@ class ActivityModel extends Model
* @param $nowTime
* @param $userId
* @param null $keyword
* @param null $isNew
* @param null $isHot
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function activityList($tId = null, $nowTime, $userId, $keyword = null)
public function activityList($tId = null, $nowTime, $userId, $keyword = null, $isNew = null, $isHot = null)
{
$where = [];
if ($tId != null) {
... ... @@ -32,6 +34,12 @@ class ActivityModel extends Model
if ($keyword != null) {
$where['name'] = ['like', "%$keyword%"];
}
if ($isNew != null) {
$where['is_new'] = ['eq', 1];
}
if ($isHot != null) {
$where['is_hot'] = ['eq', 1];
}
$res = Db::name('activity')->field('id,name,thumb')->where($where)->select()->toArray();
//只显示还未到报名日期活动最近的一条行程
foreach ($res as $key => $item) {
... ... @@ -70,8 +78,8 @@ class ActivityModel extends Model
->where(['activity_id' => $activityId])
->select();
foreach ($res as $k => $v) {
$v['start_time'] = date('Y-m-d', $v['start_time']);
$v['end_time'] = date('Y-m-d', $v['end_time']);
$v['start_time'] = date('Y.m.d', $v['start_time']);
$v['end_time'] = date('Y.m.d', $v['end_time']);
$v['sales_num'] = $v['real_join_num'] + $v['addition_join_num'];
$v['residue_num'] = $v['maximum'] - $v['sales_num'];
unset($v['real_join_num']);
... ...
... ... @@ -20,15 +20,51 @@ class NewsController extends HomeBaseController
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /news/News/newsList
* @method POST
*
* @param name:t_id type:int require:1 default:11 other: desc:分类id
*/
public function newsList()
{
$news_type = Db::name('portal_category')->field('id as t_id,name,more')->where(['parent_id' => 10])->select();
foreach ($news_type as $k => $v) {
$arr = json_decode($v['more'], true);
$v['thumb'] = cmf_get_image_url($arr['thumbnail']);
unset($v['more']);
$news_type[$k] = $v;
}
$t_id = (request()->param('t_id') == null) ? $news_type[0]['t_id'] : request()->param('t_id');
$news_list = Db::name('portal_category_post')->alias('c')
->field('c.post_id as id,p.post_title,p.post_hits,more')
->join('portal_post p', 'p.id=c.post_id')
->where(['c.category_id' => $t_id])
->select();
$collect = Db::name('collect_news')->field('post_id')->where(['user_id' => session('user.id')])->select();
foreach ($collect as $k => $v) {
$temp[$k] = $v['post_id'];
}
foreach ($news_list as $k => $v) {
$arr = json_decode($v['more'], true);
$v['thumb'] = cmf_get_image_url($arr['thumbnail']);
unset($v['more']);
if (in_array($v['id'], $temp)) {
$v['is_collect'] = 1;
} else {
$v['is_collect'] = 0;
}
$news_list[$k] = $v;
}
$return = [
'news_type' => $news_type,
'type_name' => Db::name('portal_category')->where(['id' => $t_id])->value('name'),
'news_list' => $news_list
];
echo json_encode(['data' => $return, 'code' => 20000]);
exit();
}
/**
* @title 新闻详情
* @description 接口说明
* @description 接口说明(指定id为购买协议)
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /news/News/detail
* @method GET
... ... @@ -38,6 +74,8 @@ class NewsController extends HomeBaseController
public function detail()
{
$id = request()->param('id');
//阅读量+1
Db::name('portal_post')->where(['id'=>$id])->setInc('post_hits', 1);
$news = Db::name('portal_post')->field('post_title,post_content,published_time')->where(['id' => $id])->find();
$news['published_time'] = date('Y/m/d', $news['published_time']);
$news['post_content'] = html_entity_decode($news['post_content']);
... ...
... ... @@ -19,13 +19,6 @@ use EasyWeChat\Foundation\Application;
*/
class IndexController extends HomeBaseController
{
function __construct()
{
session('user.id', 2);
echo session('user.id');
}
/**
* @title 接口返回参数说明
* @description 默认访问接口
... ... @@ -54,9 +47,36 @@ class IndexController extends HomeBaseController
}
/**
* @title 首页
* @description 默认访问接口
* @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
* @url /portal/Index/index
* @method GET
*
* @return version:版本号
* @return code:错误码
*/
public function index()
{
//首页轮播图
$banner = Db::name('slide_item')->field('image,url')->where(['slide_id' => 1])->order('list_order')->select();
//分类
$type = Db::name('type')->field('type_name,type_url,type_icon')->order('listorder')->select();
//活动
$model = new ActivityModel;
$t_id = request()->param('t_id');
$keyword = request()->param('keyword');
$is_new = $model->activityList($t_id, time(), session('user.id'), $keyword, 1, '');
$is_hot = $model->activityList($t_id, time(), session('user.id'), $keyword, '', 1);
$result = [
'banner' => $banner,
'type' => $type,
'is_new' => $is_new,
'is_hot' => $is_hot
];
echo json_encode(['data' => $result, 'code' => 20000]);
exit();
}
}
\ No newline at end of file
... ...
<?php return array (
'户外频道/:id' =>
array (
0 => 'portal/Article/index?cid=8',
0 => 'portal/Article/index?cid=10',
1 =>
array (
),
2 =>
array (
'id' => '\d+',
'cid' => '\d+',
),
),
'购买协议/:id' =>
array (
0 => 'portal/Article/index?cid=9',
1 =>
array (
),
2 =>
array (
'id' => '\d+',
'cid' => '\d+',
),
),
'旅行报道/:id' =>
array (
0 => 'portal/Article/index?cid=11',
1 =>
array (
),
... ... @@ -13,7 +37,29 @@
),
'户外频道' =>
array (
0 => 'portal/List/index?id=8',
0 => 'portal/List/index?id=10',
1 =>
array (
),
2 =>
array (
'id' => '\d+',
),
),
'购买协议' =>
array (
0 => 'portal/List/index?id=9',
1 =>
array (
),
2 =>
array (
'id' => '\d+',
),
),
'旅行报道' =>
array (
0 => 'portal/List/index?id=11',
1 =>
array (
),
... ...