1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\library\Ems;
- use app\common\library\Sms;
- use fast\Random;
- use think\Config;
- use think\Validate;
- use app\common\library\Token;
- use think\Db;
- use app\common\model\UserDeviceInfo;
- use onlogin\onlogin;
- use addons\epay\library\Service;
- use addons\epay\library\Wechat;
- use TencentCloud\Common\Credential;
- use TencentCloud\Common\Profile\ClientProfile;
- use TencentCloud\Common\Profile\HttpProfile;
- use TencentCloud\Common\Exception\TencentCloudSDKException;
- use TencentCloud\Faceid\V20180301\FaceidClient;
- use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
- use TencentCloud\Iai\V20200303\IaiClient;
- use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
- /**
- * 会员接口,登录,注册,修改资料等
- */
- class User extends Api
- {
- protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig', 'mobileregister', 'mobilecheck', 'wechatregiter', 'onregister', 'ioslogin', 'iosregiter'];
- protected $noNeedRight = '*';
- public function _initialize()
- {
- parent::_initialize();
- if (!Config::get('fastadmin.usercenter')) {
- $this->error(__('User center already closed'));
- }
- }
- /**
- * 会员中心
- */
- public function index()
- {
- $this->success('', ['welcome' => $this->auth->nickname]);
- }
- /**
- * 获取美颜授权
- *
- */
- public function getmeiyan()
- {
- $code = Db::name('Config')->where(['name'=>'meiyan'])->value('value');
- $rs['code'] = $code;
- $this->success('请求成功',$code);
- }
- /**
- * 会员登录
- *
- * @ApiMethod (POST)
- * @param string $account 账号
- * @param string $password 密码
- */
- public function login()
- {
- $account = input('account');
- $password = input('password');
- if (!$account || !$password) {
- $this->error(__('Invalid parameters'));
- }
- $ret = $this->auth->login($account, $password);
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 手机验证码登录
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function mobilelogin()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if ($user->status == -1) {
- $this->error('账户已注销');
- }
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- if ($user->frozentime > time()) {
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
- /*if($user->gender == 1 && $user->gh_id == 0){
- $this->firstopen_send($user->id);
- }*/
- } else {
- // $this->success('选择性别', ['code' => 5]);
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
- //亿米
- /*if(input('register_from','') == 'xiaomi'){
- $this->yimi_advert();
- }*/
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 手机验证码验证
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function mobilecheck()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- $this->success('验证通过');
- }
- /**
- * 手机验证码注册
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- * @param string $gender 性别:1=男,0=女
- */
- public function mobileregister()
- {
- $mobile = input('mobile');
- $captcha = input('captcha');
- $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
- $this->error(__('Captcha is incorrect'));
- }
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- $this->error('账号已经存在,请直接登录');
- if ($user->status == -1) {
- $this->error('账户已注销');
- }
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
- /*if($user->gender == 1 && $user->gh_id == 0){
- $this->firstopen_send($user->id);
- }*/
- } else {
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => $gender
- ];
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
- //亿米
- /*if(input('register_from','') == 'xiaomi'){
- $this->yimi_advert();
- }*/
- }
- if ($ret) {
- Sms::flush($mobile, 'mobilelogin');
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 注册会员
- *
- * @ApiMethod (POST)
- * @param string $username 用户名
- * @param string $password 密码
- * @param string $email 邮箱
- * @param string $mobile 手机号
- * @param string $code 验证码
- */
- /*public function register()
- {
- $username = $this->request->post('username');
- $password = $this->request->post('password');
- $email = $this->request->post('email');
- $mobile = $this->request->post('mobile');
- $code = $this->request->post('code');
- if (!$username || !$password) {
- $this->error(__('Invalid parameters'));
- }
- if ($email && !Validate::is($email, "email")) {
- $this->error(__('Email is incorrect'));
- }
- if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $ret = Sms::check($mobile, $code, 'register');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- $ret = $this->auth->register($username, $password, $email, $mobile, []);
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Sign up successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }*/
- //微信登录
- public function wechatlogin(){
- // $nickname = input('nickname','');
- // $avatar = input('avatar','');
- // $gender = input('gender',1);
- $wechat_openid = input('wechat_openid','');
- if (!$wechat_openid) {
- $this->error(__('Invalid parameters'));
- }
- // if($gender != 1){
- // $gender = 0;
- // }
- $user = \app\common\model\User::getByOpenid($wechat_openid);
- if ($user) {
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- if ($user->frozentime > time()) {
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
- /*if($user->gender == 1 && $user->gh_id == 0){
- $this->firstopen_send($user->id);
- }*/
- } else {
- // $this->success('选择性别', ['code' => 5]);
- // if (!$nickname || !$avatar) {
- // $this->error(__('Invalid parameters'));
- // }
- $reg_data = [
- // 'nickname'=>$nickname,
- // 'avatar'=>$avatar,
- // 'gender'=>$gender,
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->openid_register($wechat_openid,$reg_data);
- //亿米
- /*if(input('register_from','') == 'xiaomi'){
- $this->yimi_advert();
- }*/
- }
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- //微信注册
- public function wechatregiter(){
- // $nickname = input('nickname','');
- // $avatar = input('avatar','');
- // $gender = input('gender',1);
- $wechat_openid = input('wechat_openid','');
- $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
- if (!$wechat_openid) {
- $this->error(__('Invalid parameters'));
- }
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $user = \app\common\model\User::getByOpenid($wechat_openid);
- if ($user) {
- $this->error('账号已经存在,请直接登录');
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
- /*if($user->gender == 1 && $user->gh_id == 0){
- $this->firstopen_send($user->id);
- }*/
- } else {
- // if (!$nickname || !$avatar) {
- // $this->error(__('Invalid parameters'));
- // }
- $reg_data = [
- // 'nickname'=>$nickname,
- // 'avatar'=>$avatar,
- 'gender'=>$gender,
- 'register_from' => input('register_from',''),
- ];
- $ret = $this->auth->openid_register($wechat_openid,$reg_data);
- //亿米
- /*if(input('register_from','') == 'xiaomi'){
- $this->yimi_advert();
- }*/
- }
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 运营商一键登录
- */
- public function onLogin()
- {
- $accessToken = input('accessToken');// 运营商预取号获取到的token
- $token = input('tokenT');// 易盾返回的token
- if (!$accessToken || !$token) {
- $this->error("参数获取失败!");
- }
- $params = array(
- // 运营商预取号获取到的token
- "accessToken" => $accessToken,
- // 易盾返回的token
- "token" => $token
- );
- // 获取密钥配置
- $configInfo = config("onLogin");
- $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
- $onret = $onlogin->check($params);
- // $ret = [];
- // $ret["code"] = 200;
- // $ret["msg"] = "ok";
- // $ret["data"] = [
- // "phone" => "17574504021",
- // "resultCode" => 0
- // ];
- if ($onret["code"] == 200) {
- $mobile = $onret["data"]["phone"];
- if (empty($mobile)) {
- // 取号失败,建议进行二次验证,例如短信验证码
- $this->error("取号登录失败,请用验证码方式登录!");
- } else {
- // 取号成功, 执行登录等流程
- // 用户登录逻辑 === 开始
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- if ($user->frozentime > time()) {
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- $is_register = 0;
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
- /*if($user->gender == 1 && $user->gh_id == 0){
- $this->firstopen_send($user->id);
- }*/
- } else {
- // $this->success('选择性别', ['code' => 5]);
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
- $is_register = 1;
- //亿米
- // if(input('register_from','') == 'xiaomi'){
- // $this->yimi_advert();
- // }
- }
- //结果
- /*$rs['userinfo'] = $this->auth->getUserinfo();
- $rs['is_register'] = $is_register;*/
- if ($ret) {
- $this->success(__('Logged in successful'), $this->auth->getUserinfo());
- } else {
- $this->error($this->auth->getError());
- }
- // 用户登录逻辑 === 结束
- }
- } else {
- $this->error("登录失败,请用验证码方式登录!");
- }
- }
- /**
- * 运营商一键登录注册
- */
- public function onregister()
- {
- $accessToken = input('accessToken');// 运营商预取号获取到的token
- $token = input('tokenT');// 易盾返回的token
- $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
- if (!$accessToken || !$token) {
- $this->error("参数获取失败!");
- }
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $params = array(
- // 运营商预取号获取到的token
- "accessToken" => $accessToken,
- // 易盾返回的token
- "token" => $token
- );
- // 获取密钥配置
- $configInfo = config("onLogin");
- $onlogin = new onlogin($configInfo["secretid"], $configInfo["secretkey"], $configInfo["businessid"]);
- $onret = $onlogin->check($params);
- // $ret = [];
- // $ret["code"] = 200;
- // $ret["msg"] = "ok";
- // $ret["data"] = [
- // "phone" => "17574504021",
- // "resultCode" => 0
- // ];
- if ($onret["code"] == 200) {
- $mobile = $onret["data"]["phone"];
- if (empty($mobile)) {
- // 取号失败,建议进行二次验证,例如短信验证码
- $this->error("取号登录失败,请用验证码方式登录!");
- } else {
- // 取号成功, 执行登录等流程
- // 用户登录逻辑 === 开始
- $user = \app\common\model\User::getByMobile($mobile);
- if ($user) {
- $this->error('账号已经存在,请直接登录');
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- $is_register = 0;
- //非首次注册男性用户每次打开app,系统自动推送女性(公会)打招呼消息3人次
- /*if($user->gender == 1 && $user->gh_id == 0){
- $this->firstopen_send($user->id);
- }*/
- } else {
- $extend = [
- 'register_from' => input('register_from',''),
- 'gender' => $gender
- ];
- $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, $extend);
- $is_register = 1;
- //亿米
- // if(input('register_from','') == 'xiaomi'){
- // $this->yimi_advert();
- // }
- }
- //结果
- /*$rs['userinfo'] = $this->auth->getUserinfo();
- $rs['is_register'] = $is_register;*/
- if ($ret) {
- $this->success(__('Logged in successful'), $this->auth->getUserinfo());
- } else {
- $this->error($this->auth->getError());
- }
- // 用户登录逻辑 === 结束
- }
- } else {
- $this->error("登录失败,请用验证码方式登录!");
- }
- }
- //用户详细资料
- public function userInfo($type = 1){
- $info = $this->auth->getUserinfo();
- if($type == 'return'){
- return $info;
- }
- $this->success(__('success'),$info);
- }
- public function testhaibao(){
- $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode]);
- // dump($haibao);
- $this->success('success', $haibao);
- }
- //海报
- public function haibao($player_id,$data){
- //下载页二维码,没必要保留
- $params = [
- 'text' => config('site.domain_name').'?code=' . $data['introcode'],
- 'size' => 90,
- 'logo' => false,
- 'label' => false,
- 'padding' => 0,
- ];
- $qrCode = \addons\qrcode\library\Service::qrcode($params);
- $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
- mk_dir($qrcode_path);
- $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
- $qrCode->writeFile($download_qrcode);
- //海报
- $haibao = $this->createhaibao($download_qrcode,$player_id,$data);
- return $haibao;
- }
- /*public function createhaibao($download_qrcode,$player_id,$sub_data){
- //背景图
- $background = $sub_data['background'] ? $sub_data['background'] : config('site.domain_name').'/assets/img/haibao.png';
- //海报图片路径
- $new_path = 'uploads/hbplayer/'.date("Ymd").'/';
- mk_dir($new_path);
- $wap_file_name = $new_path .'wap_player_'. $player_id . '.png';
- //二维码
- $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
- //合成wap图片
- $image = new \addons\poster\library\Image2();
- $imgurl = $image->createPosterImage($background,$download_qrcode,$sub_data['introcode'],$wap_file_name);
- return '/'.$wap_file_name;
- }*/
- public function createhaibao($download_qrcode,$player_id,$sub_data){
- //二维码
- $download_qrcode= config('site.domain_name').'/'.$download_qrcode;
- $data = [
- [
- "left" => "15px",
- "top" => "296px",
- "type" => "img",
- "width" => "58px",
- "height" => "58px",
- "src" => one_domain_image($this->auth->avatar)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
- ],
- [
- "left" => "81px",
- "top" => "300px",
- "type" => "nickname",
- "width" => "80px",
- "height" => "24px",
- "size" => "12px",
- "color" => "#000",
- "content" => $this->auth->nickname
- ],
- [
- "left" => "81px",
- "top" => "327px",
- "type" => "nickname",
- "width" => "80px",
- "height" => "24px",
- "size" => "12px",
- "color" => "#000",
- "content" => $this->auth->introcode
- ],
- [
- "left" => "227px",
- "top" => "283px",
- "type" => "img",
- "width" => "80px",
- "height" => "80px",
- // "src" => httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
- "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
- ]
- ];
- $data = json_encode($data, 320);
- $poster = [
- 'id' => 1,
- 'title' => '测试2',
- 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
- 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
- 'data' => $data,
- 'status' => 'normal',
- 'weigh' => 0,
- 'createtime' => 1653993709,
- 'updatetime' => 1653994259,
- ];
- $image = new \addons\poster\library\Image();
- $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
- if (!$imgurl) {
- $this->error('生成海报出错');
- }
- // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
- return '/' . $imgurl;
- }
- //实名认证信息
- public function idcard_confirm_info(){
- $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
- if (!$check) {
- $check = (object)[];
- }
- $this->success('success',$check);
- }
- /**
- * 退出登录
- * @ApiMethod (POST)
- */
- public function logout()
- {
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
- //退出im
- $tenIm = new Tenim();
- $tenIm->loginoutim($this->auth->id);
- //修改用户活跃0
- Db::name('user')->where('id',$this->auth->id)->update(['is_active' => 0]);
- $this->auth->logout();
- $this->success(__('Logout successful'));
- }
- /**
- * 修改会员个人信息
- *
- * @ApiMethod (POST)
- * @param string $avatar 头像地址
- * @param string $username 用户名
- * @param string $nickname 昵称
- * @param string $bio 个人简介
- */
- public function profile()
- {
- $field_array = ['nickname','introcode',/*'gender',*/'birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo','wechat_account','character_id','constellation_id','stature_id','is_appointment', 'greet_voice', 'greet_chat', 'is_cohabit', 'live_id', 'is_house', 'car_id', 'chest_id', 'waist'];
- $data = [];
- foreach($field_array as $key => $field){
- if(!input('?'.$field)){
- continue;
- }
- $newone = input($field);
- if($field == 'avatar'){
- // if ($this->auth->real_status == 1) {
- //$this->error('您已经真人认证不能修改头像~');
- // die;
- // }
- $newone = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
- }
- if($field == 'photo_images'){
- $newone = input('photo_images', '', 'trim,strip_tags,htmlspecialchars');
- }
- $data[$field] = $newone;
- }
- if(isset($data['birthday'])){
- $data['birthday'] = strtotime($data['birthday']);
- }
- if(isset($data['avatar'])){
- //$data['real_status'] = -1; //或许应该改成0。性别不能改所以不需要
- }
- if(isset($data['hobby_ids'])){
- $data['hobby_ids'] = implode(',',explode(',',$data['hobby_ids']));
- }
- if(isset($data['tag_ids'])){
- $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
- }
- if(isset($data['introcode'])){
- if ($this->auth->intro_uid != 0) {
- $this->error('邀请人不可修改~');
- }
- $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $data['introcode'])->find();
- if(!$intro_user){
- $this->error('不存在的邀请人');
- }
- if ($intro_user['id'] == $this->auth->id) {
- $this->error('不能填写自己邀请码');
- }
- if ($intro_user['intro_uid'] == $this->auth->id) {
- $this->error('不能填写下级邀请码');
- }
- unset($data['introcode']);//别人的邀请码,不能改了自己的
- $data['intro_uid'] = $intro_user['id'];
- $data['invite_time'] = time();
- }
- //dump($data);
- if(empty($data)){
- $this->error('没有任何改变');
- }
- Db::startTrans();
- $userData = Db::name('user')->field('avatar,gender,status')->where('id',$this->auth->id)->find();
- if (isset($data['avatar']) && !empty($data['avatar']) && $userData['status'] == 2) {//隐藏
- $boyAvatar = config('avatar_boy');
- $girlAvatar = config('avatar_girl');
- if ($userData['gender'] == 1 && $data['avatar'] != $boyAvatar) {
- $data['status'] = 1;//更新为正常
- } elseif ($userData['gender'] == 0 && $data['avatar'] != $girlAvatar) {
- $data['status'] = 1;//更新为正常
- }
- }
- $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
- if($update_rs === false){
- Db::rollback();
- $this->error('修改资料失败');
- }
- //tag任务赠送金币
- //上传头像加5金币
- if(isset($data['avatar'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- //上传生日 +5金币
- if (isset($data['birthday'])) {
- //完成设置生日 +5金币
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- //上传个性签名 5金币
- if(isset($data['audio_bio'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,2);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- //上传本人语音介绍 10金币
- if(isset($data['audio_bio'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,21);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- //上传本人五张照片 10金币
- if(isset($data['photo_images'])){
- $photo_images_num = count(explode(',',$data['photo_images'])) + count(explode(',',$this->auth->photo_images));
- if ($photo_images_num >= 5) {
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id, 5);
- if ($task_rs === false) {
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- }
- Db::commit();
- $this->success();
- }
- /*
- * 修改用户的坐标
- * */
- public function change_longlat(){
- $longitude = input_post('longitude');
- $latitude = input_post('latitude');
- $cityname = input_post('cityname');
- if(empty($longitude) || empty($latitude) || empty($cityname)){
- $this->error();
- }
- $data = [
- 'longitude' => $longitude,
- 'latitude' => $latitude,
- 'cityname' => $cityname,
- ];
- Db::name('user')->where('id',$this->auth->id)->update($data);
- $this->success();
- }
- /**
- * 修改手机号
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function changemobile()
- {
- $user = $this->auth->getUser();
- $oldcaptcha = $this->request->request('oldcaptcha');
- $mobile = $this->request->request('mobile');
- $captcha = $this->request->request('captcha');
- if (!$oldcaptcha || !$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if($user->mobile == $mobile){
- $this->error('新手机号不能与旧手机号相同');
- }
- if (\app\common\model\User::where('mobile', $mobile)->find()) {
- $this->error(__('Mobile already exist'));
- }
- $result = Sms::check($user->mobile, $oldcaptcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $verification = $user->verification;
- $verification->mobile = 1;
- $user->verification = $verification;
- $user->mobile = $mobile;
- $user->save();
- Sms::flush($user->mobile, 'changemobile');
- Sms::flush($mobile, 'changemobile');
- $this->success();
- }
- /**
- * 微信注册来的,绑定手机号
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $captcha 验证码
- */
- public function bindmobile()
- {
- $user = $this->auth->getUser();
- $mobile = $this->request->request('mobile');
- $captcha = $this->request->request('captcha');
- if(!empty($this->auth->mobile)){
- $this->error('已经绑定了手机号');
- }
- if (!$mobile || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- if (\app\common\model\User::where('mobile', $mobile)->find()) {
- $this->error('该手机号已被其他用户绑定');
- }
- $result = Sms::check($mobile, $captcha, 'changemobile');
- if (!$result) {
- $this->error(__('Captcha is incorrect'));
- }
- $verification = $user->verification;
- $verification->mobile = 1;
- $user->verification = $verification;
- $user->mobile = $mobile;
- $user->save();
- Sms::flush($mobile, 'changemobile');
- //手机号奖励
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,18);
- if($task_rs === false){
- Db::rollback();
- return false;
- }
- $this->success('success',$this->userInfo('return'));
- }
- /**
- * 手机号注册来的,绑定微信
- *
- * @ApiMethod (POST)
- * @param string wechat_openid 微信openid
- */
- public function bindopenid()
- {
- $user = $this->auth->getUser();
- $wechat_openid = $this->request->request('wechat_openid');
- if(!empty($this->auth->wechat_openid)){
- $this->error('已经绑定了微信号');
- }
- if (!$wechat_openid) {
- $this->error(__('Invalid parameters'));
- }
- if (\app\common\model\User::where('wechat_openid', $wechat_openid)->find()) {
- $this->error('该微信号已被其他用户绑定');
- }
- $user->wechat_openid = $wechat_openid;
- $user->save();
- $this->success('success',$this->userInfo('return'));
- }
- /**
- * 重置密码
- *
- * @ApiMethod (POST)
- * @param string $mobile 手机号
- * @param string $newpassword 新密码
- * @param string $captcha 验证码
- */
- public function resetpwd()
- {
- //$type = input("type");
- $type = 'mobile';
- $mobile = input("mobile");
- $email = input("email");
- $newpassword = input("newpassword");
- $captcha = input("captcha");
- if (!$newpassword || !$captcha) {
- $this->error(__('Invalid parameters'));
- }
- if ($type == 'mobile') {
- if (!Validate::regex($mobile, "^1\d{10}$")) {
- $this->error(__('Mobile is incorrect'));
- }
- $user = \app\common\model\User::getByMobile($mobile);
- if (!$user) {
- $this->error(__('User not found'));
- }
- $ret = Sms::check($mobile, $captcha, 'resetpwd');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- Sms::flush($mobile, 'resetpwd');
- } else {
- if (!Validate::is($email, "email")) {
- $this->error(__('Email is incorrect'));
- }
- $user = \app\common\model\User::getByEmail($email);
- if (!$user) {
- $this->error(__('User not found'));
- }
- $ret = Ems::check($email, $captcha, 'resetpwd');
- if (!$ret) {
- $this->error(__('Captcha is incorrect'));
- }
- Ems::flush($email, 'resetpwd');
- }
- //模拟一次登录
- $this->auth->direct($user->id);
- $ret = $this->auth->changepwd($newpassword, '', true);
- if ($ret) {
- $this->success(__('Reset password successful'));
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 修改密码
- *
- * @ApiMethod (POST)
- * @param string $newpassword 新密码
- * @param string $oldpassword 旧密码
- */
- public function changepwd(){
- $newpassword = input('newpassword');
- $oldpassword = input('oldpassword','');
- if (!$newpassword) {
- $this->error(__('Invalid parameters'));
- }
- if($this->auth->password && empty($oldpassword)){
- $this->error('原密码必填');
- }
- if(empty($this->auth->password)){
- $ret = $this->auth->changepwd($newpassword, '', true);
- }else{
- $ret = $this->auth->changepwd($newpassword,$oldpassword,false);
- }
- if ($ret) {
- $this->success(__('Reset password successful'));
- } else {
- $this->error($this->auth->getError());
- }
- }
- /**
- * 记录当前登陆的设备ID,设备信息,IP等
- */
- public function changeDeviceIp()
- {
- // 接口防并发
- if (!$this->apiLimit(1, 5)) {
- return ;
- }
- $user = $this->auth->getUser();
- $ip = request()->ip();
- $deviceId = $this->request->request('device_id','');
- $phoneModel = $this->request->request('phone_model','');
- $brand = $this->request->request('brand','');
- $apiVersion = $this->request->request('api_version','');
- $deviceOs = $this->request->request('device_os','');
- if ($ip !== $user->loginip){
- $update = [];
- $update['id'] = $user->id;
- $update['loginip'] = $ip;
- \app\common\model\User::update($update);
- }
- $userDeviceInfo = UserDeviceInfo::get(['user_id'=>$user->u_id]);
- if (empty($userDeviceInfo)){
- $userDeviceInfo = new UserDeviceInfo();
- $userDeviceInfo->user_id = $user->u_id;
- }
- $userDeviceInfo->device_os = $deviceOs;
- $userDeviceInfo->device_id = $deviceId;
- $userDeviceInfo->phone_model = $phoneModel;
- $userDeviceInfo->brand = $brand;
- $userDeviceInfo->api_version = $apiVersion;
- $userDeviceInfo->save();
- //首页接口调用,这里不反回信息
- // $this->success("更新成功!");
- }
- //假注销
- public function cancleUser(){
- if (!$this->request->isPost()) {
- $this->error(__('Invalid parameters'));
- }
- //退出im
- $tenIm = new Tenim();
- $tenIm->loginoutim($this->auth->id);
- Db::name('user')->where('id',$this->auth->id)->update(['status'=>-1]);
- $this->auth->logout();
- $this->success('注销成功');
- }
- //修改用户活跃1
- public function useractive(){
- $this->success('success');
- }
- //公众号获取openid
- public function getUserOpenid_gzh(){
- $configValue = Service::getConfig('wechat');
- $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
- $rs = $wechat->getOpenid();
- $this->success('success',$rs);
- }
- /**
- * 微信内H5-JSAPI支付
- */
- public function jssdkBuildConfig() {
- $url = $this->request->request("url");
- $configValue = Service::getConfig('wechat');
- $wechat = new Wechat($configValue['app_id'],$configValue['app_secret']);
- $sign = $wechat->getSignPackage(urldecode($url));
- $this->success("获取成功!",$sign);
- }
- //苹果账号登录
- public function ioslogin(){
- $ios_openid = input('ios_openid','');
- if (!$ios_openid) {
- $this->error(__('Invalid parameters'));
- }
- $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
- /*if (!$user) {
- $this->success('选择性别', ['code' => 5]);
- }*/
- if ($user) {
- if (!in_array($user->status,[1,2])) {
- $this->error(__('Account is locked'));
- }
- if ($user->frozentime > time()) {
- $this->error('您的账号已被封禁至' . date('Y-m-d H:i'));
- }
- //如果已经有账号则直接登录
- $ret = $this->auth->direct($user->id);
- } else {
- $reg_data = [
- 'register_from' => input('register_from',''),
- 'gender' => -1
- ];
- $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
- }
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- //苹果账号注册
- public function iosregiter(){
- $ios_openid = input('ios_openid', '', 'trim');
- $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
- if (!$ios_openid) {
- $this->error(__('Invalid parameters'));
- }
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $user = Db::name('user')->where(['ios_openid' => $ios_openid])->find();
- if ($user) {
- $this->error('账号已经存在,请直接登录');
- }
- $reg_data = [
- 'register_from' => input('register_from',''),
- 'gender' => $gender
- ];
- $ret = $this->auth->iosopenid_register($ios_openid,$reg_data);
- if ($ret) {
- $data = $this->userInfo('return');
- $this->success(__('Logged in successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
-
- //注册完善资料
- public function perfect_info() {
- $avatar = input('avatar', '', 'trim'); //头像
- $nickname = input('nickname', '', 'trim'); //昵称
- $birthday = input('birthday', '', 'strtotime'); //生日
- $hometown_cityid = input('hometown_cityid', '', 'trim'); //城市id
- $job_id = input('job_id', '', 'trim'); //职业id
- $character_id = input('character_id', '', 'trim'); //性格id
- $introcode = input('introcode', '', 'trim'); //邀请码
- $data = [];
- if ($avatar) {
- $data['avatar'] = $avatar;
- }
- if ($nickname !== '') {
- if (iconv_strlen($nickname, 'utf-8') > 10) {
- $this->error('昵称最多10个字~');
- }
- $data['nickname'] = $nickname;
- }
- if ($birthday) {
- $data['birthday'] = $birthday;
- }
- if ($hometown_cityid) {
- $count = Db::name('area')->where('id', $hometown_cityid)->count('id');
- if (!$count) {
- $this->error('城市不存在');
- }
- $data['hometown_cityid'] = $hometown_cityid;
- }
- if ($job_id) {
- $count = Db::name('enum_job')->where('id', $job_id)->count('id');
- if (!$count) {
- $this->error('职业不存在');
- }
- $data['job_id'] = $job_id;
- }
- if ($character_id) {
- $count = Db::name('enum_character')->where('id', $character_id)->count('id');
- if (!$count) {
- $this->error('性格不存在');
- }
- $data['character_id'] = $character_id;
- }
- if ($introcode && !$this->auth->intro_uid) {
- /*if ($this->auth->intro_uid) {
- $this->error('您已经填写过邀请人啦');
- }
- $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
- if(!$intro_user){
- $this->error('不存在的邀请人');
- }
- if ($intro_user['id'] == $this->auth->id) {
- $this->error('不能填写自己邀请码');
- }
- if ($intro_user['intro_uid'] == $this->auth->id) {
- $this->error('不能填写下级邀请码');
- }
- $data['intro_uid'] = $intro_user['id'];
- $data['invite_time'] = time();*/
- $intro_user = Db::name('user')->field('id, intro_uid')->where('introcode', $introcode)->find();
- if ($intro_user && $intro_user['id'] != $this->auth->id && $intro_user['intro_uid'] != $this->auth->id) {
- $data['intro_uid'] = $intro_user['id'];
- $data['invite_time'] = time();
- }
- }
- // if (!$data) {
- // $this->error('请输入要修改的信息');
- // }
- //开启事务
- Db::startTrans();
- $update_rs = Db::name('user')->where('id',$this->auth->id)->setField($data);
- if($update_rs === false){
- Db::rollback();
- $this->error('修改失败');
- }
- //上传头像加5金币
- if(isset($data['avatar'])){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,19);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- if (isset($data['birthday'])) {
- //完成设置生日 +5金币
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,1);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- }
- Db::commit();
- $this->success('修改成功');
- }
- //实名认证
- public function idcard_auth() {
- $info = Db::name('user_idconfirm')->where(['user_id' => $this->auth->id])->find();
- // if ($info && $info['status'] == 0) {
- // $this->error('您已经提交信息了,请进行人脸认证!');
- // }
- if ($info && $info['status'] == 1) {
- $this->error('您已通过审核!');
- }
- $nickname = input('nickname', '', 'trim'); // 姓名
- $idcard = input('idcard', '', 'trim'); // 身份证号
- if ($nickname === '') {
- $this->error('请输入姓名');
- }
- if (iconv_strlen($nickname, 'utf-8') > 50) {
- $this->error('请输入正确姓名');
- }
- if ($idcard === '') {
- $this->error('请输入身份证号');
- }
- if (iconv_strlen($idcard, 'utf-8') != 18) {
- $this->error('请输入正确身份证号');
- }
- $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
- if ($count) {
- $this->error('身份证号已存在');
- }
- $data = [];
- $data['truename'] = $nickname;
- $data['idcard'] = $idcard;
- //腾讯云身份证二要素认证
- $auth_restult = $this->userauth_tencent($idcard, $nickname);
- if ($auth_restult) {
- $data['status'] = 1; //通过
- $msg = '认证通过';
- } else {
- $data['status'] = 2; //不通过
- $msg = '认证不通过';
- }
- //开启事务
- Db::startTrans();
- if (!$info) { //未认证
- $data["user_id"] = $this->auth->id;
- $data["createtime"] = time();
- $res = Db::name('user_idconfirm')->insertGetId($data);
- } else { //认证被拒绝过
- $data['updatetime'] = time();
- $res = Db::name('user_idconfirm')->where(['id' => $info['id'], 'user_id' => $this->auth->id])->setField($data);
- }
- if (!$res) {
- Db::rollback();
- $this->error('认证失败');
- }
- $rt = Db::name('user')->where(['id' => $this->auth->id, 'idcard_status' => $this->auth->idcard_status])->setField('idcard_status', $data['status']);
- if ($rt === false) {
- Db::rollback();
- $this->error('认证失败');
- }
- if ($data['status'] == 1) {
- //完成实名认证 +20金币
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,4);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- //系统消息
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
- } else {
- //系统消息
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证审核不通过');
- }
- Db::commit();
- $this->success($msg);
- }
- //腾讯云身份证二要素认证
- public function userauth_tencent($idcard = '', $nickname = '') {
- // require_once 'vendor/autoload.php';
- try {
- // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
- // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
- $config = config('tencent_im');
- $cred = new Credential($config['SecretId'], $config['SecretKey']);
- // 实例化一个http选项,可选的,没有特殊需求可以跳过
- $httpProfile = new HttpProfile();
- $httpProfile->setEndpoint("faceid.tencentcloudapi.com");
- // 实例化一个client选项,可选的,没有特殊需求可以跳过
- $clientProfile = new ClientProfile();
- $clientProfile->setHttpProfile($httpProfile);
- // 实例化要请求产品的client对象,clientProfile是可选的
- $client = new FaceidClient($cred, "", $clientProfile);
- // 实例化一个请求对象,每个接口都会对应一个request对象
- $req = new IdCardVerificationRequest();
- $params = array(
- "IdCard" => $idcard,
- "Name" => $nickname
- );
- $req->fromJsonString(json_encode($params));
- // 返回的resp是一个IdCardVerificationResponse的实例,与请求对象对应
- $resp = $client->IdCardVerification($req);
- // 输出json格式的字符串回包
- // print_r($resp->toJsonString());
- $result = json_decode($resp->toJsonString(), true);
- if (isset($result['Result']) && $result['Result'] == 0) {
- return 1; //通过
- } else {
- return 0;
- }
- }
- catch(TencentCloudSDKException $e) {
- // echo $e;
- return 0;
- }
- }
- //绑定支付宝
- public function addalipayaccount() {
- $id = input('id', 0, 'intval'); //账号id
- $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
- // $type = 1;
- $realname = input('realname', '', 'trim'); //账户真实姓名
- $banknumber = input('banknumber', '', 'trim'); //卡号或账号
- $bankname = input('bankname', '', 'trim'); //银行名称
- // if ($id) {
- // $this->error('您已经拥有该类型账号,请联系后台解绑');
- // }
- if (!in_array($type, [1, 2])) {
- $this->error('参数错误');
- }
- /*if ($type == 1) {
- $this->error('暂不支持绑定支付宝');
- }*/
- if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
- $this->error('账号姓名1-30位');
- }
- if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
- $this->error('账号1-50位');
- }
- if ($type == 1) {
- if (iconv_strlen($bankname, 'utf-8') != 18) {
- $this->error('请输入正确身份证号');
- }
- }
- if ($type == 2) {
- if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
- $this->error('开户行名称1-50位');
- }
- }
- $user_bank = Db::name('user_bank');
- if ($id) {
- //编辑
- //查询账号是否存在
- $info = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->find();
- if (!$info) {
- $this->error('账号不存在');
- }
- if ($info['type'] != $type) {
- $this->error('账号类型错误');
- }
- //查询是否未通过提现记录
- $count = Db::name('take_cash')->where(['user_id' => $this->auth->id, 'alipay_account' => $info['banknumber'], 'status' => 0])->count('id');
- if ($count) {
- $this->error('该账户有未审核的提现记录,暂不可修改');
- }
- $data['realname'] = $realname;
- $data['banknumber'] = $banknumber;
- $data['updatetime'] = time();
- // if ($type == 2) {
- $data['bankname'] = $bankname;
- // }
- $rs = $user_bank->where(['id' => $id, 'user_id' => $this->auth->id])->setField($data);
- if ($rs === false) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- } else {
- //添加
- //查询是否已经拥有该类型账号
- $count = $user_bank->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
- if ($count) {
- $this->error('您已经拥有该类型账号,请联系后台解绑');
- }
- $data['user_id'] = $this->auth->id;
- $data['type'] = $type;
- $data['realname'] = $realname;
- $data['banknumber'] = $banknumber;
- // if ($type == 2) {
- $data['bankname'] = $bankname;
- // }
- $data['createtime'] = time();
- $rs = $user_bank->insertGetId($data);
- if (!$rs) {
- $this->error('添加失败');
- }
- $this->success('添加成功');
- }
- }
- //查询支付宝/银行卡信息
- public function alipayinfo() {
- $type = input('type', 0, 'intval'); //账号类型:1=支付宝,2=银行卡
- $info = Db::name('user_bank')->field('id, realname, banknumber, bankname')->where(['user_id' => $this->auth->id, 'type' => $type])->find();
- if (!$info) {
- $info = (object)[];
- }
- $this->success('success', $info);
- }
- //申请真人认证
- public function realauth() {
- if ($this->auth->real_status == 1) {
- $this->error('您已经真人认证过了~');
- }
- if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
- $this->error('请先上传真人头像~');
- }
- //获取token
- $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
- $token_result = file_get_contents($token_url);
- if (!$token_result) {
- $this->error('您的网络开小差啦1~');
- }
- $token_result = json_decode($token_result, true);
- if ($token_result['code'] != 0) {
- $this->error('您的网络开小差啦2~');
- }
- $token = $token_result['access_token'];
- //获取签名鉴权参数ticket
- $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
- $ticket_result = file_get_contents($ticket_url);
- if (!$ticket_result) {
- $this->error('您的网络开小差啦3~');
- }
- $ticket_result = json_decode($ticket_result, true);
- if ($ticket_result['code'] != 0) {
- $this->error('您的网络开小差啦4~');
- }
- $ticket = $ticket_result['tickets'][0]['value'];
- //获取签名
- $sign_data = [
- 'wbappid' => config('tencent_yun')['secret_id'],
- 'userId' => (string)$this->auth->id,
- 'version' => '1.0.0',
- 'ticket' => $ticket,
- 'nonce' => Random::alnum(32)
- ];//p($sign_data);
- asort($sign_data); //p($sign_data);//排序
- $sign_string = join('', $sign_data);//p($sign_string);
- $sign = sha1($sign_string);//p($sign);
- //上传身份信息
- $orderNo = getMillisecond() . $this->auth->id . mt_rand(1, 1000); //商户请求的唯一标识
- $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
- $avatar = one_domain_image($this->auth->avatar);
- $avatar = str_replace('https', 'http', $avatar);
- $img = file_get_contents($avatar);
- $img = str_replace('data:image/jpg;base64', '', $img);
- $img = str_replace('\n', '', $img);
- $sourcePhotoStr = base64_encode($img);
- $data = [
- 'webankAppId' => config('tencent_yun')['secret_id'],
- 'orderNo' => $orderNo,
- 'userId' => (string)$this->auth->id,
- 'sourcePhotoStr' => $sourcePhotoStr,
- 'sourcePhotoType' => 2,
- 'version' => '1.0.0',
- 'sign' => $sign,
- 'nonce' => $sign_data['nonce']
- ];
- $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
- if (!$rs) {
- $this->error('您的网络开小差啦5~');
- }
- $rs = json_decode($rs, true);
- if (!$rs || $rs['code'] != 0) {
- $this->error('您的网络开小差啦6~');
- }
- $user_auth = [
- 'user_id' => $this->auth->id,
- 'certify_id' => $rs['result']['faceId'],
- 'out_trade_no' => $data['orderNo'],
- 'status' => 0,
- 'createtime' => time(),
- 'updatetime' => time()
- ];
- //开启事务
- Db::startTrans();
- //查询是否认证过
- $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
- if ($info) {
- $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
- } else {
- $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
- }
- if (!$auth_rs) {
- Db::rollback();
- $this->error('您的网络开小差啦7~');
- }
- //修改用户表认证状态
- $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
- if ($user_rs === false) {
- Db::rollback();
- $this->error('您的网络开小差啦8~');
- }
- Db::commit();
- $return_data = [
- 'face_id' => $user_auth['certify_id'],
- 'order_no' => $user_auth['out_trade_no'],
- 'user_id' => (string)$this->auth->id,
- 'nonce' => $sign_data['nonce'],
- 'sign' => $sign
- ];
- $this->success('success', $return_data);
- }
- //查询真人认证结果
- public function getrealauthresult() {
- $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
- if (!$user_auth) {
- $this->success('尚未认证');
- }
- if ($user_auth['status'] == 1) {
- $this->success('真人认证通过');
- }
- if (!$user_auth['certify_id']) {
- $this->success('请先进行真人认证');
- }
- //获取token
- $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
- $token_result = file_get_contents($token_url);
- if (!$token_result) {
- $this->error('您的网络开小差啦1~');
- }
- $token_result = json_decode($token_result, true);
- if ($token_result['code'] != 0) {
- $this->error('您的网络开小差啦2~');
- }
- $token = $token_result['access_token'];
- //获取签名鉴权参数ticket
- $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
- $ticket_result = file_get_contents($ticket_url);
- if (!$ticket_result) {
- $this->error('您的网络开小差啦3~');
- }
- $ticket_result = json_decode($ticket_result, true);
- if ($ticket_result['code'] != 0) {
- $this->error('您的网络开小差啦4~');
- }
- $ticket = $ticket_result['tickets'][0]['value'];
- //获取签名
- $sign_data = [
- 'wbappid' => config('tencent_yun')['secret_id'],
- 'orderNo' => $user_auth['out_trade_no'],
- 'version' => '1.0.0',
- 'ticket' => $ticket,
- 'nonce' => Random::alnum(32)
- ];//p($sign_data);
- asort($sign_data); //p($sign_data);//排序
- $sign_string = join('', $sign_data);//p($sign_string);
- $sign = sha1($sign_string);//p($sign);
- //人脸核身结果查询
- $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
- $data = [
- 'appId' => config('tencent_yun')['secret_id'],
- 'version' => '1.0.0',
- 'nonce' => $sign_data['nonce'],
- 'orderNo' => $user_auth['out_trade_no'],
- 'sign' => $sign
- ];
- $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
- if (!$rs) {
- $this->error('您的网络开小差啦5~');
- }
- $rs = json_decode($rs, true);
- if (!$rs || $rs['code'] != 0) {
- $this->error($rs['msg']);
- }
- if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
- $edit_data['status'] = 1;
- $msg = '真人认证成功';
- } else {
- $edit_data['status'] = 2;
- $edit_data['certify_id'] = '';
- $edit_data['out_trade_no'] = '';
- $msg = '真人认证失败';
- }
- $edit_data['updatetime'] = time();
- //开启事务
- Db::startTrans();
- //修改认证信息
- $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
- if (!$result) {
- Db::rollback();
- $this->error('查询认证结果失败2');
- }
- //修改用户信息
- $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
- if (!$rs) {
- Db::rollback();
- $this->error('查询认证结果失败3');
- }
- if ($edit_data['status'] == 1) { //通过
- //tag任务赠送金币
- //真人认证奖励
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,20);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- //系统消息
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
- } else {
- //系统消息
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
- }
- Db::commit();
- $this->success($msg);
- }
- //客服
- public function kefu() {
- $type = input('type', 0, 'intval'); //客服位置: 0客服中心 1充值客服
- if (!in_array($type, [0, 1])) {
- $this->error('您的网络开小差啦~');
- }
- if ($type == 0) {
- $user_id = config('site.customer_service_id') ? : 0; //指定客服id
- } else {
- $user_id = config('site.pay_customer_service_id') ? : 0; //指定客服id
- }
- $list = Db::name('user')->field('id')->where(['status' => 1, 'is_kefu' => 1, 'id' => $user_id])->select();
- if (!$list) {
- $this->success('success', $list);
- }
- foreach ($list as $k => &$v) {
- $v['nickname'] = '客服' . ($k + 1);
- $v['avatar'] = config('avatar_girl');
- }
- $this->success('success', $list);
- }
- //海报背景图
- public function posterlist() {
- $list = config('site.intro_images');
- if (!$list) {
- $this->success('success', (object)[]);
- }
- foreach ($list as &$v) {
- $v = config('img_url') . $this->createposter(config('site.domain_cdnurl') . $v);
- }
- $this->success('success', $list);
- }
-
- //生成海报
- public function createposter($image = '') {
- // $image = input('image', '', 'trim');
- // if (!$image) {
- // $this->error('您的网络开小差啦~');
- // }
- $haibao = $this->haibao($this->auth->id,['introcode'=>$this->auth->introcode, 'background' => $image]);
- return $haibao;
- // $this->success('success', $haibao);
- }
- //注册设置性别
- public function setgender() {
- $user_id = $this->auth->id;
- $gender = input('gender', -1, 'intval'); //性别:1=男,0=女
- if (!in_array($gender, [1, 0])) {
- $this->error('性别错误');
- }
- $edit_data['gender'] = $gender;
- $edit_data['avatar'] = $gender == 1 ? config('avatar_boy') : config('avatar_girl'); //头像
- $rs = Db::name('user')->where(['id' => $user_id, 'gender' => $this->auth->gender])->setField($edit_data);
- if (!$rs) {
- $this->error('您的网络开小差啦~');
- }
- $data = $this->userInfo('return');
- $data['gender'] = $edit_data['gender'];
- $data['avatar'] = $edit_data['avatar'];
- $this->success('success', $data);
- }
- //真人认证后修改头像前比对
- public function realavatar_auit() {
- if ($this->auth->real_status != 1) {
- $this->error('尚未通过真人认证');
- }
- $avatar = input('avatar', '', 'trim'); //头像地址
- if ($avatar === '') {
- $this->error('参数缺失');
- }
- $avatar = one_domain_image($avatar);
- $now_avatar = one_domain_image($this->auth->avatar);
- if ($avatar == $now_avatar) {
- $this->error('头像未改变');
- }
- //腾讯云人脸识别
- $result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
- $this->success('结果', $result);
- }
- //真人认证后修改头像
- public function editrealavatar() {
- if ($this->auth->real_status != 1) {
- $this->error('尚未通过真人认证');
- }
- $avatar = input('avatar', '', 'trim'); //头像地址
- if ($avatar === '') {
- $this->error('参数缺失');
- }
- $avatar = one_domain_image($avatar);
- $now_avatar = one_domain_image($this->auth->avatar);
- if ($avatar == $now_avatar) {
- $this->error('头像未改变');
- }
- //腾讯云人脸识别
- $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
- if ($auit_result != 1) {
- $this->success('提示', ['code' => 2]);
- }
- $data['avatar'] = $avatar;
- $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
- if (!$user_result) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- }
- //真人认证后修改头像并取消真人认证
- public function editrealavatarcancelauit() {
- if ($this->auth->real_status != 1) {
- $this->error('尚未通过真人认证');
- }
- $avatar = input('avatar', '', 'trim'); //头像地址
- if ($avatar === '') {
- $this->error('参数缺失');
- }
- $avatar = one_domain_image($avatar);
- $now_avatar = one_domain_image($this->auth->avatar);
- if ($avatar == $now_avatar) {
- $this->error('头像未改变');
- }
- $data['avatar'] = $avatar;
- $data['real_status'] = -1;
- //开启事务
- Db::startTrans();
- $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
- if (!$user_result) {
- Db::rollback();
- $this->error('修改失败');
- }
- $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
- if (!$user_auth_result) {
- Db::rollback();
- $this->error('修改失败');
- }
- Db::commit();
- $this->success('修改成功');
- }
-
- //腾讯云人脸识别
- public function face_tencent($urla = '', $urlb = '') {
- // require_once 'vendor/autoload.php';
- try {
- // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
- // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
- $config = config('tencent_im');
- $cred = new Credential($config['SecretId'], $config['SecretKey']);
- // 实例化一个http选项,可选的,没有特殊需求可以跳过
- $httpProfile = new HttpProfile();
- $httpProfile->setEndpoint("iai.tencentcloudapi.com");
- // 实例化一个client选项,可选的,没有特殊需求可以跳过
- $clientProfile = new ClientProfile();
- $clientProfile->setHttpProfile($httpProfile);
- // 实例化要请求产品的client对象,clientProfile是可选的
- $client = new IaiClient($cred, "ap-beijing", $clientProfile);
- // 实例化一个请求对象,每个接口都会对应一个request对象
- $req = new CompareFaceRequest();
- $params = array(
- "UrlA" => $urla,
- "UrlB" => $urlb,
- "FaceModelVersion" => "3.0"
- );
- $req->fromJsonString(json_encode($params));
- // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
- $resp = $client->CompareFace($req);
- // 输出json格式的字符串回包
- // print_r($resp->toJsonString());
- $result = json_decode($resp->toJsonString(), true);
- //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
- if (isset($result['Score']) && $result['Score'] >= 60) {
- return 1; //通过
- } else {
- return 0;
- }
- }
- catch(TencentCloudSDKException $e) {
- // echo $e;
- return 0;
- }
- }
- //修改城市
- public function editcity() {
- $name = input('name', '', 'trim'); //城市名
- if ($name === '') {
- $this->error('参数缺失');
- }
- $hometown_cityid = Db::name('area')->where(['name' => $name])->value('id');
- if (!$hometown_cityid) {
- $this->success('修改成功');
- }
- Db::name('user')->where(['id' => $this->auth->id])->setField('hometown_cityid', $hometown_cityid);
- $this->success('修改成功');
- }
- //搜索用户
- public function searchuser() {
- $keyword = input('keyword', '', 'trim'); //昵称或ID
- if ($keyword === '') {
- $this->error('请输入关键字');
- }
- $id = Db::name('user')->where(['nickname|username' => $keyword])->value('id');
- $id = $id ? : 0;
- $this->success('用户', $id);
- }
- //绑定支付宝账号信息
- public function bindalipayaccount() {
- $mt_user_bank = Db::name('user_bank');
- $count = $mt_user_bank->where(['user_id' => $this->auth->id, 'type' => 1])->count();
- if ($count) {
- $this->error('您已绑定支付宝啦');
- }
- $auth_code = input('auth_code', '', 'trim');
- if (!$auth_code) {
- $this->error('授权码缺失');
- }
- //获取支付宝用户信息
- $rs = getAlipayInfo($auth_code);
- if ($rs['status'] == 0) {
- $this->error($rs['info']);
- }
- $rs = $rs['data'];
- /*
- * Array(
- [alipay_user_info_share_response] => Array
- (
- [code] => 10000
- [msg] => Success
- [avatar] => https://tfs.alipayobjects.com/images/partner/T1BQJsXhhbXXXXXXXX 头像
- [city] => 临沂市 市名称。
- [gender] => m 【注意】只有is_certified为T的时候才有意义,否则不保证准确性. 性别(F:女性;M:男性)。
- [is_certified] => T 是否通过实名认证。T是通过 F是没有实名认证。
- [is_student_certified] => F 是否是学生 T是 F否
- [nick_name] => 风的追求 用户昵称
- [province] => 山东省 省份名称
- [user_id] => 2088902918001020 支付宝用户的userId
- [user_status] => T 用户状态(Q/T/B/W)。 Q代表快速注册用户 T代表已认证用户 B代表被冻结账户 W代表已注册,未激活的账户
- [user_type] => 2 用户类型(1/2) 1代表公司账户2代表个人账户
- )
- )
- */
- $data['banknumber'] = $rs['user_id']; //支付宝用户id
- if (!$data['banknumber']) {
- $this->error('获取用户信息失败');
- }
- $bank_number_count = $mt_user_bank->where(['banknumber' => $data['banknumber'], 'type' => 1])->count();
- if ($bank_number_count) {
- $this->error('该支付宝账号已经绑定用户, 请先解除绑定');
- }
- if (isset($rs['nick_name'])) {
- $data['realname'] = $rs['nick_name']; //支付宝用户昵称
- }
- $data['user_id'] = $this->auth->id;
- $data['createtime'] = time();
- $data['type'] = 1;
- $rt = $mt_user_bank->insertGetId($data);
- if (!$rt) {
- $this->error('绑定失败');
- }
- $this->success('绑定成功');
- }
- //添加打招呼内容,女性使用
- public function addgreetcontent() {
- $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册
- $title = input('title', '', 'trim'); //标题(type=1必传)
- $content = input('content', '', 'trim'); //内容
- $duration = input('duration', 0, 'intval'); //时长(type=1必传)
- if (!in_array($type, [0, 1, 2])) {
- $this->error('您的网络开小差了');
- }
- if ($content === '') {
- $this->error('请设置打招呼内容');
- }
- if (iconv_strlen($content, 'utf-8') > 255) {
- $this->error('打招呼内容最多255位');
- }
- if ($type == 1) {
- if ($title === '') {
- $this->error('请输入语音名称');
- }
- if (iconv_strlen($title, 'utf-8') > 50) {
- $this->error('语音名称最多50字');
- }
- if (!$duration) {
- $this->error('参数缺失');
- }
- }
- $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'type' => $type])->count('id');
- if ($count > 10) {
- $this->error('同一类型打招呼最多设置10条');
- }
- $data['user_id'] = $this->auth->id;
- $data['type'] = $type;
- $data['content'] = $content;
- if ($type == 1) {
- $data['title'] = $title;
- $data['duration'] = $duration;
- }
- $data['createtime'] = time();
- //查询是否有默认打招呼内容
- $default_greet_count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'is_default' => 1])->count('id');
- if (!$default_greet_count) {
- $data['is_default'] = 1;
- }
- $rs = Db::name('user_greet_content')->insertGetId($data);
- if (!$rs) {
- $this->error('您的网络开小差了');
- }
- $this->success('设置成功');
- }
- //查询打招呼内容,女性使用
- public function getgreetcontent() {
- $type = input('type', 0, 'intval'); //类型:0=文字,1=语音,2=相册,3=所有招呼
- if (!in_array($type, [0, 1, 2, 3])) {
- $this->error('您的网络开小差了');
- }
- if ($type == 3) {
- $list = Db::name('user_greet_content')->where(function ($query) {
- $query->where('user_id', $this->auth->id)->where('type', 'neq', 1);
- })->whereOr(function ($query) {
- $query->where('user_id', $this->auth->id)->where('type', 1)->where('is_default', 1);
- })->select();
- } else {
- $where['user_id'] = $this->auth->id;
- $where['type'] = $type;
- $list = Db::name('user_greet_content')->where($where)->select();
- }
- if ($list) {
- foreach ($list as &$v) {
- if ($v['type'] != 0) {
- $v['content'] = one_domain_image($v['content']);
- }
- }
- }
- $this->success('打招呼内容', $list);
- }
-
- //设置默认打招呼内容,女性使用
- public function setdefaultgreet() {
- $id = input('id', 0, 'intval'); //打招呼id
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $count = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->count('id');
- if (!$count) {
- $this->error('您的网络开小差了');
- }
- //开启事务
- Db::startTrans();
- //清除之前默认
- $rs = Db::name('user_greet_content')->where(['user_id' => $this->auth->id])->setField('is_default', 0);
- if ($rs === false) {
- Db::rollback();
- $this->error('您的网络开小差了');
- }
- //设置
- $rt = Db::name('user_greet_content')->where(['user_id' => $this->auth->id, 'id' => $id])->setField('is_default', 1);
- if ($rt === false) {
- Db::rollback();
- $this->error('您的网络开小差了');
- }
- Db::commit();
- $this->success('设置成功');
- }
- //删除打招呼内容,女性使用
- public function deldefaultgreet() {
- $id = input('id', 0, 'intval'); //打招呼id
- if (!$id) {
- $this->error('您的网络开小差了');
- }
- $mt_user_greet_content = Db::name('user_greet_content');
- $info = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->find();
- if (!$info) {
- $this->error('您的网络开小差了');
- }
- //开启事务
- Db::startTrans();
- //删除
- $rs = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $id])->delete();
- if ($rs === false) {
- Db::rollback();
- $this->error('您的网络开小差了');
- }
- //若为默认打招呼内容则重新设置一条
- if ($info['is_default'] == 1) {
- $first_greet = $mt_user_greet_content->where(['user_id' => $this->auth->id])->find();
- if ($first_greet) {
- $rt = $mt_user_greet_content->where(['user_id' => $this->auth->id, 'id' => $first_greet['id']])->setField('is_default', 1);
- if ($rt === false) {
- Db::rollback();
- $this->error('您的网络开小差了');
- }
- }
- }
- Db::commit();
- $this->success('删除成功');
- }
- }
|