/// <summary>
        /// 开单
        /// </summary>
        /// <returns></returns>
        public ActionResult createOrder()
        {
            #region 数据验证
            int appId = Context.GetRequestInt("appId", 0);
            if (appId <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙appid_null" }, JsonRequestBehavior.AllowGet));
            }
            if (dzaccount == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙auth_null" }));
            }
            XcxAppAccountRelation appAcountRelation = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString());
            if (appAcountRelation == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙relation_null" }));
            }
            FootBath storeModel = FootBathBLL.SingleModel.GetModelByAppId(appId);
            if (storeModel == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙model_null" }));
            }
            int orderId = Context.GetRequestInt("orderId", 0);
            if (orderId <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙orderId_null" }));
            }
            EntGoodsOrder orderInfo = EntGoodsOrderBLL.SingleModel.GetModelByOrderIdAndAid(orderId, appId, 1);
            if (orderInfo == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙order_null" }));
            }
            #endregion

            if (orderInfo.State == (int)MiniAppEntOrderState.已超时)
            {
                orderInfo.State = (int)MiniAppEntOrderState.务中;
            }
            orderInfo.OrderType = 0;
            orderInfo.ConfDate  = DateTime.Now;
            bool isok = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,ordertype,ConfDate") && VipRelationBLL.SingleModel.updatelevel(orderInfo.UserId, "footbath");
            #region 预约成功通知 模板消息
            if (isok)
            {
                object objData = TemplateMsg_Miniapp.FootbathGetTemplateMessageData(orderInfo, SendTemplateMessageTypeEnum.足浴预约成功通知);
                TemplateMsg_Miniapp.SendTemplateMessage(orderInfo.UserId, SendTemplateMessageTypeEnum.足浴预约成功通知, TmpType.小程序足浴模板, objData);
            }
            #endregion
            string msg = isok ? "操作成功" : "操作失败";
            return(Json(new { isok = isok, msg = msg }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 足浴版退款
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public bool ZYReFundQueue(string appId, EntGoodsOrder orderInfo, ServiceTime serviceTime)
        {
            bool result = false;

            if (orderInfo == null || orderInfo.Id <= 0)
            {
                return(result);
            }
            orderInfo.outOrderDate = DateTime.Now;
            if (orderInfo.BuyMode == (int)miniAppBuyMode.储值支付)
            {
                var saveMoneyUser = new SaveMoneySetUser();
                saveMoneyUser = SaveMoneySetUserBLL.SingleModel.getModelByUserId(appId, orderInfo.UserId);
                if (saveMoneyUser == null || saveMoneyUser.Id <= 0)
                {
                    return(result);
                }

                TransactionModel tran = new TransactionModel();
                tran.Add(SaveMoneySetUserLogBLL.SingleModel.BuildAddSql(new SaveMoneySetUserLog()
                {
                    AppId          = saveMoneyUser.AppId,
                    UserId         = orderInfo.UserId,
                    MoneySetUserId = saveMoneyUser.Id,
                    Type           = 1,
                    BeforeMoney    = saveMoneyUser.AccountMoney,
                    AfterMoney     = saveMoneyUser.AccountMoney + orderInfo.BuyPrice,
                    ChangeMoney    = orderInfo.BuyPrice,
                    ChangeNote     = $" 购买商品,订单号:{orderInfo.OrderNum} ",
                    CreateDate     = DateTime.Now,
                    State          = 1
                }));
                saveMoneyUser.AccountMoney += orderInfo.BuyPrice;
                tran.Add($" update SaveMoneySetUser set AccountMoney = AccountMoney + {orderInfo.BuyPrice} where id =  {saveMoneyUser.Id} ; ");
                tran.Add($" update EntGoodsOrder set state = {(int)MiniAppEntOrderState.退款成功 },outOrderDate = '{orderInfo.outOrderDate.ToString("yyyy-MM-dd HH:mm:ss")}',Remark = @Remark where Id = {orderInfo.Id} and state <> {(int)MiniAppEntOrderState.退款成功 } ; ", new MySqlParameter[] { new MySqlParameter("@Remark", orderInfo.Remark) });//防止重复退款
                if (serviceTime != null)
                {
                    tran.Add($"update servicetime set time='{serviceTime.time}' where id={serviceTime.Id}");//取消已预订的技师服务时间
                }
                //记录订单退款日志
                tran.Add(EntGoodsOrderLogBLL.SingleModel.BuildAddSql(new EntGoodsOrderLog()
                {
                    GoodsOrderId = orderInfo.Id, UserId = orderInfo.UserId, LogInfo = $" 订单储值支付,退款成功:{orderInfo.BuyPrice * 0.01} 元 ", CreateDate = DateTime.Now
                }));
                result = ExecuteTransaction(tran.sqlArray, tran.ParameterArray);
                if (result)
                {
                    object objData = TemplateMsg_Miniapp.FootbathGetTemplateMessageData(orderInfo, SendTemplateMessageTypeEnum.足浴退款通知);
                    TemplateMsg_Miniapp.SendTemplateMessage(orderInfo.UserId, SendTemplateMessageTypeEnum.足浴退款通知, TmpType.小程序足浴模板, objData);
                }
                return(result);
            }

            if (orderInfo.BuyMode == (int)miniAppBuyMode.微信支付)
            {
                CityMorders order = new CityMordersBLL().GetModel(orderInfo.OrderId);
                orderInfo.State = (int)MiniAppEntOrderState.退款中;

                if (order == null)
                {
                    orderInfo.State = (int)MiniAppEntOrderState.退款失败;
                    EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,outOrderDate,Remark");
                    return(result);
                }

                //微信支付
                ReFundQueue reModel = new ReFundQueue
                {
                    minisnsId = -5,
                    money     = orderInfo.BuyPrice,
                    orderid   = order.Id,
                    traid     = order.trade_no,
                    addtime   = DateTime.Now,
                    note      = "小程序足浴版退款",
                    retype    = 1
                };
                try
                {
                    base.Add(reModel);
                    result = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State,outOrderDate");
                    return(result);
                }
                catch (Exception ex)
                {
                    log4net.LogHelper.WriteInfo(GetType(), $"{ex.Message} xxxxxxxxxxxxxxxx小程序足浴退款订单插入队列失败 ID={orderInfo.Id}");
                }
            }
            return(result);
        }
        /// <summary>
        /// 取消预订
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateState()
        {
            int appId = Context.GetRequestInt("appId", 0);

            if (appId <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙appid_null" }, JsonRequestBehavior.AllowGet));
            }
            if (dzaccount == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙auth_null" }));
            }
            XcxAppAccountRelation appAcountRelation = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString());

            if (appAcountRelation == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙relation_null" }));
            }
            FootBath storeModel = FootBathBLL.SingleModel.GetModel($"appId={appId}");

            if (storeModel == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙model_null" }));
            }
            int id = Context.GetRequestInt("id", 0);

            if (id <= 0)
            {
                return(Json(new { isok = false, msg = "系统繁忙orderId_null" }));
            }
            int state = Context.GetRequestInt("state", -7);

            if (state <= -7)
            {
                return(Json(new { isok = false, msg = "系统繁忙state_null" }));
            }
            EntGoodsOrder orderInfo = EntGoodsOrderBLL.SingleModel.GetModelByAidAndId(appId, id, 1);

            if (orderInfo == null)
            {
                return(Json(new { isok = false, msg = "系统繁忙model_null" }));
            }
            //是否是要直接取消的订单<未支付的订单取消订单都是直接取消>
            bool isCanncleOrder = orderInfo.PayDate == Convert.ToDateTime("0001-01-01 00:00:00");

            if (isCanncleOrder)
            {
                orderInfo.State = (int)MiniAppEntOrderState.已取消;
            }
            else
            {
                orderInfo.State = state;
            }
            EntGoodsCart cart = EntGoodsCartBLL.SingleModel.GetModelByGoodsOrderId(orderInfo.Id);

            if (cart == null)
            {
                return(Json(new { isok = false, msg = "服务项目不存在" }));
            }
            ServiceTime serviceTime = ServiceTimeBLL.SingleModel.GetModel(storeModel.appId, cart.technicianId, storeModel.Id, cart.reservationTime.ToShortDateString());

            //取消已预订的技师服务时间
            if (serviceTime != null && !string.IsNullOrEmpty(serviceTime.time))
            {
                List <string> timeList = serviceTime.time.Split(',').ToList();
                timeList.Remove(cart.reservationTime.ToString("HH:mm"));
                serviceTime.time = string.Join(",", timeList);
            }
            bool isok = false;

            if (isCanncleOrder)
            {
                isok = EntGoodsOrderBLL.SingleModel.Update(orderInfo, "State");
            }
            else
            {
                isok = EntGoodsOrderBLL.SingleModel.outOrder(appAcountRelation.AppId, orderInfo, serviceTime);
            }

            #region 取消预约通知 模板消息
            if (isok && !isCanncleOrder)
            {
                object objData = TemplateMsg_Miniapp.FootbathGetTemplateMessageData(orderInfo, SendTemplateMessageTypeEnum.足浴预约取消通知);
                TemplateMsg_Miniapp.SendTemplateMessage(orderInfo.UserId, SendTemplateMessageTypeEnum.足浴预约取消通知, TmpType.小程序足浴模板, objData);
            }
            #endregion

            string msg = isok ? "操作成功" : "操作失败";
            return(Json(new { isok = isok, msg = msg }));
        }