微信截图_20171127112435.png
AppActive.php(Model)
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/27
* Time: 11:45
*/
namespace app\common\model;
class AppActive extends Base
{
}
Index.php(Controller)
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/11/23
* Time: 15:48
*/
namespace app\api\controller\v1;
use app\api\controller\Common;
use app\common\lib\exception\ApiException;
use think\Log;
class Index extends Common
{
public function index()
{
$heads = model('News')->getIndexHadNormalNews();
$heads = $this->getDealNews($heads);
$positions = model('News')->getPositionNormalNews();
$positions = $this->getDealNews($positions);
$result = [
'heads' => $heads,
'positions' => $positions,
];
return show(config('code.success'), 'OK', $result, 200);
}
/**
* 客户端初始化接口
* 1.检测APP是否需要升级
*
*/
public function init()
{
//app_type 去ent_version 查询
$version = model('Version')->
getLastNormalVersionByAppType($this->headers['app_type']);
if (empty($version)) {
return new ApiException('error', 404);
}
if ($version->version > $this->headers['version']) {
$version->is_update = $version->is_force == 1 ? 2 : 1;
} else {
$version->is_update = 0; //0不更新 1 需要更新 2强制更新
}
//记录用户的基本信息 用于统计
$actives = [
'version' => $this->headers['version'],
'app_type' => $this->headers['app_type'],
'did' => $this->headers['did'],
];
try{
model('AppActive')->add($actives);
}catch(\Exception $e){
//统计异常不用暴露给客户端
//Log::write()
//halt($e);
}
return show(config('code.success'), 'OK', $version, 200);
}
}
image.png
image.png
网友评论