You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

148 lines
3.9 KiB

  1. <?php
  2. namespace backend\modules\zzcs\models;
  3. use Yii;
  4. use yii\db\Expression;
  5. /**
  6. * This is the model class for table "run_bus_delay".
  7. *
  8. * @property integer $id
  9. * @property integer $cancel_flag
  10. * @property integer $create_user_id
  11. * @property integer $update_user_id
  12. * @property string $create_time
  13. * @property string $update_time
  14. * @property integer $delay_res_seq_id
  15. * @property integer $delay_res_id
  16. * @property string $delay_res_name
  17. * @property integer $delay_minute
  18. * @property integer $run_id
  19. * @property integer $bus_order_id
  20. * @property integer $is_send_message
  21. */
  22. class RunBusDelay extends \yii\db\ActiveRecord
  23. {
  24. /**
  25. * @inheritdoc
  26. */
  27. public static function tableName()
  28. {
  29. return 'run_bus_delay';
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['cancel_flag', 'create_user_id', 'update_user_id', 'delay_res_seq_id', 'delay_res_id', 'delay_minute', 'run_id', 'bus_order_id', 'is_send_message'], 'integer'],
  38. [['create_time', 'update_time'], 'safe'],
  39. [['delay_res_name'], 'string', 'max' => 100],
  40. ];
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'cancel_flag' => 'Cancel Flag',
  50. 'create_user_id' => 'Create User ID',
  51. 'update_user_id' => 'Update User ID',
  52. 'create_time' => 'Create Time',
  53. 'update_time' => 'Update Time',
  54. 'delay_res_seq_id' => 'Delay Res Seq ID',
  55. 'delay_res_id' => 'Delay Res ID',
  56. 'delay_res_name' => 'Delay Res Name',
  57. 'delay_minute' => 'Delay Minute',
  58. 'run_id' => 'Run ID',
  59. 'bus_order_id' => 'Bus Order ID',
  60. 'is_send_message' => 'Is Send Message',
  61. ];
  62. }
  63. /**
  64. * Des:添加新记录
  65. * Name: addRow
  66. * @param $params
  67. * @return int|mixed
  68. * @author 倪宗锋
  69. */
  70. public function addRow($params)
  71. {
  72. $data = [
  73. 'create_user_id' => $params['user_id'],
  74. 'create_time' => date('Y-m-d H:i:s'),
  75. 'delay_res_seq_id' => $params['seq_id'],
  76. 'delay_res_id' => $params['res_id'],
  77. 'delay_res_name' => $params['res_name'],
  78. 'delay_minute' => $params['val'],
  79. 'run_id' => $params['run_id'],
  80. 'bus_order_id' => $params['bus_order_id'],
  81. ];
  82. $this->attributes = $data;
  83. $res = $this->insert();
  84. if ($res == false) {
  85. return 0;
  86. }
  87. return $this->id;
  88. }
  89. /**
  90. * Des:获取晚点时间
  91. * Name: getInfo
  92. * @param $params
  93. * @return int
  94. * @author 倪宗锋
  95. */
  96. public function getDelayTime($params)
  97. {
  98. $where = [
  99. 'and',
  100. ['=', 'a.run_id', $params['run_id']],
  101. ['=', 'a.bus_order_id', $params['bus_order_id']]
  102. ];
  103. $select = ['delay_time' => new Expression("SUM(a.delay_minute)")];
  104. $getInfo = self::find()->select($select)
  105. ->from(static::tableName() . ' a')
  106. ->where($where)
  107. ->asArray()
  108. ->one();
  109. if (empty($getInfo['delay_time'])) {
  110. return 0;
  111. }
  112. return $getInfo['delay_time'];
  113. }
  114. /**
  115. * Des:修改发送短信通知的状态
  116. * Name: setSendDelayMsg
  117. * @param $params
  118. * @return bool
  119. * @author 倪宗锋
  120. */
  121. public function setSendDelayMsg($params)
  122. {
  123. $where = [
  124. 'and',
  125. ['=', 'run_id', $params['run_id']],
  126. ['=', 'bus_order_id', $params['bus_order_id']]
  127. ];
  128. $values = [
  129. 'update_user_id' => $params['user_id'],
  130. 'update_time' => date('Y-m-d H:i:s'),
  131. 'is_send_message' => 1,
  132. ];
  133. $flag = self::updateAll($values,$where);
  134. if ($flag == false) {
  135. return false;
  136. }
  137. return true;
  138. }
  139. }