Usercenter.php 82 KB

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