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; } } }