作者 杨育虎
@@ -36,7 +36,7 @@ function handleOrder($orderInfo) { @@ -36,7 +36,7 @@ function handleOrder($orderInfo) {
36 return true; 36 return true;
37 } elseif ($orderInfo['type'] == 2) { // 购买vip 37 } elseif ($orderInfo['type'] == 2) { // 购买vip
38 $student = new \app\api\model\Student(); 38 $student = new \app\api\model\Student();
39 - $studentInfo = $student->infoByUserId($orderInfo['other']['user_id']); 39 + $studentInfo = $student->infoByUserIdCanShow($orderInfo['other']['user_id']);
40 if(!$student) { 40 if(!$student) {
41 return false; 41 return false;
42 } 42 }
@@ -716,4 +716,44 @@ class Article extends Api @@ -716,4 +716,44 @@ class Article extends Api
716 $articleTypeList = $articleType->listAll(); 716 $articleTypeList = $articleType->listAll();
717 $this->success('获取所有文章类型成功', $articleTypeList); 717 $this->success('获取所有文章类型成功', $articleTypeList);
718 } 718 }
  719 +
  720 +
  721 +
  722 + /**
  723 + * 删除某个文章
  724 + * @ApiTitle (删除某个文章)
  725 + * @ApiSummary (删除某个文章)
  726 + * @ApiMethod (POST)
  727 + * @ApiHeaders (name="token", type="string", required=true, description="请求的Token")
  728 + * @ApiParams (name="article_id", type="integer", required=true, description="文章ID")
  729 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  730 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  731 + * @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
  732 + * @ApiReturn (删除某个文章)
  733 + */
  734 + public function delArticle()
  735 + {
  736 + $userId = $this->auth->id;
  737 + $articleId = $this->request->param('article_id', 0, 'int');
  738 + if(!$articleId) {
  739 + $this->error('');
  740 + }
  741 +
  742 + $articleModel = new ArticleModel();
  743 +
  744 + $articleInfo = $articleModel->infoByIdNoWhere($articleId);
  745 + if(!$articleInfo) {
  746 + $this->error('');
  747 + }
  748 +
  749 + if($articleInfo['user_id'] != $userId) {
  750 + $this->error('');
  751 + }
  752 +
  753 + $res = $articleModel->delOne($articleId, ['deletetime' => time()]);
  754 + if(!$res) {
  755 + $this->error('删除某个文章失败');
  756 + }
  757 + $this->success('删除某个文章成功');
  758 + }
719 } 759 }
@@ -5,6 +5,8 @@ namespace app\api\controller; @@ -5,6 +5,8 @@ namespace app\api\controller;
5 use app\common\controller\Api; 5 use app\common\controller\Api;
6 use app\api\model\Mes as MesModel; 6 use app\api\model\Mes as MesModel;
7 use app\api\model\Student; 7 use app\api\model\Student;
  8 +use think\Log;
  9 +
8 /** 10 /**
9 * 消息相关 11 * 消息相关
10 */ 12 */
@@ -172,6 +174,7 @@ class Mes extends Api @@ -172,6 +174,7 @@ class Mes extends Api
172 $userId = $this->auth->id; 174 $userId = $this->auth->id;
173 175
174 $useraId = $this->request->param('usera_id', 0, 'int'); 176 $useraId = $this->request->param('usera_id', 0, 'int');
  177 +
175 if(!$useraId) { 178 if(!$useraId) {
176 $this->error('您的操作有误'); 179 $this->error('您的操作有误');
177 } 180 }
@@ -187,7 +190,11 @@ class Mes extends Api @@ -187,7 +190,11 @@ class Mes extends Api
187 $updateData = [ 190 $updateData = [
188 'readtime' => time() 191 'readtime' => time()
189 ]; 192 ];
190 - $mes->updateByWhere($where, $updateData); 193 + $res = $mes->updateByWhere($where, $updateData);
  194 + if(!$res) {
  195 + $this->error('已读失败');
  196 + }
  197 + $this->success('已读成功');
191 } 198 }
192 199
193 200
@@ -4,6 +4,7 @@ namespace app\api\controller; @@ -4,6 +4,7 @@ namespace app\api\controller;
4 4
5 use app\api\model\Student; 5 use app\api\model\Student;
6 use app\common\controller\Api; 6 use app\common\controller\Api;
  7 +use think\Log;
