|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
-
- namespace backend\modules\api\models;
-
- use yii\db\ActiveRecord;
-
- /**
- * This is the model class for table "driver_app_update_status".
- *
- * @property integer $id
- * @property integer $driver_res_id
- * @property integer $driver_bus_type
- * @property string $driver_update_time
- * @property string $publish_update_time
- * @property string $download_address
- * @property string $driver_name
- * @property string $version_code
- * @property string $version_code_now
- */
- class DriverAppUpdateStatus extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'driver_app_update_status';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['driver_res_id'], 'required'],
- [['driver_res_id', 'driver_bus_type'], 'integer'],
- [['driver_update_time', 'publish_update_time', 'driver_name'], 'string', 'max' => 50],
- [['download_address', 'version_code', 'version_code_now'], 'string', 'max' => 255],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'driver_res_id' => 'Driver Res ID',
- 'driver_bus_type' => 'Driver Bus Type',
- 'driver_update_time' => 'Driver Update Time',
- 'publish_update_time' => '用来记录司机是否需要更新app',
- 'download_address' => 'Download Address',
- 'driver_name' => 'Driver Name',
- 'version_code' => 'Version Code',
- 'version_code_now' => 'Version Code Now',
- ];
- }
-
- /**
- * Function Description:上传版本号
- * Function Name: uploadVersion
- * @param int $driver_id 司机id
- * @param string $version_code 版本号
- *
- * @return bool
- *
- * @author 张帅
- */
- public function uploadVersion($driver_id, $version_code)
- {
- #region 1.查询有无司机记录
- $version = self::find()->select('id')->where(['driver_res_id' => $driver_id])->asArray()->one();
- #endregion
-
- #region 2.上传版本号
- if (count($version) == 0) {//不存在新增
- //(1)获取司机信息
- $driver_info = BaseDriver::find()->select('driver_id,driver_name')->where(['driver_id' => $driver_id, 'cancel_flag' => 0])->asArray()->one();
-
- //(2)获取最新版本号
- $version_code_new = DriverAppVersion::find()->select('app_version,app_url')->asArray()->one();
-
- //(3)上传
- $values = [
- 'driver_res_id' => $driver_id,
- 'driver_bus_type' => 256,
- 'driver_update_time' => date('Y-m-d H:i:s', time()),
- 'publish_update_time' => date('Y-m-d H:i:s', time()),
- 'download_address' => $version_code_new['app_url'],
- 'driver_name' => $driver_info['driver_name'],
- 'version_code' => $version_code_new['app_version'],
- 'version_code_now' => $version_code,
- ];
-
- $this->attributes = $values;
- $res = $this->insert();
-
- } else {//存在修改
- $version_one = self::findOne(['id' => $version['id']]);
- $version_one->attributes = ['version_code_now' => $version_code, 'publish_update_time' => date('Y-m-d H:i:s', time())];
- $res = $version_one->update();
- }
- #endregion
-
- if ($res) {
- return true;
- } else {
- return false;
- }
- }
- }
|