Esempio n. 1
0
        public bool TiXian(Order order, TipsFlow tf, string accountnm, string storename, decimal balance, int aid, string accountid, decimal tips, decimal point, out string msg)
        {
            CompanyPay.AliPay ali = new CompanyPay.AliPay();

            Aop.Api.Response.AlipayFundTransToaccountTransferResponse response = ali.GetCompanyPay(order.Out_trade_no, accountid, (order.Total_amount - tips).ToString(), storename, accountnm, order.Remark);
            CompanyPay.LogHelper.WriteLine(Jayrock.Json.Conversion.JsonConvert.ExportToString(response));

            CompanyPay.LogHelper.WriteLine(response.Body);


            #region MyRegion
            try
            {
                TakeList takelist = takelistapp.Repository.GetWhere(r => r.Out_trade_no == order.Out_trade_no).FirstOrDefault();
                order = Repository.Get(order.Id);
                if (response.Code == "10000")
                {
                    Account account = accountapp.Get(aid);
                    if (account == null)
                    {
                        throw new Exception("找不到该资金账户");
                    }
                    using (var tran = new TransactionScope())
                    {
                        if (point >= 1)
                        {
                            UnitWork.RegisterNew(new PointDetail()
                            {
                                FromType = order.PayType, Money = order.Total_amount, CreateTime = DateTime.Now.ToLocalTime(), IsActive = true, Point = point, StoreId = order.StoreNo, StoreName = storename, BuyerId = accountid
                            });
                        }

                        UnitWork.RegisterDirty(tf, () => new TipsFlow {
                            IsActive = true
                        });
                        UnitWork.RegisterDirty(takelist, () => new TakeList {
                            State = 1
                        });

                        order.Gmt_payment  = Convert.ToDateTime(response.PayDate);
                        order.Trade_status = response.Code;
                        order.IsSuccess    = 1;
                        order.Trade_no     = response.OrderId;
                        UnitWork.RegisterDirty <Order>(order);

                        account.Balance -= order.Total_amount;
                        account.TakeOut += order.Total_amount;
                        UnitWork.RegisterDirty <Account>(account);

                        UnitWork.Commit();
                        tran.Complete();
                    }
                }
                else
                {  //失败
                    using (var tran = new TransactionScope())
                    {
                        UnitWork.RegisterDirty(takelist, () => new TakeList {
                            State = 2
                        });

                        UnitWork.RegisterDirty <Order>(order, () => new Order()
                        {
                            Gmt_payment  = DateTime.Now,
                            Trade_status = response.Code,
                            IsSuccess    = 2,
                            Remark       = response.SubMsg + "【" + response.SubCode + "】",
                        });

                        UnitWork.Commit();
                        tran.Complete();
                    }
                }
                if (response.IsError)
                {
                    msg = response.SubMsg;
                    return(false);
                }
                else
                {
                    msg = response.Msg;
                    return(true);
                }
            }
            catch (Exception)
            {
                //记录这笔成功订单 写入JSON
                if (response.Code == "10000")
                {
                    string orderstr = response.Body;
                    orderstr  = orderstr.Substring(0, orderstr.LastIndexOf("sign") - 3).Replace("alipay_fund_trans_toaccount_transfer_response", "ResponseOrder");
                    orderstr += ",\"oid\":" + order.Id + ",\"tfid\":" + tf.Id + ",\"aid\":" + aid + ",\"point\":" + point + "}}";
                    OrderJson    orderjson = ConfigFactory.GetConfig <OrderJson>();
                    SuccessOrder resOrder  = Newtonsoft.Json.JsonConvert.DeserializeObject <SuccessOrder>(orderstr);
                    if (orderjson == null || orderjson.list == null)
                    {
                        orderjson      = new OrderJson();
                        orderjson.list = new List <SuccessOrder>();
                    }
                    orderjson.list.Add(new SuccessOrder {
                        ResponseOrder = resOrder.ResponseOrder
                    });
                    ConfigFactory.SetConfig <OrderJson>(orderjson);
                    msg = "支付成功,订单有误";
                }
                else
                {
                    msg = response.SubMsg;
                }
                return(false);
            }
            #endregion
        }
