更新
This commit is contained in:
119
application/api/controller/Redpacket.php
Normal file
119
application/api/controller/Redpacket.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?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 = input('redpacket_id', 0);
|
||||
|
||||
if (empty($redpacketId)) {
|
||||
return V(0, '红包ID不能为空');
|
||||
}
|
||||
|
||||
$service = new RedpacketService();
|
||||
// 在抢红包前确保状态正确
|
||||
$service->checkAndUpdateRedpacketStatus($redpacketId);
|
||||
$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 = input('redpacket_id', 0);
|
||||
|
||||
if (empty($redpacketId)) {
|
||||
return V(0, '红包ID不能为空');
|
||||
}
|
||||
|
||||
$service = new RedpacketService();
|
||||
// 在获取详情前确保状态正确
|
||||
$service->checkAndUpdateRedpacketStatus($redpacketId);
|
||||
$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');//展示时间
|
||||
$item['nickname'] = Db::name('user')->where('id', $item['user_id'])->value('nickname');
|
||||
$item['avatar'] = Db::name('user')->where('id', $item['user_id'])->value('avatar');
|
||||
$is_qiang = Db::name('redpacket_record')->where(['redpacket_id' => $item['id'], 'user_id' => $this->uid])->find();
|
||||
$item['is_qiang'] = $is_qiang ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return V(1, '获取成功', $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user