HotelService.js 7.8 KB
"use strict";
var HotelService = angular.module('HotelService',[]);

HotelService.service("HotelService", [
	'$rootScope',
	'BaseService',
	function ($rootScope,BaseService) {
		var _service = {
				hotels:[],
				hotel:[],
				rooms:[],
				room:[],
				stockList:[],
				orders:[],
				order:[],
				refundOrders:[],
				orderProcedureList:[],
				hotelList:function(){
					BaseService.request({
						url:BaseService.url.hotelList_url,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.hotels = response.data;
								$rootScope.$broadcast('hotels.list');
							}
						}
					});
				},
				hotelDetail:function(hotelId){
					BaseService.request({
						url:BaseService.url.hotelDetail_url+"/"+hotelId,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.hotel = response.data;
								$rootScope.$broadcast('hotels.detail');
							}
						}
					});
				},
				saveOrUpdate:function(hotel){
					BaseService.request({
						url:BaseService.url.hotelSaveOrUpdate_url,
						method:'post',
						mark:true,
						data:hotel,
						fn:function(response) {
							if(response.code==0){
								//callback.call();
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				delHotel:function(param){
					BaseService.request({
						url:BaseService.url.delHotel_url,
						method:'post',
						mark:true,
						data:param,
						fn:function(response) {
							if(response.code==0){
								//callback.call();
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				roomList:function(hotelId){
					BaseService.request({
						url:BaseService.url.roomList_url+"/"+hotelId,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code==0){
								_service.rooms = response.data;
								$rootScope.$broadcast('room.list');
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				roomDetail:function(roomId){
					BaseService.request({
						url:BaseService.url.roomDetail_url+"/"+roomId,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code==0){
								_service.room = response.data;
								$rootScope.$broadcast('room.detail');
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				
				delRoom:function(roomId){
					BaseService.request({
						url:BaseService.url.delRoom_url+"/"+roomId,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code==0){
								//callback.call();
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				saveOrUpdateRoomType:function(room){
					BaseService.request({
						url:BaseService.url.roomSaveOrUpdate_url,
						method:'post',
						mark:true,
						data:room,
						fn:function(response) {
							if(response.code==0){
								//callback.call();
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				
				roomStockList:function(roomId){
					BaseService.request({
						url:BaseService.url.roomStock_url+"/"+roomId,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.stockList = response.data;
								$rootScope.$broadcast('roomStock.list');
							}
						}
					});
				},
				
				updateRoomStock:function(roomStock){
					BaseService.request({
						url:BaseService.url.roomStockUpdate_url,
						method:'post',
						mark:true,
						data:roomStock,
						fn:function(response) {
							if(response.code==0){
								//callback.call();
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				orderPagerList:function(queryParam){
					BaseService.request({
						url:BaseService.url.hotelOrderPager_url,
						method:'post',
						mark:true,
						data:queryParam,
						fn:function(response) {
							if(response.code == 0) {
								_service.orders = response.data;
								$rootScope.$broadcast('orders.list');
							}
						}
					});
				},
				refundOrderPagerList:function(queryParam){
					BaseService.request({
						url:BaseService.url.hotelRefundOrderPager_url,
						method:'post',
						mark:true,
						data:queryParam,
						fn:function(response) {
							if(response.code == 0) {
								_service.refundOrders = response.data;
								$rootScope.$broadcast('refundOrders.list');
							}
						}
					});
				},
				orderDetail:function(orderId){
					BaseService.request({
						url:BaseService.url.hotelOrderDetail_url+"/"+orderId,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.order = response.data;
								$rootScope.$broadcast('orders.detail');
							}
						}
					});
				},
				verifyOrder:function(ids,callback){
					BaseService.request({
						url:BaseService.url.verifyOrder_url,
						method:'post',
						mark:true,
						data:{ids:ids},
						fn:function(response) {
							if(response.code == 0) {
								callback();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				updateOrderRefundAccept:function(id,callback){
					BaseService.request({
						url:BaseService.url.refundOrder_accept_url+id,
						method:'post',
						mark:true,
						data:{ids:id},
						fn:function(response) {
							if(response.code == 0) {
								callback();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				updateOrderRefundSuccess:function(id,callback){
					BaseService.request({
						url:BaseService.url.refundOrder_success_url+id,
						method:'post',
						mark:true,
						data:{ids:id},
						fn:function(response) {
							if(response.code == 0) {
								callback();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				updateOrderStay:function(id){
					BaseService.request({
						url:BaseService.url.updateOrderStay_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				
				updateOrderBookingStatus:function(id,success){
					var url=""
					if(success){
						url=BaseService.url.updateOrderBookingSuccess_url
					}else{
						url=BaseService.url.updateOrderBookingFail_url
					}
					BaseService.request({
						url:url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code ==0){
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message);
								
							}
						}
					});
				},
				
				updateOrderOverTimeStatus:function(id,success){
					BaseService.request({
						url:BaseService.url.updateOrderOvertime_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				getOrderProcedureList:function(subOrderId){
					BaseService.request({
						url:BaseService.url.hotelOrderProcedure_url+subOrderId,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.orderProcedureList = response.data;
								$rootScope.$broadcast('ordersProcedure.list');
							}
						}
					});
				},
		}
		return _service;
	}]);