Usercenter.php 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Cache;
  5. use think\Db;
  6. use app\common\model\wallet;
  7. use Redis;
  8. /**
  9. * 会员中心,不是个人中心
  10. */
  11. class Usercenter extends Api
  12. {
  13. protected $noNeedLogin = ['test','testredis'];
  14. protected $noNeedRight = '*';
  15. protected $allowFields = [
  16. 'id',
  17. 'username',
  18. 'nickname',
  19. //'truename',//
  20. 'email',
  21. 'mobile',
  22. 'avatar',
  23. 'real_status',
  24. 'gender',
  25. 'height',
  26. 'weight',
  27. 'birthday',
  28. 'bio',
  29. 'audio_bio',
  30. //'alipay_account',//
  31. 'idcard_status',
  32. 'is_active',
  33. 'longitude',
  34. 'latitude',
  35. 'cityname',
  36. 'photo_images',
  37. 'education_id',
  38. 'hobby_ids',
  39. 'job_id',
  40. 'marital_id',
  41. 'tag_ids',
  42. 'wages_id',
  43. 'hometown_cityid',
  44. 'wechat_account',
  45. 'secretvideo_status',
  46. 'character_id',
  47. 'constellation_id',
  48. 'stature_id',
  49. 'is_appointment',
  50. 'chat_price',
  51. 'voice_price',
  52. 'video_price',
  53. 'greet_voice',
  54. 'greet_chat',
  55. 'is_kefu',
  56. 'is_hideaddress', 'is_recommend','is_cohabit', 'live_id', 'is_house', 'car_id', 'chest_id', 'waist'
  57. ];
  58. public function testredis(){
  59. //redis_matching_set(1,125);
  60. dump(redis_matching_get(1));
  61. $a = cache('?mt_matching_uid_1','',['type'=>'Redis']);
  62. dump($a);
  63. }
  64. public function test(){
  65. $a = [1,4,10,22,66,36,102,45,23,52,35,76,7];
  66. $b = [1,10,7,102];
  67. $c = [10,102];
  68. //dump(array_intersect($a,$b));
  69. $data = array_merge($c,$b);
  70. dump($data);
  71. dump(array_flip(array_flip($data)));
  72. dump(array_flip([]));
  73. }
  74. //获取他人用户信息,留下足迹
  75. public function getuserinfo(){
  76. $uid = input_post('uid',0);
  77. $userinfo = Db::name('user')->field($this->allowFields)->where('id',$uid)->find();
  78. if(!$userinfo){
  79. $this->error('不存在的用户');
  80. }
  81. //用户数据
  82. $userinfo = info_domain_image($userinfo,['avatar','photo_images']);
  83. $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$uid)->find();
  84. $secretvideo = Db::name('user_secretvideo')->where('user_id',$uid)->find();
  85. $new_data = [
  86. 'age' => birthtime_to_age($userinfo['birthday']),
  87. 'truename' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['truename'])) ? $idcard_confirm['truename'] : '',
  88. 'alipay_account' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['alipay_account'])) ? $idcard_confirm['alipay_account'] : '',
  89. // 'secretvideo' => ($userinfo['secretvideo_status'] == 1 && isset($secretvideo['secretvideo'])) ? $secretvideo['secretvideo'] : '',
  90. ];
  91. //亲密度,登录用户给当前用户花了多少钱
  92. /* $gift_map = [
  93. 'user_id' => $this->auth->id,
  94. 'user_to_id' => $uid,
  95. ];
  96. $gift_user_typing = Db::name('gift_user_typing')->where($gift_map)->sum('price');//文字聊天送礼物
  97. $gift_user_party = Db::name('gift_user_party')->where($gift_map)->sum('value');//派对音聊送礼物
  98. $gift_user_livebc = Db::name('gift_user_livebc')->where($gift_map)->sum('price');//直播送礼物
  99. $match_map_str = '(user_id = '.$this->auth->id.' and to_user_id = '.$uid.') or (user_id = '.$uid.' and to_user_id = '.$this->auth->id.')';
  100. $match_typing = Db::name('user_match_typing_log')->where($match_map_str)->sum('price'); //聊天
  101. $match_audio = Db::name('user_match_audio_log')->where($match_map_str)->sum('price'); //语音
  102. $match_video = Db::name('user_match_video_log')->where($match_map_str)->sum('price'); //视频
  103. $new_data['qinmi_sum'] = $qinmi_sum = $gift_user_typing + $gift_user_party + $gift_user_livebc + $match_typing + $match_audio + $match_video;*/
  104. if ($this->auth->gender == 1) {
  105. $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $this->auth->id, 'other_uid' => $uid])->value('value');
  106. } elseif ($this->auth->gender == 0) {
  107. $qinmi_sum = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $this->auth->id])->value('value');
  108. } else {
  109. $qinmi_sum = 0;
  110. }
  111. $new_data['qinmi_sum'] = $qinmi_sum ? :0;
  112. //解锁开关
  113. /*$new_data['isshow_unlock_wechataccount'] = $qinmi_sum >= 15 ? 1 : 0; //满足15亲密值才展示
  114. if(config('site.open_unlock_wechataccount') == 0){
  115. $new_data['isshow_unlock_wechataccount'] = 0; //总开关,强制隐藏
  116. }
  117. $new_data['isshow_unlock_secretvideo'] = $qinmi_sum >= 15 ? 1 : 0; //满足15亲密值才展示
  118. $new_data['isshow_unlock_secretvideo'] = 1; //又不受限制了
  119. //上次解锁过期日期
  120. $check_map = [
  121. 'user_id' => $this->auth->id,
  122. 'to_user_id' => $uid,
  123. ];
  124. $order_secretvideo = Db::name('order_secretvideo')->where($check_map)->order('id desc')->value('endtime');
  125. $order_wechataccount = Db::name('order_wechataccount')->where($check_map)->order('id desc')->value('endtime');
  126. $new_data['unlock_secretvideo_endtime'] = !empty($order_secretvideo) ? $order_secretvideo : 0;
  127. $new_data['unlock_secretvideo_status'] = $new_data['unlock_secretvideo_endtime'] > time() ? 1 : 0;
  128. $new_data['unlock_wechataccount_endtime'] = !empty($order_wechataccount) ? $order_wechataccount : 0;
  129. $new_data['unlock_wechataccount_status'] = $new_data['unlock_wechataccount_endtime'] > time() ? 1 : 0;*/
  130. //提示语而已
  131. /* $new_data['unlock_secretvideo_notice'] = '是否花费'.config('site.unlock_secretvideo').'金币解锁一周(或年费vip可每日免费解锁一次)?';
  132. $new_data['unlock_wechataccount_notice'] = '是否花费'.config('site.unlock_wechataccount').'金币解锁一周(或年费vip可每日免费解锁一次)?';*/
  133. //合并
  134. $userinfo = array_merge($userinfo,$new_data);
  135. //枚举
  136. $userinfo['education'] = Db::name('enum_education')->where('id',$userinfo['education_id'])->value('name');
  137. $userinfo['education'] = $userinfo['education'] ? : '';
  138. $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$userinfo['hobby_ids'])->field(['id','name'])->select();
  139. $userinfo['job'] = Db::name('enum_job')->where('id',$userinfo['job_id'])->value('name');
  140. $userinfo['job'] = $userinfo['job'] ? : '';
  141. $userinfo['marital'] = Db::name('enum_marital')->where('id',$userinfo['marital_id'])->value('name');
  142. $userinfo['marital'] = $userinfo['marital'] ? : '';
  143. $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
  144. $userinfo['wages'] = Db::name('enum_wages')->where('id',$userinfo['wages_id'])->value('name');
  145. $userinfo['wages'] = $userinfo['wages'] ? : '';
  146. $userinfo['character'] = Db::name('enum_character')->where('id',$userinfo['character_id'])->value('name');
  147. $userinfo['character'] = $userinfo['character'] ? : '';
  148. $userinfo['constellation'] = Db::name('enum_constellation')->where('id',$userinfo['constellation_id'])->value('name');
  149. $userinfo['constellation'] = $userinfo['constellation'] ? : '';
  150. $userinfo['stature'] = Db::name('enum_stature')->where('id',$userinfo['stature_id'])->value('name');
  151. $userinfo['stature'] = $userinfo['stature'] ? : '';
  152. $userinfo['live'] = Db::name('enum_live')->where('id',$userinfo['live_id'])->value('name');
  153. $userinfo['live'] = $userinfo['live'] ? : '';
  154. $userinfo['car'] = Db::name('enum_car')->where('id',$userinfo['car_id'])->value('name');
  155. $userinfo['car'] = $userinfo['car'] ? : '';
  156. $userinfo['chest'] = Db::name('enum_chest')->where('id',$userinfo['chest_id'])->value('name');
  157. $userinfo['chest'] = $userinfo['chest'] ? : '';
  158. //家乡
  159. $userinfo['hometown_city'] = Db::name('area')->where('id',$userinfo['hometown_cityid'])->value('name');
  160. $userinfo['hometown_city'] = ($userinfo['hometown_city'] && $userinfo['is_hideaddress'] == 0) ? $userinfo['hometown_city'] : '';
  161. //vip
  162. $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime');
  163. $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0;
  164. //是否喜欢和关注
  165. $is_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>$uid])->find();
  166. $userinfo['is_follow'] = $is_follow ? 1 : 0;
  167. $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find();
  168. $userinfo['is_like'] = $is_like ? 1 : 0;
  169. //是否拉黑
  170. $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
  171. $userinfo['is_black'] = $is_black ? 1 : 0;
  172. //关注人数,粉丝人数
  173. $follow_num = Db::name('user_follow')->where(['uid'=>$this->auth->id])->count('id');
  174. $fans_num = Db::name('user_follow')->where(['follow_uid'=>$this->auth->id])->count('id');
  175. $userinfo['follow_num'] = $follow_num;
  176. $userinfo['fans_num'] = $fans_num;
  177. //查询是否打过招呼
  178. $count = Db::name('user_greet')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  179. if ($count) {
  180. $userinfo['is_chat'] = 1; //是否打过招呼: 1是 0否
  181. } else {
  182. $userinfo['is_chat'] = 0; //是否打过招呼: 1是 0否
  183. }
  184. //守护数量和是否已经守护
  185. $userinfo['guard_num'] = Db::name('user_guard')->where(['user_to_id' => $uid])->count('id');
  186. $userinfo['is_guard'] = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  187. //查询财富等级和魅力等级
  188. $wallet_info = Db::name('user_wallet')->where(['user_id' => $uid])->find();
  189. $wealth_level = Db::name('wealth_level')->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
  190. if ($wealth_level) {
  191. $userinfo['wealth_level'] = $wealth_level['name'];
  192. } else {
  193. $userinfo['wealth_level'] = '';
  194. }
  195. $charm_level = Db::name('charm_level')->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
  196. if ($charm_level) {
  197. $userinfo['charm_level'] = $charm_level['name'];
  198. } else {
  199. $userinfo['charm_level'] = '';
  200. }
  201. //开通守护消耗金币数量
  202. $userinfo['guard_price'] = config('site.guard_price') ? : 0;
  203. //男性非会员是否已开通聊天
  204. // $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  205. // $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $uid])->count('id');
  206. // if ($this->auth->gender == 0 || $vip_endtime > time() || $user_chat_unlock) {
  207. $userinfo['is_chat_unlock'] = 1; //已解锁
  208. // } else {
  209. // $userinfo['is_chat_unlock'] = 0;
  210. // }
  211. //男性非会员解锁聊天所需金币数量
  212. $userinfo['unlock_chat_gold'] = config('site.unlock_chat_gold') > 0 ? config('site.unlock_chat_gold') : 10;
  213. //动态信息
  214. $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();
  215. if ($dongtai) {
  216. $dongtai_image = [];
  217. foreach ($dongtai as &$v) {
  218. $arr['type'] = $v['type'];
  219. if ($v['type'] == 1) {
  220. //图片
  221. $images_url = explode(',', $v['images']);
  222. foreach ($images_url as &$value) {
  223. $arr['images'] = one_domain_image($value);
  224. array_push($dongtai_image, $arr);
  225. if (count($dongtai_image) == 3) {
  226. break 2;
  227. }
  228. }
  229. } else {
  230. //视频
  231. $images_url = explode('.', $v['images']);
  232. unset($images_url[count($images_url) - 1]);
  233. $arr['images'] = join('.', $images_url) . '_0.jpg';
  234. $arr['images'] = one_domain_image($arr['images']);
  235. array_push($dongtai_image, $arr);
  236. if (count($dongtai_image) == 3) {
  237. break;
  238. }
  239. }
  240. }
  241. $userinfo['dongtai_image'] = $dongtai_image;
  242. // $dongtai = join(',', $dongtai);
  243. // $dongtai = explode(',', $dongtai);
  244. // $dongtai = array_slice($dongtai, 0, 3);
  245. // $dongtai = join(',', $dongtai);
  246. // $userinfo['dongtai_image'] = one_domain_image($dongtai);
  247. // $userinfo['dongtai_image'] = explode(',', $userinfo['dongtai_image']);
  248. } else {
  249. $userinfo['dongtai_image'] = [];
  250. }
  251. if ($this->auth->id != $uid) {
  252. //查看别人信息,就要留下痕迹
  253. $data = [
  254. 'uid' => $this->auth->id,
  255. 'to_uid' => $uid,
  256. ];
  257. $check = Db::name('user_visit')->where($data)->find();
  258. if ($check) {
  259. Db::name('user_visit')->where($data)->update(['number' => $check['number'] + 1, 'updatetime' => time()]);
  260. } else {
  261. $data['number'] = 1;
  262. $data['updatetime'] = time();
  263. Db::name('user_visit')->insertGetId($data);
  264. }
  265. }
  266. $this->success('success',$userinfo);
  267. }
  268. //这里不用连user_active表,完全使用user表的active_time,user_active表只做离线用
  269. //同城
  270. public function samecity(){
  271. $gender = input_post('gender','all');
  272. $agemin = input_post('agemin',0);
  273. $agemax = input_post('agemax',100);
  274. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  275. // $this->success('success',[]);
  276. }
  277. $map = [
  278. 'user.status' => 1,
  279. // 'user.cityname' => $this->auth->cityname,
  280. 'user.id' => ['neq',$this->auth->id],
  281. // 'user.longitude' => ['neq',''],
  282. // 'user.latitude' => ['neq',''],
  283. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  284. 'user.active_time' => ['gt',time()-86400],
  285. ];
  286. if($gender != 'all'){
  287. $map['user.gender'] = $gender;
  288. }
  289. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  290. //dump($map);
  291. $field = [
  292. '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'
  293. ];
  294. $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
  295. //dump($list);
  296. $list = list_domain_image($list,['avatar']);
  297. foreach($list as $key => $one){
  298. $one['age'] = birthtime_to_age($one['birthday']);
  299. // $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  300. $one['distance'] = rand(0,10).'km';
  301. //状态
  302. $one['active_text'] = '刚刚离线';
  303. if($one['active_time'] > time()-21600){
  304. $one['active_text'] = '1小时内在线';
  305. }
  306. if($one['active_time'] > time()-3600){
  307. $one['active_text'] = '在线';
  308. }
  309. $list[$key] = $one;
  310. }
  311. $this->success('success',$list);
  312. }
  313. //附近
  314. public function nearuser(){
  315. $gender = input_post('gender','all');
  316. $agemin = input_post('agemin',0);
  317. $agemax = input_post('agemax',100);
  318. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  319. // $this->success('success',[]);
  320. }
  321. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  322. $map = [
  323. 'user.status' => 1,
  324. ////'user.cityname' => $this->auth->cityname,
  325. 'user.id' => ['neq',$this->auth->id],
  326. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  327. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  328. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  329. 'user.active_time' => ['gt',time()-86400],
  330. ];
  331. if($gender != 'all'){
  332. $map['user.gender'] = $gender;
  333. }
  334. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  335. //dump($map);
  336. $field = [
  337. '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'
  338. ];
  339. $list = Db::name('user')->alias('user')->field($field)->where($map)->order('user.active_time desc')->autopage()->select();
  340. //dump($list);exit;
  341. $list = list_domain_image($list,['avatar']);
  342. foreach($list as $key => $one){
  343. $one['age'] = birthtime_to_age($one['birthday']);
  344. //$one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  345. $one['distance'] = rand(0,10).'km';
  346. //状态
  347. $one['active_text'] = '刚刚离线';
  348. if($one['active_time'] > time()-21600){
  349. $one['active_text'] = '1小时内在线';
  350. }
  351. if($one['active_time'] > time()-3600){
  352. $one['active_text'] = '在线';
  353. }
  354. $list[$key] = $one;
  355. }
  356. $this->success('success',$list);
  357. }
  358. //因为接受者拿不到发起者的uid,废弃了
  359. //视频和语音,接收方使用,如果是性别劣势方,检查钱是否够用
  360. public function video_audio_moneycheck(){
  361. //检测用户,发起方的uid
  362. $to_user_id = input_post('from_user_id');
  363. $to_user_info = Db::name('user')->field('id,real_status,gender')->where('id',$to_user_id)->find();
  364. if(!$to_user_info){
  365. $this->error('不存在的用户');
  366. }
  367. //扣费金币
  368. $type = input_post('type','video'); //类型
  369. $price = $type == 'video' ? config('site.video_min_price') : config('site.audio_min_price');
  370. //发起用户的分数,被发起用户的分数。按性别给分
  371. $auth_level = 0;
  372. $tous_level = 0;
  373. //打分
  374. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  375. $auth_level = 30;//实名女最高
  376. }
  377. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  378. $auth_level = 20;//未实名女次之
  379. }
  380. if($this->auth->gender == 1){
  381. $auth_level = 10;//男性最低
  382. }
  383. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  384. $tous_level = 30;
  385. }
  386. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  387. $tous_level = 20;
  388. }
  389. if($to_user_info['gender'] == 1){
  390. $tous_level = 10;
  391. }
  392. //同性不收钱
  393. //都是男的,不扣钱
  394. //都是实名认证的女性,不扣钱
  395. //都是未实名认证的女性,不扣钱
  396. if($auth_level == $tous_level){
  397. $price = 0;
  398. $this->success('success');
  399. }
  400. //扣钱uid,收钱uid,收钱free_video
  401. //分数少扣钱,分数多收益
  402. if($auth_level < $tous_level){
  403. $kou_user = $this->auth->id;
  404. }else{
  405. $kou_user = $to_user_info['id'];
  406. }
  407. //需要扣我的(接收方的)钱,判断钱是否够
  408. if($price > 0 && $kou_user == $this->auth->id){
  409. Db::startTrans();
  410. $gold = model('wallet')->getWallet($kou_user,'gold');
  411. if(bccomp($price,$gold) == 1){
  412. Db::rollback();
  413. $this->error('金币不足');
  414. }
  415. Db::commit();
  416. }
  417. $this->success('success');
  418. }
  419. //视频通话每分钟调用一次
  420. public function video_onemin(){
  421. //检测用户
  422. $to_user_id = input_post('to_user_id');
  423. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  424. if(!$to_user_info){
  425. $this->error('不存在的用户');
  426. }
  427. //正常价格
  428. $price = config('site.video_min_price'); //扣费金币
  429. $bili = config('site.money_to_gold'); //兑换比例
  430. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  431. $money = bcdiv($price,$bili,2); //对应人民币
  432. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  433. //发起用户的分数,被发起用户的分数。按性别给分
  434. $auth_level = 0;
  435. $tous_level = 0;
  436. //打分
  437. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  438. $auth_level = 30;//实名女最高
  439. }
  440. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  441. $auth_level = 20;//未实名女次之
  442. }
  443. if($this->auth->gender == 1){
  444. $auth_level = 10;//男性最低
  445. }
  446. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  447. $tous_level = 30;
  448. }
  449. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  450. $tous_level = 20;
  451. }
  452. if($to_user_info['gender'] == 1){
  453. $tous_level = 10;
  454. }
  455. //同性不收钱
  456. //都是男的,不扣钱
  457. //都是实名认证的女性,不扣钱
  458. //都是未实名认证的女性,不扣钱
  459. if($auth_level == $tous_level){
  460. $price = 0;$money = 0;
  461. }
  462. Db::startTrans();
  463. //记录日志
  464. $data = [
  465. 'user_id' => $this->auth->id,
  466. 'price' => $price,
  467. 'createtime' => time(),
  468. 'to_user_id' => $to_user_id,
  469. 'money' => $money,
  470. ];
  471. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  472. if(!$log_id){
  473. Db::rollback();
  474. $this->error('扣费失败');
  475. }
  476. //同性别,提前结束
  477. if($auth_level == $tous_level){
  478. Db::commit();
  479. $this->success('success');
  480. }
  481. //扣钱uid,收钱uid,收钱free_video
  482. //分数少扣钱,分数多收益
  483. if($auth_level < $tous_level){
  484. $kou_user = $this->auth->id;
  485. $get_user = $to_user_info['id'];
  486. $get_user_free = $to_user_info['free_video'];
  487. }else{
  488. $kou_user = $to_user_info['id'];
  489. $get_user = $this->auth->id;
  490. $get_user_free = $this->auth->free_video;
  491. }
  492. //需要扣别人的钱,判断钱是否购
  493. if($price > 0 && $kou_user != $this->auth->id){
  494. $gold = model('wallet')->getWallet($kou_user,'gold');
  495. if(bccomp($price,$gold) == 1){
  496. Db::rollback();
  497. $this->error('对方金币不足');
  498. }
  499. }
  500. //有性别差,扣费
  501. if($price > 0){
  502. $rs = model('wallet')->lockChangeAccountRemain($kou_user, $get_user,'gold',-$price,11,'','user_match_video_log',$log_id);
  503. if($rs['status'] === false){
  504. Db::rollback();
  505. $this->error($rs['msg']);
  506. }
  507. }
  508. //另一方加钱,0收费
  509. if($money > 0 && $get_user_free == 0){
  510. $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,21,'','user_match_video_log',$log_id);
  511. if($rs['status'] === false){
  512. Db::rollback();
  513. $this->error($rs['msg']);
  514. }
  515. }
  516. Db::commit();
  517. $this->success('success');
  518. }
  519. //语音通话每分钟调用一次
  520. public function audio_onemin(){
  521. //检测用户
  522. $to_user_id = input_post('to_user_id');
  523. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  524. if(!$to_user_info){
  525. $this->error('不存在的用户');
  526. }
  527. //正常价格
  528. $price = config('site.audio_min_price'); //扣费金币
  529. $bili = config('site.money_to_gold'); //兑换比例
  530. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  531. $money = bcdiv($price,$bili,2); //对应人民币
  532. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  533. //发起用户的分数,被发起用户的分数。按性别给分
  534. $auth_level = 0;
  535. $tous_level = 0;
  536. //打分
  537. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  538. $auth_level = 30;//实名女最高
  539. }
  540. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  541. $auth_level = 20;//未实名女次之
  542. }
  543. if($this->auth->gender == 1){
  544. $auth_level = 10;//男性最低
  545. }
  546. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  547. $tous_level = 30;
  548. }
  549. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  550. $tous_level = 20;
  551. }
  552. if($to_user_info['gender'] == 1){
  553. $tous_level = 10;
  554. }
  555. //同性不收钱
  556. //都是男的,不扣钱
  557. //都是实名认证的女性,不扣钱
  558. //都是未实名认证的女性,不扣钱
  559. if($auth_level == $tous_level){
  560. $price = 0;$money = 0;
  561. }
  562. Db::startTrans();
  563. //记录日志
  564. $data = [
  565. 'user_id' => $this->auth->id,
  566. 'price' => $price,
  567. 'createtime' => time(),
  568. 'to_user_id' => $to_user_id,
  569. 'money' => $money,
  570. ];
  571. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  572. if(!$log_id){
  573. Db::rollback();
  574. $this->error('扣费失败');
  575. }
  576. //同性别,提前结束
  577. if($auth_level == $tous_level){
  578. Db::commit();
  579. $this->success('success');
  580. }
  581. //扣钱uid,收钱uid,收钱free_video
  582. //分数少扣钱,分数多收益
  583. if($auth_level < $tous_level){
  584. $kou_user = $this->auth->id;
  585. $get_user = $to_user_info['id'];
  586. $get_user_free = $to_user_info['free_audio'];
  587. }else{
  588. $kou_user = $to_user_info['id'];
  589. $get_user = $this->auth->id;
  590. $get_user_free = $this->auth->free_audio;
  591. }
  592. //需要扣别人的钱,判断钱是否购
  593. if($price > 0 && $kou_user != $this->auth->id){
  594. $gold = model('wallet')->getWallet($kou_user,'gold');
  595. if(bccomp($price,$gold) == 1){
  596. Db::rollback();
  597. $this->error('对方金币不足');
  598. }
  599. }
  600. //有性别差,扣费
  601. if($price > 0){
  602. $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
  603. if($rs['status'] === false){
  604. Db::rollback();
  605. $this->error($rs['msg']);
  606. }
  607. }
  608. //另一方加钱,0收费
  609. if($money > 0 && $get_user_free == 0){
  610. $rs = model('wallet')->lockChangeAccountRemain($get_user, $kou_user,'money',$money,22,'','user_match_audio_log',$log_id);
  611. if($rs['status'] === false){
  612. Db::rollback();
  613. $this->error($rs['msg']);
  614. }
  615. }
  616. Db::commit();
  617. $this->success('success');
  618. }
  619. //打字聊天每句话调用一次
  620. public function typing_once(){
  621. //检测用户
  622. $to_user_id = input_post('to_user_id');
  623. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  624. if(!$to_user_info){
  625. $this->error('不存在的用户');
  626. }
  627. //正常价格
  628. $price = config('site.typing_min_price'); //扣费金币
  629. $bili = config('site.money_to_gold'); //兑换比例
  630. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  631. $money = bcdiv($price,$bili,2); //对应人民币
  632. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  633. //发起用户的分数,被发起用户的分数。按性别给分
  634. $auth_level = 0;
  635. $tous_level = 0;
  636. //打分
  637. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  638. $auth_level = 30;//实名女最高
  639. }
  640. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  641. $auth_level = 20;//未实名女次之
  642. }
  643. if($this->auth->gender == 1){
  644. $auth_level = 10;//男性最低
  645. }
  646. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  647. $tous_level = 30;
  648. }
  649. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  650. $tous_level = 20;
  651. }
  652. if($to_user_info['gender'] == 1){
  653. $tous_level = 10;
  654. }
  655. //同性不收钱
  656. //都是男的,不扣钱
  657. //都是实名认证的女性,不扣钱
  658. //都是未实名认证的女性,不扣钱
  659. if($auth_level == $tous_level){
  660. $price = 0;$money = 0;
  661. }
  662. //性别优势的人发起,免费
  663. if($auth_level > $tous_level){
  664. $price = 0;$money = 0;
  665. }
  666. Db::startTrans();
  667. //记录日志
  668. $data = [
  669. 'user_id' => $this->auth->id,
  670. 'price' => $price,
  671. 'createtime' => time(),
  672. 'to_user_id' => $to_user_id,
  673. 'money' => $money,
  674. ];
  675. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  676. if(!$log_id){
  677. Db::rollback();
  678. $this->error('扣费失败');
  679. }
  680. //同性别,提前结束
  681. if($auth_level == $tous_level){
  682. Db::commit();
  683. $this->success('success');
  684. }
  685. //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
  686. if($price == 0 && $money == 0){
  687. Db::commit();
  688. $this->success('success');
  689. }
  690. //扣钱uid,收钱uid,收钱free_video
  691. //分数少扣钱,分数多收益
  692. if($auth_level < $tous_level){
  693. $kou_user = $this->auth->id;
  694. $get_user = $to_user_info['id'];
  695. $get_user_free = $to_user_info['free_typing'];
  696. }else{
  697. //这种已经没有了
  698. $kou_user = $to_user_info['id'];
  699. $get_user = $this->auth->id;
  700. $get_user_free = $this->auth->free_typing;
  701. }
  702. //有性别差,扣费
  703. if($price > 0){
  704. $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
  705. if($rs['status'] === false){
  706. Db::rollback();
  707. $this->error($rs['msg']);
  708. }
  709. }
  710. //另一方加钱,0收费
  711. if($money > 0 && $get_user_free == 0){
  712. $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,23,'','user_match_typing_log',$log_id);
  713. if($rs['status'] === false){
  714. Db::rollback();
  715. $this->error($rs['msg']);
  716. }
  717. }
  718. //tag任务赠送金币
  719. //搭讪奖励
  720. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  721. if($task_rs === false){
  722. Db::rollback();
  723. $this->error('完成任务赠送奖励失败');
  724. }
  725. Db::commit();
  726. $this->success('success');
  727. }
  728. //语音匹配
  729. public function getaudiouser(){
  730. //判断资格
  731. /*$start = strtotime(date('Y-m-d'));
  732. $end = $start + 86399;
  733. $map = [
  734. 'user_id' => $this->auth->id,
  735. 'createtime' => ['between',[$start,$end]],
  736. 'price' => 0,
  737. ];
  738. $check = Db::name('user_match_audio_log')->where($map)->find();*/
  739. $check = true;
  740. //已经用掉免费的了,判断金额
  741. if($check){
  742. $price = config('site.audio_min_price');
  743. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  744. if($gold < $price){
  745. $this->error('您的金币已经不足,请充值');
  746. }
  747. }
  748. //找到互关的人,排除
  749. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  750. //dump($follow_me);
  751. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  752. //dump($my_follow);exit;
  753. //给出备选用户
  754. $map = [
  755. 'status' =>1, //未封禁用户
  756. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  757. 'is_online' => 0, //不在语聊间的
  758. 'is_livebc' => 0, //不在直播的
  759. 'is_active' => 1, //在线的
  760. //'real_status' => 1, //真人认证
  761. //'idcard_status' => 1, //实名认证
  762. 'open_match_audio' => 1, //打开语聊开关
  763. //'id' => ['NOT IN',$my_follow] //不是好友的
  764. ];
  765. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  766. $lists = $this->fliter_user($lists,10);
  767. $result = [];
  768. if(!empty($lists)){
  769. foreach($lists as $key => $val){
  770. $result[] = ['id'=>$val];
  771. }
  772. }
  773. //tag任务赠送金币
  774. //语音匹配奖励 +5金币
  775. if(!empty($result)){
  776. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  777. if($task_rs === false){
  778. $this->error('完成任务赠送奖励失败');
  779. }
  780. }
  781. $this->success('success',$result);
  782. }
  783. //视频匹配
  784. public function getvideouser(){
  785. //判断资格
  786. /*$start = strtotime(date('Y-m-d'));
  787. $end = $start + 86399;
  788. $map = [
  789. 'user_id' => $this->auth->id,
  790. 'createtime' => ['between',[$start,$end]],
  791. 'price' => 0,
  792. ];
  793. $check = Db::name('user_match_video_log')->where($map)->find();*/
  794. $check = true;
  795. //已经用掉免费的了,判断金额
  796. if($check){
  797. $price = config('site.video_min_price');
  798. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  799. if($gold < $price){
  800. $this->error('您的金币已经不足,请充值');
  801. }
  802. }
  803. //找到互关的人,排除
  804. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  805. //dump($follow_me);
  806. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  807. //dump($my_follow);exit;
  808. //给出备选用户
  809. $map = [
  810. 'status' =>1, //未封禁用户
  811. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  812. 'is_online' => 0, //不在语聊间的
  813. 'is_livebc' => 0, //不在直播的
  814. 'is_active' => 1, //在线的
  815. //'real_status' => 1, //真人认证
  816. //'idcard_status' => 1, //实名认证
  817. 'open_match_video' => 1, //打开视频开关的
  818. // 'id' => ['NOT IN',$my_follow] //不是好友的
  819. ];
  820. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  821. $lists = $this->fliter_user($lists,10);
  822. $result = [];
  823. if(!empty($lists)){
  824. foreach($lists as $key => $val){
  825. $result[] = ['id'=>$val];
  826. }
  827. }
  828. //tag任务赠送金币
  829. //视频匹配奖励 +5金币
  830. if(!empty($result)){
  831. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
  832. if($task_rs === false){
  833. $this->error('完成任务赠送奖励失败');
  834. }
  835. }
  836. $this->success('success',$result);
  837. }
  838. //聊天匹配
  839. public function gettypinguser(){
  840. //找到互关的人,排除
  841. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  842. //dump($follow_me);
  843. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  844. //dump($my_follow);exit;
  845. //给出备选用户
  846. $map = [
  847. 'status' =>1, //未封禁用户
  848. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  849. //'real_status' => 1, //真人认证
  850. //'idcard_status' => 1, //实名认证
  851. //'is_active' => 1, //在线的
  852. //打开聊天开关的
  853. 'open_match_typing' => 1, //打开文字聊天开关的
  854. //'id' => ['NOT IN',$my_follow] //不是好友的
  855. ];
  856. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  857. //$lists = $this->fliter_user($lists,100);
  858. $lists = array_column($lists,'id');
  859. $result = [];
  860. if(!empty($lists)){
  861. /*foreach($lists as $key => $val){
  862. $result[] = ['id'=>$val];
  863. }*/
  864. $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
  865. $result = list_domain_image($result,['avatar,audio_bio']);
  866. }
  867. //tag任务赠送金币
  868. //缘分匹配奖励 +5金币
  869. if(!empty($result)){
  870. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
  871. if($task_rs === false){
  872. $this->error('完成任务赠送奖励失败');
  873. }
  874. }
  875. $this->success('success',$result);
  876. }
  877. //过滤规则
  878. private function fliter_user($lists,$number = 1){
  879. if(empty($lists)){
  880. return $lists;
  881. }
  882. //dump($lists);
  883. //过滤掉通话中的
  884. foreach($lists as $key => $val){
  885. if(redis_matching_get($val['id']) == 1){
  886. unset($lists[$key]);
  887. }
  888. }
  889. //预留全部
  890. $all_result = array_column($lists,'id');
  891. //dump($all_result);
  892. //提取同城的
  893. $citydata = [];
  894. foreach($lists as $key => $val){
  895. if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
  896. $citydata[] = $val['id'];
  897. }
  898. }
  899. //dump($citydata);
  900. //有标签交集的
  901. $tagdata = [];
  902. foreach($lists as $key => $val){
  903. if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
  904. $auth_tag_ids = explode(',',$this->auth->tag_ids);
  905. $val_tag_ids = explode(',',$val['tag_ids']);
  906. if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
  907. $tagdata[] = $val['id'];
  908. }
  909. }
  910. }
  911. //dump($tagdata);
  912. //双条件都满足
  913. $double_data = [];
  914. if(!empty($citydata) && !empty($tagdata)){
  915. $double_data = array_intersect($citydata,$tagdata);
  916. }
  917. //dump($double_data);
  918. if(count($double_data) >= $number){
  919. return $double_data;
  920. }
  921. //两种条件合并,去重。空数组合并没影响
  922. $merge_data = array_merge($citydata,$tagdata);
  923. $merge_data = array_flip(array_flip($merge_data));
  924. //dump($merge_data);
  925. if(count($merge_data) >= $number){
  926. return $merge_data;
  927. }
  928. return $all_result;
  929. }
  930. /**
  931. * 是否关注
  932. */
  933. public function isFollows() {
  934. $user_id = $this->request->request("user_id",0,"intval");
  935. if (!$user_id || $user_id<=0) {
  936. $this->error(__('Invalid parameters'));
  937. }
  938. $map = [
  939. 'uid' => $this->auth->id,
  940. 'follow_uid' => $user_id,
  941. ];
  942. $check = Db::name('user_follow')->where($map)->find();
  943. $data = [];
  944. if($check){
  945. $data["is_show_follow"] = 0;
  946. }else{
  947. $data["is_show_follow"] = 1;
  948. }
  949. $this->success("获取成功!",$data);
  950. }
  951. /**
  952. * 获取主播技能分类
  953. */
  954. public function getAnchorType() {
  955. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  956. }
  957. /**
  958. * 主播申请
  959. */
  960. public function anchorApply() {
  961. $this->error('不需要申请');
  962. /*$type_id = $this->request->request('type_id'); // 技能分类ID
  963. $desc = $this->request->request('desc'); // 申请备注
  964. if (!$type_id && !$desc) {
  965. $this->error(__('Invalid parameters'));
  966. }
  967. $useranchorModel = new \app\common\model\UserAnchor();
  968. $data = [];
  969. $data["user_id"] = $this->auth->id;
  970. $data["type_id"] = $type_id;
  971. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  972. $data["desc"] = $desc;
  973. $data["createtime"] = time();
  974. $res = $useranchorModel->insertGetId($data);
  975. if($res) {
  976. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  977. $this->success("申请发送成功!");
  978. } else {
  979. $this->error("网络错误,请稍后重试");
  980. }*/
  981. }
  982. /**
  983. * 获取当前用户信息
  984. */
  985. public function getMyUserInfo() {
  986. $userInfo = $this->auth->getUserinfo();
  987. //当月消费金额
  988. $redis = new Redis();
  989. $redisconfig = config("redis");
  990. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  991. $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
  992. $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
  993. $this->success("获取成功!",$userInfo);
  994. }
  995. /**
  996. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  997. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  998. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  999. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  1000. * @return float | false | string
  1001. */
  1002. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  1003. if( empty( $point_1 ) || empty( $point_2 ) ){
  1004. return false;
  1005. }
  1006. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  1007. $p1_x = $point_1[0];
  1008. $p1_y = $point_1[1];
  1009. $p2_x = $point_2[0];
  1010. $p2_y = $point_2[1];
  1011. if(
  1012. $p1_x < -180 || $p1_x > 180
  1013. || $p2_x < -180 || $p2_x > 180
  1014. || $p1_y < -90 || $p1_y > 90
  1015. || $p2_y < -90 || $p2_y > 90
  1016. ){
  1017. return '0公里';
  1018. }
  1019. // 根据2点各自的坐标,计算2点之间直线距离的公式
  1020. $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);
  1021. // 是否计算为字符串公里距离
  1022. if( !$calc_as_string ){
  1023. return (string)round( $distance / 1000 , 1 ) . '公里';
  1024. }
  1025. // 如果计算为字符串公里距离
  1026. if( $distance / 1000 > 1 ){
  1027. $k = (string)round( $distance / 1000 , 1 );
  1028. $m = (string)$distance % 1000 ;
  1029. $distance = "{$k}公里{$m}米";
  1030. }
  1031. else{
  1032. $distance = "{$distance}米";
  1033. }
  1034. return $distance;
  1035. }
  1036. //地图api,根据两地坐标,获得两地距离,打卡用的
  1037. //type=0直线,type=1开车
  1038. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  1039. $result = 0;
  1040. $apiurl = 'https://restapi.amap.com/v3/distance?';
  1041. $param = [
  1042. 'key' => '398c424811d1a59beac2f915323d334e',
  1043. 'origins' => $start_lon.','.$start_lat,
  1044. 'destination' => $end_lon.','.$end_lat,
  1045. 'type' => $type,
  1046. 'output' => 'json',
  1047. ];
  1048. $apiurl .= http_build_query($param);
  1049. $request_rs = json_decode(curl_get($apiurl),true);
  1050. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  1051. if(isset($request_rs['results'][0]['distance']))
  1052. {
  1053. $result = $request_rs['results'][0]['distance'];
  1054. }
  1055. }
  1056. //dump($result);
  1057. return $result;
  1058. }
  1059. public function distance()
  1060. {
  1061. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  1062. dump($a);
  1063. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  1064. dump($a);
  1065. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  1066. dump($b);
  1067. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  1068. dump($b);
  1069. }
  1070. //开通守护
  1071. public function addguard() {
  1072. // 接口防并发
  1073. if (!$this->apiLimit(1, 1000)) {
  1074. $this->error(__('Operation frequently'));
  1075. }
  1076. $user_id = input('user_id', 0, 'intval');// 守护对象
  1077. if (!$user_id) {
  1078. $this->error();
  1079. }
  1080. // 不可以守护给自己
  1081. if($this->auth->id == $user_id) {
  1082. $this->error("不可以守护自己");
  1083. }
  1084. //查询是否开通守护
  1085. $count = Db::name('user_guard')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  1086. if ($count) {
  1087. $this->error('已经开通守护了');
  1088. }
  1089. $giftvalue = config('site.guard_price');
  1090. if ($giftvalue <= 0) {
  1091. $this->error('守护金额异常~');
  1092. }
  1093. //被守护人信息
  1094. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  1095. if (!$touserinfo) {
  1096. $this->error("不存在的用户");
  1097. }
  1098. // 判断当前用户余额
  1099. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  1100. if($user_gold < $giftvalue) {
  1101. $this->error("您的金币余额不足");
  1102. }
  1103. Db::startTrans();
  1104. // 添加礼物守护记录表
  1105. $data = [
  1106. 'user_id' => $this->auth->id,
  1107. 'user_to_id' => $user_id,
  1108. 'price' => $giftvalue,
  1109. 'createtime' => time(),
  1110. ];
  1111. $log_id = Db::name('user_guard')->insertGetId($data);
  1112. if(!$log_id){
  1113. Db::rollback();
  1114. $this->error('守护失败');
  1115. }
  1116. if($giftvalue > 0){
  1117. // 扣除当前用户余额
  1118. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_guard',$log_id);
  1119. if($wallet_rs['status'] === false){
  1120. Db::rollback();
  1121. $this->error($wallet_rs['msg']);
  1122. }
  1123. // 添加守护用户余额
  1124. $money_to_gold = config('site.money_to_gold');
  1125. $gift_plat_scale = config('site.gift_plat_scale');
  1126. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  1127. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  1128. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_guard',$log_id,2);
  1129. if($wallet_rs['status'] === false){
  1130. Db::rollback();
  1131. $this->error($wallet_rs['msg']);
  1132. }
  1133. //增加赠送用户上级余额
  1134. if ($touserinfo['intro_uid']) {
  1135. //获取返利比率
  1136. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1137. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1138. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1139. //上级获得金额
  1140. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1141. if ($intro_uid_money > 0) {
  1142. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人开通守护获赠奖励','gift_user_typing',$log_id);
  1143. if($intro_result['status']===false)
  1144. {
  1145. Db::rollback();
  1146. $this->error($intro_result['msg']);
  1147. }
  1148. }
  1149. }
  1150. }
  1151. }
  1152. //tag任务守护金币
  1153. //搭讪奖励
  1154. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  1155. // if($task_rs === false){
  1156. // Db::rollback();
  1157. // $this->error('完成任务守护奖励失败');
  1158. // }
  1159. Db::commit();
  1160. $this->success('守护成功');
  1161. }
  1162. //守护列表
  1163. public function guardlist(){
  1164. $user_id = input('user_id', 0, 'intval');
  1165. if (!$user_id) {
  1166. $this->error('您的网络开小差啦~');
  1167. }
  1168. $list = Db::name('user_guard')
  1169. ->alias('a')
  1170. ->join('user','a.user_id = user.id','LEFT')
  1171. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  1172. ->where('a.user_to_id',$user_id)->order('a.id desc')->autopage()->select();
  1173. if (!$list) {
  1174. $this->success('success', $list);
  1175. }
  1176. $list = list_domain_image($list,['avatar']);
  1177. $time = time();
  1178. foreach ($list as &$v) {
  1179. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  1180. }
  1181. $this->success('success',$list);
  1182. }
  1183. //我的守护
  1184. public function myguardlist(){
  1185. $type = input('type', 0, 'intval'); //类型: 1我守护的 2守护我的
  1186. if (!in_array($type, [1, 2])) {
  1187. $this->error('您的网络开小差了');
  1188. }
  1189. $where = [];
  1190. if ($type == 1) {
  1191. $join = 'a.user_to_id = user.id';
  1192. $where['a.user_id'] = $this->auth->id;
  1193. } else {
  1194. $join = 'a.user_id = user.id';
  1195. $where['a.user_to_id'] = $this->auth->id;
  1196. }
  1197. $list = Db::name('user_guard')
  1198. ->alias('a')
  1199. ->join('user',$join,'LEFT')
  1200. ->field('a.createtime,user.id,user.nickname,user.avatar,user.real_status')
  1201. ->where($where)->order('a.id desc')->autopage()->select();
  1202. if (!$list) {
  1203. $this->success('success', $list);
  1204. }
  1205. $list = list_domain_image($list,['avatar']);
  1206. $time = time();
  1207. foreach ($list as &$v) {
  1208. $v['createtime'] = ceil(($time - $v['createtime']) / 86400);
  1209. }
  1210. $this->success('success',$list);
  1211. }
  1212. //打字聊天每句话调用一次
  1213. public function chat_once(){
  1214. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1215. $this->success('success',array('money'=>''));
  1216. }
  1217. if ($this->auth->gender == 0) { //女生不花钱
  1218. $this->error('您的网络开小差啦~');
  1219. }
  1220. //检测用户
  1221. $to_user_id = input_post('to_user_id');
  1222. $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();
  1223. if(!$to_user_info){
  1224. $this->error('不存在的用户');
  1225. }
  1226. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1227. $this->success('success',array('money'=>''));
  1228. }
  1229. if ($to_user_info['gender'] != 0) {
  1230. $this->error('同性不能聊天~');
  1231. }
  1232. //验证金额
  1233. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1234. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1235. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  1236. //获取折扣
  1237. $vip_chat_discount = config('site.vip_chat_discount');
  1238. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1239. $price = ceil($price * $vip_chat_discount / 10);
  1240. }
  1241. } else {
  1242. $price = $to_user_info['chat_price'];//config('site.typing_min_price'); //扣费金币
  1243. }
  1244. //正常价格
  1245. $bili = config('site.money_to_gold'); //兑换比例
  1246. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1247. $money = bcdiv($price,$bili,2); //对应人民币
  1248. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1249. $resArray['money'] = $money; //返回给前端的计算结果
  1250. Db::startTrans();
  1251. //记录日志
  1252. $data = [
  1253. 'user_id' => $this->auth->id,
  1254. 'price' => $price,
  1255. 'createtime' => time(),
  1256. 'to_user_id' => $to_user_id,
  1257. 'money' => $money,
  1258. ];
  1259. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  1260. if(!$log_id){
  1261. Db::rollback();
  1262. $this->error('扣费失败');
  1263. }
  1264. //有性别差,扣费
  1265. if($price > 0){
  1266. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$to_user_id,'gold',-$price,13,'文字聊天消费','user_match_typing_log',$log_id);
  1267. if($rs['status'] === false){
  1268. Db::rollback();
  1269. $this->error($rs['msg']);
  1270. }
  1271. }
  1272. //另一方加钱,0收费
  1273. if($money > 0){
  1274. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,$this->auth->id,'money',$money,23,'文字聊天收益','user_match_typing_log',$log_id,2);
  1275. if($rs['status'] === false){
  1276. Db::rollback();
  1277. $this->error($rs['msg']);
  1278. }
  1279. $touserinfo = $to_user_info;
  1280. //增加赠送用户上级余额
  1281. if ($touserinfo['intro_uid']) {
  1282. //获取返利比率
  1283. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1284. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1285. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1286. //上级获得金额
  1287. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1288. if ($intro_uid_money > 0) {
  1289. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$to_user_id,'money',$intro_uid_money,68, '邀请人文字聊天获赠奖励','gift_user_typing',$log_id);
  1290. if($intro_result['status']===false)
  1291. {
  1292. Db::rollback();
  1293. $this->error($intro_result['msg']);
  1294. }
  1295. }
  1296. }
  1297. }
  1298. }
  1299. //增加亲密度
  1300. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1301. if (!$user_intimacy_rs['status']) {
  1302. Db::rollback();
  1303. $this->error('您的网络开小差啦~');
  1304. }
  1305. //tag任务赠送金币
  1306. //私信5名异性奖励
  1307. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  1308. if($task_rs === false){
  1309. Db::rollback();
  1310. $this->error('完成任务赠送奖励失败');
  1311. }
  1312. /*$task_rs = \app\common\model\TaskLog::tofinish($to_user_id,23);
  1313. if($task_rs === false){
  1314. Db::rollback();
  1315. $this->error('完成任务赠送奖励失败');
  1316. }*/
  1317. Db::commit();
  1318. //发送消息
  1319. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1320. $tenim = new \app\api\controller\Tenim;
  1321. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1322. }
  1323. $this->success('success',$resArray);
  1324. }
  1325. //语音通话每分钟调用一次
  1326. public function voice_onemin(){
  1327. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1328. $this->success('success');
  1329. }
  1330. if ($this->auth->gender == 0) { //女生不花钱
  1331. $this->error('您的网络开小差啦~');
  1332. }
  1333. //检测用户
  1334. $to_user_id = input_post('to_user_id');
  1335. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  1336. $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();
  1337. if(!$to_user_info){
  1338. $this->error('不存在的用户');
  1339. }
  1340. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1341. $this->success('success');
  1342. }
  1343. if ($to_user_info['gender'] != 0) {
  1344. $this->error('同性不能聊天~');
  1345. }
  1346. //验证金额
  1347. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1348. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1349. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  1350. //获取折扣
  1351. $vip_video_discount = config('site.vip_video_discount');
  1352. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1353. $price = ceil($price * $vip_video_discount / 10);
  1354. }
  1355. } else {
  1356. $price = $to_user_info['voice_price'];//config('site.video_min_price'); //扣费金币
  1357. }
  1358. //正常价格
  1359. $bili = config('site.money_to_gold'); //兑换比例
  1360. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1361. $money = bcdiv($price,$bili,2); //对应人民币
  1362. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1363. Db::startTrans();
  1364. //查询是否有匹配记录
  1365. $user_match_audio_log_info = [];
  1366. if ($request_id) {
  1367. $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();
  1368. }
  1369. if ($user_match_audio_log_info) {
  1370. //修改记录日志
  1371. $data = [
  1372. 'price' => $user_match_audio_log_info['price'] + $price,
  1373. 'createtime' => time(),
  1374. 'money' => $user_match_audio_log_info['money'] + $money,
  1375. 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
  1376. ];
  1377. $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);
  1378. if (!$log_id) {
  1379. Db::rollback();
  1380. $this->error('扣费失败');
  1381. }
  1382. } else {
  1383. //添加记录日志
  1384. $data = [
  1385. 'user_id' => $this->auth->id,
  1386. 'price' => $price,
  1387. 'createtime' => time(),
  1388. 'to_user_id' => $to_user_id,
  1389. 'money' => $money,
  1390. 'request_id' => $request_id,
  1391. 'call_minutes' => 1
  1392. ];
  1393. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  1394. if (!$log_id) {
  1395. Db::rollback();
  1396. $this->error('扣费失败');
  1397. }
  1398. }
  1399. //有性别差,扣费
  1400. if($price > 0){
  1401. $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);
  1402. if($rs['status'] === false){
  1403. Db::rollback();
  1404. $this->error($rs['msg']);
  1405. }
  1406. }
  1407. //另一方加钱,0收费
  1408. if($money > 0){
  1409. $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);
  1410. if($rs['status'] === false){
  1411. Db::rollback();
  1412. $this->error($rs['msg']);
  1413. }
  1414. $touserinfo = $to_user_info;
  1415. //增加赠送用户上级余额
  1416. if ($touserinfo['intro_uid']) {
  1417. //获取返利比率
  1418. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1419. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1420. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1421. //上级获得金额
  1422. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1423. if ($intro_uid_money > 0) {
  1424. $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);
  1425. if($intro_result['status']===false)
  1426. {
  1427. Db::rollback();
  1428. $this->error($intro_result['msg']);
  1429. }
  1430. }
  1431. }
  1432. }
  1433. }
  1434. //增加亲密度
  1435. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1436. if (!$user_intimacy_rs['status']) {
  1437. Db::rollback();
  1438. $this->error('您的网络开小差啦~');
  1439. }
  1440. //tag任务赠送金币
  1441. //与1名异性语音通话奖励
  1442. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,25);
  1443. if($task_rs === false){
  1444. Db::rollback();
  1445. $this->error('完成任务赠送奖励失败');
  1446. }
  1447. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,25);
  1448. if($task_rs === false){
  1449. Db::rollback();
  1450. $this->error('完成任务赠送奖励失败');
  1451. }
  1452. //发送消息
  1453. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1454. $tenim = new \app\api\controller\Tenim;
  1455. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1456. }
  1457. Db::commit();
  1458. $this->success('success');
  1459. }
  1460. //视频通话每分钟调用一次
  1461. public function videochat_onemin(){
  1462. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1463. $this->success('success');
  1464. }
  1465. if ($this->auth->gender == 0) { //女生不花钱
  1466. $this->error('您的网络开小差啦~');
  1467. }
  1468. //检测用户
  1469. $to_user_id = input_post('to_user_id');
  1470. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  1471. $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();
  1472. if(!$to_user_info){
  1473. $this->error('不存在的用户');
  1474. }
  1475. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  1476. $this->success('success');
  1477. }
  1478. if ($to_user_info['gender'] != 0) {
  1479. $this->error('同性不能聊天~');
  1480. }
  1481. /* //检查是否免费过
  1482. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1483. if (!$count) {
  1484. //记录日志
  1485. $data = [
  1486. 'user_id' => $this->auth->id,
  1487. 'price' => 0,
  1488. 'createtime' => time(),
  1489. 'to_user_id' => $to_user_id,
  1490. 'money' => 0,
  1491. ];
  1492. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  1493. if(!$log_id){
  1494. $this->error('扣费失败');
  1495. }
  1496. $this->success('success');
  1497. }*/
  1498. //验证金额
  1499. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1500. if ($wallet_info['vip_endtime'] >= time()) { //会员
  1501. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  1502. //获取折扣
  1503. $vip_video_discount = config('site.vip_video_discount');
  1504. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1505. $price = ceil($price * $vip_video_discount / 10);
  1506. }
  1507. } else {
  1508. $price = $to_user_info['video_price'];//config('site.video_min_price'); //扣费金币
  1509. }
  1510. //正常价格
  1511. $bili = config('site.money_to_gold'); //兑换比例
  1512. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  1513. $money = bcdiv($price,$bili,2); //对应人民币
  1514. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  1515. Db::startTrans();
  1516. //查询是否有匹配记录
  1517. $user_match_video_log_info = [];
  1518. if ($request_id) {
  1519. $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();
  1520. }
  1521. if ($user_match_video_log_info) {
  1522. //修改记录日志
  1523. $data = [
  1524. 'price' => $user_match_video_log_info['price'] + $price,
  1525. 'createtime' => time(),
  1526. 'money' => $user_match_video_log_info['money'] + $money,
  1527. 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
  1528. ];
  1529. $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);
  1530. if (!$log_id) {
  1531. Db::rollback();
  1532. $this->error('扣费失败');
  1533. }
  1534. } else {
  1535. //添加记录日志
  1536. $data = [
  1537. 'user_id' => $this->auth->id,
  1538. 'price' => $price,
  1539. 'createtime' => time(),
  1540. 'to_user_id' => $to_user_id,
  1541. 'money' => $money,
  1542. 'request_id' => $request_id,
  1543. 'call_minutes' => 1
  1544. ];
  1545. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  1546. if (!$log_id) {
  1547. Db::rollback();
  1548. $this->error('扣费失败');
  1549. }
  1550. }
  1551. //有性别差,扣费
  1552. if($price > 0){
  1553. $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);
  1554. if($rs['status'] === false){
  1555. Db::rollback();
  1556. $this->error($rs['msg']);
  1557. }
  1558. }
  1559. //另一方加钱,0收费
  1560. if($money > 0){
  1561. $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);
  1562. if($rs['status'] === false){
  1563. Db::rollback();
  1564. $this->error($rs['msg']);
  1565. }
  1566. $touserinfo = $to_user_info;
  1567. //增加赠送用户上级余额
  1568. if ($touserinfo['intro_uid']) {
  1569. //获取返利比率
  1570. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  1571. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  1572. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  1573. //上级获得金额
  1574. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  1575. if ($intro_uid_money > 0) {
  1576. $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);
  1577. if($intro_result['status']===false)
  1578. {
  1579. Db::rollback();
  1580. $this->error($intro_result['msg']);
  1581. }
  1582. }
  1583. }
  1584. }
  1585. }
  1586. //增加亲密度
  1587. $user_intimacy_rs = addintimacy($this->auth->id, $to_user_id, $price);
  1588. if (!$user_intimacy_rs['status']) {
  1589. Db::rollback();
  1590. $this->error('您的网络开小差啦~');
  1591. }
  1592. //tag任务赠送金币
  1593. //与1名异性视频通话奖励
  1594. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,26);
  1595. if($task_rs === false){
  1596. Db::rollback();
  1597. $this->error('完成任务赠送奖励失败');
  1598. }
  1599. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,26);
  1600. if($task_rs === false){
  1601. Db::rollback();
  1602. $this->error('完成任务赠送奖励失败');
  1603. }
  1604. Db::commit();
  1605. //发送消息
  1606. if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
  1607. $tenim = new \app\api\controller\Tenim;
  1608. $tenim->sendMessageToUser($this->auth->id, $to_user_id, $user_intimacy_rs['level_remark'], 1);
  1609. }
  1610. $this->success('success');
  1611. }
  1612. //消息列表好友/密友
  1613. public function intimacyfriends() {
  1614. $type = input('type', 0, 'intval'); //类型:0消息列表好友 1密友 2好友
  1615. $where = [];
  1616. /*if ($type == 0) {
  1617. $list = Db::name('user_follow')->field('follow_uid user_id')->where(['uid' => $this->auth->id])->autopage()->order('id desc')->select();
  1618. $mt_user = Db::name('user');
  1619. // $mt_user_follow = Db::name('user_follow');
  1620. $mt_user_intimacy = Db::name('user_intimacy');
  1621. foreach ($list as &$v) {
  1622. //查询亲密度
  1623. if ($this->auth->gender == 1) {
  1624. $where['uid'] = $this->auth->id;
  1625. $where['other_uid'] = $v['user_id'];
  1626. } else {
  1627. $where['other_uid'] = $this->auth->id;
  1628. $where['uid'] = $v['user_id'];
  1629. }
  1630. $user_intimacy = $mt_user_intimacy->field('value, updatetime')->where($where)->find();
  1631. $v['value'] = $user_intimacy ? $user_intimacy['value'] : 0;
  1632. $v['updatetime'] = $user_intimacy ? $user_intimacy['updatetime'] : 0;
  1633. //查询对方信息
  1634. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status')->where(['id' => $v['user_id']])->find();
  1635. $v['nickname'] = $user_info['nickname'];
  1636. $v['avatar'] = one_domain_image($user_info['avatar']);
  1637. $v['updatetime'] = get_last_time($v['updatetime']);
  1638. $v['age'] = birthtime_to_age($user_info['birthday']);
  1639. $v['gender'] = $user_info['gender'];
  1640. $v['real_status'] = $user_info['real_status'];
  1641. // $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  1642. $v['status'] = 1;
  1643. }
  1644. } else {*/
  1645. if ($this->auth->gender == 1) {
  1646. $where['uid'] = $this->auth->id;
  1647. $field = 'other_uid user_id, value, updatetime';
  1648. } else {
  1649. $where['other_uid'] = $this->auth->id;
  1650. $field = 'uid user_id, value, updatetime';
  1651. }
  1652. if ($type == 1) { //密友
  1653. $where['value'] = ['egt', 1000];
  1654. } elseif ($type == 2) { //好友
  1655. $where['value'] = ['egt', 100];
  1656. } else { //消息列表好友
  1657. $where['value'] = ['egt', 10];
  1658. }
  1659. $list = Db::name('user_intimacy')->field($field)->where($where)->autopage()->order('updatetime desc')->select();
  1660. $mt_user = Db::name('user');
  1661. $mt_user_follow = Db::name('user_follow');
  1662. foreach ($list as &$v) {
  1663. $user_info = $mt_user->field('nickname, avatar,birthday,gender,real_status,is_active')->where(['id' => $v['user_id']])->find();
  1664. $v['nickname'] = $user_info['nickname'];
  1665. $v['avatar'] = one_domain_image($user_info['avatar']);
  1666. $v['updatetime'] = get_last_time($v['updatetime']);
  1667. $v['age'] = birthtime_to_age($user_info['birthday']);
  1668. $v['gender'] = $user_info['gender'];
  1669. $v['real_status'] = $user_info['real_status'];
  1670. $v['status'] = $mt_user_follow->where(['uid' => $this->auth->id, 'follow_uid' => $v['user_id']])->count('id');
  1671. $v['is_active'] = $user_info['is_active'];
  1672. }
  1673. // }
  1674. $this->success('success',$list);
  1675. }
  1676. //消息列表通话
  1677. public function calllist() {
  1678. if ($this->auth->gender == 1) {
  1679. $list = Db::name('user_gold_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [11, 12]]])->order('id desc')->autopage()->select();
  1680. } elseif ($this->auth->gender == 0) {
  1681. $list = Db::name('user_money_log')->where(['user_id' => $this->auth->id, 'log_type' => ['in', [21, 22]]])->order('id desc')->autopage()->select();
  1682. } else {
  1683. $this->success('success', []);
  1684. }
  1685. if (!$list) {
  1686. $this->success('success', $list);
  1687. }
  1688. $arr = [];
  1689. $mt_user_match_audio_log = Db::name('user_match_audio_log');
  1690. $mt_user_match_video_log = Db::name('user_match_video_log');
  1691. $mt_user = Db::name('user');
  1692. foreach ($list as &$v) {
  1693. $data = [];
  1694. if ($this->auth->gender == 1) {
  1695. if ($v['log_type'] == 11) { //视频通话
  1696. $log_info = $mt_user_match_video_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1697. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1698. } else { //语音通话
  1699. $log_info = $mt_user_match_audio_log->field('to_user_id user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1700. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1701. }
  1702. } else {
  1703. if ($v['log_type'] == 21) { //视频通话
  1704. $log_info = $mt_user_match_video_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1705. $data['desc'] = '视频时长' . $log_info['call_minutes'] . '分钟';
  1706. } else { //语音通话
  1707. $log_info = $mt_user_match_audio_log->field('user_id, createtime, call_minutes')->where(['id' => $v['table_id']])->find();
  1708. $data['desc'] = '语音时长' . $log_info['call_minutes'] . '分钟';
  1709. }
  1710. }
  1711. $user_info = $mt_user->field('nickname, avatar,is_active')->where(['id' => $log_info['user_id']])->find();
  1712. $data['user_id'] = $log_info['user_id'];
  1713. $data['nickname'] = $user_info['nickname'];
  1714. $data['avatar'] = one_domain_image($user_info['avatar']);
  1715. $data['createtime'] = get_last_time($log_info['createtime']);
  1716. $data['is_active'] = $user_info['is_active'];
  1717. $arr[] = $data;
  1718. }
  1719. $this->success('success', $arr);
  1720. }
  1721. //查询对方用户收费价格和我的余额
  1722. public function otheruserinfo(){
  1723. $user_id = input('user_id', 0, 'intval');
  1724. if (!$user_id) {
  1725. $this->error('您的网络开小差啦~');
  1726. }
  1727. $field = [
  1728. 'chat_price','voice_price','video_price','gender','is_kefu', 'open_match_audio', 'open_match_video'
  1729. ];
  1730. $info = Db::name('user')->field($field)->where('id',$user_id)->find();
  1731. if ($info['is_kefu'] != 1 && $this->auth->is_kefu != 1) { //不是客服
  1732. if ($info['gender'] == $this->auth->gender || $info['gender'] == -1 || $this->auth->gender == -1) {
  1733. $this->error('性别存在问题');
  1734. }
  1735. }
  1736. if ($this->auth->gender == 0) { //收费价格按照女号
  1737. $info['chat_price'] = $this->auth->chat_price;
  1738. $info['voice_price'] = $this->auth->voice_price;
  1739. $info['video_price'] = $this->auth->video_price;
  1740. $info['open_match_audio'] = $this->auth->open_match_audio;
  1741. $info['open_match_video'] = $this->auth->open_match_video;
  1742. }
  1743. $info['chat_price_vip'] = $info['chat_price']; //vip价格
  1744. $info['voice_price_vip'] = $info['voice_price'];
  1745. $info['video_price_vip'] = $info['video_price'];
  1746. $info['is_vip'] = 0; //是否vip: 0否 1是
  1747. //获取聊天折扣
  1748. $vip_chat_discount = config('site.vip_chat_discount');
  1749. if ($vip_chat_discount >= 0 && $vip_chat_discount <= 10) {
  1750. $info['vip_chat_discount'] = $vip_chat_discount;
  1751. } else {
  1752. $info['vip_chat_discount'] = 10;
  1753. }
  1754. //获取语音视频折扣
  1755. $vip_video_discount = config('site.vip_video_discount');
  1756. if ($vip_video_discount >= 0 && $vip_video_discount <= 10) {
  1757. $info['vip_voice_discount'] = config('site.vip_video_discount'); //语音
  1758. $info['vip_video_discount'] = config('site.vip_video_discount'); //视频
  1759. } else {
  1760. $info['vip_voice_discount'] = 10;
  1761. $info['vip_video_discount'] = 10;
  1762. }
  1763. //获取聊天折扣
  1764. $info['chat_price_vip'] = ceil($info['chat_price'] * $info['vip_chat_discount'] / 10);
  1765. //获取语音折扣
  1766. $info['voice_price_vip'] = ceil($info['voice_price'] * $info['vip_voice_discount'] / 10);
  1767. //获取视频折扣
  1768. $info['video_price_vip'] = ceil($info['video_price'] * $info['vip_video_discount'] / 10);
  1769. if ($this->auth->gender == 0) { //查询男号余额和vip
  1770. $wallet_info = Db::name('user_wallet')->where(['user_id' => $user_id])->find();
  1771. } else {
  1772. $wallet_info = Db::name('user_wallet')->where(['user_id' => $this->auth->id])->find();
  1773. }
  1774. if ($wallet_info['vip_endtime'] >= time()) {
  1775. $info['is_vip'] = 1;
  1776. }
  1777. $info['gold'] = $wallet_info['gold'];
  1778. $info['plat_scale'] = config('site.gift_plat_scale'); //平台抽成百分比
  1779. $info['money_to_gold'] = config('site.money_to_gold'); //一元人民币兑换金币数量
  1780. $this->success('success',$info);
  1781. }
  1782. //亲密度等级信息
  1783. public function intimacylevel() {
  1784. $user_id = input('user_id', 0, 'intval'); //对方id
  1785. if (!$user_id) {
  1786. $this->error('参数缺失');
  1787. }
  1788. if ($this->auth->gender == 0) { //女用户
  1789. $where['uid'] = $user_id;
  1790. $where['other_uid'] = $this->auth->id;
  1791. } else { //男用户
  1792. $where['uid'] = $this->auth->id;
  1793. $where['other_uid'] = $user_id;
  1794. }
  1795. $level = 0; //当前等级
  1796. $level_name = ''; //当前等级名称
  1797. $qinmi_sum = 0; //当前亲密度
  1798. $next_level_diff = 0; //距下一等级亲密度差值
  1799. //亲密度等级列表
  1800. $list = Db::name('intimacy_level')->field('name,level')->order('value')->select();
  1801. //当前亲密度信息
  1802. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  1803. if ($user_intimacy_info) {
  1804. //当前亲密度
  1805. $qinmi_sum = $user_intimacy_info['value'];
  1806. if ($list) {
  1807. //当前等级信息
  1808. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('id desc')->find();
  1809. if ($level_info) {
  1810. $level = $level_info['level'];
  1811. $level_name = $level_info['name'];
  1812. }
  1813. //下一等级信息
  1814. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  1815. if ($next_level_info) {
  1816. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  1817. }
  1818. }
  1819. } else {
  1820. $next_level_diff = Db::name('intimacy_level')->order('value')->value('value');
  1821. }
  1822. if ($list) {
  1823. foreach ($list as &$v) {
  1824. if ($v['level'] < $level) {
  1825. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  1826. } elseif ($v['level'] == $level) {
  1827. $v['is_unlock'] = 2;
  1828. } else {
  1829. $v['is_unlock'] = 3;
  1830. }
  1831. }
  1832. }
  1833. $data['level'] = $level; //当前等级
  1834. $data['level_name'] = $level_name; //当前等级名称
  1835. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  1836. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  1837. $data['level_list'] = $list; //等级列表
  1838. $this->success('亲密度等级信息', $data);
  1839. }
  1840. //语音视频随聊
  1841. public function getrandomuser() {
  1842. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1843. if (!in_array($type, [1, 2, 3])) {
  1844. $this->error('您的网络开小差了');
  1845. }
  1846. $size = input('size',0,'intval');// 是否查 10 条
  1847. $size = $size > 0 ? 1 : 0;
  1848. //给出备选用户
  1849. $map = [
  1850. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1851. 'is_active' => 1, //在线的
  1852. 'status' =>1, //未封禁用户
  1853. // 'is_online' => 0, //不在语聊间的
  1854. 'is_livebc' => 0, //不在直播的
  1855. // 'real_status' => 1, //真人认证
  1856. // 'idcard_status' => 1, //实名认证
  1857. // 'id' => ['NOT IN',$my_follow] //不是好友的
  1858. 'is_kefu' => 0, //不是客服
  1859. ];
  1860. if ($this->auth->gender == 1) {
  1861. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1862. }
  1863. if ($type == 1) {
  1864. $map['open_match_audio'] = 1;
  1865. } elseif ($type == 2) {
  1866. $map['open_match_video'] = 1;
  1867. }
  1868. $key = md5(json_encode($map));// 根据搜索条件做Key
  1869. $lists = Cache::remember("getrandomuser_{$key}_{$size}",function () use ($map,$size){
  1870. $query = Db::name('user')
  1871. ->field('id,nickname,username,avatar')
  1872. ->where($map)
  1873. ->order('is_active desc, active_time desc');
  1874. if ($size == 1){
  1875. $query->limit(10);
  1876. }else{
  1877. $query->page($this->page,100);
  1878. }
  1879. $lists = $query->select();
  1880. //$lists = $this->fliter_user($lists,100);
  1881. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1882. $mt_user_greet_content = Db::name('user_greet_content');
  1883. foreach ($lists as &$v) {
  1884. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1885. if ($info) {
  1886. if ($info['type'] == 0) {
  1887. $v['greet_content'] = $info['content'];
  1888. } elseif ($info['type'] == 1) {
  1889. $v['greet_content'] = '[语音]';
  1890. } elseif ($info['type'] == 2) {
  1891. $v['greet_content'] = '[图片]';
  1892. }
  1893. } else {
  1894. $v['greet_content'] = '';
  1895. }
  1896. }
  1897. return $lists;
  1898. },2);
  1899. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1900. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1901. $return_data['list'] = $lists;
  1902. $this->success('success',$return_data);
  1903. }
  1904. //语音视频随聊
  1905. public function getrandomuserbak() {
  1906. $type = input('type', 0, 'intval'); //类型:1语音 2视频
  1907. if (!in_array($type, [1, 2, 3])) {
  1908. $this->error('您的网络开小差了');
  1909. }
  1910. //找到互关的人,排除
  1911. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  1912. //dump($follow_me);
  1913. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  1914. //dump($my_follow);exit;
  1915. //给出备选用户
  1916. $map = [
  1917. 'status' =>1, //未封禁用户
  1918. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  1919. // 'is_online' => 0, //不在语聊间的
  1920. 'is_livebc' => 0, //不在直播的
  1921. 'is_active' => 1, //在线的
  1922. // 'real_status' => 1, //真人认证
  1923. // 'idcard_status' => 1, //实名认证
  1924. // 'id' => ['NOT IN',$my_follow] //不是好友的
  1925. 'is_kefu' => 0, //不是客服
  1926. ];
  1927. if ($this->auth->gender == 1) {
  1928. $map['real_status|idcard_status'] = 1; //真人认证或实名认证
  1929. }
  1930. if ($type == 1) {
  1931. $map['open_match_audio'] = 1;
  1932. } elseif ($type == 2) {
  1933. $map['open_match_video'] = 1;
  1934. }
  1935. $lists = Db::name('user')
  1936. ->field('id,nickname,username,avatar')
  1937. ->where($map)
  1938. ->order('is_active desc, active_time desc')
  1939. ->page($this->page,100)
  1940. ->select();
  1941. //$lists = $this->fliter_user($lists,100);
  1942. $lists = list_domain_image($lists,['avatar,audio_bio']);
  1943. $mt_user_greet_content = Db::name('user_greet_content');
  1944. foreach ($lists as &$v) {
  1945. $info = $mt_user_greet_content->where(['user_id' => $v['id'], 'is_default' => 1])->find();
  1946. if ($info) {
  1947. if ($info['type'] == 0) {
  1948. $v['greet_content'] = $info['content'];
  1949. } elseif ($info['type'] == 1) {
  1950. $v['greet_content'] = '[语音]';
  1951. } elseif ($info['type'] == 2) {
  1952. $v['greet_content'] = '[图片]';
  1953. }
  1954. } else {
  1955. $v['greet_content'] = '';
  1956. }
  1957. }
  1958. $count = Db::name('user')->where(['is_active' => 1])->count('id');
  1959. $return_data['count'] = config('site.randomuser_num') > 0 ? config('site.randomuser_num') + $count : $count;
  1960. $return_data['list'] = $lists;
  1961. $this->success('success',$return_data);
  1962. }
  1963. //查询免费体验视频通话用户信息
  1964. public function getfreevideouserinfo() {
  1965. $to_user_id = input('to_user_id', 0, 'intval');
  1966. $to_user_info = Db::name('user')->field('id,gender,nickname,avatar,birthday,height,bio')->where(['id' => $to_user_id, 'is_kefu' => 0])->find();
  1967. if(!$to_user_info){
  1968. $this->error('不存在的用户');
  1969. }
  1970. if ($to_user_info['gender'] == $this->auth->gender) {
  1971. $this->error('同性不能聊天~');
  1972. }
  1973. $to_user_info['desc'] = '';
  1974. $age = birthtime_to_age($to_user_info['birthday']);
  1975. if ($age > 0) {
  1976. $to_user_info['desc'] = $age . '岁';
  1977. } else {
  1978. $to_user_info['desc'] = '18岁';
  1979. }
  1980. if ($to_user_info['height']) {
  1981. $to_user_info['desc'] .= ' | ' . $to_user_info['height'];
  1982. }
  1983. //查询是否免费过
  1984. $to_user_info['free_count'] = 1;//Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1985. $this->success('信息', $to_user_info);
  1986. }
  1987. //免费体验视频通话1分钟
  1988. public function videochat_onemin_free(){
  1989. $this->success('success');
  1990. if ($this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1991. $this->success('success');
  1992. }
  1993. //检查是否免费过
  1994. $count = Db::name('user_match_video_log_free')->where(['user_id' => $this->auth->id])->count('id');
  1995. if ($count) {
  1996. $this->error('已经免费体验过');
  1997. }
  1998. //检测用户
  1999. $to_user_id = input_post('to_user_id');
  2000. $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();
  2001. if(!$to_user_info){
  2002. $this->error('不存在的用户');
  2003. }
  2004. if ($to_user_info['is_kefu'] == 1) { //我是客服或者对方是客服
  2005. $this->success('success');
  2006. }
  2007. if ($to_user_info['gender'] == $this->auth->gender) {
  2008. $this->error('同性不能聊天~');
  2009. }
  2010. //记录日志
  2011. $data = [
  2012. 'user_id' => $this->auth->id,
  2013. 'price' => 0,
  2014. 'createtime' => time(),
  2015. 'to_user_id' => $to_user_id,
  2016. 'money' => 0,
  2017. ];
  2018. $log_id = Db::name('user_match_video_log_free')->insertGetId($data);
  2019. if(!$log_id){
  2020. $this->error('扣费失败');
  2021. }
  2022. $this->success('success');
  2023. }
  2024. //男性非会员解锁聊天
  2025. public function unlockchat() {
  2026. // 接口防并发
  2027. if (!$this->apiLimit(1, 1000)) {
  2028. $this->error(__('Operation frequently'));
  2029. }
  2030. //男性非会员是否已开通聊天
  2031. if ($this->auth->gender == 0) {
  2032. $this->error('不需要解锁');
  2033. }
  2034. $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
  2035. if ($vip_endtime > time()) {
  2036. $this->error('不需要解锁');
  2037. }
  2038. $user_id = input('user_id', 0, 'intval');//对方id
  2039. if (!$user_id) {
  2040. $this->error();
  2041. }
  2042. // 不可以守护给自己
  2043. if($this->auth->id == $user_id) {
  2044. $this->error("不可以解锁自己");
  2045. }
  2046. //查询是否解锁过
  2047. $user_chat_unlock = Db::name('user_chat_unlock')->where(['user_id' => $this->auth->id, 'user_to_id' => $user_id])->count('id');
  2048. if ($user_chat_unlock) {
  2049. $this->error('已经解锁过了');
  2050. }
  2051. $giftvalue = config('site.unlock_chat_gold');
  2052. if ($giftvalue <= 0) {
  2053. $this->error('解锁金额异常~');
  2054. }
  2055. //被解锁人信息
  2056. $touserinfo = Db::name('user')->where('id',$user_id)->find();
  2057. if (!$touserinfo) {
  2058. $this->error("不存在的用户");
  2059. }
  2060. // 判断当前用户余额
  2061. $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
  2062. if($user_gold < $giftvalue) {
  2063. $this->error("您的金币余额不足");
  2064. }
  2065. Db::startTrans();
  2066. //添加解锁记录表
  2067. $data = [
  2068. 'user_id' => $this->auth->id,
  2069. 'user_to_id' => $user_id,
  2070. 'price' => $giftvalue,
  2071. 'createtime' => time(),
  2072. ];
  2073. $log_id = Db::name('user_chat_unlock')->insertGetId($data);
  2074. if(!$log_id){
  2075. Db::rollback();
  2076. $this->error('解锁失败');
  2077. }
  2078. if($giftvalue > 0){
  2079. // 扣除当前用户余额
  2080. $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,81,'开通守护','user_chat_unlock',$log_id);
  2081. if($wallet_rs['status'] === false){
  2082. Db::rollback();
  2083. $this->error($wallet_rs['msg']);
  2084. }
  2085. // 添加守护用户余额
  2086. $money_to_gold = config('site.money_to_gold');
  2087. $gift_plat_scale = config('site.gift_plat_scale');
  2088. $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
  2089. $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
  2090. $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,82,'被守护收益','user_chat_unlock',$log_id,2);
  2091. if($wallet_rs['status'] === false){
  2092. Db::rollback();
  2093. $this->error($wallet_rs['msg']);
  2094. }
  2095. //增加赠送用户上级余额
  2096. if ($touserinfo['intro_uid']) {
  2097. //获取返利比率
  2098. $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
  2099. $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
  2100. if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
  2101. //上级获得金额
  2102. $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
  2103. if ($intro_uid_money > 0) {
  2104. $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人解锁聊天获赠奖励','gift_user_typing',$log_id);
  2105. if($intro_result['status']===false)
  2106. {
  2107. Db::rollback();
  2108. $this->error($intro_result['msg']);
  2109. }
  2110. }
  2111. }
  2112. }
  2113. }
  2114. //tag任务守护金币
  2115. //搭讪奖励
  2116. // $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  2117. // if($task_rs === false){
  2118. // Db::rollback();
  2119. // $this->error('完成任务守护奖励失败');
  2120. // }
  2121. Db::commit();
  2122. $this->success('解锁成功');
  2123. }
  2124. }