Exemplo n.º 1
0
        /// <summary>
        /// 储值支付
        /// </summary>
        /// <param name="orderObj"></param>
        /// <param name="order"></param>
        /// <param name="aid"></param>
        /// <param name="saveMoneyUser"></param>
        /// <param name="sbUpdateGoodCartSql"></param>
        /// <param name="reductionCart"></param>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public object PayOrderByChuzhi(object orderObj, int aid, SaveMoneySetUser saveMoneyUser, TransactionModel tran, ref int orderId)
        {
            QiyeGoodsOrder order = (QiyeGoodsOrder)orderObj;
            //储值支付 扣除预存款金额并生成消费记录
            //添加储值日志
            SaveMoneySetUserLog userLog = new SaveMoneySetUserLog()
            {
                AppId          = saveMoneyUser.AppId,
                UserId         = order.UserId,
                MoneySetUserId = saveMoneyUser.Id,
                Type           = -1,
                BeforeMoney    = saveMoneyUser.AccountMoney,
                AfterMoney     = saveMoneyUser.AccountMoney - order.BuyPrice,
                ChangeMoney    = order.BuyPrice,
                ChangeNote     = $" 购买商品,订单号:{order.OrderNum} ",
                CreateDate     = DateTime.Now,
                State          = 1,
                AId            = order.AId,
            };

            tran.Add(Utils.BuildAddSqlS(userLog, "OrderId", "(select LAST_INSERT_ID())", SaveMoneySetUserLogBLL.SingleModel.TableName, SaveMoneySetUserLogBLL.SingleModel.arrProperty));

            //储值扣费
            tran.Add($" update SaveMoneySetUser set AccountMoney = AccountMoney - {order.BuyPrice} where id =  {saveMoneyUser.Id} ; ");

            if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray))
            {
                log4net.LogHelper.WriteInfo(this.GetType(), "储值支付:操作失败" + Newtonsoft.Json.JsonConvert.SerializeObject(tran));
                return("");
            }

            QiyeStore store = QiyeStoreBLL.SingleModel.GetModel(order.StoreId);

            if (store != null)
            {
                //清除商品缓存
                QiyeGoodsBLL.SingleModel.RemoveEntGoodListCache(store.Aid);
            }
            orderId = 1;

            order = GetModelByOrderNum(order.OrderNum);
            if (order == null)
            {
                log4net.LogHelper.WriteInfo(this.GetType(), "储值支付:生成订单失败");
                return("");
            }

            //发送支付成功通知给用户
            object orderData = TemplateMsg_Miniapp.QiyeGetTemplateMessageData(order, SendTemplateMessageTypeEnum.企业智推版订单支付成功通知);

            TemplateMsg_Miniapp.SendTemplateMessage(order.UserId, SendTemplateMessageTypeEnum.企业智推版订单支付成功通知, TmpType.企业智推版, orderData);

            //发送支付成功公众号通知给商家
            TemplateMsg_Gzh.SendQiyePaySuccessTemplateMessage(order);

            return(new { postdata = order.OrderNum, orderid = 0, dbOrder = order.Id });
        }
