SpecialSource.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\special;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. /**
  15. * Class SpecialSource 专题素材关联表
  16. */
  17. class SpecialSource extends ModelBasic
  18. {
  19. use ModelTrait;
  20. /**获取专题素材
  21. * @param bool $special_id
  22. * @return false|\PDOStatement|string|\think\Collection
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. */
  27. public static function getSpecialSource($special_id = false, $source_id = false, $limit = false, $page = false, $order = 0)
  28. {
  29. $where = array();
  30. $data = self::where($where);
  31. if ($special_id) {
  32. if (is_array($special_id)) {
  33. $data->whereIn('special_id', $special_id);
  34. } else {
  35. $where['special_id'] = $special_id;
  36. $data->where($where);
  37. }
  38. }
  39. if ($source_id) {
  40. if (!is_array($source_id)) {
  41. $where['source_id'] = $source_id;
  42. $data->where($where);
  43. } else {
  44. $data->whereIn('source_id', $source_id);
  45. }
  46. }
  47. if ($page) {
  48. $data->page((int)$page, !$limit ? 10 : (int)$limit);
  49. }
  50. if ($order) {
  51. $data->order('sort asc,id asc');
  52. } else {
  53. $data->order('sort desc,id desc');
  54. }
  55. return $data->select();
  56. }
  57. /**专栏里专题获取
  58. * @param int $special_id
  59. * @param bool $limit
  60. * @param bool $page
  61. * @param int $is_member
  62. * @param $type
  63. * @return false|\PDOStatement|string|\think\Collection
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. * @throws \think\exception\DbException
  67. */
  68. public static function get_special_source_list($special_id = 0, $is_member = 0, $type, $limit = false, $page = false, $order = 0)
  69. {
  70. $where = array();
  71. $data = self::alias('o');
  72. if ($special_id) {
  73. if (is_array($special_id)) {
  74. $data = $data->whereIn('o.special_id', $special_id);
  75. } else {
  76. $where['o.special_id'] = $special_id;
  77. $data = $data->where($where);
  78. }
  79. }
  80. if ($type == 5) {
  81. $data = $data->join('special s', 's.id=o.source_id')->where(['s.is_del' => 0, 's.status' => 1, 's.is_show' => 1]);
  82. if (!$is_member) {
  83. $data = $data->where('s.is_mer_visible', 0);
  84. }
  85. }
  86. if ($page) {
  87. $data->page((int)$page, !$limit ? 10 : (int)$limit);
  88. }
  89. if ($order) {
  90. $data->order('o.sort asc,o.id asc');
  91. } else {
  92. $data->order('o.sort desc,o.id desc');
  93. }
  94. return $data->select();
  95. }
  96. }