| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- /**
- * 会员服务
- */
- namespace app\weixin\service;
- use app\weixin\model\AccountLog;
- use app\weixin\model\UserProfile;
- use app\weixin\model\Member as MemberModel;
- use app\weixin\model\Wechat;
- use think\Db;
- class Member
- {
- /**
- * 会员信息认证审核
- * @param $userId 用户ID
- * @param $status 审核状态:2-成功,3-失败
- * @param string $scene 审核类型:idcard-身份证,education-学历,position-职业/工作
- * @param string $failRemark 审核失败原因
- * @return array|int
- */
- public static function checkAuth($userId, $status, $scene='idcard', $failRemark=''){
- try {
- // 验证认证信息是否存在
- $field = 'id,userid,idcard,idcard_check,education_check,position_check';
- $info = UserProfile::getInfo(['userid'=> $userId],$field);
- if(empty($info)){
- return 2122;
- }
- if(!in_array($status, [2,3])){
- return 2127;
- }
- //var_dump($info);
- // 审核处理
- $sceneNames = ['idcard'=>'身份证','education'=> '学历','position'=> '工作'];
- switch($scene){
- case 'idcard': // 身份认证审核
- // 验证状态
- $idcardCheck = isset($info['idcard_check'])? intval($info['idcard_check']) : 0;
- if($idcardCheck != 0 && $idcardCheck != 1 && $status == 2){
- return 2123;
- }
- $data = [
- 'idcard_check'=> $status,
- 'idcard_fail'=> $failRemark? trim($failRemark) : '',
- ];
- break;
- case 'education': // 学历认证审核
- // 验证状态
- $educationCheck = isset($info['education_check'])? intval($info['education_check']) : 0;
- if($educationCheck != 0 && $educationCheck != 1 && $status == 2){
- return 2123;
- }
- $data = [
- 'education_check'=> $status,
- 'education_fail'=> $failRemark? trim($failRemark) : '',
- ];
- break;
- case 'position': // 工作认证审核
- // 验证状态
- $positionCheck = isset($info['position_check'])? intval($info['position_check']) : 0;
- if($positionCheck != 0 && $positionCheck != 1 && $status == 2){
- return 2123;
- }
- $data = [
- 'position_check'=> $status,
- 'position_fail'=> $failRemark? trim($failRemark) : '',
- ];
- break;
- default:
- return 2126;
- break;
- }
- // 更新数据处理
- Db::startTrans();
- if(!UserProfile::saveData(['userid'=> $userId], $data)){
- Db::rollback();
- return 2125;
- }
- // 审核通过奖励处理
- $remark = '';
- $sceneName = isset($sceneNames[$scene])? $sceneNames[$scene] : '信息';
- $field = 'id,openid,user_nickname,real_name,redheart';
- $memberInfo = MemberModel::getInfo(['id'=> $userId], $field);
- if($status == 2){
- // 身份认证更新生日
- $idcard = isset($info['idcard'])? trim($info['idcard']) : '';
- if($scene == 'idcard' && $idcard){
- $birthday = substr($idcard, 6,8);
- $birthday = substr($birthday,0,4).'-'.substr($birthday,4,2).'-'.substr($birthday,6,2);
- $birthday = $birthday? strtotime($birthday) : 0;
- if($birthday){
- MemberModel::saveData(['id'=> $userId], ['birthday'=> $birthday]);
- }
- }
- $siteInfo = cmf_get_site_info();
- $awardNum = isset($siteInfo[$scene.'_award_redheart'])? intval($siteInfo[$scene.'_award_redheart']) : 0;
- if($awardNum){
- $redheart = isset($memberInfo['redheart'])? intval($memberInfo['redheart']) : 0;
- if(!MemberModel::saveData(['id'=> $userId], ['redheart'=> intval($redheart + $awardNum)])){
- Db::rollback();
- return 2125;
- }
- // 账户明细
- $remark = "{$sceneName}认证成功奖励{$awardNum}个爱心";
- $accountData = [
- 'type' => 4,
- 'account_type' => 1,
- 'change_type' => 1,
- 'user_id' => $userId,
- 'money' => $awardNum,
- 'balance' => $redheart,
- 'created_at' => date('Y-m-d H:i:s'),
- 'remark' => "{$sceneName}认证成功奖励{$awardNum}个爱心",
- ];
- AccountLog::insertGetId($accountData);
- }
- }
- Db::commit();
- // 推送审核信息
- $openid = isset($memberInfo['openid'])? $memberInfo['openid'] : '';
- if ($openid) {
- $realname = isset($memberInfo['real_name']) ? $memberInfo['real_name'] : '';
- $checkTime = date('Y.m.d H:i');
- $remark = $status==2? "感谢您的使用,点击进入公众号,遇见一段爱情!" : '请修改后重新提交';
- $params = [
- 'title' => $status==2? "恭喜!您的{$sceneName}认证已经通过审核!\n\n审核时间:\t{$checkTime}" : $failRemark."\n\n审核时间:\t{$checkTime}",
- 'remark' => $remark,
- 'type' => 'auth',
- 'keywords' => [
- /*'keyword1' => [
- 'value' => $realname,
- 'color' => '#173177',
- ],*/
- 'keyword1' => [
- 'value' => "{$sceneName}认证",
- 'color' => '#173177',
- ],
- 'keyword2' => [
- 'value' => $status==2? '审核通过' : '认证失败',
- 'color' => '#173177',
- ],
- ],
- 'url' => $status==2? url('/weixin/match/index', '', '', true) : url('/weixin/auth/' . $scene, '', '', true),
- ];
- PRedis::set('auths:message:u_'.$userId, ['result' => $memberInfo, 'params' => $params], 600);
- Wechat::sendTplMsg($openid, $params);
- }
- return ['id'=> $userId];
- } catch (\Exception $exception){
- // var_dump($exception);
- return 1015;
- }
- }
- }
|