Beispiel #1
0
        /// <summary>
        /// 提现申请界面
        /// </summary>
        /// <param name="aId"></param>
        /// <param name="storeId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        // GET: PinAdmin/Cash
        public ActionResult Index(int aId = 0, int storeId = 0)
        {
            if (aId <= 0 || storeId <= 0)
            {
                return(Content("参数错误"));
            }

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

            if (platform == null)
            {
                return(Content("平台信息错误"));
            }
            PinStore   store    = (PinStore)Request.RequestContext.RouteData.Values["pinStore"];
            C_UserInfo userInfo = C_UserInfoBLL.SingleModel.GetModel(store.userId);

            if (userInfo == null)
            {
                return(Content($"用户信息错误"));
            }

            PinAgent agent = PinAgentBLL.SingleModel.GetModelByUserId(userInfo.Id);

            int sumCash = DrawCashApplyBLL.SingleModel.GetSumCash(aId, store.userId);

            ViewBag.DrawCashSum  = (sumCash * 0.01).ToString("0.00");
            ViewData["platform"] = platform;
            ViewData["userInfo"] = userInfo;
            ViewData["agent"]    = agent;
            return(View(store));
        }
Beispiel #2
0
        public ActionResult MyIncomeList(string phone = "", string testpxhappid = "", int type = 0, int extractType = 0, string utoken = "")
        {
            if (string.IsNullOrEmpty(testpxhappid))
            {
                testpxhappid = _pxhAppId;
            }
            C_UserInfo userinfo = C_UserInfoBLL.SingleModel.GetModelByTelephone_appid(phone, testpxhappid);

            if (userinfo == null)
            {
                return(Content("无效用户"));
            }

            XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(userinfo.appId);

            if (xcxrelation == null)
            {
                return(Content("无效模板"));
            }

            if (string.IsNullOrEmpty(utoken))
            {
                return(Content("utoken无效,请重新登录"));
            }
            //获取登陆秘钥

            ViewBag.utoken = utoken;


            PinAgent agent = PinAgentBLL.SingleModel.GetModelByUserId(userinfo.Id);

            agent.userInfo = userinfo;
            return(View(agent));
        }
Beispiel #3
0
        /// <summary>
        /// 拼享惠代理提现:返回提现金额
        /// </summary>
        /// <param name="apply"></param>
        /// <returns></returns>
        public bool ReturnPinAgentCash(DrawCashApply apply, TransactionModel tranModel = null)
        {
            bool isTran = tranModel != null;

            if (!isTran)
            {
                tranModel = new TransactionModel();
            }
            MySqlParameter[] pone = null;
            tranModel.Add(base.BuildUpdateSql(apply, "drawState,DrawTime,remark,state,UpdateTime", out pone), pone);

            if (apply.appId == WebSiteConfig.GongZhongAppId)
            {
                apply.userId = apply.OrderId;
            }
            PinAgent agent = PinAgentBLL.SingleModel.GetModelByUserId(apply.userId);

            if (agent == null)
            {
                log4net.LogHelper.WriteError(GetType(), new Exception($" 拼享惠代理提现:返回提现金额失败,找不到代理userId:{ apply.userId}"));
                return(false);
            }
            int money = apply.cashMoney + apply.serviceMoney;

            agent.cash += money * 1000;
            pone        = null;
            tranModel.Add(PinAgentBLL.SingleModel.BuildUpdateSql(agent, "cash", out pone), pone);
            if (isTran)
            {
                return(true);
            }
            return(base.ExecuteTransactionDataCorect(tranModel.sqlArray, tranModel.ParameterArray));
        }
