|
- <?php
-
- namespace common\models;
-
- use Yii;
- use yii\db\Query;
-
- /**
- * This is the model class for table "opera_tourist_run".
- *
- * @property integer $id
- * @property integer $tourist_id
- * @property integer $create_user_id
- * @property string $create_time
- * @property integer $update_user_id
- * @property string $update_time
- * @property integer $cancel_flag
- * @property integer $is_onsale
- * @property string $run_date
- * @property integer $to_org_id
- * @property integer $limit_total_num
- * @property integer $limit_adult_num
- * @property integer $max_total_num
- * @property integer $max_adult_num
- * @property integer $saled_adult_num
- * @property integer $saled_child_num
- * @property string $adult_price
- * @property string $child_price
- * @property string $diff_price
- * @property string $adult_cost
- * @property string $child_cost
- * @property string $diff_cost
- * @property integer $sale_type_adult
- * @property string $diff_para_adult
- * @property integer $sale_type_child
- * @property string $diff_para_child
- */
- class OperaTouristRun extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'opera_tourist_run';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['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'],
- [['create_time', 'update_time'], 'safe'],
- [['adult_price', 'child_price', 'diff_price', 'adult_cost', 'child_cost', 'diff_cost', 'diff_para_adult', 'diff_para_child'], 'number'],
- [['run_date'], 'string', 'max' => 10],
- [['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.'],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'tourist_id' => 'Tourist ID',
- 'create_user_id' => 'Create User ID',
- 'create_time' => 'Create Time',
- 'update_user_id' => 'Update User ID',
- 'update_time' => 'Update Time',
- 'cancel_flag' => 'Cancel Flag',
- 'is_onsale' => 'Is Onsale',
- 'run_date' => 'Run Date',
- 'to_org_id' => 'To Org ID',
- 'limit_total_num' => 'Limit Total Num',
- 'limit_adult_num' => 'Limit Adult Num',
- 'max_total_num' => 'Max Total Num',
- 'max_adult_num' => 'Max Adult Num',
- 'saled_adult_num' => 'Saled Adult Num',
- 'saled_child_num' => 'Saled Child Num',
- 'adult_price' => 'Adult Price',
- 'child_price' => 'Child Price',
- 'diff_price' => 'Diff Price',
- 'adult_cost' => 'Adult Cost',
- 'child_cost' => 'Child Cost',
- 'diff_cost' => 'Diff Cost',
- 'sale_type_adult' => 'Sale Type Adult',
- 'diff_para_adult' => 'Diff Para Adult',
- 'sale_type_child' => 'Sale Type Child',
- 'diff_para_child' => 'Diff Para Child',
- ];
- }
-
-
- /**
- * Function Description:获取自由行产品价格日历加价方式统一接口
- * Function Name: getTouristAddInfo
- * @param $tourist_id
- * @param $run_date
- * @param $org_id
- *
- * @return array
- *
- * @author 冒炎
- */
- public function getTouristAddInfo($tourist_id, $run_date, $org_id)
- {
- $result = array();
- $list = (new Query())
- ->select('tourist_id,sale_type_adult,diff_para_adult,sale_type_child,diff_para_child,is_onsale')
- ->from('opera_tourist_run')
- ->where(['tourist_id' => $tourist_id, 'run_date' => $run_date, 'to_org_id' => $org_id])
- ->limit(1)
- ->one();
- $list_default = (new Query())
- ->select('tourist_id,sale_type_adult,diff_para_adult,sale_type_child,diff_para_child,is_onsale')
- ->from('opera_tourist_run')
- ->where(['tourist_id' => $tourist_id, 'run_date' => $run_date, 'to_org_id' => 0])
- ->limit(1)
- ->one();
-
- if(!$list){
- $res = $list_default;
- }else{
- $res = $list;
- }
-
- if (!$res) { //原渠道和通用渠道全部未设置,取默认设置
- $sale_type_adult = 2;
- $sale_type_child = 2;
- $diff_para_adult = Yii::$app->params['tourist_profit'] ? Yii::$app->params['tourist_profit'] : 10;
- $diff_para_child = Yii::$app->params['tourist_profit'] ? Yii::$app->params['tourist_profit'] : 10;
- } else if (!$res['is_onsale']) { //该渠道日期下架不可售
- $result['code'] = '1';
- $result['info'] = '该日期不可售';
- return $result;
- } else {
- $sale_type_adult = $res['sale_type_adult'];
- $sale_type_child = $res['sale_type_child'];
- $diff_para_adult = $res['diff_para_adult'];
- $diff_para_child = $res['diff_para_child'];
- }
- $result['code'] = '0';
- $result['info'] = '获取加价信息成功';
- $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);
- return $result;
- }
- }
|