123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Cache;
- use think\Db;
- use app\common\model\wallet;
- use Redis;
- /**
- * 会员中心,不是个人中心
- */
- class Usercenter extends Api
- {
- protected $noNeedLogin = ['test','testredis'];
- protected $noNeedRight = '*';
- protected $allowFields = [
- 'id',
- 'username',
- 'nickname',
- //'truename',//
- 'email',
- 'mobile',
- 'avatar',
- 'real_status',
- 'gender',
- 'height',
- 'weight',
- 'birthday',
- 'bio',
- 'audio_bio',
- 'idcard_status',
- 'is_active',
- 'longitude',
- 'latitude',
- 'cityname',
- 'photo_images',
- 'education_id',
- 'hobby_ids',
- 'job_id',
- 'marital_id',
- 'tag_ids',
- 'wages_id',
- 'hometown_cityid',
- 'wechat_account',
- 'secretvideo_status',
- 'character_id',
- 'constellation_id',
- 'stature_id',
- 'is_appointment',
- 'chat_price',
- 'voice_price',
- 'video_price',
- 'greet_voice',
- 'greet_chat',
- 'is_kefu',
- 'is_hideaddress', 'is_recommend','is_cohabit', 'live_id', 'is_house', 'car_id', 'chest_id', 'waist'
- ];
- public function testredis(){
- //redis_matching_set(1,125);
- dump(redis_matching_get(1));
- $a = cache('?mt_matching_uid_1','',['type'=>'Redis']);
- dump($a);
- }
- public function test(){
- $a = [1,4,10,22,66,36,102,45,23,52,35,76,7];
- $b = [1,10,7,102];
- $c = [10,102];
- //dump(array_intersect($a,$b));
- $data = array_merge($c,$b);
- dump($data);
- dump(array_flip(array_flip($data)));
- dump(array_flip([]));
- }
- //获取他人用户信息,留下足迹
- public function getuserinfo(){
- $uid = input_post('uid',0);
- $userinfo = Db::name('user')->field($this->allowFields)->where('id',$uid)->find();
- if(!$userinfo){
- $this->error('不存在的用户');
- }
- //用户数据
- $userinfo = info_domain_image($userinfo,['avatar','photo_images']);
- $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$uid)->find();
- $new_data = [
- 'age' => birthtime_to_age($userinfo['birthday']),
- 'truename' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['truename'])) ? $idcard_confirm['truename'] : '',
- 'alipay_account' => '',
- ];
- if ($this->auth->gender == 1) {
- $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $this->auth->id, 'other_uid' => $uid])->value('value');
- } elseif ($this->auth->gender == 0) {
- $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $this->auth->id])->value('value');
- } else {
- $qinmi_sum = 0;
- }
- $new_data['qinmi_sum'] = $qinmi_sum ? :0;
- //合并
- $userinfo = array_merge($userinfo,$new_data);
- //枚举
- $userinfo['education'] = Db::name('enum_education')->where('id',$userinfo['education_id'])->value('name');
- $userinfo['education'] = $userinfo['education'] ? : '';
- $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$userinfo['hobby_ids'])->field(['id','name'])->select();
- $userinfo['job'] = Db::name('enum_job')->where('id',$userinfo['job_id'])->value('name');
- $userinfo['job'] = $userinfo['job'] ? : '';
- $userinfo['marital'] = Db::name('enum_marital')->where('id',$userinfo['marital_id'])->value('name');
- $userinfo['marital'] = $userinfo['marital'] ? : '';
- $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
- $userinfo['wages'] = Db::name('enum_wages')->where('id',$userinfo['wages_id'])->value('name');
- $userinfo['wages'] = $userinfo['wages'] ? : '';
- $userinfo['character'] = Db::name('enum_character')->where('id',$userinfo['character_id'])->value('name');
- $userinfo['character'] = $userinfo['character'] ? : '';
- $userinfo['constellation'] = Db::name('enum_constellation')->where('id',$userinfo['constellation_id'])->value('name');
- $userinfo['constellation'] = $userinfo['constellation'] ? : '';
- $userinfo['stature'] = Db::name('enum_stature')->where('id',$userinfo['stature_id'])->value('name');
- $userinfo['stature'] = $userinfo['stature'] ? : '';
- $userinfo['live'] = Db::name('enum_live')->where('id',$userinfo['live_id'])->value('name');
- $userinfo['live'] = $userinfo['live'] ? : '';
- $userinfo['car'] = Db::name('enum_car')->where('id',$userinfo['car_id'])->value('name');
- $userinfo['car'] = $userinfo['car'] ? : '';
- $userinfo['chest'] = Db::name('enum_chest')->where('id',$userinfo['chest_id'])->value('name');
- $userinfo['chest'] = $userinfo['chest'] ? : '';
- //家乡
- $userinfo['hometown_city'] = Db::name('area')->where('id',$userinfo['hometown_cityid'])->value('name');
- $userinfo['hometown_city'] = ($userinfo['hometown_city'] && $userinfo['is_hideaddress'] == 0) ? $userinfo['hometown_city'] : '';
- //vip
- $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime');
- $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0;
- //是否喜欢和关注
- $is_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>$uid])->find();
- $userinfo['is_follow'] = $is_follow ? 1 : 0;
- $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find();
- $userinfo['is_like'] = $is_like ? 1 : 0;
- //是否拉黑
- $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
- $userinfo['is_black'] = $is_black ? 1 : 0;
- //关注人数,粉丝人数
- $follow_num = Db::name('user_follow')->where(['uid'=>$this->auth->id])->count('id');
- $fans_num = Db::name('user_follow')->where(['follow_uid'=>$this->auth->id])->count('id');
- $userinfo['follow_num'] = $follow_num;
- $userinfo['fans_num'] = $fans_num;
- //查询是否打过招呼
- $count = Db::name('user_greet')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
- if ($count) {
- $userinfo['is_chat'] = 1; //是否打过招呼: 1是 0否
- } else {
- $userinfo['is_chat'] = 0; //是否打过招呼: 1是 0否
- }
- //守护数量和是否已经守护
- $userinfo['guard_num'] = Db::name('user_guard')->where(['user_to_id' => $uid])->count('id');
- $userinfo['is_guard'] = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
- //查询财富等级和魅力等级
- $wallet_info = Db::name('user_wallet')->where(['user_id' => $uid])->find();
- $wealth_level = Db::name('wealth_level')->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
- if ($wealth_level) {
- $userinfo['wealth_level'] = localpath_to_netpath($wealth_level['image']);
- } else {
- $userinfo['wealth_level'] = '';
- }
- $charm_level = Db::name('charm_level')->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
- if ($charm_level) {
- $userinfo['charm_level'] = localpath_to_netpath($charm_level['image']);
- } else {
- $userinfo['charm_level'] = '';
- }
- //开通守护消耗金币数量
- $userinfo['guard_price'] = config('site.guard_price') ? : 0;
- //男性非会员是否已开通聊天
- // $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
- // $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
- // if ($this->auth->gender == 0 || $vip_endtime > time() || $user_chat_unlock) {
- $userinfo['is_chat_unlock'] = 1; //已解锁
- // } else {
- // $userinfo['is_chat_unlock'] = 0;
- // }
- //男性非会员解锁聊天所需金币数量
- $userinfo['unlock_chat_gold'] = config('site.unlock_chat_gold') > 0 ? config('site.unlock_chat_gold') : 10;
- //动态信息
- $dongtai = Db::name('topic_dongtai')->field('type, images')->where(['user_id' => $uid, 'is_hidden' => 0, 'type' => ['in', [1, 2]], 'status' => 0, 'auit_status' => 1])->order('id desc')->limit(3)->select();
- if ($dongtai) {
- $dongtai_image = [];
- foreach ($dongtai as &$v) {
- $arr['type'] = $v['type'];
- if ($v['type'] == 1) {
- //图片
- $images_url = explode(',', $v['images']);
- foreach ($images_url as &$value) {
- $arr['images'] = one_domain_image($value);
- array_push($dongtai_image, $arr);
- if (count($dongtai_image) == 3) {
- break 2;
- }
- }
- } else {
- //视频
- $images_url = explode('.', $v['images']);
- unset($images_url[count($images_url) - 1]);
- $arr['images'] = join('.', $images_url) . '_0.jpg';
- $arr['images'] = one_domain_image($arr['images']);
- array_push($dongtai_image, $arr);
- if (count($dongtai_image) == 3) {
- break;
- }
- }
- }
- $userinfo['dongtai_image'] = $dongtai_image;
- // $dongtai = join(',', $dongtai);
- // $dongtai = explode(',', $dongtai);
- // $dongtai = array_slice($dongtai, 0, 3);
- // $dongtai = join(',', $dongtai);
- // $userinfo['dongtai_image'] = one_domain_image($dongtai);
- // $userinfo['dongtai_image'] = explode(',', $userinfo['dongtai_image']);
- } else {
- $userinfo['dongtai_image'] = [];
- }
- if ($this->auth->id != $uid) {
- //查看别人信息,就要留下痕迹
- $data = [
- 'uid' => $this->auth->id,
- 'to_uid' => $uid,
- ];
- $check = Db::name('user_visit')->where($data)->find();
- if ($check) {
- Db::name('user_visit')->where($data)->update(['number' => $check['number'] + 1, 'updatetime' => time()]);
- } else {
- $data['number'] = 1;
- $data['updatetime'] = time();
- Db::name('user_visit')->insertGetId($data);
- }
- }
- $this->success('success',$userinfo);
- }
- //这里不用连user_active表,完全使用user表的active_time,user_active表只做离线用
- //同城
- public function samecity(){
- $gender = input_post('gender','all');
- $agemin = input_post('agemin',0);
- $agemax = input_post('agemax',100);
- if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
- // $this->success('success',[]);
- }
- $map = [
- 'user.status' => 1,
- // 'user.cityname' => $this->auth->cityname,
- 'user.id' => ['neq',$this->auth->id],
- // 'user.longitude' => ['neq',''],
- // 'user.latitude' => ['neq',''],
- // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
- 'user.active_time' => ['gt',time()-86400],
- ];
- if($gender != 'all'){
- $map['user.gender'] = $gender;
- }
- $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
- //dump($map);
- $field = [
- 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender','user.active_time'
- ];
- $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
- //dump($list);
- $list = list_domain_image($list,['avatar']);
- foreach($list as $key => $one){
- $one['age'] = birthtime_to_age($one['birthday']);
- // $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
- $one['distance'] = rand(0,10).'km';
- //状态
- $one['active_text'] = '刚刚离线';
- if($one['active_time'] > time()-21600){
- $one['active_text'] = '1小时内在线';
- }
- if($one['active_time'] > time()-3600){
- $one['active_text'] = '在线';
- }
- $list[$key] = $one;
- }
- $this->success('success',$list);
- }
- //附近
- public function nearuser(){
- $gender = input_post('gender','all');
- $agemin = input_post('agemin',0);
- $agemax = input_post('agemax',100);
- if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
- // $this->success('success',[]);
- }
- //经过地图测算和公式推算,经度纬度 0.1即为11公里
- $map = [
- 'user.status' => 1,
- ////'user.cityname' => $this->auth->cityname,
- 'user.id' => ['neq',$this->auth->id],
- // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
- // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
- // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
- 'user.active_time' => ['gt',time()-86400],
- ];
- if($gender != 'all'){
- $map['user.gender'] = $gender;
- }
- $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
- //dump($map);
- $field = [
- 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender','user.active_time'
- ];
- $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
- //dump($list);exit;
- $list = list_domain_image($list,['avatar']);
- foreach($list as $key => $one){
- $one['age'] = birthtime_to_age($one['birthday']);
- //$one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
- $one['distance'] = rand(0,10).'km';
- //状态
- $one['active_text'] = '刚刚离线';
- if($one['active_time'] > time()-21600){
- $one['active_text'] = '1小时内在线';
- }
- if($one['active_time'] > time()-3600){
- $one['active_text'] = '在线';
- }
-
- $list[$key] = $one;
- }
- $this->success('success',$list);
- }
- //因为接受者拿不到发起者的uid,废弃了
- //视频和语音,接收方使用,如果是性别劣势方,检查钱是否够用
- public function video_audio_moneycheck(){
- //检测用户,发起方的uid
- $to_user_id = input_post('from_user_id');
- $to_user_info = Db::name('user')->field('id,real_status,gender')->where('id',$to_user_id)->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- //扣费金币
- $type = input_post('type','video'); //类型
- $price = $type == 'video' ? config('site.video_min_price') : config('site.audio_min_price');
- //发起用户的分数,被发起用户的分数。按性别给分
- $auth_level = 0;
- $tous_level = 0;
- //打分
- if($this->auth->gender == 0 && $this->auth->real_status == 1){
- $auth_level = 30;//实名女最高
- }
- if($this->auth->gender == 0 && $this->auth->real_status != 1){
- $auth_level = 20;//未实名女次之
- }
- if($this->auth->gender == 1){
- $auth_level = 10;//男性最低
- }
- if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
- $tous_level = 30;
- }
- if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
- $tous_level = 20;
- }
- if($to_user_info['gender'] == 1){
- $tous_level = 10;
- }
- //同性不收钱
- //都是男的,不扣钱
- //都是实名认证的女性,不扣钱
- //都是未实名认证的女性,不扣钱
- if($auth_level == $tous_level){
- $price = 0;
- $this->success('success');
- }
- //扣钱uid,收钱uid,收钱free_video
- //分数少扣钱,分数多收益
- if($auth_level < $tous_level){
- $kou_user = $this->auth->id;
- }else{
- $kou_user = $to_user_info['id'];
- }
- //需要扣我的(接收方的)钱,判断钱是否够
- if($price > 0 && $kou_user == $this->auth->id){
- Db::startTrans();
- $gold = model('wallet')->getWallet($kou_user,'gold');
- if(bccomp($price,$gold) == 1){
- Db::rollback();
- $this->error('金币不足');
- }
- Db::commit();
- }
- $this->success('success');
- }
- //视频通话每分钟调用一次
- public function video_onemin(){
- //检测用户
- $to_user_id = input_post('to_user_id');
- $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- //正常价格
- $price = config('site.video_min_price'); //扣费金币
- $bili = config('site.money_to_gold'); //兑换比例
- $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
- $money = bcdiv($price,$bili,2); //对应人民币
- $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
- //发起用户的分数,被发起用户的分数。按性别给分
- $auth_level = 0;
- $tous_level = 0;
- //打分
- if($this->auth->gender == 0 && $this->auth->real_status == 1){
- $auth_level = 30;//实名女最高
- }
- if($this->auth->gender == 0 && $this->auth->real_status != 1){
- $auth_level = 20;//未实名女次之
- }
- if($this->auth->gender == 1){
- $auth_level = 10;//男性最低
- }
- if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
- $tous_level = 30;
- }
- if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
- $tous_level = 20;
- }
- if($to_user_info['gender'] == 1){
- $tous_level = 10;
- }
- //同性不收钱
- //都是男的,不扣钱
- //都是实名认证的女性,不扣钱
- //都是未实名认证的女性,不扣钱
- if($auth_level == $tous_level){
- $price = 0;$money = 0;
- }
- Db::startTrans();
- //记录日志
- $data = [
- 'user_id' => $this->auth->id,
- 'price' => $price,
- 'createtime' => time(),
- 'to_user_id' => $to_user_id,
- 'money' => $money,
- ];
- $log_id = Db::name('user_match_video_log')->insertGetId($data);
- if(!$log_id){
- Db::rollback();
- $this->error('扣费失败');
- }
- //同性别,提前结束
- if($auth_level == $tous_level){
- Db::commit();
- $this->success('success');
- }
- //扣钱uid,收钱uid,收钱free_video
- //分数少扣钱,分数多收益
- if($auth_level < $tous_level){
- $kou_user = $this->auth->id;
- $get_user = $to_user_info['id'];
- $get_user_free = $to_user_info['free_video'];
- }else{
- $kou_user = $to_user_info['id'];
- $get_user = $this->auth->id;
- $get_user_free = $this->auth->free_video;
- }
- //需要扣别人的钱,判断钱是否购
- if($price > 0 && $kou_user != $this->auth->id){
- $gold = model('wallet')->getWallet($kou_user,'gold');
- if(bccomp($price,$gold) == 1){
- Db::rollback();
- $this->error('对方金币不足');
- }
- }
- //有性别差,扣费
- if($price > 0){
- $rs = model('wallet')->lockChangeAccountRemain($kou_user, $get_user,'gold',-$price,11,'','user_match_video_log',$log_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- //另一方加钱,0收费
- if($money > 0 && $get_user_free == 0){
- $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,21,'','user_match_video_log',$log_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- Db::commit();
- $this->success('success');
- }
- //语音通话每分钟调用一次
- public function audio_onemin(){
- //检测用户
- $to_user_id = input_post('to_user_id');
- $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- //正常价格
- $price = config('site.audio_min_price'); //扣费金币
- $bili = config('site.money_to_gold'); //兑换比例
- $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
- $money = bcdiv($price,$bili,2); //对应人民币
- $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
- //发起用户的分数,被发起用户的分数。按性别给分
- $auth_level = 0;
- $tous_level = 0;
- //打分
- if($this->auth->gender == 0 && $this->auth->real_status == 1){
- $auth_level = 30;//实名女最高
- }
- if($this->auth->gender == 0 && $this->auth->real_status != 1){
- $auth_level = 20;//未实名女次之
- }
- if($this->auth->gender == 1){
- $auth_level = 10;//男性最低
- }
- if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
- $tous_level = 30;
- }
- if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
- $tous_level = 20;
- }
- if($to_user_info['gender'] == 1){
- $tous_level = 10;
- }
- //同性不收钱
- //都是男的,不扣钱
- //都是实名认证的女性,不扣钱
- //都是未实名认证的女性,不扣钱
- if($auth_level == $tous_level){
- $price = 0;$money = 0;
- }
- Db::startTrans();
- //记录日志
- $data = [
- 'user_id' => $this->auth->id,
- 'price' => $price,
- 'createtime' => time(),
- 'to_user_id' => $to_user_id,
- 'money' => $money,
- ];
- $log_id = Db::name('user_match_audio_log')->insertGetId($data);
- if(!$log_id){
- Db::rollback();
- $this->error('扣费失败');
- }
- //同性别,提前结束
- if($auth_level == $tous_level){
- Db::commit();
- $this->success('success');
- }
- //扣钱uid,收钱uid,收钱free_video
- //分数少扣钱,分数多收益
- if($auth_level < $tous_level){
- $kou_user = $this->auth->id;
- $get_user = $to_user_info['id'];
- $get_user_free = $to_user_info['free_audio'];
- }else{
- $kou_user = $to_user_info['id'];
- $get_user = $this->auth->id;
- $get_user_free = $this->auth->free_audio;
- }
- //需要扣别人的钱,判断钱是否购
- if($price > 0 && $kou_user != $this->auth->id){
- $gold = model('wallet')->getWallet($kou_user,'gold');
- if(bccomp($price,$gold) == 1){
- Db::rollback();
- $this->error('对方金币不足');
- }
- }
- //有性别差,扣费
- if($price > 0){
- $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- //另一方加钱,0收费
- if($money > 0 && $get_user_free == 0){
- $rs = model('wallet')->lockChangeAccountRemain($get_user, $kou_user,'money',$money,22,'','user_match_audio_log',$log_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- Db::commit();
- $this->success('success');
- }
- //打字聊天每句话调用一次
- public function typing_once(){
- //检测用户
- $to_user_id = input_post('to_user_id');
- $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- //正常价格
- $price = config('site.typing_min_price'); //扣费金币
- $bili = config('site.money_to_gold'); //兑换比例
- $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
- $money = bcdiv($price,$bili,2); //对应人民币
- $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
- //发起用户的分数,被发起用户的分数。按性别给分
- $auth_level = 0;
- $tous_level = 0;
- //打分
- if($this->auth->gender == 0 && $this->auth->real_status == 1){
- $auth_level = 30;//实名女最高
- }
- if($this->auth->gender == 0 && $this->auth->real_status != 1){
- $auth_level = 20;//未实名女次之
- }
- if($this->auth->gender == 1){
- $auth_level = 10;//男性最低
- }
- if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
- $tous_level = 30;
- }
- if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
- $tous_level = 20;
- }
- if($to_user_info['gender'] == 1){
- $tous_level = 10;
- }
- //同性不收钱
- //都是男的,不扣钱
- //都是实名认证的女性,不扣钱
- //都是未实名认证的女性,不扣钱
- if($auth_level == $tous_level){
- $price = 0;$money = 0;
- }
- //性别优势的人发起,免费
- if($auth_level > $tous_level){
- $price = 0;$money = 0;
- }
- Db::startTrans();
- //记录日志
- $data = [
- 'user_id' => $this->auth->id,
- 'price' => $price,
- 'createtime' => time(),
- 'to_user_id' => $to_user_id,
- 'money' => $money,
- ];
- $log_id = Db::name('user_match_typing_log')->insertGetId($data);
- if(!$log_id){
- Db::rollback();
- $this->error('扣费失败');
- }
- //同性别,提前结束
- if($auth_level == $tous_level){
- Db::commit();
- $this->success('success');
- }
- //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
- if($price == 0 && $money == 0){
- Db::commit();
- $this->success('success');
- }
- //扣钱uid,收钱uid,收钱free_video
- //分数少扣钱,分数多收益
- if($auth_level < $tous_level){
- $kou_user = $this->auth->id;
- $get_user = $to_user_info['id'];
- $get_user_free = $to_user_info['free_typing'];
- }else{
- //这种已经没有了
- $kou_user = $to_user_info['id'];
- $get_user = $this->auth->id;
- $get_user_free = $this->auth->free_typing;
- }
- //有性别差,扣费
- if($price > 0){
- $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- //另一方加钱,0收费
- if($money > 0 && $get_user_free == 0){
- $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,23,'','user_match_typing_log',$log_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- //tag任务赠送金币
- //搭讪奖励
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- Db::commit();
- $this->success('success');
- }
- //语音匹配
- public function getaudiouser(){
- //判断资格
- /*$start = strtotime(date('Y-m-d'));
- $end = $start + 86399;
- $map = [
- 'user_id' => $this->auth->id,
- 'createtime' => ['between',[$start,$end]],
- 'price' => 0,
- ];
- $check = Db::name('user_match_audio_log')->where($map)->find();*/
- $check = true;
- //已经用掉免费的了,判断金额
- if($check){
- $price = config('site.audio_min_price');
- $gold = model('wallet')->getWallet($this->auth->id,'gold');
- if($gold < $price){
- $this->error('您的金币已经不足,请充值');
- }
- }
- //找到互关的人,排除
- //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
- //dump($follow_me);
- //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
- //dump($my_follow);exit;
- //给出备选用户
- $map = [
- 'status' =>1, //未封禁用户
- 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
- 'is_online' => 0, //不在语聊间的
- 'is_livebc' => 0, //不在直播的
- 'is_active' => 1, //在线的
- //'real_status' => 1, //真人认证
- //'idcard_status' => 1, //实名认证
- 'open_match_audio' => 1, //打开语聊开关
- //'id' => ['NOT IN',$my_follow] //不是好友的
- ];
- $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
- $lists = $this->fliter_user($lists,10);
- $result = [];
- if(!empty($lists)){
- foreach($lists as $key => $val){
- $result[] = ['id'=>$val];
- }
- }
- //tag任务赠送金币
- //语音匹配奖励 +5金币
- if(!empty($result)){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
- if($task_rs === false){
- $this->error('完成任务赠送奖励失败');
- }
- }
- $this->success('success',$result);
- }
- //视频匹配
- public function getvideouser(){
- //判断资格
- /*$start = strtotime(date('Y-m-d'));
- $end = $start + 86399;
- $map = [
- 'user_id' => $this->auth->id,
- 'createtime' => ['between',[$start,$end]],
- 'price' => 0,
- ];
- $check = Db::name('user_match_video_log')->where($map)->find();*/
- $check = true;
- //已经用掉免费的了,判断金额
- if($check){
- $price = config('site.video_min_price');
- $gold = model('wallet')->getWallet($this->auth->id,'gold');
- if($gold < $price){
- $this->error('您的金币已经不足,请充值');
- }
- }
- //找到互关的人,排除
- //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
- //dump($follow_me);
- //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
- //dump($my_follow);exit;
- //给出备选用户
- $map = [
- 'status' =>1, //未封禁用户
- 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
- 'is_online' => 0, //不在语聊间的
- 'is_livebc' => 0, //不在直播的
- 'is_active' => 1, //在线的
- //'real_status' => 1, //真人认证
- //'idcard_status' => 1, //实名认证
- 'open_match_video' => 1, //打开视频开关的
- // 'id' => ['NOT IN',$my_follow] //不是好友的
- ];
- $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
- $lists = $this->fliter_user($lists,10);
- $result = [];
- if(!empty($lists)){
- foreach($lists as $key => $val){
- $result[] = ['id'=>$val];
- }
- }
- //tag任务赠送金币
- //视频匹配奖励 +5金币
- if(!empty($result)){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
- if($task_rs === false){
- $this->error('完成任务赠送奖励失败');
- }
- }
- $this->success('success',$result);
- }
- //聊天匹配
- public function gettypinguser(){
- //找到互关的人,排除
- //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
- //dump($follow_me);
- //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
- //dump($my_follow);exit;
- //给出备选用户
- $map = [
- 'status' =>1, //未封禁用户
- 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
- //'real_status' => 1, //真人认证
- //'idcard_status' => 1, //实名认证
- //'is_active' => 1, //在线的
- //打开聊天开关的
- 'open_match_typing' => 1, //打开文字聊天开关的
- //'id' => ['NOT IN',$my_follow] //不是好友的
- ];
- $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
- //$lists = $this->fliter_user($lists,100);
- $lists = array_column($lists,'id');
- $result = [];
- if(!empty($lists)){
- /*foreach($lists as $key => $val){
- $result[] = ['id'=>$val];
- }*/
- $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
- $result = list_domain_image($result,['avatar,audio_bio']);
- }
- //tag任务赠送金币
- //缘分匹配奖励 +5金币
- if(!empty($result)){
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
- if($task_rs === false){
- $this->error('完成任务赠送奖励失败');
- }
- }
- $this->success('success',$result);
- }
- //过滤规则
- private function fliter_user($lists,$number = 1){
- if(empty($lists)){
- return $lists;
- }
- //dump($lists);
- //过滤掉通话中的
- foreach($lists as $key => $val){
- if(redis_matching_get($val['id']) == 1){
- unset($lists[$key]);
- }
- }
- //预留全部
- $all_result = array_column($lists,'id');
- //dump($all_result);
- //提取同城的
- $citydata = [];
- foreach($lists as $key => $val){
- if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
- $citydata[] = $val['id'];
- }
- }
- //dump($citydata);
- //有标签交集的
- $tagdata = [];
- foreach($lists as $key => $val){
- if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
- $auth_tag_ids = explode(',',$this->auth->tag_ids);
- $val_tag_ids = explode(',',$val['tag_ids']);
- if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
- $tagdata[] = $val['id'];
- }
- }
- }
- //dump($tagdata);
- //双条件都满足
- $double_data = [];
- if(!empty($citydata) && !empty($tagdata)){
- $double_data = array_intersect($citydata,$tagdata);
- }
- //dump($double_data);
- if(count($double_data) >= $number){
- return $double_data;
- }
- //两种条件合并,去重。空数组合并没影响
- $merge_data = array_merge($citydata,$tagdata);
- $merge_data = array_flip(array_flip($merge_data));
- //dump($merge_data);
- if(count($merge_data) >= $number){
- return $merge_data;
- }
- return $all_result;
- }
- /**
- * 是否关注
- */
- public function isFollows() {
- $user_id = $this->request->request("user_id",0,"intval");
- if (!$user_id || $user_id<=0) {
- $this->error(__('Invalid parameters'));
- }
- $map = [
- 'uid' => $this->auth->id,
- 'follow_uid' => $user_id,
- ];
- $check = Db::name('user_follow')->where($map)->find();
- $data = [];
- if($check){
- $data["is_show_follow"] = 0;
- }else{
- $data["is_show_follow"] = 1;
- }
- $this->success("获取成功!",$data);
- }
- /**
- * 获取主播技能分类
- */
- public function getAnchorType() {
- $this->success("获取成功!",\app\common\model\UserAnchorType::select());
- }
- /**
- * 主播申请
- */
- public function anchorApply() {
- $this->error('不需要申请');
- /*$type_id = $this->request->request('type_id'); // 技能分类ID
- $desc = $this->request->request('desc'); // 申请备注
- if (!$type_id && !$desc) {
- $this->error(__('Invalid parameters'));
- }
- $useranchorModel = new \app\common\model\UserAnchor();
- $data = [];
- $data["user_id"] = $this->auth->id;
- $data["type_id"] = $type_id;
- if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
- $data["desc"] = $desc;
- $data["createtime"] = time();
- $res = $useranchorModel->insertGetId($data);
- if($res) {
- \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
- $this->success("申请发送成功!");
- } else {
- $this->error("网络错误,请稍后重试");
- }*/
- }
- /**
- * 获取当前用户信息
- */
- public function getMyUserInfo() {
- $userInfo = $this->auth->getUserinfo();
- //当月消费金额
- $redis = new Redis();
- $redisconfig = config("redis");
- $redis->connect($redisconfig["host"], $redisconfig["port"]);
- $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
- $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
- $this->success("获取成功!",$userInfo);
- }
- /**
- * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
- * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
- * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
- * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
- * @return float | false | string
- */
- private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
- if( empty( $point_1 ) || empty( $point_2 ) ){
- return false;
- }
- // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
- $p1_x = $point_1[0];
- $p1_y = $point_1[1];
- $p2_x = $point_2[0];
- $p2_y = $point_2[1];
- if(
- $p1_x < -180 || $p1_x > 180
- || $p2_x < -180 || $p2_x > 180
- || $p1_y < -90 || $p1_y > 90
- || $p2_y < -90 || $p2_y > 90
- ){
- return '0公里';
- }
- // 根据2点各自的坐标,计算2点之间直线距离的公式
- $distance = round(6378.138*2*asin(sqrt(pow(sin(( $p1_x *pi()/180-$p2_x*pi()/180)/2),2)+cos( $p1_x *pi()/180)*cos($p2_x*pi()/180)* pow(sin(( $p1_y *pi()/180-$p2_y*pi()/180)/2),2)))*1000);
- // 是否计算为字符串公里距离
- if( !$calc_as_string ){
- return (string)round( $distance / 1000 , 1 ) . '公里';
- }
- // 如果计算为字符串公里距离
- if( $distance / 1000 > 1 ){
- $k = (string)round( $distance / 1000 , 1 );
- $m = (string)$distance % 1000 ;
- $distance = "{$k}公里{$m}米";
- }
- else{
- $distance = "{$distance}米";
- }
- return $distance;
- }
- //地图api,根据两地坐标,获得两地距离,打卡用的
- //type=0直线,type=1开车
- private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
- $result = 0;
- $apiurl = 'https://restapi.amap.com/v3/distance?';
- $param = [
- 'key' => '398c424811d1a59beac2f915323d334e',
- 'origins' => $start_lon.','.$start_lat,
- 'destination' => $end_lon.','.$end_lat,
- 'type' => $type,
- 'output' => 'json',
- ];
- $apiurl .= http_build_query($param);
- $request_rs = json_decode(curl_get($apiurl),true);
- if(isset($request_rs['status']) && $request_rs['status'] == 1){
- if(isset($request_rs['results'][0]['distance']))
- {
- $result = $request_rs['results'][0]['distance'];
- }
- }
- //dump($result);
- return $result;
- }
- public function distance()
- {
- $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
- dump($a);
- $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
- dump($a);
- $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
- dump($b);
- $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
- dump($b);
- }
- //开通守护
- public function addguard() {
- // 接口防并发
- if (!$this->apiLimit(1, 1000)) {
- $this->error(__('Operation frequently'));
- }
- $user_id = input('user_id', 0, 'intval');// 守护对象
- if (!$user_id) {
- $this->error();
- }
- // 不可以守护给自己
- if($this->auth->id == $user_id) {
- $this->error("不可以守护自己");
- }
- //查询是否开通守护
- $count = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
- if ($count) {
- $this->error('已经开通守护了');
- }
- $giftvalue = config('site.guard_price');
- if ($giftvalue <= 0) {
- $this->error('守护金额异常~');
- }
- //被守护人信息
- $touserinfo = Db::name('user')->where('id',$user_id)->find();
- if (!$touserinfo) {
- $this->error("不存在的用户");
- }
- // 判断当前用户余额
- $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
- if($user_gold < $giftvalue) {
- $this->error("您的金币余额不足");
- }
- Db::startTrans();
- // 添加礼物守护记录表
- $data = [
- 'user_id' => $this->auth->id,
- 'user_to_id' => $user_id,
- 'price' => $giftvalue,
- 'createtime' => time(),
- ];
- $log_id = Db::name('user_guard')->insertGetId($data);
- if(!$log_id){
- Db::rollback();
- $this->error('守护失败');
- }
- if($giftvalue > 0){
- // 扣除当前用户余额
- $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_guard',$log_id);
- if($wallet_rs['status'] === false){
- Db::rollback();
- $this->error($wallet_rs['msg']);
- }
- // 添加守护用户余额
- $money_to_gold = config('site.money_to_gold');
- $gift_plat_scale = config('site.gift_plat_scale');
- $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
- $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
- $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_guard',$log_id,2);
- if($wallet_rs['status'] === false){
- Db::rollback();
- $this->error($wallet_rs['msg']);
- }
- //增加赠送用户上级余额
- if ($touserinfo['intro_uid']) {
- //获取返利比率
- $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
- $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
- if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
- //上级获得金额
- $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
- if ($intro_uid_money > 0) {
- $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人开通守护获赠奖励','gift_user_typing',$log_id);
- if($intro_result['status']===false)
- {
- Db::rollback();
- $this->error($intro_result['msg']);
- }
- }
- }
- }
- }
- //tag任务守护金币
- //搭讪奖励
- // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
- // if($task_rs === false){
- // Db::rollback();
- // $this->error('完成任务守护奖励失败');
- // }
- Db::commit();
- $this->success('守护成功');
- }
- //守护列表
- public function guardlist(){
- $user_id = input('user_id', 0, 'intval');
- if (!$user_id) {
- $this->error('您的网络开小差啦~');
- }
- $list = Db::name('user_guard')
- ->alias('a')
- ->join('user','a.user_id = user.id','LEFT')
- ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
- ->where('a.user_to_id',$user_id)->order('a.id desc')->autopage()->select();
- if (!$list) {
- $this->success('success', $list);
- }
- $list = list_domain_image($list,['avatar']);
- $time = time();
- foreach ($list as &$v) {
- $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
- }
- $this->success('success',$list);
- }
- //我的守护
- public function myguardlist(){
- $type = input('type', 0, 'intval'); //类型: 1我守护的 2守护我的
- if (!in_array($type, [1, 2])) {
- $this->error('您的网络开小差了');
- }
- $where = [];
- if ($type == 1) {
- $join = 'a.user_to_id = user.id';
- $where['a.user_id'] = $this->auth->id;
- } else {
- $join = 'a.user_id = user.id';
- $where['a.user_to_id'] = $this->auth->id;
- }
- $list = Db::name('user_guard')
- ->alias('a')
- ->join('user',$join,'LEFT')
- ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
- ->where($where)->order('a.id desc')->autopage()->select();
- if (!$list) {
- $this->success('success', $list);
- }
- $list = list_domain_image($list,['avatar']);
- $time = time();
- foreach ($list as &$v) {
- $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
- }
- $this->success('success',$list);
- }
- //打字聊天每句话调用一次
- public function chat_once(){
- if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
- $this->success('success',array('money'=>''));
- }
- if ($this->auth->gender == 0) { //女生不花钱
- $this->error('您的网络开小差啦~');
- }
- //检测用户
- $to_user_id = input_post('to_user_id');
- $to_user_info = Db::name('user')->field('id,intro_uid,real_status,gender,free_video,free_audio,free_typing,chat_price,is_kefu')->where('id',$to_user_id)->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
- $this->success('success',array('money'=>''));
- }
- if ($to_user_info['gender'] != 0) {
- $this->error('同性不能聊天~');
- }
- //验证金额
- $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
- if ($wallet_info['vip_endtime'] >= time()) { //会员
- $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
- //获取折扣
- $vip_chat_discount = config('site.vip_chat_discount');
- if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
- $price = ceil($price * $vip_chat_discount / 10);
- }
- } else {
- $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
- }
- //正常价格
- $bili = config('site.money_to_gold'); //兑换比例
- $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
- $money = bcdiv($price,$bili,2); //对应人民币
- $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
- $resArray['money'] = $money; //返回给前端的计算结果
- Db::startTrans();
- //记录日志
- $data = [
- 'user_id' => $this->auth->id,
- 'price' => $price,
- 'createtime' => time(),
- 'to_user_id' => $to_user_id,
- 'money' => $money,
- ];
- $log_id = Db::name('user_match_typing_log')->insertGetId($data);
- if(!$log_id){
- Db::rollback();
- $this->error('扣费失败');
- }
- //有性别差,扣费
- if($price > 0){
- $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,13,'文字聊天消费','user_match_typing_log',$log_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- //另一方加钱,0收费
- if($money > 0){
- $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,23,'文字聊天收益','user_match_typing_log',$log_id,2);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- $touserinfo = $to_user_info;
- //增加赠送用户上级余额
- if ($touserinfo['intro_uid']) {
- //获取返利比率
- $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
- $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
- if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
- //上级获得金额
- $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
- if ($intro_uid_money > 0) {
- $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人文字聊天获赠奖励','gift_user_typing',$log_id);
- if($intro_result['status']===false)
- {
- Db::rollback();
- $this->error($intro_result['msg']);
- }
- }
- }
- }
- }
- //增加亲密度
- $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
- if (!$user_intimacy_rs['status']) {
- Db::rollback();
- $this->error('您的网络开小差啦~');
- }
- //tag任务赠送金币
- //私信5名异性奖励
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- /*$task_rs = \app\common\model\TaskLog::tofinish($to_user_id,23);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }*/
- Db::commit();
- //发送消息
- if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
- $tenim = new \app\api\controller\Tenim;
- $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
- }
- $this->success('success',$resArray);
- }
- //语音通话每分钟调用一次
- public function voice_onemin(){
- if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
- $this->success('success');
- }
- if ($this->auth->gender == 0) { //女生不花钱
- $this->error('您的网络开小差啦~');
- }
- //检测用户
- $to_user_id = input_post('to_user_id');
- $request_id = input('request_id', '', 'trim'); //唯一请求标识
- $to_user_info = Db::name('user')->field('id,intro_uid,real_status,gender,free_video,free_audio,free_typing,voice_price,is_kefu')->where('id',$to_user_id)->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
- $this->success('success');
- }
- if ($to_user_info['gender'] != 0) {
- $this->error('同性不能聊天~');
- }
- //验证金额
- $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
- if ($wallet_info['vip_endtime'] >= time()) { //会员
- $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
- //获取折扣
- $vip_video_discount = config('site.vip_video_discount');
- if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
- $price = ceil($price * $vip_video_discount / 10);
- }
- } else {
- $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
- }
- //正常价格
- $bili = config('site.money_to_gold'); //兑换比例
- $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
- $money = bcdiv($price,$bili,2); //对应人民币
- $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
- Db::startTrans();
- //查询是否有匹配记录
- $user_match_audio_log_info = [];
- if ($request_id) {
- $user_match_audio_log_info = Db::name('user_match_audio_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
- }
- if ($user_match_audio_log_info) {
- //修改记录日志
- $data = [
- 'price' => $user_match_audio_log_info['price'] + $price,
- 'createtime' => time(),
- 'money' => $user_match_audio_log_info['money'] + $money,
- 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
- ];
- $log_id = Db::name('user_match_audio_log')->where(['id' => $user_match_audio_log_info['id'], 'createtime' => $user_match_audio_log_info['createtime']])->setField($data);
- if (!$log_id) {
- Db::rollback();
- $this->error('扣费失败');
- }
- } else {
- //添加记录日志
- $data = [
- 'user_id' => $this->auth->id,
- 'price' => $price,
- 'createtime' => time(),
- 'to_user_id' => $to_user_id,
- 'money' => $money,
- 'request_id' => $request_id,
- 'call_minutes' => 1
- ];
- $log_id = Db::name('user_match_audio_log')->insertGetId($data);
- if (!$log_id) {
- Db::rollback();
- $this->error('扣费失败');
- }
- }
- //有性别差,扣费
- if($price > 0){
- $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,12,'语音通话消费' . $data['call_minutes'] . '分钟','user_match_audio_log',$log_id, 0, $request_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- //另一方加钱,0收费
- if($money > 0){
- $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,22,'语音通话收益' . $data['call_minutes'] . '分钟','user_match_audio_log',$log_id,2, $request_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- $touserinfo = $to_user_info;
- //增加赠送用户上级余额
- if ($touserinfo['intro_uid']) {
- //获取返利比率
- $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
- $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
- if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
- //上级获得金额
- $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
- if ($intro_uid_money > 0) {
- $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人语音聊天获赠奖励' . $data['call_minutes'] . '分钟','gift_user_typing',$log_id, 0, $request_id);
- if($intro_result['status']===false)
- {
- Db::rollback();
- $this->error($intro_result['msg']);
- }
- }
- }
- }
- }
- //增加亲密度
- $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
- if (!$user_intimacy_rs['status']) {
- Db::rollback();
- $this->error('您的网络开小差啦~');
- }
- //tag任务赠送金币
- //与1名异性语音通话奖励
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,25);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,25);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- //发送消息
- if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
- $tenim = new \app\api\controller\Tenim;
- $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
- }
- Db::commit();
- $this->success('success');
- }
- //视频通话每分钟调用一次
- public function videochat_onemin(){
- if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
- $this->success('success');
- }
- if ($this->auth->gender == 0) { //女生不花钱
- $this->error('您的网络开小差啦~');
- }
- //检测用户
- $to_user_id = input_post('to_user_id');
- $request_id = input('request_id', '', 'trim'); //唯一请求标识
- $to_user_info = Db::name('user')->field('id,intro_uid,real_status,gender,free_video,free_audio,free_typing,video_price,is_kefu')->where('id',$to_user_id)->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
- $this->success('success');
- }
- if ($to_user_info['gender'] != 0) {
- $this->error('同性不能聊天~');
- }
- /* //检查是否免费过
- $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
- if (!$count) {
- //记录日志
- $data = [
- 'user_id' => $this->auth->id,
- 'price' => 0,
- 'createtime' => time(),
- 'to_user_id' => $to_user_id,
- 'money' => 0,
- ];
- $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
- if(!$log_id){
- $this->error('扣费失败');
- }
- $this->success('success');
- }*/
- //验证金额
- $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
- if ($wallet_info['vip_endtime'] >= time()) { //会员
- $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
- //获取折扣
- $vip_video_discount = config('site.vip_video_discount');
- if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
- $price = ceil($price * $vip_video_discount / 10);
- }
- } else {
- $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
- }
- //正常价格
- $bili = config('site.money_to_gold'); //兑换比例
- $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
- $money = bcdiv($price,$bili,2); //对应人民币
- $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
- Db::startTrans();
- //查询是否有匹配记录
- $user_match_video_log_info = [];
- if ($request_id) {
- $user_match_video_log_info = Db::name('user_match_video_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
- }
- if ($user_match_video_log_info) {
- //修改记录日志
- $data = [
- 'price' => $user_match_video_log_info['price'] + $price,
- 'createtime' => time(),
- 'money' => $user_match_video_log_info['money'] + $money,
- 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
- ];
- $log_id = Db::name('user_match_video_log')->where(['id' => $user_match_video_log_info['id'], 'createtime' => $user_match_video_log_info['createtime']])->setField($data);
- if (!$log_id) {
- Db::rollback();
- $this->error('扣费失败');
- }
- } else {
- //添加记录日志
- $data = [
- 'user_id' => $this->auth->id,
- 'price' => $price,
- 'createtime' => time(),
- 'to_user_id' => $to_user_id,
- 'money' => $money,
- 'request_id' => $request_id,
- 'call_minutes' => 1
- ];
- $log_id = Db::name('user_match_video_log')->insertGetId($data);
- if (!$log_id) {
- Db::rollback();
- $this->error('扣费失败');
- }
- }
- //有性别差,扣费
- if($price > 0){
- $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,11,'视频通话消费' . $data['call_minutes'] . '分钟','user_match_video_log',$log_id, 0, $request_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- }
- //另一方加钱,0收费
- if($money > 0){
- $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,21,'视频通话收益' . $data['call_minutes'] . '分钟','user_match_video_log',$log_id,2, $request_id);
- if($rs['status'] === false){
- Db::rollback();
- $this->error($rs['msg']);
- }
- $touserinfo = $to_user_info;
- //增加赠送用户上级余额
- if ($touserinfo['intro_uid']) {
- //获取返利比率
- $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
- $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
- if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
- //上级获得金额
- $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
- if ($intro_uid_money > 0) {
- $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人视频聊天获赠奖励' . $data['call_minutes'] . '分钟','gift_user_typing',$log_id, 0, $request_id);
- if($intro_result['status']===false)
- {
- Db::rollback();
- $this->error($intro_result['msg']);
- }
- }
- }
- }
- }
- //增加亲密度
- $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
- if (!$user_intimacy_rs['status']) {
- Db::rollback();
- $this->error('您的网络开小差啦~');
- }
- //tag任务赠送金币
- //与1名异性视频通话奖励
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,26);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,26);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- Db::commit();
- //发送消息
- if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
- $tenim = new \app\api\controller\Tenim;
- $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
- }
- $this->success('success');
- }
-
- //消息列表好友/密友
- public function intimacyfriends() {
- $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
- $where = [];
- /*if ($type == 0) {
- $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
- $mt_user = Db::name('user');
- // $mt_user_follow = Db::name('user_follow');
- $mt_user_intimacy = Db::name('user_intimacy');
- foreach ($list as &$v) {
- //查询亲密度
- if ($this->auth->gender == 1) {
- $where['uid'] = $this->auth->id;
- $where['other_uid'] = $v['user_id'];
- } else {
- $where['other_uid'] = $this->auth->id;
- $where['uid'] = $v['user_id'];
- }
- $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
- $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
- $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
- //查询对方信息
- $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
- $v['nickname'] = $user_info['nickname'];
- $v['avatar'] = one_domain_image($user_info['avatar']);
- $v['updatetime'] = get_last_time($v['updatetime']);
- $v['age'] = birthtime_to_age($user_info['birthday']);
- $v['gender'] = $user_info['gender'];
- $v['real_status'] = $user_info['real_status'];
- // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
- $v['status'] = 1;
- }
- } else {*/
- if ($this->auth->gender == 1) {
- $where['uid'] = $this->auth->id;
- $field = 'other_uid user_id, value, updatetime';
- } else {
- $where['other_uid'] = $this->auth->id;
- $field = 'uid user_id, value, updatetime';
- }
- if ($type == 1) { //密友
- $where['value'] = ['egt', 1000];
- } elseif ($type == 2) { //好友
- $where['value'] = ['egt', 100];
- } else { //消息列表好友
- $where['value'] = ['egt', 10];
- }
- $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
- $mt_user = Db::name('user');
- $mt_user_follow = Db::name('user_follow');
- foreach ($list as &$v) {
- $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
- $v['nickname'] = $user_info['nickname'];
- $v['avatar'] = one_domain_image($user_info['avatar']);
- $v['updatetime'] = get_last_time($v['updatetime']);
- $v['age'] = birthtime_to_age($user_info['birthday']);
- $v['gender'] = $user_info['gender'];
- $v['real_status'] = $user_info['real_status'];
- $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
- $v['is_active'] = $user_info['is_active'];
- }
- // }
- $this->success('success',$list);
- }
-
- //消息列表通话
- public function calllist() {
- if ($this->auth->gender == 1) {
- $list = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [11, 12]]])->order('id desc')->autopage()->select();
- } elseif ($this->auth->gender == 0) {
- $list = Db::name('user_money_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [21, 22]]])->order('id desc')->autopage()->select();
- } else {
- $this->success('success', []);
- }
- if (!$list) {
- $this->success('success', $list);
- }
- $arr = [];
- $mt_user_match_audio_log = Db::name('user_match_audio_log');
- $mt_user_match_video_log = Db::name('user_match_video_log');
- $mt_user = Db::name('user');
- foreach ($list as &$v) {
- $data = [];
- if ($this->auth->gender == 1) {
- if ($v['log_type'] == 11) { //视频通话
- $log_info = $mt_user_match_video_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
- $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
- } else { //语音通话
- $log_info = $mt_user_match_audio_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
- $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
- }
- } else {
- if ($v['log_type'] == 21) { //视频通话
- $log_info = $mt_user_match_video_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
- $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
- } else { //语音通话
- $log_info = $mt_user_match_audio_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
- $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
- }
- }
- $user_info = $mt_user->field('nickname, avatar,is_active')->where(['id' => $log_info['user_id']])->find();
- $data['user_id'] = $log_info['user_id'];
- $data['nickname'] = $user_info['nickname'];
- $data['avatar'] = one_domain_image($user_info['avatar']);
- $data['createtime'] = get_last_time($log_info['createtime']);
- $data['is_active'] = $user_info['is_active'];
- $arr[] = $data;
- }
- $this->success('success', $arr);
- }
- //查询对方用户收费价格和我的余额
- public function otheruserinfo(){
- $user_id = input('user_id', 0, 'intval');
- if (!$user_id) {
- $this->error('您的网络开小差啦~');
- }
- $field = [
- 'chat_price','voice_price','video_price','gender','is_kefu', 'open_match_audio', 'open_match_video'
- ];
- $info = Db::name('user')->field($field)->where('id',$user_id)->find();
- if ($info['is_kefu'] != 1 && $this->auth->is_kefu != 1) { //不是客服
- if ($info['gender'] == $this->auth->gender || $info['gender'] == -1 || $this->auth->gender == -1) {
- $this->error('性别存在问题');
- }
- }
- if ($this->auth->gender == 0) { //收费价格按照女号
- $info['chat_price'] = $this->auth->chat_price;
- $info['voice_price'] = $this->auth->voice_price;
- $info['video_price'] = $this->auth->video_price;
- $info['open_match_audio'] = $this->auth->open_match_audio;
- $info['open_match_video'] = $this->auth->open_match_video;
- }
- $info['chat_price_vip'] = $info['chat_price']; //vip价格
- $info['voice_price_vip'] = $info['voice_price'];
- $info['video_price_vip'] = $info['video_price'];
- $info['is_vip'] = 0; //是否vip: 0否 1是
- //获取聊天折扣
- $vip_chat_discount = config('site.vip_chat_discount');
- if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
- $info['vip_chat_discount'] = $vip_chat_discount;
- } else {
- $info['vip_chat_discount'] = 10;
- }
- //获取语音视频折扣
- $vip_video_discount = config('site.vip_video_discount');
- if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
- $info['vip_voice_discount'] = config('site.vip_video_discount'); //语音
- $info['vip_video_discount'] = config('site.vip_video_discount'); //视频
- } else {
- $info['vip_voice_discount'] = 10;
- $info['vip_video_discount'] = 10;
- }
- //获取聊天折扣
- $info['chat_price_vip'] = ceil($info['chat_price'] * $info['vip_chat_discount'] / 10);
- //获取语音折扣
- $info['voice_price_vip'] = ceil($info['voice_price'] * $info['vip_voice_discount'] / 10);
- //获取视频折扣
- $info['video_price_vip'] = ceil($info['video_price'] * $info['vip_video_discount'] / 10);
- if ($this->auth->gender == 0) { //查询男号余额和vip
- $wallet_info = Db::name('user_wallet')->where(['user_id' => $user_id])->find();
- } else {
- $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
- }
- if ($wallet_info['vip_endtime'] >= time()) {
- $info['is_vip'] = 1;
- }
- $info['gold'] = $wallet_info['gold'];
- $info['plat_scale'] = config('site.gift_plat_scale'); //平台抽成百分比
- $info['money_to_gold'] = config('site.money_to_gold'); //一元人民币兑换金币数量
- $this->success('success',$info);
- }
-
- //亲密度等级信息
- public function intimacylevel() {
- $user_id = input('user_id', 0, 'intval'); //对方id
- if (!$user_id) {
- $this->error('参数缺失');
- }
- if ($this->auth->gender == 0) { //女用户
- $where['uid'] = $user_id;
- $where['other_uid'] = $this->auth->id;
- } else { //男用户
- $where['uid'] = $this->auth->id;
- $where['other_uid'] = $user_id;
- }
- $level = 0; //当前等级
- $level_name = ''; //当前等级名称
- $qinmi_sum = 0; //当前亲密度
- $next_level_diff = 0; //距下一等级亲密度差值
- //亲密度等级列表
- $list = Db::name('intimacy_level')->field('name,level')->order('value')->select();
- //当前亲密度信息
- $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
- if ($user_intimacy_info) {
- //当前亲密度
- $qinmi_sum = $user_intimacy_info['value'];
- if ($list) {
- //当前等级信息
- $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('id desc')->find();
- if ($level_info) {
- $level = $level_info['level'];
- $level_name = $level_info['name'];
- }
- //下一等级信息
- $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
- if ($next_level_info) {
- $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
- }
- }
- } else {
- $next_level_diff = Db::name('intimacy_level')->order('value')->value('value');
- }
- if ($list) {
- foreach ($list as &$v) {
- if ($v['level'] < $level) {
- $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
- } elseif ($v['level'] == $level) {
- $v['is_unlock'] = 2;
- } else {
- $v['is_unlock'] = 3;
- }
- }
- }
- $data['level'] = $level; //当前等级
- $data['level_name'] = $level_name; //当前等级名称
- $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
- $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
- $data['level_list'] = $list; //等级列表
- $this->success('亲密度等级信息', $data);
- }
- //语音视频随聊
- public function getrandomuser() {
- $type = input('type', 0, 'intval'); //类型:1语音 2视频
- if (!in_array($type, [1, 2, 3])) {
- $this->error('您的网络开小差了');
- }
- $size = input('size',0,'intval');// 是否查 10 条
- $size = $size > 0 ? 1 : 0;
- //给出备选用户
- $map = [
- 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
- 'is_active' => 1, //在线的
- 'status' =>1, //未封禁用户
- // 'is_online' => 0, //不在语聊间的
- 'is_livebc' => 0, //不在直播的
- // 'real_status' => 1, //真人认证
- // 'idcard_status' => 1, //实名认证
- // 'id' => ['NOT IN',$my_follow] //不是好友的
- 'is_kefu' => 0, //不是客服
- ];
- if ($this->auth->gender == 1) {
- $map['real_status|idcard_status'] = 1; //真人认证或实名认证
- }
- if ($type == 1) {
- $map['open_match_audio'] = 1;
- } elseif ($type == 2) {
- $map['open_match_video'] = 1;
- }
- $key = md5(json_encode($map));// 根据搜索条件做Key
- $lists = Cache::remember("getrandomuser_{$key}_{$size}",function () use ($map,$size){
- $query = Db::name('user')
- ->field('id,nickname,username,avatar')
- ->where($map)
- ->order('is_active desc, active_time desc');
- if ($size == 1){
- $query->limit(10);
- }else{
- $query->page($this->page,100);
- }
- $lists = $query->select();
- //$lists = $this->fliter_user($lists,100);
- $lists = list_domain_image($lists,['avatar,audio_bio']);
- $mt_user_greet_content = Db::name('user_greet_content');
- foreach ($lists as &$v) {
- $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
- if ($info) {
- if ($info['type'] == 0) {
- $v['greet_content'] = $info['content'];
- } elseif ($info['type'] == 1) {
- $v['greet_content'] = '[语音]';
- } elseif ($info['type'] == 2) {
- $v['greet_content'] = '[图片]';
- }
- } else {
- $v['greet_content'] = '';
- }
- }
- return $lists;
- },2);
- $count = Db::name('user')->where(['is_active' => 1])->count('id');
- $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
- $return_data['list'] = $lists;
- $this->success('success',$return_data);
- }
- //语音视频随聊
- public function getrandomuserbak() {
- $type = input('type', 0, 'intval'); //类型:1语音 2视频
- if (!in_array($type, [1, 2, 3])) {
- $this->error('您的网络开小差了');
- }
- //找到互关的人,排除
- //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
- //dump($follow_me);
- //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
- //dump($my_follow);exit;
- //给出备选用户
- $map = [
- 'status' =>1, //未封禁用户
- 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
- // 'is_online' => 0, //不在语聊间的
- 'is_livebc' => 0, //不在直播的
- 'is_active' => 1, //在线的
- // 'real_status' => 1, //真人认证
- // 'idcard_status' => 1, //实名认证
- // 'id' => ['NOT IN',$my_follow] //不是好友的
- 'is_kefu' => 0, //不是客服
- ];
- if ($this->auth->gender == 1) {
- $map['real_status|idcard_status'] = 1; //真人认证或实名认证
- }
- if ($type == 1) {
- $map['open_match_audio'] = 1;
- } elseif ($type == 2) {
- $map['open_match_video'] = 1;
- }
- $lists = Db::name('user')
- ->field('id,nickname,username,avatar')
- ->where($map)
- ->order('is_active desc, active_time desc')
- ->page($this->page,100)
- ->select();
- //$lists = $this->fliter_user($lists,100);
- $lists = list_domain_image($lists,['avatar,audio_bio']);
- $mt_user_greet_content = Db::name('user_greet_content');
- foreach ($lists as &$v) {
- $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
- if ($info) {
- if ($info['type'] == 0) {
- $v['greet_content'] = $info['content'];
- } elseif ($info['type'] == 1) {
- $v['greet_content'] = '[语音]';
- } elseif ($info['type'] == 2) {
- $v['greet_content'] = '[图片]';
- }
- } else {
- $v['greet_content'] = '';
- }
- }
- $count = Db::name('user')->where(['is_active' => 1])->count('id');
- $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
- $return_data['list'] = $lists;
- $this->success('success',$return_data);
- }
- //查询免费体验视频通话用户信息
- public function getfreevideouserinfo() {
- $to_user_id = input('to_user_id', 0, 'intval');
- $to_user_info = Db::name('user')->field('id,gender,nickname,avatar,birthday,height,bio')->where(['id' => $to_user_id, 'is_kefu' => 0])->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- if ($to_user_info['gender'] == $this->auth->gender) {
- $this->error('同性不能聊天~');
- }
- $to_user_info['desc'] = '';
- $age = birthtime_to_age($to_user_info['birthday']);
- if ($age > 0) {
- $to_user_info['desc'] = $age . '岁';
- } else {
- $to_user_info['desc'] = '18岁';
- }
- if ($to_user_info['height']) {
- $to_user_info['desc'] .= ' | ' . $to_user_info['height'];
- }
- //查询是否免费过
- $to_user_info['free_count'] = 1;//Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
- $this->success('信息', $to_user_info);
- }
- //免费体验视频通话1分钟
- public function videochat_onemin_free(){
- $this->success('success');
- if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
- $this->success('success');
- }
- //检查是否免费过
- $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
- if ($count) {
- $this->error('已经免费体验过');
- }
- //检测用户
- $to_user_id = input_post('to_user_id');
- $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing,video_price,is_kefu')->where('id',$to_user_id)->find();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
- $this->success('success');
- }
- if ($to_user_info['gender'] == $this->auth->gender) {
- $this->error('同性不能聊天~');
- }
- //记录日志
- $data = [
- 'user_id' => $this->auth->id,
- 'price' => 0,
- 'createtime' => time(),
- 'to_user_id' => $to_user_id,
- 'money' => 0,
- ];
- $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
- if(!$log_id){
- $this->error('扣费失败');
- }
- $this->success('success');
- }
- //男性非会员解锁聊天
- public function unlockchat() {
- // 接口防并发
- if (!$this->apiLimit(1, 1000)) {
- $this->error(__('Operation frequently'));
- }
- //男性非会员是否已开通聊天
- if ($this->auth->gender == 0) {
- $this->error('不需要解锁');
- }
- $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
- if ($vip_endtime > time()) {
- $this->error('不需要解锁');
- }
- $user_id = input('user_id', 0, 'intval');//对方id
- if (!$user_id) {
- $this->error();
- }
- // 不可以守护给自己
- if($this->auth->id == $user_id) {
- $this->error("不可以解锁自己");
- }
- //查询是否解锁过
- $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
- if ($user_chat_unlock) {
- $this->error('已经解锁过了');
- }
- $giftvalue = config('site.unlock_chat_gold');
- if ($giftvalue <= 0) {
- $this->error('解锁金额异常~');
- }
- //被解锁人信息
- $touserinfo = Db::name('user')->where('id',$user_id)->find();
- if (!$touserinfo) {
- $this->error("不存在的用户");
- }
- // 判断当前用户余额
- $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
- if($user_gold < $giftvalue) {
- $this->error("您的金币余额不足");
- }
- Db::startTrans();
- //添加解锁记录表
- $data = [
- 'user_id' => $this->auth->id,
- 'user_to_id' => $user_id,
- 'price' => $giftvalue,
- 'createtime' => time(),
- ];
- $log_id = Db::name('user_chat_unlock')->insertGetId($data);
- if(!$log_id){
- Db::rollback();
- $this->error('解锁失败');
- }
- if($giftvalue > 0){
- // 扣除当前用户余额
- $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_chat_unlock',$log_id);
- if($wallet_rs['status'] === false){
- Db::rollback();
- $this->error($wallet_rs['msg']);
- }
- // 添加守护用户余额
- $money_to_gold = config('site.money_to_gold');
- $gift_plat_scale = config('site.gift_plat_scale');
- $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
- $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
- $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_chat_unlock',$log_id,2);
- if($wallet_rs['status'] === false){
- Db::rollback();
- $this->error($wallet_rs['msg']);
- }
- //增加赠送用户上级余额
- if ($touserinfo['intro_uid']) {
- //获取返利比率
- $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
- $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
- if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
- //上级获得金额
- $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
- if ($intro_uid_money > 0) {
- $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人解锁聊天获赠奖励','gift_user_typing',$log_id);
- if($intro_result['status']===false)
- {
- Db::rollback();
- $this->error($intro_result['msg']);
- }
- }
- }
- }
- }
- //tag任务守护金币
- //搭讪奖励
- // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
- // if($task_rs === false){
- // Db::rollback();
- // $this->error('完成任务守护奖励失败');
- // }
- Db::commit();
- $this->success('解锁成功');
- }
- }
|