| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 | 
							- <?php
 
- namespace app\admin\controller;
 
- use app\common\util\ExcelUtil;
 
- use think\App;
 
- use think\Db;
 
- use think\Exception;
 
- 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("打包失败");
 
-         }
 
-     }
 
-     public function import(){
 
-         return $this->fetch();
 
-     }
 
-     /**
 
-      * 导入
 
-      */
 
-     public function importexcel(){
 
-         set_time_limit(0);
 
-         ini_set("memory_limit", -1);
 
-         ob_flush();//清空缓存
 
-         flush();//刷新缓存
 
-         $curTime = date('Y-m-d H:i:s');
 
-         try{
 
-             $cols = ['','addr','remark','content','user_name'];
 
-             $lists = ExcelUtil::importExcel('file',$cols,2);
 
-             if($lists === false){
 
-                 exit(ExcelUtil::getError());
 
-             }
 
-             if(empty($lists)){
 
-                 exit('文件内容为空');
 
-             }
 
-             foreach ($lists as $k=>$v){
 
-                 if($k > 0){
 
-                     if(!$v['addr']){
 
-                         echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,地点为空,未导入</font><br />";
 
-                         continue;
 
-                     }
 
-                     if(!$v['content']){
 
-                         echo "<font color=\"red\" style='margin-left: 20px;font-size: 17px'>第".($k+1)."行,工作内容为空,未导入</font><br />";
 
-                         continue;
 
-                     }
 
-                     $addrInfo = Db::name('address')
 
-                         ->where('org_id',$this->orgId)
 
-                         ->where('del',0)
 
-                         ->where('title',$v['addr'])
 
-                         ->find();
 
-                     if($addrInfo){
 
-                         $types = $addrInfo ? explode(',',$addrInfo['types']):[];
 
-                         if(!in_array(10,$types)){
 
-                             if($addrInfo['types']){
 
-                                 $newtypes = $addrInfo['types'].',10';
 
-                             }else{
 
-                                 $newtypes = 10;
 
-                             }
 
-                             Db::name('address')->where('id',$addrInfo['id'])
 
-                                 ->update([
 
-                                     'types'=>$newtypes
 
-                                     ]);
 
-                         }
 
-                         $addrId = $addrInfo['id'];
 
-                     }else{
 
-                         $addrId = Db::name('address')->insertGetId([
 
-                             'org_id'=>$this->orgId,
 
-                             'title'=>$v['addr'],
 
-                             'sn'=>'',
 
-                             'remark'=>'',
 
-                             'types'=>10,
 
-                             'create_time'=>getTime()
 
-                         ]);
 
-                     }
 
-                     $contents = explode('、',$v['content']);
 
-                     $daily_form = [];
 
-                     foreach ($contents as $k1=>$v1){
 
-                         if(!$v1){
 
-                             continue;
 
-                         }
 
-                         $formId = Db::name('daily_form')
 
-                             ->where('org_id',$this->orgId)
 
-                             ->where('del',0)
 
-                             ->where('content',$v1)
 
-                             ->value('id');
 
-                         if(!$formId){
 
-                             $formId  = Db::name('daily_form')
 
-                                 ->insertGetId([
 
-                                     'org_id'=>$this->orgId,
 
-                                     'content'=>$v1,
 
-                                     'create_time'=>date('Y-m-d H:i:s')
 
-                                 ]);
 
-                         }
 
-                         $daily_form[] = $formId;
 
-                     }
 
-                     $user_names = $v['user_name']? explode('/',$v['user_name']):[];
 
-                     $userIds = Db::name('user')
 
-                         ->alias('u')
 
-                         ->join('user_org uo','uo.user_id=u.id')
 
-                         ->where('uo.org_id',$this->orgId)
 
-                         ->where('u.del',0)
 
-                         ->where('u.real_name','in',$user_names)
 
-                         ->column('u.id');
 
-                     $dforms = $daily_form?implode(',',$daily_form):'';
 
-                     $dt = [
 
-                         'org_id'=>$this->orgId,
 
-                         'address_id'=>$addrId,
 
-                         'content'=>$v['remark'],
 
-                         'daily_form'=>$dforms,
 
-                         'create_time'=>date('Y-m-d H:i:s'),
 
-                     ];
 
-                     $dailyfind = Db::name('daily')
 
-                         ->where('org_id',$this->orgId)
 
-                         ->where('address_id',$dt['address_id'])
 
-                         ->where('daily_form',$dforms)
 
-                         ->find();
 
-                     if(!$dailyfind){
 
-                         $insetId = Db::name('daily')->insertGetId($dt);
 
-                         if($userIds){
 
-                             foreach ($userIds as $kk=>$vv){
 
-                                 Db::name('daily_user')->insertGetId(['daily_id'=>$insetId,'user_id'=>$vv]);
 
-                             }
 
-                         }
 
-                         if(!$insetId){
 
-                             $msg = "第".($k+2)."行,导入失败";
 
-                             echo "<font color=\"red\">".$msg."</font><br />";
 
-                             continue;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             echo "<font color=\"green\">导入完成</font><br />";
 
-         }catch (Exception $e){
 
-             trace($e->getMessage(),'error');
 
-             echo $e->getMessage();
 
-             echo "<font color=\"red\">数据异常,已停止导入</font><br />";
 
-         }
 
-     }
 
- }
 
 
  |