From 1bb20f2a9d73bf837e918eb119ba3493213642ff Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Thu, 26 Oct 2023 14:17:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9B=B4=E6=92=AD=E9=80=81?= =?UTF-8?q?=E7=A4=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/user/Zhibo.php | 51 ++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/app/controller/api/user/Zhibo.php b/app/controller/api/user/Zhibo.php index f835311b..99b70d6c 100644 --- a/app/controller/api/user/Zhibo.php +++ b/app/controller/api/user/Zhibo.php @@ -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',