CouponService.js 8.9 KB
"use strict";
var couponService = angular.module('CouponService',[]);

couponService.service("CouponService", [
	'$rootScope',
	'BaseService',
	function ($rootScope,BaseService) {
		var _service = {
            directCoupon:"",
            directCoupons:[],
            addDirectCoupon:function(ops, id) {
                var url = id ? BaseService.url.editDirectCoupon_url : BaseService.url.addDirectCoupon_url;
                BaseService.request({
                    url:url,
                    method:'post',
                    data:ops,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            pagerCouponDirect:function(productQuery) {
                BaseService.request({
                    url:BaseService.url.pagerDirectCoupon_url,
                    method:'post',
                    mark:true,
                    data:productQuery,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.directCoupons = response.data;
                            $rootScope.$broadcast('DirectCoupon.list');
                        }
                    }
                });
            },
            deleteDirectCoupon:function(couponId) {
            BaseService.request({
                url:BaseService.url.deleteDirectCoupon_url,
                method:'post',
                mark:true,
                data:couponId,
                fn:function(response) {
                    if(response.code == 0) {
                        window.location.reload();
                    }else{
                        BaseService.updateAlert(response.message, response.code);
                    }
                }
            });
            },
            deleteFullCoupon:function(couponId) {
                BaseService.request({
                    url:BaseService.url.deleteFullCoupon_url,
                    method:'post',
                    mark:true,
                    data:couponId,
                    fn:function(response) {
                        if(response.code == 0) {
                            window.location.reload();
                        }else{
                            BaseService.updateAlert(response.message, response.code);
                        }
                    }
                });
            },
            pagerUserCoupon:function(productQuery) {
                BaseService.request({
                    url:BaseService.url.pagerUserCoupon_url,
                    method:'post',
                    mark:true,
                    data:productQuery,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.directCoupons = response.data;
                            $rootScope.$broadcast('UserCoupon.list');
                        }
                    }
                });
            },
            pagerSupplierUserCoupon:function(productQuery) {
                BaseService.request({
                    url:BaseService.url.pagerSupplierUserCoupon_url,
                    method:'post',
                    mark:true,
                    data:productQuery,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.supplierCoupons = response.data;
                            $rootScope.$broadcast('supplierUserCoupon.list');
                        }
                    }
                });
            },
            pagerSupplierUserCouponDetail:function(productQuery) {
                BaseService.request({
                    url:BaseService.url.pagerSupplierUserCouponDetail_url,
                    method:'post',
                    mark:true,
                    data:productQuery,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.supplierCouponDetails = response.data;
                            $rootScope.$broadcast('supplierUserCouponDetail.list');
                        }
                    }
                });
            },
            getCouponDirectById:function(id, callback) {
                BaseService.request({
                    url:BaseService.url.getDirectCoupon_url+id,
                    method:'get',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
            addFullCutCoupon:function(ops, id) {
                var url = id ? BaseService.url.editFullCutCoupon_url : BaseService.url.addFullCutCoupon_url;
                BaseService.request({
                    url:url,
                    method:'post',
                    data:ops,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            pagerCouponFullCut:function(productQuery) {
                BaseService.request({
                    url:BaseService.url.pagerFullCutCoupon_url,
                    method:'post',
                    mark:true,
                    data:productQuery,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.directCoupons = response.data;
                            $rootScope.$broadcast('FullCutCoupon.list');
                        }
                    }
                });
            },
            getCouponFullCutById:function(id, callback) {
                BaseService.request({
                    url:BaseService.url.getFullCutCoupon_url+id,
                    method:'get',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
            addFullCutLimitCoupon:function(ops) {
                BaseService.request({
                    url:BaseService.url.addFullCutLimitCoupon_url,
                    method:'post',
                    data:ops,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            pagerCouponLimitFullCut:function(productQuery) {
                BaseService.request({
                    url:BaseService.url.pagerFullCutLimitCoupon_url,
                    method:'post',
                    mark:true,
                    data:productQuery,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.directCoupons = response.data;
                            $rootScope.$broadcast('FullCutCouponLimit.list');
                        }
                    }
                });
            },
            deleteCouponLimitFullCut:function(ops) {
                BaseService.request({
                    url:BaseService.url.deleteFullCutLimitCoupon_url,
                    method:'post',
                    mark:true,
                    data:ops,
                    fn:function(response) {
                        if(response.code == 0) {
                            window.location.reload();
                        }else{
                            BaseService.updateAlert(response.message,response.code);
                        }
                    }
                });
            },
            addShareGiftCoupon:function(ops) {
                BaseService.request({
                    url:BaseService.url.addShareGiftCoupon_url,
                    method:'post',
                    data:ops,
                    mark:false,
                    fn:function(data){
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            getShareCoupon:function(callback) {
                BaseService.request({
                    url:BaseService.url.getShareGiftCoupon_url,
                    method:'get',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
		};
		return _service;
	}
]);