Commit 2446428e0418e8ebac93244237a66e9a215e6168

Authored by u123231312
1 parent b9f68fc4

no message

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