Version.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\api\service;
  10. use app\common\models\Version as VersionModel;
  11. use mall\utils\Check;
  12. use think\facade\Request;
  13. class Version extends Service {
  14. /**
  15. * 获取APP升级数据
  16. * @param $data
  17. * @return array
  18. * @throws \think\db\exception\DataNotFoundException
  19. * @throws \think\db\exception\DbException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. */
  22. public static function getData($data){
  23. $ver = $data["ver"]??"";
  24. $type = $data["type"]??1;
  25. if(empty($ver)){
  26. throw new \Exception("获取版本号失败",0);
  27. }
  28. $row = VersionModel::where("type='{$type}' AND version > '" . $ver . "'")->order("version","ASC")->find();
  29. if(empty($row)){
  30. throw new \Exception("当前已是最新版本",0);
  31. }
  32. if(!Check::url($row["url"])){
  33. $row["url"] = str_replace("\\", "/", Request::domain() . "/" . trim($row["url"],"/"));
  34. }
  35. return [
  36. "status"=>1,"info"=>"ok",
  37. "data"=>[
  38. "url"=>$row["url"],
  39. "content"=>$row["content"]
  40. ]
  41. ];
  42. }
  43. }