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
59 lines
2.1 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Agent;
|
|
use App\Models\Order;
|
|
use App\Models\Supplier;
|
|
use App\Models\Product;
|
|
use App\Models\OrderProductItem;
|
|
use App\Models\User;
|
|
use App\Common\OrderStatus;
|
|
use App\Service\SmsService;
|
|
use App\Traits\SmsTraits;
|
|
use EasyWeChat\Factory;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class VerificationController extends Controller
|
|
{
|
|
//核销订单
|
|
public function verify()
|
|
{
|
|
$input_verify_code = request()->input('verify_code'); //订单ID
|
|
|
|
$code_arr = explode('-', $input_verify_code);
|
|
if (count($code_arr) != 2) {
|
|
return $this->error('参数错误');
|
|
}
|
|
list($id, $verify_code) = $code_arr;
|
|
$order = Order::with(['agentProduct:id,verifier','user','agent'])
|
|
->where(['verify_code' => $verify_code])
|
|
->whereIn('status', [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID])
|
|
->find($id);
|
|
if (!$order) {
|
|
return $this->error('订单不存在或订单状态不允许核销');
|
|
}
|
|
|
|
$mobile = User::where('id', $this->user_id)->value('mobile');
|
|
|
|
$checkMobile = Product::query()->whereIn('id', explode(',', $order->product_ids))->where('verify_mobile', $mobile)->doesntExist();
|
|
if ($checkMobile) {
|
|
return $this->error('对不起,你没有核销权限,请联系管理员');
|
|
}
|
|
|
|
$order->status = OrderStatus::SUCCESS;
|
|
if ($order->save()) {
|
|
if(env('SMS_SWITCH','') == true) {
|
|
if (!empty($order->user->mobile)) {
|
|
(new SmsService)->send('verify', [$order->order_no,SmsTraits::$systeaNameText['user']], [$order->user->mobile]);//用户
|
|
}
|
|
$supplierIds = OrderProductItem::query()->with('supplier')->where('order_id',$order->id)->distinct()->pluck('supplier_id');
|
|
$phone = Supplier::query()->whereIn('id',$supplierIds)->pluck('contact_phone')->toArray();
|
|
(new SmsService)->send('verify', [$order->order_no,SmsTraits::$systeaNameText['supplier']], $phone);//供应商
|
|
(new SmsService)->send('verify', [$order->order_no,SmsTraits::$systeaNameText['agent']], [$order->agent->contact_phone]);//代理商
|
|
}
|
|
}
|
|
|
|
return $this->success();
|
|
}
|
|
}
|