Example #1
0
        /// <summary>
        /// 增加商家收入
        /// </summary>
        /// <param name="order"></param>
        /// <param name="store"></param>
        /// <param name="tran"></param>
        /// <param name="type">0:增加订单实付金额 1:增加订单返利金额</param>
        public void AddIncome(PinGoodsOrder order, PinStore store, TransactionModel tran, int type = 0)
        {
            string fileds = "";
            int    money  = 0;

            if (type == 0)
            {
                money = order.money - order.returnMoney;
            }
            else
            {
                money = order.returnMoney;
            }
            if (order.sourceType == 0)
            {
                store.money += money;
                store.cash  += money;
                fileds       = "money,cash";
            }
            else
            {
                store.qrcodeMoney += money;
                store.qrcodeCash  += money;
                fileds             = "qrcodemoney,qrcodecash";
            }
            MySqlParameter[] pone = null;
            tran.Add(BuildUpdateSql(store, fileds, out pone), pone);
        }
Example #2
0
        /// <summary>
        /// 代理升级
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="money"></param>
        /// <param name="oldAgentLevel"></param>
        /// <returns></returns>
        public bool UpdateAgentLevel(PinAgent agent, int money, int oldAgentLevel, DateTime oldAddTime)
        {
            if (base.Update(agent, "AgentLevel,addTime"))
            {
                TransactionModel  tran = new TransactionModel();
                PinAgentChangeLog pinAgentChangeLog = new PinAgentChangeLog()
                {
                    Aid         = agent.aId,
                    AgentId     = agent.id,
                    ChangeMoney = money,
                    Remark      = $"代理商升级由之前的{oldAgentLevel}等级升级为{agent.AgentLevel},花费{money * 0.01}元",
                    ChangeType  = 1,
                    AddTime     = DateTime.Now
                };
                tran.Add(PinAgentChangeLogBLL.SingleModel.BuildAddSql(pinAgentChangeLog));
                PinGoodsOrder pinOrder = new PinGoodsOrder()
                {
                    money = money
                };
                UpdateIncome(agent, pinOrder, tran);
                PinAgentIncomeLogBLL.SingleModel.AddAgentLog(agent, pinOrder, tran);//插入提成日志
                if (!ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray))
                {
                    agent.addTime    = oldAddTime;
                    agent.AgentLevel = oldAgentLevel;
                    base.Update(agent, "AgentLevel,addTime");
                    return(false);
                }

                return(true);
            }
            return(false);
        }
Example #3
0
        /// <summary>
        /// 申请通过处理
        /// </summary>
        /// <param name="apply"></param>
        /// <param name="store"></param>
        /// <returns></returns>
        public bool ApplySuccess(PinRefundApply apply, PinStore store, ref string msg)
        {
            bool result = false;

            if (apply.type == 2 || apply.type == 3)
            {
                if (string.IsNullOrEmpty(store.setting.place) || string.IsNullOrEmpty(store.setting.phone) || string.IsNullOrEmpty(store.setting.name))
                {
                    msg = "请前往店铺配置设置您的退换货寄件信息";
                    return(result);
                }
            }
            PinGoodsOrderBLL orderBLL = new PinGoodsOrderBLL();

            PinGoodsOrder order = orderBLL.GetModel(apply.orderId);

            if (order == null)
            {
                msg = "订单不存在";
                return(result);
            }
            order.state        = apply.orderState;
            order.returnCount += apply.count;
            order.state        = order.returnCount == order.count ? order.state = (int)PinOrderState.交易取消 : order.state = apply.orderState;
            orderBLL.Update(order, "state,returncount,state");
            PinGroupBLL.SingleModel.RollbackEntrantCount(order, ref msg);
            result = Update(apply, "state,updatetime");
            return(result);
        }
Example #4
0
        /// <summary>
        /// 评价
        /// </summary>
        /// <param name="comment"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public bool AddComment(PinComment comment, PinGoodsOrder order)
        {
            TransactionModel tran = new TransactionModel();

            tran.Add(BuildAddSql(comment));
            tran.Add($" update pingoodsorder set state = {(int)PinEnums.PinOrderState.已评价} where id={order.id} ");
            tran.Add($" update pingoods set  CommentCount=CommentCount+1 where id={order.goodsId}");
            return(ExecuteTransactionDataCorect(tran.sqlArray));
        }
