123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace app\admin\controller;
- use app\common\util\ExcelUtil;
- use think\Db;
- class AutoUser extends Auth
- {
- public function index(){
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','id','trim'); //排序列
- $sort = input('sord','desc','trim'); //排序方式
- $order = $sortRow.' '.$sort;
- $user = input('user','','trim');
- if($user){
- $id = Db::name('user')
- ->join('user_org uo','user.id=uo.user_id')
- ->where('uo.org_id',$this->orgId)
- ->where('user.real_name',$user)
- ->value('user.id');
- $map[] = ['user_id','=',$id];
- }
- $s = input('start','','trim');
- if($s != ''){
- $id = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('title',$s)->value('id');
- $map[] = ['start','=',$id];
- }
- $end = input('end','','trim');
- if($end != ''){
- $id = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('title',$end)->value('id');
- $map[] = ['end','=',$id];
- }
- // $map[] = ['del','=',0];
- $map[] = ['org_id','=',$this->orgId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db('auto_user')->where($map)->limit($start,$length)->order($order)->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['real_name']= Db::name('user')->where('del',0)->where('id',$v['user_id'])->value('real_name');
- $lists[$k]['start_name'] = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('id',$v['start'])->value('title');
- $lists[$k]['end_name'] = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('id',$v['end'])->value('title');
- }
- //数据返回
- $totalCount = db('auto_user')->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- return $this->fetch();
- }
- }
- /**
- * 新增/编辑
- */
- public function add($id=0){
- if(request()->isPost()){
- $res = model('AutoUser')->updates();
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error(model('AutoUser')->getError());
- }
- }else{
- if($id){
- $info = db('AutoUser')->where('id',$id)->find();
- $this->assign('info',$info);
- }
- // halt($info);
- $address = model('address')->getListByTypes('',2,$this->orgId);
- $this->assign('address',$address);
- $user = (new \app\common\model\WorkTypeMode())->getRolesUserByNum(3, $this->orgId,1);
- foreach ($user[0]['user'] as $k =>$v){
- $user[0]['user'][$k]['title']= preg_replace('/\(.*?\)/', '', $v['real_name']);
- };
- $this->assign('user', $user[0]['user']);
- return $this->fetch();
- }
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function del($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $res = db('AutoUser')->where('id',$id)->delete();
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- /**
- * 改变字段值
- * @param int $fv
- * @param string $fn
- * @param int $fv
- */
- public function changeField($id=0,$fn='',$fv=0){
- if(!$fn||!$id){
- $this->error('参数错误');
- }
- $res = db('AutoUser')->where('id',$id)->setField($fn,$fv);
- if($res){
- $this->success('操作成功');
- }else{
- $this->error('操作失败');
- }
- }
- }
|