private bool SetSubOrderDealed(SubOrder order) { BeginTransaction(); Tvip_Sub_Order daSubOrder = new Tvip_Sub_Order(); daSubOrder.ReferenceTransactionFrom(Transaction); if (!daSubOrder.SelectByPk(order.Sub_Id)) { Rollback(); return(false); } if (!daSubOrder.SetSubOrderDealed()) { Rollback(); return(false); } Commit(); return(true); }
/// <summary> /// /// </summary> /// <returns></returns> public bool CreateOrder() { if (_arg == null || _arg.UserCollection == null || _arg.UserCollection.Length <= 0) { Alert("请指定VIP升级会员"); return(false); } decimal amount = GetOrderAmount(_arg.DeviceModel) * _arg.UserCollection.Length; if (amount <= 0) { Alert("指定型号的设备已停止赠送"); return(false); } IUser user = GetUserById(_arg.UserId); if (user == null) { Alert("付款账号不存在"); return(false); } string order_no; BeginTransaction(); Tvip_Order daOrder = new Tvip_Order(); daOrder.ReferenceTransactionFrom(Transaction); daOrder.Amount = amount; daOrder.Order_Type = (int)_arg.OrderType; daOrder.Pay_Type = (int)_arg.PayType; daOrder.Status = 0; daOrder.User_Id = _arg.UserId; daOrder.Device_Id = _arg.DeviceModel; if (!string.IsNullOrEmpty(_arg.Org_Code)) { daOrder.Biz_Args = "{\"Org_Code\":\"" + _arg.Org_Code + "\"}"; } if (_arg.ConsigneeId.HasValue) { daOrder.Delivery_Type = 1; } if (!daOrder.Insert("VIP", out order_no)) { Rollback(); Alert("创建订单失败"); return(false); } if (_arg.ConsigneeId.HasValue) { ConsigneeProvider consignee = new ConsigneeProvider(); AddressInfo address = consignee.GetAddressById(_arg.ConsigneeId.Value); if (address == null) { Rollback(); Alert("无效的收货地址"); return(false); } Tvip_Express daExpress = new Tvip_Express(); daExpress.ReferenceTransactionFrom(Transaction); daExpress.Order_Id = daOrder.Order_Id; daExpress.Receiver = address.ConsigneeName; daExpress.Contract_Phone = address.MobileNo; daExpress.Province_Name = address.ProvinceName; daExpress.City_Name = address.CityName; daExpress.Region_Name = address.RegionName; daExpress.Full_Address = address.Address; daExpress.Status = 0; if (!daExpress.Insert()) { Rollback(); Alert("收货地址保存失败"); return(false); } } foreach (string userCode in _arg.UserCollection) { IUser vipUser = GetUserByCode(userCode); if (vipUser == null) { Rollback(); Alert(userCode + "不存在"); return(false); } //if (vipUser.Grade.Level == (int)UserLevel.DIP会员 || vipUser.Grade.Level == (int)UserLevel.VIP会员) //{ // Alert("您已经是VIP,不能重复申请"); // Rollback(); // return false; //} Tvip_Sub_Order daSub = new Tvip_Sub_Order(); daSub.ReferenceTransactionFrom(Transaction); daSub.Order_Id = daOrder.Order_Id; daSub.User_Id = vipUser.UserId; if (!daSub.Insert()) { Rollback(); Alert("创建订单失败"); return(false); } } string voucher = order_no; if (xUtils.IsCashPayment(_arg.PayType)) { var gpuRes = CreateGpuOrder(user, order_no, amount, _arg.PayType); if (!gpuRes.Success) { Rollback(); Alert(gpuRes.Message); return(false); } voucher = gpuRes.Content.Voucher; this.PayUrl = gpuRes.Content.PayUrl; } daOrder.Voucher = voucher; if (!daOrder.Update()) { Rollback(); Alert("获取支付凭证号失败"); return(false); } Commit(); this.OrderNo = order_no; this.Voucher = voucher; this.Amount = amount; return(true); }