Manager.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. class Manager extends BaseModel {
  5. protected $table = "message";
  6. public $timestamps = false;
  7. function getlist($list = 10, $where = '') {
  8. $data = $this->orderBy('add_time', 'desc');
  9. if (!empty($where) && is_array($where)) {
  10. $data = $data->where($where);
  11. }
  12. $data = $data->paginate($list);
  13. if (!$data) {
  14. return -4010010022; //没有数据
  15. }
  16. return $data->toArray();
  17. }
  18. //获取信息
  19. function getMsg($value, $type) {
  20. $fild = $this->getfild($type);
  21. $data = $this->where($fild, $value)->orderBy('add_time', 'desc')->limit(10)->get();
  22. if (!$data) {
  23. return -4010010122; //没有数据
  24. }
  25. return $data->toArray();
  26. }
  27. function getDmsg($value, $type) {
  28. $fild = $this->getfild($type);
  29. $data = $this->where($fild, $value)->first();
  30. if (!$data) {
  31. return -4010010122; //没有数据
  32. }
  33. return $data->toArray();
  34. }
  35. function getfild($k) {
  36. $a = array(
  37. 1 => 'id',
  38. 2 => 'type',
  39. );
  40. return $a[$k];
  41. }
  42. function updateMsg($data, $id) {
  43. $res = $this->where('id', $id)->update($data);
  44. if (!$res) {
  45. return -4010011122;
  46. }
  47. return 1;
  48. }
  49. function updateMessage($sender, $reciver, $title, $content, $type)
  50. {
  51. $data['add_time']=date('Y-m-d H:i:s');
  52. $data['formname']=$sender;
  53. $data['toname']=$reciver;
  54. $data['title'] = $title;
  55. $data['type'] =$type;
  56. $data['content'] = $content;
  57. //普通消息
  58. if ($data['type'] == 2){
  59. $dataName=explode(',',$data['toname']);
  60. foreach ($dataName as $v){
  61. $data['toname']=$v;
  62. $this->addNotice($data);
  63. }
  64. }
  65. //系统消息
  66. if ($data['type'] == 1){
  67. $data['formname']='system';
  68. $data['toname']='all';
  69. $this->addNotice($data);
  70. }
  71. //系统通知
  72. if ($data['type'] == 3){
  73. $data['formname']='notice';
  74. $data['toname']='all';
  75. $this->addNotice($data);
  76. }
  77. //系统通知
  78. if ($data['type'] == 4){
  79. $data['formname']='admin';
  80. $data['toname']='admin_all';
  81. $this->addNotice($data);
  82. }
  83. }
  84. //添加公告数据
  85. function addNotice($data){
  86. // DB::connection()->enableQueryLog();
  87. $res = $this->insertGetId ($data);
  88. // $queries = DB::getQueryLog();
  89. // print_r($queries);
  90. if(!$res){
  91. return -6030001222;
  92. }
  93. return $res;
  94. }
  95. function getlistd($where) {
  96. $data = $this->where($where[0], $where[1])->orderBy('add_time', 'desc')->limit(5)->get();
  97. if (!$data) {
  98. return -4010011122;
  99. }
  100. return $data->toArray();
  101. }
  102. }