Example #5
0
        /// <summary>
        /// 用户拼团成功返现
        /// </summary>
        /// <param name="id">提现账号id(PlatUserCash)</param>
        /// <param name="drawcashmoney">提现金额(分)</param>
        /// <returns></returns>
        public string PxhUserApplyDrawCash(PinGoodsOrder order, int userId, string appid)
        {
            PinGoodsOrderBLL pinGoodsOrderBLL = new PinGoodsOrderBLL();
            TransactionModel tran             = new TransactionModel();

            if (userId <= 0)
            {
                return("用户ID不能为0");
            }
            if (order.returnMoney <= 0)
            {
                return("返现金额不能为0");
            }
            if (string.IsNullOrEmpty(appid))
            {
                return("appid不能为空");
            }

            int           serviceFee       = 0;//服务费
            string        partner_trade_no = WxPayApi.GenerateOutTradeNo();
            DrawCashApply apply            = new DrawCashApply()
            {
                Aid              = order.aid,
                appId            = appid,
                partner_trade_no = partner_trade_no,
                userId           = userId,
                applyMoney       = order.returnMoney,
                serviceMoney     = serviceFee,
                cashMoney        = order.returnMoney - serviceFee,
                useCash          = "0",
                BeforeApplyMoney = 0,
                AddTime          = DateTime.Now,
                remark           = "拼享惠拼团成功用户申请返现",
                hostIP           = WebHelper.GetIP(),
                state            = 0,
                drawState        = (int)DrawCashState.未开始提现,
                applyType        = (int)DrawCashApplyType.拼享惠用户返现,
                drawCashWay      = (int)DrawCashWay.微信提现,
                OrderId          = order.id,
            };

            tran.Add(base.BuildAddSql(apply));

            order.isReturnMoney = 1;
            tran.Add(pinGoodsOrderBLL.BuildUpdateSql(order, "isReturnMoney"));

            if (!base.ExecuteTransactionDataCorect(tran.sqlArray))
            {
                return("申请提现失败");
            }
            return("");
        }
Example #6
0
        /// <summary>
        /// 回滚参团人数
        /// </summary>
        /// <param name="pinOrder"></param>
        /// <returns></returns>
        public bool RollbackEntrantCount(PinGoodsOrder pinOrder, ref string msg, TransactionModel tran = null)
        {
            bool isTran = tran != null;

            if (!isTran)
            {
                tran = new TransactionModel();
            }
            string   sqlwhere = $"id={pinOrder.groupId}";
            PinGroup group    = GetModel(sqlwhere);

            if (group == null)
            {
                log4net.LogHelper.WriteError(GetType(), new Exception($"拼团回滚失败{pinOrder.groupId}"));
                return(false);
            }
            if (group.state == (int)PinEnums.GroupState.已成团 || group.state == (int)PinEnums.GroupState.未成团)
            {
                //交易取消和退款不能重复减去参团人数
                if (pinOrder.state > (int)PinEnums.PinOrderState.交易取消 || pinOrder.payState != (int)PayState.已退款)
                {
                    group.entrantCount--;
                }
                if (group.entrantCount <= 0)
                {
                    group.state = (int)PinEnums.GroupState.拼团失败;
                    //log4net.LogHelper.WriteInfo(GetType(), "1"+group.stateStr);
                }
                else if (group.entrantCount < group.groupCount)
                {
                    //log4net.LogHelper.WriteInfo(GetType(), "2" + group.stateStr);

                    group.state = (int)PinEnums.GroupState.未成团;
                    if (pinOrder.payState == (int)PayState.已付款)
                    {
                        group.endTime = DateTime.Now.AddDays(1);
                    }
                }
                //log4net.LogHelper.WriteInfo(GetType(), "3" + group.stateStr);

                group.changeTime = DateTime.Now;
            }
            MySqlParameter[] parames = null;
            tran.Add(BuildUpdateSql(group, "state,endTime,entrantCount,changeTime", out parames), parames);
            if (isTran)
            {
                return(true);
            }
            return(base.ExecuteTransaction(tran.sqlArray, tran.ParameterArray));
        }
