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.
 
 
 
 
 
 

296 lines
9.0 KiB

  1. <?php
  2. namespace backend\modules\hotel\models;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%channel_base_room_mapping}}".
  8. *
  9. * @property integer $ID
  10. * @property string $create_time
  11. * @property integer $create_user_id
  12. * @property integer $update_user_id
  13. * @property string $update_time
  14. * @property integer $channel_id
  15. * @property integer $cancel_flag
  16. * @property integer $master_hotel_id
  17. * @property integer $sub_hotel_id
  18. * @property integer $hotel_id
  19. * @property integer $master_base_room_id
  20. * @property integer $sub_base_room_id
  21. * @property integer $base_room_id
  22. * @property string $master_base_room_name
  23. * @property string $master_base_room_name_en
  24. * @property integer $base_room_is_add
  25. */
  26. class ChannelBaseRoomMapping extends \yii\db\ActiveRecord
  27. {
  28. /**
  29. * @inheritdoc
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%channel_base_room_mapping}}';
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['create_time', 'create_user_id', 'channel_id', 'master_hotel_id', 'sub_hotel_id', 'hotel_id', 'master_base_room_id', 'master_base_room_name'], 'required'],
  42. [['create_time', 'update_time'], 'safe'],
  43. [['create_user_id', 'update_user_id', 'channel_id', 'cancel_flag', 'master_hotel_id', 'sub_hotel_id', 'hotel_id', 'master_base_room_id', 'sub_base_room_id', 'base_room_id', 'base_room_is_add'], 'integer'],
  44. [['master_base_room_name', 'master_base_room_name_en'], 'string', 'max' => 255],
  45. ];
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'ID' => 'ID',
  54. 'create_time' => 'Create Time',
  55. 'create_user_id' => 'Create User ID',
  56. 'update_user_id' => 'Update User ID',
  57. 'update_time' => 'Update Time',
  58. 'channel_id' => 'Channel ID',
  59. 'cancel_flag' => 'Cancel Flag',
  60. 'master_hotel_id' => 'Master Hotel ID',
  61. 'sub_hotel_id' => 'Sub Hotel ID',
  62. 'hotel_id' => 'Hotel ID',
  63. 'master_base_room_id' => 'Master Base Room ID',
  64. 'sub_base_room_id' => 'Sub Base Room ID',
  65. 'base_room_id' => 'Base Room ID',
  66. 'master_base_room_name' => 'Master Base Room Name',
  67. 'master_base_room_name_en' => 'Master Base Room Name En',
  68. 'base_room_is_add' => 'Base Room Is Add',
  69. ];
  70. }
  71. public function getOperaHotelBaseRoom()
  72. {
  73. return $this->hasOne(OperaHotelBaseRoom::className(), ['MAIN_ID' => 'base_room_id', 'HOTEL_ID' => 'hotel_id'])
  74. ->andOnCondition([OperaHotelBaseRoom::tableName() . '.cancel_flag' => 0]);
  75. }
  76. /**
  77. * des:根据子酒店ID 获取母物理房型列表
  78. * author:guhh
  79. */
  80. public function getMasterBaseRoomList($params)
  81. {
  82. $select = [
  83. 'a.master_hotel_id',
  84. 'a.sub_hotel_id',
  85. 'a.hotel_id',
  86. 'a.master_base_room_id',
  87. 'a.sub_base_room_id',
  88. 'a.base_room_id',
  89. 'a.master_base_room_name',
  90. 'a.master_base_room_name_en',
  91. 'a.base_room_is_add',
  92. ];
  93. $where = [
  94. 'and',
  95. ['=', 'a.sub_hotel_id', $params['sub_hotel_id']],
  96. ['=', 'a.channel_id', $params['channel_id']],
  97. ['=', 'a.cancel_flag', 0]
  98. ];
  99. $query = self::find()->select($select)
  100. ->from(self::tableName() . ' a')
  101. ->joinWith('operaHotelBaseRoom')
  102. ->where($where);
  103. $dataProvider = new ActiveDataProvider([
  104. 'query' => $query,
  105. 'sort' => false,
  106. 'pagination' => [
  107. 'pagesize' => 100,
  108. ],
  109. ]);
  110. return $dataProvider;
  111. }
  112. /**
  113. * Des:根据主房型id获取数据
  114. * Name: getInfoByMasterRoomId
  115. * @param $masterRoomId
  116. * @param $channel_id
  117. * @return array
  118. * @author 倪宗锋
  119. */
  120. public function getInfoByMasterRoomId($masterRoomId, $channel_id = '')
  121. {
  122. $select = [
  123. 'a.ID',
  124. 'a.master_hotel_id',
  125. 'a.sub_hotel_id',
  126. 'a.hotel_id',
  127. 'a.master_base_room_id',
  128. 'a.sub_base_room_id',
  129. 'a.base_room_id',
  130. 'a.master_base_room_name',
  131. 'a.master_base_room_name_en',
  132. 'a.base_room_is_add',
  133. 'b.base_room_name'
  134. ];
  135. $where = [
  136. 'and',
  137. ['=', 'a.master_base_room_id', $masterRoomId],
  138. ['=', 'a.cancel_flag', 0],
  139. ];
  140. if (empty($channel_id) == false) {
  141. $where[] = ['=', 'a.channel_id', $channel_id];
  142. }
  143. $info = self::find()->select($select)
  144. ->from(self::tableName() . ' a')
  145. ->leftJoin(OperaHotelBaseRoom::tableName() . ' b', 'b.MAIN_ID = a.base_room_id')
  146. ->where($where)
  147. ->asArray()
  148. ->one();
  149. return $info;
  150. }
  151. /**
  152. * Des:修改基本信息
  153. * Name: editInfo
  154. * @param $params
  155. * @param $master_base_room_id
  156. * @param $sub_hotel_id
  157. * @param $channel_arr
  158. * @return bool
  159. * @author 倪宗锋
  160. */
  161. public function editInfo($params, $master_base_room_id, $sub_hotel_id, $channel_arr)
  162. {
  163. $params['update_time'] = date('Y-m-d H:i:s');
  164. $where = [
  165. 'master_base_room_id' => $master_base_room_id,
  166. 'sub_hotel_id' => $sub_hotel_id,
  167. 'channel_id' => $channel_arr
  168. ];
  169. $flag = self::updateAll($params, $where);
  170. if ($flag == false) {
  171. return false;
  172. }
  173. return true;
  174. }
  175. /**
  176. * Des:修改基本信息
  177. * Name: editInfo
  178. * @param $roomInfo
  179. * @param $channel_arr
  180. * @author 倪宗锋
  181. */
  182. public function editRow($roomInfo, $channel_arr)
  183. {
  184. $params = [
  185. 'update_time' => date('Y-m-d H:i:s'),
  186. 'sub_base_room_id' => $roomInfo['roomTypeId'],
  187. ];
  188. if (empty($roomInfo['roomTypeId']) == false) {
  189. $params['base_room_is_add'] = 1;
  190. }
  191. self::updateAll(
  192. $params,
  193. 'master_base_room_id=:master_base_room_id and channel_id in (:channel_id)',
  194. [
  195. ':master_base_room_id' => $roomInfo['masterBasicRoomTypeId'],
  196. ':channel_id' => implode(',', $channel_arr)
  197. ]
  198. );
  199. }
  200. /**
  201. * Des:添加关联关系
  202. * Name: addRows
  203. * @param $roomInfo
  204. * @param $hotelInfo
  205. * @param $channel_arr
  206. * @author 倪宗锋
  207. */
  208. public function addRows($roomInfo, $hotelInfo, $channel_arr)
  209. {
  210. //获取cookies
  211. $cookies = Yii::$app->request->cookies;
  212. //账号权限
  213. $user_id = $cookies->getValue('user_id');
  214. foreach ($channel_arr as $channel_id) {
  215. try {
  216. $values = [
  217. 'create_time' => date('Y-m-d H:i:s'),
  218. 'create_user_id' => empty($user_id) ? 0 : $user_id,
  219. 'channel_id' => $channel_id,
  220. 'master_hotel_id' => $hotelInfo['master_hotel_id'],
  221. 'sub_hotel_id' => $hotelInfo['sub_hotel_id'],
  222. 'hotel_id' => $hotelInfo['hotel_id'],
  223. 'master_base_room_id' => $roomInfo['masterBasicRoomId'],
  224. 'master_base_room_name' => $roomInfo['basicRoomName'],
  225. 'master_base_room_name_en' => $roomInfo['basicRoomNameEn']
  226. ];
  227. if (empty($basicRoomTyp) == false) {
  228. $values['base_room_is_add'] = 1;
  229. }
  230. $table = new ChannelBaseRoomMapping();
  231. $table->isNewRecord = true;
  232. $table->setAttributes($values);
  233. $flag = $table->save();
  234. $a = $table->getErrors();
  235. $s = $flag;
  236. } catch (Exception $e) {
  237. }
  238. }
  239. }
  240. /**
  241. * Des:已经不存在的基础房型删除
  242. * Name: delRow
  243. * @author 倪宗锋
  244. */
  245. public function delRow($sub_hotel_id, $channel_arr, $ctripMasterRoomId)
  246. {
  247. $params = [
  248. 'update_time' => date('Y-m-d H:i:s'),
  249. 'cancel_flag' => 1,
  250. ];
  251. $master_base_room_id = implode(',', $ctripMasterRoomId);
  252. $channel_id = implode(',', $channel_arr);
  253. $where = "channel_id in ({$channel_id}) and sub_hotel_id = {$sub_hotel_id}";
  254. if ( !empty($master_base_room_id)){
  255. $where .= " and master_base_room_id not in ({$master_base_room_id})";
  256. }
  257. self::updateAll($params,$where);
  258. }
  259. /**
  260. * Des:删除基础房型的管理关系
  261. * Name: delMapping
  262. * @param $param
  263. * @param $channel_arr
  264. * @author 倪宗锋
  265. */
  266. public function delBaseRoomMapping($param, $channel_arr)
  267. {
  268. $data = [
  269. 'base_room_id' => null
  270. ];
  271. $where = [
  272. 'base_room_id' => $param['base_room_id'],
  273. 'channel_id' => $channel_arr
  274. ];
  275. self::updateAll($data, $where);
  276. }
  277. }