WechatNewsCategory.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/02
  5. */
  6. namespace app\admin\model\wechat;
  7. use crmeb\traits\ModelTrait;
  8. use crmeb\basic\BaseModel;
  9. use app\admin\model\article\Article as ArticleModel;
  10. /**
  11. * 图文消息 model
  12. * Class WechatNewsCategory
  13. * @package app\admin\model\wechat
  14. */
  15. class WechatNewsCategory extends BaseModel
  16. {
  17. /**
  18. * 数据表主键
  19. * @var string
  20. */
  21. protected $pk = 'id';
  22. /**
  23. * 模型名称
  24. * @var string
  25. */
  26. protected $name = 'wechat_news_category';
  27. use ModelTrait;
  28. /**
  29. * 获取配置分类
  30. * @param array $where
  31. * @return array
  32. */
  33. public static function getAll($where = array())
  34. {
  35. $model = new self;
  36. // if($where['status'] !== '') $model = $model->where('status',$where['status']);
  37. // if($where['access'] !== '') $model = $model->where('access',$where['access']);
  38. if ($where['cate_name'] !== '') $model = $model->where('cate_name', 'LIKE', "%$where[cate_name]%");
  39. $model = $model->where('status', 1);
  40. return self::page($model, function ($item) use ($where) {
  41. $new = ArticleModel::where('id', 'in', $item['new_id'])->where('status', 1)->where('hide', 0)->select();
  42. if ($new) $new = $new->toArray();
  43. $item['new'] = $new;
  44. });
  45. }
  46. /**
  47. * 获取一条图文
  48. * @param int $id
  49. * @return array|false|\PDOStatement|string|\think\Model
  50. */
  51. public static function getWechatNewsItem($id = 0, $new_id = 0)
  52. {
  53. if (!$id) return [];
  54. $list = self::where('id', $id)->where('status', 1)->field('cate_name as title,new_id')->find();
  55. if ($list) {
  56. $list = $list->toArray();
  57. $new = ArticleModel::where('id', $new_id)->where('status', 1)->where('hide', 0)->select();
  58. $new = $new->toArray();
  59. if ($new) {
  60. $temp = [];
  61. $temp[] = $new[0];
  62. $list['new'] = $temp;
  63. } else {
  64. $list['new'] = $new;
  65. }
  66. }
  67. return $list;
  68. }
  69. /**
  70. * 获取发送图文
  71. * @param array $where
  72. * @return array
  73. */
  74. public static function getSendAll($where = array())
  75. {
  76. $model = new self();
  77. if ($where['cate_name'] !== '') $model = $model->where('cate_name', 'LIKE', "%$where[cate_name]%");
  78. $new_ids = $model->where('status', 1)->column('new_id');
  79. $new_ids = array_values($new_ids);
  80. $new_ids = implode(',', $new_ids);
  81. $model = ArticleModel::where('status', 1)->where('hide', 0)->where('id', 'in', $new_ids)->field('id,title,image_input,add_time');
  82. return ArticleModel::page($model, function ($item) use ($where) {
  83. $new = self::where('status', 1)->whereFindInSet('new_id', $item['id'])->find();
  84. $item['cate_name'] = $new['cate_name'];
  85. $temp[0]['title'] = $item['title'];
  86. $temp[0]['image_input'] = $item['image_input'];
  87. $temp[0]['id'] = $item['id'];
  88. $temp[0]['add_time'] = $item['add_time'];
  89. $item['id'] = $new['id'];
  90. $item['new'] = $temp;
  91. });
  92. }
  93. }