Ejemplo n.º 1
0
        public void SaveToStoredValueCard(string cardNo, decimal amount, decimal balance)
        {
            string key         = KeyFactory.MachineKeyFactory(CompanyId, StoreId, MachineSN, DeviceSn);
            var    machineInfo = Salesclerk.onlineCache.Get(key);

            if (machineInfo == null)
            {
                throw new PosException("未能找到收银员信息,请重新登陆!");
            }
            var shoppingCart = ShoppingCartFactory.Factory(StoreId, MachineSN, CompanyId, DeviceSn);
            var cardinfo     = MembershipCardService.CurrentRepository.Entities.FirstOrDefault(o => o.CardSN == cardNo && o.CompanyId == CompanyId);

            if (cardinfo != null)
            {
                cardinfo.Balance = balance;
                MembershipCardService.CurrentRepository.Update(cardinfo, false);
                Pharos.Logic.BLL.BaseGeneralService <Pharos.Logic.Entity.StoredValueCardPayRecord, Pharos.Logic.DAL.EFDbContext> .CurrentRepository.Add(new StoredValueCardPayRecord()
                {
                    Amount    = amount,
                    CardNo    = cardNo,
                    CompanyId = CompanyId,
                    CreateDT  = DateTime.Now,
                    OrderSn   = shoppingCart.OrderSN,
                    StoreId   = StoreId,
                    CreateUID = machineInfo.CashierUid,
                    Balance   = balance
                });
            }
            else
            {
                throw new PosException(string.Format("未找到储值卡{0}!", cardNo));
            }
        }
Ejemplo n.º 2
0
        public object SetActivityId(SetActivityRequest requestParams)
        {
            var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);

            shoppingcart.SetActivityId(requestParams.ActivityId);
            ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            return(null);
        }
Ejemplo n.º 3
0
        public SuspendList RemoveHandBill([FromBody] HandBillRequest requestParams)
        {
            var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            var result       = SaleSuspend.Remove(shoppingcart, requestParams.OrderSn);

            ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            return(result);
        }
Ejemplo n.º 4
0
        public MemberInfo SetMember(SetMemberRequest requestParams)
        {
            var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            var memnerInfo   = shoppingcart.SetMember(requestParams.CardNo, requestParams.Phone, requestParams.To);

            ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            return(memnerInfo);
        }
Ejemplo n.º 5
0
        public static DateTime RefundAll(string storeId, string machineSn, int companyId, int reason, string paySn, decimal amount, string deviceSn, IPay pay, DateTime createdt)
        {
            var customOrderSn = new Pharos.Infrastructure.Data.Normalize.PaySn(companyId, storeId, machineSn);
            var dataAdapter   = DataAdapterFactory.Factory(MachinesSettings.Mode, storeId, machineSn, companyId, deviceSn);
            var shoppingcart  = ShoppingCartFactory.Factory(storeId, machineSn, companyId, deviceSn);
            var uid           = shoppingcart.MachineInformation.CashierUid;
            var datetime      = dataAdapter.RefundAll(reason, paySn, amount, uid, pay.ApiCodes, pay.PayDetails.PaySn, customOrderSn.ToString(), createdt);

            customOrderSn.NextSerialNumber();
            return(datetime);
        }
