No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

114 líneas
3.5 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use yii\db\ActiveRecord;
  4. /**
  5. * This is the model class for table "driver_app_update_status".
  6. *
  7. * @property integer $id
  8. * @property integer $driver_res_id
  9. * @property integer $driver_bus_type
  10. * @property string $driver_update_time
  11. * @property string $publish_update_time
  12. * @property string $download_address
  13. * @property string $driver_name
  14. * @property string $version_code
  15. * @property string $version_code_now
  16. */
  17. class DriverAppUpdateStatus extends ActiveRecord
  18. {
  19. /**
  20. * @inheritdoc
  21. */
  22. public static function tableName()
  23. {
  24. return 'driver_app_update_status';
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['driver_res_id'], 'required'],
  33. [['driver_res_id', 'driver_bus_type'], 'integer'],
  34. [['driver_update_time', 'publish_update_time', 'driver_name'], 'string', 'max' => 50],
  35. [['download_address', 'version_code', 'version_code_now'], 'string', 'max' => 255],
  36. ];
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'driver_res_id' => 'Driver Res ID',
  46. 'driver_bus_type' => 'Driver Bus Type',
  47. 'driver_update_time' => 'Driver Update Time',
  48. 'publish_update_time' => '用来记录司机是否需要更新app',
  49. 'download_address' => 'Download Address',
  50. 'driver_name' => 'Driver Name',
  51. 'version_code' => 'Version Code',
  52. 'version_code_now' => 'Version Code Now',
  53. ];
  54. }
  55. /**
  56. * Function Description:上传版本号
  57. * Function Name: uploadVersion
  58. * @param int $driver_id 司机id
  59. * @param string $version_code 版本号
  60. *
  61. * @return bool
  62. *
  63. * @author 张帅
  64. */
  65. public function uploadVersion($driver_id, $version_code)
  66. {
  67. #region 1.查询有无司机记录
  68. $version = self::find()->select('id')->where(['driver_res_id' => $driver_id])->asArray()->one();
  69. #endregion
  70. #region 2.上传版本号
  71. if (count($version) == 0) {//不存在新增
  72. //(1)获取司机信息
  73. $driver_info = BaseDriver::find()->select('driver_id,driver_name')->where(['driver_id' => $driver_id, 'cancel_flag' => 0])->asArray()->one();
  74. //(2)获取最新版本号
  75. $version_code_new = DriverAppVersion::find()->select('app_version,app_url')->asArray()->one();
  76. //(3)上传
  77. $values = [
  78. 'driver_res_id' => $driver_id,
  79. 'driver_bus_type' => 256,
  80. 'driver_update_time' => date('Y-m-d H:i:s', time()),
  81. 'publish_update_time' => date('Y-m-d H:i:s', time()),
  82. 'download_address' => $version_code_new['app_url'],
  83. 'driver_name' => $driver_info['driver_name'],
  84. 'version_code' => $version_code_new['app_version'],
  85. 'version_code_now' => $version_code,
  86. ];
  87. $this->attributes = $values;
  88. $res = $this->insert();
  89. } else {//存在修改
  90. $version_one = self::findOne(['id' => $version['id']]);
  91. $version_one->attributes = ['version_code_now' => $version_code, 'publish_update_time' => date('Y-m-d H:i:s', time())];
  92. $res = $version_one->update();
  93. }
  94. #endregion
  95. if ($res) {
  96. return true;
  97. } else {
  98. return false;
  99. }
  100. }
  101. }