OfficialDocs.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. namespace app\adm\model;
  14. use think\model;
  15. use think\facade\Db;
  16. class OfficialDocs extends Model
  17. {
  18. //密级程度
  19. public static $Secrets = ['','公开','秘密','机密'];
  20. //紧急程度
  21. public static $Urgency = ['','普通','紧急','加急'];
  22. /**
  23. * 获取分页列表
  24. * @param $where
  25. * @param $param
  26. */
  27. public function datalist($param=[],$where=[],$whereOr=[])
  28. {
  29. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  30. $order = empty($param['order']) ? 'id desc' : $param['order'];
  31. try {
  32. $list = self::where($where)
  33. ->where(function ($query) use($whereOr) {
  34. if (!empty($whereOr)){
  35. $query->whereOr($whereOr);
  36. }
  37. })
  38. ->order($order)
  39. ->paginate(['list_rows'=> $rows])
  40. ->each(function ($item, $key){
  41. $item->secrets_str = self::$Secrets[$item->secrets];
  42. $item->urgency_str = self::$Urgency[$item->urgency];
  43. $item->check_status_str = check_status_name($item->check_status);
  44. $item->draft_time = date('Y-m-d', $item->draft_time);
  45. $item->draft_name = Db::name('Admin')->where('id','=',$item->draft_uid)->value('name');
  46. $item->draft_dname = Db::name('Department')->where('id','=',$item->did)->value('title');
  47. $item->create_time = to_date($item->create_time);
  48. });
  49. return $list;
  50. } catch(\Exception $e) {
  51. return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
  52. }
  53. }
  54. /**
  55. * 添加数据
  56. * @param $param
  57. */
  58. public function add($param)
  59. {
  60. $insertId = 0;
  61. try {
  62. $param['create_time'] = time();
  63. $insertId = self::strict(false)->field(true)->insertGetId($param);
  64. add_log('add', $insertId, $param);
  65. } catch(\Exception $e) {
  66. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  67. }
  68. return to_assign(0,'操作成功',['aid'=>$insertId]);
  69. }
  70. /**
  71. * 编辑信息
  72. * @param $param
  73. */
  74. public function edit($param)
  75. {
  76. try {
  77. $param['update_time'] = time();
  78. self::where('id', $param['id'])->strict(false)->field(true)->update($param);
  79. add_log('edit', $param['id'], $param);
  80. } catch(\Exception $e) {
  81. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  82. }
  83. return to_assign();
  84. }
  85. /**
  86. * 根据id获取信息
  87. * @param $id
  88. */
  89. public function getById($id)
  90. {
  91. $info = self::find($id);
  92. $info['draft_name'] = Db::name('Admin')->where('id','=',$info['draft_uid'])->value('name');
  93. $info['draft_dame'] = Db::name('Department')->where('id','=',$info['did'])->value('title');
  94. $send_names = Db::name('Admin')->where([['id','in',$info['send_uids']]])->column('name');
  95. $info['send_names'] =implode(',' ,$send_names);
  96. $copy_names = Db::name('Admin')->where([['id','in',$info['copy_uids']]])->column('name');
  97. $info['copy_names'] =implode(',' ,$copy_names);
  98. $share_names = Db::name('Admin')->where([['id','in',$info['share_uids']]])->column('name');
  99. $info['share_names'] =implode(',' ,$share_names);
  100. if(!empty($info['file_ids'])){
  101. $file_array = Db::name('File')->where('id','in',$info['file_ids'])->select();
  102. $info['file_array'] = $file_array;
  103. }
  104. return $info;
  105. }
  106. /**
  107. * 删除信息
  108. * @param $id
  109. * @param $type
  110. * @return array
  111. */
  112. public function delById($id,$type=0)
  113. {
  114. if($type==0){
  115. //逻辑删除
  116. try {
  117. $param['delete_time'] = time();
  118. self::where('id', $id)->update(['delete_time'=>time()]);
  119. add_log('delete', $id);
  120. } catch(\Exception $e) {
  121. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  122. }
  123. }
  124. else{
  125. //物理删除
  126. try {
  127. self::destroy($id);
  128. add_log('delete', $id);
  129. } catch(\Exception $e) {
  130. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  131. }
  132. }
  133. return to_assign();
  134. }
  135. }