作者 郭宇鹏
1 个管道 的构建 通过 耗费 1 秒

'1-4'

@@ -641,13 +641,13 @@ class Article extends BaseApi @@ -641,13 +641,13 @@ class Article extends BaseApi
641 //4.判断是自定义价格 641 //4.判断是自定义价格
642 if ($data['status'] == 1){ 642 if ($data['status'] == 1){
643 //4.1 查询礼物 643 //4.1 查询礼物
644 - $article_gift = $this->get_data('price','价格不能为空'); 644 + $price = $this->get_data('price','价格不能为空');
645 //4.2 查询礼物订单 645 //4.2 查询礼物订单
646 $is_order = model('article_gift_order') 646 $is_order = model('article_gift_order')
647 ->where('article_id',$article['id']) 647 ->where('article_id',$article['id'])
648 ->where('is_custom',1) 648 ->where('is_custom',1)
649 ->where('status',0) 649 ->where('status',0)
650 - ->where('price',$article_gift['price']) 650 + ->where('price',$price)
651 ->find(); 651 ->find();
652 if (!$is_order){ 652 if (!$is_order){
653 $a_data = [ 653 $a_data = [
@@ -659,7 +659,7 @@ class Article extends BaseApi @@ -659,7 +659,7 @@ class Article extends BaseApi
659 'nickname'=>$this->auth->nickname, 659 'nickname'=>$this->auth->nickname,
660 'username'=>$this->auth->username, 660 'username'=>$this->auth->username,
661 'mobile'=>$this->auth->mobile, 661 'mobile'=>$this->auth->mobile,
662 - 'price'=>$article_gift['price'], 662 + 'price'=>$price,
663 'status'=>0, 663 'status'=>0,
664 'is_custom'=>0, 664 'is_custom'=>0,
665 ]; 665 ];
@@ -4,6 +4,10 @@ @@ -4,6 +4,10 @@
4 namespace app\api\controller; 4 namespace app\api\controller;
5 5
6 use dh2y\qrcode\QRcode; 6 use dh2y\qrcode\QRcode;
  7 +use think\Db;
  8 +use think\Exception;
  9 +use think\exception\PDOException;
  10 +use think\exception\ValidateException;
7 11
8 /** 12 /**
9 * 墨宝档案 13 * 墨宝档案
@@ -203,7 +207,17 @@ class Treasured extends BaseApi @@ -203,7 +207,17 @@ class Treasured extends BaseApi
203 if ($treasured && $data['page'] == 1){ 207 if ($treasured && $data['page'] == 1){
204 model('config')->where('name','mobao_num')->setInc('value'); 208 model('config')->where('name','mobao_num')->setInc('value');
205 } 209 }
206 - //4.返回数据 210 + //4.判断是不是点赞
  211 + if ($treasured){
  212 + foreach ($treasured as $key => $val){
  213 + $treasured[$key]['is_zan'] = 0;
  214 + $zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$val['id'])->find();
  215 + if ($zan){
  216 + $treasured[$key]['is_zan'] = 1;
  217 + }
  218 + }
  219 + }
  220 + //5.返回数据
207 $this->success('查询数据成功',$treasured); 221 $this->success('查询数据成功',$treasured);
208 } 222 }
209 223
@@ -255,6 +269,16 @@ class Treasured extends BaseApi @@ -255,6 +269,16 @@ class Treasured extends BaseApi
255 } 269 }
256 $treasured = $treasured->page($data['page'],$data['num']) 270 $treasured = $treasured->page($data['page'],$data['num'])
257 ->select(); 271 ->select();
  272 + //3.判断是不是点赞
  273 + if ($treasured){
  274 + foreach ($treasured as $key => $val){
  275 + $treasured[$key]['is_zan'] = 0;
  276 + $zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$val['id'])->find();
  277 + if ($zan){
  278 + $treasured[$key]['is_zan'] = 1;
  279 + }
  280 + }
  281 + }
258 //4.返回数据 282 //4.返回数据
259 $this->success('查询数据成功',$treasured); 283 $this->success('查询数据成功',$treasured);
260 } 284 }
@@ -268,14 +292,49 @@ class Treasured extends BaseApi @@ -268,14 +292,49 @@ class Treasured extends BaseApi
268 * @ApiReturnParams (name="code", type="integer", required=true, sample="0") 292 * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
269 * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功") 293 * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
270 * @ApiReturnParams (name="data", type="object", description="扩展数据返回") 294 * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
271 - * @ApiReturn () 295 + * @ApiReturn ({
  296 + "code": 1,
  297 + "msg": "查询数据成功",
  298 + "time": "1609742416",
  299 + "data": {
  300 + "id": 1,
  301 + "user_id": 2,
  302 + "avatar": "头像",
  303 + "nickname": "署名",
  304 + "title": "墨宝标题",
  305 + "number": "墨宝编号",
  306 + "author": "作者",
  307 + "images": "墨宝图片",
  308 + "content": "内容",
  309 + "production_typeface": "字体",
  310 + "production_typeface_id": "字体ID",
  311 + "production_format": "格式",
  312 + "production_format_id": "格式ID",
  313 + "treasured_size": "尺寸名称",
  314 + "treasured_size_id": "尺寸ID",
  315 + "status": "状态:0=待出售,1=已出售,2=非卖品",
  316 + "zan_num": "点赞数量",
  317 + "createtime": "2020-12-30 13:38:38",
  318 + "qr_code": "二维码",
  319 + "qr_code_d": "海报二维码",
  320 + "updatetime": "2020-12-30 13:38:38",
  321 + "deletetime": "删除时间",
  322 + "message": "删除提示",
  323 + "is_zan": "是否点赞 0=未点赞,1=已点赞"
  324 + }
  325 + })
272 */ 326 */
273 public function getTreasuredContent(){ 327 public function getTreasuredContent(){
274 //1.获取动态id 328 //1.获取动态id
275 $id = $this->get_data('id','墨宝档案ID不能为空'); 329 $id = $this->get_data('id','墨宝档案ID不能为空');
276 //2.查询数据 330 //2.查询数据
277 $treasured = model('treasured')->where('id',$id)->find(); 331 $treasured = model('treasured')->where('id',$id)->find();
278 - // 332 + //3.查询有没有点赞
  333 + $treasured['is_zan'] = 0;
  334 + $zan = model('treasured_zan')->where('user_id',$this->auth->id)->where('treasured_id',$id)->find();
  335 + if ($zan){
  336 + $treasured['is_zan'] = 1;
  337 + }
279 //4.返回数据 338 //4.返回数据
280 $this->success('查询数据成功',$treasured); 339 $this->success('查询数据成功',$treasured);
281 } 340 }
@@ -310,11 +369,14 @@ class Treasured extends BaseApi @@ -310,11 +369,14 @@ class Treasured extends BaseApi
310 ->find(); 369 ->find();
311 if ($treasured_zan){ 370 if ($treasured_zan){
312 $treasured_zan->delete(); 371 $treasured_zan->delete();
  372 + model('treasured')->where('id',$treasured_id)->setDec('zan_num');
313 $this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']); 373 $this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
314 } 374 }
315 - //3.增加点赞 375 + //4.增加点赞
316 model('treasured_zan')->create(['user_id'=>$this->auth->id,'treasured_id'=>$treasured_id]); 376 model('treasured_zan')->create(['user_id'=>$this->auth->id,'treasured_id'=>$treasured_id]);
317 - //4.返回结果 377 + //5.增加点赞数量
  378 + model('treasured')->where('id',$treasured_id)->setInc('zan_num');
  379 + //6.返回结果
318 $this->success('查询成功',['code'=>1,'msg'=>'点赞成功']); 380 $this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
319 } 381 }
320 382
@@ -7636,7 +7636,37 @@ @@ -7636,7 +7636,37 @@
7636 <div class="tab-pane" id="sample49"> 7636 <div class="tab-pane" id="sample49">
7637 <div class="row"> 7637 <div class="row">
7638 <div class="col-md-12"> 7638 <div class="col-md-12">
7639 - <pre id="sample_response49"></pre> 7639 + <pre id="sample_response49">{
  7640 + "code": 1,
  7641 + "msg": "查询数据成功",
  7642 + "time": "1609742416",
  7643 + "data": {
  7644 + "id": 1,
  7645 + "user_id": 2,
  7646 + "avatar": "头像",
  7647 + "nickname": "署名",
  7648 + "title": "墨宝标题",
  7649 + "number": "墨宝编号",
  7650 + "author": "作者",
  7651 + "images": "墨宝图片",
  7652 + "content": "内容",
  7653 + "production_typeface": "字体",
  7654 + "production_typeface_id": "字体ID",
  7655 + "production_format": "格式",
  7656 + "production_format_id": "格式ID",
  7657 + "treasured_size": "尺寸名称",
  7658 + "treasured_size_id": "尺寸ID",
  7659 + "status": "状态:0=待出售,1=已出售,2=非卖品",
  7660 + "zan_num": "点赞数量",
  7661 + "createtime": "2020-12-30 13:38:38",
  7662 + "qr_code": "二维码",
  7663 + "qr_code_d": "海报二维码",
  7664 + "updatetime": "2020-12-30 13:38:38",
  7665 + "deletetime": "删除时间",
  7666 + "message": "删除提示",
  7667 + "is_zan": "是否点赞 0=未点赞,1=已点赞"
  7668 + }
  7669 + }</pre>
7640 </div> 7670 </div>
7641 </div> 7671 </div>
7642 </div><!-- #sample --> 7672 </div><!-- #sample -->
@@ -9475,7 +9505,7 @@ @@ -9475,7 +9505,7 @@
9475 9505
9476 <div class="row mt0 footer"> 9506 <div class="row mt0 footer">
9477 <div class="col-md-6" align="left"> 9507 <div class="col-md-6" align="left">
9478 - Generated on 2021-01-04 14:26:38 </div> 9508 + Generated on 2021-01-04 14:46:39 </div>
9479 <div class="col-md-6" align="right"> 9509 <div class="col-md-6" align="right">
9480 <a href="./" target="_blank">书法公众号</a> 9510 <a href="./" target="_blank">书法公众号</a>
9481 </div> 9511 </div>