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.
84 lines
2.6 KiB
84 lines
2.6 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Agent;
|
|
use App\Models\Order;
|
|
use App\Models\Product;
|
|
use App\Models\User;
|
|
use App\Common\OrderStatus;
|
|
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')
|
|
->where(['agent_id' => $this->agent_id, 'verify_code' => $verify_code])
|
|
->whereIn('status', [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID])
|
|
->find($id);
|
|
if (!$order) {
|
|
return $this->error('订单不存在或订单状态不允许核销');
|
|
}
|
|
|
|
$user = User::firstWhere(['id' => $this->user_id, 'status' => 1]);
|
|
if (!$user || $user->is_verify !=1) {
|
|
return $this->error('对不起,你没有核销权限,请联系管理员');
|
|
}
|
|
|
|
$checkMobile = Product::query()->whereIn('id',explode(',',$order->product_ids))->where('verify_mobile',$user->mobile)->doesntExist();
|
|
|
|
if ($checkMobile) {
|
|
return $this->error('对不起,你没有核销权限,请联系管理员');
|
|
}
|
|
|
|
$order->status = OrderStatus::SUCCESS;
|
|
$order->save();
|
|
|
|
return $this->success();
|
|
}
|
|
|
|
//生成核销二维码
|
|
public function qrcode()
|
|
{
|
|
$id = request()->input('id'); //订单ID
|
|
|
|
$order = Order::where(['agent_id' => $this->agent_id, 'user_id' => $this->user_id])->find($id);
|
|
if (!$order) {
|
|
return $this->error('订单不存在!');
|
|
} else if (!in_array($order->status, [OrderStatus::PAID, OrderStatus::PAID_RETAINAGE, OrderStatus::OFFLINE_PAID, OrderStatus::REFUSED_REFUND])) {
|
|
return $this->error('当前订单状态不允许核销!');
|
|
} else if (!$order->verify_code) {
|
|
$order->verify_code = uniqid();
|
|
$order->save();
|
|
}
|
|
|
|
$verify_code = $order->id . '-' . $order->verify_code;
|
|
|
|
$agent = Agent::find($this->agent_id);
|
|
$config = [
|
|
'app_id' => $agent->appid,
|
|
'secret' => $agent->appsecret,
|
|
];
|
|
$app = Factory::miniProgram($config);
|
|
|
|
$response = $app->app_code->getUnlimit($verify_code, ['path' => 'pages/verification/index']);
|
|
|
|
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
|
$filename = $response->saveAs(storage_path('app/public/verify_code'), $verify_code);
|
|
}
|
|
|
|
$prefix = Storage::disk('public')->url('verify_code/');
|
|
return $this->success(['qrcode' => $prefix . $filename]);
|
|
}
|
|
}
|