Commit 60020b50 by 杨树贤

确认提现任务

parent 25c86ee2
......@@ -26,14 +26,11 @@ class ExchangesTask extends Task
//验证这个订单是否充值,防止重复提现
$Redis = new RedisModel();
$Cache = $Redis->hsetnx('ic_user_exchanges' , $this->data['id'].'_'.$this->data['user_id'] , 1);
Log::error('进来了');
Log::error($Cache);
if(!$Cache)
return true;
try{
DB::beginTransaction();
Log::error('事务');
//先修改提现记录状态
$UserExchangModel = new UserExchange();
$Exchang = [
......
......@@ -218,4 +218,24 @@ class UserExchangesController extends Controller
return $this->Export(ErrorCode(100, 5), '提现失败');
}
}
/**
* 确认提现接口
* @param Request $request
* @param UserExchange $userExchange
* @return false|string
*/
public function confirm(Request $request,UserExchange $userExchange)
{
$exchangeId = $request->get('exchange_id');
$userId = $request->get('user_id');
//查询该次兑换对应的兑换
$result = $userExchange->confirmExchange($exchangeId,$userId);
if (!$result) {
return $this->Export(ErrorCode(22,5),'确认兑现失败');
}
return $this->Export(0,'ok');
}
}
\ No newline at end of file
......@@ -150,4 +150,41 @@ class UserExchange extends Model
return $result;
}
//确认用户兑换
public function confirmExchange($exchangeId, $userId)
{
$userExchange = DB::table('user_exchanges')->where('id', $exchangeId)->first();
if ($userExchange) {
//先判断状态,如果是已经兑换的,直接返回失败
if ($userExchange->status != 0) {
return false;
}
//判断该兑换是否属于该用户,不属于直接返回失败
if ($userExchange->user_id != $userId) {
return false;
}
//如果是未兑换的,则要去进行提现的异步任务
$data = (array)$userExchange;
if ($data['amount'] < 20 && $data['type'] == 2) {
$ic_exchange_settings['amount'] = $data['amount'];
$Task = new ExchangesTask($data, $ic_exchange_settings);
$Task->delay(5);
$result = Task::deliver($Task);
if (!$result) {
ErrorLog(ErrorCode(1, 9), '提现任务推送失败,提现ID:' . $data['id']);
return false;
}
Log::info('进行提现任务投递成功');
return true;
} else {
//如果是大于20块的,需要审核,这步就什么都不做
return true;
}
} else {
return false;
}
}
}
\ No newline at end of file
common @ 6a492b76
Subproject commit 8428774c731bbcd89366d7d698daf57579f0b53b
Subproject commit 6a492b76f3938205ed9d94cd12b81d66feea657d
......@@ -61,6 +61,7 @@ $router->post('/user_exchanges/add', 'UserExchangesController@store');
$router->post('/user_exchanges/audit', 'UserExchangesController@audit');
$router->post('/user_exchanges/list', 'UserExchangesController@index');
$router->post('/user_exchanges/update', 'UserExchangesController@update');
$router->post('/user_exchanges/exchange/confirm', 'UserExchangesController@confirm');
$router->post('/user_exchanges/batchAuditReject', 'UserExchangesController@batchAuditReject');
......
7163
\ No newline at end of file
21975
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment