111 lines
2.5 KiB
PHP
111 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\BaseCom;
|
|
use app\common\service\RedpacketService;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 红包接口
|
|
*/
|
|
class Redpacket extends BaseCom
|
|
{
|
|
|
|
/**
|
|
* 发红包
|
|
*/
|
|
public function create()
|
|
{
|
|
$data = $this->request->post();
|
|
|
|
$data['user_id'] = $this->uid;
|
|
|
|
$service = new RedpacketService();
|
|
$reslut = $service->create($data);
|
|
|
|
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
|
}
|
|
|
|
/**
|
|
* 抢红包
|
|
*/
|
|
public function grab()
|
|
{
|
|
$redpacketId = $this->request->post('redpacket_id');
|
|
|
|
if (empty($redpacketId)) {
|
|
return V(0, '红包ID不能为空');
|
|
}
|
|
|
|
$service = new RedpacketService();
|
|
$reslut = $service->grabWithResult($redpacketId, $this->uid);
|
|
|
|
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
|
}
|
|
|
|
/**
|
|
* 获取抢红包结果
|
|
*/
|
|
public function grabResult()
|
|
{
|
|
$redpacketId = $this->request->get('redpacket_id');
|
|
|
|
if (empty($redpacketId)) {
|
|
return V(0, '红包ID不能为空');
|
|
}
|
|
|
|
$service = new RedpacketService();
|
|
$result = $service->getGrabResult($redpacketId, $this->uid);
|
|
|
|
if (!$result) {
|
|
return V(0, '红包不存在');
|
|
}
|
|
|
|
return V(1, '获取成功', $result);
|
|
}
|
|
|
|
/**
|
|
* 红包详情
|
|
*/
|
|
public function detail()
|
|
{
|
|
$redpacketId = $this->request->get('redpacket_id');
|
|
|
|
if (empty($redpacketId)) {
|
|
return V(0, '红包ID不能为空');
|
|
}
|
|
|
|
$service = new RedpacketService();
|
|
$detail = $service->getDetail($redpacketId, $this->uid);
|
|
|
|
if (!$detail) {
|
|
return V(0, '红包不存在');
|
|
}
|
|
|
|
return V(1, '获取成功', $detail);
|
|
}
|
|
|
|
/**
|
|
* 获取倒计时选项
|
|
*/
|
|
public function countdownOptions()
|
|
{
|
|
$options = \app\common\model\Redpacket::$countdownOptions;
|
|
$this->success('获取成功', $options);
|
|
}
|
|
|
|
// 获取房间内红包列表
|
|
public function roomRedPackets()
|
|
{
|
|
$roomId = $this->request->get('room_id');
|
|
$result = Db::name('redpacket')->where(['room_id' => $roomId, 'status' => ['<=',1]])->select();
|
|
if($result){
|
|
foreach ($result as &$item) {
|
|
$item['redpacket_id'] = $item['id'];
|
|
$item['redpacket_time'] = get_system_config_value('red_packet_time');//展示时间
|
|
}
|
|
}
|
|
return V(1, '获取成功', $result);
|
|
}
|
|
} |