master
parent
461f347b1a
commit
367345ea8d
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
namespace Base\Service;
|
||||
|
||||
use Base\Facade\Request;
|
||||
use Base\Tool\GameCatClient;
|
||||
|
||||
class TestingResourceService
|
||||
{
|
||||
public static $provideStatusList = [
|
||||
'0' => '待发放',
|
||||
'1' => '已发放',
|
||||
'2' => '异常',
|
||||
];
|
||||
public static $verifyStatusList = [
|
||||
'0' => '未审核',
|
||||
'1' => '审核通过',
|
||||
'2' => '审核拒绝',
|
||||
];
|
||||
|
||||
public function getProvideStatusText($provideStatus)
|
||||
{
|
||||
return self::$provideStatusList[$provideStatus] ?? '未知';
|
||||
}
|
||||
|
||||
public function getVerifyStatusText($verifyStatus)
|
||||
{
|
||||
return self::$verifyStatusList[$verifyStatus] ?? '未知';
|
||||
}
|
||||
|
||||
public function verify($batch)
|
||||
{
|
||||
if ($batch['verify_status'] != 0) {
|
||||
throw new \Exception('审核状态异常');
|
||||
}
|
||||
|
||||
$batchData = [];
|
||||
$batchData['verify_time'] = time();
|
||||
$batchData['update_time'] = time();
|
||||
|
||||
if (!in_array($batch['game_id'], [229, 230])) {
|
||||
|
||||
$batchData['verify_status'] = 2;
|
||||
$batchData['verify_remark'] = '该游戏发放功能暂未实现';
|
||||
M('testing_resource_batch', 'tab_')->where(['id' => $batch['id']])->save($batchData);
|
||||
|
||||
throw new \Exception('该游戏发放功能暂未实现');
|
||||
}
|
||||
|
||||
$batchData['verify_status'] = 1;
|
||||
$batchData['verify_remark'] = '审核成功';
|
||||
M('testing_resource_batch', 'tab_')->where(['id' => $batch['id']])->save($batchData);
|
||||
}
|
||||
|
||||
public function provide($batch)
|
||||
{
|
||||
if ($batch['provide_status'] != 0) {
|
||||
throw new \Exception('发放状态异常');
|
||||
}
|
||||
|
||||
$role = M('user_play_info', 'tab_')
|
||||
->field(['id', 'role_id', 'user_id', 'promote_id'])
|
||||
->where(['game_id' => $batch['game_id'], 'role_id' => $batch['role_id']])
|
||||
->find();
|
||||
$orders = M('testing_resource_order', 'tab_')
|
||||
->where(['batch_id' => $batch['id']])
|
||||
->select();
|
||||
|
||||
$hasError = false;
|
||||
$provideAmount = 0;
|
||||
foreach ($orders as $order) {
|
||||
$result = $this->provideFromGameCat($order, $role);
|
||||
$orderData = [
|
||||
'result' => json_encode(['code' => $result['code'], 'message' => $result['message']]),
|
||||
];
|
||||
if (!$result['status']) {
|
||||
$hasError = true;
|
||||
$orderData['provide_status'] = 2;
|
||||
}
|
||||
$provideAmount += round($order['ref_amount'] * $order['num'], 2);
|
||||
$orderData['provide_status'] = 1;
|
||||
$orderData['provide_time'] = time();
|
||||
M('testing_resource_order', 'tab_')
|
||||
->where(['id' => $order['id']])
|
||||
->save($orderData);
|
||||
}
|
||||
|
||||
$batchData = [];
|
||||
if ($hasError) {
|
||||
$batchData['provide_status'] = 2;
|
||||
}
|
||||
$batchData['provide_time'] = time();
|
||||
$batchData['provide_amount'] = $provideAmount;
|
||||
$batchData['update_time'] = time();
|
||||
M('testing_resource_batch', 'tab_')
|
||||
->where(['id' => $batch['id']])
|
||||
->save($batchData);
|
||||
}
|
||||
|
||||
public function provideFromGameCat($order, $role)
|
||||
{
|
||||
$gameCatClient = new GameCatClient();
|
||||
$result = $gameCatClient->api('provide', [
|
||||
'roleId' => $role['role_id'],
|
||||
'amount' => $order['ref_amount'],
|
||||
'supportItem' => $order['ref_id'],
|
||||
'supportType' => 0,
|
||||
'channelUid' => $role['user_id'],
|
||||
'applyRemark' => $order['remark'],
|
||||
'applyId' => $order['order_no'],
|
||||
'device_type' => $deviceType,
|
||||
]);
|
||||
if ($result['code'] == 1 && $result['data']) {
|
||||
return [
|
||||
'status' => true,
|
||||
'message' => $result['message'],
|
||||
'code' => 1,
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $result['message'],
|
||||
'code' => $result['code'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue