Esempio n. 1
0
        public static TenantPrd isPrdSPecEnought(TenantPrd prd, string item, int buyCount)
        {
            if (prd.dtSellEnd != null && prd.dtSellEnd < DateTime.Now)
            {
                return(null);
            }
            else if (string.IsNullOrEmpty(item) || string.IsNullOrEmpty(prd.prdSepc))
            {
                // 沒有商品規格不判斷
                return(prd);
            }

            dynamic itemSpec = JValue.Parse(item);
            string  code     = itemSpec.code;

            dynamic prdSpecs = JArray.Parse(prd.prdSepc);

            foreach (var prdSpec in prdSpecs)
            {
                string prdCode = prdSpec.code;
                if (prdCode.Equals(code))
                {
                    int num = int.Parse(Convert.ToString(prdSpec.num));
                    if (string.IsNullOrEmpty(prd.zeroStockMessage) || num - buyCount > -1)
                    {
                        prdSpec.num = Convert.ToString(num - buyCount);
                        prd.prdSepc = JsonConvert.SerializeObject(prdSpecs);
                        return(prd);
                    }
                }
            }
            return(null);
        }
Esempio n. 2
0
        public static ReturnMessage isProductEnough(int userId)
        {
            ReturnMessage      rm           = new ReturnMessage();
            List <ShopCartPrd> shopCartPrds = DataManager.shopCartDao.getItemsByMember(userId);
            bool       isCheck = true;
            List <int> data    = new List <int>();

            foreach (ShopCartPrd item in shopCartPrds)
            {
                TenantPrd prdItem = DataManager.tenantPrdDao.getTenandPrd(item.productId);
                if (String.IsNullOrEmpty(prdItem.zeroStockMessage) && (prdItem.dtSellEnd == null || prdItem.dtSellEnd > DateTime.Now))
                {
                    Debug.Write("success");
                    continue;
                }

                TenantPrd tmpPrdItem = isPrdSPecEnought(prdItem, item.prdSepc, item.count);
                prdItem.stockNum = prdItem.stockNum - item.count;
                if (prdItem.stockNum < 0 || tmpPrdItem == null || prdItem.dtSellEnd < DateTime.Now)
                {
                    Debug.Write("faild");
                    data.Add(prdItem.id);
                    isCheck = false;
                }
            }
            rm.code = isCheck ? MessageCode.SUCCESS : MessageCode.ERROR;
            rm.data = data;
            return(rm);
        }
Esempio n. 3
0
        //顯示獨立價格
        public static PrdPrice getPrdPrice(TenantPrd prd, string userType, int userId)
        {
            PrdPrice    prdPrice         = new PrdPrice();
            string      type             = UserType.GUEST;
            int         price            = int.MaxValue;
            int         custPriceGradeId = 0;
            string      priceGradeType   = "";
            TenantGrade tenantGrade      = DataManager.tenantDao.GetTenantGrade(prd.tenantId);
            string      tenantGradeType  = "團媽";

            if (tenantGrade != null)
            {
                tenantGradeType = tenantGrade.tenantGrade;
            }
            List <PrdPrice> prices = getPrdPrices(prd, userType, userId, tenantGradeType);

            foreach (PrdPrice itemPrice in prices)
            {
                if (itemPrice.price <= price)
                {
                    price            = itemPrice.price;
                    type             = itemPrice.type;
                    custPriceGradeId = itemPrice.custPriceGradeId;
                    priceGradeType   = itemPrice.priceGradeType;
                }
            }
            prdPrice.price            = price;
            prdPrice.type             = type;
            prdPrice.priceGradeType   = priceGradeType;
            prdPrice.custPriceGradeId = custPriceGradeId;

            return(prdPrice);
        }
