12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class ImportantRecordAnnotation extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'user_id' => input('userId/d',0),
- 'content' => input('content','','trim'),
- 'files' => input('files','','trim'),
- 'org_id' => input('orgId/d',0),
- 'important_record_id' => input('importantRecordId/d',0),
- ];
- $result = validate('ImportantRecordAnnotation')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('ImportantRecordAnnotation')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- Db::startTrans();
- try{
- 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){
- \exception('操作失败');
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error($e->getMessage());
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($id){
- $map[] = ['del','=',0];
- $map[] = ['important_record_id','=',$id];
- $lists = Db::name('important_record_annotation')
- ->where($map)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['files'] = $v['files']?json_decode($v['files'],true):[];
- }
- return $lists;
- }
- // 办结
- public function del($id,$user){
- $ret = Db::name('important_record_annotation')->where('id',$id)->where('user_id',$user)->delete();
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- }
|