MAppVersion.Class.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace JinDouYun\Model\System;
  3. use JinDouYun\Dao\System\DAppVersion;
  4. use Mall\Framework\Core\ErrorCode;
  5. use Mall\Framework\Core\ResultWrapper;
  6. /**
  7. * Class MAppVersion
  8. * @package JinDouYun\Model\System
  9. */
  10. class MAppVersion
  11. {
  12. /**
  13. * @var integer 企业id
  14. */
  15. private $onlineEnterpriseId;
  16. /**
  17. * @var DAppVersion
  18. */
  19. private $objDAppVersion;
  20. /**
  21. * MAppVersion constructor.
  22. * @param $enterpriseId
  23. */
  24. public function __construct($enterpriseId)
  25. {
  26. $this->onlineEnterpriseId = $enterpriseId;
  27. $this->objDAppVersion = new DAppVersion();
  28. }
  29. /**
  30. * @param string $oldVersion
  31. * @return ResultWrapper
  32. */
  33. public function getVersion(string $oldVersion)
  34. {
  35. $map = [
  36. 'isUpdate' => true,
  37. 'oldVersion' => $oldVersion,
  38. ];
  39. if (empty($oldVersion)){
  40. $map['isUpdate'] = false;
  41. return ResultWrapper::success($map);
  42. }
  43. $dbResult = $this->objDAppVersion->get(['enterpriseId'=> $this->onlineEnterpriseId],'appVersion,downloadUrl');
  44. if ($dbResult === false){
  45. return ResultWrapper::fail($this->objDAppVersion->error(),ErrorCode::$dberror);
  46. }
  47. if (empty($dbResult)){
  48. $map['isUpdate'] = false;
  49. return ResultWrapper::success($map);
  50. }
  51. switch (version_compare($oldVersion,$dbResult['appVersion'])){
  52. case 0:
  53. //旧版本等与新版本
  54. $map['isUpdate'] = false;
  55. break;
  56. case 1:
  57. //旧版本>新版本
  58. $map['isUpdate'] = false;
  59. break;
  60. case -1:
  61. //旧版本<新版本
  62. $map['isUpdate'] = true;
  63. $map['appVersion'] = $dbResult['appVersion'];
  64. $map['downloadUrl'] = $dbResult['downloadUrl'];
  65. break;
  66. }
  67. return ResultWrapper::success($map);
  68. }
  69. }