123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\Db;
- class Daily extends Auth {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->model = new \app\common\model\Daily();
- }
- public function index() {
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx', 'sort', 'trim'); //排序列
- $sort = input('sord', 'asc', 'trim'); //排序方式
- $order = $sortRow . ' ' . $sort . ' ,id desc';
- $title = input('title', '', 'trim');
- if ($title) {
- $map[] = ['title', 'like', '%' . $title . '%'];
- }
- $enable = input('enable', '', 'trim');
- if ($enable != '') {
- $map[] = ['enable', '=', $enable];
- }
- $map[] = ['org_id', '=', $this->orgId];
- $map[] = ['del', '=', 0];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = Db::name('daily')->where($map)->limit($start, $length)->order($order)->select();
- foreach ($lists as $k => $v) {
- // $rolesName = $this->model->getRoles($v['roles']);
- // $lists[$k]['user_name'] = implode(',', $rolesName);
- $lists[$k]['title'] = '';
- if($v['address_id'] >0){
- $lists[$k]['title'] = Db::name('address')
- ->where('id',$v['address_id'])
- ->value('title');
- }
- }
- //数据返回
- $totalCount = Db::name('daily')->where($map)->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }
- else {
- $this->assign('meta_title', '任务列表');
- return $this->fetch();
- }
- }
- /**
- * 新增/编辑
- */
- public function add($id = 0) {
- if (request()->isPost()) {
- $model = $this->model;
- $res = $model->updates();
- if ($res) {
- $this->success('操作成功', url('index'));
- }
- else {
- $this->error($model->getError());
- }
- }
- else {
- $meta_title = '新增工作地点';
- $formModel = new \app\common\model\DailyForm();
- if ($id) {
- $info = Db::name('daily')->where('id', $id)->find();
- $info['daily_form'] = $formModel->getByIdList($info['daily_form']);
- // $info['roles'] = explode(',', $info['roles']);
- $this->assign('info', $info);
- $daily_user = Db::name('daily_user')
- ->where('daily_id',$info['id'])->column('user_id');
- $info['daily_user'] = isset($daily_user)?implode(',',$daily_user):'';
- $this->assign('info',$info);
- $meta_title = '编辑工作地点';
- }
- //获取检查项
- $dailyForm = $formModel->list();
- //角色
- $roles = $this->model->getRolesList($this->orgId);
- $dailyUser = model('WorkTypeMode')->getRolesUser(9,cur_org_id());
- $this->assign('daily_form', $dailyForm);
- $this->assign('dailyUser',$dailyUser);
- $this->assign('meta_title', $meta_title);
- $this->assign('send_user_num',0);
- $address = model('Address')->getListByType(10);
- $this->assign('address',$address);
- return $this->fetch();
- }
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function del($id = 0) {
- if (!$id) {
- $this->error('参数错误');
- }
- $res = Db::name('daily')->where('id', $id)->update(['del' => 1]);
- 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::name('daily')->where('id', $id)->update([$fn => $fv]);
- if ($res) {
- $this->success('操作成功');
- }
- else {
- $this->error('操作失败');
- }
- }
- //二维码
- public function qrcode($id = 0) {
- $info = Db::name('daily')->where('id', $id)->find();
- if (!$info) {
- exit('数据不存在');
- }
- $code = get_qrcode_str('daily', $id);
- $this->assign('code', $code);
- $this->assign('info', $info);
- return $this->fetch();
- }
- public function allPrint(){
- $ids = input('ids');
- if(!$ids){
- $list = Db::name('daily')
- ->where('org_id',cur_org_id())
- ->where('enable',1)
- ->where('del',0)
- ->select();
- }else{
- $ids = explode(',',$ids);
- $list = Db::name('daily')
- ->where('org_id',cur_org_id())
- ->where('enable',1)
- ->where('id','in',$ids)
- ->where('del',0)
- ->select();
- }
- foreach ($list as $k=>$v){
- $list[$k]['qCode'] = get_qrcode_str('daily',$v['id']);
- }
- $this->assign('list',$list);
- return $this->fetch();
- }
- public function group() {
- $title = input('title', '', 'trim');
- if ($title) {
- $map[] = ['title', 'like', '%' . $title . '%'];
- }
- $map[] = ['enable', '=', 1];
- $map[] = ['org_id', '=', $this->orgId];
- $map[] = ['del', '=', 0];
- $lists = Db::name('daily')->where($map)->field('id,title,address_id')->order('id desc')->select();
- $hours = model('Daily')->getTimeDaily($this->orgId);
- foreach ($lists as $k=>$v){
- $lists[$k]['title'] = '';
- if($v['address_id'] >0){
- $lists[$k]['title'] = Db::name('address')
- ->where('id',$v['address_id'])
- ->value('title');
- }
- $users = Db::name('daily_user')
- ->alias('du')
- ->join('user u','u.id = du.user_id')
- ->where('du.daily_id',$v['id'])
- ->column('real_name');
- $users = $users?$users:[];
- $lists[$k]['users'] = $users?implode(',',$users):'';
- $m = [];
- $m[] = ['org_id','=',$this->orgId];
- $m[] = ['daily_id','=',$v['id']];
- $m[] = ['create_time','>=',$hours['start']];
- $m[] = ['create_time','<',$hours['end']];
- $count = Db::name('daily_record')->where($m)->count();
- $lists[$k]['count'] = $count;
- $lists[$k]['zc'] = 0;
- if($count > 0){
- $lists[$k]['zc'] = 1;
- }
- $m[] = ['order_id','>',0];
- $orderIds = Db::name('daily_record')->where($m)->column('order_id');
- if($orderIds){
- $res = Db::name('orders')->where('id','in',$orderIds)->where('del',0)->where('order_mode','in',[1,4])->find();
- if($res){
- $lists[$k]['zc'] = 2;
- }
- }
- }
- $this->assign('hours',$hours);
- $this->assign('lists',$lists);
- return $this->fetch();
- }
- public function record($id=0,$s='',$e='') {
- if (request()->isAjax()) {
- //分页参数
- $length = input('rows', 10, 'intval'); //每页条数
- $page = input('page', 1, 'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- $order = 'id desc';
- $map[] = ['dr.daily_id','=',$id];
- $map[] = ['dr.create_time','>=',$s];
- $map[] = ['dr.create_time','<',$e];
- $map[] = ['dr.org_id', '=', $this->orgId];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = Db::name('daily_record')
- ->alias('dr')
- ->join('daily d', 'd.id=dr.daily_id')
- ->field('dr.*,d.title,d.content as daily_details')
- ->where($map)
- ->limit($start, $length)
- ->order($order)
- ->select();
- foreach ($lists as $k => $v) {
- $lists[$k]['user_name'] = Db::name('user')
- ->where('id', $v['user_id'])
- ->value('real_name');
- $lists[$k]['zc'] = 0;
- if($v['order_id'] > 0){
- $lists[$k]['zc'] = 1;
- $res = Db::name('orders')->where('id',$v['order_id'])->where('del',0)->where('order_mode','in',[1,4])->find();
- if($res){
- $lists[$k]['zc'] = 2;
- }
- }
- }
- //数据返回
- $totalCount = Db::name('daily_record')
- ->alias('dr')
- ->field('dr.*,d.title,d.content as daily_details')
- ->join('daily d', 'd.id=dr.daily_id')
- ->where($map)->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- } else {
- $this->assign('id',$id);
- $this->assign('s',$s);
- $this->assign('e',$e);
- $this->assign('meta_title', '检查记录列表');
- return $this->fetch();
- }
- }
- public function addrdown(){
- $orgid = $this->orgId;
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$this->orgId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db('daily')->where($map)->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['code'] = get_qrcode_str('daily',$v['id']);
- }
- $path = date('Ymd').'_'.$orgid.'_'.time().mt_rand(1000,9999);
- $dir = './uploads/qrcodeimg/'.$path.'/';
- foreach ($lists as $v1){
- $v1['title'] = '';
- if($v['address_id'] >0){
- $v1['title'] = Db::name('address')
- ->where('id',$v['address_id'])
- ->value('title');
- }
- $name = $v1['title'].'('.$v1['id'].')'.'.jpg';
- $filepath = $dir.'/'.$name;
- create_qrcode($v1['code'],$filepath);
- }
- $zippath = './uploads/qrcodeimg/'.$path.'.zip';
- $spath = $dir;
- @unlink($zippath);
- $zip = new \ZipArchive();
- if($zip->open($zippath, \ZipArchive::CREATE)=== TRUE){
- add_file_to_zip($spath,$zip); //调用方法,对要打包的根目录进行操作,并将ZipArchive的对象传递给方法
- $zip->close(); //关闭处理的zip文件
- if(!file_exists($zippath)){
- $this->error("打包失败"); //即使创建,仍有可能失败。。。。
- }
- deldir($dir); // 删除生成的目录
- $downname = session('orgName').'日常工作地点二维码.zip';
- header("Cache-Control: public");
- header("Content-Description: File Transfer");
- header('Content-disposition: attachment; filename='.$downname); //文件名
- header("Content-Type: application/zip"); //zip格式的
- header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
- header('Content-Length: '. filesize($zippath)); //告诉浏览器,文件大小
- @readfile($zippath);
- }else{
- $this->error("打包失败");
- }
- }
- }
|