public function dologin()
 {
     if (!IS_POST) {
         $this->error('路径非法', 'index');
     }
     if (I('post.username') == '') {
         $this->error('请输入登录名!');
     }
     if (I('post.password') == '') {
         $this->error('请输入密码!');
     }
     $ip = get_client_ip();
     $log = wx_opera_log(I('post.username'), '登录', '登录', $ip, 'dologin');
     $db = M('user');
     $user = $db->where(array('user_name' => I('post.username')))->find();
     if (!$user || $user['user_pass'] != I('post.password', '', 'md5')) {
         $this->error('登录信息错误,请重新登陆!', 'index');
     } else {
         session(C('USER_AUTH_KEY'), $user['id']);
         session('username', $user['user_name']);
         session('logintime', date('Y-m-d H:i:s', $user['user_logtime']));
         //超级管理员识别
         if ($user['user_name'] == C('RBAC_SUPERADMIN')) {
             session(C('ADMIN_AUTH_KEY'), true);
         }
         //读取用户权限
         import('Org.Util.Rbac');
         Rbac::saveAccessList();
         $data['user_logtime'] = time();
         $db->where("id=" . $user['id'])->save($data);
         $this->success('登陆成功', redirect('Index/index'));
     }
 }
 public function massall()
 {
     $log = wx_opera_log(session('username'), '素材管理', '群发素材', '', 'massall');
     $pids = I('get.pids');
     $mid = I('get.mid');
     if (!empty($pids)) {
         $info = '';
         $wechat = A('wechat');
         $pids = explode(',', $pids);
         foreach ($pids as $pid) {
             $media_id = M('material_online')->where(array('pub_id' => $pid, 'material_id' => $mid))->getField('media_id');
             $result = $wechat::sentNewsByGroup('', $media_id, true, $pid);
             $nick_name = M('pub_account')->where(array('id' => $pid))->getField('nick_name');
             if ($result['errcode'] === 0) {
                 $data['msg_data_id'] = $result['msg_data_id'];
                 $data['msg_id'] = $result['msg_id'];
                 $data['msg_ptime'] = time();
                 M('material_online')->where(array('pub_id' => $pid, 'material_id' => $mid))->save($data);
                 $info .= '公众号<span style=color:red>' . $nick_name . '</span>素材群发成功!<br>';
             } else {
                 $info .= '公众号<span style=color:red>' . $nick_name . '</span>素材群发失败!错误信息:<span style=color:red>' . $result['errmsg'] . '</span><br>';
                 $log = wx_opera_log(session('username'), '素材', '素材群发', '公众号<span style=color:red>' . $nick_name . '</span>素材群发失败!错误信息:' . $result['errmsg'], 'massall');
             }
         }
         echo $info;
         exit;
     }
     $m = M('material_online');
     $result = $m->join('wx_pub_account ON wx_pub_account.id = wx_material_online.pub_id')->distinct(true)->field('nick_name,id')->where(array('material_id' => $mid))->select();
     $this->ajaxReturn($result);
 }
 public function pub_fans()
 {
     $log = wx_opera_log(session('username'), '订阅号管理', '订阅号粉丝', '', 'pub_fans');
     $this->pub_id = I('get.id', 0, 'intval');
     //$data['pub_id'] = $this->pub_id;
     //$id_in_msg = M('pub_wechat')->where($data)->getField('pub_id');
     //获取所有分组
     $resultGroups = self::get_groups($this->pub_id);
     $this->groups = $resultGroups[groups];
     $this->countAll = 0;
     //总关注数
     foreach ($this->groups as $value) {
         $this->countAll = $this->countAll + $value[count];
     }
     $this->pageAll = (int) floor($this->countAll / 100) + 1;
     //总页数
     $this->currentPage = 1;
     //当前页
     //每10000个都是1到10页
     $modPage = $this->currentPage;
     //1-100
     $nextPage = $_GET['nextPage'];
     $get_next_openid = null;
     if ($_GET['nextPage'] == "" || $_GET['nextPage'] == NULL) {
         $modPage = 1;
     } else {
         $this->currentPage = $nextPage;
         if ($nextPage % 100 == 0) {
             $modPage = 100;
             $get_next_openid = $_GET['next_openid'];
         } else {
             $modPage = $nextPage % 100;
         }
     }
     //获取关注列表,一次最多可获取10000个openid
     $this->resultUser = self::get_user($this->pub_id, $get_next_openid);
     $this->userData = $this->resultUser[data][openid];
     $this->next_openid = $this->resultUser[next_openid];
     //3、批量获取用户信息
     //根据openid获取用户信息,一次可最多获取100个
     //先只处理一百个以内
     $manage = new ManageController();
     $access_token = $manage->get_token($this->pub_id);
     $queryUserInfoUrl = 'https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=' . $access_token;
     //一次可获取100个用户
     $queryUserInfoAction = 'POST';
     $dataUserInfo = array();
     $dataList = array();
     for ($i = ($modPage - 1) * 100; $i < ($modPage - 1) * 100 + 99 && $i < count($this->userData); $i++) {
         $dataList['openid'] = $this->userData[$i];
         $dataList['lang'] = 'zh-CN';
         $dataUserInfo['user_list'][$i - ($modPage - 1) * 100] = $dataList;
     }
     $dataUserInfo = json_encode($dataUserInfo);
     $curl = new \Org\Util\curl();
     $this->resultUserInfo = $curl::callWebServer($queryUserInfoUrl, $dataUserInfo, $queryUserInfoAction);
     $this->resultUserList = $this->resultUserInfo[user_info_list];
     //$this->resultUserInfo =  $curl::callWebServer($queryUserInfoUrl,'',$queryUserInfoAction);
     if ($_GET['gid'] == "" || $_GET['gid'] == NULL) {
         $this->ifPage = 1;
         $this->resultUserList = $this->resultUserList;
     } else {
         //分组查询
         $this->ifPage = 0;
         $gid = $_GET['gid'];
         $arr = array();
         for ($i = 0; $i < count($this->resultUserList); $i++) {
             if ($gid == $this->resultUserList[$i][groupid]) {
                 $arr[$i] = $this->resultUserList[$i];
             }
         }
         $this->resultUserList = $arr;
     }
     $this->display();
 }
 public function updatePubGroup()
 {
     $log = wx_opera_log(session('username'), '订阅号管理', '订阅号分组', '', 'updatePubGroup');
     $this->updatePub = M("pub_account")->execute("update wx_pub_account set pub_group= " . $_GET['group_id'] . " where id=" . $_GET['pub_id'] . ";");
     echo 1;
     return;
 }
 public function modify()
 {
     $id = I('id');
     $user = D('UserRelation')->relation(true)->where(array('id' => $id))->find();
     $role = array();
     foreach ($user['role'] as $vo) {
         foreach ($vo as $k => $v) {
             if ($k == 'id') {
                 $k = 'rid';
             }
             $role[$k] = $v;
             unset($user['role']);
         }
     }
     $user = array_merge($user, $role);
     $log = wx_opera_log(session('username'), '系统管理', '修改资料-编辑', '', 'modify');
     $this->ajaxReturn($user);
 }
 public function excelImport()
 {
     $log = wx_opera_log(session('username'), '数据统计', '订阅号统计-导入', '', 'excelImport');
     if (!empty($_FILES['file_stu']['name'])) {
         $tmp_file = $_FILES['file_stu']['tmp_name'];
         $file_types = explode(".", $_FILES['file_stu']['name']);
         $file_type = $file_types[count($file_types) - 1];
         /*判别是不是.xls文件,判别是不是excel文件*/
         if (strtolower($file_type) != "xlsx" && strtolower($file_type) != "xls") {
             $this->error('不是Excel文件,重新上传!');
         }
         /*设置上传路径*/
         $savePath = './Uploads/Excel/';
         /*以时间来命名上传的文件*/
         $str = date('Ymdhis');
         $file_name = $str . "." . $file_type;
         /*是否上传成功*/
         if (!copy($tmp_file, $savePath . $file_name)) {
             $this->error('上传失败');
         }
         /*
           *对上传的Excel数据进行处理生成编程数据,这个函数会在下面第三步的ExcelToArray类中
           注意:这里调用执行了第三步类里面的read函数,把Excel转化为数组并返回给$res,再进行数据库写入
         */
         // $res = Service ( 'ExcelToArray' )->read ( $savePath . $file_name );
         $res = $this->ExcelToArray($savePath . $file_name);
         /*
             重要代码 解决Thinkphp M、D方法不能调用的问题   
             如果在thinkphp中遇到M 、D方法失效时就加入下面一句代码
         */
         //spl_autoload_register ( array ('Think', 'autoload' ) );
         /*对生成的数组进行数据库的写入*/
         foreach ($res as $k => $v) {
             if ($k != 1) {
                 $data['id'] = $v[0];
                 $data['ref_date'] = $v[1];
                 $data['city'] = $v[2];
                 $data['area'] = $v[3];
                 $data['nick_name'] = $v[4];
                 $data['pub_group'] = $v[5];
                 $data['is_vip'] = $v[6];
                 $data['is_certify'] = $v[7];
                 $data['stu_num'] = $v[8];
                 $data['care_num'] = $v[9];
                 $data['care_rate'] = round($v[9] / $v[8], 4) * 100;
                 //关注率
                 $data['daily_add'] = $v[11];
                 $data['daily_cancel'] = $v[12];
                 $data['daily_rate'] = round(($v[11] - $v[12]) / $v[8], 4) * 100;
                 //日增
                 $data['type'] = 1;
                 $result = M('pub_data')->add($data);
                 if (!$result) {
                     $this->error($v[4] . '数据导入失败');
                     //return 0;
                 } else {
                     $this->success($v[4] . '数据导入成功', 'pub_index');
                     //return 1;
                 }
             }
         }
     }
 }