Example #7
0
        /// <summary>
        /// 创建拼团
        /// </summary>
        /// <param name="pinOrder"></param>
        /// <returns></returns>
        public bool CreateGroup(PinGoodsOrder pinOrder, PinGroup group)
        {
            group = new PinGroup()
            {
                aid          = pinOrder.aid,
                storeId      = pinOrder.storeId,
                goodsId      = pinOrder.goodsId,
                groupCount   = pinOrder.goodsPhotoModel.groupUserLimit,
                entrantCount = 1,
            };
            group.endTime    = group.startTime.AddDays(1);
            pinOrder.groupId = group.id = Convert.ToInt32(Add(group));

            return(pinOrder.groupId > 0);
        }
Example #8
0
        /// <summary>
        /// 更新用户拼团成功提现结果
        /// </summary>
        /// <param name="code">0提现失败 1提现成功</param>
        /// <param name="drawCashApplyId"></param>
        /// <param name="result">附加信息</param>
        /// <returns></returns>
        public string UpdatePxhUserDrawCashResult(int code, DrawCashApply drawCashApply, string result, int state = 0)
        {
            TransactionModel tranModel = new TransactionModel();
            C_UserInfo       usercash  = C_UserInfoBLL.SingleModel.GetModel(drawCashApply.userId);

            if (usercash == null)
            {
                return("没有找到用户提现账号");
            }
            //if (drawCashApply.drawState != (int)DrawCashState.提现中)
            //{
            //    return "无效状态";
            //}
            if (code == 1)
            {
                drawCashApply.drawState = 2;
                drawCashApply.DrawTime  = DateTime.Now;
                drawCashApply.remark   += $" ;本次提现成功{DateTime.Now}";
            }
            else
            {
                PinGoodsOrderBLL pinGoodsOrderBLL = new PinGoodsOrderBLL();
                PinGoodsOrder    order            = pinGoodsOrderBLL.GetModel(drawCashApply.OrderId);
                if (order == null)
                {
                    return("没有找到拼享惠订单");
                }
                order.isReturnMoney = 0;
                tranModel.Add(pinGoodsOrderBLL.BuildUpdateSql(order, "isReturnMoney"));
                //表示提现失败
                //tranModel.Add($"update PinGoodsOrder set isReturnMoney=0 where id={order.id}");

                drawCashApply.drawState = -1;
                if (state == (int)ApplyState.审核不通过)
                {
                    drawCashApply.state = state;
                }

                drawCashApply.DrawTime = DateTime.Now;
                drawCashApply.remark   = $" ;本次提现失败{DateTime.Now},原因{result}";
            }

            tranModel.Add(base.BuildUpdateSql(drawCashApply, "state,drawState,DrawTime,remark"));

            bool success = base.ExecuteTransactionDataCorect(tranModel.sqlArray);

            return(success ? "" : "执行更新拼享惠用户提现结果失败");
        }
Example #9
0
        /// <summary>
        /// 申请不通过处理
        /// </summary>
        /// <param name="apply"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool ApplyFail(PinRefundApply apply, ref string msg)
        {
            bool             result   = false;
            PinGoodsOrderBLL orderBLL = new PinGoodsOrderBLL();
            PinGoodsOrder    order    = orderBLL.GetModel(apply.orderId);

            if (order == null)
            {
                msg = "订单不存在";
                return(result);
            }
            order.state = apply.orderState;
            orderBLL.Update(order, "state");
            result = Update(apply, "state,updatetime");
            return(result);
        }
Example #10
0
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="storeId"></param>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult Refund(int aid = 0, int storeId = 0, int orderId = 0)
        {
            if (aid <= 0 || storeId <= 0 || orderId <= 0)
            {
                result.msg = "参数错误";
                return(Json(result));
            }
            PinGoodsOrderBLL pinGoodsOrderBLL = new PinGoodsOrderBLL();
            PinGoodsOrder    order            = pinGoodsOrderBLL.GetModelByAid_StoreId_Id(aid, storeId, orderId);

            if (order == null)
            {
                result.msg = "订单错误";
                return(Json(result));
            }
            string msg = string.Empty;

            result.code = pinGoodsOrderBLL.Refund(order, ref msg);
            result.msg  = msg;
            return(Json(result));
        }
