123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class WorkNews extends Model
- {
- public function add(){
- $curTime = date('Y-m-d H:i:s');
- $data = [
- 'id' => input('id/d',0),
- 'work_type_id' => input('type/d',0),
- 'content' => input('content','','trim'),
- 'files' => input('files','','trim'),
- 'create_time' => $curTime,
- ];
- $result = validate('WorkNews')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('WorkNews')->getError());
- }
- Db::startTrans();
- try{
- $id = $data['id'];
- $sdata = [
- 'work_type_id' => $data['work_type_id'],
- 'files' => $data['files']
- ];
- if($id > 0){
- Db::name('work_news_item')->where('work_news_id',$id)->delete();
- $sdata['update_time'] = date('Y-m-d H:i:s');
- $workReportId = Db::name('work_news')->where('id',$id)->update($sdata);
- if(!$workReportId){
- \exception('提交失败');
- }
- }else{
- $sdata['status'] = 1;
- $sdata['org_id'] = input('orgId/d',0);
- $sdata['user_id'] = input('userId/d',0);
- $sdata['create_time'] = date('Y-m-d H:i:s');
- $sdata['receiver'] = check_exp_imp(input('receiver','','trim'));
- $sdata['auditor'] = input('auditor/d',0);
- if($sdata['auditor'] > 0){
- $sdata['audit_status'] = 0;
- }else{
- $sdata['audit_status'] = 1;
- }
- $workReportId = Db::name('work_news')->insertGetId($sdata);
- if(!$workReportId){
- \exception('提交失败');
- }
- $id = $workReportId;
- $type = 0;
- if($sdata['auditor'] > 0){
- $receiver = [$sdata['auditor']];
- $type = 1;
- }else{
- // 添加接收人记录及消息
- $receiver = explode(',',$sdata['receiver']);
- }
- $username = Db::name('user_info')->where('user_id',$sdata['user_id'])->value('name');
- foreach ($receiver as $k=>$v){
- $d = [
- 'org_id' => $sdata['org_id'],
- 'user_id' => $v,
- 'create_time' => $curTime,
- 'is_read' => 0,
- 'work_news_id' => $workReportId,
- 'type' => $type
- ];
- $wrrid = Db::name('work_news_receiver')->insertGetId($d);
- if(!$wrrid){
- \exception('提交失败');
- }
- $typename = Db::name('work_news_type')->where('id',$data['work_type_id'])->value('title');
- $context = $username.'提交的'.$typename.'工作动态';
- $ret = model('Message')->add(3,$wrrid,13,$v,$sdata['org_id'],$context);
- if(!$ret){
- \exception('提交失败');
- }
- }
- }
- $content = json_decode($data['content'],true);
- if($content){
- foreach ($content as $k=>$v){
- if($v['content'] || $v['date']){
- Db::name('work_news_item')->insert([
- 'work_news_id' => $id,
- 'content' => $v['content'],
- 'date' => empty($v['date'])?null:$v['date']
- ]);
- }
- }
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error($e->getMessage());
- }
- return true;
- }
- public function info($id){
- $info = Db::name('work_news')
- ->where('id',$id)
- ->where('status',1)
- ->field('id,user_id,work_type_id,create_time,files,audit_status')
- ->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $info['typeName'] = Db::name('work_news_type')->where('id',$info['work_type_id'])->value('title');
- $info['userName'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name');
- $content = Db::name('work_news_item')->where('work_news_id',$id)->field('content,date')->select();
- $info['content'] = json_encode($content);
- $receiver = Db::name('work_news_receiver')
- ->alias('wnr')
- ->join('user_info ui','ui.user_id = wnr.user_id')
- ->where('wnr.work_news_id',$info['id'])
- ->column('ui.name');
- $info['receiver'] = $receiver?implode(',',$receiver):'';
- return $info;
- }
- public function receiveInfo($id){
- $info = Db::name('work_news_receiver')
- ->alias('wrr')
- ->join('work_news wr','wr.id = wrr.work_news_id')
- ->where('wrr.id',$id)
- ->where('wr.status',1)
- ->field('wr.id,wr.audit_status,wr.user_id,wr.files,wr.work_type_id,wrr.create_time,wrr.is_read,wrr.read_time,wrr.user_id as receiver')
- ->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $info['typeName'] = Db::name('work_news_type')->where('id',$info['work_type_id'])->value('title');
- $info['userName'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name');
- if($info['is_read'] == 0){
- Db::name('work_news_receiver')->where('id',$id)->update(['is_read'=>1,'read_time'=>date('Y-m-d H:i:s')]);
- $msgid = Db::name('message')
- ->where('status',0)
- ->where('type',7)
- ->where('user_id',$info['receiver'])
- ->where('bus_type',12)
- ->where('bus_id',$id)
- ->value('id');
- if($msgid){
- model('Message')->updataStatus($msgid,$info['receiver']); // 对应标记为已读消息
- }
- }
- unset($info['receiver']);
- $content = Db::name('work_news_item')->where('work_news_id',$info['id'])->field('content,date')->select();
- $info['content'] = json_encode($content);
- $receiver = Db::name('work_news_receiver')
- ->alias('wnr')
- ->join('user_info ui','ui.user_id = wnr.user_id')
- ->where('wnr.work_news_id',$info['id'])
- ->column('ui.name');
- $info['receiver'] = $receiver?implode(',',$receiver):'';
- return $info;
- }
- // 我提交的工作汇报
- public function lists($page,$size,$userId,$orgId){
- $map[] = ['org_id','=',$orgId];
- $map[] = ['user_id','=',$userId];
- $map[] = ['status','=',1];
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->field('id,user_id,work_type_id,create_time,status,audit_status')
- ->select();
- $lists = $lists?$lists->toArray():[];
- foreach ($lists as $k=>$v){
- $lists[$k]['typeName'] = Db::name('work_news_type')->where('id',$v['work_type_id'])->value('title');
- $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- //是否可以撤回
- $count = Db::name('work_news_receiver')->where('work_news_id',$v['id'])->where('is_read',1)->count();
- $lists[$k]['is_read'] = $count > 0?1:0;
- }
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- // 我收到的工作汇报
- public function receiveList($page,$size,$userId,$orgId){
- $map[] = ['wrr.org_id','=',$orgId];
- $map[] = ['wrr.user_id','=',$userId];
- $map[] = ['wr.status','=',1];
- $lists = Db::name('work_news_receiver')
- ->alias('wrr')
- ->join('work_news wr','wr.id = wrr.work_news_id')
- ->where($map)
- ->field('wr.user_id,wr.audit_status,wrr.type,wr.work_type_id,wrr.create_time,wrr.work_news_id,wrr.is_read,wrr.id')
- ->page($page,$size)
- ->order('wrr.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['typeName'] = Db::name('work_news_type')->where('id',$v['work_type_id'])->value('title');
- $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- }
- $total = Db::name('work_news_receiver')
- ->alias('wrr')
- ->join('work_news wr','wr.id = wrr.work_news_id')
- ->where($map)
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- public function myReceiver($userId,$orgId){
- $receiver = Db::name('work_news')
- ->where('org_id',$orgId)
- ->where('user_id',$userId)
- ->order('id desc')
- ->value('receiver');
- $receiver = '100006,100135'; // 暂时默认两人
- if(!$receiver){
- return [];
- }
- $receiver = explode(',',$receiver);
- $lists = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where('u.id','in',$receiver)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->field('u.id,ui.name')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $jobs = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->where('uj.user_id',$v['id'])
- ->where('j.del',0)
- ->where('j.enable',1)
- ->field('j.*')
- ->select();
- $lists[$k]['listJob'] = $jobs?$jobs:[];
- }
- return $lists;
- }
- public function auditor($userId,$orgId){
- $receiver = Db::name('work_news')
- ->where('org_id',$orgId)
- ->where('user_id',$userId)
- ->order('id desc')
- ->value('auditor');
- if(!$receiver){
- return [];
- }
- $lists = Db::name('user')
- ->alias('u')
- ->join('user_info ui','ui.user_id = u.id')
- ->where('u.id',$receiver)
- ->where('u.del',0)
- ->where('u.enable',1)
- ->field('u.id,ui.name')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $jobs = Db::name('user_job')
- ->alias('uj')
- ->join('job j','j.id = uj.job_id')
- ->where('uj.user_id',$v['id'])
- ->where('j.del',0)
- ->where('j.enable',1)
- ->field('j.*')
- ->select();
- $lists[$k]['listJob'] = $jobs?$jobs:[];
- }
- return $lists;
- }
- // 获取工作汇报未读数量
- public function unReadNums($userId,$orgId){
- $count = Db::name('work_news_receiver')
- ->where('is_read',0)
- ->where('user_id',$userId)
- ->where('org_id',$orgId)
- ->count();
- return $count;
- }
- public function cancel($id,$userId){
- $info = Db::name('work_news')->where('id',$id)->where('user_id',$userId)->find();
- if(!$info){
- HelpHander::error('记录不存在');
- }
- if($info['status'] == 0){
- HelpHander::error('记录已撤销');
- }
- //是否可以撤回
- $count = Db::name('work_news_receiver')->where('work_news_id',$id)->where('is_read',1)->count();
- if($count > 0){
- HelpHander::error('上级已阅读,无法撤销');
- }
- Db::startTrans();
- try{
- $res = Db::name('work_news')->where('id',$id)->update(['status' => 0,'update_time' => date('Y-m-d H:i:s')]);
- if(!$res){
- \exception('操作失败');
- }
- // 删除上级记录
- $lists = Db::name('work_news_receiver')->where('work_news_id',$id)->select();
- foreach ($lists as $k=>$v){
- Db::name('work_news_receiver')->where('id',$v['id'])->delete();
- Db::name('message')->where('type',3)->where('bus_id',$v['id'])->where('bus_type',13)->delete(); //原数据type=7
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function itemLists($page,$size,$userId,$orgId,$content,$workTypeId,$name){
- if($content){
- $map[] = ['wi.content','like','%'.$content.'%'];
- $map2[] = ['wi.content','like','%'.$content.'%'];
- }
- if($workTypeId > 0){
- $map[] = ['wr.work_type_id','=',$workTypeId];
- $map2[] = ['wr.work_type_id','=',$workTypeId];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- $map2[] = ['ui.name','like','%'.$name.'%'];
- }
- $map[] = ['wrr.org_id','=',$orgId];
- $map[] = ['wrr.user_id','=',$userId];
- $map[] = ['wr.status','=',1];
- $map[] = ['wr.audit_status','=',1];
- $map2[] = ['wrr.org_id','=',$orgId];
- $map2[] = ['wr.user_id','=',$userId];
- $map2[] = ['wr.status','=',1];
- $map2[] = ['wr.audit_status','=',1];
- $lists = Db::name('work_news_item')
- ->alias('wi')
- ->join('work_news wr','wr.id = wi.work_news_id')
- ->join('user_info ui','ui.user_id = wr.user_id')
- ->join('work_news_receiver wrr','wrr.work_news_id = wr.id','left')
- ->whereOr([ $map, $map2 ])
- ->field('wr.id,wr.user_id,wr.work_type_id,wr.create_time,wi.content,wi.date,wi.id as item_id')
- ->page($page,$size)
- ->group('wi.id')
- ->order('wi.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['typeName'] = Db::name('work_news_type')->where('id',$v['work_type_id'])->value('title');
- $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- $lists[$k]['label_id'] = 0;
- $lists[$k]['label_name'] = '';
- $label = Db::name('work_news_item_label')->where('user_id',$userId)->where('item_id',$v['item_id'])->find();
- if($label){
- $lists[$k]['label_id'] = $label['id'];
- if($label['label'] == 1){
- $lists[$k]['label_name'] = '留存';
- }else if($label['label'] == 2){
- $lists[$k]['label_name'] = '一般';
- }else{
- $lists[$k]['label_name'] = '重要';
- }
- }
- }
- $total = Db::name('work_news_item')
- ->alias('wi')
- ->join('work_news wr','wr.id = wi.work_news_id')
- ->join('user_info ui','ui.user_id = ui.user_id')
- ->join('work_news_receiver wrr','wrr.work_news_id = wr.id','left')
- ->whereOr([ $map, $map2 ])
- ->group('wi.id')
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- public function itemAll($userId,$orgId,$content,$workTypeId,$name){
- if($content){
- $map[] = ['wi.content','like','%'.$content.'%'];
- $map2[] = ['wi.content','like','%'.$content.'%'];
- }
- if($workTypeId > 0){
- $map[] = ['wr.work_type_id','=',$workTypeId];
- $map2[] = ['wr.work_type_id','=',$workTypeId];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- $map2[] = ['ui.name','like','%'.$name.'%'];
- }
- $map[] = ['wrr.org_id','=',$orgId];
- $map[] = ['wrr.user_id','=',$userId];
- $map[] = ['wr.status','=',1];
- $map[] = ['wr.audit_status','=',1];
- $map2[] = ['wrr.org_id','=',$orgId];
- $map2[] = ['wr.user_id','=',$userId];
- $map2[] = ['wr.status','=',1];
- $map2[] = ['wr.audit_status','=',1];
- $lists = Db::name('work_news_item')
- ->alias('wi')
- ->join('work_news wr','wr.id = wi.work_news_id')
- ->join('user_info ui','ui.user_id = ui.user_id')
- ->join('work_news_receiver wrr','wrr.work_news_id = wr.id','left')
- ->whereOr([ $map, $map2 ])
- ->field('wr.id,wr.user_id,wr.work_type_id,wr.create_time,wi.content,wi.date,wi.id as item_id')
- ->group('wi.id')
- ->order('wi.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['typeName'] = Db::name('work_news_type')->where('id',$v['work_type_id'])->value('title');
- $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- $lists[$k]['label_id'] = 0;
- $lists[$k]['label_name'] = '';
- $label = Db::name('work_news_item_label')->where('user_id',$userId)->where('item_id',$v['item_id'])->find();
- if($label){
- $lists[$k]['label_id'] = $label['id'];
- if($label['label'] == 1){
- $lists[$k]['label_name'] = '留存';
- }else if($label['label'] == 2){
- $lists[$k]['label_name'] = '一般';
- }else{
- $lists[$k]['label_name'] = '重要';
- }
- }
- }
- $columns = [
- ["title" => "姓名","key" => "userName"],
- ["title" => "类型","key" => "typeName"],
- ["title" => "工作内容","key" => "content"],
- ["title" => "完成时间","key" => "date"],
- ["title" => "标注","key" => "labelName"],
- ];
- $data = [
- 'columns' => $columns,
- 'list' => $lists
- ];
- return $data;
- }
- public function allItemLists($page,$size,$userId,$orgId,$content,$workTypeId,$name,$label){
- if($content){
- $map[] = ['wi.content','like','%'.$content.'%'];
- }
- if($workTypeId > 0){
- $map[] = ['wr.work_type_id','=',$workTypeId];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($label > 0){
- $ids = Db::name('work_news_item_label')->where('label',$label)->where('user_id',$userId)->column('item_id');
- if($ids){
- $map[] = ['wi.id','in',$ids];
- }
- }
- $map[] = ['wrr.org_id','=',$orgId];
- $map[] = ['wr.status','=',1];
- $map[] = ['wr.audit_status','=',1];
- $lists = Db::name('work_news_item')
- ->alias('wi')
- ->join('work_news wr','wr.id = wi.work_news_id')
- ->join('user_info ui','ui.user_id = wr.user_id')
- ->join('work_news_receiver wrr','wrr.work_news_id = wr.id','left')
- ->where($map)
- ->field('wr.id,wr.user_id,wr.work_type_id,wr.create_time,wi.content,wi.date,wi.id as item_id')
- ->page($page,$size)
- ->order('wi.id desc')
- ->group('wi.id')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['typeName'] = Db::name('work_news_type')->where('id',$v['work_type_id'])->value('title');
- $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- $lists[$k]['label_id'] = 0;
- $lists[$k]['label_name'] = '';
- $label = Db::name('work_news_item_label')->where('user_id',$userId)->where('item_id',$v['item_id'])->find();
- if($label){
- $lists[$k]['label_id'] = $label['id'];
- if($label['label'] == 1){
- $lists[$k]['label_name'] = '留存';
- }else if($label['label'] == 2){
- $lists[$k]['label_name'] = '一般';
- }else{
- $lists[$k]['label_name'] = '重要';
- }
- }
- }
- $total = Db::name('work_news_item')
- ->alias('wi')
- ->join('work_news wr','wr.id = wi.work_news_id')
- ->join('user_info ui','ui.user_id = wr.user_id')
- ->join('work_news_receiver wrr','wrr.work_news_id = wr.id','left')
- ->where($map)
- ->group('wi.id')
- ->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- public function allItemAll($userId,$orgId,$content,$workTypeId,$name,$label){
- if($content){
- $map[] = ['wi.content','like','%'.$content.'%'];
- }
- if($workTypeId > 0){
- $map[] = ['wr.work_type_id','=',$workTypeId];
- }
- if($name){
- $map[] = ['ui.name','like','%'.$name.'%'];
- }
- if($label > 0){
- $ids = Db::name('work_news_item_label')->where('label',$label)->where('user_id',$userId)->column('item_id');
- if($ids){
- $map[] = ['wi.id','in',$ids];
- }
- }
- $map[] = ['wrr.org_id','=',$orgId];
- $map[] = ['wr.status','=',1];
- $map[] = ['wr.audit_status','=',1];
- $lists = Db::name('work_news_item')
- ->alias('wi')
- ->join('work_news wr','wr.id = wi.work_news_id')
- ->join('user_info ui','ui.user_id = wr.user_id')
- ->join('work_news_receiver wrr','wrr.work_news_id = wr.id','left')
- ->where($map)
- ->field('wr.id,wr.user_id,wr.work_type_id,wr.create_time,wi.content,wi.date,wi.id as item_id')
- ->order('wi.id desc')
- ->group('wi.id')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['typeName'] = Db::name('work_news_type')->where('id',$v['work_type_id'])->value('title');
- $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
- $lists[$k]['label_id'] = 0;
- $lists[$k]['label_name'] = '';
- $label = Db::name('work_news_item_label')->where('user_id',$userId)->where('item_id',$v['item_id'])->find();
- if($label){
- $lists[$k]['label_id'] = $label['id'];
- if($label['label'] == 1){
- $lists[$k]['label_name'] = '留存';
- }else if($label['label'] == 2){
- $lists[$k]['label_name'] = '一般';
- }else{
- $lists[$k]['label_name'] = '重要';
- }
- }
- }
- $columns = [
- ["title" => "姓名","key" => "userName"],
- ["title" => "类型","key" => "typeName"],
- ["title" => "工作内容","key" => "content"],
- ["title" => "完成时间","key" => "date"],
- ["title" => "标注","key" => "labelName"],
- ];
- $data = [
- 'columns' => $columns,
- 'list' => $lists
- ];
- return $data;
- }
- public function addLabel($itemId,$type,$userId){
- $data = [
- 'item_id' => $itemId,
- 'label' => $type,
- 'user_id' => $userId
- ];
- $ret = Db::name('work_news_item_label')->insertGetId($data);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function delLabel($id,$userId){
- $ret = Db::name('work_news_item_label')->where('id',$id)->where('user_id',$userId)->delete();
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function unapply($userId){
- $lists = Db::name('work_news_receiver')
- ->alias('wnr')
- ->join('work_news wn','wn.id = wnr.work_news_id')
- ->join('user_info ui','ui.user_id = wn.user_id')
- ->join('work_news_type unt','unt.id = wn.work_type_id')
- ->where('wnr.user_id',$userId)
- ->where('wnr.is_read',0)
- ->where('wn.status',1)
- ->field('wnr.id,ui.name,unt.title,wnr.create_time')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['title'] = $v['name']."提交的".$v['title'];
- unset($lists[$k]['name']);
- }
- return $lists;
- }
- public function agree($id){
- $info = Db::name('work_news')->where('id',$id)->find();
- if(!$info){
- HelpHander::error('记录不存在');
- }
- if($info['audit_status'] != 0){
- HelpHander::error('记录已审核');
- }
- $curTime = date('Y-m-d H:i:s');
- Db::startTrans();
- try{
- $res = Db::name('work_news')->where('id',$id)->update(['audit_status' => 1,'audit_time' => $curTime]);
- if(!$res){
- \exception('操作失败');
- }
- $receiver = $info['receiver']?explode(',',$info['receiver']):[];
- $username = Db::name('user_info')->where('user_id',$info['user_id'])->value('name');
- foreach ($receiver as $k=>$v){
- $d = [
- 'org_id' => $info['org_id'],
- 'user_id' => $v,
- 'create_time' => $curTime,
- 'is_read' => 0,
- 'work_news_id' => $id,
- 'type' => 0
- ];
- $wrrid = Db::name('work_news_receiver')->insertGetId($d);
- if(!$wrrid){
- \exception('提交失败');
- }
- $typename = Db::name('work_news_type')->where('id',$info['work_type_id'])->value('title');
- $context = $username.'提交的'.$typename.'工作动态';
- $ret = model('Message')->add(3,$wrrid,13,$v,$info['org_id'],$context);
- if(!$ret){
- \exception('提交失败');
- }
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function disagree($id){
- $info = Db::name('work_news')->where('id',$id)->find();
- if(!$info){
- HelpHander::error('记录不存在');
- }
- if($info['audit_status'] != 0){
- HelpHander::error('记录已审核');
- }
- $curTime = date('Y-m-d H:i:s');
- Db::startTrans();
- try{
- $res = Db::name('work_news')->where('id',$id)->update(['audit_status' => 2,'audit_time' => $curTime]);
- if(!$res){
- \exception('操作失败');
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error('操作失败');
- }
- return true;
- }
- }
|