123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use app\Request;
- use think\Db;
- use think\Model;
- class File extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'sn' => input('sn','','trim'),
- 'source' => input('source','','trim'),
- 'remark' => input('remark','','trim'),
- 'sw_time' => input('swTime','','trim'),
- 'enable' => input('enable/d',0),
- 'org_id' => input('orgId/d',0),
- ];
- if(!$data['sw_time']){
- $data['sw_time'] = null;
- }
- $result = validate('File')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('File')->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('操作失败');
- }
- 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)->update(['del'=>1]);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($page,$size,$sn,$source,$title,$enable,$swTime,$orgId){
- $map[] = ['org_id','=',$orgId];
- $map[] = ['del','=',0];
- if($sn != ''){
- $map[] = ['sn','like','%'.$sn.'%'];
- }
- if($source != ''){
- $map[] = ['source','like','%'.$source.'%'];
- }
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- if($enable >= 0){
- $map[] = ['enable','=',$enable];
- }
- if($swTime != ''){
- $map[] = ['sw_time','=',$swTime];
- }
- $lists = Db::name('file')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $iid = Db::name('important')->where('transfer_id',$v['id'])->where('del',0)->value('id');
- $lists[$k]['transfer'] = $iid > 0?1:0;
- }
- $total = Db::name('file')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- }
|