Beispiel #4
0
        /// <summary>
        /// 成为代理自动入驻店铺
        /// </summary>
        /// <param name="agent"></param>
        /// <returns></returns>
        public bool AddStore(PinAgent agent)
        {
            C_UserInfo userInfo = C_UserInfoBLL.SingleModel.GetModel(agent.userId);

            if (userInfo == null)
            {
                log4net.LogHelper.WriteError(GetType(), new Exception($"代理缴费自动入驻门店失败:找不到用户信息 userid:{agent.userId}"));
                return(false);
            }
            if (userInfo.StoreId > 0)
            {
                return(true);
            }
            PinStore store = GetModel($"loginName=@loginName and state>-1 and aid={agent.aId}", new MySqlParameter[] {
                new MySqlParameter("@loginName", userInfo.TelePhone)
            });

            if (store != null)
            {
                return(true);
            }
            PinPlatform platform = PinPlatformBLL.SingleModel.GetModelByAid((agent.aId));

            if (platform == null)
            {
                log4net.LogHelper.WriteError(GetType(), new Exception($"代理缴费自动入驻门店失败:平台信息错误 aId:{agent.aId}"));
                return(false);
            }
            PinStore storeInfo = new PinStore
            {
                aId       = agent.aId,
                rz        = 1,
                state     = 1,
                endDate   = DateTime.Now.AddDays(platform.freeDays),
                loginName = userInfo.TelePhone,
                password  = Utility.DESEncryptTools.GetMd5Base32("123456"),
                startDate = DateTime.Now,
                userId    = userInfo.Id,
                phone     = userInfo.TelePhone,
                logo      = userInfo.HeadImgUrl,
                storeName = userInfo.NickName,
            };
            int result = OpenStore(userInfo, storeInfo);

            return(result > 0);
        }
Beispiel #5
0
        /// <summary>
        /// 订单提成日志
        /// </summary>
        /// <param name="store"></param>
        /// <param name="pinOrder"></param>
        /// <param name="tran"></param>
        /// <returns></returns>
        public bool AddAgentLog(PinStore store, int money, PinAgent agent, TransactionModel tran = null, string remark = "", int second = 0)
        {
            bool istran = tran != null;

            if (!istran)
            {
                tran = new TransactionModel();
            }
            PinAgentIncomeLog log = new PinAgentIncomeLog()
            {
                aId       = store.aId,
                agentId   = agent.id,//store.agentId,
                sourceUid = store.userId,
                income    = money,
                source    = 1
            };

            log.remark = $"店铺:{store.storeName} 订单提现,{remark}";

            log.beforeMoney = agent.cash;
            log.afterMoney  = agent.cash + money;
            C_UserInfo fuserInfo = C_UserInfoBLL.SingleModel.GetModel(agent.userId);

            if (fuserInfo == 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));
            }
            string s = second == 1 ? "来自下下级" : string.Empty;

            log.remark += $",{fuserInfo.NickName}获得提成{s}{log.incomeStr}元";
            tran.Add(BuildAddSql(log));

            if (istran)
            {
                return(true);
            }
            return(ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray));
        }
Beispiel #6
0
        public ActionResult TiXian(int id = 0, string openId = "", string phone = "", string testappid = "")
        {
            if (string.IsNullOrEmpty(testappid))
            {
                testappid = _pxhAppId;
            }
            C_UserInfo userinfo = C_UserInfoBLL.SingleModel.GetModelByTelephone_appid(phone, testappid);//_pxhAppId

            if (userinfo == null)
            {
                return(Content("无效用户"));
            }
            if (id <= 0)
            {
                return(Content("无效用户id"));
            }
            userinfo.zbSiteId = id;

            XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(userinfo.appId);

            if (xcxrelation == null)
            {
                return(Content("无效模板"));
            }

            //获取登陆秘钥
            string utoken = CheckLoginClass.GetLoginSessionKey("1", userinfo.OpenId);

            ViewBag.utoken = utoken;

            //是否为代理
            PinAgent agent = PinAgentBLL.SingleModel.GetModelByUserId(userinfo.Id);

            ViewBag.isAgent = agent != null ? 1 : 0;

            //店铺
            PinStore store = PinStoreBLL.SingleModel.GetModelByAid_UserId(xcxrelation.Id, userinfo.Id);

            ViewBag.storeId = store != null ? store.id : 0;

            return(View(userinfo));
        }