Exemplo n.º 2
0
        public ActionResult addSaveMoneySet(string appid, string openid, int saveMoneySetId)
        {
            if (string.IsNullOrEmpty(appid))
            {
                return(Json(new { isok = false, msg = "获取失败(appid不能为空)" }, JsonRequestBehavior.AllowGet));
            }

            XcxAppAccountRelation r = _xcxAppAccountRelationBLL.GetModel($"AppId='{appid}'");

            if (r == null)
            {
                return(Json(new { isok = false, msg = "获取失败(还未进行授权)" }, JsonRequestBehavior.AllowGet));
            }
            var minisnsId = 0;
            //获取当前小程序模板类型
            var typeSql = $" select type from xcxtemplate where id = {r.TId} ";
            var temp    = Convert.ToInt32(SqlMySql.ExecuteScalar(_xcxAppAccountRelationBLL.connName, CommandType.Text, typeSql, null));

            if (temp == (int)TmpType.小程序电商模板 || temp == (int)TmpType.小程序电商模板测试)
            {
                var store = StoreBLL.SingleModel.GetModelByRid(r.Id) ?? new Store();
                minisnsId = store.Id;
                try
                {
                    store.funJoinModel = JsonConvert.DeserializeObject <StoreConfigModel>(store.configJson);
                }
                catch (Exception)
                {
                    store.funJoinModel = new StoreConfigModel();
                }
                if (!store.funJoinModel.canSaveMoneyFunction)
                {
                    return(Json(new { isok = false, msg = "商家未开启储值优惠功能" }, JsonRequestBehavior.AllowGet));
                }
            }
            else if (temp == (int)TmpType.小程序餐饮模板)
            {
                var food = FoodBLL.SingleModel.GetModel($" appId = {r.Id} ") ?? new Food();
                minisnsId = food.Id;
                if (!food.funJoinModel.canSaveMoneyFunction)
                {
                    return(Json(new { isok = false, msg = "商家未开启储值优惠功能" }, JsonRequestBehavior.AllowGet));
                }
            }

            var model = SaveMoneySetBLL.SingleModel.GetModel(saveMoneySetId, r.AppId);

            if (model == null || model.State != 1)//要是上架状态的储值项目
            {
                return(Json(new { isok = false, msg = "找不到储值项目" }, JsonRequestBehavior.AllowGet));
            }
            var userInfo = C_UserInfoBLL.SingleModel.GetModelByAppId_OpenId(appid, openid);

            if (userInfo == null)
            {
                return(Json(new { isok = -1, msg = "用户不存在" }, JsonRequestBehavior.AllowGet));
            }
            if (model == null || model.State != 1)//要是上架状态的储值项目
            {
                return(Json(new { isok = false, msg = "找不到储值项目" }, JsonRequestBehavior.AllowGet));
            }
            var user = SaveMoneySetUserBLL.SingleModel.getModelByUserId(r.AppId, userInfo.Id);

            if (user == null)
            {
                //用户储值账户,若无则开通一个
                user = new SaveMoneySetUser()
                {
                    AppId        = r.AppId,
                    UserId       = userInfo.Id,
                    AccountMoney = 0,
                    CreateDate   = DateTime.Now
                };
                user.Id = Convert.ToInt32(SaveMoneySetUserBLL.SingleModel.Add(user));
                if (user.Id <= 0)
                {
                    return(Json(new { isok = -1, msg = "开通储值账户失败,请重试" }, JsonRequestBehavior.AllowGet));
                }
            }
            //充值记录
            var newLog = new SaveMoneySetUserLog()
            {
                AppId          = r.AppId,
                UserId         = userInfo.Id,
                MoneySetUserId = user.Id,
                Type           = 0,
                BeforeMoney    = user.AccountMoney,
                AfterMoney     = user.AccountMoney + model.AmountMoney,
                ChangeMoney    = model.AmountMoney,
                ChangeNote     = model.SetName,
                CreateDate     = DateTime.Now,
                State          = 0,
                GiveMoney      = model.GiveMoney
            };

            //付款后才去累计预充值金额
            //user.AccountMoney += model.AmountMoney;
            //_miniappsavemoneysetuserBll.Update(user, "AccountMoney");
            newLog.Id = Convert.ToInt32(SaveMoneySetUserLogBLL.SingleModel.Add(newLog));
            //小程序信息
            var xcxconfig = OpenAuthorizerConfigBLL.SingleModel.GetModel($" appid = '{r.AppId}' ");

            #region cityMorder
            string no = WxPayApi.GenerateOutTradeNo();

            CityMorders citymorderModel = new CityMorders
            {
                OrderType      = (int)ArticleTypeEnum.MiniappSaveMoneySet,
                ActionType     = (int)ArticleTypeEnum.MiniappSaveMoneySet,
                Addtime        = DateTime.Now,
                payment_free   = model.JoinMoney,
                trade_no       = no,
                Percent        = 99,//不收取服务费
                userip         = WebHelper.GetIP(),
                FuserId        = userInfo.Id,
                Fusername      = userInfo.NickName,
                orderno        = no,
                payment_status = 0,
                Status         = 0,
                Articleid      = 0,
                CommentId      = 0,
                MinisnsId      = minisnsId, //r.Id,//模板权限表Id
                TuserId        = newLog.Id, //充值记录的ID
                ShowNote       = $" {xcxconfig?.nick_name} 储值项目[{model.SetName}]购买商品支付{(model.JoinMoney * 0.01).ToString("0.00")}元",
                CitySubId      = 0,         //无分销,默认为0
                PayRate        = 1,
                buy_num        = 0,         //无
                appid          = appid,
            };
            var orderid = Convert.ToInt32(_cityMordersBLL.Add(citymorderModel));
            if (orderid <= 0)
            {
                return(Json(new { isok = false, msg = "生成订单失败!" }, JsonRequestBehavior.AllowGet));
            }
            newLog.OrderId = orderid;
            SaveMoneySetUserLogBLL.SingleModel.Update(newLog, "OrderId");
            #endregion

            return(Json(new { isok = true, msg = "获取成功!", orderid = newLog.OrderId }, JsonRequestBehavior.AllowGet));
        }