예제 #1
0
        public async Task <IActionResult> Edit(Coupon editCoupon)
        {
            // var editCoupon = JsonConvert.DeserializeObject<Coupon>(form["coupon"]);
            string message;

            try
            {
                // TODO: Add update logic here
                await _service.EditCoupon(editCoupon);

                message = "Success";
            }
            catch (Exception ex)
            {
                message = ex.Message.ToString();
            }
            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
 /// <summary>
 /// 商家修改一个优惠券
 /// </summary>
 /// <param name="info"></param>
 public static void EditCoupon(CouponInfo info)
 {
     _iCouponService.EditCoupon(info);
 }
예제 #3
0
        public JsonResult Edit(CouponInfo info)
        {
            bool flag = false;

            if (info.Id == 0)
            {
                flag = true;
            }
            ICouponService couponService = ServiceHelper.Create <ICouponService>();
            long           shopId        = base.CurrentSellerManager.ShopId;

            info.ShopId = shopId;
            string shopName = ServiceHelper.Create <IShopService>().GetShop(shopId, false).ShopName;

            info.ShopName = shopName;
            if (flag)
            {
                info.CreateTime = DateTime.Now;
                if (info.StartTime >= info.EndTime)
                {
                    Result result = new Result()
                    {
                        success = false,
                        msg     = "开始时间必须小于结束时间"
                    };
                    return(Json(result));
                }
                info.IsSyncWeiXin = 0;
                if (info.FormIsSyncWeiXin)
                {
                    info.IsSyncWeiXin = 1;
                    if (string.IsNullOrWhiteSpace(info.FormWXColor))
                    {
                        Result result1 = new Result()
                        {
                            success = false,
                            msg     = "错误的卡券颜色"
                        };
                        return(Json(result1));
                    }
                    if (string.IsNullOrWhiteSpace(info.FormWXCTit))
                    {
                        Result result2 = new Result()
                        {
                            success = false,
                            msg     = "请填写卡券标题"
                        };
                        return(Json(result2));
                    }
                    if (!WXCardLogInfo.WXCardColors.Contains(info.FormWXColor))
                    {
                        Result result3 = new Result()
                        {
                            success = false,
                            msg     = "错误的卡券颜色"
                        };
                        return(Json(result3));
                    }
                    Encoding @default = Encoding.Default;
                    if (@default.GetBytes(info.FormWXCTit).Count() > 18)
                    {
                        Result result4 = new Result()
                        {
                            success = false,
                            msg     = "卡券标题不得超过9个汉字"
                        };
                        return(Json(result4));
                    }
                    if (!string.IsNullOrWhiteSpace(info.FormWXCSubTit) && @default.GetBytes(info.FormWXCSubTit).Count() > 36)
                    {
                        Result result5 = new Result()
                        {
                            success = false,
                            msg     = "卡券副标题不得超过18个汉字"
                        };
                        return(Json(result5));
                    }
                }
            }
            string item = base.Request.Form["chkShow"];

            info.CanVshopIndex = base.CurrentSellerManager.VShopId > 0;
            switch (info.ReceiveType)
            {
            case CouponInfo.CouponReceiveType.IntegralExchange:
            {
                if (!couponService.CanAddIntegralCoupon(shopId, info.Id))
                {
                    Result result6 = new Result()
                    {
                        success = false,
                        msg     = "当前己有积分优惠券,每商家只可以推广一张积分优惠券!"
                    };
                    return(Json(result6));
                }
                info.Himall_CouponSetting.Clear();
                if (!info.EndIntegralExchange.HasValue)
                {
                    Result result7 = new Result()
                    {
                        success = false,
                        msg     = "错误的兑换截止时间"
                    };
                    return(Json(result7));
                }
                DateTime?endIntegralExchange = info.EndIntegralExchange;
                DateTime date = info.EndTime.AddDays(1).Date;
                if ((endIntegralExchange.HasValue ? endIntegralExchange.GetValueOrDefault() > date : false))
                {
                    Result result8 = new Result()
                    {
                        success = false,
                        msg     = "错误的兑换截止时间"
                    };
                    return(Json(result8));
                }
                if (info.NeedIntegral >= 10)
                {
                    break;
                }
                Result result9 = new Result()
                {
                    success = false,
                    msg     = "积分最少10分起兑"
                };
                return(Json(result9));
            }

            case CouponInfo.CouponReceiveType.DirectHair:
            {
                info.Himall_CouponSetting.Clear();
                break;
            }

            default:
            {
                if (string.IsNullOrEmpty(item))
                {
                    Result result10 = new Result()
                    {
                        success = false,
                        msg     = "必须选择一个推广类型"
                    };
                    return(Json(result10));
                }
                info.Himall_CouponSetting.Clear();
                string[] strArrays = item.Split(new char[] { ',' });
                if (strArrays.Contains <string>("WAP") && info.CanVshopIndex)
                {
                    ICollection <CouponSettingInfo> himallCouponSetting = info.Himall_CouponSetting;
                    CouponSettingInfo couponSettingInfo = new CouponSettingInfo()
                    {
                        Display  = new int?(1),
                        PlatForm = PlatformType.Wap
                    };
                    himallCouponSetting.Add(couponSettingInfo);
                }
                if (!strArrays.Contains <string>("PC"))
                {
                    break;
                }
                ICollection <CouponSettingInfo> couponSettingInfos = info.Himall_CouponSetting;
                CouponSettingInfo couponSettingInfo1 = new CouponSettingInfo()
                {
                    Display  = new int?(1),
                    PlatForm = PlatformType.PC
                };
                couponSettingInfos.Add(couponSettingInfo1);
                break;
            }
            }
            Server.MapPath(string.Format("/Storage/Shop/{0}/Coupon/{1}", shopId, info.Id));
            if (!flag)
            {
                couponService.EditCoupon(info);
            }
            else
            {
                couponService.AddCoupon(info);
            }
            return(Json(new { success = true }));
        }