選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

OperaTouristRun.php 5.5 KiB

3年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace common\models;
  3. use Yii;
  4. use yii\db\Query;
  5. /**
  6. * This is the model class for table "opera_tourist_run".
  7. *
  8. * @property integer $id
  9. * @property integer $tourist_id
  10. * @property integer $create_user_id
  11. * @property string $create_time
  12. * @property integer $update_user_id
  13. * @property string $update_time
  14. * @property integer $cancel_flag
  15. * @property integer $is_onsale
  16. * @property string $run_date
  17. * @property integer $to_org_id
  18. * @property integer $limit_total_num
  19. * @property integer $limit_adult_num
  20. * @property integer $max_total_num
  21. * @property integer $max_adult_num
  22. * @property integer $saled_adult_num
  23. * @property integer $saled_child_num
  24. * @property string $adult_price
  25. * @property string $child_price
  26. * @property string $diff_price
  27. * @property string $adult_cost
  28. * @property string $child_cost
  29. * @property string $diff_cost
  30. * @property integer $sale_type_adult
  31. * @property string $diff_para_adult
  32. * @property integer $sale_type_child
  33. * @property string $diff_para_child
  34. */
  35. class OperaTouristRun extends \yii\db\ActiveRecord
  36. {
  37. /**
  38. * @inheritdoc
  39. */
  40. public static function tableName()
  41. {
  42. return 'opera_tourist_run';
  43. }
  44. /**
  45. * @inheritdoc
  46. */
  47. public function rules()
  48. {
  49. return [
  50. [['tourist_id', 'create_user_id', 'update_user_id', 'cancel_flag', 'is_onsale', 'to_org_id', 'limit_total_num', 'limit_adult_num', 'max_total_num', 'max_adult_num', 'saled_adult_num', 'saled_child_num', 'sale_type_adult', 'sale_type_child'], 'integer'],
  51. [['create_time', 'update_time'], 'safe'],
  52. [['adult_price', 'child_price', 'diff_price', 'adult_cost', 'child_cost', 'diff_cost', 'diff_para_adult', 'diff_para_child'], 'number'],
  53. [['run_date'], 'string', 'max' => 10],
  54. [['tourist_id', 'to_org_id', 'run_date'], 'unique', 'targetAttribute' => ['tourist_id', 'to_org_id', 'run_date'], 'message' => 'The combination of Tourist ID, Run Date and To Org ID has already been taken.'],
  55. ];
  56. }
  57. /**
  58. * @inheritdoc
  59. */
  60. public function attributeLabels()
  61. {
  62. return [
  63. 'id' => 'ID',
  64. 'tourist_id' => 'Tourist ID',
  65. 'create_user_id' => 'Create User ID',
  66. 'create_time' => 'Create Time',
  67. 'update_user_id' => 'Update User ID',
  68. 'update_time' => 'Update Time',
  69. 'cancel_flag' => 'Cancel Flag',
  70. 'is_onsale' => 'Is Onsale',
  71. 'run_date' => 'Run Date',
  72. 'to_org_id' => 'To Org ID',
  73. 'limit_total_num' => 'Limit Total Num',
  74. 'limit_adult_num' => 'Limit Adult Num',
  75. 'max_total_num' => 'Max Total Num',
  76. 'max_adult_num' => 'Max Adult Num',
  77. 'saled_adult_num' => 'Saled Adult Num',
  78. 'saled_child_num' => 'Saled Child Num',
  79. 'adult_price' => 'Adult Price',
  80. 'child_price' => 'Child Price',
  81. 'diff_price' => 'Diff Price',
  82. 'adult_cost' => 'Adult Cost',
  83. 'child_cost' => 'Child Cost',
  84. 'diff_cost' => 'Diff Cost',
  85. 'sale_type_adult' => 'Sale Type Adult',
  86. 'diff_para_adult' => 'Diff Para Adult',
  87. 'sale_type_child' => 'Sale Type Child',
  88. 'diff_para_child' => 'Diff Para Child',
  89. ];
  90. }
  91. /**
  92. * Function Description:获取自由行产品价格日历加价方式统一接口
  93. * Function Name: getTouristAddInfo
  94. * @param $tourist_id
  95. * @param $run_date
  96. * @param $org_id
  97. *
  98. * @return array
  99. *
  100. * @author 冒炎
  101. */
  102. public function getTouristAddInfo($tourist_id, $run_date, $org_id)
  103. {
  104. $result = array();
  105. $list = (new Query())
  106. ->select('tourist_id,sale_type_adult,diff_para_adult,sale_type_child,diff_para_child,is_onsale')
  107. ->from('opera_tourist_run')
  108. ->where(['tourist_id' => $tourist_id, 'run_date' => $run_date, 'to_org_id' => $org_id])
  109. ->limit(1)
  110. ->one();
  111. $list_default = (new Query())
  112. ->select('tourist_id,sale_type_adult,diff_para_adult,sale_type_child,diff_para_child,is_onsale')
  113. ->from('opera_tourist_run')
  114. ->where(['tourist_id' => $tourist_id, 'run_date' => $run_date, 'to_org_id' => 0])
  115. ->limit(1)
  116. ->one();
  117. if(!$list){
  118. $res = $list_default;
  119. }else{
  120. $res = $list;
  121. }
  122. if (!$res) { //原渠道和通用渠道全部未设置,取默认设置
  123. $sale_type_adult = 2;
  124. $sale_type_child = 2;
  125. $diff_para_adult = Yii::$app->params['tourist_profit'] ? Yii::$app->params['tourist_profit'] : 10;
  126. $diff_para_child = Yii::$app->params['tourist_profit'] ? Yii::$app->params['tourist_profit'] : 10;
  127. } else if (!$res['is_onsale']) { //该渠道日期下架不可售
  128. $result['code'] = '1';
  129. $result['info'] = '该日期不可售';
  130. return $result;
  131. } else {
  132. $sale_type_adult = $res['sale_type_adult'];
  133. $sale_type_child = $res['sale_type_child'];
  134. $diff_para_adult = $res['diff_para_adult'];
  135. $diff_para_child = $res['diff_para_child'];
  136. }
  137. $result['code'] = '0';
  138. $result['info'] = '获取加价信息成功';
  139. $result['list'] = array('sale_type_adult' => $sale_type_adult, 'diff_para_adult' => $diff_para_adult,'sale_type_child'=>$sale_type_child,'diff_para_child'=>$diff_para_child);
  140. return $result;
  141. }
  142. }