BlogPlateModel.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Web\Models;
  3. use App\Models\BaseModel;
  4. class BlogPlateModel extends BaseModel
  5. {
  6. /**
  7. * 状态字段
  8. */
  9. const DELETED_AT = 'status';
  10. const NEWS = 1;
  11. const SUCCESSCASES = 2;
  12. const Q_AND_A = 3;
  13. const PARTNERS = 4;
  14. const KNOWLEDGECENTRE = 5;
  15. const SOLUTION = 6;
  16. const VIDEO = 7;
  17. const SPONSOR = 8; //视频
  18. const TOURISM = 9;
  19. const CATERING = 10;
  20. const ABOUTUS = 11;
  21. const JOB = 13;
  22. const FUNGI_COMMENT = 13; //岗位招聘
  23. const Media = 15;
  24. /**
  25. * @var string
  26. */
  27. protected $table = 'blog_plate';
  28. // const HOTEL = 8;
  29. // const COMMENT = 13;
  30. // const TOURISM_PARTNERS = 15;
  31. /**
  32. * 获取文章板块
  33. * */
  34. public function getBlogPlateList($params, $fields = '')
  35. {
  36. list($pageSize, $page, $skip) = $this->getPaginatorParams($params);
  37. $where = [];
  38. if (isset($params['status'])) {
  39. $where[] = ['a.status', '=', $params['status']];
  40. } else {
  41. $where[] = ['a.status', '<', 2];
  42. }
  43. if (empty($fields)) {
  44. $fields = 'a.*,b.urla,b.seo_title,b.seo_keyword,b.seo_describe';
  45. }
  46. $query = $this->newInstance()->alias('a')
  47. ->leftJoin('web_seo as b', 'a.seo_id', '=', 'b.id')
  48. ->where($where);
  49. if (!empty($params['keyword'])) {
  50. $keyword = $params['keyword'];
  51. $query->where('a.plate_name', 'like', "%" . $keyword . "%");
  52. }
  53. $totalCount = $query->count();
  54. $list = $query->skip($skip)
  55. ->limit($pageSize)
  56. ->selectRaw($fields)
  57. ->orderBy('sort')
  58. ->get();
  59. foreach ($list as &$l) {
  60. $l['plate_fields'] = json_decode($l['plate_fields'], true);
  61. }
  62. if (!empty($list)) {
  63. $list = $list->toArray();
  64. } else {
  65. $list = [];
  66. }
  67. $result = $this->buildPaginator($list, $skip, $page, $pageSize, $totalCount);
  68. return $result;
  69. }
  70. /**
  71. * 文章类型保存
  72. * @param array $data
  73. * */
  74. public function savePlateData($data)
  75. {
  76. if (!empty($data['id'])) {
  77. $id = $data['id'];
  78. $this->newInstance()->where('id', $data['id'])->update($data);
  79. } else {
  80. $id = $this->newInstance()->insertGetId($data);
  81. }
  82. return $id;
  83. }
  84. /**
  85. * 检查 名称是否唯一
  86. * */
  87. public function checkPlateNameUnique($name, $id = 0)
  88. {
  89. $where = [];
  90. if (!empty($id)) {
  91. $where[] = ['id', '<>', $id];
  92. }
  93. $where[] = ['status', '<', 2];
  94. $where[] = ['plate_name', '=', trim($name)];
  95. return $this->checkFieldUnique('plate_name', $where);
  96. }
  97. /**
  98. * 获取板块详情
  99. * @param array $params
  100. * */
  101. public function getBlogPlateInfo($params = [])
  102. {
  103. if (empty($params)) {
  104. return [];
  105. }
  106. $where = [];
  107. $where[] = ['status', '<', 2];
  108. if (!empty($params['id'])) {
  109. $where['id'] = $params['id'];
  110. }
  111. $info = $this->newInstance()->where($where)->first();
  112. if (!empty($info)) {
  113. return $info->toArray();
  114. } else {
  115. return [];
  116. }
  117. }
  118. }