Beispiel #7
0
        /// <summary>
        /// 拼享惠代理提现
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="userId"></param>
        /// <param name="account"></param>
        /// <param name="accountName"></param>
        /// <param name="cash"></param>
        /// <param name="drawCashWay"></param>
        /// <param name="serviceFee"></param>
        /// <returns></returns>
        public int PxhAddApply(PinAgent agent, int userId, string account, string accountName, int cash, int drawCashWay, int serviceFee, int xwkjUserId = 0)
        {
            agent.cash -= cash * 1000;
            TransactionModel tran = new TransactionModel();

            MySqlParameter[] pone = null;
            tran.Add(PinAgentBLL.SingleModel.BuildUpdateSql(agent, "cash", out pone), pone);
            int code = 0;
            XcxAppAccountRelation xcx = XcxAppAccountRelationBLL.SingleModel.GetModel(agent.aId);

            if (xcx == null)
            {
                log4net.LogHelper.WriteError(GetType(), new Exception($"拼享惠申请提现失败:小程序信息错误 aid:{agent.aId}"));
                return(code);
            }
            string        partner_trade_no = WxPayApi.GenerateOutTradeNo();
            DrawCashApply apply            = new DrawCashApply()
            {
                Aid              = agent.aId,
                appId            = xwkjUserId == 0 ? xcx.AppId : WebSiteConfig.GongZhongAppId,
                userId           = xwkjUserId == 0 ? userId : xwkjUserId,
                partner_trade_no = partner_trade_no,
                applyMoney       = cash,
                serviceMoney     = serviceFee,
                cashMoney        = cash - serviceFee,
                useCash          = agent.cashStr,
                AddTime          = DateTime.Now,
                remark           = "拼享惠代理商申请提现",
                hostIP           = Utility.WebHelper.GetIP(),
                applyType        = (int)DrawCashApplyType.拼享惠代理收益,
                account          = account,
                accountName      = accountName,
                drawCashWay      = drawCashWay,
                OrderId          = userId,
            };

            tran.Add(BuildAddSql(apply));
            code = base.ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray) ? 1 : 0;
            return(code);
        }
Beispiel #8
0
        public ActionResult AgentTixianRecord(string openId = "", string phone = "", string testpxhappid = "", string utoken = "")
        {
            if (string.IsNullOrEmpty(testpxhappid))
            {
                testpxhappid = _pxhAppId;
            }
            C_UserInfo userinfo = C_UserInfoBLL.SingleModel.GetModelByTelephone_appid(phone, testpxhappid);//_pxhAppId

            if (userinfo == null)
            {
                return(Content("无效用户"));
            }

            XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(userinfo.appId);

            if (xcxrelation == null)
            {
                return(Content("无效模板"));
            }
            if (string.IsNullOrEmpty(utoken))
            {
                return(Content("utoken无效,请重新登录"));
            }

            ViewBag.utoken = utoken;

            PinAgent agent = PinAgentBLL.SingleModel.GetModelByUserId(userinfo.Id);

            agent.userInfo = userinfo;

            PinStore pinStore = PinStoreBLL.SingleModel.GetModelByAid_UserId(agent.aId, agent.userId);

            ViewBag.storeId = pinStore.id;


            return(View(agent));
        }
