You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
7.8 KiB
181 lines
7.8 KiB
2 months ago
|
<?php
|
||
|
|
||
|
namespace app\api\controller;
|
||
|
|
||
|
use app\common\controller\Api;
|
||
|
use app\admin\model\play\place\Info as PlayinfoModel;
|
||
|
use app\admin\model\play\place\Log as PlaylogModel;
|
||
|
use think\Db;
|
||
|
use think\Exception;
|
||
|
use addons\miniprogram\library\WechatService;
|
||
|
class play extends Api{
|
||
|
|
||
|
protected $model = null;
|
||
|
|
||
|
protected $noNeedRight = '*';
|
||
|
protected $noNeedLogin = ['getlist','getplayinfolist','getgroupdetail','getplaydetail','getUserplaylist'];
|
||
|
|
||
|
|
||
|
|
||
|
public function _initialize(){
|
||
|
parent::_initialize();
|
||
|
$this->model = new \app\admin\model\play\place\Info;
|
||
|
}
|
||
|
//获取会玩列表页信息
|
||
|
public function getplayinfolist(){
|
||
|
$data = $this->request->post();
|
||
|
if($this->request->post()){
|
||
|
$uid = isset($data['token'])&&!empty($data['token'])?$this->auth->id:0;
|
||
|
$where = "";
|
||
|
$order = "";
|
||
|
$offset = $data['offset'];
|
||
|
$limit = $data['limit'];
|
||
|
$list = $this->model->getlist($where, $order, $offset, $limit,$uid);
|
||
|
return $this->success('获取成功',$list);
|
||
|
}
|
||
|
}
|
||
|
public function delpaly(){
|
||
|
$data = $this->request->post();
|
||
|
if($this->request->post()){
|
||
|
$uid = $this->auth->id;
|
||
|
$id = $data['id'];
|
||
|
//查询会玩动态
|
||
|
$playinfo = PlayinfoModel::get($id);
|
||
|
if($playinfo->uid!=$uid) return $this->error("操作频繁,请休息一下再试");
|
||
|
$playinfo->is_del = 1;
|
||
|
if(!$playinfo->save()&&$playinfo->is_del=0) return $this->error("操作频繁,请休息一下再试");
|
||
|
return $this->success("动态已删除");
|
||
|
}
|
||
|
}
|
||
|
//发布会玩动态
|
||
|
public function addPlayInfo(){
|
||
|
$data = $this->request->post();
|
||
|
if($this->request->post()){
|
||
|
$userinfo = $this->auth->getUserinfo();
|
||
|
$data['uid'] = $userinfo['id'];
|
||
|
$data['create'] = time();
|
||
|
if($data['content_img']) $data['content_img'] = htmlspecialchars_decode($data['content_img']);
|
||
|
//检测文字是否含有违禁词
|
||
|
$min_user = new \app\admin\model\miniprogram\User;
|
||
|
$min_user_info = $min_user->getbyUser_id($this->auth->id);
|
||
|
$openid = $min_user_info['openid'];
|
||
|
$check = WechatService::security(['openid'=>$openid,'content'=>$data['content']]);
|
||
|
$cd = $check['result'];
|
||
|
if($cd['label']!=100) return $this->error("内容含涉嫌违规,请修改后再发布");
|
||
|
unset($data['token']);
|
||
|
try{
|
||
|
if(!PlayinfoModel::insertGetId($data)) throw new Exception("请选择分类");
|
||
|
return $this->success('发布成功');
|
||
|
}catch (Exception $e) {
|
||
|
return $this->error($e->getMessage());
|
||
|
}
|
||
|
}
|
||
|
return $this->error('非法请求');
|
||
|
}
|
||
|
//喜欢、点赞接口
|
||
|
public function logopera(){
|
||
|
$data = $this->request->post();
|
||
|
if($this->request->post()){
|
||
|
$insert['faid'] = $data['id'];
|
||
|
$insert['type'] = $data['type'];
|
||
|
$insert['is_del'] = 0;
|
||
|
$insert['uid'] = $this->auth->id;
|
||
|
DB::startTrans();
|
||
|
try {
|
||
|
$logModel = new PlaylogModel;
|
||
|
$playinfo = PlayinfoModel::get($data['id']);
|
||
|
//查询是否存在该记录
|
||
|
$loginfo = $logModel->where($insert)->find();
|
||
|
//取消操作
|
||
|
if(isset($data['is_del']) && $data['is_del']){
|
||
|
if(!$loginfo) throw new Exception("操作繁忙,请歇一会");
|
||
|
$loginfo->is_del = 1;
|
||
|
if(!$loginfo->save()) throw new Exception("操作繁忙,请歇一会");
|
||
|
//修改主表点赞喜欢数量
|
||
|
if($data['type']==1){
|
||
|
$playinfo->like = $playinfo->like - 1;
|
||
|
}else{
|
||
|
$playinfo->dianzan = $playinfo->dianzan - 1;
|
||
|
}
|
||
|
}else{
|
||
|
//点赞喜欢操作
|
||
|
$insert['created'] = time();
|
||
|
if($loginfo) throw new Exception("操作繁忙,请歇一会");
|
||
|
if(!$logModel->insert($insert)) throw new Exception("操作繁忙,请歇一会");
|
||
|
//修改主表点赞喜欢数量
|
||
|
if($data['type']==1){
|
||
|
$playinfo->like = $playinfo->like + 1;
|
||
|
}else{
|
||
|
$playinfo->dianzan = $playinfo->dianzan + 1;
|
||
|
}
|
||
|
}
|
||
|
if(!$playinfo->save()) throw new Exception("操作繁忙,请歇一会");
|
||
|
DB::commit();
|
||
|
return $this->success("成功");
|
||
|
} catch (Exception $e) {
|
||
|
DB::rollback();
|
||
|
return $this->error($e->getMessage());
|
||
|
}
|
||
|
}
|
||
|
$this->error("非法请求");
|
||
|
}
|
||
|
public function getUserplaylist(){
|
||
|
$data = $this->request->post();
|
||
|
if($this->request->post()){
|
||
|
$myuid = isset($data['token'])&&!empty($data['token'])?$this->auth->id:0;
|
||
|
$uid = $data['uid'];
|
||
|
$where = [];
|
||
|
$order = "";
|
||
|
$offset = $data['offset'];
|
||
|
$limit = $data['limit'];
|
||
|
$list = $this->model->getuserlist($where, $order, $offset, $limit,$uid,$myuid);
|
||
|
return $this->success('获取成功',$list);
|
||
|
}
|
||
|
}
|
||
|
public function getplaydetail(){
|
||
|
$data = $this->request->post();
|
||
|
if($this->request->post()){
|
||
|
$id = $data['id'];
|
||
|
$playinfo = PlayinfoModel::get($id);
|
||
|
if(!$playinfo) return $this->error("动态不存在");
|
||
|
$uid = isset($data['token'])&&!empty($data['token'])?$this->auth->id:0;
|
||
|
//查询当前用户是否点赞
|
||
|
$playinfo['is_like'] = PlaylogModel::where(['faid'=>$playinfo['id'],'type'=>1,'uid'=>$uid,"is_del"=>0])->find()?1:0;
|
||
|
//查询当前用户是否喜欢
|
||
|
$playinfo['is_dianzan'] = PlaylogModel::where(['faid'=>$playinfo['id'],'type'=>2,'uid'=>$uid,"is_del"=>0])->find()?1:0;
|
||
|
$playinfo['create_time'] = date("Y-m-d",$playinfo['create'])==date("Y-m-d",time())?date("H:i",$playinfo['create']):date("Y/m/d H:i",$playinfo['create']);
|
||
|
$playinfo['is_my'] = $playinfo['uid']==$uid?1:0;
|
||
|
return $this->success('获取成功',$playinfo);
|
||
|
}
|
||
|
return $this->error('非法请求');
|
||
|
|
||
|
}
|
||
|
public function getmyshoucanglist(){
|
||
|
$uid = $this->auth->id;
|
||
|
$offset = $this->request->post('offset');
|
||
|
$list = $this->model->table("fa_play_place_log log,fa_play_place_info ppi,fa_user u")->field("ppi.*,u.nickname,u.avatar")
|
||
|
->whereRaw('ppi.uid=u.id')
|
||
|
->whereRaw('log.faid=ppi.id')
|
||
|
->whereRaw('ppi.is_del=0')
|
||
|
->whereRaw('log.is_del=0')
|
||
|
->whereRaw('log.type=1')
|
||
|
->where("log.uid",$uid)
|
||
|
->group('log.id')
|
||
|
->order('created','desc')
|
||
|
->paginate(['page'=> $offset?? 1,'list_rows' => 10])->each(function($item) use(&$uid){
|
||
|
$item['content_img'] = $item['content_img']?explode(',',$item['content_img']):[];
|
||
|
$item['create_time'] = date("Y-m-d",$item['create'])==date("Y-m-d",time())?date("H:i",$item['create']):date("Y/m/d H:i",$item['create']);
|
||
|
$item['is_daren'] = 1;
|
||
|
$item['daren_text'] = "玩乐达人";
|
||
|
$item['is_my'] = $item['uid']==$uid?1:0;
|
||
|
//查询当前用户是否点赞
|
||
|
$item['is_like'] = PlaylogModel::where(['faid'=>$item['id'],'type'=>1,'uid'=>$uid,"is_del"=>0])->find()?1:0;
|
||
|
//查询当前用户是否喜欢
|
||
|
$item['is_dianzan'] = PlaylogModel::where(['faid'=>$item['id'],'type'=>2,'uid'=>$uid,"is_del"=>0])->find()?1:0;
|
||
|
return $item;
|
||
|
});
|
||
|
|
||
|
$result = array("total" => $list->total(), "rows" => $list->items());
|
||
|
return $this->success("获取成功",$result);
|
||
|
}
|
||
|
}
|