|
|
|
<?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('该申请未审核通过');
|
|
|
|
}
|
|
|
|
|
|
|
|
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'])
|
|
|
|
->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;
|
|
|
|
}
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
$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' => intval($order['ref_amount']),
|
|
|
|
'supportItem' => $order['ref_id'],
|
|
|
|
'supportType' => '0',
|
|
|
|
'channelUid' => $role['user_account'],
|
|
|
|
'applyRemark' => $order['remark'] == '' ? '测试资源申请' : $order['remark'],
|
|
|
|
'applyId' => $order['order_no'],
|
|
|
|
'device_type' => $role['sdk_version'] == 1 ? 'andriod' : 'ios',
|
|
|
|
]);
|
|
|
|
if ($result['state'] == 1 && $result['data']) {
|
|
|
|
return [
|
|
|
|
'status' => true,
|
|
|
|
'message' => $result['msg'],
|
|
|
|
'code' => 1,
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
return [
|
|
|
|
'status' => false,
|
|
|
|
'msg' => $result['msg'],
|
|
|
|
'code' => $result['state'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|