123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- /**
- * 官网频道管理模块
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2020/2/11
- * Time: 下午3:38
- */
- namespace JinDouYun\Model\Manage;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Manage\DCategory;
- use JinDouYun\Model\Manage\MArticle;
- class MCategory
- {
- protected $objDCategory;
- public function __construct()
- {
- $this->objDCategory = new DCategory();
- }
- // 添加频道
- public function addCategory($params)
- {
- $dbResult = $this->objDCategory->insert($params);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($dbResult);
- }
- }
- // 修改频道启用/停用状态
- public function updateEnbaleStatus($params)
- {
- $dbResult = $this->objDCategory->update(['id'=>$params['id'],'enableStatus'=>$params['enableStatus']], $params['id']);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror);
- }else{
- return ResultWrapper::success($dbResult);
- }
- }
- //频道删除
- public function delCategory($id)
- {
- $dbResult = $this->objDCategory->delete(['id' => $id]);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- // 获取所有频道数据
- public function getAllCategory($type)
- {
- $dbResult = $this->objDCategory->select(['enableStatus'=>StatusCode::$standard, 'type' => $type], '*', 'sort desc');
- if($dbResult === false){
- return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::fail('数据空了', ErrorCode::$contentNotExists);
- }
- return ResultWrapper::success($dbResult);
- }
- //获取频道和文章标题
- public function getCategoryAndArticle($params)
- {
- $sql = 'select id,categoryName from category where enableStatus = '.StatusCode::$standard.' and `type` = '.StatusCode::$delete.' order by id asc limit '.$params['categoryLimit'];
- $categoryData = $this->objDCategory->query($sql);
- if($categoryData === false){
- return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror);
- }
- if(empty($categoryData)){
- return ResultWrapper::success($categoryData);
- }
- $categoryIds = [];
- foreach($categoryData as $value){
- $categoryIds[] = $value['id'];
- }
- unset($sql);
- $sql = 'select * from article where categoryId in ('.implode(',', $categoryIds).') and deleteStatus = '.StatusCode::$standard. ' order by createTime desc';
- $dbResult = $this->objDCategory->query($sql);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::success($categoryData);
- }
- $formatArticle = [];
- foreach($dbResult as $value){
- if(isset($formatArticle[$value['categoryId']])){
- $count = count($formatArticle[$value['categoryId']]);
- }else{
- $count = 0;
- }
- if($count < $params['articleLimit']){
- $formatArticle[$value['categoryId']][] = $value;
- }
- }
- $returnData = [];
- foreach($categoryData as $value){
- $article = [];
- if(isset($formatArticle[$value['id']])){
- $article = $formatArticle[$value['id']];
- }
- $returnData[] = [
- 'id' => $value['id'],
- 'categoryName' => $value['categoryName'],
- 'article' => $article,
- ];
- }
- return ResultWrapper::success($returnData);
- }
- // 获取指定频道信息
- public function getCategoryInfo($params)
- {
- $dbResult = $this->objDCategory->get($params);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror);
- } else {
- return ResultWrapper::success($dbResult);
- }
- }
- // 修改频道信息
- public function editCategory($params)
- {
- if (empty($params['id'])) {
- return ResultWrapper::fail('没有指定要修改的频道id', ErrorCode::$paramError);
- }
- $dbResult = $this->objDCategory->update($params, $params['id']);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDCategory->error(), ErrorCode::$dberror);
- } else {
- return ResultWrapper::success($dbResult);
- }
- }
- }
|