Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

194 linhas
6.3 KiB

  1. <?php
  2. namespace backend\modules\api\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "opera_tourist_common".
  6. *
  7. * @property integer $tourist_id
  8. * @property string $tourist_code
  9. * @property integer $main_corp_id
  10. * @property integer $supplier_id
  11. * @property string $tourist_name
  12. * @property string $tourist_sub_head
  13. * @property integer $is_onsale
  14. * @property integer $cancel_flag
  15. * @property integer $create_user_id
  16. * @property string $create_time
  17. * @property integer $update_user_id
  18. * @property string $update_time
  19. * @property string $tourist_description
  20. * @property integer $min_people_num
  21. * @property integer $day_num
  22. * @property integer $night_num
  23. * @property string $tourist_type
  24. * @property integer $start_area_id
  25. * @property string $end_area_list
  26. * @property integer $pre_days
  27. * @property string $pre_time
  28. * @property string $list_image_url
  29. * @property string $top_image_url
  30. * @property string $message
  31. */
  32. class OperaTouristCommon extends \yii\db\ActiveRecord
  33. {
  34. /**
  35. * @inheritdoc
  36. */
  37. public static function tableName()
  38. {
  39. return 'opera_tourist_common';
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function rules()
  45. {
  46. return [
  47. [['main_corp_id', 'supplier_id', 'is_onsale', 'cancel_flag', 'create_user_id', 'update_user_id', 'min_people_num', 'day_num', 'night_num', 'start_area_id', 'pre_days'], 'integer'],
  48. [['supplier_id', 'tourist_name', 'tourist_sub_head', 'list_image_url', 'top_image_url', 'message'], 'required'],
  49. [['create_time', 'update_time'], 'safe'],
  50. [['tourist_description'], 'string'],
  51. [['tourist_code'], 'string', 'max' => 30],
  52. [['refund_limit_day', 'refund_limit_time'], 'string', 'max' => 20],
  53. [['tourist_name', 'tourist_sub_head'], 'string', 'max' => 200],
  54. [['tourist_type'], 'string', 'max' => 3],
  55. [['end_area_list', 'list_image_url', 'top_image_url', 'message'], 'string', 'max' => 255],
  56. [['pre_time'], 'string', 'max' => 5],
  57. ];
  58. }
  59. /**
  60. * @inheritdoc
  61. */
  62. public function attributeLabels()
  63. {
  64. return [
  65. 'tourist_id' => 'Tourist ID',
  66. 'tourist_code' => 'Tourist Code',
  67. 'main_corp_id' => 'Main Corp ID',
  68. 'supplier_id' => 'Supplier ID',
  69. 'tourist_name' => 'Tourist Name',
  70. 'tourist_sub_head' => 'Tourist Sub Head',
  71. 'is_onsale' => 'Is Onsale',
  72. 'cancel_flag' => 'Cancel Flag',
  73. 'create_user_id' => 'Create User ID',
  74. 'create_time' => 'Create Time',
  75. 'update_user_id' => 'Update User ID',
  76. 'update_time' => 'Update Time',
  77. 'tourist_description' => 'Tourist Description',
  78. 'min_people_num' => 'Min People Num',
  79. 'day_num' => 'Day Num',
  80. 'night_num' => 'Night Num',
  81. 'tourist_type' => 'Tourist Type',
  82. 'start_area_id' => 'Start Area ID',
  83. 'end_area_list' => 'End Area List',
  84. 'pre_days' => 'Pre Days',
  85. 'pre_time' => 'Pre Time',
  86. 'list_image_url' => 'List Image Url',
  87. 'top_image_url' => 'Top Image Url',
  88. 'message' => 'Message',
  89. ];
  90. }
  91. public static function getOperaTouristCommonOne($tourist_id)
  92. {
  93. $data = self::findOne(['tourist_id' => $tourist_id, 'cancel_flag' => 0]);
  94. return $data;
  95. }
  96. /**
  97. * Function Description:判断自由行产品是否在允许售卖日期内
  98. * Function Name: judgeTouristTimeAllow
  99. * @param int $tourist_id 自由行产品id
  100. * @param string $run_date 出发日期
  101. * @return bool
  102. *
  103. * @author 温依莅
  104. */
  105. public static function judgeTouristTimeAllow($tourist_id, $run_date)
  106. {
  107. $res = self::find()->select('tourist_id,is_onsale,pre_days,pre_time')
  108. ->where('tourist_id=' . $tourist_id)
  109. ->asArray()->limit(1)->one();
  110. $time_diff = strtotime('-' . $res['pre_days'] . ' day', strtotime($run_date . ' ' . $res['pre_time'] . ':00')) - time();
  111. $time_allow = $time_diff > 0 ? 1 : 0;//是否在可售时间内
  112. if (!$time_allow) {
  113. return false;
  114. }
  115. return true;
  116. }
  117. /**
  118. * Function Description:获取自由行产品短信模板
  119. * Function Name: getTouristMsg
  120. * @param $tourist_id
  121. * @return array
  122. * @author 温依莅
  123. */
  124. public static function getTouristMsg($tourist_id)
  125. {
  126. $res = self::find()->select('tourist_id,message')->where(['tourist_id' => $tourist_id])->asArray()->one();
  127. return $res;
  128. }
  129. /**
  130. * Function Description:根据tourist_id获取自由行行程天数
  131. * Function Name: getDays
  132. * @param $tourist_id
  133. * @return array|null|\yii\db\ActiveRecord
  134. * @author 田玲菲
  135. */
  136. public function getDays($tourist_id)
  137. {
  138. $res = self::find()->select('day_num')->where(['tourist_id' => $tourist_id])->asArray()->one();
  139. return $res;
  140. }
  141. /**
  142. * Function Description:判断自由行产品是否已过取消限制时间
  143. * Function Name: checkRefundTime
  144. * @param $tourist_id,$date
  145. *
  146. * @return bool
  147. *
  148. * @author 娄梦宁
  149. */
  150. public function checkRefundTime($tourist_id,$date)
  151. {
  152. $refund_limit = self::find()->select('refund_limit_day,refund_limit_time')->from(self::tableName())
  153. ->where(['and', ['=', 'cancel_flag', 0], ['=', 'tourist_id', $tourist_id]])
  154. ->asArray()->one();
  155. if ($refund_limit['refund_limit_day'] == '-1') {
  156. return true;
  157. }
  158. $time_diff = strtotime('-' . $refund_limit['refund_limit_day'] . ' day', strtotime($date . ' ' . $refund_limit['refund_limit_time'] . ':00')) - time();
  159. $time_allow = $time_diff > 0 ? 1 : 0;//是否在可取消时间内
  160. if (!$time_allow) {
  161. return false;
  162. }
  163. return true;
  164. }
  165. /**
  166. * Des:更加code获取 ID
  167. * Name: getTouristByCode
  168. * @param $code
  169. * @return int
  170. * @author 倪宗锋
  171. */
  172. public function getTouristByCode($code)
  173. {
  174. $where = ['tourist_code' => $code, 'cancel_flag' => 0];
  175. $data = self::find()->select(['tourist_id'])
  176. ->where($where)
  177. ->asArray()
  178. ->one();
  179. return empty($data['tourist_id']) ? 0 : $data['tourist_id'];
  180. }
  181. }