Article.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Models;
  3. class Article extends BaseModel {
  4. protected $table = "article";
  5. public $timestamps = false;
  6. function getlist($list = 10, $where = '') {
  7. $data = $this->select('title', 'id', 'time', 'type','child_id','sort','status','typebind')->orderBy('time', 'desc')->where('type', '!=', 8)->where('type', '!=', 9);
  8. if (!empty($where) && is_array($where)) {
  9. $data = $data->where($where);
  10. }
  11. $data = $data->paginate($list);
  12. if (!$data) {
  13. return -4010010022; //没有数据
  14. }
  15. return $data->toArray();
  16. }
  17. //获取信息
  18. function getMsg($value, $type) {
  19. $fild = $this->getfild($type);
  20. $data = $this->select('id', 'time', 'title')->where($fild, $value)->orderBy('time', 'desc')->limit(10)->get();
  21. if (!$data) {
  22. return -4010010122; //没有数据
  23. }
  24. return $data->toArray();
  25. }
  26. function getDmsg($value, $type) {
  27. $fild = $this->getfild($type);
  28. $data = $this->select('id', 'time', 'title', 'content','img','author','type','sort','child_id','mobilecontent','mobileimg','typebind')->where($fild, $value)->first();
  29. if (!$data) {
  30. return -4010010122; //没有数据
  31. }
  32. return $data->toArray();
  33. }
  34. function getfild($k) {
  35. $a = array(
  36. 1 => 'id',
  37. 2 => 'type',
  38. );
  39. return $a[$k];
  40. }
  41. function updateMsg($data, $id) {
  42. $res = $this->where('id', $id)->update($data);
  43. if (!$res) {
  44. return -4010011122;
  45. }
  46. return 1;
  47. }
  48. //添加公告数据
  49. function addNotice($data){
  50. $res=$this->insert($data);
  51. if(!$res){
  52. return -6030001222;
  53. }
  54. }
  55. //获取内容
  56. function getContent($type){
  57. $data=$this->where('type',$type)->orderBy('time', 'asc')->first();
  58. if(!$data){
  59. return -4010010022; //没有数据
  60. }
  61. return $data->toArray();
  62. }
  63. //更新内容
  64. function updateContent($data,$type){
  65. //检查是否存在
  66. $check=$this->getContent($type);
  67. if(!$check<0){
  68. $data['type']=$type;
  69. $data['identity']=UUID();
  70. $res=$this->insert($data);
  71. }else{
  72. $res=$this->where('type',$type)->orderBy('time', 'asc')->update($data);
  73. }
  74. if(!$res){
  75. return -4010011122;
  76. }
  77. return 1;
  78. }
  79. public function closeGame($where,$data){
  80. return $this->where($where)->update($data);
  81. }
  82. }