123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace JinDouYun\Model\System;
- use JinDouYun\Dao\System\DAppVersion;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- /**
- * Class MAppVersion
- * @package JinDouYun\Model\System
- */
- class MAppVersion
- {
- /**
- * @var integer 企业id
- */
- private $onlineEnterpriseId;
- /**
- * @var DAppVersion
- */
- private $objDAppVersion;
- /**
- * MAppVersion constructor.
- * @param $enterpriseId
- */
- public function __construct($enterpriseId)
- {
- $this->onlineEnterpriseId = $enterpriseId;
- $this->objDAppVersion = new DAppVersion();
- }
- /**
- * @param string $oldVersion
- * @return ResultWrapper
- */
- public function getVersion(string $oldVersion)
- {
- $map = [
- 'isUpdate' => true,
- 'oldVersion' => $oldVersion,
- ];
- if (empty($oldVersion)){
- $map['isUpdate'] = false;
- return ResultWrapper::success($map);
- }
- $dbResult = $this->objDAppVersion->get(['enterpriseId'=> $this->onlineEnterpriseId],'appVersion,downloadUrl');
- if ($dbResult === false){
- return ResultWrapper::fail($this->objDAppVersion->error(),ErrorCode::$dberror);
- }
- if (empty($dbResult)){
- $map['isUpdate'] = false;
- return ResultWrapper::success($map);
- }
- switch (version_compare($oldVersion,$dbResult['appVersion'])){
- case 0:
- //旧版本等与新版本
- $map['isUpdate'] = false;
- break;
- case 1:
- //旧版本>新版本
- $map['isUpdate'] = false;
- break;
- case -1:
- //旧版本<新版本
- $map['isUpdate'] = true;
- $map['appVersion'] = $dbResult['appVersion'];
- $map['downloadUrl'] = $dbResult['downloadUrl'];
- break;
- }
- return ResultWrapper::success($map);
- }
- }
|