Esempio n. 4
0
        public ActionResult getHomePrdItem(int prdId)
        {
            ReturnMessage rm = new ReturnMessage();

            try
            {
                string type     = User.Claims.FirstOrDefault(p => p.Type == "type").Value;
                string tenantId = User.Claims.FirstOrDefault(p => p.Type == "tenantId").Value;
                int    memberId = -1;
                if (!UserType.GUEST.Equals(type))
                {
                    memberId = int.Parse(User.Claims.FirstOrDefault(p => p.Type == "jti").Value);
                }
                TenantGrade tenantGrade     = DataManager.tenantDao.GetTenantGrade(Guid.Parse(tenantId));
                string      tenantGradeType = "團媽";
                if (tenantGrade != null)
                {
                    tenantGradeType = tenantGrade.tenantGrade;
                }
                TenantPrd prd = DataManager.tenantPrdDao.getTenandPrd(prdId);
                rm.code = MessageCode.SUCCESS;
                rm.data = CTenantPrdManager.getPrdItem(prd, type, memberId, tenantGradeType);
            }
            catch (Exception e)
            {
                rm.code = MessageCode.ERROR;
                rm.data = e.Message;
            }
            return(Ok(rm));
        }
Esempio n. 5
0
 // 單獨商品
 public TenantPrd getTenandPrd(int prdId)
 {
     using (CrazyBuyDbContext dbContext = ContextInit())
     {
         TenantPrd model = dbContext.TenantPrd.Where(
             m => m.id == prdId).SingleOrDefault();
         return(model);
     }
 }
        public ActionResult Put([FromBody] ShopCartRequest value)
        {
            ReturnMessage rm = new ReturnMessage();

            try
            {
                string type     = User.Claims.FirstOrDefault(p => p.Type == "type").Value;
                int    memberId = int.Parse(User.Claims.FirstOrDefault(p => p.Type == "jti").Value);
                string sepc     = value.sepc;
                Guid   tenantId = Guid.Parse(User.Claims.FirstOrDefault(p => p.Type == "tenantId").Value);
                Guid   itemId   = Guid.NewGuid();

                TenantPrd prd      = DataManager.tenantPrdDao.getTenandPrd(value.productId);
                PrdPrice  prdPrice = CTenantPrdManager.getPrdPrice(prd, type, memberId);

                if (!string.IsNullOrEmpty(sepc))
                {
                    sepc = (string)JObject.Parse(sepc).GetValue("code");
                }
                ShopCart shopCart = DataManager.shopCartDao.getShopCartPrd(tenantId, memberId, value.productId, sepc);

                if (shopCart == null)
                {
                    shopCart                = new ShopCart();
                    shopCart.id             = itemId;
                    shopCart.memberId       = memberId;
                    shopCart.productId      = value.productId;
                    shopCart.createTime     = DateTime.Now;
                    shopCart.count          = value.count;
                    shopCart.amount         = prdPrice.price * value.count;
                    shopCart.type           = prdPrice.type;
                    shopCart.tenantId       = tenantId;
                    shopCart.prdSepc        = value.sepc;
                    shopCart.prdCustPriceId = prdPrice.custPriceGradeId;
                    shopCart.priceGradeType = prdPrice.priceGradeType;
                    DataManager.shopCartDao.addItem(shopCart);
                }
                else
                {
                    itemId          = shopCart.id;
                    shopCart.count += value.count;
                    shopCart.amount = prdPrice.price * shopCart.count;
                    DataManager.shopCartDao.updateItem(shopCart);
                }
                rm.code = MessageCode.SUCCESS;
                rm.data = itemId;
            }
            catch (Exception e)
            {
                rm.code = MessageCode.ERROR;
                rm.data = e.Message;
            }
            return(Ok(rm));
        }
Esempio n. 7
0
 public void updateTenandPrd(TenantPrd tenantPrd)
 {
     using (CrazyBuyDbContext dbContext = ContextInit())
     {
         TenantPrd model = dbContext.TenantPrd.Where(
             m => m.id == tenantPrd.id).SingleOrDefault();
         if (model != null)
         {
             dbContext.Entry(model).CurrentValues.SetValues(tenantPrd);
             dbContext.SaveChanges();
         }
     }
 }
