'无', 1 => 'I级', 2 => 'II级', 3 => 'III级', 4 => '特级', ]; public static $gender = [ 0 => '男', 1 => '女', ]; protected $append = [ 'level_name', 'gender_name', ]; use ModelTrait; public function getLevelNameAttr($value, $data) { return self::$level[$data['level'] ?: 0]; } public function getAddTimeAttr($value) { return date('Y-m-d H:i:s', $value); } public function getGenderNameAttr($value, $data) { return self::$gender[$data['gender'] ?: 0]; } public static function getList($where) { if (isset($where['status']) && $where['status'] != '') { $model = self::where('status', $where['status']); } else { $model = new self(); } if (isset($where['uid']) && $where['uid'] != '') { $model = $model->where('uid', $where['uid']); } $count = $model->count(); $data = $model->page((int)$where['page'], (int)$where['limit'])->order('id desc')->select(); return compact('count', 'data'); } 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, $data) { $info = self::get($id); // if ($info['status'] != 0) return self::setErrorInfo('记录已处理'); if (!$info['code'] && $data['status'] == 1) { $date = date('Y-m-d'); $code = self::createNewCode($data); $data['date'] = $date; $data['code'] = $code; if (!$info['qrcode']) { $name = 'cert_' . $info['uid'] . '_' . $code . '.jpg'; $imageInfo = SystemAttachment::getInfo($name, 'name'); if (!$imageInfo) { $codeUrl = UtilService::setHttpType(sys_config('site_url') . '/index/pages/certificate/showCertificate?id=' . $id, 1);//二维码链接 $imageInfo = UtilService::getQRCodePath($codeUrl, $name); if (!$imageInfo) return self::setErrorInfo('二维码生成失败'); SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2); $url = $imageInfo['dir']; } else $url = $imageInfo['att_dir']; $data['qrcode'] = $url; if ($imageInfo['image_type'] == 1) $data['qrcode'] = sys_config('site_url') . $url; } $res = self::where('id', $id)->update($data); } else { $res = self::where('id', $id)->update($data); } return $res; } public static function createNewCode($info) { $str = CertType::where('cert_name', $info['job'])->value('cert_code'); if (!$str) $str = 'UK'; $str .= ($info['level'] == 4 ? '特' : ('0' . $info['level'])); $str .= '-021-' . substr($info['idcard'], strlen($info['idcard']) - 4, 4); $str .= '-' . str_pad((self::where('status', 1)->count() + 1), 4, 0, STR_PAD_LEFT); // do { // $str = date('ymd') . strtoupper(substr(md5($id . rand(100000, 999999)), 3, 8)); // } while (self::be(['code' => $str])); return $str; } }