1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class HouseContractDefault extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'intro' => input('intro','','trim'),
- 'contract_id' => input('contractId/d',0),
- 'default_date' => input('defaultDate','','trim'),
- 'remark' => input('remark','','trim'),
- 'files' => input('files','','trim'),
- 'org_id' => input('orgId/d',0),
- ];
- $result = validate('HouseContractDefault')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('HouseContractDefault')->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 del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($page,$size,$intro,$contractId,$orgId){
- $map[] = ['org_id','=',$orgId];
- if($intro != ''){
- $map[] = ['intro','like','%'.$intro.'%'];
- }
- if($contractId > 0){
- $map[] = ['contract_id','=',$contractId];
- }
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists->toArray():[];
- foreach ($lists as $k=>$v){
- $files = $v['files']?json_decode($v['files'],true):[];
- $lists[$k]['filesUrl'] = empty($files)?'':$files[0]['url'];
- $lists[$k]['filesName'] = empty($files)?'':$files[0]['name'];
- }
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- }
|