| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Services\PaymentOrderService;
- use Exception;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Validation\ValidationException;
- class PaymentOrder extends Controller
- {
- public function audit()
- {
- DB::beginTransaction();
- try {
- $validate = [
- // 'id' => ['required', 'integer', 'min:1'],
- 'ids' => ['required', 'array', 'min:1','max:20'],
- 'ids.*' => ['required', 'integer', 'min:1'],
- 'status' => ['required', 'integer', 'in:1,3'],
- ];
- $status = request()->input('status', null);
- if ($status != 1) {
- $validate['remark'] = ['required', 'string', 'min:1', 'max:120'];
- }
- $params = request()->validate($validate);
- $remark = request()->input('remark', '');
- $count = 0;
- if ($params['status'] == 1) {
- $ret = PaymentOrderService::createPayout($params['id']);
- if ($ret['code'] === 0)$count++;
- if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
- } else {
- $ret = PaymentOrderService::withdrawalFailed($params['id'], $remark);
- if ($ret['code'] === 0)$count++;
- if ($ret['code'] !== 0) throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR);
- }
- if ($count < 1) {
- throw new Exception('操作失败', HttpStatus::CUSTOM_ERROR);
- }
- 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();
- }
- /**
- * @apiParam {int} [page]
- * @apiParam {int} [limit]
- * @apiParam {int=0,1,2} type 类型 0全部 1=代收,2=代付
- * @apiParam {String} order_no 订单号
- * @apiPaaram {String} member_id 会员ID
- * @apiParam {int=0,1,2,3} [status] 状态:0待处理 1处理中 2成功 3失败
- *
- */
- public function index()
- {
- try {
- $params = request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1'],
- 'type' => ['required', 'integer', 'in:0,1,2'],
- 'order_no' => ['nullable', 'string'],
- 'status' => ['nullable', 'integer', 'in:0,1,2,3'],
- ]);
- $result = PaymentOrderService::paginate($params);
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
- }
- return $this->success($result);
- }
- /**
- * @description: 查询订单的支付情况
- * @return {*}
- */
- public function check()
- {
- $id = request()->input('id');
- if (empty($id)) {
- return $this->error(HttpStatus::CUSTOM_ERROR, '参数错误');
- }
- try {
- $result = PaymentOrderService::singlePayOrder($id);
- $this->success([], $result['msg'] ?? '操作成功');
- } catch (Exception $e) {
- return $this->error(intval($e->getCode()));
- }
- return $this->success([], $result['msg'] ?? '操作成功');
- }
- }
|