WechatNewsCategory.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\wechat;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use app\admin\model\article\Article as ArticleModel;
  15. /**
  16. * 图文消息 model
  17. * Class WechatNewsCategory
  18. * @package app\admin\model\wechat
  19. */
  20. class WechatNewsCategory extends ModelBasic {
  21. use ModelTrait;
  22. /**
  23. * 获取配置分类
  24. * @param array $where
  25. * @return array
  26. */
  27. public static function getAll($where = array()){
  28. $model = new self;
  29. if($where['cate_name'] !== '') $model = $model->where('cate_name','LIKE',"%$where[cate_name]%");
  30. $model = $model->where('status',1);
  31. return self::page($model,function ($item){
  32. $new = ArticleModel::where('id','in',$item['new_id'])->where('hide',1)->select();
  33. $item['new'] = $new;
  34. });
  35. }
  36. /**
  37. * 获取一条图文
  38. * @param int $id
  39. * @return array|false|\PDOStatement|string|\think\Model
  40. */
  41. public static function getWechatNewsItem($id = 0){
  42. if(!$id) return [];
  43. $list = self::where('id',$id)->where('status',1)->field('cate_name as title,new_id')->find();
  44. if($list){
  45. $list = $list->toArray();
  46. $new = ArticleModel::where('id','in',$list['new_id'])->where('hide',1)->select();
  47. if($new) $new = $new->toArray();
  48. $list['new'] = $new;
  49. }
  50. return $list;
  51. }
  52. }