Ejemplo n.º 6
0
        public DateTime SaveRecord(string storeId, string machineSn, int companyId, int reason, decimal amount, decimal receive, IPay pay, string deviceSn)
        {
            var      dataAdapter  = DataAdapterFactory.Factory(MachinesSettings.Mode, storeId, machineSn, companyId, deviceSn);
            var      shoppingcart = ShoppingCartFactory.Factory(storeId, machineSn, companyId, deviceSn);
            var      uid          = shoppingcart.MachineInformation.CashierUid;
            string   apiCodes     = pay != null ? pay.ApiCodes : "-1";
            DateTime saveTime     = pay != null ? pay.PayDetails.CreateDt : DateTime.Now;
            var      orderTime    = dataAdapter.ChangeOrRefund(this, reason, shoppingcart.MachineInformation, this.CustomOrderSn, amount, receive, uid, apiCodes, saveTime, this.SaleMan, this.OldOrderSn);

            new Pharos.Infrastructure.Data.Normalize.PaySn(companyId, storeId, machineSn).NextSerialNumber();
            return(orderTime);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 验证用户登录
        /// </summary>
        /// <param name="userParams">登录参数</param>
        /// <returns></returns>
        public static LoginResult Login(LoginParams userParams, string deviceSn, bool inTestMode = false, bool isLock = false)
        {
            var dataAdapter = DataAdapterFactory.Factory(MachinesSettings.Mode, userParams.StoreId, userParams.MachineSn, userParams.CompanyId, deviceSn);
            var userInfo    = dataAdapter.GetUser(userParams.Account);

            if (userInfo == null)
            {
                throw new LoginExecption("401", "账号错误!");
            }
            if (userInfo.LoginPwd != MD5.MD5Encrypt(userParams.Password))
            {
                throw new LoginExecption("401", "密码错误!");
            }
            //本店角色(1:店长、2:营业员、3:收银员、4:数据维护),格式:门店ID,角色ID|门店ID,角色ID
            if (!inTestMode && !(VerfyOperateAuth(userInfo, dataAdapter.StoreId, StoreOperateAuth.Cashier) || VerfyOperateAuth(userInfo, dataAdapter.StoreId, StoreOperateAuth.DataManager)))
            {
                throw new LoginExecption("402", "非销售员或数据维护员不允许登录销售!");
            }
            var key         = KeyFactory.MachineKeyFactory(userParams.CompanyId, userParams.StoreId, userParams.MachineSn, deviceSn);
            var machineInfo = new MachineInformation()
            {
                CashierName        = userInfo.FullName,
                CashierOperateAuth = userInfo.OperateAuth,
                CashierUid         = userInfo.UID,
                CashierUserCode    = userInfo.UserCode,
                StoreName          = userInfo.StoreName,
                StoreId            = userParams.StoreId,
                MachineSn          = userParams.MachineSn,
                CompanyId          = userParams.CompanyId,
                InTestMode         = inTestMode,
                DeviceSn           = deviceSn
            };

            onlineCache.Set(key, machineInfo);
#if (Local != true)
            RedisManager.Publish("SyncOnlineCache", JsonConvert.SerializeObject(machineInfo));
#endif
#if (Local)
            StoreManager.PubEvent("SyncOnlineCache", JsonConvert.SerializeObject(machineInfo));
#endif
            if (!isLock)
            {
                ShoppingCartFactory.Factory(userParams.StoreId, userParams.MachineSn, userParams.CompanyId, deviceSn, true);
            }
            return(new LoginResult()
            {
                FullName = userInfo.FullName,
                OperateAuth = userInfo.OperateAuth,
                UserCode = userInfo.UserCode,
                StoreName = userInfo.StoreName
            });
        }
Ejemplo n.º 8
0
        public OrdersDetails ClearOrder([FromBody] MachineInfo requestParams)
        {
            var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);

            shoppingcart.Clear();
            var result = new OrdersDetails()
            {
                BuyList    = shoppingcart.GetBuyList(),
                Gifts      = new List <GiftResult>(),
                Statistics = shoppingcart.GetSaleStatistics()
            };

            ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            return(result);
        }
Ejemplo n.º 9
0
        public OrdersDetails SaleOrderEnableMarketing([FromBody] SaleEnableMarketingRequest requestParams)
        {
            var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);

            shoppingcart.EnableRangeMarketings = requestParams.EnableRangeMarketings;
            var result = new OrdersDetails()
            {
                BuyList    = shoppingcart.GetBuyList(),
                Gifts      = new List <GiftResult>(),
                Statistics = shoppingcart.GetSaleStatistics()
            };

            ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            return(result);
        }
