海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Order;
  5. use App\Models\User;
  6. use App\Common\OrderStatus;
  7. class VerificationController extends Controller
  8. {
  9. //核销订单
  10. public function verify()
  11. {
  12. $input_verify_code = request()->input('verify_code'); //订单ID
  13. $code_arr = explode('-', $input_verify_code);
  14. if (count($code_arr) != 2) {
  15. $this->error('参数错误');
  16. }
  17. list($id, $verify_code) = $code_arr;
  18. $order = Order::with('agentProduct:id,verifier')
  19. ->where(['agent_id' => $this->agent_id, 'verify_code' => $verify_code])
  20. ->whereIn('status', [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID])
  21. ->find($id);
  22. if (!$order) {
  23. return $this->error('订单不存在或订单状态不允许核销');
  24. }
  25. $user = User::firstWhere(['id' => $this->user_id, 'status' => 1]);
  26. if (!$user || $user->id != $order->agentProduct->verifier) {
  27. return $this->error('对不起,你没有核销权限,请联系管理员');
  28. }
  29. $order->status = OrderStatus::SUCCESS;
  30. $order->save();
  31. return $this->success();
  32. }
  33. }