playerCertificateModel = new PlayerCertificate(); } /** * 获取用户证书,如果不存在则创建 * @Author:Soar * @Time:2023/12/27 10:58 * @param array $param * @return object|int */ public function getCertificate(array $param) { $match_id = $param['match_id'] ? $param['match_id'] : 0; $player_id = $param['player_id'] ? $param['player_id'] : 0; $member_id = $param['member_id'] ? $param['member_id'] : 0; $club_id = $param['club_id'] ? $param['club_id'] : 0; $certificate_res = $this->playerCertificateModel ->where("match_id", $match_id) ->where("player_id", $player_id) ->where("member_id", $member_id) ->where("club_id", $club_id) ->find(); if (empty($certificate_res)) { $data['certificate_number'] = CertificateService::generateUUID(); $data['match_id'] = $match_id; $data['player_id'] = $player_id; $data['member_id'] = $member_id; $data['club_id'] = $club_id; return $this->addCertificate($data) ? $data['certificate_number'] : 0; } return $certificate_res->certificate_number ? $certificate_res->certificate_number : 0; } /** * 根据证书编号 获取详细信息 * @Author:Soar * @Time:2023/12/27 13:17 * @param string $certificate_number * @return array */ public function getCertificateToNumber(string $certificate_number) { $info = $this->playerCertificateModel ->where("certificate_number", $certificate_number) ->find()->toArray(); $archives = new Archives(); $match_info = $archives->where("id", $info['match_id'])->find(); if(!empty($info['player_id'])){ $players_info = Players::get($info['player_id'])->toArray(); $res['name'] = $players_info['real_name']; $res['match_title'] = @$match_info->title ? @$match_info->title : "赛事已被删除"; $res['certificate_number'] = $info['certificate_number']; }else{ $club = new Club(); $club_info = $club->where('id',$info['club_id'])->find(); $res['name'] = $club_info['name_short']; $res['match_title'] = @$match_info->title ? @$match_info->title : "赛事已被删除"; $res['certificate_number'] = $info['certificate_number']; } return $res; } /** * 添加证书 * @Author:Soar * @Time:2023/12/27 11:01 * @param array $param * @return int|string */ public function addCertificate(array $param) { $data['match_id'] = $param['match_id'] ? $param['match_id'] : 0; $data['player_id'] = $param['player_id'] ? $param['player_id'] : 0; $data['member_id'] = $param['member_id'] ? $param['member_id'] : 0; $data['club_id'] = $param['club_id'] ? $param['club_id'] : 0; $data['certificate_number'] = $param["certificate_number"] ? $param["certificate_number"] : CertificateService::generateUUID(); $data['look_num'] = 0; return $this->playerCertificateModel->insert($data); } /** * 验证证书编号 * @Author:Soar * @Time:2023/12/27 11:02 * @param string $certificate_number * @return bool */ public function checkCertificate($certificate_number) { $certificate_res = $this->playerCertificateModel ->where("certificate_number", $certificate_number) ->field("certificate_number") ->find(); if ($certificate_res ? true : false) { $this->updateCertificate($certificate_number); } return $certificate_res ? true : false; } /** * 更新验证次数 * @Author:Soar * @Time:2023/12/27 11:05 * @param string $certificate_number * @return bool */ public function updateCertificate(string $certificate_number) { $res = $this->playerCertificateModel ->where("certificate_number", $certificate_number) ->setInc("look_num"); return $res ? true : false; } /** * 生成UUID * @Author:Soar * @Time:2023/12/27 10:59 * @return string */ public static function generateUUID() { $chars = md5(uniqid(mt_rand(), true)); $uuid = substr ( $chars, 0, 8 ) . '-' . substr ( $chars, 8, 4 ) . '-' . substr ( $chars, 12, 4 ) . '-' . substr ( $chars, 16, 4 ) . '-' . substr ( $chars, 20, 12 ); return $uuid ; } }