Beispiel #9
0
        /// <summary>
        /// 申请提现
        /// </summary>
        /// <param name="aId"></param>
        /// <param name="storeId"></param>
        /// <param name="txway"></param>
        /// <param name="cash"></param>
        /// <param name="cashType">0:扫码提现  1:平台提现</param>
        /// <returns></returns>
        public ActionResult AddApply(int aId = 0, int storeId = 0, int txway = -1, int cash = 0, int cashType = (int)DrawCashApplyType.拼享惠平台交易)
        {
            if (aId <= 0 || storeId <= 0)
            {
                result.msg = "参数错误";
                return(Json(result));
            }

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

            if (platform == null)
            {
                result.msg = "平台信息错误";
                return(Json(result));
            }
            PinStore store = PinStoreBLL.SingleModel.GetModelByAid_Id(aId, storeId);

            if (store == null)
            {
                result.msg = "店铺信息错误";
                return(Json(result));
            }
            C_UserInfo userInfo = C_UserInfoBLL.SingleModel.GetModel(store.userId);

            if (userInfo == null)
            {
                result.msg = "用户信息错误";
                return(Json(result));
            }


            if (cash < platform.minTxMoney)
            {
                result.msg = $"提现金额不可低于{platform.minTxMoneyStr}元";
                return(Json(result));
            }
            string account     = string.Empty;
            string accountName = string.Empty;

            switch (txway)
            {
            case 1:    //提现到银行卡
                if (string.IsNullOrEmpty(store.bankcardName))
                {
                    result.msg = "请设置银行卡账户名称";
                    return(Json(result));
                }
                accountName = store.bankcardName;
                if (string.IsNullOrEmpty(store.bankcardNum))
                {
                    result.msg = "请设置银行卡账户";
                    return(Json(result));
                }
                if (platform.toBank != 1)
                {
                    result.msg = "暂时无法通过银行卡提现";
                    return(Json(result));
                }
                account = store.bankcardNum;
                break;

            case 0:    //提现到微信
                if (platform.toWx != 1)
                {
                    result.msg = "暂时无法通过微信提现";
                    return(Json(result));
                }
                accountName = "微信账号";
                account     = userInfo.NickName;
                break;

            default:
                result.msg = "参数错误";
                return(Json(result));
            }

            int serviceFee = cash * platform.serviceFee / 1000;

            switch (cashType)
            {
            case (int)DrawCashApplyType.拼享惠平台交易:
                if (cash > store.cash && cashType == (int)DrawCashApplyType.拼享惠平台交易)
                {
                    result.msg = "超出可提现金额";
                    return(Json(result));
                }
                double fee = cash * platform.serviceFee * 0.001;
                serviceFee  = (int)Math.Ceiling(fee);
                result.code = DrawCashApplyBLL.SingleModel.PxhAddApply(store, userInfo.Id, account, accountName, cash, txway, serviceFee, (int)DrawCashApplyType.拼享惠平台交易);
                break;

            case (int)DrawCashApplyType.拼享惠代理收益:

                PinAgent agent = PinAgentBLL.SingleModel.GetModelByUserId(userInfo.Id);
                if (agent == null)
                {
                    result.msg = "你还不是代理";
                    return(Json(result));
                }
                if (cash * 1000 > agent.cash)
                {
                    result.msg = "超出可提现金额";
                    return(Json(result));
                }
                fee         = cash * platform.agentServiceFee * 0.001;
                serviceFee  = (int)Math.Ceiling(fee);
                result.code = DrawCashApplyBLL.SingleModel.PxhAddApply(agent, userInfo.Id, account, accountName, cash, txway, serviceFee);
                break;

            case (int)DrawCashApplyType.拼享惠扫码收益:
                if (cash > store.qrcodeCash && cashType == (int)DrawCashApplyType.拼享惠扫码收益)
                {
                    result.msg = "超出可提现金额";
                    return(Json(result));
                }
                fee         = cash * platform.qrcodeServiceFee * 0.001;
                serviceFee  = (int)Math.Ceiling(fee);
                result.code = DrawCashApplyBLL.SingleModel.PxhAddApply(store, userInfo.Id, account, accountName, cash, txway, serviceFee, (int)DrawCashApplyType.拼享惠扫码收益);
                break;

            default:
                result.msg = "参数错误";
                return(Json(result));
            }

            //result.code = drawCashApplyBLL.PxhAddApply(store, userInfo.Id, account, accountName, cash, txway, serviceFee, 0);
            result.msg = result.code == 1 ? "申请已提交" : "提交失败";
            return(Json(result));
        }
