Beispiel #1
0
 public function search($pk)
 {
     $map['status'] = 1;
     if ($val = act_decrypt(I('pk'))) {
         $map['id'] = $val;
     }
     if ($val = I('query')) {
         $map['_string'] = "(hy.name LIKE '%{$val}%' OR hy.user_no='{$val}')";
     }
     if ($val = I('cls')) {
         $map['student.class_id'] = $val;
     }
     $map = count($map) > 1 ? $map : 'false';
     $lists = $this->where($map)->reflect(array('student|id|user_id|class_id,building,room,bank_card,parent_phone', 'class|student.class_id|id|name class_name'))->select('hy');
     if (1 === count($lists)) {
         $user = $lists[0];
         $user['id'] = act_encrypt($user['id']);
         $user['name'] = $user['name'];
         $user['phone'] = val_decrypt($user['phone']);
         $user['class_id'] = act_encrypt($classId = $user['class_id']);
         $user['roles'] = $this->callback_rolesRead($user['roles']);
         $lists = null;
     } else {
         foreach ($lists as $k => &$v) {
             $v['id'] = act_encrypt($v['id']);
         }
     }
     if ($user['building'] && $user['room']) {
         $user['dorm'] = $user['building'] . ' - ' . $user['room'];
         $roomMates = $this->reflect(array('student|id|user_id|building,room'))->where(array('student.building' => $user['building'], 'id' => array('neq', act_decrypt($user['id'])), 'student.room' => $user['room']))->select('hy');
         $roomMates = md_arr_2_asc_arr($roomMates, 'name', 'phone');
         $user['roomMates'] = '';
         foreach ($roomMates as $k => $v) {
             $user['roomMates'] .= $k;
             $user['roomMates'] .= $v ? '(' . $v . ')<br>' : '';
         }
     }
     $classMonitorId = D('StudentCadre')->getCadreUid($classId, '班长');
     $classSecretaryId = D('StudentCadre')->getCadreUid($classId, '团支书');
     $userM['monitor'] = $this->where(array('id' => $classMonitorId))->find() ?: array();
     $userS['secretary'] = $this->where(array('id' => $classSecretaryId))->find() ?: array();
     $user['class_id'] = act_decrypt($user['class_id']);
     $userI['instructor'] = $this->reflect(array('instructor|id|teacher_id|class_id'))->where(array('instructor.class_id' => $user['class_id']))->select(array('hy' => true));
     $ms = array_merge($userM, $userS, $userI);
     foreach ($ms as $k => $v) {
         if ($k != 'instructor') {
             $user[$k] = $v['name'] . '(' . $v['phone'] . ')';
         } else {
             foreach ($v as $k1 => $v1) {
                 $user[$k] .= $v1['name'] . '(' . $v1['phone'] . ')<br/>';
             }
         }
     }
     $arr['userInfo'] = array('name' => '姓名', 'user_no' => '学号', 'sex' => '性别', 'roles' => '角色', 'class_name' => '班级', 'monitor' => '班长', 'secretary' => '团支书', 'instructor' => '辅导员', 'college' => '学院', 'phone' => '电话', 'email' => '邮箱', 'dorm' => '寝室', 'roomMates' => '室友', 'nation' => '民族', 'native' => '籍贯', 'qq' => 'QQ', 'parent_phone' => '家长电话', 'id_card' => '身份证号', 'bank_phone' => '银行卡号', 'roles' => '职务');
     $arr['lists'] = $lists;
     $arr['user'] = $user;
     $arr['arrInfo'] = array('class_name', 'user_no', 'nation', 'roles', 'native');
     return $arr;
 }
Beispiel #2
0
 /**
  * 列表页Datatables数据输出
  * @return array
  */
 protected function getDtData()
 {
     $records = array();
     $total = $this->count(array('hy' => true, 'scope' => 'lists'));
     $records['status'] = is_numeric($total) ? true : false;
     $total = $total ?: 0;
     $log = array('msg' => "共{$total} 条记录");
     Hook::listen('hy_log', $log);
     $limit = intval(I('length'));
     $limit = $limit < 0 ? $total : $limit;
     $offset = intval(I('start')) ?: 0;
     $draw = intval(I('draw'));
     if ($draw > 1) {
         // 字段排序
         $order = I('order');
         if (0 !== strpos($order['field'], '_') && false !== ($_order = $this->fieldsOptions[$order['field']]['list']['order'])) {
             $table = $this->fieldsOptions[$order['field']]['table'];
             $this->pageOptions['order'] = (is_string($_order) ? $_order : ($table ? $table . '.' : '') . $order['field']) . ' ' . $order['sort'];
         }
         $this->pageOptions['limit'] = "{$offset},{$limit}";
     }
     if ($this->sqlOptions['associate'] && is_string($this->pageOptions['order'])) {
         $this->pageOptions['order'] = $this->fieldPre($this->pageOptions['order'], self::HYP);
     }
     $data = array();
     if ($total) {
         $data = $this->scope('lists')->order($this->pageOptions['order'])->limit($this->pageOptions['limit'])->select();
     }
     //=============<Debug begin>===========
     // 		$records['sql'] = $this->_sql();
     // 		$records['select'] = $data;
     // 		$records['model'] = $this;
     //=============<Debug end>=============
     $valid = array();
     foreach ($this->fieldsOptions as $k => $v) {
         if ($v['title'] && false !== $v['list']['hidden']) {
             $valid[$k] = '';
         }
     }
     $lists = array();
     $iD = 0;
     // 方法回调
     $pk = $this->getPk();
     if ($data) {
         foreach ($data as $kD => &$vD) {
             $lists[$iD]['_pk'] = act_encrypt($vD[$pk]);
             foreach ($this->fieldsOptions as $kF => $vF) {
                 if ($tmp = $vF['list']['callback']) {
                     $lists[$iD][$kF] = $this->callbackHandler($tmp, $kF, $vD);
                 } else {
                     $lists[$iD][$kF] = $vD[$kF];
                 }
             }
             $vD = array_intersect_key($vD, $valid);
             $iD++;
         }
     }
     $records["data"] = $lists;
     $records["recordsTotal"] = $total;
     $records["recordsFiltered"] = $total;
     return $records;
 }
 /**
  * 角色信息缓存
  * @param number $roleId
  */
 private function roleCache($roleId)
 {
     session('roleId', $roleId);
     $role = array();
     $roleSwitch = array();
     $tmp = M('frame_role')->where(array('status' => 1, 'id' => array('IN', session('roleIdArr'))))->getField('id,name,title,table');
     if (is_array($tmp)) {
     }
     foreach ($tmp as $k => $v) {
         if (!$v) {
             continue;
         }
         if ($k == $roleId) {
             $role = $v;
             continue;
         }
         $roleSwitch[act_encrypt($k)] = $v['title'];
     }
     $roleSwitch[act_encrypt($roleId)] = $role['title'];
     $roleSwitch = array_reverse($roleSwitch);
     session('roleSwitch', $roleSwitch);
     session('roleTitle', $role['title']);
     // 角色切换后置方法
     D('HyAccount')->onRoleSwitch($role);
     HyAuthModel::cacheAccess($roleId);
 }