7 8
8 /** 9 /**
9 * 注册相关 10 * 注册相关
@@ -39,7 +40,7 @@ class Register extends Api @@ -39,7 +40,7 @@ class Register extends Api
39 $userId = $this->auth->id; 40 $userId = $this->auth->id;
40 41
41 $student = new Student(); 42 $student = new Student();
42 - $studentInfo = $student->infoByUserId($userId); 43 + $studentInfo = $student->infoByUserIdCanShow($userId);
43 if($studentInfo) { 44 if($studentInfo) {
44 $this->success('已经注册', $studentInfo); 45 $this->success('已经注册', $studentInfo);
45 } 46 }
@@ -81,7 +82,7 @@ class Register extends Api @@ -81,7 +82,7 @@ class Register extends Api
81 $userId = $this->auth->id; 82 $userId = $this->auth->id;
82 83
83 $student = new Student(); 84 $student = new Student();
84 - $studentInfo = $student->infoByUserId($userId); 85 + $studentInfo = $student->infoByUserIdCanShow($userId);
85 if($studentInfo) { 86 if($studentInfo) {
86 $this->success('已经注册', $studentInfo); 87 $this->success('已经注册', $studentInfo);
87 } 88 }
@@ -622,7 +622,7 @@ class Student extends Api @@ -622,7 +622,7 @@ class Student extends Api
622 $userId = $this->auth->id; 622 $userId = $this->auth->id;
623 623
624 $student = new StudentModel(); 624 $student = new StudentModel();
625 - $studentInfo = $student->infoByUserId($userId); 625 + $studentInfo = $student->infoByUserIdCanShow($userId);
626 if(!$studentInfo) { 626 if(!$studentInfo) {
627 $this->error('还没有注册'); 627 $this->error('还没有注册');
628 } 628 }
@@ -12,6 +12,7 @@ use app\api\model\University as UniversityModel; @@ -12,6 +12,7 @@ use app\api\model\University as UniversityModel;
12 use app\api\model\UniversityLevel; 12 use app\api\model\UniversityLevel;
13 use app\api\model\Up; 13 use app\api\model\Up;
14 use app\common\controller\Api; 14 use app\common\controller\Api;
  15 +use think\Log;
15 16
16 /** 17 /**
17 * 大学相关 18 * 大学相关
@@ -15,13 +15,12 @@ class Article extends Model @@ -15,13 +15,12 @@ class Article extends Model
15 protected $deleteTime = 'deletetime'; 15 protected $deleteTime = 'deletetime';
16 16
17 17
18 -  
19 -  
20 // 根据条件获取文章 18 // 根据条件获取文章
21 public function listByWhere($where, $page, $size, $schoolId) 19 public function listByWhere($where, $page, $size, $schoolId)
22 { 20 {
23 return $this 21 return $this
24 ->alias('a') 22 ->alias('a')
  23 + ->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')
25 ->join('student b', 'a.user_id = b.user_id') 24 ->join('student b', 'a.user_id = b.user_id')
26 ->where(function ($query) use ($schoolId) { 25 ->where(function ($query) use ($schoolId) {
27 $query 26 $query
@@ -34,33 +33,12 @@ class Article extends Model @@ -34,33 +33,12 @@ class Article extends Model
34 ->select(); 33 ->select();
35 } 34 }
36 35
37 - // 根据用户ID获取文章  
38 - public function listByUserIdAndShowType($page, $size, $userId, $showType)  
39 - {  
40 - return $this  
41 - ->where(['show_switch' => ['=', 1], 'show_type' => ['in', $showType], 'user_id' => ['=', $userId]])  
42 - ->order('createtime', 'desc')  
43 - ->useSoftDelete($this->deleteTime)  
44 - ->page($page, $size)  
45 - ->select();  
46 - }  
47 -  
48 - // 根据用户ID获取文章  
49 - public function listByUserIdAndShowTypeAndTypeId($page, $size, $userId, $showType, $typeId)  
50 - {  
51 - return $this  
52 - ->where(['show_switch' => ['=', 1], 'show_type' => ['in', $showType], 'user_id' => ['=', $userId], 'article_type_id' => ['=', $typeId]])  
53 - ->order('createtime', 'desc')  
54 - ->useSoftDelete($this->deleteTime)  
55 - ->page($page, $size)  
56 - ->select();  
57 - }  
58 -  
59 // 获取文章详细 36 // 获取文章详细
60 public function infoById($id) 37 public function infoById($id)
61 { 38 {
62 return $this 39 return $this
63 ->alias('a') 40 ->alias('a')
  41 + ->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')
64 ->join('student b', 'a.user_id = b.user_id') 42 ->join('student b', 'a.user_id = b.user_id')
65 ->where(['a.id' => ['=', $id], 'a.show_switch' => ['=', 1]]) 43 ->where(['a.id' => ['=', $id], 'a.show_switch' => ['=', 1]])
66 ->useSoftDelete('a.'.$this->deleteTime)->find(); 44 ->useSoftDelete('a.'.$this->deleteTime)->find();
@@ -77,4 +55,16 @@ class Article extends Model @@ -77,4 +55,16 @@ class Article extends Model
77 { 55 {
78 return $this->where(['user_id' => ['=', $userId]])->page($page, $size)->order($this->createTime, 'desc')->select(); 56 return $this->where(['user_id' => ['=', $userId]])->page($page, $size)->order($this->createTime, 'desc')->select();
79 } 57 }
  58 +
  59 + // 获取
  60 + public function infoByIdNoWhere($articleId)
  61 + {
  62 + return $this->where(['id' => ['=', $articleId]])->find();
  63 + }
  64 +
  65 + // 删除某个文章
  66 + public function delOne($articleId, $data)
  67 + {
  68 + return $this->where(['id' => ['=', $articleId]])->update($data);
  69 + }
80 } 70 }
@@ -37,6 +37,7 @@ class LikeArticle extends Model @@ -37,6 +37,7 @@ class LikeArticle extends Model
37 { 37 {
38 return $this 38 return $this
39 ->alias('a') 39 ->alias('a')
  40 + ->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.*')
40 ->join('student b', 'a.user_id = b.user_id') 41 ->join('student b', 'a.user_id = b.user_id')
41 ->join('article c', 'a.article_id = c.id') 42 ->join('article c', 'a.article_id = c.id')
42 ->where(['a.user_id' => ['=', $userId]]) 43 ->where(['a.user_id' => ['=', $userId]])
@@ -20,6 +20,7 @@ class LikeUniversity extends Model @@ -20,6 +20,7 @@ class LikeUniversity extends Model
20 { 20 {
21 return $this 21 return $this
22 ->alias('a') 22 ->alias('a')
  23 + ->field('a.university_id, a.user_id, b.*')
23 ->join('university b', 'a.university_id = b.id') 24 ->join('university b', 'a.university_id = b.id')
24 ->where(['a.user_id' => ['=', $userId], 'b.show_switch' => ['=', 1], 'b.deletetime' => null]) 25 ->where(['a.user_id' => ['=', $userId], 'b.show_switch' => ['=', 1], 'b.deletetime' => null])
25 ->useSoftDelete('a.'.$this->deleteTime) 26 ->useSoftDelete('a.'.$this->deleteTime)
@@ -43,6 +43,7 @@ class LookArticle extends Model @@ -43,6 +43,7 @@ class LookArticle extends Model
43 { 43 {
44 return $this 44 return $this
45 ->alias('a') 45 ->alias('a')
  46 + ->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.*')
46 ->join('student b', 'a.user_id = b.user_id') 47 ->join('student b', 'a.user_id = b.user_id')
47 ->join('article c', 'a.article_id = c.id') 48 ->join('article c', 'a.article_id = c.id')
48 ->where(['a.user_id' => ['=', $userId]]) 49 ->where(['a.user_id' => ['=', $userId]])
@@ -14,13 +14,6 @@ class Student extends Model @@ -14,13 +14,6 @@ class Student extends Model
14 protected $updateTime = 'updatetime'; 14 protected $updateTime = 'updatetime';
15 protected $deleteTime = 'deletetime'; 15 protected $deleteTime = 'deletetime';
16 16
17 -  
18 - // 根据用户ID获取一个学生的数据  
19 - public function infoByUserId($userId)  
20 - {  
21 - return $this->where(['user_id' => ['=', $userId]])->useSoftDelete($this->deleteTime)->find();  
22 - }  
23 -  
24 // 添加一条学生的数据 17 // 添加一条学生的数据
25 public function addOne($data) 18 public function addOne($data)
26 { 19 {
@@ -62,7 +55,7 @@ class Student extends Model @@ -62,7 +55,7 @@ class Student extends Model
62 // 修改一个学生的数据 55 // 修改一个学生的数据
63 public function updateOne($id, $data) 56 public function updateOne($id, $data)
64 { 57 {
65 - return $this->where(['id' => ['=', $id]])->update($data); 58 + return $this->where(['user_id' => ['=', $id]])->update($data);
66 } 59 }
67 60
68 61
此 diff 太大无法显示。