Beispiel #10
0
        public ActionResult PayRecords(string act = "", int aId = 0, int pageIndex = 0, int pageSize = 10, int recordType = 0, string storePhone = "",
            string payUserPhone = "",
            string transaction_id = "",
            string out_trade_no = "",
            int parentAgentId = 0)
        {
            pageIndex -= 1;
            if (pageIndex < 0)
                pageIndex = 0;

            if (string.IsNullOrEmpty(act))
            {

                string fieldSql = $@" 

p.transaction_id,
p.out_trade_no,
p.time_end,
p.total_fee,

c.TuserId,
c.orderno,
c.ShowNote,
c.id as CityMordersId,

s.storename,
s.phone as StoreUserPhone,

go.ordertype,
go.goodsid as GoodsOrderGoodsId,

fu.id as payUserId,
fu.NickName as payusername,
fu.telephone as PayUserPhone,
su.NickName as storeUserName,
su.Id as storeUserId,
g.name as goodsname,
g.id as goodsid,
g.img as goodsimg
";
                if (parentAgentId > 0)
                {
                    fieldSql += ",aa.fuserid";
                }

                string fromSql = $@"
from payresult p LEFT  JOIN citymorders c on p.out_trade_no = c.orderno
LEFT JOIN c_userinfo fu on c.FuserId = fu.Id
LEFT JOIN pinstore s on c.TuserId = s.id
LEFT JOIN c_userinfo su on s.userid = su.id
LEFT JOIN pingoodsorder go on c.id=go.payno
LEFT JOIN pingoods g on go.goodsid=g.id

";
                if (parentAgentId > 0)
                {
                    fromSql += " LEFT JOIN pinagent aa on fu.id=aa.userid ";
                }
                List<MySqlParameter> parameters = new List<MySqlParameter>();
                string whereSql = $" c.ActionType ='{(int)ArticleTypeEnum.PinOrderPay}' and go.aid={aId} ";
                if (recordType == 1)
                    whereSql += " and go.ordertype=1 ";
                else if (recordType == 2)
                    whereSql += " and go.ordertype=0 ";
                if (!string.IsNullOrEmpty(payUserPhone))
                {
                    whereSql += $" and fu.telephone=@PayUserPhone";
                    parameters.Add(new MySqlParameter("@PayUserPhone", payUserPhone));
                }
                if (!string.IsNullOrEmpty(storePhone))
                {
                    whereSql += " and s.phone=@StoreUserPhone";
                    parameters.Add(new MySqlParameter("@StoreUserPhone", storePhone));
                }
                if (!string.IsNullOrEmpty(transaction_id))
                {
                    whereSql += " and p.transaction_id=@transaction_id";
                    parameters.Add(new MySqlParameter("@transaction_id", transaction_id));
                }
                if (!string.IsNullOrEmpty(out_trade_no))
                {
                    whereSql += " and p.out_trade_no=@out_trade_no";
                    parameters.Add(new MySqlParameter("@out_trade_no", out_trade_no));
                }
                if (parentAgentId > 0)
                {
                    whereSql += " and go.ordertype=1  and  aa.fuserid=" + parentAgentId;//and aa.state=1
                }

                string orderSql = " order by p.id desc ";
                string pagerSql = $" limit {pageSize * pageIndex},{pageSize} ";

                string querySql = $" select distinct {fieldSql} {fromSql} where {whereSql} {orderSql} {pagerSql}";
                string countSql = $" select distinct count(0) {fromSql} where {whereSql}";



                List<PayRecordModel> list = DataHelper.ConvertDataTableToList<PayRecordModel>(SqlMySql.ExecuteDataSet(Utility.dbEnum.MINIAPP.ToString(), System.Data.CommandType.Text, querySql, parameters.ToArray()).Tables[0]);

                string goodsIds = string.Join(",",list?.Select(s=>s.GoodsId).Distinct());
                List<PinGoods> pinGoodsList = PinGoodsBLL.SingleModel.GetListByIds(goodsIds);
                list?.ForEach(p =>
                {
                    p.OrderGoods = pinGoodsList?.FirstOrDefault(f=>f.id ==p.GoodsId);
                    if (p.OrderType == 1)
                    {
                        PinAgent agentInfo = PinAgentBLL.SingleModel.GetModelByUserId(p.PayUserId);
                        if (agentInfo != null && agentInfo.fuserId > 0)
                        {
                            p.ParentAgentUser = C_UserInfoBLL.SingleModel.GetModel(agentInfo.fuserId);
                            p.ParentAgentStore = PinStoreBLL.SingleModel.GetModelByAid_Id(agentInfo.aId, agentInfo.fuserId);
                        }

                    }

                });
                ViewModel<PayRecordModel> vm = new ViewModel<PayRecordModel>();
                vm.DataList = list;
                vm.aId = aId;
                vm.PageSize = pageSize;
                vm.PageIndex = pageIndex;
                vm.TotalCount = PayResultBLL.SingleModel.GetCountBySql(countSql, parameters.ToArray());
                return View(vm);
            }
            return View();
        }
