You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.3 KiB
PHTML

4 years ago
<?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['verify_status'] != 1) {
throw new \Exception('该申请未审核通过');
}
4 years ago
if ($batch['provide_status'] != 0) {
throw new \Exception('发放状态异常');
}
$role = M('user_play_info', 'tab_')
->field(['id', 'role_id', 'user_id', 'promote_id', 'user_account', 'sdk_version'])
4 years ago
->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;
} else {
$orderData['provide_status'] = 1;
4 years ago
}
$provideAmount += round($order['ref_amount'] * $order['num'], 2);
$orderData['provide_time'] = time();
M('testing_resource_order', 'tab_')
->where(['id' => $order['id']])
->save($orderData);
}
$batchData = [];
if ($hasError) {
$batchData['provide_status'] = 2;
} else {
$batchData['provide_status'] = 1;
4 years ago
}
$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'],
4 years ago
'amount' => intval($order['ref_amount']),
4 years ago
'supportItem' => $order['ref_id'],
4 years ago
'supportType' => '0',
4 years ago
'channelUid' => $role['user_account'],
4 years ago
'applyRemark' => $order['remark'] == '' ? '测试资源申请' : $order['remark'],
4 years ago
'applyId' => $order['order_no'],
4 years ago
'device_type' => $role['sdk_version'] == 1 ? 'andriod' : 'ios',
4 years ago
]);
4 years ago
if ($result['state'] == 1 && $result['data']) {
4 years ago
return [
'status' => true,
4 years ago
'message' => $result['msg'],
4 years ago
'code' => 1,
];
} else {
return [
'status' => false,
4 years ago
'msg' => $result['msg'],
'code' => $result['state'],
4 years ago
];
}
}
}