|
@@ -9,16 +9,98 @@ use App\Services\PaymentOrderService;
|
|
|
use Exception;
|
|
use Exception;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Validation\ValidationException;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
|
+use App\Models\PaymentOrder as PaymentOrderModel;
|
|
|
|
|
+use App\Models\Wallet;
|
|
|
|
|
+use App\Services\BalanceLogService;
|
|
|
|
|
|
|
|
class PaymentOrder extends Controller
|
|
class PaymentOrder extends Controller
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
|
|
+ //人工充值,配置充值信息
|
|
|
|
|
+ public function setPayData()
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $params = request()->validate([
|
|
|
|
|
+ 'ids' => ['required', 'array', 'min:1'],
|
|
|
|
|
+ 'ids.*' => ['required', 'integer', 'min:1'],
|
|
|
|
|
+ 'payment_type' => ['required', 'integer'],
|
|
|
|
|
+ 'pay_data' => ['required', 'string'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $count = PaymentOrderModel::whereIn('id', $params['ids'])->where('payment_type', $params['payment_type'])->where('status', 0)->count();
|
|
|
|
|
+ if ($count != count($params['ids'])) throw new Exception('数据匹配异常,请刷新页面重试!', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+
|
|
|
|
|
+ PaymentOrderModel::whereIn('id', $params['ids'])->where('payment_type', $params['payment_type'])->where('status', 0)->update(['pay_data' => $params['pay_data']]);
|
|
|
|
|
+
|
|
|
|
|
+ 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(HttpStatus::CUSTOM_ERROR, $e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return $this->success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //人工充值审核
|
|
|
|
|
+ public function manualAudit()
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $params = request()->validate([
|
|
|
|
|
+ 'id' => ['required', 'integer'],
|
|
|
|
|
+ 'status' => ['required', 'integer', 'in:2,3'],
|
|
|
|
|
+ 'remark' => ['nullable', 'string'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $remark = $params['remark'] ?? '';
|
|
|
|
|
+ $info = PaymentOrderModel::find($params['id']);
|
|
|
|
|
+ if (!$info) throw new Exception('数据不存在', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ if ($info->status != 1) throw new Exception('数据已处理', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ if ($info->payment_type == 0) throw new Exception('当前订单非人工充值,无法操作', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ if ($params['status'] == 3) {
|
|
|
|
|
+ if (empty($remark)) {
|
|
|
|
|
+ throw new Exception('请填写原因', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ $info->status = $params['status'];
|
|
|
|
|
+ $info->remark = $remark;
|
|
|
|
|
+ $info->save();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //充值成功
|
|
|
|
|
+ $info->status = $params['status'];
|
|
|
|
|
+ $info->remark = $remark;
|
|
|
|
|
+ $info->state = 1;
|
|
|
|
|
+ $info->is_send = 0;//标记发送通知
|
|
|
|
|
+ $info->save();
|
|
|
|
|
+
|
|
|
|
|
+ $memberId = $info->member_id;
|
|
|
|
|
+ $amount = $info->amount;
|
|
|
|
|
+ $changeType = '人工充值';
|
|
|
|
|
+ $wallet = Wallet::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(HttpStatus::CUSTOM_ERROR, $e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return $this->success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function audit()
|
|
public function audit()
|
|
|
{
|
|
{
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
try {
|
|
try {
|
|
|
$validate = [
|
|
$validate = [
|
|
|
-// 'id' => ['required', 'integer', 'min:1'],
|
|
|
|
|
'ids' => ['required', 'array', 'min:1', 'max:20'],
|
|
'ids' => ['required', 'array', 'min:1', 'max:20'],
|
|
|
'ids.*' => ['required', 'integer', 'min:1'],
|
|
'ids.*' => ['required', 'integer', 'min:1'],
|
|
|
'status' => ['required', 'integer', 'in:1,3'],
|
|
'status' => ['required', 'integer', 'in:1,3'],
|
|
@@ -73,6 +155,8 @@ class PaymentOrder extends Controller
|
|
|
'status' => ['nullable', 'integer', 'in:0,1,2,3'],
|
|
'status' => ['nullable', 'integer', 'in:0,1,2,3'],
|
|
|
'member_id' => ['nullable', 'integer'],
|
|
'member_id' => ['nullable', 'integer'],
|
|
|
'first_name' => ['nullable'],
|
|
'first_name' => ['nullable'],
|
|
|
|
|
+ 'payment_type' => ['nullable', 'integer'],
|
|
|
|
|
+ 'channel' => ['nullable', 'string'],
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
$params['type'] = 1;
|
|
$params['type'] = 1;
|