Beispiel #11
0
        public ActionResult UpdateAgentLevel()
        {
            int aid        = Utility.IO.Context.GetRequestInt("aid", 0);
            int agentLevel = Utility.IO.Context.GetRequestInt("agentLevel", 0);
            int agentId    = Utility.IO.Context.GetRequestInt("agentId", 0);
            int agentFee   = Utility.IO.Context.GetRequestInt("agentFee", 0);

            if (aid <= 0 || agentId <= 0)
            {
                result.code = 0;
                result.msg  = "参数错误";
                return(Json(result));
            }
            XcxAppAccountRelation xcxAppAccountRelation = XcxAppAccountRelationBLL.SingleModel.GetModel(aid);

            if (xcxAppAccountRelation == null)
            {
                result.code = 0;
                result.msg  = "小程序不存在";
                return(Json(result));
            }

            PinAgent pinAgent = PinAgentBLL.SingleModel.GetModel(agentId);

            if (pinAgent == null)
            {
                result.code = 0;
                result.msg  = "代理商不存在";
                return(Json(result));
            }
            if (pinAgent.state == 0)
            {
                result.code = 0;
                result.msg  = "代理商不可用";
                return(Json(result));
            }
            int      oldAgentLevel = pinAgent.AgentLevel;//保存之前的等级
            DateTime oldAddtime    = pinAgent.addTime;

            pinAgent.AgentLevel = agentLevel;
            pinAgent.addTime    = DateTime.Now;
            PinAgentLevelConfig pinAgentLevel = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(agentLevel, aid);

            if (pinAgentLevel == null)
            {
                result.code = 0;
                result.msg  = "升级的等级不存在";
                return(Json(result));
            }
            if (pinAgentLevel.State == -1)
            {
                result.code = 0;
                result.msg  = "升级的等级被删除了";
                return(Json(result));
            }
            agentFee = agentFee < 0 ? pinAgentLevel.AgentFee : agentFee;

            if (!PinAgentBLL.SingleModel.UpdateAgentLevel(pinAgent, agentFee, oldAgentLevel, oldAddtime))
            {
                result.code = 0;
                result.msg  = "升级失败";
                return(Json(result));
            }

            result.code = 1;
            result.msg  = "升级成功";
            return(Json(result));
        }