Ejemplo n.º 10
0
        public OrdersDetails ReadHandBill([FromBody] HandBillRequest requestParams)
        {
            var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            var barcodes     = SaleSuspend.Read(shoppingcart, requestParams.OrderSn);

            shoppingcart.RunMarketings();
            var result = new OrdersDetails()
            {
                BuyList    = shoppingcart.GetBuyList(),
                Gifts      = new List <GiftResult>(),
                Statistics = shoppingcart.GetSaleStatistics()
            };

            ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            return(result);
        }
Ejemplo n.º 11
0
        public OrdersDetails SaleOrderRemove([FromBody] SaleRemoveRequest requestParams)
        {
            var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);

            shoppingcart.Remove(requestParams.Barcode, requestParams.Status, requestParams.HasEditPrice, requestParams.RecordId);
            shoppingcart.RunMarketings();
            var result = new OrdersDetails()
            {
                BuyList    = shoppingcart.GetBuyList(),
                Gifts      = new List <GiftResult>(),
                Statistics = shoppingcart.GetSaleStatistics()
            };

            ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            return(result);
        }
Ejemplo n.º 12
0
        public OrdersDetails HandBill([FromBody] HandBillRequest requestParams)
        {
            var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);

            if (shoppingcart.RecordCount == 0)
            {
                throw new PosException("订单列表为空不能挂单!");
            }
            SaleSuspend.Suspend(shoppingcart);
            var result = new OrdersDetails()
            {
                BuyList    = shoppingcart.GetBuyList(),
                Gifts      = new List <GiftResult>(),
                Statistics = shoppingcart.GetSaleStatistics()
            };

            ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
            return(result);
        }
Ejemplo n.º 13
0
        public object RequestPay()
        {
            var shoppingCart = ShoppingCartFactory.Factory(StoreId, MachineSn, CompanyId, DeviceSn);

            lock (SwiftNumber.LockObject)
            {
                var ordersn = new PayOrderSn(CompanyId, StoreId);
                shoppingCart.PayOrderSn = ordersn.ToString();
                ShoppingCartFactory.ResetCache(shoppingCart, StoreId, MachineSn, CompanyId, DeviceSn);
            }
            var p = GetRongHeDynamicQRCodePayRequestParameter(CompanyId, StoreId, MachineSn, shoppingCart.PayOrderSn, PayDetails.Amount, PayDetails.CardNo);

            RequestPayDate = DateTime.Now;
            var RongHeDynamicQRCodePayUrl = Path.Combine(ConfigurationManager.AppSettings["RongHeDynamicQRCodePay"].ToString(), "api/pay/scanpay");

            if (string.IsNullOrEmpty(RongHeDynamicQRCodePayUrl))
            {
                throw new PosException("支付配置不完整,无法完成支付!");
            }
            return(PostPay(RongHeDynamicQRCodePayUrl, p));
        }
Ejemplo n.º 14
0
        public ThirdPartyPaymentStatus GetPayStatus()
        {
            var payConfig = BaseGeneralService <Pharos.Logic.Entity.PayConfiguration, EFDbContext> .Find(o => o.CompanyId == CompanyId && o.PayType == 25);

            var ordersn = ShoppingCartFactory.Factory(StoreId, MachineSn, CompanyId, DeviceSn).PayOrderSn;
            var storePaymentAuthorization = BaseGeneralService <Pharos.Logic.Entity.StorePaymentAuthorization, EFDbContext> .Find(o => o.CompanyId == CompanyId && o.PayType == 25 && o.StoreId == StoreId);

            var mic    = int.Parse(payConfig.PaymentMerchantNumber);
            var entity = PayNotifyResultService.Find(o => o.ApiCode == 25 && o.PaySN == ordersn && o.CompanyId == mic);

            if (entity == null)
            {
                return(ThirdPartyPaymentStatus.Unknown);
            }
            else if (entity.State == "PAYSUCCESS")
            {
                return(ThirdPartyPaymentStatus.Complete);
            }
            else
            {
                return(ThirdPartyPaymentStatus.Error);
            }
        }
