根据公安部车检计算器?中国政府网服务频道 车检计算器查查您的爱车是否属于6年内免检车辆http://www.gov.cn/fuwu/bmfw/gabcjjsq/index.html
<?php
namespace app\api\controller;
use think\Controller;
use app\api\validate\ExamInfoValidate;
/**
* Class ExamInfo
* @package app\api\controller
*/
class ExamInfo extends Controller
{
public function cal_lastday($ccdjrq, $year)
{
return date('Y-m-t', strtotime("+$year year", strtotime($ccdjrq)));
}
public function cal_jyqz($ccdjrq, $sysDate, $interval, $sfmj)
{
$ccdjrq_y = date('Y', strtotime($ccdjrq));
$ccdjrq_m = date('m', strtotime($ccdjrq));
$sysDate_y = date('Y', strtotime($sysDate));
$sysDate_m = date('m', strtotime($sysDate));
if ($sysDate_y == $ccdjrq_y && $sysDate_m == $ccdjrq_m) {
$yy = $interval / 12;
$y1 = $sysDate_y + $yy . '-' . $sysDate_m . '-01';
$last = date('Y-m-t', strtotime($y1));
} else {
$m = (12 * ($sysDate_y - $ccdjrq_y + 2) + $ccdjrq_m - $sysDate_m) % $interval;
$y1 = $sysDate_y . '-' . $sysDate_m . '-01';
$last = date('Y-m-t', strtotime("+$m month", strtotime($y1)));
}
$dates = date('Y', strtotime($last)) . "年" . date('m', strtotime($last)) . "月" . date('d', strtotime($last)) . "日";
$y2014 = '2014-09-01';
if ($last >= $y2014 && $sfmj == "1") {
return "您的爱车属于6年内免检车辆。 本轮检验周期内,请于 $dates 前携带相关材料到车管所为爱车领取检验标志。";
} else {
return "您的爱车不属于6年内免检车辆。本轮检验周期内,请于 $dates 前至检验机构参加安全技术检验。";
}
}
public function calculator()
{
$param = $this->request->only(['car_type', 'car_date', 'illegal' => 0], 'get');
$validate = new ExamInfoValidate();
if (!$validate->scene('jsq')->check($param)) {
return render_error($validate->getError());
}
$cllx = $param['car_type']; // 车辆类型
$ccdjrq = $param['car_date']; // 车辆登记日期
$sgqk = $param['illegal']; // 事故情况 违法 1是0否
$sysDate = $day = $lastday = date('Y-m-d');
if ($ccdjrq > $sysDate) {
return render_error('注册日期超过当前时间,请重新选择!');
}
if ($cllx == "1") {
//取5年内的最后一天比较
$lastday = $this->cal_lastday($ccdjrq, 5);
if ($sysDate <= $lastday) {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 12, 0);
return render_success($res);
}
//每6个月检验一次
$res = $this->cal_jyqz($ccdjrq, $sysDate, 6, 0);
return render_success($res);
}
if ($cllx == "2") {
//取10年内的最后一天比较
$lastday = $this->cal_lastday($ccdjrq, 10);
if ($sysDate <= $lastday) {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 12, 0);
return render_success($res);
}
//每6个月检验一次
$res = $this->cal_jyqz($ccdjrq, $sysDate, 6, 0);
return render_success($res);
}
if ($cllx == "3") {
//取6年内的最后一天比较
$lastday = $this->cal_lastday($ccdjrq, 4);
if ($sysDate <= $lastday) {
$y2010 = '2010-09-01';
if ($sgqk == "0" && $ccdjrq >= $y2010) {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 24, 1);
} else {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 24, 0);
}
return render_success($res);
}
//15年内
$lastday = $this->cal_lastday($ccdjrq, 15);
if ($sysDate <= $lastday) {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 12, 0);
return render_success($res);
}
//每6个月检验一次
$res = $this->cal_jyqz($ccdjrq, $sysDate, 6, 0);
return render_success($res);
}
if ($cllx == "4") {
//取6年内的最后一天比较
$lastday = $this->cal_lastday($ccdjrq, 4);
if ($sysDate <= $lastday) {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 24, 0);
return render_success($res);
}
$res = $this->cal_jyqz($ccdjrq, $sysDate, 12, 0);
return render_success($res);
}
if ($cllx == "5") {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 12, 0);
return render_success($res);
}
if ($cllx == "6") {
//取6年内的最后一天比较
$lastday = $this->cal_lastday($ccdjrq, 6);
if ($sysDate <= $lastday) {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 24, 0);
return render_success($res);
}
//15年内
$lastday = $this->cal_lastday($ccdjrq, 15);
if ($sysDate <= $lastday) {
$res = $this->cal_jyqz($ccdjrq, $sysDate, 12, 0);
return render_success($res);
}
//每6个月检验一次
$res = $this->cal_jyqz($ccdjrq, $sysDate, 6, 0);
return render_success($res);
}
return render_error('未知');
}
}
<?php
namespace app\api\validate;
use think\Validate;
class ExamInfoValidate extends Validate
{
protected $rule = [
'car_type' => 'require',
'car_date' => 'require',
];
protected $message = [
'car_type.require' => '车辆类型必须',
'car_date.require' => '注册日期必须',
];
protected $scene = [
'jsq' => ['car_type', 'car_date'],
];
}
// 在common.php 下的方法
function render_success($data = [], $msg = 'success', $code = 1)
{
return json(['code' => $code, 'msg' => $msg, 'data' => $data]);
}
function render_error($msg = 'error', $data = [], $code = 0)
{
return json(['code' => $code, 'msg' => $msg, 'data' => $data]);
}
调用 http://web.chejian.com/api/exam_info/calculator?car_type=1&car_date=2011-01-01&illegal
{
"code": 1,
"msg": "success",
"data": "您的爱车不属于6年内免检车辆。本轮检验周期内,请于 2022年01月31日 前至检验机构参加安全技术检验。"
}
|