Beispiel #12
0
        /// <summary>
        /// 获取代理商列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetAgentList()
        {
            int    aid       = Utility.IO.Context.GetRequestInt("aid", 0);
            int    pageIndex = Utility.IO.Context.GetRequestInt("pageIndex", 1);
            int    pageSize  = Utility.IO.Context.GetRequestInt("pageSize", 10);
            string nickName  = Utility.IO.Context.GetRequest("nickName", string.Empty);
            string phone     = Utility.IO.Context.GetRequest("phone", string.Empty);
            string fnickName = Utility.IO.Context.GetRequest("fnickName", string.Empty);
            string fphone    = Utility.IO.Context.GetRequest("fphone", string.Empty);

            if (aid <= 0)
            {
                result.code = 0;
                result.msg  = "参数错误";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            XcxAppAccountRelation xcxAppAccountRelation = XcxAppAccountRelationBLL.SingleModel.GetModel(aid);

            if (xcxAppAccountRelation == null)
            {
                result.code = 0;
                result.msg  = "小程序不存在";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            int recordCount = 0;


            List <PinAgent> agentList = PinAgentBLL.SingleModel.GetListByAid_State(xcxAppAccountRelation.AppId, aid, pageSize, pageIndex, out recordCount, phone: phone, nickName: nickName, fnickName: fnickName, fphone: fphone);

            if (agentList != null && agentList.Count > 0)
            {
                string userIds  = string.Join(",", agentList.Select(s => s.userId).Distinct());
                string fuserIds = string.Join(",", agentList.Where(w => w.fuserId > 0)?.Select(s => s.fuserId).Distinct());
                if (!string.IsNullOrEmpty(fuserIds))
                {
                    if (!string.IsNullOrEmpty(userIds))
                    {
                        userIds = userIds + "," + fuserIds;
                    }
                    else
                    {
                        userIds = fuserIds;
                    }
                }
                List <C_UserInfo> userInfoList = C_UserInfoBLL.SingleModel.GetListByIds(userIds);
                agentList.ForEach(x =>
                {
                    C_UserInfo userInfo = userInfoList?.FirstOrDefault(f => f.Id == x.userId);
                    if (userInfo != null)
                    {
                        x.userInfo = userInfo;
                    }

                    PinAgentLevelConfig pinAgentLevel = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(x.AgentLevel, aid);
                    if (pinAgentLevel != null)
                    {
                        x.AgentLevelName = pinAgentLevel.LevelName;
                        x.AgentLevelTimeList.Add(new { Time = -1, Txt = "请选择", Money = 0 });
                        x.AgentLevelTimeList.Add(new { Time = 1, Txt = "1年", Money = pinAgentLevel.AgentFee * 0.01 });
                        x.AgentLevelTimeList.Add(new { Time = 2, Txt = "2年", Money = pinAgentLevel.AgentFee * 0.01 * 2 });
                        x.AgentLevelTimeList.Add(new { Time = 3, Txt = "3年", Money = pinAgentLevel.AgentFee * 0.01 * 3 });
                        x.AgentLevelTimeList.Add(new { Time = 4, Txt = "4年", Money = pinAgentLevel.AgentFee * 0.01 * 4 });
                        x.AgentLevelTimeList.Add(new { Time = 5, Txt = "5年", Money = pinAgentLevel.AgentFee * 0.01 * 5 });
                    }


                    if (x.fuserId > 0)
                    {
                        PinAgentDec pinAgentDec = new PinAgentDec();

                        C_UserInfo fuserInfo = userInfoList?.FirstOrDefault(f => f.Id == x.fuserId);
                        if (fuserInfo != null)
                        {
                            pinAgentDec.UserId   = fuserInfo.Id;
                            pinAgentDec.UserName = fuserInfo.NickName;
                            pinAgentDec.Phone    = fuserInfo.TelePhone;
                        }

                        PinAgent fpinAgent = PinAgentBLL.SingleModel.GetModelByUserId(x.fuserId);
                        if (fpinAgent != null)
                        {
                            PinAgentLevelConfig pinFAgentLevel = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(fpinAgent.AgentLevel, aid);
                            if (pinFAgentLevel != null)
                            {
                                pinAgentDec.AgentLevelName = pinFAgentLevel.LevelName;
                                pinAgentDec.AgentLevel     = pinFAgentLevel.LevelId;
                            }
                        }

                        x.pinAgentDec = pinAgentDec;
                    }

                    x.TotalAgentMoney = PinAgentBLL.SingleModel.GetAgentFee(x.id);
                });
            }


            result.code = 1;
            result.obj  = new { list = agentList, recordCount };
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #13
0
        public ActionResult AddAgentTime()
        {
            int aid        = Utility.IO.Context.GetRequestInt("aid", 0);
            int timeLength = Utility.IO.Context.GetRequestInt("timeLength", 0);
            int agentId    = Utility.IO.Context.GetRequestInt("agentId", 0);

            if (aid <= 0 || agentId <= 0 || timeLength <= 0)
            {
                result.code = 0;
                result.msg  = "参数错误";
                return(Json(result));
            }
            XcxAppAccountRelation xcxAppAccountRelation = XcxAppAccountRelationBLL.SingleModel.GetModel(aid);

            if (xcxAppAccountRelation == null)
            {
                result.code = 0;
                result.msg  = "小程序不存在";
                return(Json(result));
            }

            PinAgent pinAgent = PinAgentBLL.SingleModel.GetModel(agentId);

            if (pinAgent == null)
            {
                result.code = 0;
                result.msg  = "代理商不存在";
                return(Json(result));
            }
            if (pinAgent.state == 0)
            {
                result.code = 0;
                result.msg  = "代理商不可用";
                return(Json(result));
            }


            PinAgentLevelConfig pinAgentLevel = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(pinAgent.AgentLevel, aid);

            if (pinAgentLevel == null)
            {
                result.code = 0;
                result.msg  = "续期失败,代理商的等级不存在";
                return(Json(result));
            }
            if (pinAgentLevel.State == -1)
            {
                result.code = 0;
                result.msg  = "续期失败,代理商的等级被删除了";
                return(Json(result));
            }

            if (!PinAgentBLL.SingleModel.AddAgentTime(pinAgent, pinAgentLevel.AgentFee * timeLength, timeLength))
            {
                result.code = 0;
                result.msg  = "续期失败";
                return(Json(result));
            }



            result.code = 1;
            result.msg  = "续期成功";
            return(Json(result));
        }
Beispiel #14
0
        public ActionResult MyAgentInfo(int id = 0, string openId = "", string phone = "", string testpxhappid = "", string utoken = "")
        {
            if (string.IsNullOrEmpty(testpxhappid))
            {
                testpxhappid = _pxhAppId;
            }
            C_UserInfo userinfo = C_UserInfoBLL.SingleModel.GetModelByTelephone_appid(phone, testpxhappid);//_pxhAppId

            if (userinfo == null)
            {
                return(Content("无效用户"));
            }

            XcxAppAccountRelation xcxrelation = XcxAppAccountRelationBLL.SingleModel.GetModelByAppid(userinfo.appId);

            if (xcxrelation == null)
            {
                return(Content("无效模板"));
            }

            if (id <= 0)
            {
                return(Content("无效用户id"));
            }

            //获取登陆秘钥
            utoken = CheckLoginClass.GetLoginSessionKey("1", userinfo.OpenId);


            if (string.IsNullOrEmpty(utoken))
            {
                return(Content("utoken无效,请重新登录"));
            }

            PinAgent agent = PinAgentBLL.SingleModel.GetModelByUserId(userinfo.Id);

            userinfo.zbSiteId = id;
            agent.userInfo    = userinfo;

            agent.First = new AgentDistributionDetail()
            {
                AgentCount    = PinAgentBLL.SingleModel.GetAgentCount(agent.aId, agent.userId, 0),
                AgentSumMoney = PinAgentIncomeLogBLL.SingleModel.GetIncomeSum(agent.id, 0, 0),
                OrderSum      = PinAgentIncomeLogBLL.SingleModel.GetIncomeSum(agent.id, 1, 0),
                StoreCount    = PinStoreBLL.SingleModel.GetStoreCount(agent.id, 0)
            };

            agent.Second = new AgentDistributionDetail()
            {
                AgentCount    = PinAgentBLL.SingleModel.GetAgentCount(agent.aId, agent.userId, 1),
                AgentSumMoney = PinAgentIncomeLogBLL.SingleModel.GetIncomeSum(agent.id, 0, 1),
                OrderSum      = PinAgentIncomeLogBLL.SingleModel.GetIncomeSum(agent.id, 1, 1),
                StoreCount    = PinStoreBLL.SingleModel.GetStoreCount(agent.id, 1)
            };
            PinAgentLevelConfig pinAgentLevelConfig = PinAgentLevelConfigBLL.SingleModel.GetPinAgentLevelConfig(agent.AgentLevel, agent.aId);

            if (pinAgentLevelConfig != null)
            {
                agent.AgentLevelName = pinAgentLevelConfig.LevelName;//等级名称
            }


            ViewBag.utoken = utoken;
            ViewBag.openId = openId;
            return(View(agent));
        }
Beispiel #15
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));
        }