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

59 lines
2.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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\Supplier;
  7. use App\Models\Product;
  8. use App\Models\OrderProductItem;
  9. use App\Models\User;
  10. use App\Common\OrderStatus;
  11. use App\Service\SmsService;
  12. use App\Traits\SmsTraits;
  13. use EasyWeChat\Factory;
  14. use Illuminate\Support\Facades\Storage;
  15. class VerificationController extends Controller
  16. {
  17. //核销订单
  18. public function verify()
  19. {
  20. $input_verify_code = request()->input('verify_code'); //订单ID
  21. $code_arr = explode('-', $input_verify_code);
  22. if (count($code_arr) != 2) {
  23. return $this->error('参数错误');
  24. }
  25. list($id, $verify_code) = $code_arr;
  26. $order = Order::with(['agentProduct:id,verifier','user','agent'])
  27. ->where(['verify_code' => $verify_code])
  28. ->whereIn('status', [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID])
  29. ->find($id);
  30. if (!$order) {
  31. return $this->error('订单不存在或订单状态不允许核销');
  32. }
  33. $mobile = User::where('id', $this->user_id)->value('mobile');
  34. $checkMobile = Product::query()->whereIn('id', explode(',', $order->product_ids))->where('verify_mobile', $mobile)->doesntExist();
  35. if ($checkMobile) {
  36. return $this->error('对不起,你没有核销权限,请联系管理员');
  37. }
  38. $order->status = OrderStatus::SUCCESS;
  39. if ($order->save()) {
  40. if(env('SMS_SWITCH','') == true) {
  41. if (!empty($order->user->mobile)) {
  42. (new SmsService)->send('verify', [$order->order_no,SmsTraits::$systeaNameText['user']], [$order->user->mobile]);//用户
  43. }
  44. $supplierIds = OrderProductItem::query()->with('supplier')->where('order_id',$order->id)->distinct()->pluck('supplier_id');
  45. $phone = Supplier::query()->whereIn('id',$supplierIds)->pluck('contact_phone')->toArray();
  46. (new SmsService)->send('verify', [$order->order_no,SmsTraits::$systeaNameText['supplier']], $phone);//供应商
  47. (new SmsService)->send('verify', [$order->order_no,SmsTraits::$systeaNameText['agent']], [$order->agent->contact_phone]);//代理商
  48. }
  49. }
  50. return $this->success();
  51. }
  52. }