Msg.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\home\model;
  14. use think\Model;
  15. use think\facade\Db;
  16. class Msg extends Model
  17. {
  18. /**
  19. * 获取分页列表
  20. * @param $where
  21. * @param $param
  22. */
  23. public function datalist($where, $param)
  24. {
  25. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  26. $order = empty($param['order']) ? 'id desc' : $param['order'];
  27. try {
  28. $list = self::where($where)
  29. ->order($order)
  30. ->paginate(['list_rows'=> $rows])
  31. ->each(function ($item, $key){
  32. $item->from_name = '系统';
  33. $item->thumb = '/static/home/images/icon.png';
  34. $item['create_time'] = to_date($item['create_time'],'Y-m-d H:i:s');
  35. if($item->from_uid>0){
  36. $from_name = Db::name('Admin')->where('id',$item->from_uid)->find();
  37. $item->from_name = $from_name['name'];
  38. $item->thumb = $from_name['thumb'];
  39. }
  40. if(!empty($item->uids)){
  41. $to_name = Db::name('Admin')->where(['id','in',$item->uids])->column('name');
  42. $item->to_name = implode(',',$to_name);
  43. }
  44. else{
  45. $item->to_name = '-';
  46. }
  47. });
  48. return $list;
  49. } catch(\Exception $e) {
  50. return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
  51. }
  52. }
  53. //消息详情
  54. public function detail($id)
  55. {
  56. $detail = self::find($id);
  57. if(!empty($detail)){
  58. //消息附件
  59. $file_array = Db::name('File')->order('create_time desc')->where([['id','in',$detail['file_ids']]])->select()->toArray();
  60. $detail['file_array'] = $file_array;
  61. //引用消息附件
  62. if($detail['msg_id']>0){
  63. $from_msg = Db::name('Msg')->find($detail['msg_id']);
  64. if(!empty($from_msg)){
  65. $detail['from_template'] = $from_msg['template'];
  66. $detail['from_action_id'] = $from_msg['action_id'];
  67. $detail['from_content'] = $from_msg['content'];
  68. $detail['from_file_ids'] = $from_msg['file_ids'];
  69. $from_file_array = Db::name('File')->order('create_time desc')->where([['id','in',$detail['from_file_ids']]])->select()->toArray();
  70. $detail['from_file_array'] = $from_file_array;
  71. }
  72. }
  73. $detail['create_time'] = to_date($detail['create_time'],'Y-m-d H:i:s');
  74. }
  75. return $detail;
  76. }
  77. }