123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use app\Request;
- use think\Db;
- use think\Model;
- class NoticeUserTemp extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'userids' => input('userids','','trim'),
- 'title' => input('title','','trim'),
- 'org_id' => input('orgId/d',0),
- ];
- trace($data);
- $result = validate('NoticeUserTemp')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('NoticeUserTemp')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $data = $info->toArray();
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($page,$size,$title,$orgId){
- $map[] = ['org_id','=',$orgId];
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- $lists = Db::name('notice_user_temp')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $userids = $v['userids']?explode(',',$v['userids']):[];
- $userNames = [];
- foreach ($userids as $kk=>$vv){
- $uinfo = Db::name('user_info')
- ->where('user_id',$vv)
- ->field('user_id,name')
- ->find();
- $userNames[] = $uinfo?$uinfo['name']:'';
- }
- $lists[$k]['userNames'] = $userNames?implode(',',$userNames):'';
- }
- $total = Db::name('notice_user_temp')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- public function all($orgId){
- $map[] = ['org_id','=',$orgId];
- $lists = Db::name('notice_user_temp')
- ->where($map)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $userids = $v['userids']?explode(',',$v['userids']):[];
- $userNames = [];
- foreach ($userids as $kk=>$vv){
- $uinfo[$kk] = Db::name('user_info')
- ->where('user_id',$vv)
- ->field('user_id,name')
- ->find();
- $userNames = $uinfo?$uinfo:[];
- }
- $lists[$k]['userNames']=$userNames;
- }
- return $lists?$lists:[];
- }
- }
|