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

'12-29'

@@ -610,7 +610,7 @@ class Article extends BaseApi @@ -610,7 +610,7 @@ class Article extends BaseApi
610 'status'=>0, 610 'status'=>0,
611 'is_custom'=>0, 611 'is_custom'=>0,
612 'gift_id'=>$article_gift['id'], 612 'gift_id'=>$article_gift['id'],
613 - 'article_gift_name'=>$article_gift['name'], 613 + 'gift_name'=>$article_gift['name'],
614 ]; 614 ];
615 $is_order = model('article_gift_order')->create($a_data); 615 $is_order = model('article_gift_order')->create($a_data);
616 } 616 }
@@ -3,6 +3,10 @@ @@ -3,6 +3,10 @@
3 3
4 namespace app\api\controller; 4 namespace app\api\controller;
5 5
  6 +use EasyWeChat\Factory;
  7 +use think\Db;
  8 +use think\Exception;
  9 +
6 /** 10 /**
7 * 作品相关 11 * 作品相关
8 * @package app\api\controller 12 * @package app\api\controller
@@ -121,10 +125,10 @@ class Production extends BaseApi @@ -121,10 +125,10 @@ class Production extends BaseApi
121 $this->success('增加作品成功',$production); 125 $this->success('增加作品成功',$production);
122 } 126 }
123 /** 127 /**
124 - * 增加作品列表  
125 - * @ApiTitle (获取首页动态) 128 + * 获取作品列表
  129 + * @ApiTitle (获取作品列表)
126 * @ApiMethod (POST) 130 * @ApiMethod (POST)
127 - * @ApiRoute (/api/production/articleList) 131 + * @ApiRoute (/api/production/ProductionList)
128 * @ApiParams (name="page", type="integer", required=true, description="分页次数") 132 * @ApiParams (name="page", type="integer", required=true, description="分页次数")
129 * @ApiParams (name="num", type="integer", required=true, description="分页数量") 133 * @ApiParams (name="num", type="integer", required=true, description="分页数量")
130 * @ApiParams (name="status", type="integer", required=true, description="1=最热,2=最新作品,3=书体筛选") 134 * @ApiParams (name="status", type="integer", required=true, description="1=最热,2=最新作品,3=书体筛选")
@@ -156,6 +160,7 @@ class Production extends BaseApi @@ -156,6 +160,7 @@ class Production extends BaseApi
156 "ping_num": "点赞数量", 160 "ping_num": "点赞数量",
157 "price_num": "打赏总数", 161 "price_num": "打赏总数",
158 "shoucang_num": "收藏数量", 162 "shoucang_num": "收藏数量",
  163 + "is_zan":"判断是否点赞 0=未点赞,1=已经点赞",
159 "createtime": "2020-12-29 11:46:43", 164 "createtime": "2020-12-29 11:46:43",
160 "updatetime": "2020-12-29 11:46:43", 165 "updatetime": "2020-12-29 11:46:43",
161 "id": "2" 166 "id": "2"
@@ -186,13 +191,14 @@ class Production extends BaseApi @@ -186,13 +191,14 @@ class Production extends BaseApi
186 ->order('createtime','desc') 191 ->order('createtime','desc')
187 ->page($data['page'],$data['num']) 192 ->page($data['page'],$data['num'])
188 ->select(); 193 ->select();
189 - }else if ($data['status'] == 2){  
190 - $typeface_id = $this->get_data('typeface_id','字体ID不能为空'); 194 + }else if ($data['status'] == 3){
  195 + $typeface_id = $this->get_data('production_typeface_id','字体ID不能为空');
191 //最新作品 196 //最新作品
192 $Pro_list = model('production') 197 $Pro_list = model('production')
193 ->where('deletetime',null) 198 ->where('deletetime',null)
194 ->with(['user']) 199 ->with(['user'])
195 ->where('typeface_id',$typeface_id) 200 ->where('typeface_id',$typeface_id)
  201 + ->order('createtime','desc')
196 ->page($data['page'],$data['num']) 202 ->page($data['page'],$data['num'])
197 ->select(); 203 ->select();
198 } 204 }
@@ -200,16 +206,618 @@ class Production extends BaseApi @@ -200,16 +206,618 @@ class Production extends BaseApi
200 $user_id = $this->auth->id; 206 $user_id = $this->auth->id;
201 if (!empty($Pro_list)){ 207 if (!empty($Pro_list)){
202 foreach ($Pro_list as $key => $val){ 208 foreach ($Pro_list as $key => $val){
203 - //1.查询关注和被关注  
204 - $attention = model('production_zan')->where('','')->where('','')->count();  
205 - if ($attention == 2){  
206 - $art_list[$key]['is_friend'] = 1;  
207 - }else{  
208 - $art_list[$key]['is_friend'] = 1; 209 + //1.查询是否点赞
  210 + $attention = model('production_zan')->where('user_id',$user_id)->where('production_id',$val['id'])->find();
  211 + $attention?$Pro_list[$key]['is_zan'] = 1:$Pro_list[$key]['is_zan'] = 0;
  212 + }
  213 + }
  214 + $this->success('查询数据成功',$Pro_list);
  215 + }
  216 + /**
  217 + * 获取作品详情
  218 + * @ApiTitle (获取作品详情)
  219 + * @ApiMethod (POST)
  220 + * @ApiRoute (/api/production/ProductionContent)
  221 + * @ApiParams (name="production_id", type="integer", required=true, description="作品id")
  222 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  223 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  224 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  225 + * @ApiReturn ({
  226 + "code": 1,
  227 + "msg": "增加作品成功",
  228 + "time": "1609213602",
  229 + "data": {
  230 + "title": "作品标题",
  231 + "content": "作品内容",
  232 + "images": "作品图片",
  233 + "typeface_id": "字体ID",
  234 + "dynasty_id": "朝代ID",
  235 + "format_id": "格式ID",
  236 + "width": "宽度",
  237 + "height": "高度",
  238 + "typeface": "字体",
  239 + "dynasty": "朝代",
  240 + "format": "格式",
  241 + "user_id": "用户ID",
  242 + "avatar": "头像",
  243 + "nickname": "署名",
  244 + "fenxiang_num": "分享数量",
  245 + "zan_num": "点赞数量",
  246 + "ping_num": "点赞数量",
  247 + "price_num": "打赏总数",
  248 + "shoucang_num": "收藏数量",
  249 + "is_zan":"判断是否点赞 0=未点赞,1=已经点赞",
  250 + "is_collect":"判断是否收藏 0=未收藏,1=已收藏",
  251 + "createtime": "2020-12-29 11:46:43",
  252 + "updatetime": "2020-12-29 11:46:43",
  253 + "id": "2"
  254 + }
  255 + })
  256 + */
  257 + public function ProductionContent(){
  258 + //1.获取数据
  259 + $data = $this->get_data_array([
  260 + ['production_id','作品id不能为空'],
  261 + ]);
  262 + //2.获取作品详情
  263 + $production = model('production')->where('id',$data['production_id'])->find();
  264 + if (!$production){
  265 + $this->error('您的作品不存在');
  266 + }
  267 + //3.查询是否点赞
  268 + $attention = model('production_zan')->where('user_id',$this->auth->id)->where('production_id',$production['id'])->find();
  269 + $attention?$production['is_zan'] = 1:$production['is_zan'] = 0;
  270 + //4.查询是否收藏
  271 + $production_collect = model('production_collect')->where('user_id',$this->auth->id)->where('production_id',$production['id'])->find();
  272 + $production_collect?$production['is_collect'] = 1:$production['is_collect'] = 0;
  273 + $this->success('查询数据成功',$production);
  274 + }
  275 + /**
  276 + * 作品点赞或取消点赞{注意}
  277 + * @ApiTitle (作品点赞或取消点赞{注意})
  278 + * @ApiMethod (POST)
  279 + * @ApiRoute (/api/production/setProductionZan)
  280 + * @ApiParams (name="production_id", type="integer", required=true, description="作品id")
  281 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  282 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  283 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  284 + * @ApiReturn ({
  285 + "code": 1,
  286 + "msg": "查询成功",
  287 + "time": "1608886856",
  288 + "data": {
  289 + "code": "0取消点赞 1=点赞成功",
  290 + "msg": "提示"
  291 + }
  292 + })
  293 + */
  294 + public function setProductionZan(){
  295 + //1.获取数据
  296 + $production_id = $this->get_data('production_id','作品id不能为空');
  297 + //2.查询作品数据
  298 + $production = model('production')->where('id',$production_id)->find();
  299 + //3.查询点赞
  300 + $production_zan = model('production_zan')
  301 + ->where('user_id',$this->auth->id)
  302 + ->where('production_id',$production_id)
  303 + ->find();
  304 + if ($production_zan){
  305 + $production_zan->delete();
  306 + $production->zan_num -= 1;
  307 + $production->save();
  308 + $this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
  309 + }
  310 + //4.增加点赞
  311 + model('production_zan')->create(['user_id'=>$this->auth->id,'production_id'=>$production_id]);
  312 + //5.增加点赞数量
  313 + $production->zan_num += 1;
  314 + $production->save();
  315 + //6.返回结果
  316 + $this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
  317 + }
  318 + /**
  319 + * 获取作品评论列表
  320 + * @ApiTitle (获取作品评论列表)
  321 + * @ApiMethod (POST)
  322 + * @ApiRoute (/api/production/getComment)
  323 + * @ApiParams (name="production_id", type="integer", required=true, description="作品id")
  324 + * @ApiParams (name="page", type="integer", required=true, description="分页次数")
  325 + * @ApiParams (name="num", type="integer", required=true, description="分页数量")
  326 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  327 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  328 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  329 + * @ApiReturn ({
  330 + "code": 1,
  331 + "msg": "查询成功",
  332 + "time": "1608890670",
  333 + "data": [
  334 + {
  335 + "id": 2,
  336 + "production_id": "作品id",
  337 + "user_id": "用户id",
  338 + "content": "评论内容",
  339 + "pid": "0一级评论 不是0是父级评论id",
  340 + "zan_num": "点赞数量",
  341 + "createtime": "2020-12-25 17:53:07",
  342 + "updatetime": "2020-12-25 17:53:07",
  343 + "deletetime": null,
  344 + "message": null,
  345 + "is_zan": "是否点赞 0未点赞 1点赞",
  346 + "son_num":"子评论数量",
  347 + "user": "用户信息参考首页列表注释",
  348 + "str_time": "发布时间"
  349 + }
  350 + ]
  351 + })
  352 + */
  353 + public function getComment(){
  354 + Db::startTrans();
  355 + try {
  356 + //1.获取作品id
  357 + $data = $this->get_data_array([
  358 + ['production_id','作品id不能为空'],
  359 + ['page','分页次数不能为空'],
  360 + ['num','分页数量不能为空']
  361 + ]);
  362 + //2.获取一级评论
  363 + $production_comment = model('production_comment')
  364 + ->with(['user'])
  365 + ->where('production_id',$data['production_id'])
  366 + ->where('pid',0)
  367 + ->order('createtime','desc')
  368 + ->order('deletetime',null)
  369 + ->page($data['page'],$data['num'])
  370 + ->select();
  371 + //3.循环父级评论
  372 + foreach ($production_comment as $key => $val){
  373 + //3.1 判断用户有没有点赞
  374 + $is_zan = model('production_comment_zan')
  375 + ->where('user_id',$this->auth->id)
  376 + ->where('production_comment_id',$val['id'])
  377 + ->find();
  378 + $production_comment[$key]['is_zan'] = 1;
  379 + if (!$is_zan){
  380 + $production_comment[$key]['is_zan'] = 0;
209 } 381 }
  382 + //3.2 获取子评论数量
  383 + $production_comment[$key]['son_num'] = model('production_comment')
  384 + ->where('pid',$val['id'])
  385 + ->count();
210 } 386 }
  387 + } catch (Exception $e) {
  388 + Db::rollback();
  389 + $this->error($e->getMessage());
211 } 390 }
212 - $this->success('查询数据成功',$art_list); 391 + //4.返回数据
  392 + $this->success('查询成功',$production_comment);
