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.
 
 
 
 
 
 

578 lines
23 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2018/4/28
  6. * Time: 11:01
  7. */
  8. namespace backend\modules\hotel\models;
  9. use backend\common\Utils;
  10. use Yii;
  11. use yii\base\Model;
  12. use backend\modules\hotel\models\ChannelHotelMapping;
  13. use backend\modules\hotel\models\OperaRoomDistrib;
  14. use yii\filters\AccessControl;
  15. use yii\filters\ContentNegotiator;
  16. use yii\web\Response;
  17. use yii\helpers\Html;
  18. use yii\base\Module;
  19. use yii\httpclient\Client;
  20. use backend\modules\hotel\models\CtripCountryList;
  21. use backend\modules\hotel\models\CtripCityList;
  22. use backend\modules\hotel\models\CtripHotelList;
  23. use backend\modules\hotel\models\ChannelBaseRoomMapping;
  24. use backend\modules\hotel\models\OperaHotel;
  25. use yii\db\Exception;
  26. use yii\db\Expression;
  27. use yii\data\ActiveDataProvider;
  28. class CtripSwitch extends Model
  29. {
  30. public $masterHotelID; //母酒店ID
  31. public $hotelId; //子酒店ID
  32. public $masterBasicRoomTypeId; //母物理房型ID
  33. public $basicRoomTypeId; //子物理房型
  34. public $roomTypeId; //售卖房型,即子房型
  35. public $supplierID; //供应商ID 即代理通分配给我们的ID
  36. public $channel; //代理通 渠道
  37. public $roomStatus; //售卖房型上下线状态
  38. public $zz_room_id; //蜘蛛子房型ID
  39. public $zz_channel_id; //蜘蛛渠道ID
  40. public $zz_hotel_id; //蜘蛛酒店ID
  41. public $zz_base_room_id; //蜘蛛基础房型ID
  42. public $roomDataEntitys; // 房态推送数据实体
  43. public $start_date; // 房态房价日期范围开始日期
  44. public $end_date; // 房态房价日期范围结束日期
  45. public $ctripConf; //基础配置参数
  46. const SUCCESS_CODE = 0;
  47. const SYS_ERR0R = 100; //系统错误
  48. const CTRIP_HOTEL_CODE = 101; //携程创建子酒店失败
  49. const MASTER_HOTEL_EMPTY = 102; //母酒店ID不能为空
  50. const REPEAT_CREATE = 103; //该酒店已添加
  51. const MAPPING_HOTEL_ERROR = 104; //酒店关联失败
  52. const UNMAPPING_CODE = 105; //酒店未关联
  53. const PARAM_ERR0R = 106; //请求参数缺失
  54. const ADD_HOTEL_ERR = 107; //添加酒店信息失败
  55. const GET_MASTER_HOTEL_ERR = 108; //添加酒店信息失败
  56. const RETURN_MSG = [
  57. self::SUCCESS_CODE => 'success',
  58. self::CTRIP_HOTEL_CODE => '携程创建子酒店失败',
  59. self::SYS_ERR0R => '系统错误',
  60. self::MASTER_HOTEL_EMPTY => '母酒店ID不能为空',
  61. self::REPEAT_CREATE => '携程子酒店已创建,但cs系统不存在子酒店id',
  62. self::MAPPING_HOTEL_ERROR => '酒店关联失败',
  63. self::UNMAPPING_CODE => '请检查 Mapping 关系!',
  64. self::PARAM_ERR0R => '请求参数缺失',
  65. self::ADD_HOTEL_ERR => '添加酒店信息失败',
  66. self::GET_MASTER_HOTEL_ERR => '获取代理通酒店信息失败',
  67. ];
  68. const CTRIP_ID = 669; //携程
  69. const QUNAR_ID = 1667; //去哪
  70. const ELONG_ID = 1668; //艺龙
  71. const CHANNELA_ID = 1669; //分销A
  72. const B2B_ID = 1670; //b2b
  73. public function __construct(array $config = [])
  74. {
  75. $this->supplierID = Yii::$app->params['ctrip_switch']['switch_supplier_id'];
  76. $this->ctripConf = Yii::$app->params['ctrip_switch'];
  77. parent::__construct($config);
  78. }
  79. /**
  80. * Created by PhpStorm.
  81. * NOTES:设置场景
  82. * User: Steven
  83. * Date: 2018/4/28
  84. * Time: 11:11
  85. * Class scenarios
  86. * @return array
  87. */
  88. public function scenarios()
  89. {
  90. $scenarios = parent::scenarios();
  91. $scenarios['updateRoomSaleName'] = ['zz_room_id', 'zz_channel_id', 'zz_hotel_id'];
  92. $scenarios['setRoomOnlineOffline'] = ['zz_room_id', 'zz_channel_id', 'roomStatus'];
  93. $scenarios['CheckMapping'] = ['zz_hotel_id', 'zz_channel_id', 'zz_room_id']; // 验证的zz_room_id 实为room_type
  94. $scenarios['PushRoomData'] = ['zz_hotel_id', 'zz_room_id', 'zz_channel_id', 'roomDataEntitys'];
  95. return $scenarios;
  96. }
  97. /**
  98. * Created by PhpStorm.
  99. * NOTES:
  100. * User: Steven
  101. * Date: 2018/4/28
  102. * Time: 11:11
  103. * Class rules
  104. * @return array
  105. */
  106. public function rules()
  107. {
  108. return [
  109. //酒店试单
  110. [['zz_room_id', 'zz_channel_id', 'zz_hotel_id'], 'required', 'on' => ['updateRoomSaleName']],
  111. [['zz_room_id', 'zz_channel_id', 'roomStatus'], 'required', 'on' => ['setRoomOnlineOffline']],
  112. [['zz_hotel_id', 'zz_channel_id', 'zz_room_id'], 'required', 'on' => ['CheckMapping']],
  113. [['zz_hotel_id', 'zz_channel_id', 'zz_room_id', 'roomDataEntitys'], 'required', 'on' => ['CheckMapping']],
  114. ];
  115. }
  116. public function loadPushData($data, $formName = null)
  117. {
  118. $scope = $formName === null ? $this->formName() : $formName;
  119. if ($scope === '' && !empty($data)) {
  120. $this->setAttributes($data, false);
  121. if (!$this->getProductInfo()) {
  122. return false;
  123. }
  124. return true;
  125. } elseif (isset($data[$scope])) {
  126. $this->setAttributes($data[$scope]);
  127. return true;
  128. } else {
  129. return false;
  130. }
  131. }
  132. /**
  133. * Notes:request请求
  134. * User: Steven
  135. * Date: 2018/4/16
  136. * Time: 15:28
  137. * @param $target_url
  138. * @param $data
  139. * @return mixed
  140. */
  141. public function request($target_url, $data)
  142. {
  143. $data['requestor'] = $this->getCommonParams();
  144. $timestamp = $this->getTimestamp();
  145. $signature = $this->setSignature($this->ctripConf['switch_supplier_id'], $timestamp, $this->ctripConf['interfacekey']);
  146. $client = new Client(['baseUrl' => $this->ctripConf['base_url']]);
  147. $request = $client->createRequest()
  148. ->setHeaders(['content-type' => 'application/json;charset=UTF-8'])
  149. ->addHeaders(["timestamp" => $timestamp])
  150. ->addHeaders(['signature' => $signature])
  151. ->setFormat(Client::FORMAT_JSON)
  152. ->setMethod('post')
  153. ->setUrl($target_url)
  154. ->setData($data);
  155. $t1 = microtime(true);
  156. self::writeLog($target_url . '-' . $timestamp, json_encode($request->getData()));
  157. $response = $request->send();
  158. $t2 = microtime(true);
  159. self::writeLog($target_url . '-' . $timestamp . ' 耗时:' . round($t2 - $t1, 3) . 's', json_encode($response->getData()) . PHP_EOL);
  160. return json_decode($response->content);
  161. }
  162. /**
  163. * Notes:生成公共节点
  164. * User: Steven
  165. * Date: 2018/4/19
  166. * Time: 14:38
  167. * @return array
  168. */
  169. private function getCommonParams()
  170. {
  171. return [
  172. 'invoker' => $this->ctripConf['requestor']['invoker'],
  173. 'operatorName' => $this->ctripConf['requestor']['operatorName'],
  174. 'opClientIP' => $this->ctripConf['requestor']['opClientIP'],
  175. 'userId' => $this->ctripConf['requestor']['userId'],
  176. 'languageType' => $this->ctripConf['requestor']['languageType'],
  177. ];
  178. }
  179. /**
  180. * Notes:加密验证逻辑
  181. * User: Steven
  182. * Date: 2018/4/16
  183. * Time: 15:42
  184. * @param $supplierID //供应商ID,int类型
  185. * @param $timestamp
  186. * @param $interfacekey //密钥Key
  187. * @param $signature
  188. * @return bool
  189. */
  190. private function getSignature($supplierID, $timestamp, $interfacekey, $signature)
  191. {
  192. //加密算法是md5(base64)
  193. $signature_str = strtoupper(base64_encode(md5($supplierID . $timestamp . $interfacekey, true)));
  194. return $signature == $signature_str;
  195. }
  196. /**
  197. * Notes:生成加密串
  198. * User: Steven
  199. * Date: 2018/4/16
  200. * Time: 17:58
  201. * @param $supplierID
  202. * @param $timestamp
  203. * @param $interfacekey
  204. * @return string
  205. */
  206. private function setSignature($supplierID, $timestamp, $interfacekey)
  207. {
  208. //加密算法是md5(base64)
  209. $signature = strtoupper(base64_encode(md5($supplierID . $timestamp . $interfacekey, true)));
  210. return $signature;
  211. }
  212. /**
  213. * Notes:获取当前时间的毫秒数
  214. * User: Steven
  215. * Date: 2018/4/16
  216. * Time: 18:01
  217. * @return float
  218. */
  219. public function getTimestamp()
  220. {
  221. list($msec, $sec) = explode(' ', microtime());
  222. $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
  223. return $msectime;
  224. }
  225. /**
  226. * Created by PhpStorm.
  227. * NOTES:获取接口所需要的渠道ID
  228. * User: Steven
  229. * Date: 2018/4/27
  230. * Time: 16:25
  231. * Class getChannelID
  232. * @param $channel_str
  233. * @return string
  234. */
  235. public function getChannelID($channel_str)
  236. {
  237. $channel_arr = explode(',', $channel_str);
  238. $channel_id_str = '';
  239. foreach ($channel_arr as $value) {
  240. $channel_id_str .= $channel_id_str == '' ? '' : ',';
  241. switch ($value) {
  242. case self::CTRIP_ID:
  243. $channel_id_str .= 'Ctrip';
  244. break;
  245. case self::QUNAR_ID:
  246. $channel_id_str .= 'Qunar';
  247. break;
  248. case self::ELONG_ID:
  249. $channel_id_str .= 'Elong';
  250. break;
  251. case self::CHANNELA_ID:
  252. $channel_id_str .= 'ChannelA';
  253. break;
  254. case self::B2B_ID:
  255. $channel_id_str .= 'B2B';
  256. break;
  257. default:
  258. break;
  259. }
  260. }
  261. return $channel_id_str;
  262. }
  263. /**
  264. * Notes:根据代理通渠道标识获取CS蜘蛛渠道ID
  265. * User: Steven
  266. * Date: 2018/5/11
  267. * Time: 11:37
  268. * @param $dltOrderId
  269. * @return int
  270. */
  271. public static function SupplierDict($supplier_str)
  272. {
  273. //supplier:手工单,这种订单是人工在代理通录入的
  274. switch ($supplier_str) {
  275. case 'EBK':
  276. case 'Email':
  277. case 'SMS':
  278. case 'FAX':
  279. case 'DirectConn':
  280. case 'NotCtripOrder':
  281. return 669;
  282. break;
  283. case 'Elong':
  284. return 1668;
  285. break;
  286. case 'Qunar':
  287. return 1667;
  288. break;
  289. case 'B2B':
  290. case 'B2BOffLine':
  291. return 1670;
  292. break;
  293. case 'TC':
  294. return 1669;
  295. break;
  296. default:
  297. return 0;
  298. }
  299. }
  300. /**
  301. * Created by PhpStorm.
  302. * NOTES:批量插入数据
  303. * User: Steven
  304. * Date: 2018/4/20
  305. * Time: 11:37
  306. * Class batchInsert
  307. * @param $model 表名称
  308. * @param $table_key 表字段
  309. * @param $table_value 表字段的值
  310. * @return int 受影响行数
  311. * @throws yii\db\Exception
  312. */
  313. public function batchInsert($model, $table_key, $table_value)
  314. {
  315. $res = Yii::$app->db->createCommand()
  316. ->batchInsert($model, $table_key, $table_value)
  317. ->execute();
  318. $query = CtripCountryList::find()
  319. ->from('user')
  320. ->indexBy('username');
  321. $query->each();
  322. return $res;
  323. }
  324. /**
  325. * Notes:携程代理通直连请求日志
  326. * User: Steven
  327. * Date: 2018/5/22
  328. * Time: 16:00
  329. * @param $Invoketype
  330. * @param $string
  331. */
  332. public static function writeLog($Invoketype, $string)
  333. {
  334. $dir = "/../../../runtime/logs/ctripSwitchLog";
  335. $string = date('Y-m-d H:i:s') . " $Invoketype " . PHP_EOL . $string . PHP_EOL;
  336. if (!file_exists(__DIR__ . $dir)) {
  337. mkdir(__DIR__ . $dir, 0777, true);
  338. }
  339. file_put_contents(__DIR__ . $dir . '/' . date('Y-m-d') . '.log', $string, FILE_APPEND);
  340. }
  341. /**
  342. * @Author: wanglg
  343. * @DESC: 获取房型在某渠道的信息
  344. * @param $params // hotel_id,parent_room_type, room_type,channel_id, start_date, end_date
  345. * @return $this
  346. */
  347. public function getProductInfo()
  348. {
  349. // 查询某房型在一定日期段内的房态房价信息
  350. $products = OperaHotelRoom::find()
  351. ->leftJoin('opera_room_distrib b', 'a.ID=b.ROOM_ID and b.cancel_flag=0 and b.distrib_id=' . $this->zz_channel_id)
  352. ->leftJoin('run_hotel_distrib c', 'a.hotel_id=c.hotel_id and a.parent_room_type=c.base_room_type and a.room_type=c.room_type and c.distrib_id=b.distrib_id')
  353. ->leftJoin('run_hotel_sub_room d', 'a.hotel_id=d.hotel_id and a.parent_room_type=d.base_room_type and a.room_type=d.room_type and c.run_date=d.run_date')
  354. ->leftJoin('run_hotel e', 'a.hotel_id=e.hotel_id and a.parent_room_type=e.base_room_type and c.run_date=e.run_date')
  355. ->leftJoin('opera_hotel_gift f', 'c.gift_id=f.id and a.hotel_id=f.hotel_id and f.cancel_flag=0')
  356. ->from('opera_hotel_room a')
  357. ->where(['a.hotel_id' => $this->zz_hotel_id, 'a.parent_room_type' => $this->zz_base_room_id, 'a.room_type' => $this->zz_room_id, 'a.cancel_flag' => 0,]);
  358. $products->andWhere(['between', 'c.run_date', $this->start_date, $this->end_date]);
  359. $products->addSelect(['if(c.prod_price = 0, c.cus_price, c.prod_price) as room_price', 'a.breakfast_include', 'c.distrib_id', 'c.run_date', 'c.run_status', 'b.channel_mapping_id',
  360. 'c.oversell_flag', 'c.remaining_count', 'c.saled_count', 'b.latest_comfirm_time', 'b.distrib_room_name', 'b.authority_status', 'a.lastest_book_time',
  361. 'd.is_onsale as base_is_onsale', 'd.run_status as base_run_status', 'c.gift_id', 'f.gift_name', 'f.gift_content', 'e.is_onsale base_room_onsale',
  362. 'SUM(case e.stock_type when 228 then e.remaining_count else 0 end) as buyout',
  363. 'SUM(case e.stock_type when 229 then e.remaining_count else 0 end) as inquiry',
  364. 'SUM(case e.stock_type when 230 then e.remaining_count else 0 end) as retain',]);
  365. $products->groupBy('c.run_date');
  366. $res = $products->asArray()->all();
  367. foreach ($res as $key => $value) {
  368. // 获取渠道信息, 处理渠道名称,如果是推送房价、房态、动态规则,渠道名称首字母大写, Ctrip,Qunar, QunarB,QunarD,QunarY,QunarT ,Elong,B2B ,ChannelA,B2BOffline ,Share
  369. // 如果是房量,渠道名称全部为小写 ctrip,qunar,elong,manual
  370. $channel_price = $value['distrib_id'] == Yii::$app->params['ctrip']['supplier_id'] ? 'Ctrip' :
  371. ($value['distrib_id'] == Yii::$app->params['qunar']['supplier_id'] ? 'Qunar' :
  372. ($value['distrib_id'] == Yii::$app->params['elong']['supplier_id'] ? 'Elong' :
  373. ($value['distrib_id'] == Yii::$app->params['channela']['supplier_id'] ? 'ChannelA' :
  374. ($value['distrib_id'] == Yii::$app->params['channela']['supplier_id'] ? 'B2B' : ''))));
  375. $channel_quanity = $value['distrib_id'] == Yii::$app->params['ctrip']['supplier_id'] ? 'ctrip' :
  376. ($value['distrib_id'] == Yii::$app->params['qunar']['supplier_id'] ? 'qunar' :
  377. ($value['distrib_id'] == Yii::$app->params['elong']['supplier_id'] ? 'elong' :
  378. ($value['distrib_id'] == Yii::$app->params['channela']['supplier_id'] ? 'channela' :
  379. ($value['distrib_id'] == Yii::$app->params['channela']['supplier_id'] ? 'b2b' : ''))));
  380. if (!$channel_quanity || !$channel_price) {
  381. return false;
  382. }
  383. if ($value['base_run_status'] == 0 || $value['base_is_onsale'] == 0 || $value['run_status'] == 329 || $value['authority_status'] == 0) {
  384. $sale_status = 0;
  385. } else {
  386. if ($value['oversell_flag'] == 0) {
  387. $sale_status = $value['remaining_count'] <= 0 ? 0 : 2;
  388. } else {
  389. $sale_status = 1;
  390. }
  391. }
  392. $pre_quantity = $value['remaining_count'] <= 0 ? 0 : $value['remaining_count'];
  393. $data = [
  394. 'roomId' => (int)$value['channel_mapping_id'],
  395. 'startDate' => $value['run_date'],
  396. 'endDate' => $value['run_date'],
  397. 'weekDayIndex' => '1111111', //依次周一值周日,为1设置生效为0不生效
  398. 'roomPriceModel' => [ //房价信息
  399. 'roomPrice' => (float)$value['room_price'],
  400. 'tax' => (float)0,
  401. 'currency' => 'CNY',
  402. 'breakfast' => (int)$value['breakfast_include'],
  403. 'channel' => $channel_price,
  404. ],
  405. 'roomStatusModel' => [ // 房态信息
  406. 'saleStatus' => (int)$sale_status, // 0. 满房 1. 销售 2. 限量
  407. 'channel' => $channel_price,
  408. ],
  409. 'roomInventoryModel' => [ // 房量信息
  410. 'preservedQuantity' => (int)$pre_quantity, // 保留房数量
  411. 'unPreservedQuantity' => (int)($value['buyout'] + $value['inquiry'] + $value['retain'] - $pre_quantity), //非保留房数量
  412. 'autoCloseRoom' => 0, // 自动关房
  413. 'channel' => $channel_quanity, // 渠道
  414. ],
  415. 'saleRuleModel' => [
  416. 'channel' => $channel_price,
  417. ],
  418. ];
  419. // 如果当前渠道是b2b 或 channelA ,动态售卖规则中的 礼盒信息和最晚立即确认时间不能同时为空
  420. if (empty($value['gift_id']) && $value['latest_comfirm_time'] == -1 && (strtolower($channel_price) == 'b2b' || strtolower($channel_quanity) == 'channela')) {
  421. return false;
  422. }
  423. if (!empty($value['gift_id'])) {
  424. $data['saleRuleModel']['roomGiftRule'] = [ // 礼盒规则
  425. 'giftId' => $value['gift_id'], // 礼盒ID
  426. 'takeEffectType' => 1, //1:入住生效 2:离店生效 3:在店生效
  427. 'giftDesc' => $value['distrib_id'] == Yii::$app->params['ctrip']['supplier_id'] ? $value['gift_content'] : '', // 礼盒信息
  428. ];
  429. }
  430. // 如果有设置渠道最晚预订时间推送相关信息
  431. if ($value['latest_comfirm_time'] != -1) {
  432. $last_confirm = explode(',', $value['latest_comfirm_time']);
  433. if ($value['distrib_id'] != Yii::$app->params['ctrip']['supplier_id']) {
  434. $last_book_time = explode(',', $value['lastest_book_time']);
  435. $data['saleRuleModel']['ctripSellRule'] = [
  436. 'latestconfirmTimeOfDays' => $last_confirm[0],
  437. 'latestconfirmTimeOfHours' => Utils::timeHour($last_confirm[1]),
  438. 'latestBookingTimeOfDays' => $last_book_time[0],
  439. 'latestBookingTimeOfHours' => Utils::timeHour($last_book_time[1]),
  440. 'cancelType' => 1,
  441. ];
  442. } else {
  443. $data['saleRuleModel']['sellingRule'] = [
  444. 'latestconfirmTimeOfDays' => (int)$last_confirm[0],
  445. 'latestconfirmTimeOfHours' => Utils::timeHour($last_confirm[1]),
  446. ];
  447. }
  448. }
  449. $this->roomDataEntitys[] = $data;
  450. }
  451. return $this;
  452. }
  453. /**
  454. * @Author: wanglg
  455. * @DESC:判断酒店、房型、基础房型是否直连
  456. * @param :hotel_id 酒店ID
  457. * @param :room_type 子房型type
  458. * @param :channel_id 关联渠道ID:可不传,默认为携程
  459. * @return array
  460. */
  461. public function isMapping($hotel_id, $room_type = 0, $channel_id = 669)
  462. {
  463. // 判断渠道
  464. $request = ['zz_channel_id' => $channel_id, 'zz_hotel_id' => $hotel_id, 'zz_room_id' => $room_type];
  465. $request['zz_channel_id'] = empty($request['zz_channel_id']) ? Yii::$app->params['ctrip']['supplier_id'] : $request['zz_channel_id'];
  466. $model = new CtripSwitch(['scenario' => 'CheckMapping']);
  467. if (!$model->load($request, '') || !$model->validate()) {
  468. return ['code' => CtripSwitch::PARAM_ERR0R, 'msg' => CtripSwitch::RETURN_MSG[CtripSwitch::PARAM_ERR0R]];
  469. }
  470. $query = ChannelHotelMapping::find()
  471. ->select(['a.sub_hotel_id'])
  472. ->from('channel_hotel_mapping a')->where(['a.hotel_id' => $model->zz_hotel_id, 'a.channel_id' => $model->zz_channel_id, 'a.cancel_flag' => 0]);
  473. // 子房型type不为空,关联查询子房型是否直连
  474. if (!empty($model->zz_room_id)) {
  475. $query->addSelect(['b.sub_base_room_id', 'd.channel_mapping_id']);
  476. $query->leftJoin('opera_hotel_room c', 'a.hotel_id=c.hotel_id and c.room_type=' . $model->zz_room_id)
  477. ->leftJoin('channel_base_room_mapping b', 'b.base_room_id=c.parent_room_type and b.cancel_flag=0 and a.sub_hotel_id=b.sub_hotel_id and a.channel_id=b.channel_id and a.hotel_id=b.hotel_id and a.master_hotel_id = b.master_hotel_id')
  478. ->leftJoin('opera_room_distrib d', 'd.room_id=c.id and d.distrib_id=a.channel_id');
  479. }
  480. $mapping_res = $query->asArray()->one();
  481. // 代理通酒店id未查到说明酒店未直连
  482. if (empty($mapping_res['sub_hotel_id'])) {
  483. return ['code' => CtripSwitch::UNMAPPING_CODE, 'msg' => CtripSwitch::RETURN_MSG[CtripSwitch::UNMAPPING_CODE]];
  484. }
  485. // 存在子房型但是结果集中没有查到代理通售卖房型id,说明子房型未直连
  486. if (!empty($model->zz_room_id) && (empty($mapping_res['channel_mapping_id']) || empty($mapping_res['sub_base_room_id']))) {
  487. return ['code' => CtripSwitch::UNMAPPING_CODE, 'msg' => CtripSwitch::RETURN_MSG[CtripSwitch::UNMAPPING_CODE]];
  488. }
  489. // 成功,返回直连id
  490. return ['code' => CtripSwitch::SUCCESS_CODE, 'msg' => CtripSwitch::RETURN_MSG[CtripSwitch::SUCCESS_CODE], 'data' => $mapping_res];
  491. }
  492. /**
  493. * Notes:根据携程酒店ID ,房型ID 查找mapping 的蜘蛛Id
  494. * User: Steven
  495. * Date: 2018/5/11
  496. * Time: 19:38
  497. */
  498. public static function getZzIDByCtripID($distrib_id, $room_id)
  499. {
  500. $res = OperaRoomDistrib::find()->select(['b.HOTEL_ID', 'b.ID as ROOM_ID'])
  501. ->leftJoin('opera_hotel_room b', 'a.ROOM_ID=b.ID')
  502. ->from('opera_room_distrib a')
  503. ->where(['a.CHANNEL_MAPPING_ID' => 37138191, 'a.DISTRIB_ID' => 669, 'a.CANCEL_FLAG' => 0, 'b.CANCEL_FLAG' => 0])
  504. ->asArray()->one();
  505. return $res;
  506. }
  507. /**
  508. * @Author: wanglg
  509. * @DESC:通过传入需要处理的周天数据,例如 周二周三[2, 3]
  510. * @param $week_arr
  511. * @return array
  512. */
  513. public function weekDays($week_arr)
  514. {
  515. $init_arr = array(0, 0, 0, 0, 0, 0, 0);
  516. foreach ($week_arr as $value) {
  517. $init_arr[$value - 1] = 1;
  518. }
  519. return $init_arr;
  520. }
  521. }