Пример #1
0
 public function execute($_addons = null, $_controller = null, $_action = null)
 {
     if (!empty($_action) && !empty($_addons) && empty($_controller)) {
         $_controller = $_GET['_controller'] = $_addons;
         $_REQUEST['_controller'] = $_REQUEST['_addons'];
     }
     if (C('URL_CASE_INSENSITIVE')) {
         $_addons = ucfirst(parse_name($_addons, 1));
         $_controller = parse_name($_controller, 1);
     }
     define('ADDON_PUBLIC_PATH', __ROOT__ . '/Addons/' . $_addons . '/View/default/Public');
     defined('_ADDONS') or define('_ADDONS', $_addons);
     defined('_CONTROLLER') or define('_CONTROLLER', $_controller);
     defined('_ACTION') or define('_ACTION', $_action);
     $token = get_token();
     if (in_array($_action, array('lists', 'config', 'nulldeal')) && (empty($token) || $token == '-1')) {
         $this->error('请先增加公众号!', U('Home/MemberPublic/lists'));
     }
     $this->_nav();
     if (!empty($_addons) && !empty($_controller) && !empty($_action)) {
         tongji($_addons);
         A("Addons://{$_addons}/{$_controller}")->{$_action}();
     } else {
         $this->error('没有指定插件名称,控制器或操作!');
     }
 }
 private function reply($data, $weixin)
 {
     $key = $data['Content'];
     $keywordArr = array();
     // 插件权限控制
     $token_status = D('Common/AddonStatus')->getList();
     foreach ($token_status as $a => $s) {
         $s == 1 || ($forbit_addon[$a] = $a);
     }
     // 所有安装过的微信插件
     $addon_list = (array) D('Addons')->getWeixinList(false, $token_status);
     /**
      * 通过微信事件来定位处理的插件
      * event可能的值:
      * subscribe : 关注公众号
      * unsubscribe : 取消关注公众号
      * scan : 扫描带参数二维码事件
      * click : 自定义菜单事件
      */
     if ($data['MsgType'] == 'event') {
         $event = strtolower($data['Event']);
         foreach ($addon_list as $vo) {
             require_once ONETHINK_ADDON_PATH . $vo['name'] . '/Model/WeixinAddonModel.class.php';
             $model = D('Addons://' . $vo['name'] . '/WeixinAddon');
             !method_exists($model, $event) || $model->{$event}($data);
         }
         if ($event == 'subscribe') {
             $config = getAddonConfig('Wecome');
             if ($config['type'] == 2) {
                 $key = $data['Content'] = $config['keyword'];
             }
         } else {
             if ($event == 'click' && !empty($data['EventKey'])) {
                 $key = $data['Content'] = $data['EventKey'];
             } else {
                 return true;
             }
         }
     }
     // location : 上报地理位置事件 感谢网友【blue7wings】和【strivi】提供的方案
     if ($data['MsgType'] == 'location') {
         $event = strtolower($data['MsgType']);
         foreach ($addon_list as $vo) {
             require_once ONETHINK_ADDON_PATH . $vo['name'] . '/Model/WeixinAddonModel.class.php';
             $model = D('Addons://' . $vo['name'] . '/WeixinAddon');
             !method_exists($model, $event) || $model->{$event}($data);
         }
     }
     // 通过获取上次缓存的用户状态来定位处理的插件
     $openid = $data['FromUserName'];
     $user_status = S('user_status_' . $openid);
     $accept = $user_status['keywordArr']['accept'];
     if ($accept['type'] == 'regex' && !preg_match($accept['data'], $key) || $accept['type'] == 'array' && !in_array($key, $accept['data'])) {
         $user_status = false;
         S('user_status_' . $openid, null);
         // 可设置规定只能接收某些值,如果用户输入的内容不是规定的值,则放弃当前状态,支持正则和数组两种规定方式
     }
     if (!isset($addons[$key]) && $user_status) {
         $addons[$key] = $user_status['addon'];
         $keywordArr = $user_status['keywordArr'];
         S('user_status_' . $openid, null);
     }
     // 通过插件标识名、插件名或者自定义关键词来定位处理的插件
     if (!isset($addons[$key])) {
         foreach ($addon_list as $k => $vo) {
             $addons[$vo['name']] = $k;
             $addons[$vo['title']] = $k;
             $path = ONETHINK_ADDON_PATH . $vo['name'] . '/keyword.php';
             if (file_exists($path)) {
                 $keywords = (include $path);
                 if (isset($keywords[$key])) {
                     $addons[$key] = $k;
                     $keywordArr = $keywords[$key];
                 }
             }
         }
     }
     // 通过精准关键词来定位处理的插件 token=0是插件安装时初始化的模糊关键词,所有公众号都可以用
     if (!empty($forbit_addon)) {
         $like['addon'] = array('not in', $forbit_addon);
     }
     $like['token'] = array('exp', "='0' or token='{$this->token}'");
     if (!isset($addons[$key])) {
         $like['keyword'] = $key;
         $like['keyword_type'] = 0;
         $keywordArr = M('keyword')->where($like)->order('id desc')->find();
         addWeixinLog(M()->getLastSql(), 'addon1');
         if (!empty($keywordArr['addon'])) {
             $addons[$key] = $keywordArr['addon'];
             $this->request_count($keywordArr);
         }
     }
     // 通过模糊关键词来定位处理的插件
     if (!isset($addons[$key])) {
         unset($like['keyword']);
         $like['keyword_type'] = array('gt', 0);
         $list = M('keyword')->where($like)->order('keyword_length desc, id desc')->select();
         foreach ($list as $keywordInfo) {
             $this->_contain_keyword($keywordInfo, $key, $addons, $keywordArr);
         }
     }
     addWeixinLog(M()->getLastSql(), 'addon2');
     // 通过通配符,查找默认处理方式
     // by 肥仔聪要淡定 2014.6.8
     if (!isset($addons[$key])) {
         unset($like['keyword_type']);
         $like['keyword'] = '*';
         $keywordArr = M('keyword')->where($like)->order('id desc')->find();
         if (!empty($keywordArr['addon'])) {
             $addons[$key] = $keywordArr['addon'];
             $this->request_count($keywordArr);
         }
     }
     addWeixinLog(M()->getLastSql(), 'addon3');
     // 以上都无法定位插件时,如果开启了智能聊天,则默认使用智能聊天插件
     if (!isset($addons[$key]) && isset($addon_list['Chat'])) {
         // 您问我答插件特殊处理
         $YouaskServiceconfig = getAddonConfig('YouaskService');
         // 获取后台插件的配置参数
         if ($YouaskServiceconfig['state'] == 1) {
             $addons[$key] = 'YouaskService';
         } else {
             $addons[$key] = 'Chat';
         }
     }
     // 最终也无法定位到插件,终止操作
     if (!isset($addons[$key]) || !file_exists(ONETHINK_ADDON_PATH . $addons[$key] . '/Model/WeixinAddonModel.class.php')) {
         return false;
     }
     addWeixinLog($addons[$key], 'addon2');
     // 加载相应的插件来处理并反馈信息
     require_once ONETHINK_ADDON_PATH . $addons[$key] . '/Model/WeixinAddonModel.class.php';
     $model = D('Addons://' . $addons[$key] . '/WeixinAddon');
     $model->reply($data, $keywordArr);
     // 运营统计
     tongji($addons[$key]);
 }
