WechatNewsCategory.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/02
  5. */
  6. namespace app\models\wechat;
  7. use crmeb\traits\ModelTrait;
  8. use crmeb\basic\BaseModel;
  9. use app\models\article\Article as ArticleModel;
  10. /**
  11. * 图文消息 model
  12. * Class WechatNewsCategory
  13. * @package app\models\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. $model = new self;
  35. // if($where['status'] !== '') $model = $model->where('status',$where['status']);
  36. // if($where['access'] !== '') $model = $model->where('access',$where['access']);
  37. if($where['cate_name'] !== '') $model = $model->where('cate_name','LIKE',"%$where[cate_name]%");
  38. $model = $model->where('status',1);
  39. $model = $model->order('add_time desc');
  40. $count = $model->count();
  41. $list=$model
  42. ->page((int)$where['page'],(int)$where['limit'])
  43. ->select()
  44. ->each(function ($item){
  45. $new = ArticleModel::where('id','in',$item['new_id'])->where('hide',0)->select();
  46. if($new) $new = $new->toArray();
  47. $item['new'] = $new;
  48. });
  49. return compact('count','list');
  50. }
  51. /**
  52. * 获取一条图文
  53. * @param int $id
  54. * @return array|false|\PDOStatement|string|\think\Model
  55. */
  56. public static function getWechatNewsItem($id = 0){
  57. if(!$id) return [];
  58. $list = self::where('id',$id)->where('status',1)->field('cate_name as title,new_id')->find();
  59. if($list){
  60. $list = $list->toArray();
  61. $new = ArticleModel::where('id','in',$list['new_id'])->where('hide',0)->select();
  62. if($new) $new = $new->toArray();
  63. $list['new'] = $new;
  64. }
  65. return $list;
  66. }
  67. /**
  68. * 发送客服消息选择文章列表
  69. * @param $where
  70. * @return array
  71. */
  72. public static function list($where){
  73. $list=self::where('cate_name','LIKE',"%$where[cate_name]%")
  74. ->where('status',1)
  75. ->page((int)$where['page'],(int)$where['limit'])
  76. ->select()
  77. ->each(function ($item){
  78. $item['new']=ArticleModel::where('id','in',$item['new_id'])->where('hide',0)->select();
  79. });
  80. return ['list'=>$list];
  81. }
  82. }