Esempio n. 8
0
        public static Dictionary <string, object> getPrdItem(TenantPrd prd, string userType, int userId, string type)
        {
            Dictionary <string, object> data   = new Dictionary <string, object>();
            Dictionary <string, string> prices = new Dictionary <string, string>();
            string price;

            List <PrdPrice> prdPrices = getPrdPrices(prd, userType, userId, type);

            foreach (PrdPrice prdPrice in prdPrices)
            {
                if (prdPrice.price <= 0)
                {
                    continue;
                }
                price = string.Format("${0}", prdPrice.price);
                prices.Add(prdPrice.type, price);
            }

            data.Add("prices", prices);
            data.Add("id", prd.id);
            data.Add("name", prd.name);
            data.Add("prdCode", prd.prdCode);
            data.Add("tenantId", prd.tenantId);
            data.Add("summary", prd.summary);
            data.Add("desc", prd.desc);
            data.Add("prdImages", prd.prdImages);
            data.Add("paymentType", prd.paymentType);
            data.Add("shipType", prd.shipType);
            data.Add("tags", prd.SpecialRule);
            data.Add("sepc", prd.prdSepc);
            data.Add("zeroStock", prd.zeroStockMessage);
            data.Add("count", prd.stockNum);
            data.Add("isOpenOrder", prd.isOpenOrder);
            data.Add("isTakeOff", DateTime.Now > prd.dtSellEnd);
            data.Add("takeOffMessage", prd.takeOffMessage);
            data.Add("face2faceRule", prd.face2faceRule);
            return(data);
        }
