Usercenter.php 93 KB

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