Пример #3
0
 private function reply($data, $weixin)
 {
     $key = $data['Content'];
     $keywordArr = array();
     // 插件权限控制
     $token_status = D('Common/AddonStatus')->getList();
     foreach ($token_status as $a => $s) {
         $s == 1 || ($forbit_addon[$a] = $a);
     }
     // 所有安装过的微信插件
     $addon_list = (array) D('Addons')->getWeixinList(false, $token_status);
     /**
      * 通过微信事件来定位处理的插件
      * event可能的值:
      * subscribe : 关注公众号
      * unsubscribe : 取消关注公众号
      * scan : 扫描带参数二维码事件
      * location : 上报地理位置事件
      * click : 自定义菜单事件
      */
     if ($data['MsgType'] == 'event') {
         $event = strtolower($data['Event']);
         foreach ($addon_list as $vo) {
             require_once ONETHINK_ADDON_PATH . $vo['name'] . '/Model/WeixinAddonModel.class.php';
             $model = D('Addons://' . $vo['name'] . '/WeixinAddon');
             !method_exists($model, $event) || $model->{$event}($data);
         }
         if ($event == 'click' && !empty($data['EventKey'])) {
             $key = $data['Content'] = $data['EventKey'];
         } else {
             return true;
         }
     }
     // 通过获取上次缓存的用户状态来定位处理的插件
     $openid = $data['FromUserName'];
     $user_status = S('user_status_' . $openid);
     $accept = $user_status['keywordArr']['accept'];
     if ($accept['type'] == 'regex' && !preg_match($accept['data'], $key) || $accept['type'] == 'array' && !in_array($key, $accept['data'])) {
         $user_status = false;
         S('user_status_' . $openid, null);
         // 可设置规定只能接收某些值,如果用户输入的内容不是规定的值,则放弃当前状态,支持正则和数组两种规定方式
     }
     if (!isset($addons[$key]) && $user_status) {
         $addons[$key] = $user_status['addon'];
         $keywordArr = $user_status['keywordArr'];
         S('user_status_' . $openid, null);
     }
     // 通过插件标识名和插件名来定位处理的插件
     if (!isset($addons[$key])) {
         foreach ($addon_list as $k => $vo) {
             $addons[$vo['name']] = $k;
             $addons[$vo['title']] = $k;
         }
     }
     // 通过精准关键词来定位处理的插件 token=0是插件安装时初始化的模糊关键词,所有公众号都可以用
     if (!empty($forbit_addon)) {
         $like['addon'] = array('not in', $forbit_addon);
     }
     $like['token'] = array('exp', "=0 or token='{$this->token}'");
     if (!isset($addons[$key])) {
         $like['keyword'] = $key;
         $like['keyword_type'] = 0;
         $keywordArr = M('keyword')->where($like)->order('id desc')->find();
         $addons[$key] = $keywordArr['addon'];
     }
     // 通过模糊关键词来定位处理的插件
     if (!isset($addons[$key])) {
         unset($like['keyword']);
         $like['keyword_type'] = array('gt', 0);
         $list = M('keyword')->where($like)->order('keyword_length desc, id desc')->select();
         foreach ($list as $keywordInfo) {
             $this->_contain_keyword($keywordInfo, $key, $addons, $keywordArr);
         }
     }
     // 以上都无法定位插件时,如果开启了智能聊天,则默认使用智能聊天插件
     if (!isset($addons[$key]) && isset($addon_list['Chat'])) {
         $addons[$key] = 'Chat';
     }
     // 最终也无法定位到插件,终止操作
     if (!isset($addons[$key]) || !file_exists(ONETHINK_ADDON_PATH . $addons[$key] . '/Model/WeixinAddonModel.class.php')) {
         return false;
     }
     // 加载相应的插件来处理并反馈信息
     require_once ONETHINK_ADDON_PATH . $addons[$key] . '/Model/WeixinAddonModel.class.php';
     $model = D('Addons://' . $addons[$key] . '/WeixinAddon');
     $model->reply($data, $keywordArr);
     //运营统计
     tongji($addons[$key]);
 }
