Commit 34ff923f by 杨树贤

审核通过后需要对剩余金额进行更新以及批量审核

parent 9b167fca
......@@ -24,7 +24,7 @@ class UserExchangesController extends Controller
public function show(Request $request)
{
$id = $request->id;
$userExchange = UserExchange::where('user_id', $id)->first()->toArray();
$userExchange = UserExchange::with('exchange_setting')->where('id', $id)->first()->toArray();
return $this->Export(0, 'ok', ['data' => $userExchange]);
}
......@@ -40,7 +40,8 @@ class UserExchangesController extends Controller
$page = $request->has('page') ? $request->page : 1;
$pageSize = $request->has('page_size') ? $request->page_size : 10;
$userExchanges = UserExchange::filter($filter)->page($page, $pageSize)
$userExchanges = UserExchange::with(['exchange_setting', 'user_integral'])->filter($filter)->page($page,
$pageSize)
->orderBy('id', 'desc')
->get()->toArray();
$count = UserExchange::filter($filter)->count();
......@@ -66,22 +67,52 @@ class UserExchangesController extends Controller
}
}
/**
* 审核用户的兑换
* @param Request $request
* @param UserExchange $userExchange
* @return array
*/
public function audit(Request $request, UserExchange $userExchange)
{
$data = [
'audit_reason' => $request->audit_reason,
'audit_time' => time(),
'update_time' => time(),
'audit_id' => $request->audit_id,
'user_id' => $request->user_id,
'audit_email' => $request->audit_email,
'status' => $request->status,
];
$res = $userExchange->auditUserExchange($request->id, $request->exchange_amount, $data);
if ($res) {
return $this->Export(0, 'ok');
} else {
return $this->Export(033, '审核用户兑换失败');
}
}
/**
* 批量审核
* @param Request $request
* @return array
*/
public function batchUpdateStatus(Request $request)
public function batchAuditReject(Request $request, UserExchange $userExchange)
{
$ids = $request->ids;
if (!is_array($ids)) {
return Log::Info('批量修改参数不是数组');
}
$status = $request->status;
$res = DB::table('user_exchanges')
->whereIn('id', $ids)
->update(['status' => (int)$status, 'update_time' => time()]);
$data = [
'status' => (int)$request->status,
'audit_reason' => $request->audit_reason,
'audit_id' => $request->audit_id,
'audit_email' => $request->audit_email,
'update_time' => time(),
];
$res = $userExchange->batchAuditRejectUserExchange($ids, $data);
if ($res) {
return $this->Export(0, 'ok');
} else {
......
......@@ -6,6 +6,7 @@ namespace App\Models;
use App\Http\Filters\QueryFilter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class UserExchange extends Model
{
......@@ -20,4 +21,59 @@ class UserExchange extends Model
{
return $filters->apply($query);
}
public function exchange_setting()
{
return $this->hasOne(ExchangeSetting::class, 'id', 'exchange_id');
}
public function user_integral()
{
return $this->belongsTo(UserIntegral::class, 'user_id', 'user_id');
}
//审核用户的兑换
public function auditUserExchange($id, $exchangedAmount, $data = [])
{
$result = DB::transaction(function () use ($id, $exchangedAmount, $data) {
//先去修改审核状态等信息
$result = DB::table('user_exchanges')->where('id', $id)->update($data);
if (!$result) {
return false;
}
//兑换审核通过后,需要对用户剩余的红包金额进行对应的减少
$result = DB::table('user_integrals')->where('user_id', $data['user_id'])
->decrement('integral', $exchangedAmount);
if (!$result) {
return false;
}
//同时用户积分详情的更新时间
$result = DB::table('user_integrals')->where('user_id', $data['user_id'])
->update(['update_time' => $data['update_time']]);
if (!$result) {
return false;
}
return true;
});
if (!$result) {
return false;
}
return true;
}
public function batchAuditRejectUserExchange($ids = [], $data = [])
{
$res = DB::table('user_exchanges')
->whereIn('id', $ids)
->update($data);
return $res;
}
}
\ No newline at end of file
......@@ -60,9 +60,10 @@ $router->post('/exchange_settings/batchUpdateStatus', 'ExchangeSettingsControlle
//用户兑换记录
$router->post('/user_exchanges/info', 'UserExchangesController@show');
$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/batchUpdateStatus', 'UserExchangesController@batchUpdateStatus');
$router->post('/user_exchanges/batchAuditReject', 'UserExchangesController@batchAuditReject');
//抢兑换名额
$router->post('/rob/exchange/quota', 'ExchangeController@create');
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