Kirin 2 rokov pred
rodič
commit
8e3b64934e

+ 32 - 0
app/api/controller/user/UserController.php

@@ -6,6 +6,7 @@ use app\http\validates\user\AddressValidate;
 use app\models\member\MemberCheck;
 use app\models\member\MemberGrade;
 use app\models\system\SystemCity;
+use app\models\user\Cert;
 use app\models\user\UserTicket;
 use app\models\user\UserVisit;
 use crmeb\repositories\OrderRepository;
@@ -735,4 +736,35 @@ class UserController
         else
             return app('json')->fail('核销失败');
     }
+
+
+    public function addCert(Request $request)
+    {
+        list($name, $gender, $idcard, $job, $photo) = UtilService::postMore([
+            ['name', '', '', '', 'not_empty', '请输入姓名'],
+            ['gender', '', '', '', 'not_empty', '请选择性别'],
+            ['idcard', '', '', '', 'not_empty', '请输入身份证号码'],
+            ['job', '', '', '', 'not_empty', '请输入职业'],
+            ['photo', '', '', '', 'not_empty', '请上传照片'],
+        ], $request, true);
+        $res = Cert::add_cert($request->uid(), $name, $gender, $idcard, $job, $photo);
+        if ($res) {
+            return app('json')->success('申请成功');
+        } else {
+            return app('json')->fail(Cert::getErrorInfo());
+        }
+    }
+
+
+    public function getCert(Request $request, $id = 0)
+    {
+        list($name) = UtilService::getMore([
+            ['name', ''],
+        ], $request, true);
+        if ($id) {
+            return app('json')->success('ok', ['info' => Cert::get($id)]);
+        } else {
+            return app('json')->success('ok', ['info' => Cert::search($name)]);
+        }
+    }
 }

+ 67 - 0
app/models/user/Cert.php

@@ -0,0 +1,67 @@
+<?php
+/**
+ * @Created by PhpStorm
+ * @author: Kirin
+ * @day: 2023/8/23
+ * @time: 17:04
+ */
+
+namespace app\models\user;
+
+
+use crmeb\basic\BaseModel;
+use crmeb\traits\ModelTrait;
+
+class Cert extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'cert';
+
+
+    use ModelTrait;
+
+    public static function add_cert($uid, $name, $gender, $idcard, $job, $photo, $level = '')
+    {
+        if (self::be(['idcard' => $idcard, 'status' => [0, 1]])) {
+            return self::setErrorInfo('已有身份证号码相同的记录存在');
+        }
+        $add_time = time();
+        return self::create(compact('uid', 'name', 'gender', 'idcard', 'job', 'photo', 'level', 'add_time'));
+    }
+
+    public static function search($name)
+    {
+        return self::where('name|iscard|code', 'like', "%$name%")->where('status', 1)->find();
+    }
+
+    public static function check_cert($id, $status, $level)
+    {
+        $info = self::get($id);
+        if ($info['status'] != 0) return self::setErrorInfo('记录已处理');
+        if ($status == 1) {
+            $date = date('Y-m-d');
+            $code = self::createNewCode($id);
+            $res = self::where('id', $id)->update(['status' => 1, 'level' => $level]);
+        } else {
+            $res = self::where('id', $id)->update(['status' => 0]);
+        }
+        return $res;
+    }
+
+    public static function createNewCode($id)
+    {
+        do {
+            $str = date('ymd') . strtoupper(substr(md5($id . rand(100000, 999999)), 3, 8));
+        } while (self::be(['code' => $str]));
+        return $str;
+    }
+}

+ 69 - 4
crmeb/services/UtilService.php