Пример #4
0
/**
 *
 *
 * @access  public
 * @param
 *
 * @return void
 */
function account_list()
{
    $result = get_filter();
    if ($result === false) {
        /*add by hg for date 2014-04-23 获取代理商信息 begin*/
        $filter['admin_agency_id'] = !empty($_REQUEST['admin_agency_id']) ? intval($_REQUEST['admin_agency_id']) : 0;
        $GLOBALS['smarty']->assign('agency_list', agency_list());
        $GLOBALS['smarty']->assign('admin_agency_id', $filter['admin_agency_id']);
        $action_list = if_agency() ? 'all' : '';
        $GLOBALS['smarty']->assign('all', $action_list);
        /*end*/
        /*时间*/
        //dump($filter);
        /* 过滤列表 */
        $filter['user_id'] = !empty($_REQUEST['user_id']) ? intval($_REQUEST['user_id']) : 0;
        $filter['keywords'] = empty($_REQUEST['keywords']) ? '' : trim($_REQUEST['keywords']);
        if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1) {
            $filter['keywords'] = json_str_iconv($filter['keywords']);
        }
        $filter['process_type'] = isset($_REQUEST['process_type']) ? intval($_REQUEST['process_type']) : -1;
        $filter['payment'] = empty($_REQUEST['payment']) ? '' : trim($_REQUEST['payment']);
        $filter['is_paid'] = isset($_REQUEST['is_paid']) ? intval($_REQUEST['is_paid']) : -1;
        $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'add_time' : trim($_REQUEST['sort_by']);
        $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
        $filter['start_date'] = empty($_REQUEST['start_date']) ? local_strtotime('-7 days') : $_REQUEST['start_date'];
        $filter['end_date'] = empty($_REQUEST['end_date']) ? local_strtotime('today') : $_REQUEST['end_date'];
        if (strpos($filter['start_date'], '-')) {
            $filter['start_date'] = local_strtotime($filter['start_date']);
            $filter['end_date'] = local_strtotime($filter['end_date']);
        }
        $where = " WHERE 1 ";
        /*add by hg for date 2014-04-22 只显示代理商本身所属信息 begin*/
        $where .= agency_where();
        /*end*/
        if ($filter['user_id'] > 0) {
            $where .= " AND ua.user_id = '{$filter['user_id']}' ";
        }
        if ($filter['process_type'] != -1) {
            $where .= " AND ua.process_type = '{$filter['process_type']}' ";
        } else {
            $where .= " AND ua.process_type " . db_create_in(array(SURPLUS_SAVE, SURPLUS_RETURN));
        }
        if ($filter['payment']) {
            $where .= " AND ua.payment = '{$filter['payment']}' ";
        }
        if ($filter['is_paid'] != -1) {
            $where .= " AND ua.is_paid = '{$filter['is_paid']}' ";
        }
        if ($filter['keywords']) {
            $where .= " AND u.user_name LIKE '%" . mysql_like_quote($filter['keywords']) . "%'";
            $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('user_account') . " AS ua, " . $GLOBALS['ecs']->table('users') . " AS u " . $where;
        }
        /* 时间过滤 */
        if (!empty($filter['start_date']) && !empty($filter['end_date'])) {
            $where .= "AND add_time >= " . $filter['start_date'] . " AND add_time < '" . $filter['end_date'] . "'";
        }
        /*add by hg for date 2014-04-23 根据代理商筛选 begin*/
        if ($filter['admin_agency_id'] > 0 && if_agency()) {
            $where .= " AND ua.admin_agency_id  = '{$filter['admin_agency_id']}' ";
        }
        /*end*/
        $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('user_account') . " AS ua LEFT JOIN " . $GLOBALS['ecs']->table('users') . " AS u on ua.user_id = u.user_id" . $where;
        //dump($sql);
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);
        /* 分页大小 */
        $filter = page_and_size($filter);
        /* 查询数据 */
        $sql = 'SELECT ua.*, u.user_name FROM ' . $GLOBALS['ecs']->table('user_account') . ' AS ua LEFT JOIN ' . $GLOBALS['ecs']->table('users') . ' AS u ON ua.user_id = u.user_id' . $where . "ORDER by " . $filter['sort_by'] . " " . $filter['sort_order'] . " LIMIT " . $filter['start'] . ", " . $filter['page_size'];
        $filter['keywords'] = stripslashes($filter['keywords']);
        set_filter($filter, $sql);
    } else {
        $sql = $result['sql'];
        $filter = $result['filter'];
    }
    $list = $GLOBALS['db']->getAll($sql);
    tongji($sql);
    foreach ($list as $key => $value) {
        $list[$key]['surplus_amount'] = price_format(abs($value['amount']), false);
        $list[$key]['add_date'] = local_date($GLOBALS['_CFG']['time_format'], $value['add_time']);
        $list[$key]['process_type_name'] = $GLOBALS['_LANG']['surplus_type_' . $value['process_type']];
    }
    $GLOBALS['smarty']->assign('start_date', local_date('Y-m-d', $filter['start_date']));
    $GLOBALS['smarty']->assign('end_date', local_date('Y-m-d', $filter['end_date']));
    $filter['start_date'] = local_date('Y-m-d', $filter['start_date']);
    $filter['end_date'] = local_date('Y-m-d', $filter['end_date']);
    $arr = array('list' => $list, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
    return $arr;
}
 private function reply($data, $weixin)
 {
     $key = $data['Content'];
     $keywordArr = array();
     // 插件权限控制
     $token_status = D('Common/AddonStatus')->getList();
     foreach ($token_status as $a => $s) {
         $s == 1 || ($forbit_addon[$a] = $a);
     }
     // 所有安装过的微信插件
     $addon_list = (array) D('Addons')->getWeixinList(false, $token_status);
     /**
      * 微信事件转化成特定的关键词来处理
      * event可能的值:
      * subscribe : 关注公众号
      * unsubscribe : 取消关注公众号
      * scan : 扫描带参数二维码事件
      * location : 上报地理位置事件
      * click : 自定义菜单事件
      */
     if ($data['MsgType'] == 'event' || $data['MsgType'] == 'location') {
         $event = strtolower($data['MsgType'] == 'location' ? $data['MsgType'] : $data['Event']);
         if ($event == 'click' && !empty($data['EventKey'])) {
             $key = $data['Content'] = $data['EventKey'];
         } else {
             $key = $data['Content'] = $event;
         }
     } else {
         // 数据保存到消息管理中
         M('weixin_message')->add($data);
     }
     // 通过获取上次缓存的用户状态来定位处理的插件
     $openid = $data['FromUserName'];
     $user_status = S('user_status_' . $openid);
     $accept = $user_status['keywordArr']['accept'];
     if ($accept['type'] == 'regex' && !preg_match($accept['data'], $key) || $accept['type'] == 'array' && !in_array($key, $accept['data'])) {
         $user_status = false;
         S('user_status_' . $openid, null);
         // 可设置规定只能接收某些值,如果用户输入的内容不是规定的值,则放弃当前状态,支持正则和数组两种规定方式
     }
     if (!isset($addons[$key]) && $user_status) {
         $addons[$key] = $user_status['addon'];
         $keywordArr = $user_status['keywordArr'];
         S('user_status_' . $openid, null);
     }
     if (!isset($addons[$key])) {
         $map['keyword'] = $key;
         $map['from_type'] = array('neq', 9);
         $map['token'] = $data['ToUserName'];
         $map['type'] = 'click';
         $customMenu = M('custom_menu')->where($map)->order('id desc')->find();
         if (!empty($customMenu)) {
             if ($customMenu['addon']) {
                 $addons[$key] = $customMenu['addon'];
                 $keywordArr['aim_id'] = $customMenu['target_id'];
                 $this->request_count($keywordArr);
             } else {
                 if ($customMenu['sucai_type']) {
                     $map['token'] = get_token();
                     $map['openid'] = $openid;
                     $uid = M('public_follow')->where($map)->getField('uid');
                     switch ($customMenu['sucai_type']) {
                         case 1:
                             // 1:图文
                             D('Common/Custom')->replyNews($uid, $customMenu['target_id']);
                             break;
                         case 2:
                             // 2:文本
                             $textMap['id'] = $customMenu['target_id'];
                             $content = M('material_text')->where($textMap)->getField('content');
                             D('Common/Custom')->replyText($uid, $content);
                             break;
                         case 3:
                             // 3:图片
                             $textMap['id'] = $customMenu['target_id'];
                             D('Common/Custom')->replyImage($uid, $customMenu['target_id'], 'material_image');
                             break;
                         case 4:
                             // 4:语音
                             D('Common/Custom')->replyVoice($uid, $customMenu['target_id'], 'material_file');
                             break;
                         case 5:
                             // 5:视频
                             D('Common/Custom')->replyVideo($uid, $customMenu['target_id'], 'material_file', '', '', '');
                             break;
                     }
                     exit;
                 }
             }
         }
     }
     // 通过插件标识名、插件名或者自定义关键词来定位处理的插件
     if (!isset($addons[$key])) {
         $keyword_cache = F('keyword_cache');
         if ($keyword_cache === false || APP_DEBUG) {
             foreach ($addon_list as $k => $vo) {
                 $keyword_cache[$vo['name']] = $k;
                 $keyword_cache[$vo['title']] = $k;
                 $path = ONETHINK_ADDON_PATH . $vo['name'] . '/keyword.php';
                 if (file_exists($path)) {
                     $keywords = (include $path);
                     if (!empty($keywords)) {
                         $keyword_cache = array_merge($keyword_cache, $keywords);
                     }
                 }
                 F('keyword_cache', $keyword_cache);
             }
         }
         foreach ($keyword_cache as $k => $val) {
             $addons[$k] = $val;
         }
         // addWeixinLog($addons,'textman2');
         // addWeixinLog($addons,'textman');
     }
     // 通过精准关键词来定位处理的插件 token=0是插件安装时初始化的模糊关键词,所有公众号都可以用
     if (!empty($forbit_addon)) {
         $like['addon'] = array('not in', $forbit_addon);
     }
     $like['token'] = array('exp', "='0' or token='{$this->token}'");
     // 完全匹配
     if (!isset($addons[$key])) {
         $like['keyword'] = $key;
         $like['keyword_type'] = 0;
         $keywordArr = M('keyword')->where($like)->order('id desc')->find();
         if (!empty($keywordArr['addon'])) {
             $addons[$key] = $keywordArr['addon'];
             $this->request_count($keywordArr);
         }
     }
     // 随机匹配(前提是关键词是完全匹配)
     if (!isset($addons[$key])) {
         $like['keyword'] = $key;
         $like['keyword_type'] = 5;
         $keywordArr = M('keyword')->where($like)->order('RAND()')->find();
         if (!empty($keywordArr['addon'])) {
             $addons[$key] = $keywordArr['addon'];
             $this->request_count($keywordArr);
         }
     }
     // 通过模糊关键词来定位处理的插件
     if (!isset($addons[$key])) {
         unset($like['keyword']);
         $like['keyword_type'] = array('exp', 'in (1,2,3,4)');
         $list = M('keyword')->where($like)->order('keyword_length desc, id desc')->select();
         foreach ($list as $keywordInfo) {
             $this->_contain_keyword($keywordInfo, $key, $addons, $keywordArr);
         }
     }
     // 通过通配符,查找默认处理方式
     // by 肥仔聪要淡定 2014.6.8
     if (!isset($addons[$key])) {
         unset($like['keyword_type']);
         $like['keyword'] = '*';
         $keywordArr = M('keyword')->where($like)->order('id desc')->find();
         if (!empty($keywordArr['addon'])) {
             $addons[$key] = $keywordArr['addon'];
             $this->request_count($keywordArr);
         }
     }
     // 以上都无法定位插件时,如果开启了智能聊天,则默认使用智能聊天插件
     if (!isset($addons[$key]) && isset($addon_list['Chat'])) {
         // 您问我答插件特殊处理
         $YouaskServiceconfig = getAddonConfig('YouaskService');
         // 获取后台插件的配置参数
         if ($YouaskServiceconfig['state'] == 1) {
             $addons[$key] = 'YouaskService';
         } else {
             $addons[$key] = 'Chat';
         }
     }
     // 以上都无法定位插件时,如果开启了未识别回答,则默认使用未识别回答插件
     if (!isset($addons[$key]) && isset($addon_list['NoAnswer'])) {
         $addons[$key] = 'NoAnswer';
     }
     error_log('addon:' . $addons[$key]);
     // 最终也无法定位到插件,终止操作
     if (!isset($addons[$key]) || !file_exists(ONETHINK_ADDON_PATH . $addons[$key] . '/Model/WeixinAddonModel.class.php')) {
         return false;
     }
     // 加载相应的插件来处理并反馈信息
     require_once ONETHINK_ADDON_PATH . $addons[$key] . '/Model/WeixinAddonModel.class.php';
     $model = D('Addons://' . $addons[$key] . '/WeixinAddon');
     $model->reply($data, $keywordArr);
     // 运营统计
     tongji($addons[$key]);
 }