12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class Certificate extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'remark' => input('remark','','trim'),
- 'org_id' => input('orgId/d',0),
- 'user_id' => input('uid/d',0),
- 'end_time' => input('endTime','','trim'),
- 'status' => input('status/d',1)
- ];
- $logdata = json_encode($data);
- $result = validate('Certificate')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('Certificate')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- if($id > 0){
- $content = '修改证件';
- }else{
- $content = '添加证件';
- }
- model('ActionLog')->add(8,$content,0,$logdata);
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($page,$size,$title,$userName){
- $map[] = ['c.del','=',0];
- if($title){
- $map[] = ['c.title','like','%'.$title.'%'];
- }
- if($userName){
- $map[] = ['ui.name','like','%'.$userName.'%'];
- }
- $lists = Db::name('certificate')
- ->alias('c')
- ->join('user_info ui','ui.user_id = c.user_id')
- ->field('c.*,ui.name as userName')
- ->where($map)
- ->page($page,$size)
- ->order('c.id desc')
- ->select();
- $total = Db::name('certificate')
- ->alias('c')
- ->join('user_info ui','ui.user_id = c.user_id')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- $logdata = json_encode(['id' => $id]);
- model('ActionLog')->add(8,'删除证件',0,$logdata);
- return true;
- }
- }
|