|
@@ -5,53 +5,52 @@ namespace App\Http\Controllers\admin;
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Models\FundsRecord;
|
|
use App\Models\FundsRecord;
|
|
|
use App\Models\User;
|
|
use App\Models\User;
|
|
|
-use App\Models\Admin;
|
|
|
|
|
use App\Models\Order as OrderModel;
|
|
use App\Models\Order as OrderModel;
|
|
|
use Exception;
|
|
use Exception;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use App\Constants\HttpStatus;
|
|
use App\Constants\HttpStatus;
|
|
|
|
|
+use App\Models\Wallet;
|
|
|
|
|
|
|
|
class Order extends Controller
|
|
class Order extends Controller
|
|
|
{
|
|
{
|
|
|
/**
|
|
/**
|
|
|
* 订单手动退款
|
|
* 订单手动退款
|
|
|
*/
|
|
*/
|
|
|
- public function adminRefund()
|
|
|
|
|
|
|
+ public function refund()
|
|
|
{
|
|
{
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
try {
|
|
try {
|
|
|
$params = request()->validate([
|
|
$params = request()->validate([
|
|
|
- 'order_id' => ['required', 'array', 'min:1'],
|
|
|
|
|
- 'safe_word' => ['required', 'string'],
|
|
|
|
|
|
|
+ 'id' => ['required', 'array', 'min:1'],
|
|
|
]);
|
|
]);
|
|
|
- $id = request()->user->id;
|
|
|
|
|
- $admin = Admin::where('id', $id)->first();
|
|
|
|
|
- if (!password_verify($params['safe_word'], $admin->payment_password)) throw new Exception('资金密码错误');
|
|
|
|
|
-
|
|
|
|
|
- $orderList = OrderModel::whereIn('id', $params['order_id'])->get();
|
|
|
|
|
|
|
+ $orderList = OrderModel::whereIn('id', $params['id'])->get();
|
|
|
foreach ($orderList as $order) {
|
|
foreach ($orderList as $order) {
|
|
|
- if ($order->return_status != 0 || $order->pay_status != 1) {
|
|
|
|
|
|
|
+ if ($order->return_status != 0 || $order->pay_status != 1 || $order->settlement_status != 0) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $order->status = 3;
|
|
|
|
|
|
|
+ $order->status = 2;
|
|
|
$order->return_status = 2;
|
|
$order->return_status = 2;
|
|
|
$order->return_operation_time = time();
|
|
$order->return_operation_time = time();
|
|
|
$order->save();
|
|
$order->save();
|
|
|
-
|
|
|
|
|
- $user = User::where('user_id', $order->user_id)->first();
|
|
|
|
|
- if (!$user) continue;
|
|
|
|
|
- if ($user->type == 1) {
|
|
|
|
|
- FundsRecord::addData([
|
|
|
|
|
- 'transaction_type' => '退款',
|
|
|
|
|
- 'amount' => $order->amount,
|
|
|
|
|
- 'before_balance' => $user->money,
|
|
|
|
|
- 'after_balance' => bcsub($user->money, $order->amount, 2),
|
|
|
|
|
- 'member_id' => $user->user_id,
|
|
|
|
|
- ]);
|
|
|
|
|
- $user->money = bcsub($user->money, $order->amount, 2);
|
|
|
|
|
- $user->save();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 获取用户余额
|
|
|
|
|
+ $walletInfo = Wallet::where(['member_id' => $order->user_id])->first();
|
|
|
|
|
+ if (!$walletInfo) continue;
|
|
|
|
|
+
|
|
|
|
|
+ $before = $walletInfo->available_balance;
|
|
|
|
|
+ $after = bcsub($walletInfo->available_balance, $order->amount, 2);
|
|
|
|
|
+ $walletInfo->available_balance = $after;
|
|
|
|
|
+ $walletInfo->save();
|
|
|
|
|
+
|
|
|
|
|
+ FundsRecord::addData([
|
|
|
|
|
+ 'change_type' => '退款',
|
|
|
|
|
+ 'amount' => $order->amount,
|
|
|
|
|
+ 'before_balance' => $before,
|
|
|
|
|
+ 'after_balance' => $after,
|
|
|
|
|
+ 'member_id' => $order->user_id,
|
|
|
|
|
+ 'related_id' => $order->id,
|
|
|
|
|
+ 'remark' => '体彩订单退款',
|
|
|
|
|
+ ]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
DB::commit();
|
|
DB::commit();
|
|
@@ -62,89 +61,6 @@ class Order extends Controller
|
|
|
return $this->success();
|
|
return $this->success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @api {post} /order/refund 同意退款
|
|
|
|
|
- * @apiGroup 订单管理
|
|
|
|
|
- */
|
|
|
|
|
- public function refund()
|
|
|
|
|
- {
|
|
|
|
|
- $errors = [];
|
|
|
|
|
- try {
|
|
|
|
|
- DB::beginTransaction();
|
|
|
|
|
- $params = request()->validate([
|
|
|
|
|
- 'order_id' => ['required', 'array', 'min:1'],
|
|
|
|
|
- 'safe_word' => ['required', 'string'],
|
|
|
|
|
- ]);
|
|
|
|
|
- $order_id = $params['order_id'];
|
|
|
|
|
- $safeWord = $params['safe_word'];
|
|
|
|
|
- $id = request()->user()->id;
|
|
|
|
|
- $admin = Admin::where('id', $id)->first();
|
|
|
|
|
- if (!password_verify($safeWord, $admin->payment_password)) throw new Exception('资金密码错误');
|
|
|
|
|
- $order = OrderModel::where('id', $order_id)->first();
|
|
|
|
|
- if (!$order) throw new Exception('订单不存在');
|
|
|
|
|
- if ($order->return_status != 1 || $order->pay_status != 1) {
|
|
|
|
|
- $errors = ['id' => $order_id];
|
|
|
|
|
- throw new Exception("该订单状态无法操作");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $order->status = 3;
|
|
|
|
|
- $order->return_status = 2;
|
|
|
|
|
- $order->return_operation_time = time();
|
|
|
|
|
- $order->save();
|
|
|
|
|
-
|
|
|
|
|
- $user = User::where('user_id', $order->user_id)->first();
|
|
|
|
|
- $balanceAfter = bcadd($user->money, $order->amount, 2);
|
|
|
|
|
- FundsRecord::addData([
|
|
|
|
|
- 'transaction_type' => '退款',
|
|
|
|
|
- 'amount' => $order->amount,
|
|
|
|
|
- 'before_balance' => $user->money,
|
|
|
|
|
- 'after_balance' => bcsub($user->money, $order->amount, 2),
|
|
|
|
|
- 'member_id' => $user->user_id,
|
|
|
|
|
- ]);
|
|
|
|
|
- $user->money = $balanceAfter;
|
|
|
|
|
- $user->save();
|
|
|
|
|
-
|
|
|
|
|
- DB::commit();
|
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage(), $errors);
|
|
|
|
|
- }
|
|
|
|
|
- return $this->success();
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 驳回退款申请
|
|
|
|
|
- * @apiGroup 订单管理
|
|
|
|
|
- */
|
|
|
|
|
- public function rejection()
|
|
|
|
|
- {
|
|
|
|
|
- $errors = [];
|
|
|
|
|
- DB::beginTransaction();
|
|
|
|
|
- try {
|
|
|
|
|
- $params = request()->validate([
|
|
|
|
|
- 'order_id' => ['required', 'array', 'min:1'],
|
|
|
|
|
- 'failure_msg' => ['nullable', 'string', 'max:200'],
|
|
|
|
|
- ]);
|
|
|
|
|
- if (empty($params['failure_msg'])) $params['failure_msg'] = '';
|
|
|
|
|
-
|
|
|
|
|
- $order = OrderModel::where('id', $params['order_id'])->first();
|
|
|
|
|
- if (!$order) throw new Exception('订单不存在');
|
|
|
|
|
- if ($order->status != 1 || $order->return_status != 1) {
|
|
|
|
|
- $errors = ['id' => $params['order_id']];
|
|
|
|
|
- throw new Exception("该订单状态无法操作");
|
|
|
|
|
- }
|
|
|
|
|
- $order->return_operation_time = time();
|
|
|
|
|
- $order->failure_msg = $params['failure_msg'];
|
|
|
|
|
- $order->save();
|
|
|
|
|
- DB::commit();
|
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
|
- DB::rollBack();
|
|
|
|
|
- return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage(), $errors);
|
|
|
|
|
- }
|
|
|
|
|
- return $this->success();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 订单列表
|
|
* 订单列表
|
|
|
*/
|
|
*/
|