public async Task <IActionResult> Edit(int id, [Bind("OrderDid,Quantity,Price,OrderId,ReceiveId")] TOrderDetail tOrderDetail)
        {
            if (id != tOrderDetail.OrderDid)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tOrderDetail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TOrderDetailExists(tOrderDetail.OrderDid))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.TOrder, "OrderId", "OrderId", tOrderDetail.OrderId);
            ViewData["ReceiveId"] = new SelectList(_context.TReceive, "ReceiveId", "ReceiveId", tOrderDetail.ReceiveId);
            return(View(tOrderDetail));
        }
Exemplo n.º 2
0
 public OrderDetailsViewModel()
 {
     iv_orderDetails = new TOrderDetail();
     iv_member       = new TMember();
     iv_orderStatus  = new TOrderStatus();
     iv_product      = new TProduct();
 }
Exemplo n.º 3
0
 public OrderDetailsViewModel(TOrderDetail orderDetail, TMember member, TOrderStatus orderStatus, TProduct product)
 {
     orderDetail = iv_orderDetails;
     member      = iv_member;
     orderStatus = iv_orderStatus;
     product     = iv_product;
 }
Exemplo n.º 4
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns>返回:该条数据的主键Id</returns>
        public int Insert(TOrderDetail obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            String stmtId = "TOrderDetail.Insert";

            return(SqlMapper.Instance().QueryForObject <int>(stmtId, obj));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>返回:ture 成功,false 失败</returns>
        public bool Update(TOrderDetail obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            String stmtId = "TOrderDetail.Update";
            int    result = SqlMapper.Instance().QueryForObject <int>(stmtId, obj);

            return(result > 0 ? true : false);
        }
        public async Task <IActionResult> Create([Bind("OrderDid,Quantity,Price,OrderId,ReceiveId")] TOrderDetail tOrderDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tOrderDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["OrderId"]   = new SelectList(_context.TOrder, "OrderId", "OrderId", tOrderDetail.OrderId);
            ViewData["ReceiveId"] = new SelectList(_context.TReceive, "ReceiveId", "ReceiveId", tOrderDetail.ReceiveId);
            return(View(tOrderDetail));
        }
Exemplo n.º 7
0
        public bool gotoblack(int?id)
        {
            TOrderDetail table = db.TOrderDetails.FirstOrDefault(n => n.COrderDetailId == id);
            bool         x     = true;

            if (table != null)
            {
                if (table.CFeedBackStatus == 1)
                {
                    table.CFeedBackStatus = 0;
                }
                else
                {
                    table.CFeedBackStatus = 1;
                    x = false;
                }
            }
            db.SaveChanges();
            return(x);
        }
Exemplo n.º 8
0
 public void DetailBoardDelete([FromBody] List <yupushstrViewModel> Array)
 {
     if (Array != null)
     {
         擺腹BuyFoodContext db = new 擺腹BuyFoodContext();
         for (int i = 0; i < Array.Count; i++)
         {
             TOrderDetail table = db.TOrderDetails.FirstOrDefault(a => a.COrderDetailId.ToString() == Array[i].strmember);
             if (table != null)
             {
                 if (table.CFeedBackStatus == 1)
                 {
                     table.CFeedBackStatus = 0;
                 }
                 else
                 {
                     table.CFeedBackStatus = 1;
                 }
             }
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 9
0
        public Task <ResultWrapper <CustomerCreatePaymentSessionOutput> > Handle(CustomerCreatePaymentSessionCommand request, CancellationToken cancellationToken)
        {
            ResultWrapper <CustomerCreatePaymentSessionOutput> result = new ResultWrapper <CustomerCreatePaymentSessionOutput>();

            try
            {
                using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    TUser tUser = _dbContext.TUser.FirstOrDefault(x => x.FireBaseId == request.firebaseId);
                    if (tUser == null)
                    {
                        result.Status  = false;
                        result.Message = "cannot find customer!";
                        return(Task.FromResult(result));
                    }

                    if (!request.OrderItems.Any())
                    {
                        result.Status  = false;
                        result.Message = "invalid foods data!";
                        return(Task.FromResult(result));
                    }

                    TUser tSupplier = _dbContext.TFood
                                      .Include(x => x.TUser)
                                      .FirstOrDefault(x => x.Id == request.OrderItems.First().FoodId)?.TUser;
                    if (tSupplier == null)
                    {
                        result.Status  = false;
                        result.Message = "cannot find supplier!";
                        return(Task.FromResult(result));
                    }

                    string generatedCode   = "";
                    string generatedTitle  = "";
                    Guid   PaymentUniqueId = Guid.NewGuid();

                    TOrder tOrder = new TOrder()
                    {
                        Enabled           = true,
                        Code              = generatedCode,
                        Created           = DateTime.Now,
                        Date              = DateTime.Now,
                        Title             = generatedTitle,
                        TrackingCode      = PaymentUniqueId.ToString(),
                        TSupplierId       = tSupplier.Id,
                        TUserId           = tUser.Id,
                        TotalPayablePrice = 0,
                        Submited          = false
                    };
                    _dbContext.TOrder.Add(tOrder);
                    _dbContext.SaveChanges();

                    decimal TotalPayablePrice = 0;
                    foreach (var detail in request.OrderItems)
                    {
                        TFood food = _dbContext.TFood
                                     .FirstOrDefault(x => x.Id == detail.FoodId);

                        if (food == null)
                        {
                            result.Status  = false;
                            result.Message = "invalid food data!";
                            return(Task.FromResult(result));
                        }
                        TOrderDetail tOrderDetail = new TOrderDetail()
                        {
                            Enabled   = true,
                            Created   = DateTime.Now,
                            Amount    = detail.Amount,
                            TFoodId   = food.Id,
                            TUserId   = tSupplier.Id,
                            UnitPrice = food.Price,
                            RowPrice  = food.Price * detail.Amount,
                            TOrderId  = tOrder.Id
                        };
                        TotalPayablePrice += tOrderDetail.RowPrice;
                        _dbContext.TOrderDetail.Add(tOrderDetail);
                    }
                    _dbContext.SaveChanges();

                    tOrder.TotalPayablePrice = TotalPayablePrice;
                    _dbContext.TOrder.Update(tOrder);
                    _dbContext.SaveChanges();

                    string   SuccessUrl = request.SuccessUrl + "?UID=" + PaymentUniqueId;
                    TPayment tPayment   = new TPayment()
                    {
                        UniqueId = PaymentUniqueId,
                        UserId   = tUser.Id,
                        Amount   = TotalPayablePrice,
                        OrderId  = tOrder.Id,
                        Success  = false,
                        Used     = false,
                        Enabled  = true,
                        Created  = DateTime.Now,
                    };
                    _dbContext.TPayment.Add(tPayment);
                    _dbContext.SaveChanges();

                    transaction.Complete();

                    string secretKey = "sk_test_51JKejjB9j2pHQUNgVymkcotBwOhw64UhTOxrOWLn6QzpdIqmUOGh0lJCkozGMgWNLYQcg4XKriYmiNjfDRiwujnV00Lv2iKYgC";
                    StripeConfiguration.ApiKey = secretKey;
                    var options = new SessionCreateOptions()
                    {
                        PaymentMethodTypes = new List <String>()
                        {
                            "card"
                        },
                        LineItems = new List <SessionLineItemOptions>()
                        {
                        },
                        PaymentIntentData = new SessionPaymentIntentDataOptions()
                        {
                            ApplicationFeeAmount = 500,
                            TransferData         = new SessionPaymentIntentDataTransferDataOptions()
                            {
                                Destination = "acct_1JL9JuPUzKlkrnDH"
                            }
                        },
                        Mode       = "payment",
                        SuccessUrl = SuccessUrl,
                        CancelUrl  = request.CancelUrl
                    };
                    foreach (var item in request.OrderItems)
                    {
                        options.LineItems.Add(new SessionLineItemOptions()
                        {
                            Quantity  = item.Amount,
                            PriceData = new SessionLineItemPriceDataOptions()
                            {
                                Currency    = "usd",
                                UnitAmount  = item.Price,
                                ProductData = new SessionLineItemPriceDataProductDataOptions()
                                {
                                    Name = item.FoodId.ToString()
                                }
                            }
                        });
                    }
                    var            service = new SessionService();
                    Task <Session> session = service.CreateAsync(options);
                    session.Wait();
                    result = new ResultWrapper <CustomerCreatePaymentSessionOutput>()
                    {
                        Status = true,
                        Result = new CustomerCreatePaymentSessionOutput()
                        {
                            SessionId  = session.Result.Id,
                            SessionUrl = session.Result.Url
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
            }
            return(Task.FromResult(result));
        }
Exemplo n.º 10
0
        public void DoExchange(
            int accountType, string accountName, string accountNo, int amount, int exchangeAccId,
            string bankName, string provinceName, string areaName, int?provinceId, int?areaId
            )
        {
            try
            {
                #region 参数检测
                if (string.IsNullOrEmpty(accountName))
                {
                    throw new TmmException("账户名不能为空");
                }
                if (string.IsNullOrEmpty(accountNo))
                {
                    throw new TmmException("账号不能为空");
                }
                if (amount == 0)
                {
                    throw new TmmException("兑换金额不能为0");
                }
                int toExchange = (int)Helper.FormatHelper.ExchangeValue(amount);
                if (toExchange == 0 || toExchange % ConfigHelper.MinExchange != 0)
                {
                    throw new TmmException("兑换金额只能为" + ConfigHelper.MinExchange.ToString() + "的倍数");
                }

                #endregion
                OrderService os = Context.GetService <OrderService>();
                U_UserInfo   u  = base.GetUser();
                if (exchangeAccId == 0)
                {
                    //新增兑换账户ID
                    ExchangeAccount ea = new ExchangeAccount()
                    {
                        AccountName  = accountName,
                        AccountNo    = accountNo,
                        AccountType  = accountType,
                        AreaId       = areaId,
                        AreaName     = areaName,
                        BankName     = bankName,
                        ProvinceId   = provinceId,
                        ProvinceName = provinceName,
                        CreateTime   = DateTime.Now,
                        UserId       = u.UserId
                    };
                    exchangeAccId = os.ExchangeAccountBll.Insert(ea);
                }
                else
                {
                    //更新账户信息
                    ExchangeAccount oldEa = os.ExchangeAccountBll.Get(exchangeAccId);
                    oldEa.AccountName  = accountName;
                    oldEa.AccountNo    = accountNo;
                    oldEa.AreaId       = areaId;
                    oldEa.AreaName     = areaName;
                    oldEa.ProvinceId   = provinceId;
                    oldEa.ProvinceName = provinceName;
                    oldEa.BankName     = bankName;
                    os.ExchangeAccountBll.Update(oldEa);
                    //如果因为用户自己更改了兑换账户信息而可能产生的纠纷,管理员在后台处理的时候需要把相关账户信息写进管理员备注
                }

                //冻结账户部分余额
                os.MAccountBll.FrozenSomeAmount(amount, u.UserId);
                //生成订单
                decimal      orderId = Utils.TmmUtils.GenOrderId();
                TOrderDetail detail  = new TOrderDetail()
                {
                    DocId      = -2, //-2代表兑换,-1代表直接充值
                    DocTitle   = "兑换:" + amount.ToString(),
                    GoodsCount = 1,
                    Price      = amount,
                    OrderId    = orderId
                };
                TOrder o = new TOrder()
                {
                    CreateTime    = DateTime.Now,
                    Email         = u.Email,
                    ExchangeAccId = exchangeAccId,
                    Ip            = Utils.TmmUtils.IPAddress(),
                    OrderDetails  = new List <TOrderDetail>()
                    {
                        detail
                    },
                    OrderId   = orderId,
                    OrderType = (int)OrderType.Exchange,
                    PayWay    = 0,
                    Remark    = accountType.ToString(), //此处备注字段用户保存是支付宝兑换,还是银行账户兑换
                    Status    = (int)OrderStatus.FrozenSomeAmount,
                    Total     = amount,
                    UserId    = u.UserId,
                    //把生成订单时填写的账户信息写入管理员备注
                    AdminRemark = string.Format("户名:【{0}】,账号:【{2}{1}】", accountName, accountNo, bankName + ",")
                };
                os.TOrderBll.SaveOrder(o);
                Flash["exchangeResult"] = true;
            }
            catch (TmmException te) {
                AddError(te.Message);
            }
            Redirect("Exchange.do");
        }
Exemplo n.º 11
0
        public JsonResult newOrder()
        {
            擺腹BuyFoodContext db = new 擺腹BuyFoodContext();

            int[] memberBox = new int[]
            {
                11, 17, 21, 30, 31
            };
            string[] addressBox = new string[]
            {
                "106台北市大安區復興南路一段303號9樓",
                "106台北市大安區信義路三段147巷11弄1號1樓",
                "106台北市大安區瑞安街31巷1號",
                "106台北市大安區通安街115號",
                "106台北市大安區新生南路二段50號",
                "105台北市松山區敦化北路199號",
                "106台北市大安區忠孝東路四段77巷28號",
                "104台北市中山區市民大道三段143號",
                "106台北市大安區安和路二段92號B1F",
                "106台北市大安區復興南路二段102號",
                "106台北市大安區仁愛路三段26-5號",
                "106台北市大安區建國南路二段231號",
                "106台北市大安區通安街115號",
                "106台北市大安區新生南路二段50號",
                "105台北市松山區敦化北路199號",
                "110台北市信義區信義路五段1號",
                "106台北市大安區光復南路180巷11號",
            };
            string[] dateBox = new string[]
            {
                "2021/01/01 10:10:10",
                "2021/02/01 10:10:10",
                "2021/03/01 10:10:10",
                "2021/04/01 10:10:10",
                "2020/01/01 10:10:10",
                "2020/02/01 10:10:10",
                "2020/03/01 10:10:10",
                "2020/04/01 10:10:10",
                "2020/05/01 10:10:10",
                "2020/06/01 10:10:10",
                "2020/07/01 10:10:10",
                "2020/08/01 10:10:10",
                "2020/09/01 10:10:10",
                "2020/10/01 10:10:10",
                "2020/11/01 10:10:10",
                "2020/12/01 10:10:10",
            };

            Random random     = new Random();
            var    productBox = db.TProducts.ToList();

            for (int i = 0; i < 2000; i++)
            {
                TOrder order = new TOrder()
                {
                    CMemberId        = memberBox[random.Next(0, 3)],
                    COrderStatusId   = 2,
                    CCuponId         = 1,
                    CArrivedAddress  = addressBox[random.Next(0, 8)],
                    CPayTypeId       = 1,
                    COrderDate       = dateBox[random.Next(0, dateBox.Count())],
                    CTransportMinute = random.Next(5, 30)
                };
                db.TOrders.Add(order);
                db.SaveChanges();

                var orderdetailCount = random.Next(1, 6);
                for (int p = 0; p < orderdetailCount; p++)
                {
                    var          productID = productBox[random.Next(0, productBox.Count())].CProductId;
                    TOrderDetail od        = new TOrderDetail()
                    {
                        CProductId      = productID,
                        COrderId        = order.COrderId,
                        CQuantity       = random.Next(1, 4),
                        CPriceAtTheTime = productBox.First(n => n.CProductId == productID).CPrice,
                    };
                    db.TOrderDetails.Add(od);
                }
            }
            db.SaveChanges();

            return(Json("done"));
        }
Exemplo n.º 12
0
        public void GotoPay(string PayWay, decimal total, string pname, int docId, int chargeType)
        {
            OrderService   os        = Context.GetService <OrderService>();
            AccountService accs      = Context.GetService <AccountService>();
            U_UserInfo     logonUser = base.GetUser();
            decimal        orderId   = Utils.TmmUtils.GenOrderId();

            DDocInfo     doc    = new DDocInfo();
            TOrder       order  = new TOrder();
            TOrderDetail detail = new TOrderDetail();

            int orderType = 0;  //订单类型

            if (chargeType == 1)
            {
                doc       = os.DDocInfoBll.Get(docId);
                orderType = (int)OrderType.DownDocOrder;
            }
            else if (chargeType == 0)
            {
                //如果是直接充值,这里虚拟一个doc对象,来作为订单的商品
                doc = new DDocInfo()
                {
                    DocId = -1,
                    Title = "直接充值:" + total.ToString(),
                    Price = total
                };
                orderType = (int)OrderType.DirectCharge;
            }


            detail = new TOrderDetail()
            {
                DocId      = doc.DocId,
                DocTitle   = doc.Title,
                GoodsCount = 1,
                Price      = doc.Price,
                OrderId    = orderId
            };
            order = new TOrder()
            {
                OrderType    = orderType,
                OrderId      = orderId,
                UserId       = logonUser.UserId,
                Email        = logonUser.Email,
                Total        = detail.Price * detail.GoodsCount,
                Ip           = Context.Request.UserHostAddress,
                Status       = (int)OrderStatus.NewOrder,
                CreateTime   = DateTime.Now,
                PayWay       = Helper.FormatHelper.GetPayWay(PayWay),
                OrderDetails = new List <TOrderDetail>()
                {
                    detail
                }
            };
            os.TOrderBll.SaveOrder(order);



            TOrder o = os.TOrderBll.Get(orderId);


            decimal amount = 0;//除扣除账户余额外还需要支付金额

            amount = total;

            //if (total > minfo.Amount)
            //{
            //    amount = total - minfo.Amount;
            //}
            //else {
            //    //账户支付
            //}

            #region 转至支付接口
            if (PayWay.ToLower() == "tenpay")
            {
                TenPay pay = new TenPay();
                pay.UserId = logonUser.UserId;
                pay.Send(orderId.ToString(), amount.ToString(), pname);
            }

            if (PayWay.ToLower() == "chinabank")
            {
                ChinaBankPay pay = new ChinaBankPay();
                pay.Send(orderId.ToString(), amount.ToString(), pname);

                // Response.Write("ChinaBank");
            }
            if (PayWay.ToLower() == "alipay")
            {
                AliPay pay = new AliPay();
                pay.Send(orderId.ToString(), amount.ToString(), pname, logonUser.UserId);

                // Response.Write("ChinaBank");
            }
            if (PayWay.ToLower() == "useraccount")
            {
                MAccount minfo = accs.MAccountBll.GetByUserId(logonUser.UserId);    //账户

                if (o.Total <= minfo.Amount && (o.Status == (int)OrderStatus.NewOrder))
                {
                    //ms.MAccount.AccountExpend(o.OrderId);
                    ////ms.MOrder.UpdateOrder2Paid(o.OrderId, 0, "账户支付", (int)Models.MOrderStateInfo.己付款);
                    //Web.Common.OrderCallBack oCallBack = new MamShare.Mall.Web.Common.OrderCallBack(
                    //            o.UserId, o.OrderId, 0, (int)Models.MOrderStateInfo.己付款, "账户支付");
                    //oCallBack.Update2Paid();

                    //Hashtable p = new Hashtable();
                    //p.Add("OrderId", o.OrderId);
                    //RedirectToAction("payok.do", p);
                    os.MAccountBll.AccountExpend(o.OrderId, Utils.TmmUtils.IPAddress());    //账户花销
                    Common.OrderCallBack oCallBack = new TMM.Core.Common.OrderCallBack();
                    oCallBack.UserId    = o.UserId;
                    oCallBack.OrderId   = o.OrderId;
                    oCallBack.PayWay    = 0;
                    oCallBack.Status    = (int)OrderStatus.IsPaied;
                    oCallBack.PayDetail = "账户支付";
                    oCallBack.GotoUrl   = "/my/purchase.do";

                    oCallBack.ExecAfterPaid();
                }
                else
                {
                    Redirect("NetPay.do?orderid=" + o.OrderId);
                }
            }
            #endregion
            RenderView("pay");
        }
Exemplo n.º 13
0
 /// <summary>
 /// 更新数据
 /// </summary>
 /// <param name="obj"></param>
 /// <returns>返回:ture 成功,false 失败</returns>
 public bool Update(TOrderDetail obj)
 {
     return(dal.Update(obj));
 }
Exemplo n.º 14
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="obj">对象</param>
 /// <returns>返回:该条数据的主键Id</returns>
 public int Insert(TOrderDetail obj)
 {
     return(dal.Insert(obj));
 }
Exemplo n.º 15
0
        public string InsertOrderToDB([FromBody] CartOrderJson CartOrder)
        {
            if (CartOrder == null)
            {
                return("購物車內尚無任何商品");
            }
            擺腹BuyFoodContext BuyFoodDB = new 擺腹BuyFoodContext();

            //檢查訂單內的商品數量是否小於現有庫存
            foreach (var i in CartOrder.cartOrder)
            {
                var quantity = BuyFoodDB.TProducts.Where(x => x.CProductId == i.cProductId).FirstOrDefault();
                if (i.QuantityInCart > quantity.CQuantity)
                {
                    return("已超過現有可製作的份量");
                }
            }
            int GetMemberID = int.Parse(HttpContext.Session.GetString(CDictionary.CURRENT_LOGINED_USERID));
            //檢查會員的餘額是否足夠付款
            decimal TotalPriceInCart = 0;

            foreach (var i in CartOrder.cartOrder)
            {
                TotalPriceInCart += i.QuantityInCart * i.cPrice;
            }
            var MemberDeposit = BuyFoodDB.TMembers.FirstOrDefault(x => x.CMemberId == GetMemberID); //從資料庫中取出該物件

            if (MemberDeposit.CDeposit - TotalPriceInCart < 0)
            {
                return("您的錢包餘額不足");
            }
            //檢查有無使用優惠券
            decimal CouponPrice = 0;
            var     CouponID    = BuyFoodDB.TCupons.FirstOrDefault(x => x.CCuponId == CartOrder.couponSelected);

            if (CouponID.CCuponCategoryId != 1)
            {
                CouponPrice      = (decimal)BuyFoodDB.TCuponCategories.FirstOrDefault(x => x.CCuponCategoryId == CouponID.CCuponCategoryId).CCutPrice;
                CouponID.CBeUsed = 1;
            }
            //先在資料庫中建立一筆新的訂單
            TOrder DbOrder = new TOrder()
            {
                CMemberId        = GetMemberID,
                COrderStatusId   = 1,
                CCuponId         = CartOrder.couponSelected,
                CPayTypeId       = CartOrder.payType,
                CArrivedAddress  = CartOrder.address,
                CTransportMinute = CartOrder.transportTime,
                COrderDate       = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
            };

            BuyFoodDB.TOrders.Add(DbOrder);
            BuyFoodDB.SaveChanges();

            //將訂單內的商品一一存入資料庫中
            foreach (var i in CartOrder.cartOrder)
            {
                var          InStoreProduct = BuyFoodDB.TProducts.FirstOrDefault(x => x.CProductId == i.cProductId);
                TOrderDetail ProductInOrder = new TOrderDetail()
                {
                    CProductId      = i.cProductId,
                    COrderId        = DbOrder.COrderId,
                    CQuantity       = i.QuantityInCart,
                    CPriceAtTheTime = InStoreProduct.CPrice,
                    CScores         = null, //暫時資料會移除
                    CReview         = null  //暫時資料會移除
                };
                InStoreProduct.CQuantity -= ProductInOrder.CQuantity;
                BuyFoodDB.TOrderDetails.Add(ProductInOrder);
            }
            MemberDeposit.CDeposit -= (TotalPriceInCart - CouponPrice);   //直接從欄位更改數值才有效果
            BuyFoodDB.SaveChanges();
            return("已收到訂單,請稍後");
        }