diff --git a/README.md b/README.md index 071225ff..06bc3743 100755 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@   坦率地讲,在不久的将来,这也许会是辽东半岛上第二好用的成绩统计系统。 -![表情包](https://gitee.com/dlbz/shangma/raw/master/public/examples/timg.jpg =250x400) +![表情包](https://gitee.com/dlbz/shangma/raw/master/public/examples/timg.jpg) +   言归正传 diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 6f192839..01ab452d 100755 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -32,13 +32,13 @@ class Index extends AdminBase { // 获取参数 $src = $this->request - ->only([ - 'page' => '1' - ,'limit' => '10' - ,'field' => 'id' - ,'order' => 'desc' - ,'searchval' => '' - ],'POST'); + ->only([ + 'page' => '1' + ,'limit' => '10' + ,'field' => 'id' + ,'order' => 'desc' + ,'searchval' => '' + ],'POST'); // 实例化 $ad = new AD; @@ -59,7 +59,8 @@ class Index extends AdminBase ,'status' ,'update_time' ]); - $data = reSetObject($data, $src); + $cnt = $ad->cnt(); + $data = reSetData($data, $cnt); return json($data); } diff --git a/app/admin/model/Admin.php b/app/admin/model/Admin.php index 894d8466..ae61a281 100755 --- a/app/admin/model/Admin.php +++ b/app/admin/model/Admin.php @@ -42,12 +42,17 @@ class Admin extends BaseModel ]; - // 查询所有用户 + // 查询按条件查用户 public function search($srcfrom) { // 整理变量 $src = [ 'searchval' => '' + ,'page' => 1 + ,'limit' => 10 + ,'field' => 'id' + ,'order' => 'desc' + ,'srccnt' => false ]; $src = array_cover($srcfrom, $src); @@ -64,6 +69,11 @@ class Admin extends BaseModel } ,'glGroup' ]) + ->when($src['cnt'] == false, function ($query) use $src { + $query + ->page($src['page'], $src['limit']) + ->order([$src['field']=>$src['order']]); + }) ->hidden([ 'password' ,'create_time' @@ -75,6 +85,14 @@ class Admin extends BaseModel } + // 查询所有用户 + public function cnt() + { + $cnt = self::count('id'); + return $cnt; + } + + // 查询用户权限 public function srcAuth($user_id) { diff --git a/app/common.php b/app/common.php index 2f917e25..2b86a407 100755 --- a/app/common.php +++ b/app/common.php @@ -11,28 +11,8 @@ // 应用公共文件 - // // 获取类别列表 - // function categoryChildren($p_id = 0) - // { - // // 查询类别 - // $category = new \app\system\model\Category; - // $list = $category->srcChild($p_id); - // // 返回类别列表 - // return $list; - // } - -// // 单位列表 -// function danweiJibie($low = '班级', $high = '其它级', $order = 'asc') -// { -// // 实例化单位模型 -// $sch = new \app\system\model\School; -// $data = $sch->srcJibie($low, $high, $order); -// return $data; -// } - - // 班级列表 - function banJiNamelist() + function banji_name_list() { // 实例化年级控制器 $bj = new \app\teach\model\Banji; @@ -41,7 +21,7 @@ } // 查询统计项目 - function srcTjxm($category_id) + function src_tjxm($category_id) { $tjxm = new \app\kaoshi\model\TongjiXiangmu; $data = $tjxm->srcTongji($category_id); @@ -50,7 +30,7 @@ // 可以组织考试的单位列表 - function kaoshiSchoolList() + function kaoshi_school_list() { // 实例化单位模型 $sch = new \app\system\model\School; @@ -59,8 +39,8 @@ } - // 整理教师名 - function teacherNames($list = array()) + // 整理教师名,数组转字符串 + function teacher_names($list = array()) { if (count($list) == 0) { return ''; @@ -100,7 +80,7 @@ * @param str或array $str 表单中获取的参数 * @return array 返回类型 */ - function strToArray($str) + function str_to_array($str) { $data = \app\facade\Tools::strToArray($str); return $data; @@ -113,9 +93,9 @@ * @param str或array $str 表单中获取的参数 * @return array 返回类型 */ - function reSetObject($obj, $srcfrom) + function reset_data($data, $cnt) { - $data = \app\facade\Tools::reSetObject($obj, $srcfrom); + $data = \app\facade\Tools::reSetData($data, $cnt); return $data; } @@ -126,7 +106,7 @@ * @param str或array $str 表单中获取的参数 * @return array 返回类型 */ - function reSetArray($arr, $srcfrom) + function reset_array($arr, $srcfrom) { $data = \app\facade\Tools::reSetArray($arr, $srcfrom); return $data; @@ -134,7 +114,7 @@ // 定义EXCEL列名 - function excelColumnName() + function excel_column_name() { $liemingarr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW']; return $liemingarr; @@ -142,7 +122,7 @@ // 多字段排序 - function sortArrByManyField($arr, $srcfrom) + function sort_arr_by_many_field($arr, $srcfrom) { $data = \app\facade\Tools::sortArrByManyField($arr, $srcfrom); return $data; @@ -150,7 +130,7 @@ // 已知密码进行验证 - function loginCheck($inputPassword, $serverPassword) + function login_check($inputPassword, $serverPassword) { // 实例化加密类 $md5 = new \WhiteHat101\Crypt\APR1_MD5; @@ -166,3 +146,9 @@ return round($size, 2) . $delimiter . $units[$i]; } + + // 整理变量 + function reset_src($form) { + + } + diff --git a/app/tools/controller/Index.php b/app/tools/controller/Index.php index 1e6cfa02..e7a35850 100755 --- a/app/tools/controller/Index.php +++ b/app/tools/controller/Index.php @@ -103,18 +103,9 @@ class Index extends BaseController * @param str或array $str 表单中获取的参数 * @return array 返回类型 */ - public function reSetObject($obj, $srcfrom) + public function reSetData($data, $cnt) { - // 整理变量 - $src = [ - 'field' => '' - ,'order' => 'asc' - ,'page' => 1 - ,'limit' => 10 - ]; - $src = array_cover($srcfrom, $src) ; - - $data = [ + $arr = [ 'code' => 0 // ajax请求次数,作为标识符 ,'msg' => "" // 获取到的结果数(每页显示数量) ,'count' => 0 // 符合条件的总数据量 @@ -122,24 +113,16 @@ class Index extends BaseController ]; // 整理数据 - $cnt = $obj->count(); if($cnt > 0) { - if($src['field'] != '') # 排序 - { - $obj = $obj->order($src['field'], $src['order']); - } - $limit_start = $src['page'] * $src['limit'] - $src['limit']; - $limit_length = $src['limit'] * 1; - $obj = $obj->slice($limit_start, $limit_length); - $data = [ + $arr = [ 'code' => 0 // ajax请求次数,作为标识符 ,'msg' => "" // 获取到的结果数(每页显示数量) ,'count' => $cnt // 符合条件的总数据量 - ,'data' => $obj //获取到的数据结果 + ,'data' => $data //获取到的数据结果 ]; } - return $data; + return $arr; }