ImportantRecordAnnotation.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class ImportantRecordAnnotation extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'user_id' => input('userId/d',0),
  13. 'content' => input('content','','trim'),
  14. 'files' => input('files','','trim'),
  15. 'org_id' => input('orgId/d',0),
  16. 'important_record_id' => input('importantRecordId/d',0),
  17. ];
  18. $result = validate('ImportantRecordAnnotation')->check($data,[],'');
  19. if(true !== $result){
  20. HelpHander::error(validate('ImportantRecordAnnotation')->getError());
  21. }
  22. $id = $data['id'];
  23. unset($data['id']);
  24. Db::startTrans();
  25. try{
  26. if($id > 0){
  27. $data['update_time'] = date('Y-m-d H:i:s');
  28. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  29. }else{
  30. $data['create_time'] = date('Y-m-d H:i:s');
  31. $ret = $this->allowField(true)->save($data);
  32. }
  33. if(!$ret){
  34. \exception('操作失败');
  35. }
  36. Db::commit();
  37. }catch (Exception $e){
  38. Db::rollback();
  39. HelpHander::error($e->getMessage());
  40. }
  41. return true;
  42. }
  43. public function info($id){
  44. $info = $this->where('id',$id)->find();
  45. if(!$info){
  46. HelpHander::error('数据不存在');
  47. }
  48. return $info->toArray();
  49. }
  50. public function lists($id){
  51. $map[] = ['del','=',0];
  52. $map[] = ['important_record_id','=',$id];
  53. $lists = Db::name('important_record_annotation')
  54. ->where($map)
  55. ->order('id desc')
  56. ->select();
  57. $lists = $lists?$lists:[];
  58. foreach ($lists as $k=>$v){
  59. $lists[$k]['files'] = $v['files']?json_decode($v['files'],true):[];
  60. }
  61. return $lists;
  62. }
  63. // 办结
  64. public function del($id,$user){
  65. $ret = Db::name('important_record_annotation')->where('id',$id)->where('user_id',$user)->delete();
  66. if(!$ret){
  67. HelpHander::error('操作失败');
  68. }
  69. return true;
  70. }
  71. }