Api.php
2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Env;
use think\facade\Request;
class Api{
protected $filepath,$publicpath,$viewSuffix;
function initialize()
{
parent::initialize();
$viewPath = config('template.view_path');
$this->viewSuffix = config('template.view_suffix');
$viewPath = $viewPath ? $viewPath : 'view';
$this->filepath = Env::get('app_path').strtolower(config('default_module')).'/'.$viewPath.'/';
$this->publicpath = 'static/android/';
$this->assign ( 'viewSuffix',$this->viewSuffix );
}
//获取最新版本
public function compareVersion() {
$flag = input('get.flag') ? input('get.flag') : 1;
$list = db('android')->where(array('flag'=>$flag))->select();
if(isset($list)){
foreach ($list as $key => $value) {
$array[] = $value['version'];
}
}
if(isset($array)){
$newarray = array();
foreach ($array as $value) {
$newarray[] = explode('.',$value);
}
$max = $newarray[0][0];
foreach ($newarray as $v){
if($v[0]>$max){
$max = $v[0];
}
}
foreach ($newarray as $k=> $vl){
if($vl[0] != $max){
unset($newarray[$k]);
}
}
$max = $newarray[0][1];
foreach ($newarray as $v){
if($v[1]>$max){
$max = $v[1];
}
}
foreach ($newarray as $k=> $vl){
if($vl[1] != $max){
unset($newarray[$k]);
}
}
$max = $newarray[0][2];
foreach ($newarray as $k=> $v){
if($v[2]>$max){
$max = $v[2];
}
}
foreach ($newarray as $k=> $vl){
if($vl[2] != $max){
unset($newarray[$k]);
}
}
foreach ($newarray as $ve) {
$ay = implode('.',$ve);
}
}
$version = db('android')->where(array('version'=>$ay,'flag'=>$flag))->select();
if($version){
$str = "http://xt03.colorcun.com".$version['0']['file_url'];
$version[0]['file_url'] = $str;
$result['ret'] = 200;
$result['data'] = $version;
$result['msg'] = 'success';
return json_encode($result);
}else{
$result['ret'] = 0;
$result['data'] = '';
$result['msg'] = 'fail';
return json_encode($result);
}
}
}