Esempio n. 9
0
        public static ReturnMessage addOrder(OrderMaster orderMaster, UserInfo userInfo)
        {
            ReturnMessage rm          = new ReturnMessage();
            int           orderResult = MessageCode.ERROR;

            try
            {
                DateTime now = DateTime.Now;
                orderMaster.tenantId   = userInfo.tnenatId;
                orderMaster.memberId   = userInfo.memberId;
                orderMaster.dtOrder    = now;
                orderMaster.dtInStock  = now;
                orderMaster.createTime = now;
                orderMaster.updateTime = now;
                int total     = 0;
                int taxAmount = 0;
                DataManager.shopCartDao.deleteTimeOutItem(userInfo.memberId); //防止購入超時商品
                List <ShopCartPrd>          shopCartPrds = DataManager.shopCartDao.getItemsByMember(userInfo.memberId);
                List <OrderDetail>          detailList   = new List <OrderDetail>();
                Dictionary <int, TenantPrd> prdMap       = new Dictionary <int, TenantPrd>();
                TenantMemLevel tenantMemLevel            = DataManager.tenantMemberDao.getMemberLevel(userInfo.memberId);

                //是否有高級會員折扣
                double dis           = 1;
                int    memberLevelId = MessageCode.ERROR;
                if (tenantMemLevel != null)
                {
                    memberLevelId = tenantMemLevel.id;
                    dis           = tenantMemLevel.discount * 0.01;
                }

                //結算購物車價錢及規格數量
                foreach (ShopCartPrd item in shopCartPrds)
                {
                    TenantPrd prdItem = DataManager.tenantPrdDao.getTenandPrd(item.productId);
                    prdItem = isPrdSPecEnought(prdItem, item.prdSepc, item.count);
                    if (prdItem != null)
                    {
                        OrderDetail detail = new OrderDetail();
                        detail.prdId = item.productId;
                        detail.qty   = item.count;

                        detail.amount = item.amount;
                        if (item.SpecialRule == null || !item.SpecialRule.Contains(UserDisType.NO_DIS))
                        {
                            detail.amount = (int)(detail.amount * dis);
                        }

                        detail.unitPrice      = detail.amount / detail.qty;
                        detail.status         = "正常";
                        detail.createTime     = now;
                        detail.updateTime     = now;
                        detail.prdSpec        = item.prdSepc;
                        detail.prdCustPriceId = item.prdCustPriceId;
                        detail.priceGradeType = item.priceGradeType;
                        total += detail.amount;
                        detailList.Add(detail);
                        if (!prdMap.ContainsKey(prdItem.id))
                        {
                            prdMap.Add(prdItem.id, prdItem);
                        }
                    }
                }

                //檢查是否數量足夠
                foreach (OrderDetail item in detailList)
                {
                    TenantPrd prdItem = prdMap.GetValueOrDefault(item.prdId);
                    prdItem.stockNum = prdItem.stockNum - item.qty;
                    if (!string.IsNullOrEmpty(prdItem.zeroStockMessage) && prdItem.dtSellEnd > DateTime.Now)
                    {
                        if (prdItem.stockNum < 0)
                        {
                            Debug.WriteLine(prdItem.name);
                            rm.code = MessageCode.PRD_NOT_ENOUGHT;
                            return(rm);
                        }
                    }
                }

                //開始寫入價格
                if (total != 0)
                {
                    orderMaster.orderAmount = total;
                    if (orderMaster.isNeedInvoice || orderMaster.invoiceType.Equals("捐贈"))
                    {
                        taxAmount = Convert.ToInt32(total * 0.05);
                    }
                    total += taxAmount;
                    total += orderMaster.shippingAmount;
                    orderMaster.totalAmount = total;
                    // 5/14有需求說先將等待貨款拿掉
                    //orderMaster.payStatus = "等待貨款";
                    orderMaster.shippingStatus = "未出貨";
                    orderMaster.status         = "新訂單";
                    orderMaster.taxAmount      = taxAmount;
                    if (MessageCode.ERROR != memberLevelId)
                    {
                        orderMaster.levelId = memberLevelId;
                    }

                    OrderMaster master = DataManager.orderDao.addOrderMaster(orderMaster);

                    orderResult = master.id;
                    rm.data     = master;
                    foreach (OrderDetail item in detailList)
                    {
                        TenantPrd prdItem = prdMap.GetValueOrDefault(item.prdId);
                        DataManager.tenantPrdDao.updateTenandPrd(prdItem);

                        item.orderId = master.id;
                        DataManager.orderDao.addOrderDetail(item);
                    }
                    DataManager.shopCartDao.removeItemsByMember(userInfo.memberId);

                    OrderAmountHistory histroy = new OrderAmountHistory();
                    histroy.orderId          = master.id;
                    histroy.changeDesc       = "購物完成";
                    histroy.changeAmount     = total;
                    histroy.cumulativeAmount = 0;
                    histroy.status           = "正常";
                    histroy.createTime       = DateTime.Now;
                    histroy.creator          = userInfo.memberId;
                    DataManager.orderAmountHistoryDao.add(histroy);
                }
            }
            catch (Exception e)
            {
                MDebugLog.error("[COrderManager-addOrder] error: " + e);
            }
            rm.code = orderResult;
            return(rm);
        }