@@ -15,6 +15,71 @@ use crmeb\services\upload\Upload;
 class UtilService
 {
 
+    public static function filtrate($string)
+    {
+        $ra = array(
+            '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
+            '/script/',
+            '/javascript/',
+            '/vbscript/',
+            '/expression/',
+            '/applet/',
+            '/meta/',
+            '/xml/',
+            '/blink/',
+            '/link/',
+            '/style/',
+            '/embed/',
+            '/object/',
+            '/frame/',
+            '/layer/',
+            '/title/',
+            '/bgsound/',
+            '/base/',
+            '/onload/',
+            '/onunload/',
+            '/onchange/',
+            '/onsubmit/',
+            '/onreset/',
+            '/onselect/',
+            '/onblur/',
+            '/onfocus/',
+            '/onabort/',
+            '/onkeydown/',
+            '/onkeypress/',
+            '/onkeyup/',
+            '/onclick/',
+            '/ondblclick/',
+            '/onmousedown/',
+            '/onmousemove/',
+            '/onmouseout/',
+            '/onmouseover/',
+            '/onmouseup/',
+            '/onunload/',
+            "/<(\\/?)(script|i?frame|style|html|body|title|link|meta|object|\\?|\\%)([^>]*?)>/isU",
+            "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",
+        );
+        $string = preg_replace($ra, '', $string);     //删除非打印字符,粗暴式过滤xss可疑字符串
+        $string = str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $string);
+        if (!get_magic_quotes_gpc())             //不对magic_quotes_gpc转义过的字符使用    addslashes(),避免双重转义。
+        {
+            $string = addslashes($string);           //给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
+        }
+        //去除 HTML 和 PHP 标记并转换为 HTML 实体
+        return htmlentities(strip_tags($string));
+    }
+    public static function sweep($array)
+    {
+        if (is_array($array)) {
+            foreach ($array as $k => $v) {
+                $array[$k] = self::sweep($v);
+            }
+        } else {
+            $array = self::filtrate($array);
+        }
+        return $array;
+    }
+
     /**
      * 获取POST请求的数据
      * @param $params
@@ -29,7 +94,7 @@ class UtilService
         $i = 0;
         foreach ($params as $param) {
             if (!is_array($param)) {
-                $p[$suffix == true ? $i++ : $param] = $request->param($param);
+                $p[$suffix == true ? $i++ : $param] = self::sweep($request->param($param));
             } else {
                 if (!isset($param[1])) $param[1] = null;
                 if (!isset($param[2])) $param[2] = '';
@@ -43,7 +108,7 @@ class UtilService
                     $name = is_array($param[1]) ? $param[0] . '/a' : $param[0];
                     $keyName = $param[0];
                 }
-                $p[$suffix == true ? $i++ : ($param[3] ? $param[3] : $keyName)] = $request->param($name, $param[1], $param[2]);
+                $p[$suffix == true ? $i++ : ($param[3] ? $param[3] : $keyName)] = self::sweep($request->param($name, $param[1], $param[2]));
                 if (not_empty_check($param[4])) {
                     if (!is_array($param[4])) {
                         if (is_string($param[4]) && !function_exists($param[4])) {
@@ -82,7 +147,7 @@ class UtilService
         $i = 0;
         foreach ($params as $param) {
             if (!is_array($param)) {
-                $p[$suffix == true ? $i++ : $param] = $request->param($param);
+                $p[$suffix == true ? $i++ : $param] = self::sweep($request->param($param));
             } else {
                 if (!isset($param[1])) $param[1] = null;
                 if (!isset($param[2])) $param[2] = '';
@@ -96,7 +161,7 @@ class UtilService
                     $name = is_array($param[1]) ? $param[0] . '/a' : $param[0];
                     $keyName = $param[0];
                 }
-                $p[$suffix == true ? $i++ : ($param[3] ? $param[3] : $keyName)] = $request->param($name, $param[1], $param[2]);
+                $p[$suffix == true ? $i++ : ($param[3] ? $param[3] : $keyName)] = self::sweep($request->param($name, $param[1], $param[2]));
                 if (not_empty_check($param[4])) {
                     if (!is_array($param[4])) {
                         if (is_string($param[4]) && !function_exists($param[4])) {

+ 2 - 0
route/api/route.php

@@ -50,6 +50,7 @@ Route::group(function () {
 
 //会员授权接口
 Route::group(function () {
+    Route::post('cert','user.UserController/addCert')->name('addCert');//首页
     Route::post('member/apply/:type', 'user.UserController/applyMemberCheck')->name('applyMemberCheck');//首页
     Route::get('vote/:id', 'vote.VoteController/detail')->name('vote');//投票详情
     Route::get('vote/join/:id', 'vote.VoteController/join_list')->name('vote');//投票参加人
@@ -172,6 +173,7 @@ Route::group(function () {
 //未授权接口
 Route::group(function () {
     //公共类
+    Route::get('cert/:id','user.UserController/getCert')->name('getCert');//首页
     Route::get('index', 'PublicController/index')->name('index');//首页
     Route::get('member/config/:type', 'user.UserController/getMemberConfig')->name('getMemberConfig');//首页
     Route::get('member/get/:type', 'user.UserController/getMember')->name('getMember');//首页