Banner.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. class Banner extends BaseModel {
  5. protected $table = "banner";
  6. public $timestamps = false;
  7. function getlist($list = 10, $where = '') {
  8. $data = $this->orderBy('sort', '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. //添加公告数据
  50. function addNotice($data){
  51. // DB::connection()->enableQueryLog();
  52. $res=$this->insert($data);
  53. // $queries = DB::getQueryLog();
  54. // print_r($queries);
  55. if(!$res){
  56. return -6030001222;
  57. }
  58. }
  59. function getlistd($where) {
  60. $data = $this->where($where[0], $where[1])->orderBy('add_time', 'desc')->limit(5)->get();
  61. if (!$data) {
  62. return -4010011122;
  63. }
  64. return $data->toArray();
  65. }
  66. }