コード例 #1
0
 /// <summary>
 /// 更新异步返回结果
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 public static int UpdateTask(Am_Task task)
 {
     using (var conn = GetOpenConnection())
     {
         var sql = "update Am_Task set Status=@Status,StatusStr=@StatusStr,OverTime=@OverTime,Remark=@Remark  where Number=@Number ";
         return(conn.Execute(sql, task));
     }
 }
コード例 #2
0
 /// <summary>
 /// 返回电表处理
 /// </summary>
 /// <param name="example"></param>
 /// <param name="item"></param>
 private void AmmeterHandle(Root example, Am_Task item)
 {
     if (example.data != null && example.data.Count > 0)
     {
         int type = example.data[0].type;
         List <DbParameter> par = new List <DbParameter>();
         par.Add(DbFactory.CreateDbParameter("@Number", item.AmmeterNumber));
         var ammeter = database.FindEntityByWhere <Am_Ammeter>(" and Number =@Number ", par.ToArray());
         //查询余额
         if (type == 22)
         {
             if (ammeter != null)
             {
                 ammeter.CurrMoney = double.Parse(example.data[0].value[0].ToString());
                 ammeter.CM_Time   = DateTime.Parse(example.resolve_time);
                 ammeter.Acount_Id = null;
                 database.Update <Am_Ammeter>(ammeter);
             }
         }
         //查询电量
         if (type == 20)
         {
             if (ammeter != null)
             {
                 ammeter.CurrPower = decimal.Parse(example.data[0].value[0].ToString()).ToString("0.00");
                 ammeter.CP_Time   = DateTime.Parse(example.resolve_time);
                 ammeter.Acount_Id = null;
                 database.Update <Am_Ammeter>(ammeter);
             }
         }
         //电价设置
         if (type == 12)
         {
             if (ammeter != null)
             {
                 ammeter.AmmeterMoney = decimal.Parse(example.data[0].value[0].ToString());
                 ammeter.Acount_Id    = null;
                 database.Update <Am_Ammeter>(ammeter);
             }
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// 成功处理
        /// </summary>
        /// <param name="result"></param>
        /// <param name="example"></param>
        /// <param name="item"></param>
        private void Success(string result, Root example, Am_Task item)
        {
            item.Status    = 1;
            item.StatusStr = "成功";
            if (example.data != null)
            {
                if (example.data[0].type == 20)
                {
                    item.Remark = "剩余电量:" + example.data[0].dsp;
                }
                else if (example.data[0].type == 22)
                {
                    item.Remark = "剩余金额:" + example.data[0].dsp;
                }
            }
            item.OverTime = DateTime.Parse(example.resolve_time);

            if (item.OperateType == 8)
            {
                List <DbParameter> par = new List <DbParameter>();
                par.Add(DbFactory.CreateDbParameter("@Number", item.AmmeterNumber));
                var ammeter = database.FindEntityByWhere <Am_Ammeter>(" and Number =@Number ", par.ToArray());
                if (ammeter != null && ammeter.Number != null)
                {
                    ammeter.Count     = 2;
                    ammeter.Status    = 1;
                    ammeter.StatusStr = "已开户";
                    ammeter.Acount_Id = null;
                    database.Update <Am_Ammeter>(ammeter);
                }
                item.Remark = "开户成功";
            }
            else if (item.OperateType == 4 || item.OperateType == 9)
            {
                List <DbParameter> par = new List <DbParameter>();
                par.Add(DbFactory.CreateDbParameter("@Number", item.AmmeterNumber));
                var ammeter = database.FindEntityByWhere <Am_Ammeter>(" and Number =@Number ", par.ToArray());
                if (ammeter != null && ammeter.Number != null)
                {
                    ammeter.Count     = ammeter.Count + 1;
                    ammeter.Acount_Id = null;
                    ammeter.CurrMoney = ammeter.CurrMoney + item.Money.Value;
                    if (ammeter.CurrMoney > ammeter.FirstAlarm)
                    {
                        ammeter.IsLowerWarning = 1;
                    }
                    database.Update <Am_Ammeter>(ammeter);
                }
                if (result.Contains("params"))
                {
                    var pr = JsonHelper.JonsToList <Root>(result.Replace("params", "paramsContent"));
                    if (pr[0].paramsContent != null)
                    {
                        item.Remark = "充值成功:" + pr[0].paramsContent.money + "元";
                    }
                    item.TaskMark = result;
                }
                //如果是用户充值

                //发送通知租户缴费成功
                SendMessage(ammeter.Number, ammeter.U_Number, ammeter.CurrMoney.Value.ToString("0.00"), "成功", item.Money.Value.ToString("0.00"), item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:dd"));
                //发送通知给业主
                SendMessage(ammeter.Number, ammeter.UY_Number, ammeter.CurrMoney.Value.ToString("0.00"), "成功", item.Money.Value.ToString("0.00"), item.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:dd"));
            }
            else if (item.OperateType == 20)//设置电价
            {
                if (result.Contains("params"))
                {
                    var pr = JsonHelper.JonsToList <Root>(result.Replace("params", "paramsContent"));
                    if (pr[0].paramsContent != null)
                    {
                        item.Remark = "设置电价成功:" + pr[0].paramsContent.p1 + "元";
                    }
                    item.TaskMark = result;


                    List <DbParameter> par = new List <DbParameter>();
                    par.Add(DbFactory.CreateDbParameter("@Number", item.AmmeterNumber));
                    var ammeter = database.FindEntityByWhere <Am_Ammeter>(" and Number =@Number ", par.ToArray());
                    if (ammeter != null && ammeter.Number != null)
                    {
                        ammeter.AmmeterMoney = decimal.Parse(pr[0].paramsContent.p1);
                        ammeter.Acount_Id    = null;
                        database.Update <Am_Ammeter>(ammeter);
                    }
                }
            }
            else if (item.OperateType == 3)
            {
                List <DbParameter> par = new List <DbParameter>();
                par.Add(DbFactory.CreateDbParameter("@Number", item.AmmeterNumber));
                var ammeter = database.FindEntityByWhere <Am_Ammeter>(" and Number =@Number ", par.ToArray());
                if (ammeter != null && ammeter.Number != null)
                {
                    ammeter.Count     = 1;
                    ammeter.Status    = 0;
                    ammeter.StatusStr = "未开户";
                    ammeter.Acount_Id = null;
                    database.Update <Am_Ammeter>(ammeter);
                }
            }
            else if (item.OperateType == 1)
            {
                item.Remark = "合闸成功";
            }
            else if (item.OperateType == 2)
            {
                item.Remark = "拉闸成功";
            }
        }
コード例 #4
0
ファイル: PayController.cs プロジェクト: gxlbang/yoga
        public ActionResult WepayWebNotify()
        {
            //var _logger = ObjectContainer.Resolve<ILoggerFactory>().Create(GetType().FullName);
            WePayReturnModel payResult = new WePayReturnModel();
            WePay            _wePay    = new WePay();
            var result = _wePay.VerifyNotify(Request, out payResult);

            // _logger.Info("resultXml:" + payResult.RequestForm);


            if (result)
            {
                List <DbParameter> parameter = new List <DbParameter>();
                parameter.Add(DbFactory.CreateDbParameter("@OrderNumber", payResult.OutTradeNo));
                parameter.Add(DbFactory.CreateDbParameter("@STATUS", "0"));
                var order = database.FindEntityByWhere <Am_Charge>(" and OrderNumber=@OrderNumber and STATUS=@STATUS ", parameter.ToArray());
                if (order != null && order.Number != null)
                {
                    if (payResult.TotalFee == Decimal.Parse(order.Money.ToString()))
                    {
                        //var orderCommand = new Commands.TradeCenter.UpdateOrderStatusCommand(order.OrderId, 1);
                        //var status = await _commandService.SendAsync(orderCommand);
                        //if (status.Status == ECommon.IO.AsyncTaskStatus.Success)
                        //{
                        //    return Content(payResult.ReturnXml);
                        //}
                        if (order.ChargeType == 1) //余额充值
                        {
                            List <DbParameter> par = new List <DbParameter>();
                            par.Add(DbFactory.CreateDbParameter("@Number", order.U_Number));
                            var accout = database.FindEntityByWhere <Ho_PartnerUser>(" and Number=@Number", par.ToArray());
                            if (accout != null && accout.Number != null)
                            {
                                order.OutNumber = payResult.TradeNo;
                                order.STATUS    = 1;
                                order.StatusStr = "充值成功";
                                order.SucTime   = DateTime.Now;
                                database.Update <Am_Charge>(order);

                                accout.Money = accout.Money + order.Money;
                                var status = database.Update <Ho_PartnerUser>(accout);
                                if (status > 0)
                                {
                                    var moneyDetail = new Am_MoneyDetail
                                    {
                                        Number         = CommonHelper.GetGuid,
                                        CreateTime     = DateTime.Now,
                                        CreateUserId   = order.U_Number,
                                        CreateUserName = order.UserName,
                                        CurrMoney      = accout.Money,
                                        Money          = order.Money,
                                        OperateType    = 1,
                                        OperateTypeStr = "微信充值",
                                        Remark         = "",
                                        UserName       = order.UserName,
                                        U_Number       = order.U_Number
                                    };
                                    database.Insert <Am_MoneyDetail>(moneyDetail);

                                    return(Content(payResult.ReturnXml));
                                }
                            }
                        }
                        else if (order.ChargeType == 2) //电费缴费
                        {
                            order.OutNumber = payResult.TradeNo;
                            order.STATUS    = 1;
                            order.StatusStr = "充值成功";
                            order.SucTime   = DateTime.Now;
                            database.Update <Am_Charge>(order);

                            List <DbParameter> par = new List <DbParameter>();
                            par.Add(DbFactory.CreateDbParameter("@Number", order.AmmeterNumber));
                            var ammeter = database.FindEntityByWhere <Am_Ammeter>(" and Number=@Number", par.ToArray());
                            var item    = CommonClass.AmmeterApi.AmmeterRecharge(ammeter.Collector_Code, ammeter.AM_Code, ammeter.Acount_Id.Value, ammeter.Count.Value, int.Parse(order.Money.ToString()));
                            if (item.suc)
                            {
                                var task = new Am_Task
                                {
                                    AmmeterCode     = ammeter.AM_Code,
                                    AmmeterNumber   = ammeter.Number,
                                    Number          = item.opr_id,
                                    CollectorCode   = ammeter.Collector_Code,
                                    CollectorNumber = ammeter.Collector_Number,
                                    CreateTime      = DateTime.Now,
                                    OperateType     = 4,
                                    OperateTypeStr  = "微信充值",
                                    OrderNumber     = order.OrderNumber,
                                    OverTime        = DateTime.Now,
                                    Remark          = "",
                                    Status          = 0,
                                    StatusStr       = "队列中",
                                    TaskMark        = "",
                                    UserName        = order.UserName,
                                    U_Name          = order.U_Name,
                                    U_Number        = order.U_Number,
                                    Money           = order.Money
                                };
                                database.Insert <Am_Task>(task);
                            }
                            return(Content(payResult.ReturnXml));
                        }
                        else if (order.ChargeType == 3)  //账单支付
                        {
                            order.OutNumber = payResult.TradeNo;
                            order.STATUS    = 1;
                            order.StatusStr = "缴费成功";
                            order.SucTime   = DateTime.Now;
                            database.Update <Am_Charge>(order);

                            List <DbParameter> par = new List <DbParameter>();
                            par.Add(DbFactory.CreateDbParameter("@Number", order.ObjectNumber));
                            par.Add(DbFactory.CreateDbParameter("@Status", "1"));
                            var bill = database.FindEntityByWhere <Am_Bill>(" and Number=@Number and Status=@Status ", par.ToArray());

                            if (bill != null && bill.Number != null)
                            {
                                bill.Status    = 2;
                                bill.StatusStr = "已支付";
                                bill.PayTime   = DateTime.Now;

                                List <DbParameter> parBill = new List <DbParameter>();
                                parBill.Add(DbFactory.CreateDbParameter("@Number", bill.Number));
                                parBill.Add(DbFactory.CreateDbParameter("@Status", bill.Status));
                                parBill.Add(DbFactory.CreateDbParameter("@StatusStr", bill.StatusStr));
                                parBill.Add(DbFactory.CreateDbParameter("@PayTime", bill.PayTime));

                                StringBuilder sql = new StringBuilder("update Am_Bill set Status=@Status,PayTime=@PayTime,StatusStr=@StatusStr where Number=@Number  and Status = 1");

                                if (database.ExecuteBySql(sql, parBill.ToArray()) > 0)
                                {
                                    //押金
                                    UserDeposit(bill);

                                    var ammodel = database.FindEntity <Am_Ammeter>(bill.AmmeterNumber);
                                    //给余额加钱
                                    var userModel = database.FindEntity <Ho_PartnerUser>(ammodel.UY_Number);
                                    userModel.Money += bill.Money;
                                    userModel.Modify(userModel.Number);
                                    database.Update(userModel);
                                    //记录余额日志
                                    var modeldetail = new Am_MoneyDetail()
                                    {
                                        CreateTime     = DateTime.Now,
                                        CreateUserId   = userModel.Number,
                                        CreateUserName = userModel.Account,
                                        CurrMoney      = userModel.Money + bill.Money, //变动后余额
                                        Money          = bill.Money,
                                        OperateType    = 4,
                                        OperateTypeStr = "账单缴费",
                                        UserName       = userModel.Account,
                                        U_Name         = userModel.Name,
                                        U_Number       = userModel.Number,
                                        Number         = CommonHelper.GetGuid,
                                        Remark         = ""
                                    };
                                    database.Insert(modeldetail); //记录日志
                                                                  //分账
                                    var    config = database.FindList <Fx_WebConfig>().FirstOrDefault();
                                    double fmoney = 0;
                                    double money  = 0;//1:1押金返还金额
                                    fmoney = bill.Money.Value * (1 - config.ChargeFee.Value);
                                    PayToPerson pay = new BusinessCard.Web.Code.PayToPerson();
                                    try
                                    {
                                        var user = database.FindEntity <Ho_PartnerUser>(ammodel.UY_Number);
                                        if (user.FreezeMoney > 0) //首先要有押金
                                        {
                                            money = bill.Money.Value * config.ChargeFee.Value;
                                            //如果返还的金额大于
                                            if (money > user.FreezeMoney)
                                            {
                                                money = user.FreezeMoney.Value;
                                            }
                                            fmoney += money;
                                        }

                                        PayToPersonModel m = pay.EnterprisePay(bill.Number.Replace("-", ""), userModel.OpenId, decimal.Parse(fmoney.ToString("0.00")), userModel.Name, bill.T_U_Name + ",账单支付");
                                        if (m.result_code == "SUCCESS")//分成功
                                        {
                                            userModel.Money       -= bill.Money;
                                            userModel.FreezeMoney -= money;
                                            userModel.Modify(userModel.Number);
                                            database.Update(userModel); //扣掉余额


                                            //添加押金返还记录
                                            var recordModel = new Am_AmDepositDetail()
                                            {
                                                CreateTime = DateTime.Now,
                                                CurrMoney  = user.FreezeMoney,
                                                Mark       = "押金1:1返还",
                                                Money      = money,
                                                UserName   = userModel.Account,
                                                U_Name     = userModel.Name,
                                                U_Number   = userModel.Number
                                            };
                                            recordModel.Create();
                                            database.Insert(recordModel); //添加返还记录


                                            //记录余额日志
                                            var modeldetail1 = new Am_MoneyDetail()
                                            {
                                                CreateTime     = DateTime.Now,
                                                CreateUserId   = userModel.Number,
                                                CreateUserName = userModel.Account,
                                                CurrMoney      = userModel.Money - bill.Money, //变动后余额
                                                Money          = -bill.Money,
                                                OperateType    = 6,
                                                OperateTypeStr = "分账",
                                                UserName       = userModel.Account,
                                                U_Name         = userModel.Name,
                                                U_Number       = userModel.Number,
                                                Number         = CommonHelper.GetGuid,
                                                Remark         = ""
                                            };
                                            database.Insert(modeldetail1); //记录日志

                                            //记录分账信息
                                            var payToUser = new Am_PayToUserMoneyDetails()
                                            {
                                                CreateTime     = DateTime.Now,
                                                F_UName        = userModel.Name,
                                                Number         = CommonHelper.GetGuid,
                                                F_UserName     = userModel.Account,
                                                F_UserNumber   = userModel.Number,
                                                Money          = fmoney,
                                                MoneyFree      = money,
                                                ObjectNumber   = bill.Number,
                                                OpenId         = userModel.OpenId,
                                                OperateType    = 1,
                                                OperateTypeStr = "账单缴费",
                                                Remark         = "",
                                                TaskNumber     = "",
                                                TotalMoney     = bill.Money,
                                                UName          = bill.T_U_Name,
                                                UserName       = bill.T_UserName,
                                                UserNumber     = bill.T_U_Number
                                            };

                                            database.Insert <Am_PayToUserMoneyDetails>(payToUser);
                                        }
                                        else
                                        {
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                }
                                return(Content(payResult.ReturnXml));
                            }
                            //发送微信通知
                        }
                    }
                }
            }
            return(Content(BuildWepayReturnXml("FAIL", "")));
        }