Esempio n. 10
0
        //畫面呈現價格
        public static List <PrdPrice> getPrdPrices(TenantPrd prd, string userType, int userId, string tenantGrade)
        {
            List <PrdPrice> prices = new List <PrdPrice>();

            switch (userType)
            {
            case LoginType.LOGIN_USER:
                TenantMember tenantMember = DataManager.tenantMemberDao.getTenantMemberByMemberId(userId);
                PrdPrice     prdPriceUser = new PrdPrice();
                prdPriceUser.price            = prd.fixedprice == null ? 0 : (int)prd.fixedprice;
                prdPriceUser.type             = CHType.PRICE_NORMAL;
                prdPriceUser.priceGradeType   = "";
                prdPriceUser.custPriceGradeId = 0;
                prices.Add(prdPriceUser);

                prdPriceUser                  = new PrdPrice();
                prdPriceUser.price            = prd.memberPrice == null ? 0 : (int)prd.memberPrice;
                prdPriceUser.type             = CHType.PRICE_MEMBER;
                prdPriceUser.priceGradeType   = "";
                prdPriceUser.custPriceGradeId = 0;
                prices.Add(prdPriceUser);

                if (UserGradeType.TRANS.Equals(tenantMember.gradeType))
                {
                    prdPriceUser                  = new PrdPrice();
                    prdPriceUser.price            = prd.transferPrice == null ? 0 : (int)prd.transferPrice;
                    prdPriceUser.type             = CHType.PRICE_NTRANS;
                    prdPriceUser.priceGradeType   = "轉批價";
                    prdPriceUser.custPriceGradeId = 0;
                    prices.Add(prdPriceUser);
                }
                break;

            case UserType.ADMIN:
                PrdPrice prdPriceAdmin = new PrdPrice();
                prdPriceAdmin.price            = prd.fixedprice == null ? 0 : (int)prd.fixedprice;
                prdPriceAdmin.type             = CHType.PRICE_NORMAL;
                prdPriceAdmin.priceGradeType   = "";
                prdPriceAdmin.custPriceGradeId = 0;
                prices.Add(prdPriceAdmin);

                prdPriceAdmin                  = new PrdPrice();
                prdPriceAdmin.price            = prd.memberPrice == null ? 0 : (int)prd.memberPrice;
                prdPriceAdmin.type             = CHType.PRICE_MEMBER;
                prdPriceAdmin.priceGradeType   = "";
                prdPriceAdmin.custPriceGradeId = 0;
                prices.Add(prdPriceAdmin);
                Debug.WriteLine("[CMemberManager-addMember] error:" + tenantGrade);
                if (tenantGrade != "轉批媽" && tenantGrade != "批發商")
                {
                    break;
                }
                prdPriceAdmin                  = new PrdPrice();
                prdPriceAdmin.price            = prd.transferPrice == null ? 0 : (int)prd.transferPrice;
                prdPriceAdmin.type             = CHType.PRICE_NTRANS;
                prdPriceAdmin.priceGradeType   = "轉批價";
                prdPriceAdmin.custPriceGradeId = 0;
                prices.Add(prdPriceAdmin);
                break;

            default:
                if (userType.StartsWith(UserType.SPC_MEMBER))
                {
                    string   custGrade         = userType.Split(":")[1];
                    PrdPrice prdPriceSPCMember = new PrdPrice();
                    prdPriceSPCMember.price            = prd.fixedprice == null ? 0 : (int)prd.fixedprice;
                    prdPriceSPCMember.type             = CHType.PRICE_NORMAL;
                    prdPriceSPCMember.priceGradeType   = "";
                    prdPriceSPCMember.custPriceGradeId = 0;
                    prices.Add(prdPriceSPCMember);

                    prdPriceSPCMember                  = new PrdPrice();
                    prdPriceSPCMember.price            = prd.memberPrice == null ? 0 : (int)prd.memberPrice;
                    prdPriceSPCMember.type             = CHType.PRICE_MEMBER;
                    prdPriceSPCMember.priceGradeType   = "";
                    prdPriceSPCMember.custPriceGradeId = 0;
                    prices.Add(prdPriceSPCMember);

                    CustSpcPrice spc_price = DataManager.tenantPrdDao.getSpcTenantPrdPrice(prd.tenantId, prd.id, int.Parse(custGrade));
                    if (spc_price != null)
                    {
                        prdPriceSPCMember                  = new PrdPrice();
                        prdPriceSPCMember.price            = spc_price.price;
                        prdPriceSPCMember.type             = spc_price.name;
                        prdPriceSPCMember.priceGradeType   = "自訂價";
                        prdPriceSPCMember.custPriceGradeId = spc_price.id;
                        prices.Add(prdPriceSPCMember);
                    }
                }
                break;
            }
            return(prices);
        }