Beispiel #1
0
        public ActionResult getBankInfo()
        {
            ReturnMessage rm = new ReturnMessage();

            try
            {
                int  memberId = int.Parse(User.Claims.FirstOrDefault(p => p.Type == "jti").Value);
                Guid tenantId = Guid.Parse(User.Claims.FirstOrDefault(p => p.Type == "tenantId").Value);
                List <TenantSetting>        settings = DataManager.tenantDao.getAllTenantSetting(tenantId);
                Dictionary <string, string> type     = new Dictionary <string, string>();
                foreach (TenantSetting setting in settings)
                {
                    if (!string.IsNullOrEmpty(setting.content))
                    {
                        type.Add(TenantSettingMapping.getType(setting.title), setting.content);
                    }
                }
                var data = new
                {
                    bank = new
                    {
                        bankTitle   = type.GetValueOrDefault("bankTitle"),
                        bankCode    = type.GetValueOrDefault("bankCode"),
                        bankAccount = type.GetValueOrDefault("bankAccount"),
                        bankName    = type.GetValueOrDefault("bankName"),
                        subBankName = type.GetValueOrDefault("subBankName")
                    }
                };


                rm.code = MessageCode.SUCCESS;
                rm.data = data;
            }
            catch (Exception e)
            {
                rm.code = MessageCode.ERROR;
                rm.data = e.Message;
            }
            return(Ok(rm));
        }
Beispiel #2
0
        public ActionResult getFreight()
        {
            ReturnMessage rm = new ReturnMessage();

            try
            {
                int  memberId = int.Parse(User.Claims.FirstOrDefault(p => p.Type == "jti").Value);
                Guid tenantId = Guid.Parse(User.Claims.FirstOrDefault(p => p.Type == "tenantId").Value);

                List <ShopCartPrd>       items    = DataManager.shopCartDao.getItemsByMember(memberId);
                List <TenantSetting>     settings = DataManager.tenantDao.getTenantSetting(tenantId);
                Dictionary <string, int> type     = new Dictionary <string, int>();
                TenantMemLevel           level    = DataManager.tenantMemberDao.getMemberLevel(memberId);
                foreach (TenantSetting setting in settings)
                {
                    if (!string.IsNullOrEmpty(setting.content))
                    {
                        type.Add(TenantSettingMapping.getType(setting.title), int.Parse(setting.content));
                    }
                }

                //step1 統整可選運費的方式
                HashSet <string> shipList = new HashSet <string>();
                int  total       = 0;
                bool hasOnlyFree = false;

                foreach (ShopCartPrd item in items)
                {
                    total      += item.amount;
                    hasOnlyFree = hasOnlyFree || item.SpecialRule.Contains("單一件免運");

                    //if (item.face2faceSet.Contains(TenantSettingTAG.FACE))
                    //{
                    //    shipList.Add(TenantSettingTAG.FACE);
                    //}

                    if (item.shipType.Contains(TenantSettingTAG.FACE))
                    {
                        shipList.Add(TenantSettingTAG.FACE);
                    }

                    if (item.shipType.Contains(TenantSettingTAG.NOMAL))
                    {
                        shipList.Add(TenantSettingTAG.NOMAL);
                    }

                    if (item.shipType.Contains(TenantSettingTAG.COOL))
                    {
                        shipList.Add(TenantSettingTAG.COOL);
                    }
                }
                double discount = 1;
                if (level != null)
                {
                    discount = level.discount * 0.01;
                }

                double totalPrice = Math.Round(Convert.ToDouble(total) * discount, 0);
                //step2 整理運費方式及運費
                List <ShipMethod> methods = new List <ShipMethod>();
                int freePrice             = type.GetValueOrDefault(TenantSettingTAG.FACE);
                foreach (string method in shipList)
                {
                    if (type.ContainsKey(method))
                    {
                        if (method.Equals(TenantSettingTAG.FACE))
                        {
                            ShipMethod shipMethod = new ShipMethod();
                            shipMethod.method = method;
                            shipMethod.price  = 0;
                            methods.Add(shipMethod);
                        }
                        else
                        {
                            ShipMethod shipMethod = new ShipMethod();
                            shipMethod.method = method;
                            shipMethod.price  = totalPrice > freePrice || hasOnlyFree ? 0 : type.GetValueOrDefault(method);
                            methods.Add(shipMethod);
                        }
                    }
                }

                rm.code = MessageCode.SUCCESS;
                rm.data = methods;
            }
            catch (Exception e)
            {
                rm.code = MessageCode.ERROR;
                rm.data = e.Message;
            }
            return(Ok(rm));
        }