Disk.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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\disk\model;
  14. use think\model;
  15. use think\facade\Db;
  16. class Disk extends Model
  17. {
  18. protected $autoWriteTimestamp=false;
  19. /**
  20. * 获取分页列表
  21. * @param $where
  22. * @param $param
  23. */
  24. public function datalist($param,$where,$whereOr=[])
  25. {
  26. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  27. try {
  28. $list = self::where($where)
  29. ->where(function ($query) use($whereOr) {
  30. if (!empty($whereOr)){
  31. $query->whereOr($whereOr);
  32. }
  33. })
  34. ->orderRaw("case when types = 2 then 1 else 2 end, id desc")
  35. ->paginate(['list_rows'=> $rows])
  36. ->each(function ($item, $key){
  37. $item->admin_name = Db::name('Admin')->where('id',$item->admin_id)->value('name');
  38. $item->department = Db::name('Department')->where('id',$item->did)->value('title');
  39. if($item->types == 0){
  40. $item->filepath = Db::name('File')->where('id',$item->action_id)->value('filepath');
  41. $item->thumbpath = Db::name('File')->where('id',$item->action_id)->value('thumbpath');
  42. if(empty($item->thumbpath)){
  43. $item->thumbpath = $item->filepath;
  44. }
  45. }
  46. else{
  47. $item->filepath='';
  48. $item->thumbpath='';
  49. }
  50. });
  51. return $list;
  52. } catch(\Exception $e) {
  53. return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
  54. }
  55. }
  56. /**
  57. * 添加数据
  58. * @param $param
  59. */
  60. public function add($param)
  61. {
  62. $insertId = 0;
  63. try {
  64. $param['create_time'] = time();
  65. $insertId = self::strict(false)->field(true)->insertGetId($param);
  66. add_log('add', $insertId, $param);
  67. } catch(\Exception $e) {
  68. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  69. }
  70. return to_assign(0,'操作成功',['return_id'=>$insertId]);
  71. }
  72. /**
  73. * 编辑信息
  74. * @param $param
  75. */
  76. public function edit($param)
  77. {
  78. try {
  79. $param['update_time'] = time();
  80. self::where('id', $param['id'])->strict(false)->field(true)->update($param);
  81. $info = self::find($param['id']);
  82. if($info['types'] == 0){
  83. Db::name('File')->where('id',$info['action_id'])->update(['name'=>$param['name']]);
  84. }
  85. if($info['types'] == 1){
  86. Db::name('Article')->where('id',$info['action_id'])->update(['name'=>$param['name'],'update_time'=>time()]);
  87. }
  88. add_log('edit', $param['id'], $param);
  89. } catch(\Exception $e) {
  90. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  91. }
  92. return to_assign(0,'操作成功',['return_id'=>$param['id']]);
  93. }
  94. /**
  95. * 根据id获取信息
  96. * @param $id
  97. */
  98. public function getById($id)
  99. {
  100. $info = self::find($id);
  101. return $info;
  102. }
  103. /**
  104. * 删除信息
  105. * @param $id
  106. * @param $type
  107. * @return array
  108. */
  109. public function delById($id,$type=0)
  110. {
  111. if($type==0){
  112. //逻辑删除
  113. try {
  114. $param['delete_time'] = time();
  115. self::where('id', $id)->update(['delete_time'=>time()]);
  116. add_log('delete', $id);
  117. } catch(\Exception $e) {
  118. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  119. }
  120. }
  121. else{
  122. //物理删除
  123. try {
  124. self::destroy($id);
  125. add_log('delete', $id);
  126. } catch(\Exception $e) {
  127. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  128. }
  129. }
  130. return to_assign();
  131. }
  132. }