215 lines
7.8 KiB
PHP
215 lines
7.8 KiB
PHP
<?php
|
|
|
|
namespace addon\article\api\controller;
|
|
|
|
use addon\article\model\ArticleCategory;
|
|
use addon\article\model\ArticleFabulous;
|
|
use addon\article\model\ArticleHistory;
|
|
use addon\article\model\ArticleShareRecord;
|
|
use addon\article\model\ArticleShareRewardRecord;
|
|
use addon\businesscard\model\Record;
|
|
use addon\fenxiao\newModel\Fenxiao;
|
|
use app\api\controller\BaseApi;
|
|
use addon\article\model\Article;
|
|
use app\model\newModel\Config;
|
|
use app\model\newModel\member\Member;
|
|
use app\model\newModel\common\ShareRecord;
|
|
use app\model\newModel\common\CaChe;
|
|
|
|
class Index extends BaseApi{
|
|
/**
|
|
* Common: 分类列表
|
|
* Author: wu-hui
|
|
* Time: 2022/10/21 15:40
|
|
* @return false|string
|
|
* @throws \think\db\exception\DbException
|
|
*/
|
|
public function cateList(){
|
|
$list = (new ArticleCategory())->apiGetList();
|
|
|
|
return $this->response($list);
|
|
}
|
|
/**
|
|
* Common: 获取设置信息
|
|
* Author: wu-hui
|
|
* Time: 2022/10/21 16:03
|
|
* @return false|string
|
|
*/
|
|
public function setInfo(){
|
|
$info = (new Config())->getConfigInfo('ARTICLE_SETTING');
|
|
|
|
return $this->response($this->success($info));
|
|
}
|
|
/**
|
|
* Common: 获取文章列表
|
|
* Author: wu-hui
|
|
* Time: 2022/10/17 14:25
|
|
* @return false|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function articleList(){
|
|
// 缓存名称
|
|
$cacheTag = CaChe::tag($this->params);
|
|
$list = CaChe::get('article_list',$cacheTag);
|
|
if($list){
|
|
// 存在缓存时的处理
|
|
$list = json_decode($list,TRUE);
|
|
}else{
|
|
$list = (new Article())->getList();
|
|
// 记录缓存
|
|
CaChe::set('article_list',json_encode($list,JSON_UNESCAPED_UNICODE),$cacheTag);
|
|
}
|
|
|
|
return $this->response($list);
|
|
}
|
|
/**
|
|
* Common: 获取详细信息
|
|
* Author: wu-hui
|
|
* Time: 2022/10/17 14:35
|
|
* @return false|string
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function details(){
|
|
// 获取用户登录信息
|
|
$checkToken = $this->checkToken();
|
|
if ($checkToken[ 'code' ] < 0) return $this->response($checkToken);
|
|
// 参数获取
|
|
$id = input('article_id');
|
|
$sourceMember = input('source_member',0);
|
|
// 获取文章信息
|
|
$field = [
|
|
'article_id',
|
|
'article_title',
|
|
'article_content',
|
|
'article_abstract',
|
|
'cover_img',
|
|
'is_show_release_time',
|
|
'is_show_read_num',
|
|
'is_show_dianzan_num',
|
|
"(read_num + initial_read_num) as read_num",
|
|
"(dianzan_num + initial_dianzan_num) as dianzan_num",
|
|
'create_time'
|
|
];
|
|
$info = (new Article())->singleInfo($id,$field);
|
|
$info['data']['is_fabulous'] = (new ArticleFabulous())->isFabulous($id,$this->member_id);
|
|
// 获取用户信息
|
|
$info['member'] = (new Member())->getArticleMemberInfo($this->member_id);
|
|
// 文章浏览信息处理
|
|
(new ArticleHistory())->addInfo($this->member_id,$id);
|
|
// 记录用户浏览信息
|
|
if($this->member_id != $sourceMember) (new Record())->addInfo($this->member_id,$sourceMember);
|
|
|
|
|
|
if(empty($info['data'])) return $this->response($this->error('', '文章不存在'));
|
|
return $this->response($info);
|
|
}
|
|
/**
|
|
* Common: 点赞 || 取消点赞
|
|
* Author: wu-hui
|
|
* Time: 2022/11/03 15:18
|
|
* @return false|string
|
|
*/
|
|
public function fabulous(){
|
|
// 获取用户登录信息
|
|
$checkToken = $this->checkToken();
|
|
if ($checkToken[ 'code' ] < 0) return $this->response($checkToken);
|
|
// 参数获取
|
|
$id = input('article_id');
|
|
$result = (new ArticleFabulous())->fabulousOperation($id,$this->member_id);
|
|
|
|
return $this->response($result);
|
|
}
|
|
/**
|
|
* Common: 获取用户分享、点赞、浏览记录
|
|
* Author: wu-hui
|
|
* Time: 2022/11/07 14:33
|
|
* @return false|string
|
|
*/
|
|
public function getRecordList(){
|
|
// 获取用户登录信息
|
|
$checkToken = $this->checkToken();
|
|
if ($checkToken[ 'code' ] < 0) return $this->response($checkToken);
|
|
// 参数获取
|
|
$recordType = input('record_type');// share=分享;fabulous=点赞;browse=浏览
|
|
switch($recordType){
|
|
case 'share':$list = (new ShareRecord())->articleRecord($this->member_id);break;
|
|
case 'fabulous':$list = (new ArticleFabulous())->record($this->member_id);break;
|
|
case 'browse':$list = (new ArticleHistory())->record($this->member_id);break;
|
|
default: $list = $this->error('','记录类型错误!');
|
|
}
|
|
|
|
return $this->response($list);
|
|
}
|
|
/**
|
|
* Common: 删除浏览记录、取消点赞
|
|
* Author: wu-hui
|
|
* Time: 2022/11/07 15:09
|
|
* @return false|string
|
|
*/
|
|
public function delRecordInfo(){
|
|
// 获取用户登录信息
|
|
$checkToken = $this->checkToken();
|
|
if ($checkToken[ 'code' ] < 0) return $this->response($checkToken);
|
|
// 参数获取
|
|
$recordType = input('record_type');// share=分享;fabulous=点赞;browse=浏览
|
|
$articleId = input('article_id');
|
|
switch($recordType){
|
|
case 'fabulous':$list = (new ArticleFabulous())->fabulousOperation($articleId,$this->member_id);break;
|
|
case 'browse':$list = (new ArticleHistory())->delRecord($articleId,$this->member_id);break;
|
|
default: $list = $this->error('','记录类型错误!');
|
|
}
|
|
|
|
return $this->response($list);
|
|
}
|
|
/**
|
|
* Common: 分享奖励发放
|
|
* Author: wu-hui
|
|
* Time: 2022/12/09 15:09
|
|
* @return false|string
|
|
*/
|
|
public function getShareReward(){
|
|
// 获取用户登录信息
|
|
$checkToken = $this->checkToken();
|
|
if ($checkToken[ 'code' ] < 0) return $this->response($checkToken);
|
|
// 参数获取
|
|
$ArticleShareRecordModel = new ArticleShareRecord();
|
|
$ArticleShareRewardRecordModel = new ArticleShareRewardRecord();
|
|
$articleId = input('article_id');
|
|
$shareId = input('share_id');
|
|
$sourceMember = input('source_member');
|
|
$set = (new Config())->getConfigInfo('ARTICLE_SETTING');
|
|
if((float)$set['integral'] > 0){
|
|
// 判断:用户是否通过今日分享信息进入
|
|
[$startTime,$endTime] = getTimeStamp('today');
|
|
$isHas = $ArticleShareRecordModel
|
|
->where('share_time','>=',$startTime)
|
|
->where('share_time','<',$endTime)
|
|
->where('share_id','=',$shareId)
|
|
->value('id');
|
|
// 判断:用户是否已经领取过当前用户的分享奖励
|
|
$isGet = (float)$ArticleShareRewardRecordModel->isReceive($articleId,$this->member_id,$sourceMember);
|
|
if($isHas > 0 && !$isGet){
|
|
// 正常领取奖励
|
|
$res = $ArticleShareRewardRecordModel->shareReward($articleId,$this->member_id,$sourceMember,(float)$set['integral']);
|
|
if($set['parent_integral'] > 0 && $res['code'] == 0){
|
|
// 上级领取奖励
|
|
$parentMemberId = (new Fenxiao())->getParentMemberId($sourceMember);
|
|
$res = $ArticleShareRewardRecordModel->shareReward($articleId,$this->member_id,$parentMemberId,(float)$set['parent_integral'],1);
|
|
}
|
|
|
|
return $this->response($res);
|
|
}
|
|
return $this->response($this->error('','不符合领取条件'));
|
|
}
|
|
|
|
return $this->response($this->error('','未开启文章分享奖励积分'));
|
|
}
|
|
|
|
|
|
|
|
|
|
} |