Ejemplo n.º 15
0
        public SaleManInfo SetSaleMan([FromBody] SetSaleManRequest requestParams)
        {
            switch (requestParams.Source)
            {
            case 0:
            {
                var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
                var result       = shoppingcart.SetSaleMan(requestParams.SaleMan);
                ShoppingCartFactory.ResetCache(shoppingcart, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
                return(result);
            }

            case 1:
            case 2:
            {
                var orderChangeRefund = OrderChangeFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.Mode, requestParams.DeviceSn);
                var result            = orderChangeRefund.SetSaleMan(requestParams.SaleMan, requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
                return(result);
            }

            default:
                throw new PosException("未能设置导购员,请重试!");
            }
        }
Ejemplo n.º 16
0
        public object Pay([FromBody] PayRequest requestParams)
        {
            if (requestParams == null || requestParams.Payway == null || requestParams.Payway.Count() == 0)
            {
                throw new PosException("未知支付方式!");
            }
            string key = string.Format("{0}-{1}-{2}-{3}", requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);

            lock (lockobjforadd)
            {
                if (!lockobjs.ContainsKey(key))
                {
                    lockobjs = lockobjs.ToList().Concat(new List <KeyValuePair <string, object> >()
                    {
                        new KeyValuePair <string, object>(key, new object())
                    }).ToDictionary(o => o.Key, o => o.Value);
                }
            }
            var    dict    = lockobjs;//防止并发
            var    lockkv  = dict.First(o => o.Key == key);
            object lockobj = new object();

            if (!lockkv.Equals(default(KeyValuePair <string, object>)) && lockkv.Value != null)
            {
                lockobj = lockkv.Value;
            }

            DateTime createDt = DateTime.Now;

            lock (lockobj)
            {
                switch (requestParams.Mode)
                {
                case PayAction.RefundAll:    //退单
                    return(DoPay(requestParams.CID, requestParams.StoreId, requestParams.MachineSn, requestParams.DeviceSn, Guid.NewGuid().ToString("N"), requestParams, createDt, (o) =>
                    {
                        OrderChangeRefundSale.RefundAll(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.Reason, requestParams.OldOrderSn, requestParams.OrderAmount, requestParams.DeviceSn, o, createDt);
                    }));

                case PayAction.Refund:    //退货
                    var orderRefund = OrderChangeFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, AfterSaleMode.Refunding, requestParams.DeviceSn);
                    return(DoPay(requestParams.CID, requestParams.StoreId, requestParams.MachineSn, requestParams.DeviceSn, orderRefund.PaySn, requestParams, createDt, (o) =>
                    {
                        orderRefund.SaveRecord(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.Reason, requestParams.OrderAmount, requestParams.Receivable, o, requestParams.DeviceSn);
                    }));

                case PayAction.Change:    //换货支付
                    var orderChange = OrderChangeFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, AfterSaleMode.Changing, requestParams.DeviceSn);
                    return(DoPay(requestParams.CID, requestParams.StoreId, requestParams.MachineSn, requestParams.DeviceSn, orderChange.PaySn, requestParams, createDt, (o) =>
                    {
                        orderChange.SaveRecord(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.Reason, requestParams.OrderAmount, requestParams.Receivable, o, requestParams.DeviceSn);
                    }));

                case PayAction.Sale:    //销售支付

                    var shoppingcart = ShoppingCartFactory.Factory(requestParams.StoreId, requestParams.MachineSn, requestParams.CID, requestParams.DeviceSn);
                    var orderList    = shoppingcart.GetOrdeList();
                    if (orderList == null || orderList.Count() == 0)
                    {
                        throw new PosException("该商品已结算,遇到网络异常,请手动按 Q 清空购物车!");
                    }
                    try
                    {
                        return(DoPay(requestParams.CID, requestParams.StoreId, requestParams.MachineSn, requestParams.DeviceSn, shoppingcart.OrderSN, requestParams, createDt, (o) =>
                        {
                            shoppingcart.Record(o.ApiCodes, requestParams.OrderAmount, requestParams.Receivable, requestParams.DeviceSn, createDt);
                        }));
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
            }
            return(createDt);
        }