213 } 393 }
  394 + /**
  395 + * 发布评论
  396 + * @ApiTitle (发布评论)
  397 + * @ApiMethod (POST)
  398 + * @ApiRoute (/api/production/setComment)
  399 + * @ApiParams (name="production_id", type="integer", required=true, description="作品id")
  400 + * @ApiParams (name="content", type="integer", required=true, description="评论内容")
  401 + * @ApiParams (name="pid", type="integer", required=true, description="父级评论id")
  402 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  403 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  404 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  405 + * @ApiReturn ( )
  406 + */
  407 + public function setComment(){
  408 + Db::startTrans();
  409 + try {
  410 + //1.获取作品id
  411 + $data= $this->get_data_array([
  412 + ['production_id','作品id不能为空'],
  413 + ['content','评论内容'],
  414 + ]);
  415 + //2.发布评论
  416 + $pid = empty(input('param.pid'))?0:input('param.pid');
  417 + $data['pid'] = $pid;
  418 + $data['user_id'] = $this->auth->id;
  419 + $data['zan_num'] = 0;
  420 + $res = model('production_comment')->create($data);
  421 + Db::commit();
  422 + } catch (Exception $e) {
  423 + Db::rollback();
  424 + $this->error($e->getMessage());
  425 + }
  426 + //3.发布成功
  427 + $this->success('发布评论成功',$res);
  428 + }
  429 + /**
  430 + * 根据父级评论获取子评论
  431 + * @ApiTitle (根据父级评论获取子评论)
  432 + * @ApiMethod (POST)
  433 + * @ApiRoute (/api/production/getTwoComment)
  434 + * @ApiParams (name="production_comment_id", type="integer", required=true, description="作品评论id")
  435 + * @ApiParams (name="page", type="integer", required=true, description="分页次数")
  436 + * @ApiParams (name="num", type="integer", required=true, description="分页数量")
  437 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  438 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  439 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  440 + * @ApiReturn ({
  441 + "code": 1,
  442 + "msg": "获取评论成功",
  443 + "time": "1608892708",
  444 + "data": [
  445 + {
  446 + "id": 2,
  447 + "production_id": "作品ID",
  448 + "user_id": "用户ID",
  449 + "content": "评论内容",
  450 + "pid": "父级id 注意:第一次返回的第一个数据是父级数据 第二次不会返回",
  451 + "zan_num": "点赞数量",
  452 + "createtime": "2020-12-25 17:53:07",
  453 + "updatetime": "2020-12-25 17:53:07",
  454 + "deletetime": null,
  455 + "message": null,
  456 + "is_zan": "是否点赞",
  457 + "is_this": "是不是自己发布的评论 1=是,0=不是",
  458 + "user": "用户信息 参考首页列表注释",
  459 + "str_time": "时间"
  460 + }
  461 + ]
  462 + })
  463 + */
  464 + public function getTwoComment(){
  465 + Db::startTrans();
  466 + try {
  467 + //1.获取作品id
  468 + $data= $this->get_data_array([
  469 + ['production_comment_id','作品评论id不能为空'],
  470 + ['page','分页次数不能为空'],
  471 + ['num','分页数量不能为空']
  472 + ]);
  473 + //2.发布评论
  474 + $father_production_comment = model('production_comment')
  475 + ->with(['user'])
  476 + ->where('id',$data['production_comment_id'])
  477 + ->find();
  478 + if (!$father_production_comment){
  479 + $this->error('您的父级评论不存在');
  480 + }
  481 + //3.判断是不是第一次 如果是第一次添加进去父级评论
  482 + $array = [];
  483 + if ($data['page'] == 1){
  484 + $array[] = $father_production_comment;
  485 + }
  486 + //4.查询子级数据
  487 + $son_production_somment_array = model('production_comment')
  488 + ->with(['user'])
  489 + ->where('pid',$father_production_comment['id'])
  490 + ->order('createtime','desc')
  491 + ->page($data['page'],$data['num'])
  492 + ->select();
  493 + foreach ($son_production_somment_array as $val){
  494 + $array[] = $val;
  495 + }
  496 + //5.循环查询是否点赞
  497 + foreach ($array as $key => $val){
  498 + //3.1 判断用户有没有点赞
  499 + $is_zan = model('production_comment_zan')
  500 + ->where('user_id',$this->auth->id)
  501 + ->where('production_comment_id',$val['id'])
  502 + ->find();
  503 + $array[$key]['is_zan'] = 1;
  504 + if (!$is_zan){
  505 + $array[$key]['is_zan'] = 0;
  506 + }
  507 + //3.2判断是不是自己发布的评论
  508 + $array[$key]['is_this'] = 0;
  509 + if ($val['user_id'] == $this->auth->id){
  510 + $array[$key]['is_this'] = 1;
  511 + }
  512 + }
  513 + Db::commit();
  514 + } catch (Exception $e) {
  515 + Db::rollback();
  516 + $this->error($e->getMessage());
  517 + }
  518 + //3.发布成功
  519 + $this->success('获取评论成功',$array);
  520 + }
  521 +
  522 + /**
  523 + * 作品评论点赞或取消点赞{注意}
  524 + * @ApiTitle (作品评论点赞或取消点赞{注意})
  525 + * @ApiMethod (POST)
  526 + * @ApiRoute (/api/production/setProductionCommentZan)
  527 + * @ApiParams (name="production_comment_id", type="integer", required=true, description="作品内容")
  528 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  529 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  530 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  531 + * @ApiReturn ({
  532 + "code": 1,
  533 + "msg": "查询成功",
  534 + "time": "1608886856",
  535 + "data": {
  536 + "code": "0取消点赞 1=点赞成功",
  537 + "msg": "提示"
  538 + }
  539 + })
  540 + */
  541 + public function setProductionCommentZan(){
  542 + //1.获取数据
  543 + $production_comment_id = $this->get_data('production_comment_id','作品评论id不能为空');
  544 + //2.查询作品数据
  545 + $production_comment = model('production_comment')->where('id',$production_comment_id)->find();
  546 + //3.查询点赞
  547 + $production_comment_zan = model('production_comment_zan')
  548 + ->where('user_id',$this->auth->id)
  549 + ->where('production_comment_id',$production_comment_id)
  550 + ->find();
  551 + if ($production_comment_zan){
  552 + $production_comment_zan->delete();
  553 + $production_comment->zan_num -= 1;
  554 + $production_comment->save();
  555 + $this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
  556 + }
  557 + //4.增加点赞
  558 + model('production_comment_zan')->create(['user_id'=>$this->auth->id,'production_comment_id'=>$production_comment_id]);
  559 + //5.增加点赞数量
  560 + $production_comment->zan_num += 1;
  561 + $production_comment->save();
  562 + //6.返回结果
  563 + $this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
  564 + }
  565 + /**
  566 + * 举报作品
  567 + * @ApiTitle (举报作品)
  568 + * @ApiMethod (POST)
  569 + * @ApiRoute (/api/production/setProductionReport)
  570 + * @ApiParams (name="production_id", type="integer", required=true, description="作品id")
  571 + * @ApiParams (name="report_type_id", type="integer", required=true, description="举报类型ID")
  572 + * @ApiParams (name="content", type="integer", required=true, description="举报内容")
  573 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  574 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  575 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  576 + * @ApiReturn ({
  577 + "code": 1,
  578 + "msg": "举报成功",
  579 + "time": "1609236276",
  580 + "data": {
  581 + "production_id": "1",
  582 + "report_type_id": "1",
  583 + "content": "瓦达",
  584 + "user_id": 2,
  585 + "avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eo0mGhWdZVZMqyNCg4CWn7Xyplya5eEF1UUnFlOcF4vvZ9IibfWGocjiatViaP9b4JtosbuP9NibhlEWw/132",
  586 + "nickname": "珍惜自己的名字",
  587 + "username": "u2",
  588 + "mobile": "",
  589 + "status": 0,
  590 + "report_type_name": "违法违禁",
  591 + "createtime": "2020-12-29 18:04:36",
  592 + "updatetime": "2020-12-29 18:04:36",
  593 + "id": "2"
  594 + }
  595 + })
  596 + */
  597 + public function setProductionReport(){
  598 + try {
  599 + //1.获取作品id
  600 + $data= $this->get_data_array([
  601 + ['production_id','作品ID不能为空'],
  602 + ['report_type_id','举报类型ID不能为空'],
  603 + ['content','举报内容不能为空'],
  604 + ]);
  605 + //2.查询举报内容
  606 + $production_report = model('production_report')
  607 + ->where('user_id',$this->auth->id)
  608 + ->where('production_id',$data['production_id'])
  609 + ->where('report_type_id',$data['report_type_id'])
  610 + ->where('status',0)
  611 + ->find();
  612 + if ($production_report){
  613 + $this->error('您已经举报该作品,请等待管理员审核!');
  614 + }
  615 + //3.查询举报类型
  616 + $data['user_id'] = $this->auth->id;
  617 + $data['avatar'] = $this->auth->avatar;
  618 + $data['nickname'] = $this->auth->nickname;
  619 + $data['username'] = $this->auth->username;
  620 + $data['mobile'] = $this->auth->mobile;
  621 + $data['status'] = 0;
  622 + $data['report_type_name'] = model('report_type')->where('id',$data['report_type_id'])->find()['name']??'';
  623 + $res = model('production_report')->create($data);
  624 + Db::commit();
  625 + } catch (Exception $e) {
  626 + Db::rollback();
  627 + $this->error($e->getMessage());
  628 + }
  629 + //3.发布成功
  630 + $this->success('举报成功',$res);
  631 + }
  632 + /**
  633 + * 举报评论
  634 + * @ApiTitle (举报评论)
  635 + * @ApiMethod (POST)
  636 + * @ApiRoute (/api/production/setProductionCommentReport)
  637 + * @ApiParams (name="production_comment_id", type="integer", required=true, description="评论id")
  638 + * @ApiParams (name="report_type_id", type="integer", required=true, description="举报类型ID")
  639 + * @ApiParams (name="content", type="integer", required=true, description="举报内容")
  640 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  641 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  642 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  643 + * @ApiReturn ()
  644 + */
  645 + public function setProductionCommentReport(){
  646 + try {
  647 + //1.获取作品id
  648 + $data= $this->get_data_array([
  649 + ['production_comment_id','评论ID不能为空'],
  650 + ['report_type_id','举报类型ID不能为空'],
  651 + ['content','举报内容不能为空'],
  652 + ]);
  653 + //2.查询举报内容
  654 + $production_report = model('production_comment_report')
  655 + ->where('user_id',$this->auth->id)
  656 + ->where('production_comment_id',$data['production_comment_id'])
  657 + ->where('report_type_id',$data['report_type_id'])
  658 + ->where('status',0)
  659 + ->find();
  660 + if ($production_report){
  661 + $this->error('您已经举报该评论,请等待管理员审核!');
  662 + }
  663 + //3.查询举报类型
  664 + $data['user_id'] = $this->auth->id;
  665 + $data['avatar'] = $this->auth->avatar;
  666 + $data['nickname'] = $this->auth->nickname;
  667 + $data['username'] = $this->auth->username;
  668 + $data['mobile'] = $this->auth->mobile;
  669 + $data['status'] = 0;
  670 + $data['report_type_name'] = model('report_type')->where('id',$data['report_type_id'])->find()['name']??'';
  671 + $res = model('production_comment_report')->create($data);
  672 + Db::commit();
  673 + } catch (Exception $e) {
  674 + Db::rollback();
  675 + $this->error($e->getMessage());
  676 + }
  677 + //3.发布成功
  678 + $this->success('举报成功',$res);
  679 + }
  680 + /**
  681 + * 送给作品礼物
  682 + * @ApiTitle (送给作品礼物)
  683 + * @ApiMethod (POST)
  684 + * @ApiRoute (/api/production/giveGift)
  685 + * @ApiParams (name="production_id", type="integer", required=true, description="作品id")
  686 + * @ApiParams (name="gift_id", type="integer", required=true, description="礼物id")
  687 + * @ApiParams (name="price", type="integer", required=true, description="价格")
  688 + * @ApiParams (name="status", type="integer", required=true, description="是否是自定义价格:0=不是{需要填写gift_id},1=是{需要填写金额}")
  689 + * @ApiReturnParams (name="code", type="integer", required=true, sample="0")
  690 + * @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
  691 + * @ApiReturnParams (name="data", type="object", description="扩展数据返回")
  692 + * @ApiReturn ({
  693 + "code": 1,
  694 + "msg": "获取数据成功",
  695 + "time": "1608963789",
  696 + "data": ""
  697 + */
  698 + public function giveGift(){
  699 + //1.获取数据
  700 + $data = $this->get_data_array([
  701 + ['production_id','您的作品ID不能为空'],
  702 + ['status','您的自定义价格字段不能为空']
  703 + ]);
  704 + //2.查询作品
  705 + $production = model('production')->where('id',$data['production_id'])->find();
  706 + if (!$production)$this->error('您的作品不存在,请您检查production_id');
  707 + //3.判断不是自定义价格
  708 + if ($data['status'] == 0){
  709 + //3.1 查询礼物
  710 + $production_gift = model('gift')->where('id',$this->get_data('gift_id','礼物id不能为空'))->find();
  711 + if (!$production_gift)$this->error('未查询到相关礼物,请您检查gift_id');
  712 + //3.2 查询礼物订单
  713 + $is_order = model('production_gift_order')
  714 + ->where('production_id',$production['id'])
  715 + ->where('gift_id',$production_gift['id'])
  716 + ->where('is_custom',0)
  717 + ->where('status',0)
  718 + ->where('price',$production_gift['price'])
  719 + ->find();
  720 + if (!$is_order){
  721 + $a_data = [
  722 + 'number'=>time()+rand(111111,999999),
  723 + 'production_id'=>$production['id'],
  724 + 'production_user_id'=>$production['user_id'],
  725 + 'user_id'=>$this->auth->id,
  726 + 'avatar'=>$this->auth->avatar,
  727 + 'nickname'=>$this->auth->nickname,
  728 + 'username'=>$this->auth->username,
  729 + 'mobile'=>$this->auth->mobile,
  730 + 'price'=>$production_gift['price'],
  731 + 'status'=>0,
  732 + 'is_custom'=>0,
  733 + 'gift_id'=>$production_gift['id'],
  734 + 'gift_name'=>$production_gift['name'],
  735 + ];
  736 + $is_order = model('production_gift_order')->create($a_data);
  737 + }
  738 +
  739 + }
  740 + //4.判断是自定义价格
  741 + if ($data['status'] == 1){
  742 + //4.1 查询礼物
  743 + $production_gift = $this->get_data('price','价格不能为空');
  744 + //4.2 查询礼物订单
  745 + $is_order = model('production_gift_order')
  746 + ->where('production_id',$production['id'])
  747 + ->where('is_custom',1)
  748 + ->where('status',0)
  749 + ->where('price',$production_gift['price'])
  750 + ->find();
  751 + if (!$is_order){
  752 + $a_data = [
  753 + 'number'=>time()+rand(111111,999999),
  754 + 'production_id'=>$production['id'],
  755 + 'production_user_id'=>$production['user_id'],
  756 + 'user_id'=>$this->auth->id,
  757 + 'avatar'=>$this->auth->avatar,
  758 + 'nickname'=>$this->auth->nickname,
  759 + 'username'=>$this->auth->username,
  760 + 'mobile'=>$this->auth->mobile,
  761 + 'price'=>$production_gift['price'],
  762 + 'status'=>0,
  763 + 'is_custom'=>0,
  764 + ];
  765 + $is_order = model('production_gift_order')->create($a_data);
  766 + }
  767 + }
  768 + //------------ 支付 -------------
  769 + //5.获取配置信息
  770 + $config = config('EasyWeChat');
  771 + $app = Factory::payment($config);
  772 + //6.查询用户的第三方登录信息
  773 + $fa_third = Db::name('third')->where('user_id',$this->auth->id)->find();
  774 + if (!$fa_third)$this->error('第三方授权数据不存在');
  775 + //3.统一下单接口
  776 + $result = $app->order->unify([
  777 + 'body' => '送出礼物',
  778 + 'out_trade_no' => $is_order['number'],
  779 + //'total_fee' => $order['price'] * 100,
  780 + 'total_fee' => 1,
  781 + 'notify_url' =>this_url().'/api/production/setWechatGiftNotify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
  782 + 'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
  783 + 'openid' => $fa_third['openid'],
  784 + ]);
  785 + //4.判断返回结果
  786 + if ($result['result_code'] == 'SUCCESS' && $result['return_code'] == 'SUCCESS') {
  787 + $prepayId = $result['prepay_id'];
  788 + $jssdk = $app->jssdk;
  789 + $config = $jssdk->sdkConfig($prepayId);
  790 + $this->success('获取支付成功',$config);
  791 + } else {
  792 + $this->error('失败',$result);
  793 + }
  794 + $list = model('production_gift')->order('weigh','desc')->limit(7)->select();
  795 + //2.返回数据
  796 + $this->success('获取数据成功',$list);
  797 + }
  798 + /**
  799 + * 支付礼物回调
  800 + * @ApiMethod (POST)
  801 + * @ApiRoute (/api/production/setWechatGiftNotify)
  802 + * @ApiReturn ()
  803 + */
  804 + public function setWechatNotify(){
  805 + $config = config('EasyWeChat');
  806 + $app = Factory::payment($config);
  807 + $response = $app->handlePaidNotify(function ($message, $fail) {
  808 + //将礼物进行支付
  809 + $order = model('production_gift_order')->where('number',$message['out_trade_no'])->find();
  810 + if (!$order)$fail('订单不存在');
  811 + if ($order['status'] == 1)$fail('您的订单已经支付');
  812 + $order->status = 1;
  813 + $order->save();
  814 + //给礼物用户一个通知
  815 + //
  816 + });
  817 + $response->send(); // Laravel 里请使用:return $response;
  818 + }
  819 +
  820 +
  821 +
