Headline.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hp
  5. * Date: 2017/11/21
  6. * Time: 8:59
  7. */
  8. namespace App\Modules\Promotion\Models;
  9. use Illuminate\Database\Eloquent\Model;
  10. /**
  11. * Class Headline 标题
  12. * @package App\Modules\Promotion\Models
  13. */
  14. class Headline extends Model
  15. {
  16. protected $table = 'headlines';
  17. protected $fillable = [
  18. 'id',
  19. 'title',
  20. 'category',
  21. 'serial_number',
  22. 'remark',
  23. 'type',
  24. 'quality',
  25. 'created_at',
  26. 'updated_at'
  27. ];
  28. /**
  29. * category:类型 (1: 男频,2:女频)
  30. * @return mixed 获取类型下的所有的标题
  31. */
  32. static function getAllHeadlines($category)
  33. {
  34. if (1 == $category) {
  35. $category = '男频';
  36. } else {
  37. $category = '女频';
  38. }
  39. return $result = self::select('id', 'title')->where('type', 1)->where('category', $category)->get();
  40. }
  41. /**
  42. * @return mixed 获取所有的标题
  43. */
  44. static function getHeadlines()
  45. {
  46. return $result = self::select('id', 'title')->where('type', 2)->get();
  47. }
  48. /**
  49. * category:类型 (1: 男频,2:女频)
  50. * count: 获取的条数(默认为1条)
  51. * @return mixed 随机获取标题库中的若干条标题
  52. */
  53. static function getRandomHeadline($category, $count = 1)
  54. {
  55. if (1 == $category) {
  56. $category = '男频';
  57. } else {
  58. $category = '女频';
  59. }
  60. return $result = self::select('id', 'title')->where('category', $category)->where('type', 2)->where('remark', 2)->inRandomOrder()->take($count)->get();
  61. }
  62. static function getFullHeadline()
  63. {
  64. return $result = self::select('id', 'title')->where('type', 2)->where('remark', 2)->get();
  65. }
  66. /**
  67. * 添加标题
  68. */
  69. static function addHeadline($data)
  70. {
  71. return self::create($data);
  72. }
  73. /**
  74. * 添加标题
  75. */
  76. static function delHeadlines($ids)
  77. {
  78. return self::whereIn('id', $ids)->delete();
  79. }
  80. /**
  81. * 获取标题库中的serial_number 的最大值
  82. * @return mixed
  83. */
  84. static function getMaxSerialNumber()
  85. {
  86. return self::max('serial_number');
  87. }
  88. static function getHeadlineByParams($param)
  89. {
  90. $search_object = self::orderBy('id', 'desc');
  91. if (isset($param['id']) && $param['id']) {
  92. $search_object->where('id', $param['id']);
  93. }
  94. if (isset($param['remark']) && $param['remark']) {
  95. $search_object->where('remark', $param['remark']);
  96. }
  97. if (isset($param['title']) && $param['title']) {
  98. $search_object->where('title', 'like', '%' . $param['title'] . '%');
  99. }
  100. if (isset($param['category']) && $param['category']) {
  101. //category:类型 (1: 男频,2:女频)
  102. $category = $param['category'];
  103. if (1 == $category) {
  104. $category = '男频';
  105. } elseif (2 == $category) {
  106. $category = '女频';
  107. }
  108. $search_object->where('category', $category);
  109. }
  110. if (isset($param['type']) && $param['type']) {
  111. $search_object->where('type', $param['type']);
  112. }
  113. if (isset($param['quality']) && $param['quality']) {
  114. $search_object->where('quality', $param['quality']);
  115. }
  116. return $search_object->paginate();
  117. }
  118. }