Example #11
0
        /// <summary>
        /// 回滚库存
        /// </summary>
        /// <param name="order"></param>
        /// <param name="tran"></param>
        public bool RollbackGoodsStock(PinGoodsOrder order, TransactionModel tran = null)
        {
            bool isTran = tran != null;

            if (!isTran)
            {
                tran = new TransactionModel();
            }
            PinGoods goods = GetModel(order.goodsId);

            if (goods == null)
            {
                log4net.LogHelper.WriteError(GetType(), new Exception($"回滚库存失败 商品不存在 orderId:{order.id} goodsId:{order.goodsId}"));
                return(false);
            }
            if (!string.IsNullOrEmpty(order.specificationId))
            {
                List <SpecificationDetailModel> specList = goods.SpecificationDetailList;
                specList.ForEach(spec =>
                {
                    if (spec.id == order.specificationId)
                    {
                        spec.stock += order.count;
                    }
                });
                goods.specificationdetail = JsonConvert.SerializeObject(specList);
                tran.Add(BuildUpdateSql(goods, "specificationdetail"));
            }
            else
            {
                goods.stock += order.count;
                tran.Add(BuildUpdateSql(goods, "stock"));
            }
            if (isTran)
            {
                return(true);
            }
            return(base.ExecuteTransaction(tran.sqlArray, tran.ParameterArray));
        }
Example #12
0
        /// <summary>
        /// 代理续费
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="money"></param>
        /// <returns></returns>
        public bool AddAgentTime(PinAgent agent, int money, int timeLength)
        {
            TransactionModel  tran = new TransactionModel();
            PinAgentChangeLog pinAgentChangeLog = new PinAgentChangeLog()
            {
                Aid         = agent.aId,
                AgentId     = agent.id,
                ChangeMoney = money,
                Remark      = $"代理商续费{timeLength}年,花费{money * 0.01}元",
                ChangeType  = 0,
                AddTime     = DateTime.Now
            };

            tran.Add(PinAgentChangeLogBLL.SingleModel.BuildAddSql(pinAgentChangeLog));

            if (agent.IsExpired)
            {
                //如果过期了则当前时间为入驻时间
                agent.addTime   = DateTime.Now;
                agent.AgentTime = timeLength;
                tran.Add(base.BuildUpdateSql(agent, "addTime,AgentTime"));
            }
            else
            {
                agent.AgentTime += timeLength;
                tran.Add(base.BuildUpdateSql(agent, "AgentTime"));
            }



            PinGoodsOrder pinOrder = new PinGoodsOrder()
            {
                money = money
            };

            UpdateIncome(agent, pinOrder, tran);
            PinAgentIncomeLogBLL.SingleModel.AddAgentLog(agent, pinOrder, tran);//插入提成日志
            return(ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray));
        }
Example #13
0
        public ActionResult FaHuo(int aid = 0, int storeId = 0, int orderId = 0, string act = "")
        {
            if (string.IsNullOrEmpty(act))
            {
                PinGoodsOrder order = orderBLL.GetModelByAid_StoreId_Id(aid, storeId, orderId);
                if (order == null)
                {
                    return(Content("订单不存在"));
                }
                ViewModel <PinGoodsOrder> vm = new ViewModel <PinGoodsOrder>();
                vm.DataModel     = order;
                vm.aId           = aid;
                vm.storeId       = storeId;
                ViewBag.companys = DeliveryCompanyBLL.SingleModel.GetCompanys();

                return(View(vm));
            }
            else
            {
                return(Json(result));
            }
        }
