更新直播送礼

This commit is contained in:
yaooo 2023-10-26 14:17:47 +08:00
parent f537c3b18c
commit 1bb20f2a9d

View File

@ -19,6 +19,8 @@ use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\facade\Db;
use think\response\Json;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
/**
* Class Auth
@ -28,18 +30,36 @@ use think\response\Json;
*/
class Zhibo extends BaseController
{
//用户直播送礼
public function reward()
{
$params = $this->request->params(['live_stream_id', 'gift_id', 'master_id']);
$user = $this->request->userInfo();
$params['live_name'] = '直播间名称';
$params['gift_name'] = '礼物名称';
$params['amount'] = 10;
if ($params['amount'] > $user['now_money']) {
return app('json')->fail('用户余额不足');
$user = $this->request->userInfo();
if (empty($params['live_stream_id']) || empty($params['master_id']) || empty($params['gift_id'])) {
return app('json')->fail('live_stream_id, master_id, gift_id 参数不能为空');
}
$token = request()->header('x-token');
//查询直播间及礼物接口,验证直播间信息及礼物信息
$checkUrl = 'https://ceshi-zhibo.lihaink.cn/api/zhibo/checkGift';
$client = new Client();
$response = $client->request('POST', $checkUrl, [
'verify' => false,
'headers' => ['X-Token' => $token],
'json' => [
"live_stream_id" => $params['live_stream_id'],
"master_id" => $params['master_id'],
"gift_id" => $params['gift_id']
]
]);
$responseData = json_decode($response->getBody()->getContents(), true);
if (empty($responseData['code'])) {
$failMsg = $responseData['msg'];
return app('json')->fail($failMsg);
}
$giftData = $responseData['data'];
$params['live_name'] = $giftData['live_name'];
$params['gift_name'] = $giftData['gift_name'];
$params['amount'] = $giftData['gift_price'];
try {
Db::transaction(function () use ($user, $params) {
//打赏订单
@ -86,12 +106,27 @@ class Zhibo extends BaseController
} catch (Exception $e) {
return app('json')->fail($e->getMessage());
}
$message = "{$user['nickname']}送出了{$params['gift_name']}";
//发送礼物消息
$giftUrl = 'https://ceshi-zhibo.lihaink.cn/api/zhibo/sendGiftMessage';
$client = new Client();
$client->request('POST', $giftUrl, [
'verify' => false,
'headers' => ['X-Token' => $token],
'json' => [
"live_stream_id" => $params['live_stream_id'],
"app_name" => 'shop',
"message" => $message
]
]);
return app('json')->success('送礼成功');
}
//用户送礼收礼记录
public function rewardList()
{
[$page, $limit] = $this->getPage();
$token = request()->header('x-token');
$params = $this->request->params(['type']);
if (empty($params['type'])) {
return app('json')->fail('类型不能为空');
@ -112,7 +147,7 @@ class Zhibo extends BaseController
return app('json')->fail('类型错误');
}
$count = Db::name('user_bill')->alias('ub')->leftJoin('user_zhibo_order uzo','uzo.order_id = ub.link_id')->where($where)->count();
$list = Db::name('user_bill')->alias('ub')->leftJoin('user_zhibo_order uzo','uzo.order_id = ub.link_id')->where($where)->limit(($page-1) * $limit, $limit)->field([
$list = Db::name('user_bill')->alias('ub')->leftJoin('user_zhibo_order uzo','uzo.order_id = ub.link_id')->where($where)->limit(($page-1) * $limit, $limit)->field([
'uzo.order_id',
'uzo.live_stream_id',
'uzo.live_name',