123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class Program extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'sn' => input('sn','','trim'),
- 'content' => input('content','','trim'),
- 'enable' => input('enable/d',1),
- 'org_id' => input('orgId/d',0),
- 'company_id' => input('companyId/d',0)
- ];
- $logdata = json_encode($data);
- $result = validate('Program')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('Program')->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('操作失败');
- }
- if($id > 0){
- $content = '修改项目';
- }else{
- $content = '添加项目';
- }
- model('ActionLog')->add(3,$content,0,$logdata);
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->where('del',0)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($page,$size,$title,$companyId,$orgId){
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$orgId];
- $map[] = ['company_id','=',$companyId];
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- public function allLists($orgId){
- $map[] = ['org_id','=',$orgId];
- $map[] = ['del','=',0];
- $map[] = ['enable','=',1];
- $lists = $this
- ->where($map)
- ->field('id,title,company_id')
- ->order('id desc')
- ->select();
- return $lists?$lists->toArray():[];
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- $logdata = json_encode(['id' => $id]);
- model('ActionLog')->add(3,'删除项目',0,$logdata);
- return true;
- }
- }
|