Browse Source

公告接口

master
wanghongjun 3 years ago
parent
commit
903f4d927c
  1. 56
      app/controller/Index.php
  2. 14
      app/model/Notice.php
  3. 2
      app/model/Zone.php
  4. 3
      config/database.php
  5. 5
      route/app.php

56
app/controller/Index.php

@ -3,8 +3,11 @@ namespace app\controller;
use app\BaseController;
use app\model\AwardsRecords;
use app\model\Notice;
use app\model\RotationChart;
use app\model\User as UserModel;
use app\model\Zone as ZoneModel;
use think\exception\ValidateException;
use think\facade\Request;
class Index extends BaseController
@ -24,14 +27,14 @@ class Index extends BaseController
$list = $RotationChart
->field('image,url')
->where('status',1)
->order('create_time desc')
->order('sort asc,create_time desc')
->paginate($limit);
$data = $list->toArray()['data'];
foreach ($data as &$item) {
$item['image'] = get_image_url($item['image']);
$item['url'] = get_jump_url($item['url']);
if ($item['url']) $item['url'] = get_jump_url($item['url']);
}
return $this->renderSuccess('数据返回成功',[
@ -72,4 +75,53 @@ class Index extends BaseController
'total' => $list->total()
]);
}
/**
* 首页专区列表
* @return array
*/
public function zoneList()
{
return $this->renderSuccess('数据返回成功',ZoneModel::getList());
}
/**
* 返回公告
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getNotice()
{
$Notice = Notice::where('status',1)->order('create_time','desc')->find();
return $this->renderSuccess('数据返回成功',!empty($Notice) ? ['id' => $Notice->id, 'title' => $Notice->title] : []);
}
/**
* 公告详情
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getNoticeInfo()
{
$param = Request::param();
try {
validate()->rule(['id|公告id' => 'require|number'])->check($param);
$Notice = Notice::where('id',$param['id'])->order('create_time','desc')->find();
return $this->renderSuccess('数据返回成功',[
'title' => $Notice->title,
'create_time' => date("Y.m.d H:i:s",strtotime($Notice->create_time)),
'content' => $Notice->content
]);
} catch (ValidateException $validateException) {
return $this->renderError($validateException->getMessage());
}
}
}

14
app/model/Notice.php

@ -0,0 +1,14 @@
<?php
declare (strict_types = 1);
namespace app\model;
use think\Model;
/**
* @mixin \think\Model
*/
class Notice extends Model
{
//
}

2
app/model/Zone.php

@ -8,7 +8,7 @@ class Zone extends Model
{
public static function getList()
{
$zone = self::where('status',1)->select();
$zone = self::where('status',1)->field('id,title')->select();
return $zone->toArray();
}

3
config/database.php

@ -80,6 +80,7 @@ return [
'ggl_zone',
'ggl_zone_amount_param',
'ggl_zone_goods',
'ggl_zone_goods_param'
'ggl_zone_goods_param',
'ggl_notice',
]
];

5
route/app.php

@ -28,6 +28,9 @@ Route::group('passport',function (){
Route::group('index',function () {
Route::post('awardRecords','index/awardRecords');
Route::post('rotationChart','index/rotationChart');
Route::post('zoneList','index/zoneList');
Route::post('getNotice','index/getNotice');
Route::post('getNoticeInfo','index/getNoticeInfo')->middleware(CheckUser::class);
})->allowCrossDomain();
Route::group('user',function (){
@ -40,7 +43,7 @@ Route::group('user',function (){
})->middleware(CheckUser::class)->allowCrossDomain();
Route::group('zone',function(){
Route::post('zoneList','zone/zoneList')->allowCrossDomain();
#Route::post('zoneList','zone/zoneList');
Route::post('zoneGoodsList','zone/zoneGoodsList');
Route::post('beginLottery','zone/beginLottery');
Route::post('endLottery','zone/endLottery');

Loading…
Cancel
Save