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

50 lines
1.4 KiB

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. $user = User::firstWhere(['id' => $this->user_id, 'status' => 1]);
  30. if (!$user || $user->is_verify !=1) {
  31. return $this->error('对不起,你没有核销权限,请联系管理员');
  32. }
  33. $checkMobile = Product::query()->whereIn('id',explode(',',$order->product_ids))->where('verify_mobile',$user->mobile)->doesntExist();
  34. if ($checkMobile) {
  35. return $this->error('对不起,你没有核销权限,请联系管理员');
  36. }
  37. $order->status = OrderStatus::SUCCESS;
  38. $order->save();
  39. return $this->success();
  40. }
  41. }