苗总组局小程序
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.
 
 
 
 
 
 

188 lines
6.4 KiB

<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\Area;
use app\admin\model\shop\Type as TypeModel;
use app\admin\model\Shop as ShopModel;
use app\admin\model\Comment as CommentModel;
use app\api\controller\Order;
use think\Db;
use think\Exception;
class Group extends Api{
protected $model = null;
protected $noNeedRight = '*';
protected $noNeedLogin = ['getlist','getgroupdetail','getSearchSet','getcomment','getRanklist','getindexrank'];
public function _initialize(){
parent::_initialize();
$this->model = new \app\admin\model\Group;
}
public function getlist(){
$data = $this->request->post();
if($this->request->isPost()){
$uid = isset($data['token'])&&!empty($data['token'])?$this->auth->id: 0;
$where = json_decode(htmlspecialchars_decode($data['filter']),true);
$order = json_decode(htmlspecialchars_decode($data['order']),true);
$offset = $data['offset'];
$limit = $data['limit'];
$list = $this->model->getlist($where, $order, $offset, $limit,$uid);
return $this->success('获取成功',$list);
}
}
public function getgroupdetail(){
$data = $this->request->post();
if($this->request->isPost()){
$return = $this->model->getgroupdetail($data['gid']);
return $this->success('获取成功',$return);
}
}
public function getSearchSet(){
if($this->request->isPost()){
$data = $this->request->post();
//获取市信息
$Area = !$data['city']?['id'=>0]:Area::getbyName($data['city']);
//获取市下面的地区
$AreaInfo = Area::field('id as value,name as title,0 as selected,pid')->where('pid',$Area['id'])->select();
foreach($AreaInfo as $k => $v){
if($Area['id']==0){
$AreaInfo[$k]['city'] = $this->resolve2($v,$v['pid']);
}
if(isset($data['district'])&&$data['district'] && $Area['id']!=0){
$AreaInfo[$k]['selected'] = $v['title']==$data['district']?1:0;
}
}
$data['searchcity'] = $AreaInfo;
}
//获取时间段列表
$data['searchdate'] = $this->model->getTimeList();
//配置时间端
$data['searchtime'] = [['title'=>'上午场','value'=>'08:00-12:00'],['title'=>'下午场','value'=>'12:00-18:00'],['title'=>'夜间场','value'=>'12:00-次日06:00']];
//配置搜索项
$data['searchother'] = [['title'=>'距离优先','value'=>'start_time'],['title'=>'最近开场时间','value'=>'distance_in_meters']];
return $this->success('获取成功',$data);
}
public function getDistrictinfo($list,$city_id){
//获取省信息
$area = new Area;
$list = $area->field("id as value,name as title,0 as selected")->where('pid',$city_id)->select();
return $list;
}
function resolve2( $list, $pid = 0) {
$manages = array();
foreach ($list as $row) {
if ($row['pid'] == $pid) {
$manages[$row['value']] = $row;
$children = $this->resolve2($list, $row['value']);
$children && $manages[$row['value']]['children'] = $children;
}
}
return $manages;
}
// 获取组局评价
public function getcomment(){
if($this->request->isPost()){
$data = $this->request->post();
$offset = $data['offset'];
$limit = $data['limit'];
$list = CommentModel::where('gid',$data['gid'])->paginate(['page'=> $offset?? 1,'list_rows' => $limit])->each(function($item){
if(isset($item['uid']) && !empty($item['uid']) ){
}else{
$item['is_daren'] = 0;
}
$item['create'] = date('Y-m-d H:i:s',time());
return $item;
});
$result = array("total" => $list->total(), "rows" => $list->items());
return $this->success('获取成功',$result);
}
}
public function getRanklist(){
$data = $this->request->post();
if($this->request->isPost()){
$where = json_decode(htmlspecialchars_decode($data['filter']),true);
$order = [];
$offset = $data['offset'];
$limit = $data['limit'];
$list = $this->model->getRanklist($where, $order, $offset, $limit);
return $this->success('获取成功',$list);
}
}
public function getindexrank(){
$data = $this->request->post();
if($this->request->isPost()){
$uid = isset($data['token'])&&!empty($data['token'])?$this->auth->id: 0;
$where = json_decode(htmlspecialchars_decode($data['filter']),true);
$order = ['rankings_num'=>'asc'];
$offset = 1;
$limit= 4;
$zhuwhere = $where;
$datalist = $this->model->getRanklist($zhuwhere, $order, $offset, $limit);
$list = [];
if($datalist['rows']){
$list['rank'] = $datalist['rows'];
$list['list'] = $this->model->getRanklist($zhuwhere, ['create'=>"desc"], $offset, $limit);
}
return $this->success('获取成功',$list);
}
}
public function exitgroup(){
if($this->request->isPost()){
$data = $this->request->post();
$uid = $this->auth->id;
$vid = $data['vid'];
$gid = $data['gid'];
//查询符合条件的订单
$order = \app\admin\model\Order::where('vid',$vid)->where('gid',$gid)->where('uid',$uid)->where('status',1)->find();
if($order){
$venue = \app\admin\model\Venue::where('id',$vid)->find();
// if($venue['start_time']-time()<60*60*24) return $this->error('开场24小时之内,不能退出哦');
Db::startTrans();
try {
if($venue['ing_people']>=$venue['min_people']){
$order->status = -1;
if(!$order->save()) throw new Exception("退出组局失败");
}else{
//退费操作
$refund=[
'out_trade_no' => $order->orderno,
'out_refund_no' => "RE".time(),
'total_fee' => $order->pay_price*100,
'refund_fee' => $order->pay_price*100,
'refund_desc' => '退款',
'type' => 'miniapp',
];
$ordeM = new Order;
$result =$ordeM->orderRefunds($refund);
if(!$result) throw new Exception("退款失败");
$order->status = -2;
$order->refund_time = time();
$order->refund_money = $order->pay_price;
$order->refund_oderno = $refund['out_refund_no'];
$venue->ing_people = $venue['ing_people']-$order['people_num'];
//
if(!$order->save()||!$venue->save()) throw new Exception("退出组局失败");
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
return $this->error($e->getMessage());
}
if($venue['ing_people']>=$venue['min_people']){
return $this->success('已提交商家审核');
}else{
return $this->success('退出组局成功');
}
}
return $this->error('未找到组局信息');
}
return $this->error('非法请求');
}
}