Exemple #1
0
        //当客户的渠道为0时,随机自动分配一个渠道编号(优先未锁定用户的),sendtype= 当为1的时候 有渠道也发送,一般是点击我的顾问时候发送,0=则是留言的时候变更渠道发送
        public static int AutoFenpeiChannel(int comid, string openid, int sendtype = 1, int companyid = 0, int channleid = 0)
        {
            var            crmdata       = new B2bCrmData();
            MemberCardData carddata      = new MemberCardData();
            var            channeldata   = new MemberChannelData();//读取渠道信息
            decimal        idcard        = 0;
            decimal        channelid     = 0;
            var            userinfo_auto = carddata.GetMemberCardByOpenId(openid);;//获取微信操作账户

            if (userinfo_auto != null)
            {
                idcard    = userinfo_auto.Cardcode;;
                channelid = userinfo_auto.IssueCard;//获取渠道ID
            }

            //判断对 微信注册,网站注册渠道进行归0
            var channeltype = channeldata.GetChannelDetail(int.Parse(channelid.ToString()));

            if (channeltype != null)
            {
                if (channeltype.Issuetype == 3 || channeltype.Issuetype == 4 || channeltype.Name == "默认渠道")
                {//如果渠道时微信注册或网站注册,渠道ID归0,下面自动重新分配有效渠道
                    channelid = 0;
                }
            }

            if (channelid == 0)
            {
                //查询在线渠道列表,
                int totalcount  = 0;                                                                                 //在线数量
                var channellist = channeldata.GetChannelListByComid(comid, companyid, 2, out totalcount, channleid); //先查询渠道列表 锁定客户为空的

                if (channellist != null)
                {
                    if (totalcount > 0)
                    {
                        //随机选择一个渠道
                        Random rand           = new Random();
                        var    channel_temp   = channellist[rand.Next(0, totalcount - 1)];
                        var    channelid_temp = channel_temp.Id;

                        //绑定渠道
                        int upchannel = new MemberCardData().upCardcodeChannel(idcard.ToString(), channelid_temp);
                        channelid = channelid_temp;
                    }
                }
                //只有变更时才发送顾问信息
                Sendweixinchient(openid, comid);
            }
            else
            {
                //点击顾问也发送
                if (sendtype == 1)
                {
                    Sendweixinchient(openid, comid);
                }
            }
            return(int.Parse(channelid.ToString()));
        }