Usercenter.php 93 KB

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