Example #14
0
        /// <summary>
        /// 代理提成日志
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="pinOrder"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public bool AddAgentLog(PinAgent agent, PinGoodsOrder pinOrder, TransactionModel tran = null)
        {
            bool istran = tran != null;

            if (!istran)
            {
                tran = new TransactionModel();
            }

            PinPlatform platform = PinPlatformBLL.SingleModel.GetModelByAid(agent.aId);

            if (platform == null)
            {
                log4net.LogHelper.WriteError(GetType(), new Exception("平台信息错误"));
                return(false);
            }

            #region 旧代码 没有代理商等级时候的逻辑
            //int Percent = platform.agentExtract;//上级比例
            //PinAgent grandfatherAgent = null;
            //int money = pinOrder.money * Percent;
            //if (agent.fuserId > 0)
            //{
            //    PinAgent fatherAgent = PinAgentBLL.SingleModel.GetModelByUserId(agent.fuserId);
            //    if (fatherAgent != null)
            //    {
            //        grandfatherAgent = PinAgentBLL.SingleModel.GetModelByUserId(fatherAgent.fuserId);
            //        if (grandfatherAgent != null && platform.FirstExtract > 0 && platform.SecondExtract > 0 && (platform.FirstExtract + platform.SecondExtract) <= 1000)
            //        {
            //            //表示有上上级 重新分配上级提成比例
            //            money = Convert.ToInt32(platform.FirstExtract * 0.001 * money);
            //        }
            //    }
            //}

            //PinAgentIncomeLog log = new PinAgentIncomeLog()
            //{
            //    aId = agent.aId,
            //    userId = agent.fuserId,
            //    sourceUid = agent.userId,
            //    income = money,
            //    source = 0
            //};
            //C_UserInfo userInfo = C_UserInfoBLL.SingleModel.GetModel(agent.userId);
            //if (userInfo == null)
            //{
            //    log.remark = $"代理付费日志出错:找不到代理用户信息 userid:{agent.userId}";
            //    log4net.LogHelper.WriteError(GetType(), new Exception(log.remark));
            //    tran.Add(BuildAddSql(log));
            //    if (istran) return true;
            //    return ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray);
            //}
            //log.remark = $"{userInfo.NickName} 成为代理";

            //if (agent.fuserId > 0)
            //{
            //    PinAgent fagent = PinAgentBLL.SingleModel.GetModelByUserId(agent.fuserId);
            //    if (fagent == null)
            //    {
            //        log.remark = $"代理付费日志出错:找不到上级代理 userid:{agent.fuserId}";
            //        log4net.LogHelper.WriteError(GetType(), new Exception(log.remark));
            //        tran.Add(BuildAddSql(log));
            //        if (istran) return true;
            //        return ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray);
            //    }
            //    log.agentId = fagent.id;
            //    log.beforeMoney = fagent.cash;
            //    log.afterMoney = fagent.cash + money;
            //    C_UserInfo fuserInfo = C_UserInfoBLL.SingleModel.GetModel(agent.fuserId);
            //    if (fuserInfo == null)
            //    {
            //        log.remark = $"代理付费日志出错:找不到上级代理用户信息 userid:{agent.fuserId}";
            //        log4net.LogHelper.WriteError(GetType(), new Exception(log.remark));
            //        tran.Add(BuildAddSql(log));
            //        if (istran) return true;
            //        return ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray);
            //    }
            //    log.remark += $",{fuserInfo.NickName}获得提成{log.incomeStr}元";
            //}
            //tran.Add(BuildAddSql(log));

            #region   级分提成日志
            //if (grandfatherAgent != null && platform.FirstExtract > 0 && platform.SecondExtract > 0 && (platform.FirstExtract + platform.SecondExtract) <= 1000)
            //{
            //    //表示有上上级 记录分给上上级提成日志

            //    int grandfatherAgentMoney = Convert.ToInt32(pinOrder.money * Percent * platform.SecondExtract * 0.001);
            //    PinAgentIncomeLog grandfatherAgentLog = new PinAgentIncomeLog()
            //    {
            //        aId = grandfatherAgent.aId,
            //        userId = grandfatherAgent.userId,
            //        sourceUid = agent.userId,
            //        income = grandfatherAgentMoney,
            //        source = 0,
            //        ExtractType = 1
            //    };

            //    grandfatherAgentLog.agentId = grandfatherAgent.id;
            //    grandfatherAgentLog.beforeMoney = grandfatherAgent.cash;
            //    grandfatherAgentLog.afterMoney = grandfatherAgent.cash + grandfatherAgentMoney;

            //    C_UserInfo gfuserInfo = C_UserInfoBLL.SingleModel.GetModel(grandfatherAgent.userId);
            //    if (gfuserInfo == null)
            //    {
            //        grandfatherAgentLog.remark = $"代理付费日志出错:找不到上上级代理用户信息 userid:{grandfatherAgent.userId}";
            //        log4net.LogHelper.WriteError(GetType(), new Exception(grandfatherAgentLog.remark));
            //        tran.Add(BuildAddSql(grandfatherAgentLog));
            //        if (istran) return true;
            //        return ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray);
            //    }
            //    grandfatherAgentLog.remark += $",{gfuserInfo.NickName}获得提成{grandfatherAgentLog.incomeStr}元";
            //    grandfatherAgentLog.remark += $"{userInfo.NickName} 成为代理(下下级)";
            //    tran.Add(BuildAddSql(grandfatherAgentLog));

            //}

            #endregion
            #endregion


            PinAgentLevelConfig agentLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(agent.AgentLevel, agent.aId);
            if (agentLevelConfig == null)
            {
                log4net.LogHelper.WriteInfo(GetType(), $"代理提成log错误:当前入驻代理商{agent.id}等级找不到");
                return(false);
            }

            PinAgent fagent = PinAgentBLL.SingleModel.GetModelByUserId(agent.fuserId);
            if (fagent == null)
            {
                log4net.LogHelper.WriteInfo(GetType(), $"代理提成log错误:找不到上级代理信息 userid:{agent.fuserId}");
                return(false);
            }

            //查找该代理上级所属等级 根据所属等级进行不同比例分成

            PinAgentLevelConfig fagentLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(fagent.AgentLevel, fagent.aId);
            if (fagentLevelConfig == null)
            {
                log4net.LogHelper.WriteInfo(GetType(), $"代理提log成错误:上级代理商{fagent.id}等级找不到");
                return(false);
            }

            int percent = fagentLevelConfig.AgentExtract;
            if (agentLevelConfig.LevelId > fagentLevelConfig.LevelId)
            {
                //表示当前代理商级别高于所属上级代理商级别则按越级比例分配给上级
                percent = platform.JumpExtract;
            }

            int money = pinOrder.money * percent;

            PinAgentIncomeLog fAgengLog = new PinAgentIncomeLog()
            {
                aId         = agent.aId,
                userId      = agent.fuserId,
                sourceUid   = agent.userId,
                income      = money,
                source      = 0,
                agentId     = fagent.id,
                beforeMoney = fagent.cash,
                afterMoney  = fagent.cash + money
            };
            C_UserInfo agentUserInfo = C_UserInfoBLL.SingleModel.GetModel(agent.userId);
            if (agentUserInfo == null)
            {
                fAgengLog.remark = $"代理付费日志出错:找不到代理用户信息 userid:{agent.userId}";
                log4net.LogHelper.WriteInfo(GetType(), fAgengLog.remark);
                tran.Add(BuildAddSql(fAgengLog));
                if (istran)
                {
                    return(true);
                }
                return(ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray));
            }
            fAgengLog.remark = $"{agentUserInfo.NickName}成为{agentLevelConfig.LevelName}代理";

            C_UserInfo fuserInfo = C_UserInfoBLL.SingleModel.GetModel(agent.fuserId);
            if (fuserInfo == null)
            {
                fAgengLog.remark = $"代理付费日志出错:找不到上级代理用户信息 userid:{agent.fuserId}";
                log4net.LogHelper.WriteInfo(GetType(), fAgengLog.remark);
                tran.Add(BuildAddSql(fAgengLog));
                if (istran)
                {
                    return(true);
                }
                return(ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray));
            }
            fAgengLog.remark += $",{fuserInfo.NickName}获得提成{fAgengLog.incomeStr}元";
            tran.Add(BuildAddSql(fAgengLog));

            #region   级分提成日志
            PinAgent grandfatherAgent = PinAgentBLL.SingleModel.GetModelByUserId(fagent.fuserId);

            if (grandfatherAgent != null)
            {
                //表示有上上级 记录分给上上级提成日志

                PinAgentLevelConfig gfagentLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(grandfatherAgent.AgentLevel, grandfatherAgent.aId);
                if (fagentLevelConfig == null || gfagentLevelConfig.SecondAgentExtract <= 0 || (gfagentLevelConfig.AgentExtract + gfagentLevelConfig.SecondAgentExtract) > 1000)
                {
                    log4net.LogHelper.WriteInfo(GetType(), $"上上级代理提成错误:上上级代理商{grandfatherAgent.id}等级找不到或者比例不能分成");
                    return(istran);
                }

                int grandfatherAgentMoney             = pinOrder.money * gfagentLevelConfig.SecondAgentExtract;
                PinAgentIncomeLog grandfatherAgentLog = new PinAgentIncomeLog()
                {
                    aId         = grandfatherAgent.aId,
                    userId      = grandfatherAgent.userId,
                    sourceUid   = agent.userId,
                    income      = grandfatherAgentMoney,
                    source      = 0,
                    ExtractType = 1,
                    agentId     = grandfatherAgent.id,
                    beforeMoney = grandfatherAgent.cash,
                    afterMoney  = grandfatherAgent.cash + grandfatherAgentMoney
                };


                C_UserInfo gfuserInfo = C_UserInfoBLL.SingleModel.GetModel(grandfatherAgent.userId);
                if (gfuserInfo == null)
                {
                    grandfatherAgentLog.remark = $"代理付费日志出错:找不到上上级代理用户信息 userid:{grandfatherAgent.userId}";
                    log4net.LogHelper.WriteError(GetType(), new Exception(grandfatherAgentLog.remark));
                    tran.Add(BuildAddSql(grandfatherAgentLog));
                    if (istran)
                    {
                        return(true);
                    }
                    return(ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray));
                }
                grandfatherAgentLog.remark += $",{gfuserInfo.NickName}获得提成{grandfatherAgentLog.incomeStr}元";
                grandfatherAgentLog.remark += $"{fuserInfo.NickName} 成为代理(下下级)";
                tran.Add(BuildAddSql(grandfatherAgentLog));
            }

            #endregion


            if (istran)
            {
                return(true);
            }
            return(ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray));
        }