Esempio n. 2
0
        public bool TiXian(Order order, TipsFlow tf, string accountnm, string storename, decimal balance, int aid, int tfid, string accountid, decimal tips, decimal point, out string msg)
        {
            CompanyPay.AliPay ali = new CompanyPay.AliPay();

            Aop.Api.Response.AlipayFundTransToaccountTransferResponse response = ali.GetCompanyPay(order.Out_trade_no, accountid, (order.Total_amount - tips).ToString(), storename, accountnm, order.Remark);
            CompanyPay.LogHelper.WriteLine(Jayrock.Json.Conversion.JsonConvert.ExportToString(response));

            CompanyPay.LogHelper.WriteLine(response.Body);
            TakeList takelist = takelistapp.Repository.GetWhere(r => r.Out_trade_no == order.Out_trade_no).FirstOrDefault();

            order = Repository.Get(order.Id);
            if (response.Code == "10000")
            {
                Account  account  = accountapp.Get(aid);
                TipsFlow tipsflow = tipsflowapp.Get(tfid);
                if (account == null)
                {
                    throw new Exception("找不到该资金账户");
                }
                using (var tran = new TransactionScope())
                {
                    if (point >= 1)
                    {
                        UnitWork.RegisterNew(new PointDetail()
                        {
                            FromType = order.PayType, Money = order.Total_amount, CreateTime = DateTime.Now, IsActive = true, Point = point, StoreId = order.StoreNo, StoreName = storename, BuyerId = accountid
                        });
                    }

                    UnitWork.RegisterNew <TipsFlow>(tf);
                    UnitWork.RegisterDirty(takelist, () => new TakeList {
                        State = 1
                    });

                    order.Gmt_payment  = Convert.ToDateTime(response.PayDate);
                    order.Trade_status = response.Code;
                    order.IsSuccess    = 1;
                    order.Trade_no     = response.OrderId;
                    UnitWork.RegisterDirty <Order>(order);

                    account.Balance -= order.Total_amount;
                    account.TakeOut += order.Total_amount;
                    UnitWork.RegisterDirty <Account>(account);

                    UnitWork.Commit();
                    tran.Complete();
                }
            }
            else    //失败
            {
                using (var tran = new TransactionScope())
                {
                    UnitWork.RegisterDirty(takelist, () => new TakeList {
                        State = 2
                    });

                    UnitWork.RegisterDirty <Order>(order, () => new Order()
                    {
                        Gmt_payment  = DateTime.Now,
                        Trade_status = response.Code,
                        IsSuccess    = 2,
                        //order.Trade_no = "";
                        Remark = response.SubMsg + "【" + response.SubCode + "】",
                    });

                    UnitWork.Commit();
                    tran.Complete();
                }
            }
            if (response.IsError)
            {
                msg = response.SubMsg;
                return(false);
            }
            else
            {
                msg = response.Msg;
                return(true);
            }
        }
Esempio n. 3
0
        public bool TiXian(Order order, Collect collect, TipsFlow tf, string storename, decimal balance, int aid, int tfid, string accountid, decimal tips, out string msg)
        {
            CompanyPay.AliPay ali = new CompanyPay.AliPay();

            Aop.Api.Response.AlipayFundTransToaccountTransferResponse response = ali.GetCompanyPay(order.Out_trade_no, accountid, (order.Total_amount - tips).ToString(), storename, collect.Account, order.Remark);

            TakeList takelist = null;// takelistapp.Repository.GetWhere(r => r.Out_trade_no == order.Out_trade_no).FirstOrDefault();

            order = Repository.Get(order.Id);
            if (response.Code == "10000")
            {
                Account  account  = accountapp.Get(aid);
                TipsFlow tipsflow = tipsflowapp.Get(tfid);
                if (account == null)
                {
                    throw new Exception("找不到该资金账户");
                }
                using (var tran = new TransactionScope())
                {
                    UnitWork.RegisterNew <TipsFlow>(tf);
                    UnitWork.RegisterDirty(takelist, () => new TakeList {
                        State = 1
                    });

                    order.Gmt_payment  = Convert.ToDateTime(response.PayDate);
                    order.Trade_status = response.Code;
                    order.IsSuccess    = 1;
                    order.Trade_no     = response.OrderId;
                    UnitWork.RegisterDirty <Order>(order);

                    account.Balance -= order.Total_amount;
                    account.TakeOut += order.Total_amount;
                    UnitWork.RegisterDirty <Account>(account);

                    UnitWork.Commit();
                    tran.Complete();
                }
            }
            else    //失败
            {
                using (var tran = new TransactionScope())
                {
                    UnitWork.RegisterDirty(takelist, () => new TakeList {
                        State = 1
                    });
                    UnitWork.RegisterDirty(takelist, () => new TakeList {
                        State = 2
                    });

                    UnitWork.RegisterDirty <Order>(order, () => new Order()
                    {
                        Gmt_payment  = DateTime.Now,
                        Trade_status = response.Code,
                        IsSuccess    = 2,
                        //order.Trade_no = "";
                        Remark = response.SubMsg + "【" + response.SubCode + "】",
                    });

                    UnitWork.Commit();
                    tran.Complete();
                }
            }
            if (response.IsError)
            {
                msg = response.SubMsg;
                return(false);
            }
            else
            {
                msg = response.Msg;
                return(true);
            }
        }