更新直播打赏
This commit is contained in:
parent
e12c0aa066
commit
9c0e7645f8
92
app/controller/api/user/Zhibo.php
Normal file
92
app/controller/api/user/Zhibo.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\user;
|
||||
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\repositories\user\UserBillRepository;
|
||||
use think\App;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* Class Auth
|
||||
* @package app\controller\api
|
||||
* @author xaboy
|
||||
* @day 2020-05-06
|
||||
*/
|
||||
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('用户余额不足');
|
||||
}
|
||||
//查询直播间及礼物接口,验证直播间信息及礼物信息
|
||||
|
||||
try {
|
||||
Db::transaction(function () use ($user, $params) {
|
||||
//打赏订单
|
||||
$orderId = Db::name('user_zhibo_order')->insertGetId([
|
||||
'live_stream_id' => $params['live_stream_id'],
|
||||
'live_name' => $params['live_name'],
|
||||
'gift_id' => $params['gift_id'],
|
||||
'gift_name' => $params['gift_name'],
|
||||
'uid' => $user['uid'],
|
||||
'master_id' => $params['master_id'],
|
||||
'order_sn' => 'zb' . date('YmdHis') . mt_rand(1000, 9999),
|
||||
'amount' => $params['amount'],
|
||||
'pay_status' => 1,
|
||||
'pay_time' => date('Y-m-d H:i:s'),
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
//打赏人扣钱
|
||||
$user->now_money = bcsub($user['now_money'], $params['amount']);
|
||||
$user->save();
|
||||
$userBillRepository = app()->make(UserBillRepository::class);
|
||||
//打赏人账单
|
||||
$userBillRepository->decBill($user['uid'], 'now_money', 'zhibo_reward', [
|
||||
'link_id' => $orderId,
|
||||
'status' => 1,
|
||||
'title' => '直播打赏支出',
|
||||
'number' => $params['amount'],
|
||||
'mark' => '余额打赏',
|
||||
'balance' => $user->now_money
|
||||
]);
|
||||
//主播加钱
|
||||
Db::name('user')->where('uid', $params['master_id'])->inc('now_money', $params['amount'])->update();
|
||||
$master = Db::name('user')->where('uid', $params['master_id'])->find();
|
||||
//主播账单
|
||||
$userBillRepository->incBill($master['uid'], 'now_money', 'zhibo_reward', [
|
||||
'link_id' => $orderId,
|
||||
'status' => 1,
|
||||
'title' => '直播打赏收入',
|
||||
'number' => $params['amount'],
|
||||
'mark' => '直播打赏收入',
|
||||
'balance' => $master['now_money']
|
||||
]);
|
||||
});
|
||||
} catch (Exception $e) {
|
||||
return app('json')->fail($e->getMessage());
|
||||
}
|
||||
|
||||
return app('json')->success($params);
|
||||
}
|
||||
}
|
@ -77,6 +77,9 @@ Route::group('api/', function () {
|
||||
Route::post('user/margin', 'api.Auth/doMargin');
|
||||
Route::get('user/margin/list', 'api.Auth/marginList');
|
||||
|
||||
//绑定推荐人
|
||||
Route::post('zhibo/reward', 'api.user.Zhibo/reward');
|
||||
|
||||
//优惠券
|
||||
Route::group('coupon', function () {
|
||||
Route::post('receive/:id', 'api.store.product.StoreCoupon/receiveCoupon');
|
||||
|
Loading…
x
Reference in New Issue
Block a user