Example #15
0
        /// <summary>
        /// 代理提成
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="pinOrder"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public bool UpdateIncome(PinAgent agent, PinGoodsOrder pinOrder, TransactionModel tran = null)
        {
            bool istran = tran != null;

            if (!istran)
            {
                tran = new TransactionModel();
            }

            PinPlatform platform = PinPlatformBLL.SingleModel.GetModelByAid(agent.aId);

            if (platform == null)
            {
                log4net.LogHelper.WriteError(GetType(), new Exception($"代理提成错误:找不到平台信息信息 userid:{agent.fuserId}"));
                return(istran);
            }


            PinAgentLevelConfig agentLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(agent.AgentLevel, agent.aId);

            if (agentLevelConfig == null)
            {
                log4net.LogHelper.WriteInfo(GetType(), $"代理提成错误:当前入驻代理商{agent.id}等级找不到");
                return(istran);
            }

            PinAgent fagent = GetModelByUserId(agent.fuserId);

            if (fagent == null)
            {
                log4net.LogHelper.WriteInfo(GetType(), $"代理提成错误:找不到上级代理信息 userid:{agent.fuserId}");
                return(istran);
            }

            //查找该代理上级所属等级 根据所属等级进行不同比例分成

            PinAgentLevelConfig fagentLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(fagent.AgentLevel, fagent.aId);

            if (fagentLevelConfig == null)
            {
                log4net.LogHelper.WriteInfo(GetType(), $"代理提成错误:上级代理商{fagent.id}等级找不到");
                return(istran);
            }
            int percent = fagentLevelConfig.AgentExtract;

            if (agentLevelConfig.LevelId > fagentLevelConfig.LevelId)
            {
                //表示当前代理商级别高于所属上级代理商级别则按越级比例分配给上级
                percent = platform.JumpExtract;
            }



            //上级代理获得提成
            fagent.cash  += pinOrder.money * percent;
            fagent.money += pinOrder.money * percent;
            tran.Add(BuildUpdateSql(fagent, "cash,money"));


            #region 查找上级代理商是否有上级,如果有上级则上级也要获得抽成
            PinAgent grandfatherAgent = GetModelByUserId(fagent.fuserId);
            if (grandfatherAgent != null)
            {
                //上上级
                PinAgentLevelConfig gfagentLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(grandfatherAgent.AgentLevel, grandfatherAgent.aId);
                if (fagentLevelConfig == null || gfagentLevelConfig.SecondAgentExtract <= 0 || (gfagentLevelConfig.AgentExtract + gfagentLevelConfig.SecondAgentExtract) > 1000)
                {
                    log4net.LogHelper.WriteInfo(GetType(), $"上上级代理提成错误:上上级代理商{grandfatherAgent.id}等级找不到或者比例不能分成");
                    return(istran);
                }

                grandfatherAgent.cash  += pinOrder.money * gfagentLevelConfig.SecondAgentExtract;
                grandfatherAgent.money += pinOrder.money * gfagentLevelConfig.SecondAgentExtract;
                tran.Add(BuildUpdateSql(grandfatherAgent, "cash,money"));
            }
            #endregion



            if (istran)
            {
                return(true);
            }
            return(ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray));
        }