214 822
215 } 823 }
@@ -7,4 +7,11 @@ namespace app\common\model; @@ -7,4 +7,11 @@ namespace app\common\model;
7 class Production extends BaseModel 7 class Production extends BaseModel
8 { 8 {
9 9
  10 + /**
  11 + * 关联用户表
  12 + */
  13 + public function User(){
  14 + return $this->belongsTo('user','user_id','id')->field('id,avatar,nickname,username,authlist');
  15 + }
  16 +
10 } 17 }
  1 +<?php
  2 +
  3 +
  4 +namespace app\common\model;
  5 +
  6 +
  7 +class ProductionCollect extends BaseModel
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\common\model;
  5 +
  6 +
  7 +class ProductionComment extends BaseModel
  8 +{
  9 + // 追加属性
  10 + protected $append = [
  11 + 'str_time'
  12 + ];
  13 +
  14 + /**
  15 + * 时间格式修改
  16 + * @param $value
  17 + * @param $data
  18 + * @return false|string 最新格式时间
  19 + */
  20 + public function getStrTimeAttr($value,$data){
  21 + //获取今天凌晨0点时间
  22 + $jin = strtotime(date("Y-m-d"),time());
  23 + //如果小于10分钟
  24 + if ($data['createtime'] + 10*60 > time()){
  25 + return '刚刚';
  26 + }
  27 + //如果是今天的
  28 + if ($data['createtime'] > $jin){
  29 + return date('H:i',$data['createtime']);
  30 + }
  31 + //其他
  32 + return date('m-d H:i',$data['createtime']);
  33 + }
  34 +
  35 + /**
  36 + * 关联用户表
  37 + */
  38 + public function User(){
  39 + return $this->belongsTo('user','user_id','id')->field('id,avatar,nickname,username,authlist');
  40 + }
  41 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\common\model;
  5 +
  6 +
  7 +class ProductionCommentReport extends BaseModel
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\common\model;
  5 +
  6 +
  7 +use think\Model;
  8 +
  9 +class ProductionCommentZan extends Model
  10 +{
  11 +
  12 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\common\model;
  5 +
  6 +
  7 +class ProductionGiftOrder extends BaseModel
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace app\common\model;
  5 +
  6 +
  7 +class ProductionReport extends BaseModel
  8 +{
  9 +
  10 +}
此 diff 太大无法显示。