作者 杨育虎
... ... @@ -36,7 +36,7 @@ function handleOrder($orderInfo) {
return true;
} elseif ($orderInfo['type'] == 2) { // 购买vip
$student = new \app\api\model\Student();
$studentInfo = $student->infoByUserId($orderInfo['other']['user_id']);
$studentInfo = $student->infoByUserIdCanShow($orderInfo['other']['user_id']);
if(!$student) {
return false;
}
... ...
... ... @@ -716,4 +716,44 @@ class Article extends Api
$articleTypeList = $articleType->listAll();
$this->success('获取所有文章类型成功', $articleTypeList);
}
/**
* 删除某个文章
* @ApiTitle (删除某个文章)
* @ApiSummary (删除某个文章)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
* @ApiParams (name="article_id", type="integer", required=true, description="文章ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
* @ApiReturn (删除某个文章)
*/
public function delArticle()
{
$userId = $this->auth->id;
$articleId = $this->request->param('article_id', 0, 'int');
if(!$articleId) {
$this->error('');
}
$articleModel = new ArticleModel();
$articleInfo = $articleModel->infoByIdNoWhere($articleId);
if(!$articleInfo) {
$this->error('');
}
if($articleInfo['user_id'] != $userId) {
$this->error('');
}
$res = $articleModel->delOne($articleId, ['deletetime' => time()]);
if(!$res) {
$this->error('删除某个文章失败');
}
$this->success('删除某个文章成功');
}
}
\ No newline at end of file
... ...
... ... @@ -5,6 +5,8 @@ namespace app\api\controller;
use app\common\controller\Api;
use app\api\model\Mes as MesModel;
use app\api\model\Student;
use think\Log;
/**
* 消息相关
*/
... ... @@ -172,6 +174,7 @@ class Mes extends Api
$userId = $this->auth->id;
$useraId = $this->request->param('usera_id', 0, 'int');
if(!$useraId) {
$this->error('您的操作有误');
}
... ... @@ -187,7 +190,11 @@ class Mes extends Api
$updateData = [
'readtime' => time()
];
$mes->updateByWhere($where, $updateData);
$res = $mes->updateByWhere($where, $updateData);
if(!$res) {
$this->error('已读失败');
}
$this->success('已读成功');
}
... ...
... ... @@ -4,6 +4,7 @@ namespace app\api\controller;
use app\api\model\Student;
use app\common\controller\Api;
use think\Log;
/**
* 注册相关
... ... @@ -39,7 +40,7 @@ class Register extends Api
$userId = $this->auth->id;
$student = new Student();
$studentInfo = $student->infoByUserId($userId);
$studentInfo = $student->infoByUserIdCanShow($userId);
if($studentInfo) {
$this->success('已经注册', $studentInfo);
}
... ... @@ -81,7 +82,7 @@ class Register extends Api
$userId = $this->auth->id;
$student = new Student();
$studentInfo = $student->infoByUserId($userId);
$studentInfo = $student->infoByUserIdCanShow($userId);
if($studentInfo) {
$this->success('已经注册', $studentInfo);
}
... ...
... ... @@ -622,7 +622,7 @@ class Student extends Api
$userId = $this->auth->id;
$student = new StudentModel();
$studentInfo = $student->infoByUserId($userId);
$studentInfo = $student->infoByUserIdCanShow($userId);
if(!$studentInfo) {
$this->error('还没有注册');
}
... ...
... ... @@ -12,6 +12,7 @@ use app\api\model\University as UniversityModel;
use app\api\model\UniversityLevel;
use app\api\model\Up;
use app\common\controller\Api;
use think\Log;
/**
* 大学相关
... ...
... ... @@ -15,13 +15,12 @@ class Article extends Model
protected $deleteTime = 'deletetime';
// 根据条件获取文章
public function listByWhere($where, $page, $size, $schoolId)
{
return $this
->alias('a')
->field('a.*, b.user_id, b.level, b.nickname, b.head_image, b.school_id, b.subject_ids, b.up_id, b.college_id, b.university_id, b.graduated_id, b.starttime, b.endtime, b.show_switch, b.email, b.vip_level, b.vip_endtime')
->join('student b', 'a.user_id = b.user_id')
->where(function ($query) use ($schoolId) {
$query
... ... @@ -34,33 +33,12 @@ class Article extends Model
->select();
}
// 根据用户ID获取文章
public function listByUserIdAndShowType($page, $size, $userId, $showType)
{
return $this
->where(['show_switch' => ['=', 1], 'show_type' => ['in', $showType], 'user_id' => ['=', $userId]])
->order('createtime', 'desc')
->useSoftDelete($this->deleteTime)
->page($page, $size)
->select();
}
// 根据用户ID获取文章
public function listByUserIdAndShowTypeAndTypeId($page, $size, $userId, $showType, $typeId)
{
return $this
->where(['show_switch' => ['=', 1], 'show_type' => ['in', $showType], 'user_id' => ['=', $userId], 'article_type_id' => ['=', $typeId]])
->order('createtime', 'desc')
->useSoftDelete($this->deleteTime)
->page($page, $size)
->select();
}
// 获取文章详细
public function infoById($id)
{
return $this
->alias('a')
->field('a.*, b.user_id, b.level, b.nickname, b.head_image, b.school_id, b.subject_ids, b.up_id, b.college_id, b.university_id, b.graduated_id, b.starttime, b.endtime, b.show_switch, b.email, b.vip_level, b.vip_endtime')
->join('student b', 'a.user_id = b.user_id')
->where(['a.id' => ['=', $id], 'a.show_switch' => ['=', 1]])
->useSoftDelete('a.'.$this->deleteTime)->find();
... ... @@ -77,4 +55,16 @@ class Article extends Model
{
return $this->where(['user_id' => ['=', $userId]])->page($page, $size)->order($this->createTime, 'desc')->select();
}
// 获取
public function infoByIdNoWhere($articleId)
{
return $this->where(['id' => ['=', $articleId]])->find();
}
// 删除某个文章
public function delOne($articleId, $data)
{
return $this->where(['id' => ['=', $articleId]])->update($data);
}
}
\ No newline at end of file
... ...
... ... @@ -37,6 +37,7 @@ class LikeArticle extends Model
{
return $this
->alias('a')
->field('a.article_id, a.user_id, b.user_id, b.level, b.nickname, b.head_image, b.school_id, b.subject_ids, b.up_id, b.college_id, b.university_id, b.graduated_id, b.starttime, b.endtime, b.show_switch, b.email, b.vip_level, b.vip_endtime, c.*')
->join('student b', 'a.user_id = b.user_id')
->join('article c', 'a.article_id = c.id')
->where(['a.user_id' => ['=', $userId]])
... ...
... ... @@ -20,6 +20,7 @@ class LikeUniversity extends Model
{
return $this
->alias('a')
->field('a.university_id, a.user_id, b.*')
->join('university b', 'a.university_id = b.id')
->where(['a.user_id' => ['=', $userId], 'b.show_switch' => ['=', 1], 'b.deletetime' => null])
->useSoftDelete('a.'.$this->deleteTime)
... ...
... ... @@ -43,6 +43,7 @@ class LookArticle extends Model
{
return $this
->alias('a')
->field('a.article_id, a.user_id, b.user_id, b.level, b.nickname, b.head_image, b.school_id, b.subject_ids, b.up_id, b.college_id, b.university_id, b.graduated_id, b.starttime, b.endtime, b.show_switch, b.email, b.vip_level, b.vip_endtime, c.*')
->join('student b', 'a.user_id = b.user_id')
->join('article c', 'a.article_id = c.id')
->where(['a.user_id' => ['=', $userId]])
... ...
... ... @@ -14,13 +14,6 @@ class Student extends Model
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 根据用户ID获取一个学生的数据
public function infoByUserId($userId)
{
return $this->where(['user_id' => ['=', $userId]])->useSoftDelete($this->deleteTime)->find();
}
// 添加一条学生的数据
public function addOne($data)
{
... ... @@ -62,7 +55,7 @@ class Student extends Model
// 修改一个学生的数据
public function updateOne($id, $data)
{
return $this->where(['id' => ['=', $id]])->update($data);
return $this->where(['user_id' => ['=', $id]])->update($data);
}
... ...
此 diff 太大无法显示。