Example #16
0
        /// <summary>
        /// 平台后台-配置代理
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int SetAgent(int aid, int userId, int state, out string msg, int agentMoney = 0)
        {
            int      code  = 0;
            PinAgent agent = null;

            switch (state)
            {
            case 0:    //取消代理
                agent = GetModelByUserId(userId);
                if (agent == null)
                {
                    code = 1;
                    msg  = "操作成功";
                }
                else
                {
                    agent.state = 0;
                    code        = Update(agent, "state") ? 1 : 0;
                    msg         = code == 1 ? "操作成功" : "操作失败";
                }
                break;

            case 1:
                agent = GetModel($"userid={userId}");
                if (agent == null)
                {
                    agent = new PinAgent
                    {
                        aId        = aid,
                        userId     = userId,
                        addTime    = DateTime.Now,
                        state      = 1,
                        AgentLevel = 1,
                        AgentTime  = 1
                    };
                    code = Convert.ToInt32(Add(agent)) > 0 ? 1 : 0;
                    msg  = code == 1 ? "操作成功" : "操作失败";
                }
                else
                {
                    agent.AgentLevel = 1;
                    agent.AgentTime  = 1;
                    agent.addTime    = DateTime.Now;
                    agent.state      = 1;
                    code             = Update(agent, "state,AgentLevel,AgentTime,addTime") ? 1 : 0;
                    msg = code == 1 ? "操作成功" : "操作失败";
                }

                PinGoodsOrder pinOrder = new PinGoodsOrder()
                {
                    money = agentMoney
                };
                TransactionModel  tran = new TransactionModel();
                PinAgentChangeLog pinAgentChangeLog = new PinAgentChangeLog()
                {
                    Aid         = agent.aId,
                    AgentId     = agent.id,
                    ChangeMoney = agentMoney,
                    Remark      = $"成为代理,花费{agentMoney * 0.01}元",
                    ChangeType  = 2,
                    AddTime     = DateTime.Now
                };
                tran.Add(PinAgentChangeLogBLL.SingleModel.BuildAddSql(pinAgentChangeLog));
                UpdateIncome(agent, pinOrder, tran);
                PinAgentIncomeLogBLL.SingleModel.AddAgentLog(agent, pinOrder, tran);    //插入提成日志

                //分提成
                if (!base.ExecuteTransactionDataCorect(tran.sqlArray))
                {
                    agent.state = 0;
                    Update(agent, "state");
                    code = 0;
                    msg  = "代理分成异常";
                }



                break;

            default:
                msg = "参数错误";
                break;
            }
            return(code);
        }
Example #17
0
 public int GetOrderFeedCount(PinGoodsOrder order)
 {
     return(GetOrderFeedCount(order.id, DeliveryOrderType.拼享惠订单商家发货));
 }