...
|
...
|
@@ -3,6 +3,10 @@ |
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use EasyWeChat\Factory;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
|
|
|
/**
|
|
|
* 作品相关
|
|
|
* @package app\api\controller
|
...
|
...
|
@@ -121,10 +125,10 @@ class Production extends BaseApi |
|
|
$this->success('增加作品成功',$production);
|
|
|
}
|
|
|
/**
|
|
|
* 增加作品列表
|
|
|
* @ApiTitle (获取首页动态)
|
|
|
* 获取作品列表
|
|
|
* @ApiTitle (获取作品列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/articleList)
|
|
|
* @ApiRoute (/api/production/ProductionList)
|
|
|
* @ApiParams (name="page", type="integer", required=true, description="分页次数")
|
|
|
* @ApiParams (name="num", type="integer", required=true, description="分页数量")
|
|
|
* @ApiParams (name="status", type="integer", required=true, description="1=最热,2=最新作品,3=书体筛选")
|
...
|
...
|
@@ -156,6 +160,7 @@ class Production extends BaseApi |
|
|
"ping_num": "点赞数量",
|
|
|
"price_num": "打赏总数",
|
|
|
"shoucang_num": "收藏数量",
|
|
|
"is_zan":"判断是否点赞 0=未点赞,1=已经点赞",
|
|
|
"createtime": "2020-12-29 11:46:43",
|
|
|
"updatetime": "2020-12-29 11:46:43",
|
|
|
"id": "2"
|
...
|
...
|
@@ -186,13 +191,14 @@ class Production extends BaseApi |
|
|
->order('createtime','desc')
|
|
|
->page($data['page'],$data['num'])
|
|
|
->select();
|
|
|
}else if ($data['status'] == 2){
|
|
|
$typeface_id = $this->get_data('typeface_id','字体ID不能为空');
|
|
|
}else if ($data['status'] == 3){
|
|
|
$typeface_id = $this->get_data('production_typeface_id','字体ID不能为空');
|
|
|
//最新作品
|
|
|
$Pro_list = model('production')
|
|
|
->where('deletetime',null)
|
|
|
->with(['user'])
|
|
|
->where('typeface_id',$typeface_id)
|
|
|
->order('createtime','desc')
|
|
|
->page($data['page'],$data['num'])
|
|
|
->select();
|
|
|
}
|
...
|
...
|
@@ -200,16 +206,618 @@ class Production extends BaseApi |
|
|
$user_id = $this->auth->id;
|
|
|
if (!empty($Pro_list)){
|
|
|
foreach ($Pro_list as $key => $val){
|
|
|
//1.查询关注和被关注
|
|
|
$attention = model('production_zan')->where('','')->where('','')->count();
|
|
|
if ($attention == 2){
|
|
|
$art_list[$key]['is_friend'] = 1;
|
|
|
}else{
|
|
|
$art_list[$key]['is_friend'] = 1;
|
|
|
//1.查询是否点赞
|
|
|
$attention = model('production_zan')->where('user_id',$user_id)->where('production_id',$val['id'])->find();
|
|
|
$attention?$Pro_list[$key]['is_zan'] = 1:$Pro_list[$key]['is_zan'] = 0;
|
|
|
}
|
|
|
}
|
|
|
$this->success('查询数据成功',$Pro_list);
|
|
|
}
|
|
|
/**
|
|
|
* 获取作品详情
|
|
|
* @ApiTitle (获取作品详情)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/ProductionContent)
|
|
|
* @ApiParams (name="production_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", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "增加作品成功",
|
|
|
"time": "1609213602",
|
|
|
"data": {
|
|
|
"title": "作品标题",
|
|
|
"content": "作品内容",
|
|
|
"images": "作品图片",
|
|
|
"typeface_id": "字体ID",
|
|
|
"dynasty_id": "朝代ID",
|
|
|
"format_id": "格式ID",
|
|
|
"width": "宽度",
|
|
|
"height": "高度",
|
|
|
"typeface": "字体",
|
|
|
"dynasty": "朝代",
|
|
|
"format": "格式",
|
|
|
"user_id": "用户ID",
|
|
|
"avatar": "头像",
|
|
|
"nickname": "署名",
|
|
|
"fenxiang_num": "分享数量",
|
|
|
"zan_num": "点赞数量",
|
|
|
"ping_num": "点赞数量",
|
|
|
"price_num": "打赏总数",
|
|
|
"shoucang_num": "收藏数量",
|
|
|
"is_zan":"判断是否点赞 0=未点赞,1=已经点赞",
|
|
|
"is_collect":"判断是否收藏 0=未收藏,1=已收藏",
|
|
|
"createtime": "2020-12-29 11:46:43",
|
|
|
"updatetime": "2020-12-29 11:46:43",
|
|
|
"id": "2"
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function ProductionContent(){
|
|
|
//1.获取数据
|
|
|
$data = $this->get_data_array([
|
|
|
['production_id','作品id不能为空'],
|
|
|
]);
|
|
|
//2.获取作品详情
|
|
|
$production = model('production')->where('id',$data['production_id'])->find();
|
|
|
if (!$production){
|
|
|
$this->error('您的作品不存在');
|
|
|
}
|
|
|
//3.查询是否点赞
|
|
|
$attention = model('production_zan')->where('user_id',$this->auth->id)->where('production_id',$production['id'])->find();
|
|
|
$attention?$production['is_zan'] = 1:$production['is_zan'] = 0;
|
|
|
//4.查询是否收藏
|
|
|
$production_collect = model('production_collect')->where('user_id',$this->auth->id)->where('production_id',$production['id'])->find();
|
|
|
$production_collect?$production['is_collect'] = 1:$production['is_collect'] = 0;
|
|
|
$this->success('查询数据成功',$production);
|
|
|
}
|
|
|
/**
|
|
|
* 作品点赞或取消点赞{注意}
|
|
|
* @ApiTitle (作品点赞或取消点赞{注意})
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/setProductionZan)
|
|
|
* @ApiParams (name="production_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", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "查询成功",
|
|
|
"time": "1608886856",
|
|
|
"data": {
|
|
|
"code": "0取消点赞 1=点赞成功",
|
|
|
"msg": "提示"
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function setProductionZan(){
|
|
|
//1.获取数据
|
|
|
$production_id = $this->get_data('production_id','作品id不能为空');
|
|
|
//2.查询作品数据
|
|
|
$production = model('production')->where('id',$production_id)->find();
|
|
|
//3.查询点赞
|
|
|
$production_zan = model('production_zan')
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('production_id',$production_id)
|
|
|
->find();
|
|
|
if ($production_zan){
|
|
|
$production_zan->delete();
|
|
|
$production->zan_num -= 1;
|
|
|
$production->save();
|
|
|
$this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
|
|
|
}
|
|
|
//4.增加点赞
|
|
|
model('production_zan')->create(['user_id'=>$this->auth->id,'production_id'=>$production_id]);
|
|
|
//5.增加点赞数量
|
|
|
$production->zan_num += 1;
|
|
|
$production->save();
|
|
|
//6.返回结果
|
|
|
$this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
|
|
|
}
|
|
|
/**
|
|
|
* 获取作品评论列表
|
|
|
* @ApiTitle (获取作品评论列表)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/getComment)
|
|
|
* @ApiParams (name="production_id", type="integer", required=true, description="作品id")
|
|
|
* @ApiParams (name="page", type="integer", required=true, description="分页次数")
|
|
|
* @ApiParams (name="num", type="integer", required=true, description="分页数量")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "查询成功",
|
|
|
"time": "1608890670",
|
|
|
"data": [
|
|
|
{
|
|
|
"id": 2,
|
|
|
"production_id": "作品id",
|
|
|
"user_id": "用户id",
|
|
|
"content": "评论内容",
|
|
|
"pid": "0一级评论 不是0是父级评论id",
|
|
|
"zan_num": "点赞数量",
|
|
|
"createtime": "2020-12-25 17:53:07",
|
|
|
"updatetime": "2020-12-25 17:53:07",
|
|
|
"deletetime": null,
|
|
|
"message": null,
|
|
|
"is_zan": "是否点赞 0未点赞 1点赞",
|
|
|
"son_num":"子评论数量",
|
|
|
"user": "用户信息参考首页列表注释",
|
|
|
"str_time": "发布时间"
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getComment(){
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
//1.获取作品id
|
|
|
$data = $this->get_data_array([
|
|
|
['production_id','作品id不能为空'],
|
|
|
['page','分页次数不能为空'],
|
|
|
['num','分页数量不能为空']
|
|
|
]);
|
|
|
//2.获取一级评论
|
|
|
$production_comment = model('production_comment')
|
|
|
->with(['user'])
|
|
|
->where('production_id',$data['production_id'])
|
|
|
->where('pid',0)
|
|
|
->order('createtime','desc')
|
|
|
->order('deletetime',null)
|
|
|
->page($data['page'],$data['num'])
|
|
|
->select();
|
|
|
//3.循环父级评论
|
|
|
foreach ($production_comment as $key => $val){
|
|
|
//3.1 判断用户有没有点赞
|
|
|
$is_zan = model('production_comment_zan')
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('production_comment_id',$val['id'])
|
|
|
->find();
|
|
|
$production_comment[$key]['is_zan'] = 1;
|
|
|
if (!$is_zan){
|
|
|
$production_comment[$key]['is_zan'] = 0;
|
|
|
}
|
|
|
//3.2 获取子评论数量
|
|
|
$production_comment[$key]['son_num'] = model('production_comment')
|
|
|
->where('pid',$val['id'])
|
|
|
->count();
|
|
|
}
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
$this->success('查询数据成功',$art_list);
|
|
|
//4.返回数据
|
|
|
$this->success('查询成功',$production_comment);
|
|
|
}
|
|
|
/**
|
|
|
* 发布评论
|
|
|
* @ApiTitle (发布评论)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/setComment)
|
|
|
* @ApiParams (name="production_id", type="integer", required=true, description="作品id")
|
|
|
* @ApiParams (name="content", type="integer", required=true, description="评论内容")
|
|
|
* @ApiParams (name="pid", 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", description="扩展数据返回")
|
|
|
* @ApiReturn ( )
|
|
|
*/
|
|
|
public function setComment(){
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
//1.获取作品id
|
|
|
$data= $this->get_data_array([
|
|
|
['production_id','作品id不能为空'],
|
|
|
['content','评论内容'],
|
|
|
]);
|
|
|
//2.发布评论
|
|
|
$pid = empty(input('param.pid'))?0:input('param.pid');
|
|
|
$data['pid'] = $pid;
|
|
|
$data['user_id'] = $this->auth->id;
|
|
|
$data['zan_num'] = 0;
|
|
|
$res = model('production_comment')->create($data);
|
|
|
Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
//3.发布成功
|
|
|
$this->success('发布评论成功',$res);
|
|
|
}
|
|
|
/**
|
|
|
* 根据父级评论获取子评论
|
|
|
* @ApiTitle (根据父级评论获取子评论)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/getTwoComment)
|
|
|
* @ApiParams (name="production_comment_id", type="integer", required=true, description="作品评论id")
|
|
|
* @ApiParams (name="page", type="integer", required=true, description="分页次数")
|
|
|
* @ApiParams (name="num", type="integer", required=true, description="分页数量")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "获取评论成功",
|
|
|
"time": "1608892708",
|
|
|
"data": [
|
|
|
{
|
|
|
"id": 2,
|
|
|
"production_id": "作品ID",
|
|
|
"user_id": "用户ID",
|
|
|
"content": "评论内容",
|
|
|
"pid": "父级id 注意:第一次返回的第一个数据是父级数据 第二次不会返回",
|
|
|
"zan_num": "点赞数量",
|
|
|
"createtime": "2020-12-25 17:53:07",
|
|
|
"updatetime": "2020-12-25 17:53:07",
|
|
|
"deletetime": null,
|
|
|
"message": null,
|
|
|
"is_zan": "是否点赞",
|
|
|
"is_this": "是不是自己发布的评论 1=是,0=不是",
|
|
|
"user": "用户信息 参考首页列表注释",
|
|
|
"str_time": "时间"
|
|
|
}
|
|
|
]
|
|
|
})
|
|
|
*/
|
|
|
public function getTwoComment(){
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
//1.获取作品id
|
|
|
$data= $this->get_data_array([
|
|
|
['production_comment_id','作品评论id不能为空'],
|
|
|
['page','分页次数不能为空'],
|
|
|
['num','分页数量不能为空']
|
|
|
]);
|
|
|
//2.发布评论
|
|
|
$father_production_comment = model('production_comment')
|
|
|
->with(['user'])
|
|
|
->where('id',$data['production_comment_id'])
|
|
|
->find();
|
|
|
if (!$father_production_comment){
|
|
|
$this->error('您的父级评论不存在');
|
|
|
}
|
|
|
//3.判断是不是第一次 如果是第一次添加进去父级评论
|
|
|
$array = [];
|
|
|
if ($data['page'] == 1){
|
|
|
$array[] = $father_production_comment;
|
|
|
}
|
|
|
//4.查询子级数据
|
|
|
$son_production_somment_array = model('production_comment')
|
|
|
->with(['user'])
|
|
|
->where('pid',$father_production_comment['id'])
|
|
|
->order('createtime','desc')
|
|
|
->page($data['page'],$data['num'])
|
|
|
->select();
|
|
|
foreach ($son_production_somment_array as $val){
|
|
|
$array[] = $val;
|
|
|
}
|
|
|
//5.循环查询是否点赞
|
|
|
foreach ($array as $key => $val){
|
|
|
//3.1 判断用户有没有点赞
|
|
|
$is_zan = model('production_comment_zan')
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('production_comment_id',$val['id'])
|
|
|
->find();
|
|
|
$array[$key]['is_zan'] = 1;
|
|
|
if (!$is_zan){
|
|
|
$array[$key]['is_zan'] = 0;
|
|
|
}
|
|
|
//3.2判断是不是自己发布的评论
|
|
|
$array[$key]['is_this'] = 0;
|
|
|
if ($val['user_id'] == $this->auth->id){
|
|
|
$array[$key]['is_this'] = 1;
|
|
|
}
|
|
|
}
|
|
|
Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
//3.发布成功
|
|
|
$this->success('获取评论成功',$array);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 作品评论点赞或取消点赞{注意}
|
|
|
* @ApiTitle (作品评论点赞或取消点赞{注意})
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/setProductionCommentZan)
|
|
|
* @ApiParams (name="production_comment_id", type="integer", required=true, description="作品内容")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "查询成功",
|
|
|
"time": "1608886856",
|
|
|
"data": {
|
|
|
"code": "0取消点赞 1=点赞成功",
|
|
|
"msg": "提示"
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function setProductionCommentZan(){
|
|
|
//1.获取数据
|
|
|
$production_comment_id = $this->get_data('production_comment_id','作品评论id不能为空');
|
|
|
//2.查询作品数据
|
|
|
$production_comment = model('production_comment')->where('id',$production_comment_id)->find();
|
|
|
//3.查询点赞
|
|
|
$production_comment_zan = model('production_comment_zan')
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('production_comment_id',$production_comment_id)
|
|
|
->find();
|
|
|
if ($production_comment_zan){
|
|
|
$production_comment_zan->delete();
|
|
|
$production_comment->zan_num -= 1;
|
|
|
$production_comment->save();
|
|
|
$this->success('查询成功',['code'=>0,'msg'=>'取消点赞成功']);
|
|
|
}
|
|
|
//4.增加点赞
|
|
|
model('production_comment_zan')->create(['user_id'=>$this->auth->id,'production_comment_id'=>$production_comment_id]);
|
|
|
//5.增加点赞数量
|
|
|
$production_comment->zan_num += 1;
|
|
|
$production_comment->save();
|
|
|
//6.返回结果
|
|
|
$this->success('查询成功',['code'=>1,'msg'=>'点赞成功']);
|
|
|
}
|
|
|
/**
|
|
|
* 举报作品
|
|
|
* @ApiTitle (举报作品)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/setProductionReport)
|
|
|
* @ApiParams (name="production_id", type="integer", required=true, description="作品id")
|
|
|
* @ApiParams (name="report_type_id", type="integer", required=true, description="举报类型ID")
|
|
|
* @ApiParams (name="content", type="integer", required=true, description="举报内容")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "举报成功",
|
|
|
"time": "1609236276",
|
|
|
"data": {
|
|
|
"production_id": "1",
|
|
|
"report_type_id": "1",
|
|
|
"content": "瓦达",
|
|
|
"user_id": 2,
|
|
|
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eo0mGhWdZVZMqyNCg4CWn7Xyplya5eEF1UUnFlOcF4vvZ9IibfWGocjiatViaP9b4JtosbuP9NibhlEWw/132",
|
|
|
"nickname": "珍惜自己的名字",
|
|
|
"username": "u2",
|
|
|
"mobile": "",
|
|
|
"status": 0,
|
|
|
"report_type_name": "违法违禁",
|
|
|
"createtime": "2020-12-29 18:04:36",
|
|
|
"updatetime": "2020-12-29 18:04:36",
|
|
|
"id": "2"
|
|
|
}
|
|
|
})
|
|
|
*/
|
|
|
public function setProductionReport(){
|
|
|
try {
|
|
|
//1.获取作品id
|
|
|
$data= $this->get_data_array([
|
|
|
['production_id','作品ID不能为空'],
|
|
|
['report_type_id','举报类型ID不能为空'],
|
|
|
['content','举报内容不能为空'],
|
|
|
]);
|
|
|
//2.查询举报内容
|
|
|
$production_report = model('production_report')
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('production_id',$data['production_id'])
|
|
|
->where('report_type_id',$data['report_type_id'])
|
|
|
->where('status',0)
|
|
|
->find();
|
|
|
if ($production_report){
|
|
|
$this->error('您已经举报该作品,请等待管理员审核!');
|
|
|
}
|
|
|
//3.查询举报类型
|
|
|
$data['user_id'] = $this->auth->id;
|
|
|
$data['avatar'] = $this->auth->avatar;
|
|
|
$data['nickname'] = $this->auth->nickname;
|
|
|
$data['username'] = $this->auth->username;
|
|
|
$data['mobile'] = $this->auth->mobile;
|
|
|
$data['status'] = 0;
|
|
|
$data['report_type_name'] = model('report_type')->where('id',$data['report_type_id'])->find()['name']??'';
|
|
|
$res = model('production_report')->create($data);
|
|
|
Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
//3.发布成功
|
|
|
$this->success('举报成功',$res);
|
|
|
}
|
|
|
/**
|
|
|
* 举报评论
|
|
|
* @ApiTitle (举报评论)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/setProductionCommentReport)
|
|
|
* @ApiParams (name="production_comment_id", type="integer", required=true, description="评论id")
|
|
|
* @ApiParams (name="report_type_id", type="integer", required=true, description="举报类型ID")
|
|
|
* @ApiParams (name="content", type="integer", required=true, description="举报内容")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ()
|
|
|
*/
|
|
|
public function setProductionCommentReport(){
|
|
|
try {
|
|
|
//1.获取作品id
|
|
|
$data= $this->get_data_array([
|
|
|
['production_comment_id','评论ID不能为空'],
|
|
|
['report_type_id','举报类型ID不能为空'],
|
|
|
['content','举报内容不能为空'],
|
|
|
]);
|
|
|
//2.查询举报内容
|
|
|
$production_report = model('production_comment_report')
|
|
|
->where('user_id',$this->auth->id)
|
|
|
->where('production_comment_id',$data['production_comment_id'])
|
|
|
->where('report_type_id',$data['report_type_id'])
|
|
|
->where('status',0)
|
|
|
->find();
|
|
|
if ($production_report){
|
|
|
$this->error('您已经举报该评论,请等待管理员审核!');
|
|
|
}
|
|
|
//3.查询举报类型
|
|
|
$data['user_id'] = $this->auth->id;
|
|
|
$data['avatar'] = $this->auth->avatar;
|
|
|
$data['nickname'] = $this->auth->nickname;
|
|
|
$data['username'] = $this->auth->username;
|
|
|
$data['mobile'] = $this->auth->mobile;
|
|
|
$data['status'] = 0;
|
|
|
$data['report_type_name'] = model('report_type')->where('id',$data['report_type_id'])->find()['name']??'';
|
|
|
$res = model('production_comment_report')->create($data);
|
|
|
Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
//3.发布成功
|
|
|
$this->success('举报成功',$res);
|
|
|
}
|
|
|
/**
|
|
|
* 送给作品礼物
|
|
|
* @ApiTitle (送给作品礼物)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/giveGift)
|
|
|
* @ApiParams (name="production_id", type="integer", required=true, description="作品id")
|
|
|
* @ApiParams (name="gift_id", type="integer", required=true, description="礼物id")
|
|
|
* @ApiParams (name="price", type="integer", required=true, description="价格")
|
|
|
* @ApiParams (name="status", type="integer", required=true, description="是否是自定义价格:0=不是{需要填写gift_id},1=是{需要填写金额}")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", description="扩展数据返回")
|
|
|
* @ApiReturn ({
|
|
|
"code": 1,
|
|
|
"msg": "获取数据成功",
|
|
|
"time": "1608963789",
|
|
|
"data": ""
|
|
|
*/
|
|
|
public function giveGift(){
|
|
|
//1.获取数据
|
|
|
$data = $this->get_data_array([
|
|
|
['production_id','您的作品ID不能为空'],
|
|
|
['status','您的自定义价格字段不能为空']
|
|
|
]);
|
|
|
//2.查询作品
|
|
|
$production = model('production')->where('id',$data['production_id'])->find();
|
|
|
if (!$production)$this->error('您的作品不存在,请您检查production_id');
|
|
|
//3.判断不是自定义价格
|
|
|
if ($data['status'] == 0){
|
|
|
//3.1 查询礼物
|
|
|
$production_gift = model('gift')->where('id',$this->get_data('gift_id','礼物id不能为空'))->find();
|
|
|
if (!$production_gift)$this->error('未查询到相关礼物,请您检查gift_id');
|
|
|
//3.2 查询礼物订单
|
|
|
$is_order = model('production_gift_order')
|
|
|
->where('production_id',$production['id'])
|
|
|
->where('gift_id',$production_gift['id'])
|
|
|
->where('is_custom',0)
|
|
|
->where('status',0)
|
|
|
->where('price',$production_gift['price'])
|
|
|
->find();
|
|
|
if (!$is_order){
|
|
|
$a_data = [
|
|
|
'number'=>time()+rand(111111,999999),
|
|
|
'production_id'=>$production['id'],
|
|
|
'production_user_id'=>$production['user_id'],
|
|
|
'user_id'=>$this->auth->id,
|
|
|
'avatar'=>$this->auth->avatar,
|
|
|
'nickname'=>$this->auth->nickname,
|
|
|
'username'=>$this->auth->username,
|
|
|
'mobile'=>$this->auth->mobile,
|
|
|
'price'=>$production_gift['price'],
|
|
|
'status'=>0,
|
|
|
'is_custom'=>0,
|
|
|
'gift_id'=>$production_gift['id'],
|
|
|
'gift_name'=>$production_gift['name'],
|
|
|
];
|
|
|
$is_order = model('production_gift_order')->create($a_data);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//4.判断是自定义价格
|
|
|
if ($data['status'] == 1){
|
|
|
//4.1 查询礼物
|
|
|
$production_gift = $this->get_data('price','价格不能为空');
|
|
|
//4.2 查询礼物订单
|
|
|
$is_order = model('production_gift_order')
|
|
|
->where('production_id',$production['id'])
|
|
|
->where('is_custom',1)
|
|
|
->where('status',0)
|
|
|
->where('price',$production_gift['price'])
|
|
|
->find();
|
|
|
if (!$is_order){
|
|
|
$a_data = [
|
|
|
'number'=>time()+rand(111111,999999),
|
|
|
'production_id'=>$production['id'],
|
|
|
'production_user_id'=>$production['user_id'],
|
|
|
'user_id'=>$this->auth->id,
|
|
|
'avatar'=>$this->auth->avatar,
|
|
|
'nickname'=>$this->auth->nickname,
|
|
|
'username'=>$this->auth->username,
|
|
|
'mobile'=>$this->auth->mobile,
|
|
|
'price'=>$production_gift['price'],
|
|
|
'status'=>0,
|
|
|
'is_custom'=>0,
|
|
|
];
|
|
|
$is_order = model('production_gift_order')->create($a_data);
|
|
|
}
|
|
|
}
|
|
|
//------------ 支付 -------------
|
|
|
//5.获取配置信息
|
|
|
$config = config('EasyWeChat');
|
|
|
$app = Factory::payment($config);
|
|
|
//6.查询用户的第三方登录信息
|
|
|
$fa_third = Db::name('third')->where('user_id',$this->auth->id)->find();
|
|
|
if (!$fa_third)$this->error('第三方授权数据不存在');
|
|
|
//3.统一下单接口
|
|
|
$result = $app->order->unify([
|
|
|
'body' => '送出礼物',
|
|
|
'out_trade_no' => $is_order['number'],
|
|
|
//'total_fee' => $order['price'] * 100,
|
|
|
'total_fee' => 1,
|
|
|
'notify_url' =>this_url().'/api/production/setWechatGiftNotify', // 支付结果通知网址,如果不设置则会使用配置里的默认地址
|
|
|
'trade_type' => 'JSAPI', // 请对应换成你的支付方式对应的值类型
|
|
|
'openid' => $fa_third['openid'],
|
|
|
]);
|
|
|
//4.判断返回结果
|
|
|
if ($result['result_code'] == 'SUCCESS' && $result['return_code'] == 'SUCCESS') {
|
|
|
$prepayId = $result['prepay_id'];
|
|
|
$jssdk = $app->jssdk;
|
|
|
$config = $jssdk->sdkConfig($prepayId);
|
|
|
$this->success('获取支付成功',$config);
|
|
|
} else {
|
|
|
$this->error('失败',$result);
|
|
|
}
|
|
|
$list = model('production_gift')->order('weigh','desc')->limit(7)->select();
|
|
|
//2.返回数据
|
|
|
$this->success('获取数据成功',$list);
|
|
|
}
|
|
|
/**
|
|
|
* 支付礼物回调
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/production/setWechatGiftNotify)
|
|
|
* @ApiReturn ()
|
|
|
*/
|
|
|
public function setWechatNotify(){
|
|
|
$config = config('EasyWeChat');
|
|
|
$app = Factory::payment($config);
|
|
|
$response = $app->handlePaidNotify(function ($message, $fail) {
|
|
|
//将礼物进行支付
|
|
|
$order = model('production_gift_order')->where('number',$message['out_trade_no'])->find();
|
|
|
if (!$order)$fail('订单不存在');
|
|
|
if ($order['status'] == 1)$fail('您的订单已经支付');
|
|
|
$order->status = 1;
|
|
|
$order->save();
|
|
|
//给礼物用户一个通知
|
|
|
//
|
|
|
});
|
|
|
$response->send(); // Laravel 里请使用:return $response;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|