Example #1
0
function allmember_changeusersid()
{
    $uid = MooGetGPC('kefuuid', 'integer', 'P');
    $uidarr = isset($_POST['changesid']) && $_POST['changesid'] ? $_POST['changesid'] : array();
    $uidlist = implode(',', $uidarr);
    if (empty($uid) || empty($uidlist)) {
        salert('操作出错,请重试');
        exit;
    }
    //$uidlist .= ',';
    $pre_url = $_POST['pre_url'];
    //正则取得action和h参数,做为记录uid的参数
    //index.php?action=allmember&h=regnoallot_members
    preg_match('/index.php\\?action=([a-zA-z1-9_]*)&h=([a-zA-z1-9_]*)/', $pre_url, $matchs);
    $remember_action = isset($matchs[1]) ? $matchs[1] : 'changeusersid';
    $remember_h = isset($matchs[2]) ? $matchs[2] : '';
    $remember_adminid = in_array($GLOBALS['groupid'], $GLOBALS['admin_service_arr']) ? '0' : $GLOBALS['adminid'];
    $remember_key = $remember_action . '_' . $remember_h . '_' . $remember_adminid;
    /*
    	$sql = "SELECT COUNT(*) c FROM {$GLOBALS['dbTablePre']}member_admininfo ma LEFT JOIN {$GLOBALS['dbTablePre']}members m ON ma.uid=m.uid AND m.uid='{$uid}' AND ma.effect_grade!=10";
    	$kefu_have_members_total = $GLOBALS['_MooClass']['MooMySQL']->getOne($sql);
    */
    $re = $GLOBALS['_MooClass']['MooMySQL']->getOne("SELECT groupid,member_count,allot_member,three_day,seven_day ,allot_time FROM {$GLOBALS['dbTablePre']}admin_user WHERE uid='{$uid}'", true);
    $time = time();
    if (in_array($re['groupid'], $GLOBALS['general_service_pre']) && $re['member_count'] >= 150) {
        //note 普通售前客服分配最大限制数为150
        salert('此客服已经超过了最多150个会员的限制,不能再分配', $pre_url);
        exit;
    }
    if (in_array($re['groupid'], $GLOBALS['admin_service_group']) && $re['member_count'] >= 1000 && $uid != '52' && $uid != '372') {
        //note 销售组长分配最大限制数为1000
        salert('此组长已经超过了最多1000个会员的限制,不能再分配', $pre_url);
        exit;
    }
    $generalmembers = isset($_POST['generalmembers']) ? MooGetGPC('generalmembers', 'string', 'P') : '';
    //note 限制给售后客服分配的高级、钻石会员数量
    //note 该客服的所属groupid组  售后客服限制分配给她的本站注册的高级、钻石会员不超过100
    if ($generalmembers != 'generalmembers') {
        if (in_array($re['groupid'], $GLOBALS['general_service_sale'])) {
            //note 查找该客服下有多少本站注册的钻石、高级会员  未过期的
            /*$sql_sale = "select count(*) count from {$GLOBALS['dbTablePre']}members_search where sid='{$uid}' and s_cid in(20,30) and usertype=1 and endtime>=".$time;
            		$res_sale = $GLOBALS['_MooClass']['MooMySQL']->getOne($sql_sale);
            		$sale_count = $res_sale['count'];*/
            $filter = array();
            $filter[] = array('sid', $uid);
            $filter[] = array('s_cid', '20|30');
            $filter[] = array('usertype', 1);
            $time = time();
            $filter[] = array('endtime', array($time, intval($time) + 3600 * 24 * 365));
            //这里需要区间,时间向后推荐三年
            $limits = array(0, 1);
            $sp = searchApi('members_women members_man');
            $sp->setQueryType(true);
            $sp->getResultOfReset($filter, $limits);
            $sale_count = $sp->getRs('total_found');
            echo "此客服{$uid}下本站注册的钻石、高级会员  未过期的有 " . $sale_count . " 人<br>";
            //$uidlist1 = trim($uidlist,',');
            $uidarr = explode(',', $uidlist);
            $countarr = count($uidarr);
            echo "要分给他的会员数为 " . $countarr . " 人<br>";
            $allcount = $countarr + $sale_count;
            echo "此客服下的会员数将为 " . $allcount . " 人";
            //		echo $allcount;die;
            if ($allcount >= 121) {
                salert('分配给此客服的本站注册的高级、钻石会员已经超过了最多120个会员的限制,不能再分配', $pre_url);
                exit;
            }
        }
    }
    $uidarr = explode(',', $uidlist);
    $len = count($uidarr);
    if (date("m-d", $re['allot_time']) != date("m-d")) {
        $GLOBALS['_MooClass']['MooMySQL']->query("UPDATE {$GLOBALS['dbTablePre']}admin_user SET allot_member=0 WHERE uid='{$uid}'");
        $re['allot_member'] = 0;
    }
    //每天最多可给每个客服分配的会员数量(//note 售后连长 /组长/售后/客服每天分配数不作限制)
    if (in_array($re['groupid'], $GLOBALS['admin_service_manager']) || in_array($re['groupid'], $GLOBALS['admin_service_group']) || in_array($re['groupid'], $GLOBALS['admin_aftersales_service']) || in_array($re['groupid'], $GLOBALS['admin_aftersales_service2'])) {
        $today_total_allot = 99999;
    } elseif (in_array($GLOBALS['groupid'], $GLOBALS['admin_service_arr']) || in_array($GLOBALS['groupid'], $GLOBALS['admin_service_team'])) {
        //客服主管分会员时不要限制
        $today_total_allot = 99999;
    } elseif (in_array($GLOBALS['groupid'], $GLOBALS['admin_service_manager'])) {
        $today_total_allot = 500;
    } elseif (in_array($re['groupid'], $GLOBALS['admin_resource_manager'])) {
        $today_total_allot = 500;
    } else {
        $today_total_allot = 200;
    }
    //今天已经分配给此客服的会员总数---> 30-已分配数-当前正分配数
    $meb = $today_total_allot - $re['allot_member'] - $len;
    if ($meb >= 0) {
        $i = 0;
        //note 分配来源,如果从客服删除会员列表不重复会员数-1
        //$reduce = preg_match("/&h=giveup/",$_SERVER['HTTP_REFERER']);
        //print_r($uidarr);
        echo "<pre>";
        $GLOBALS['_MooClass']['MooMySQL']->query('begin');
        foreach ($uidarr as $v) {
            //已分配会员重新分配给其它客服时,原客服分配总数减去
            $sid_arr = array();
            $sql = "SELECT sid,s_cid from {$GLOBALS['dbTablePre']}members_search where uid='{$v}'";
            $sid_arr = $GLOBALS['_MooClass']['MooMySQL']->getOne($sql, true);
            $sid = $sid_arr['sid'];
            $s_cid = $sid_arr['s_cid'];
            if ($uid == $sid) {
                continue;
            }
            //已经被分配过了给这个客服
            //售前组长和大区不能对售后会员进行分配 主要针对高级搜索的bug处理
            //echo $GLOBALS['username'];exit;
            //if(!preg_match("/^[Vv](\.)*/",$GLOBALS['username']) && $s_cid<40){
            //   salert('您不能分配VIP会员!');exit;
            //   continue;
            //}
            //查询原客服 member_count  status
            $sql = "SELECT member_count FROM {$GLOBALS['dbTablePre']}admin_user WHERE uid = '{$sid}'";
            $uid_info = $GLOBALS['_MooClass']['MooMySQL']->getOne($sql, true);
            if (!empty($sid) && $uid_info['member_count'] > 0) {
                //有问题  原先客服的会员总数减1
                $sql = "UPDATE {$GLOBALS['dbTablePre']}admin_user SET member_count=member_count-1 WHERE uid='{$sid}'";
                $GLOBALS['_MooClass']['MooMySQL']->query($sql);
            }
            //更新members表sid
            $now = time();
            //分配会员更新updatetime
            $sql = "UPDATE {$GLOBALS['dbTablePre']}members_search SET sid='{$uid}'  WHERE uid='{$v}'";
            $a = $GLOBALS['_MooClass']['MooMySQL']->query($sql);
            searchApi('members_man members_women')->updateAttr(array('sid'), array($v => array($uid)));
            sphinx_remember_uids($remember_key, $v);
            //记录更新id
            $sql = "UPDATE {$GLOBALS['dbTablePre']}members_base SET allotdate='{$time}' WHERE uid='{$v}'";
            $a = $GLOBALS['_MooClass']['MooMySQL']->query($sql);
            if (MOOPHP_ALLOW_FASTDB) {
                $value1 = $value2 = array();
                $value1['sid'] = $uid;
                $value1['updatetime'] = $now;
                $value2['allotdate'] = $time;
                MooFastdbUpdate('members_search', 'uid', $v, $value1);
                MooFastdbUpdate('members_base', 'uid', $v, $value2);
            }
            //插入分配记录表
            $sql = "INSERT INTO {$GLOBALS['dbTablePre']}allotuser (uid,sid,allot_sid,allot_con,allot_time) \n\t\t\t\t\tVALUES('{$v}','{$GLOBALS['adminid']}','{$uid}','正常分配给{$uid}号客服','{$time}')";
            $GLOBALS['_MooClass']['MooMySQL']->query($sql);
            //判断member_admininfo表中是否有此会员
            $sql = "SELECT uid FROM {$GLOBALS['dbTablePre']}member_admininfo WHERE uid='{$v}'";
            $temp = $GLOBALS['_MooClass']['MooMySQL']->getOne($sql, true);
            if (empty($temp)) {
                $sql = "INSERT INTO {$GLOBALS['dbTablePre']}member_admininfo SET uid='{$v}',effect_grade=1,allto_time='{$time}'";
            } else {
                //更改为新分客户
                $sql = "UPDATE {$GLOBALS['dbTablePre']}member_admininfo SET effect_grade=1,allto_time='{$time}' WHERE uid='{$v}'";
            }
            $GLOBALS['_MooClass']['MooMySQL']->query($sql);
            unset($temp);
            //更新member_sellinfo表的sid
            //判断member_sellinfo表中是否有此会员的信息
            $sqlsell = "SELECT uid FROM {$GLOBALS['dbTablePre']}member_sellinfo WHERE uid='{$v}'";
            $tempsell = $GLOBALS['_MooClass']['MooMySQL']->getAll($sqlsell, 0, 0, 0, true);
            if (!empty($tempsell)) {
                $sql_sellinfo = "UPDATE {$GLOBALS['dbTablePre']}member_sellinfo SET sid='{$uid}' WHERE uid='{$v}'";
                $GLOBALS['_MooClass']['MooMySQL']->query($sql_sellinfo);
            }
            unset($tempsell);
            //写日志
            serverlog(3, $GLOBALS['dbTablePre'] . 'members', "{$GLOBALS['username']}客服将{$v}会员分配给{$uid}号客服", $GLOBALS['adminid'], $v);
            $i++;
            //note 普通售前客服分配最大限制数为300
            $member_count = $re['member_count'] + $i;
        }
        $GLOBALS['_MooClass']['MooMySQL']->query('commit');
        //更新客服当前分配数及分配总数
        /*$sql1="SELECT count(*) as num from {$GLOBALS['dbTablePre']}members_search where sid='{$uid}'";
        		$new_member_count=$GLOBALS['_MooClass']['MooMySQL']->getOne($sql1);*/
        $filter = array();
        $filter[] = array('sid', $uid);
        $limits = array(0, 1);
        $sp = searchApi('members_women members_man');
        $sp->setQueryType(false);
        $result = $sp->getResultOfReset($filter, $limits);
        $new_member_count = $sp->getRs('total_found');
        $sql = "UPDATE {$GLOBALS['dbTablePre']}admin_user SET allot_member=allot_member+{$i},member_count='{$new_member_count}',allot_time= '{$time}' WHERE uid='{$uid}'";
        $GLOBALS['_MooClass']['MooMySQL']->query($sql);
    } else {
        salert('已超过今天可分配最大数量100个');
        exit;
    }
    $current_total_allo = $re['allot_member'] + $i;
    if ($time >= strtotime('2011-05-01')) {
        $msg = $i < $len ? ',达到240上限' . ($len - $i) . '个未分配。' : '';
    } else {
        $msg = $i < $len ? ',达到300上限' . ($len - $i) . '个未分配。' : '';
    }
    salert("分配成功,今天已分配给此客服会员总数{$current_total_allo}" . $msg, $pre_url);
    exit;
}
Example #2
0
function sphinx_search($filters, $limits, $sorts)
{
    if (isset($filters['uid'])) {
        return array('total' => 0);
    }
    if ($limits[0] + $limits[1] >= 1000) {
        return array('total' => 0);
    }
    $allow_sorts = array('uid', 'birthyear', 'images_ischeck', 'regdate', 'sid', 'is_lock');
    $sort = '';
    if (!empty($sorts)) {
        $sort = str_replace('order by ', '', $sorts);
        $sort_arr = explode(' ', trim($sort));
        if (!in_array($sort_arr[0], $allow_sorts)) {
            return array('total' => 0);
        }
        $sort = str_replace('uid', '@id', $sort);
    }
    $filter = array();
    $index = !isset($filters['gender']) || $filters['gender'] == 3 ? 'members_women  members_man' : ($filters['gender'] == 1 ? 'members_women' : 'members_man');
    unset($filters['gender']);
    foreach ($filters as $key => $value) {
        if (strpos($key, 'in') && strpos($key, '(')) {
            list($key, $value) = explode('in', $key);
            $key = trim($key);
            $value = str_replace(',', '|', str_replace(array('(', ')'), '', $value));
            $filter[] = array($key, $value);
        } else {
            $filter[] = array($key, $value);
        }
    }
    //过滤记忆uid
    if (isset($_GET['h']) && isset($_GET['action'])) {
        $remember_adminid = in_array($GLOBALS['groupid'], $GLOBALS['admin_service_arr']) ? '0' : $GLOBALS['adminid'];
        $uids = sphinx_remember_uids($_GET['action'] . '_' . $_GET['h'] . '_' . $remember_adminid);
        if (!empty($uids)) {
            $filter[] = array('@id', implode('|', $uids), true);
        }
    }
    //exit;
    $sp = searchApi($index);
    $sp->setQueryType(true);
    $sp->getResultOfReset($filter, $limits, $sort);
    $total = $sp->getRs('total_found');
    $member_list = array();
    if ($total > 0 && ($uids = $sp->getIds())) {
        $where = 'where m.uid in (' . implode(',', $uids) . ')';
        $member_list = get_member_list($where, $sorts);
    }
    return array('total' => $total, 'member_list' => $member_list);
}