Browse Source

增加核销二维码

develop
李可松 5 years ago
parent
commit
dfeb6a3180
  1. 38
      app/Http/Controllers/Api/VerificationController.php

38
app/Http/Controllers/Api/VerificationController.php

@ -2,9 +2,12 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Agent;
use App\Models\Order;
use App\Models\User;
use App\Common\OrderStatus;
use EasyWeChat\Factory;
use Illuminate\Support\Facades\Storage;
class VerificationController extends Controller
{
@ -15,7 +18,7 @@ class VerificationController extends Controller
$code_arr = explode('-', $input_verify_code);
if (count($code_arr) != 2) {
$this->error('参数错误');
return $this->error('参数错误');
}
list($id, $verify_code) = $code_arr;
@ -37,4 +40,37 @@ class VerificationController extends Controller
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::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='.$verify_code);
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]);
}
}
Loading…
Cancel
Save