sifangpay/app/Models/UploadQrcode.php

40 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class UploadQrcode extends BaseModel
{
//
// use SoftDeletes;
public function msg($data)
{
if (request()->ajax()) {
return response()->json($data);
}
return $this->htmlAlert($data);
}
public function htmlAlert($data)
{
echo '<script>alert("' . $data['msg'] . '");window.history.back()</script>';
}
public function findOneQrcode($request){
$time = time();
$token = $request->input('_token');
$old = $this::where([['session_id', '=', $token], ['expire_time', '>', intval($time)]])->orderBy('order_id', 'asc')->first();
if ($old) {
return $old;
}
$has_order = $this::where([['expire_time', '<', intval($time)]])->orderBy('order_id', 'asc')->first();
if ($has_order) {
$this::where('id', $has_order->id)->update(['session_id' => $token, 'expire_time' => $time + 1800, 'order_id' => $has_order->order_id + 1]);
} else {
return $this->msg(['error' => 1, 'msg' => '无可用二维码']);
}
return $has_order;
}
}