海南旅游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.

46 lines
1.3 KiB

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