|
@@ -61,6 +61,7 @@ class Wallet extends Controller
|
|
|
return $this->success($data);
|
|
return $this->success($data);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //扣款
|
|
|
public function debiting()
|
|
public function debiting()
|
|
|
{
|
|
{
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
@@ -69,8 +70,6 @@ class Wallet extends Controller
|
|
|
'amount' => ['required', 'numeric', 'min:0.01'],
|
|
'amount' => ['required', 'numeric', 'min:0.01'],
|
|
|
'member_id' => ['required', 'string', 'min:1'],
|
|
'member_id' => ['required', 'string', 'min:1'],
|
|
|
'remark' => ['required', 'string', 'min:1'],
|
|
'remark' => ['required', 'string', 'min:1'],
|
|
|
- 'order_type' => ['nullable'],
|
|
|
|
|
- 'order_id' => ['nullable'],
|
|
|
|
|
]);
|
|
]);
|
|
|
$memberId = request()->input('member_id');
|
|
$memberId = request()->input('member_id');
|
|
|
$amount = request()->input('amount');
|
|
$amount = request()->input('amount');
|
|
@@ -91,19 +90,6 @@ class Wallet extends Controller
|
|
|
$wallet->available_balance = $availableBalance;
|
|
$wallet->available_balance = $availableBalance;
|
|
|
$wallet->save();
|
|
$wallet->save();
|
|
|
|
|
|
|
|
- if (!empty($params['order_type']) && !empty($params['order_id'])) {
|
|
|
|
|
- if ($params['order_type'] == 'sport') {
|
|
|
|
|
- $info = Order::where('id', $params['order_id'])->first();
|
|
|
|
|
- } elseif ($params['order_type'] == 'lhc') {
|
|
|
|
|
- $info = LhcOrder::where('id', $params['order_id'])->first();
|
|
|
|
|
- }
|
|
|
|
|
- if (!$info) {
|
|
|
|
|
- throw new \Exception('订单不存在');
|
|
|
|
|
- } else {
|
|
|
|
|
- $info->remark = $info->remark ? $info->remark. '|' . $params['remark'] : $params['remark'];
|
|
|
|
|
- $info->save();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
} catch (ValidationException $e) {
|
|
} catch (ValidationException $e) {
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
@@ -129,8 +115,6 @@ class Wallet extends Controller
|
|
|
'member_id' => ['required', 'string', 'min:1'],
|
|
'member_id' => ['required', 'string', 'min:1'],
|
|
|
'remark' => ['required', 'string', 'min:1'],
|
|
'remark' => ['required', 'string', 'min:1'],
|
|
|
'change_type' => ['required', 'string', 'in:' . implode(',', BalanceLogService::$manualRecharge)],
|
|
'change_type' => ['required', 'string', 'in:' . implode(',', BalanceLogService::$manualRecharge)],
|
|
|
- 'order_type' => ['nullable'],
|
|
|
|
|
- 'order_id' => ['nullable'],
|
|
|
|
|
]);
|
|
]);
|
|
|
$memberId = request()->input('member_id');
|
|
$memberId = request()->input('member_id');
|
|
|
$amount = request()->input('amount');
|
|
$amount = request()->input('amount');
|
|
@@ -150,19 +134,6 @@ class Wallet extends Controller
|
|
|
$wallet->available_balance = $availableBalance;
|
|
$wallet->available_balance = $availableBalance;
|
|
|
$wallet->save();
|
|
$wallet->save();
|
|
|
|
|
|
|
|
- if (!empty($params['order_type']) && !empty($params['order_id'])) {
|
|
|
|
|
- if ($params['order_type'] == 'sport') {
|
|
|
|
|
- $info = Order::where('id', $params['order_id'])->first();
|
|
|
|
|
- } elseif ($params['order_type'] == 'lhc') {
|
|
|
|
|
- $info = LhcOrder::where('id', $params['order_id'])->first();
|
|
|
|
|
- }
|
|
|
|
|
- if (!$info) {
|
|
|
|
|
- throw new \Exception('订单不存在');
|
|
|
|
|
- } else {
|
|
|
|
|
- $info->remark = $info->remark ? $info->remark. '|' . $params['remark'] : $params['remark'];
|
|
|
|
|
- $info->save();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
} catch (ValidationException $e) {
|
|
} catch (ValidationException $e) {
|
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
@@ -179,6 +150,118 @@ class Wallet extends Controller
|
|
|
return $this->success();
|
|
return $this->success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //订单充值
|
|
|
|
|
+ public function orderTopUp()
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ request()->validate([
|
|
|
|
|
+ 'amount' => ['required', 'numeric', 'min:0.01'],
|
|
|
|
|
+ 'remark' => ['required', 'string', 'min:1'],
|
|
|
|
|
+ 'order_type' => ['nullable'],
|
|
|
|
|
+ 'order_id' => ['nullable'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $order_type = request()->input('order_type');
|
|
|
|
|
+ $order_id = request()->input('order_id');
|
|
|
|
|
+ $amount = request()->input('amount');
|
|
|
|
|
+ $remark = request()->input('remark');
|
|
|
|
|
+ $changeType = "人工充值";
|
|
|
|
|
+ $key = 'api_request_' . md5($order_id . json_encode([
|
|
|
|
|
+ 'amount' => $amount,
|
|
|
|
|
+ 'remark' => $remark,
|
|
|
|
|
+ 'action' => "wallet/orderTopUp"
|
|
|
|
|
+ ]));
|
|
|
|
|
+ if (Cache::has($key)) throw new Exception("请求太频繁,请稍后再试。", HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ Cache::put($key, true, 3);
|
|
|
|
|
+
|
|
|
|
|
+ if ($order_type == 'sport') {
|
|
|
|
|
+ $info = Order::where('id', $order_id)->first();
|
|
|
|
|
+ } elseif ($order_type == 'lhc') {
|
|
|
|
|
+ $info = LhcOrder::where('id', $order_id)->first();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!$info) {
|
|
|
|
|
+ throw new \Exception('订单不存在');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $info->remark = $info->remark ? $info->remark. '|' . $remark : $remark;
|
|
|
|
|
+ $info->save();
|
|
|
|
|
+ }
|
|
|
|
|
+ $memberId = $order_type == 'sport' ? $info->user_id : $info->member_id;
|
|
|
|
|
+
|
|
|
|
|
+ $wallet = WalletModel::where('member_id', $memberId)->first();
|
|
|
|
|
+ if (!$wallet) throw new Exception('用户不存在', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ $availableBalance = bcadd($wallet->available_balance, $amount, 10);
|
|
|
|
|
+ BalanceLogService::addLog($memberId, $amount, $wallet->available_balance, $availableBalance, $changeType, null, $remark);
|
|
|
|
|
+ $wallet->available_balance = $availableBalance;
|
|
|
|
|
+ $wallet->save();
|
|
|
|
|
+
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ } catch (ValidationException $e) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return $this->error(intval($e->getCode()), $e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $this->success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //订单扣款
|
|
|
|
|
+ public function orderDebiting()
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ request()->validate([
|
|
|
|
|
+ 'amount' => ['required', 'numeric', 'min:0.01'],
|
|
|
|
|
+ 'remark' => ['required', 'string', 'min:1'],
|
|
|
|
|
+ 'order_type' => ['required'],
|
|
|
|
|
+ 'order_id' => ['required'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $order_type = request()->input('order_type');
|
|
|
|
|
+ $order_id = request()->input('order_id');
|
|
|
|
|
+ $amount = request()->input('amount');
|
|
|
|
|
+ $amount = $amount * -1;
|
|
|
|
|
+ $remark = request()->input('remark');
|
|
|
|
|
+ $key = 'api_request_' . md5($order_id . json_encode([
|
|
|
|
|
+ 'amount' => $amount,
|
|
|
|
|
+ 'remark' => $remark,
|
|
|
|
|
+ 'action' => "wallet/orderDebiting"
|
|
|
|
|
+ ]));
|
|
|
|
|
+ if (Cache::has($key)) throw new Exception("请求太频繁,请稍后再试。", HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ Cache::put($key, true, 3);
|
|
|
|
|
+
|
|
|
|
|
+ if ($order_type == 'sport') {
|
|
|
|
|
+ $info = Order::where('id', $order_id)->first();
|
|
|
|
|
+ } elseif ($order_type == 'lhc') {
|
|
|
|
|
+ $info = LhcOrder::where('id', $order_id)->first();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!$info) {
|
|
|
|
|
+ throw new \Exception('订单不存在');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $info->remark = $info->remark ? $info->remark. '|' . $remark : $remark;
|
|
|
|
|
+ $info->save();
|
|
|
|
|
+ }
|
|
|
|
|
+ $memberId = $order_type == 'sport' ? $info->user_id : $info->member_id;
|
|
|
|
|
+
|
|
|
|
|
+ $wallet = WalletModel::where('member_id', $memberId)->first();
|
|
|
|
|
+ if (!$wallet) throw new Exception('用户不存在', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ $availableBalance = bcadd($wallet->available_balance, $amount, 10);
|
|
|
|
|
+ if ($availableBalance < 0) throw new Exception('可用余额不足', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ BalanceLogService::addLog($memberId, $amount, $wallet->available_balance, $availableBalance, "人工扣款", null, $remark);
|
|
|
|
|
+ $wallet->available_balance = $availableBalance;
|
|
|
|
|
+ $wallet->save();
|
|
|
|
|
+
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ } catch (ValidationException $e) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return $this->error(intval($e->getCode()), $e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return $this->success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @api {post} /admin/wallet/verifyRecharge 审核
|
|
* @api {post} /admin/wallet/verifyRecharge 审核
|
|
|
* @apiGroup 充值管理
|
|
* @apiGroup 充值管理
|