12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667 |
- <?php
- namespace app\common\model;
- use app\common\library\AliPay;
- use app\common\library\WxMerchPay;
- use app\common\library\WxPay;
- use app\common\model\Sms;
- use app\common\library\Email;
- use EasyWeChat\Factory;
- use phpDocumentor\Reflection\Type;
- use app\common\model\UserIntegralLog;
- use think\Model;
- use app\common\library\Common;
- use think\facade\Validate;
- use think\Request;
- use think\Db;
- use function foo\func;
- use app\common\library\WxService;
- header('Access-Control-Allow-Origin: *');
- /**
- * 会员模型
- */
- class User Extends Model
- {
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'TIMESTAMP';
- // 定义时间戳字段名
- protected $createTime = 'create_at';
- protected $updateTime = 'update_at';
- // 追加属性
- protected $append = [
- 'url',
- ];
- /**
- * 微信授权登录、注册
- */
- public static function wechatLogin($code,$rawData){
- $appid = Config::get_values('wechat_appid');
- $secret = Config::get_values('wechat_appsecret');
- $url = "https://api.weixin.qq.com/sns/jscode2session?appid=" . $appid . "&secret=" . $secret . "&js_code=" . $code . "&grant_type=authorization_code";
- $session_key = Common::curlRequest($url);
- //数据库是否已注册
- // $user = Db::name('User')->where('openid','oo7E85LrD0ovt7hbz4sZGrf-_flA')->find();
- // $user = Db::name('User')->where('id',53)->find();
- // if ($user){
- // $user['UserIformationPerfect'] = self::checkUserIformationPerfect($user['id']) ? true : false;
- // app()->session->set('us', $user);
- // //注册环信
- // // Common::huanxin_zhuce('huxuanmao-'.$user['id'],$user['nickname']);
- // return Common::return_success('授权成功',$user);
- // }
- if (!empty($session_key['session_key'])) {
- $openid = $session_key['openid'];
- //数据库是否已注册
- $user = Db::name('User')->where('openid',$openid)
- ->where('is_cancellation_account',1)
- ->where('is_del',1)
- ->find();
- if ($user){
- $user['UserIformationPerfect'] = self::checkUserIformationPerfect($user['id']) ? true : false;
- app()->session->set('us', $user);
- $users = self::getUserInfo($user['id']);
- User::where('id',$user['id'])->update(['huanxinID'=>'huxuanmao-'.$user['id']]);
- //注册环信
- Common::huanxin_zhuce('huxuanmao-'.$users['id'],$users['nickname']);
- return Common::return_success('授权成功',$users);
- }else{
- $data['sex'] = 0;
- if ($rawData){
- $rawData = json_decode($rawData,true);
- $data['nickname'] = $rawData['nickName'];
- $data['openid'] = $openid;
- $data['sex'] = $rawData['gender'];
- $data['headimgurl'] = $rawData['avatarUrl'];
- }
- // $data['province'] = $rawData['province'];
- // $data['city'] = $rawData['city'];
- Db::startTrans();
- try {
- $user = self::create($data);
- Db::commit();
- $userId =$user->id;
- $us =Db::name('User')->where('id',$userId)->find();
- $us['UserIformationPerfect'] = false;
- app()->session->set('us', $us);
- //系统赠送注册积分数量
- $register_give_integral = Config::get_values('register_give_integral');
- if ($register_give_integral>0){
- //加积分
- self::integral($register_give_integral,$userId, '注册赠送积分',1);
- }
- User::where('id',$userId)->update(['huanxinID'=>'huxuanmao-'.$userId]);
- $users = self::getUserInfo($userId);
- //注册环信
- Common::huanxin_zhuce('huxuanmao-'.$userId,$users['nickname']);
- return Common::return_success('授权成功',$users);
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('授权失败');
- }
- }
- }else{
- return Common::return_error('获取session_key失败!');
- }
- }
- /**
- * 获取用户信息
- */
- public static function getUserInfo($id=''){
- $user = app()->session->get('us');
- if ($id){
- $userid = $id;
- }else{
- $userid = $user['id'];
- }
- $userinfo = Db::name('user')->where('id',$userid)->find();
- if ($userinfo['sex']==0){
- $userinfo['sex'] = null;
- }
- if (!$userinfo['hope_age']){
- $userinfo['hope_age'] = [];
- }else{
- $userinfo['hope_age'] = explode(',',$userinfo['hope_age']);
- }
- if (!$userinfo['hope_height']){
- $userinfo['hope_height'] = [];
- }else{
- $userinfo['hope_height'] = explode(',',$userinfo['hope_height']);
- }
- if (!$userinfo['imgs']){
- $userinfo['imgs'] = [];
- }else{
- $userinfo['imgs'] = explode(',',$userinfo['imgs']);
- }
- if (!$userinfo['label']){
- $userinfo['label'] = [];
- }else{
- $userinfo['label'] = explode(',',$userinfo['label']);
- }
- if (!$userinfo['introduce_myself_imgs']) {
- $userinfo['introduce_myself_imgs'] = [];
- }else{
- $userinfo['introduce_myself_imgs'] = explode(',',$userinfo['introduce_myself_imgs']);
- }
- if (!$userinfo['family_background_imgs']) {
- $userinfo['family_background_imgs'] = [];
- }else{
- $userinfo['family_background_imgs'] = explode(',',$userinfo['family_background_imgs']);
- }
- if (!$userinfo['interests_hobbies_imgs']) {
- $userinfo['interests_hobbies_imgs'] = [];
- }else{
- $userinfo['interests_hobbies_imgs'] = explode(',',$userinfo['interests_hobbies_imgs']);
- }
- if (!$userinfo['love_imgs']){
- $userinfo['love_imgs'] = [];
- }else{
- $userinfo['love_imgs'] = explode(',',$userinfo['love_imgs']);
- }
- if (!$userinfo['other_half_imgs']){
- $userinfo['other_half_imgs'] = [];
- }else{
- $userinfo['other_half_imgs'] = explode(',',$userinfo['other_half_imgs']);
- }
- if (!$userinfo['why_single_imgs']){
- $userinfo['why_single_imgs'] = [];
- }else{
- $userinfo['why_single_imgs'] = explode(',',$userinfo['why_single_imgs']);
- }
- if (!$userinfo['look_life_imgs']){
- $userinfo['look_life_imgs'] = [];
- }else{
- $userinfo['look_life_imgs'] = explode(',',$userinfo['look_life_imgs']);
- }
- if (!$userinfo['real_auth_img']){
- $userinfo['real_auth_img'] = [];
- }else{
- $userinfo['real_auth_img'] = explode(',',$userinfo['real_auth_img']);
- }
- if (!$userinfo['work_auth_img']){
- $userinfo['work_auth_img'] = [];
- }else{
- $userinfo['work_auth_img'] = explode(',',$userinfo['work_auth_img']);
- }
- if (!$userinfo['education_auth_img']){
- $userinfo['education_auth_img'] = [];
- }else{
- $userinfo['education_auth_img'] = explode(',',$userinfo['education_auth_img']);
- }
- $userinfo['UserIformationPerfect'] = self::checkUserIformationPerfect($userid) ? true : false;
- $count = Collection::where('a.user_id',$userid)
- ->alias('a')
- ->where('b.is_del',1)
- ->join('User b','a.to_user_id=b.id')
- ->where('a.is_effective',1)
- ->count();
- $collect_num = Config::get_values('collect_num');
- $collect_num = $collect_num ? $collect_num : 10;
- $userinfo['remaining_collect_num'] = bcsub($collect_num,$count);
- $userinfo['want_know_num'] = UserWantKnow::where('a.to_user_id',$userid)
- ->alias('a')
- ->where('b.is_del',1)
- ->join('User b','a.user_id=b.id')
- ->count();
- if ($userinfo['stealth_switch_time'] && ($userinfo['stealth_switch_time']+(7*24*60*60))>time()){
- $userinfo['stealth_is_allow_open'] = false;
- }else{
- $userinfo['stealth_is_allow_open'] = true;
- }
- $userinfo['stealth_switch_end_time'] = date('Y-m-d H:i:s',$userinfo['stealth_switch_time']+(7*24*60*60)); //隐私模式下次可以开启时间
- $userinfo['stealth_switch_time'] = date('Y-m-d H:i:s',$userinfo['stealth_switch_time']); //隐私模式开启时间
- //我的动态数量
- $userinfo['dynamic_count'] = Dynamic::where('user_id',$userid)->where('is_del',1)->count();
- return $userinfo;
- }
- /**
- * 完善资料
- */
- public static function perfectInformation($data){
- $user = app()->session->get('us');
- if (isset($data['stealth_switch'])){
- if ($data['stealth_switch']==2){
- $userinfo = Db::name('user')->where('id',$user['id'])->find();
- if ($userinfo['stealth_switch_time'] && ($userinfo['stealth_switch_time']+(7*24*60*60))>time()){
- return Common::return_error('无法开启隐私模式');
- }
- $data['stealth_switch_time'] = time();
- }
- }
- $data['update_at'] = date('Y-m-d H:i:s');
- if (isset($data['imgs'])){
- $data['headimgurl'] = explode(',',$data['imgs'])[0];
- }
- Db::startTrans();
- try {
- self::where('id',$user['id'])->update($data);
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 判断用户是否完善信息
- */
- public static function checkUserIformationPerfect($user_id){
- $user = self::get($user_id);
- // if (!$user['nickname'] || !$user['headimgurl'] || !$user['date_of_birth'] || !$user['height'] || !$user['phone'] ||
- // !$user['wechat_id'] || !$user['annual_income'] || !$user['household'] || !$user['education'] || !$user['graduated_from'] ||
- // !$user['province'] || !$user['city'] || !$user['area'] || !$user['introduce_myself'] || !$user['family_background'] || !$user['interests_hobbies'] ||
- // !$user['love'] || !$user['other_half'] || !$user['why_single'] || !$user['look_life'] || !$user['label'] || !$user['imgs'] || !$user['professional']){
- // return false;
- // }
- if (!$user['nickname'] || !$user['date_of_birth'] || !$user['height'] || !$user['phone'] ||
- !$user['wechat_id'] || !$user['annual_income'] || !$user['household'] || !$user['education'] || !$user['graduated_from'] ||
- !$user['province'] || !$user['city'] || !$user['area'] || !$user['professional']){
- return false;
- }
- return true;
- }
- /**
- * 心动区
- */
- public static function cardiacArea($Nowpage,$limits){
- $user = app()->session->get('us');
- $count = UserWantKnow::where('user_id',$user['id'])->count();
- if ($count){
- $list = UserWantKnow::where('a.user_id',$user['id'])
- ->alias('a')
- ->join('User b','a.to_user_id=b.id')
- ->where('b.is_del',1)
- ->where('a.state',2)
- ->field('b.id as user_id,b.nickname,b.headimgurl,a.create_at')
- ->page($Nowpage,$limits)
- ->order('a.id desc')
- ->select()
- ->toArray();
- }else{
- $list = [];
- }
- $data['count'] = $count;
- $data['list'] = $list;
- return Common::return_success('成功',$data);
- }
- /**
- * 互选区
- */
- public static function electArea($Nowpage,$limits){
- $user = app()->session->get('us');
- $user_ids = UserWantKnow::where('to_user_id',$user['id'])->column('user_id');
- $count = UserWantKnow::where('user_id',$user['id'])->where('to_user_id','in',$user_ids)->count();
- if ($count){
- $list = UserWantKnow::where('user_id',$user['id'])
- ->alias('a')
- ->join('User b','a.to_user_id=b.id')
- ->where('b.is_del',1)
- ->field('b.id as user_id,b.nickname,b.headimgurl,a.create_at')
- ->where('a.to_user_id','in',$user_ids)
- ->order('a.id desc')
- ->page($Nowpage,$limits)
- ->select()->toArray();
- }else{
- $list = [];
- }
- $data['count'] = $count;
- $data['list'] = $list;
- return Common::return_success('成功',$data);
- }
- /**
- * 我的积分
- */
- public static function myIntegral($Nowpage,$limits,$type){
- $user = app()->session->get('us');
- $integral = self::where('id',$user['id'])->value('integral');
- $count = self::myintegralByWhere($type)->where('user_id',$user['id'])->count();
- if ($count){
- $list = self::myintegralByWhere($type)
- ->where('user_id',$user['id'])
- ->field('id,user_id,pm,title,change_money,create_at')
- ->page($Nowpage,$limits)
- ->order('id desc')->select();
- foreach ($list as $k=>$v){
- $list[$k]['create_at'] = date('Y-m-d',strtotime($v['create_at']));
- $change_money = floatval($v['change_money']);
- $change_money = $v['pm'] ? "+".$change_money : "-".$change_money;
- $list[$k]['change_money'] = $change_money;
- }
- }else{
- $list = [];
- }
- $data['count'] = $count;
- $data['list'] = $list;
- return Common::return_success('成功',compact('integral','data'));
- }
- /**
- * 我的积分where条件
- */
- public static function myintegralByWhere($type){
- $model = Db::name('UserIntegralLog');
- if ($type=='' || $type==-1){
- return $model;
- }elseif ($type==1){
- return $model->where('pm',1);
- }elseif ($type==2){
- return $model->where('pm',0);
- }
- }
- /**
- * 消息
- */
- public static function message($Nowpage,$limits){
- $user = app()->session->get('us');
- //系统消息
- $official = OfficialMessage::where('status',1)
- ->where('is_del',1)
- ->field('id,content,create_at')
- ->select();
- if ($official){
- $official = $official->toArray();
- foreach ($official as $k=>$v){
- $official[$k]['id'] = 'off_'.$v['id'];
- $official[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
- $official[$k]['user_id'] = 0;
- $official[$k]['type'] = 3;
- $official[$k]['title'] = '官方消息';
- $read = OfficialUser::where('message_id',$v['id'])->where('user_id',$user['id'])->count();
- $official[$k]['is_read'] = $read ? 1 : 0;
- }
- }
- $list = Message::where('user_id',$user['id'])
- ->page($Nowpage,$limits)
- ->order('id desc')
- ->select();
- if ($list){
- $list = $list->toArray();
- foreach ($list as $k=>$v){
- $list[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
- }
- }
- $list = array_merge($official,$list);
- $count = count($list);
- array_multisort(array_column($list,'create_at'),SORT_DESC,$list);
- $list = array_slice($list,($Nowpage-1)*$limits,$limits);
- return Common::return_success('成功',compact('count','list'));
- // $count = Message::where('user_id',$user['id'])->count();
- // if ($count){
- // $list = Message::where('user_id',$user['id'])
- // ->page($Nowpage,$limits)
- // ->order('id desc')
- // ->select()->toArray();
- // foreach ($list as $k=>$v){
- // $list[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
- // }
- // }else{
- // $list = [];
- // }
- // $data['count'] = $count;
- // $data['list'] = $list;
- // return Common::return_success('成功',$data);
- }
- /**
- * 读取消息
- */
- public static function readMessage($message_id){
- $user = app()->session->get('us');
- $message = Message::get($message_id);
- if (!$message){
- $id = explode('_',$message_id);
- $official = OfficialMessage::where('id',$id[1])->where('status',1)->where('is_del',1)->find();
- if (!$official)
- return Common::return_error('消息不存在');
- }
- Db::startTrans();
- try {
- if ($message){
- $message->is_read = 1;
- $message->save();
- }elseif ($official){
- $message_user = OfficialUser::where('message_id',$id[1])->where('user_id',$user['id'])->count();
- if (!$message_user){
- $data['message_id'] = $id[1];
- $data['user_id'] = $user['id'];
- OfficialUser::create($data);
- }
- }
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 剩余未读消息数量
- */
- public static function messageCount(){
- $user = app()->session->get('us');
- if ($user){
- //系统消息未读数量
- $ids = OfficialMessage::where('status',1)->where('is_del',1)->column('id');
- $is_read_count = OfficialUser::whereIn('message_id',$ids)->where('user_id',$user['id'])->count();
- $off_count = bcsub(count($ids),$is_read_count);
- //消息表未读数量
- $count = Message::where('user_id',$user['id'])->where('is_read',0)->count();
- $count = bcadd($off_count,$count);
- }else{
- $count = 0;
- }
- return Common::return_success('成功',$count);
- }
- /**
- * 变更会员余额
- * @param int $money 余额
- * @param int $user_id 会员ID
- * @param string $memo 备注
- */
- public static function integral($integral, $user_id, $memo, $pm = 0)
- {
- $user = self::get($user_id);
- if ($user)
- {
- $before = $user->integral;
- if ($pm==1){
- $after = $user->integral + $integral;
- }else{
- $after = $user->integral - $integral;
- }
- //更新会员信息
- $user->save(['integral' => $after]);
- //写入日志
- MoneyLog::create(['user_id' => $user_id,'pm' => $pm, 'change_money' => $integral, 'before' => $before, 'after' => $after, 'title' => $memo]);
- }
- }
- /**
- * 变更会员余额
- * @param int $money 余额
- * @param int $user_id 会员ID
- * @param string $memo 备注
- */
- public static function money($money, $user_id, $memo, $pm = 0)
- {
- $user = self::get($user_id);
- if ($user)
- {
- $before = $user->money;
- if ($pm==1){
- $after = $user->money + $money;
- }else{
- $after = $user->money - $money;
- }
- //更新会员信息
- $user->save(['money' => $after]);
- //写入日志
- MoneyLog2::create(['user_id' => $user_id,'pm' => $pm, 'change_money' => $money, 'before' => $before, 'after' => $after, 'title' => $memo]);
- }
- }
- /**
- * 置顶用户列表
- */
- public static function topUser($city){
- $count = self::topUserByWhere($city)->count();
- if ($count){
- $list = self::topUserByWhere($city)
- ->order('like_count desc')
- ->limit(10)
- ->select();
- }else{
- $city = '广州市';
- $list = self::topUserByWhere($city)
- ->order('like_count desc')
- ->limit(10)
- ->select();
- }
- if ($list){
- foreach ($list as $k=>$v){
- if (!$v['imgs']){
- $list[$k]['imgs'] = [];
- }else{
- $list[$k]['imgs'] = explode(',',$v['imgs']);
- }
- }
- }
- return Common::return_success('成功',$list);
- }
- /**
- * 置顶用户条件
- */
- public static function topUserByWhere($city){
- $user = app()->session->get('us');
- $user_id = $user['id'];
- $user = Db::name('user')->where('id',$user['id'])->find();
- $sex = $user['sex'];
- $work_auth_status = $user['work_auth_status'];
- $work_auth_company_name = $user['work_auth_company_name'];
- return Db::name('User')
- ->where('is_home',1)
- ->where('stealth_switch',1)
- ->where('is_cancellation_account',1)
- ->where('is_del',1)
- ->when($city,function ($query) use ($city){
- if ($city)
- $query->whereLike('city','%'.$city.'%');
- })
- ->when($user_id,function ($query) use ($user_id,$sex){
- if ($user_id){
- $sex = $sex==1 ? 2 : 1;
- $query->where('sex',$sex);
- }
- })
- ->when($work_auth_company_name,function ($query) use ($work_auth_company_name,$work_auth_status,$user_id){
- if ($user_id && $work_auth_company_name && $work_auth_status==1){
- $query->whereRaw('work_auth_company_name like "%'.$work_auth_company_name.'%" and shielding_colleagues_switch=1 or work_auth_company_name not like "%'.$work_auth_company_name.'%" or work_auth_company_name=""');
- }
- })
- ->field('*,'.UserWantKnow::where('to_user_id',$user_id)->count().' as like_count');
- }
- /**
- * 首页推荐嘉宾列表
- */
- public static function recommendedUser($city){
- $user = app()->session->get('us');
- $user = Db::name('user')->where('id',$user['id'])->find();
- if ($user){
- $list = self::byWhere($city)
- ->order('like_count desc')
- ->limit(5)
- ->select();
- if (!$list){
- $city = '广州市';
- $list = self::topUserByWhere($city)
- ->order('like_count desc')
- ->limit(5)
- ->select();
- }
- }else{
- $city = '广州市';
- $list = self::topUserByWhere($city)
- ->order('like_count desc')
- ->limit(5)
- ->select();
- }
- if ($list){
- foreach ($list as $k=>$v){
- if (!$v['imgs']){
- $list[$k]['imgs'] = [];
- }else{
- $list[$k]['imgs'] = explode(',',$v['imgs']);
- }
- if ($v['household']){
- $household = explode('-',$v['household']);
- $list[$k]['household_city'] = isset($household[1]) ? $household[1] : '';
- }else{
- $list[$k]['household_city'] = '';
- }
- }
- }
- return Common::return_success('成功',$list);
- }
- /**
- * 单身广场
- */
- public static function singleUser($city,$keywords,$Nowpage,$limits){
- $count = self::byWhere($city)->count();
- if ($count){
- $list = self::byWhere($city,$keywords)
- ->orderRand()
- //->order('like_count desc')
- ->page($Nowpage,$limits)
- ->select();
- }else{
- $city = '广州市';
- $list = self::topUserByWhere($city)
- ->orderRand()
- // ->order('like_count desc')
- ->page($Nowpage,$limits)
- ->select();
- }
- if ($list){
- foreach ($list as $k=>$v){
- if ($v['household']){
- $household = explode('-',$v['household']);
- $list[$k]['household_city'] = isset($household[1]) ? $household[1] : '';
- }else{
- $list[$k]['household_city'] = '';
- }
- if (!$v['imgs']){
- $list[$k]['imgs'] = [];
- }else{
- $list[$k]['imgs'] = explode(',',$v['imgs']);
- }
- }
- }
- return Common::return_success('成功',compact('count','list'));
- }
- /**
- * where条件
- */
- public static function byWhere($city,$keywords=''){
- $user = app()->session->get('us');
- $user = Db::name('user')->where('id',$user['id'])->find();
- $sex = $user['sex'];
- $hope_age = $user['hope_age'];
- $hope_height = $user['hope_height'];
- $hope_city = $user['hope_city'];
- $hope_hometown = $user['hope_hometown'];
- $hope_education = $user['hope_education'];
- $hope_marriage = $user['hope_marriage'];
- $household = $user['household'];
- $work_auth_status = $user['work_auth_status'];
- $work_auth_company_name = $user['work_auth_company_name'];
- return Db::name('User')
- ->where('stealth_switch',1)
- ->where('is_cancellation_account',1)
- ->where('is_del',1)
- ->when($keywords,function ($query) use ($keywords){
- if ($keywords){
- $query->whereLike('nickname','%'.$keywords.'%');
- }
- })
- ->when($sex,function ($query) use ($sex){
- $sex = $sex==1 ? 2 : 1;
- $query->where('sex',$sex);
- $user = Db::name('User')->where('sex',$sex)->where('is_del',1)
- ->field('id,nickname,headimgurl,date_of_birth,height,phone,wechat_id,annual_income,household,education,graduated_from,province,city,area,introduce_myself,family_background,interests_hobbies,love,other_half,why_single,look_life,label,imgs,professional')
- ->select();
- $ids = [];
- if ($user){
- foreach ($user as &$k){
- $improve = intval(count(array_filter($k))/count($k)*100); //完善度
- if ($improve>=50){
- $ids[] = $k['id'];
- }
- }
- }
- if (count($ids)>0){
- $query->whereIn('id',$ids);
- }
- })
- ->when($hope_age,function ($query) use ($hope_age){
- if ($hope_age){
- $query->whereBetween('age',$hope_age);
- }
- })
- ->when($hope_height,function ($query) use ($hope_height){
- if ($hope_height){
- $query->whereBetween('height',$hope_height);
- }
- })
- ->when($hope_city,function ($query) use ($hope_city,$city){
- if ($hope_city && $hope_city==2 && $city){
- $query->whereLike('city','%'.$city.'%');
- }elseif ($hope_city && $hope_city==1 && $city){
- $query->orderRaw('city="'.$city.'" desc');
- }
- })
- ->when($hope_education,function ($query) use ($hope_education){
- if ($hope_education==1){
- $array = ['本科','硕士','博士'];
- $query->whereIn('education',$array);
- }elseif ($hope_education==2){
- $array = ['硕士','博士'];
- $query->whereIn('education',$array);
- }
- })
- ->when($hope_marriage,function ($query) use ($hope_marriage){
- if ($hope_marriage && $hope_marriage==1){
- $query->where('marriage',1);
- }
- })
- ->when($work_auth_company_name,function ($query) use ($work_auth_company_name,$work_auth_status){
- if ($work_auth_company_name && $work_auth_status==1){
- $query->whereRaw('work_auth_company_name like "%'.$work_auth_company_name.'%" and shielding_colleagues_switch=1 or work_auth_company_name not like "%'.$work_auth_company_name.'%" or work_auth_company_name=""' );
- }
- })
- ->when($hope_hometown,function ($query) use ($hope_hometown,$household){
- if ($hope_hometown && $hope_hometown==2){
- $query->orderRaw('household="'.$household.'" desc');
- }
- })
- ->field('*,'.UserWantKnow::where('to_user_id',$user['id'])->count().' as like_count');
- }
- /**
- * 判断认证信息
- * type 1:实名认证 2:工作认证 3:学历认证
- */
- public static function check_auth($type){
- $user = app()->session->get('us');
- $user = Db::name('user')->where('id',$user['id'])->find();
- switch ($type){
- case 1:
- if ($user['real_auth_status']==1){
- return false;
- }
- break;
- case 2:
- if ($user['work_auth_status']==1){
- return false;
- }
- break;
- case 3:
- if ($user['education_auth_status']==1){
- return false;
- }
- break;
- }
- return true;
- }
- /**
- * 收藏用户
- */
- public static function collectUser($user_id){
- $user = app()->session->get('us');
- if ($user_id==$user['id'])
- return Common::return_error('不能收藏自己');
- $collect = Collection::where('user_id',$user['id'])
- ->where('to_user_id',$user_id)
- ->where('is_effective',1)
- ->find();
- if ($collect)
- return Common::return_error('已收藏');
- $count = Collection::where('a.user_id',$user['id'])
- ->alias('a')
- ->where('b.is_del',1)
- ->join('User b','a.to_user_id=b.id')
- ->where('a.is_effective',1)
- ->count();
- $collect_num = Config::get_values('collect_num');
- $collect_num = $collect_num ? $collect_num : 10;
- if ($count>=$collect_num)
- return Common::return_error('收藏卡数量不足');
- $data['user_id'] = $user['id'];
- $data['to_user_id'] = $user_id;
- if (Collection::create($data)){
- return Common::return_success('收藏成功');
- }else{
- return Common::return_error('收藏失败');
- }
- }
- /**
- * 取消收藏用户
- */
- public static function delCollectUser($user_id){
- $user = app()->session->get('us');
- $collect = Collection::where('user_id',$user['id'])
- ->where('to_user_id',$user_id)
- ->where('is_effective',1)
- ->find();
- if (!$collect)
- return Common::return_error('未收藏过');
- if (Collection::where('id',$collect['id'])->delete()){
- return Common::return_success('取消成功');
- }else{
- return Common::return_error('取消失败');
- }
- }
- /**
- * 收藏列表
- */
- public static function collectList(){
- $user = app()->session->get('us');
- $list = Collection::where('a.user_id',$user['id'])->alias('a')
- ->where('a.is_effective',1)
- ->where('b.is_del',1)
- ->join('User b','a.to_user_id=b.id')
- ->order('a.id desc')
- ->field('b.*')
- ->select();
- if ($list) $list = $list->toArray();
- foreach ($list as $k=>$v){
- if (!$v['imgs']){
- $list[$k]['imgs'] = [];
- }else{
- $list[$k]['imgs'] = explode(',',$v['imgs']);
- }
- if ($v['household']){
- $household = explode('-',$v['household']);
- $list[$k]['household_city'] = isset($household[1]) ? $household[1] : '';
- }else{
- $list[$k]['household_city'] = '';
- }
- }
- return Common::return_success('成功',$list);
- }
- /**
- * 特权价格列表
- */
- public static function privilegePriceList(){
- $list = PrivilegePrice::where('is_del',1)
- ->where('status',1)
- ->order('integral asc')
- ->field('status,is_del,create_at,update_at',true)
- ->select();
- if ($list) $list = $list->toArray();
- return Common::return_success('成功',$list);
- }
- /**
- * 开通特权
- */
- public static function openPrivilege($privilege_id){
- $user = app()->session->get('us');
- $user = Db::name('user')->where('id',$user['id'])->find();
- $privilege = PrivilegePrice::where('id',$privilege_id)
- ->where('status',1)
- ->where('is_del',1)
- ->find();
- if (!$privilege)
- return Common::return_error('价格不存在');
- if ($user['integral']<$privilege['integral'])
- return Common::return_error('积分不足');
- Db::startTrans();
- try {
- if ($user['open_privilege']==1)
- $privilege_overdue_time = $user['privilege_overdue_time']+$privilege['day']*24*60*60;
- else
- $privilege_overdue_time = time() + $privilege['day']*24*60*60;
- //扣除积分
- self::integral($privilege['integral'],$user['id'],'开通特权');
- self::where('id',$user['id'])->update(['open_privilege'=>1,'privilege_overdue_time'=>$privilege_overdue_time]);
- $data['user_id'] = $user['id'];
- $data['privilege_id'] = $privilege_id;
- $data['title'] = $privilege['title'];
- $data['day'] = $privilege['day'];
- PrivilegeLog::create($data);
- Db::commit();
- return Common::return_success('开成通功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('开通失败');
- }
- }
- /**
- * 想认识我列表
- */
- public static function wantToMeList($Nowpage,$limits){
- $user = app()->session->get('us');
- $user = Db::name('user')->where('id',$user['id'])->find();
- if (!$user['open_privilege'])
- return Common::return_error('未开通特权');
- $count = UserWantKnow::where('a.to_user_id',$user['id'])
- ->alias('a')
- ->where('b.is_del',1)
- ->join('User b','a.user_id=b.id')
- ->count();
- if ($count){
- $list = UserWantKnow::where('a.to_user_id',$user['id'])
- ->alias('a')
- ->where('b.is_del',1)
- ->join('User b','a.user_id=b.id')
- ->field('b.id as user_id,b.nickname,b.headimgurl,a.create_at')
- ->page($Nowpage,$limits)
- ->order('a.id desc')
- ->select()
- ->toArray();
- }else{
- $list = [];
- }
- return Common::return_success('成功',compact('count','list'));
- }
- /**
- * 我想认识-收到的
- */
- public static function ReceiveWantKnow(){
- $user = app()->session->get('us');
- //待处理列表
- $pending = UserWantKnow::where('to_user_id',$user['id'])
- ->where('state',1)
- ->field('id,leave_message,state,deal_at,refused_why,create_at,user_id')
- ->order('id desc')
- ->all()
- ->toArray();
- if ($pending){
- foreach ($pending as &$v){
- $seven = date('Y-m-d H:i:s',strtotime($v['create_at'])+(7*24*60*60));
- $v['seven'] = Common::timeTranRun($seven);
- $touser = Db::name('User')->where('id',$v['user_id'])->find();
- if (!$touser)
- return Common::return_error('用户不存在');
- if (!$touser['label']){
- $touser['label'] = [];
- }else{
- $touser['label'] = explode(',', $touser['label']);
- }
- if (!$touser['imgs']){
- $touser['imgs'] = [];
- }else{
- $touser['imgs'] = explode(',',$touser['imgs']);
- }
- if (!$touser['hope_age']){
- $touser['hope_age'] = [];
- }else{
- $touser['hope_age'] = explode(',',$touser['hope_age']);
- }
- if (!$touser['hope_height']){
- $touser['hope_height'] = [];
- }else{
- $touser['hope_height'] = explode(',',$touser['hope_height']);
- }
- if (!$touser['introduce_myself_imgs']) {
- $touser['introduce_myself_imgs'] = [];
- }else{
- $touser['introduce_myself_imgs'] = explode(',',$touser['introduce_myself_imgs']);
- }
- if (!$touser['family_background_imgs']) {
- $touser['family_background_imgs'] = [];
- }else{
- $touser['family_background_imgs'] = explode(',',$touser['family_background_imgs']);
- }
- if (!$touser['interests_hobbies_imgs']) {
- $touser['interests_hobbies_imgs'] = [];
- }else{
- $touser['interests_hobbies_imgs'] = explode(',',$touser['interests_hobbies_imgs']);
- }
- if (!$touser['love_imgs']){
- $touser['love_imgs'] = [];
- }else{
- $touser['love_imgs'] = explode(',',$touser['love_imgs']);
- }
- if (!$touser['other_half_imgs']){
- $touser['other_half_imgs'] = [];
- }else{
- $touser['other_half_imgs'] = explode(',',$touser['other_half_imgs']);
- }
- if (!$touser['why_single_imgs']){
- $touser['why_single_imgs'] = [];
- }else{
- $touser['why_single_imgs'] = explode(',',$touser['why_single_imgs']);
- }
- if (!$touser['look_life_imgs']){
- $touser['look_life_imgs'] = [];
- }else{
- $touser['look_life_imgs'] = explode(',',$touser['look_life_imgs']);
- }
- if (!$touser['real_auth_img']){
- $touser['real_auth_img'] = [];
- }else{
- $touser['real_auth_img'] = explode(',',$touser['real_auth_img']);
- }
- if (!$touser['work_auth_img']){
- $touser['work_auth_img'] = [];
- }else{
- $touser['work_auth_img'] = explode(',',$touser['work_auth_img']);
- }
- if (!$touser['education_auth_img']){
- $touser['education_auth_img'] = [];
- }else{
- $touser['education_auth_img'] = explode(',',$touser['education_auth_img']);
- }
- if ($touser['household']){
- $household = explode('-',$touser['household']);
- $touser['household_city'] = $household[1];
- }else{
- $touser['household_city'] = '';
- }
- $v['userinfo'] = $touser;
- }
- }
- $pend['count'] = count($pending);
- $pend['list'] = $pending;
- $array['pending'] = $pend;
- //已处理
- $have_deal = UserWantKnow::where('to_user_id',$user['id'])
- ->alias('a')
- ->join('User b','a.user_id=b.id')
- ->where('a.state','neq',1)
- ->field('a.id,a.user_id,a.leave_message,a.state,a.deal_at,a.refused_why,a.create_at,b.nickname,b.headimgurl')
- ->order('id desc')
- ->all()
- ->toArray();
- if ($have_deal){
- foreach ($have_deal as &$v){
- $seven = date('Y-m-d H:i:s',strtotime($v['create_at'])+(7*24*60*60));
- $v['seven'] = Common::timeTranRun($seven);
- $touser = Db::name('User')->where('id',$v['user_id'])->find();
- if (!$touser)
- return Common::return_error('用户不存在');
- if (!$touser['label']){
- $touser['label'] = [];
- }else{
- $touser['label'] = explode(',', $touser['label']);
- }
- if (!$touser['imgs']){
- $touser['imgs'] = [];
- }else{
- $touser['imgs'] = explode(',',$touser['imgs']);
- }
- if (!$touser['hope_age']){
- $touser['hope_age'] = [];
- }else{
- $touser['hope_age'] = explode(',',$touser['hope_age']);
- }
- if (!$touser['hope_height']){
- $touser['hope_height'] = [];
- }else{
- $touser['hope_height'] = explode(',',$touser['hope_height']);
- }
- if (!$touser['introduce_myself_imgs']) {
- $touser['introduce_myself_imgs'] = [];
- }else{
- $touser['introduce_myself_imgs'] = explode(',',$touser['introduce_myself_imgs']);
- }
- if (!$touser['family_background_imgs']) {
- $touser['family_background_imgs'] = [];
- }else{
- $touser['family_background_imgs'] = explode(',',$touser['family_background_imgs']);
- }
- if (!$touser['interests_hobbies_imgs']) {
- $touser['interests_hobbies_imgs'] = [];
- }else{
- $touser['interests_hobbies_imgs'] = explode(',',$touser['interests_hobbies_imgs']);
- }
- if (!$touser['love_imgs']){
- $touser['love_imgs'] = [];
- }else{
- $touser['love_imgs'] = explode(',',$touser['love_imgs']);
- }
- if (!$touser['other_half_imgs']){
- $touser['other_half_imgs'] = [];
- }else{
- $touser['other_half_imgs'] = explode(',',$touser['other_half_imgs']);
- }
- if (!$touser['why_single_imgs']){
- $touser['why_single_imgs'] = [];
- }else{
- $touser['why_single_imgs'] = explode(',',$touser['why_single_imgs']);
- }
- if (!$touser['look_life_imgs']){
- $touser['look_life_imgs'] = [];
- }else{
- $touser['look_life_imgs'] = explode(',',$touser['look_life_imgs']);
- }
- if (!$touser['real_auth_img']){
- $touser['real_auth_img'] = [];
- }else{
- $touser['real_auth_img'] = explode(',',$touser['real_auth_img']);
- }
- if (!$touser['work_auth_img']){
- $touser['work_auth_img'] = [];
- }else{
- $touser['work_auth_img'] = explode(',',$touser['work_auth_img']);
- }
- if (!$touser['education_auth_img']){
- $touser['education_auth_img'] = [];
- }else{
- $touser['education_auth_img'] = explode(',',$touser['education_auth_img']);
- }
- if ($touser['household']){
- $household = explode('-',$touser['household']);
- $touser['household_city'] = $household[1];
- }else{
- $touser['household_city'] = '';
- }
- $v['userinfo'] = $touser;
- }
- }
- $deal['count'] = count($have_deal);
- $deal['list'] = $have_deal;
- $array['have_deal'] = $deal;
- return Common::return_success('成功',$array);
- }
- /**
- * 我想认识-我发出的
- */
- public static function ApplyWantKnow(){
- $user = app()->session->get('us');
- $list = UserWantKnow::where('user_id',$user['id'])
- ->field('id,leave_message,state,deal_at,refused_why,create_at,to_user_id')
- ->whereNotIn('state','4,5')
- ->order('id desc')
- ->all()
- ->toArray();
- foreach ($list as &$v){
- $seven = date('Y-m-d H:i:s',strtotime($v['create_at'])+(7*24*60*60));
- $v['seven'] = Common::timeTranRun($seven);
- $touser = Db::name('User')->where('id',$v['to_user_id'])->find();
- if (!$touser)
- return Common::return_error('用户不存在');
- if (!$touser['label']){
- $touser['label'] = [];
- }else{
- $touser['label'] = explode(',', $touser['label']);
- }
- if (!$touser['imgs']){
- $touser['imgs'] = [];
- }else{
- $touser['imgs'] = explode(',',$touser['imgs']);
- }
- if (!$touser['hope_age']){
- $touser['hope_age'] = [];
- }else{
- $touser['hope_age'] = explode(',',$touser['hope_age']);
- }
- if (!$touser['hope_height']){
- $touser['hope_height'] = [];
- }else{
- $touser['hope_height'] = explode(',',$touser['hope_height']);
- }
- if (!$touser['introduce_myself_imgs']) {
- $touser['introduce_myself_imgs'] = [];
- }else{
- $touser['introduce_myself_imgs'] = explode(',',$touser['introduce_myself_imgs']);
- }
- if (!$touser['family_background_imgs']) {
- $touser['family_background_imgs'] = [];
- }else{
- $touser['family_background_imgs'] = explode(',',$touser['family_background_imgs']);
- }
- if (!$touser['interests_hobbies_imgs']) {
- $touser['interests_hobbies_imgs'] = [];
- }else{
- $touser['interests_hobbies_imgs'] = explode(',',$touser['interests_hobbies_imgs']);
- }
- if (!$touser['love_imgs']){
- $touser['love_imgs'] = [];
- }else{
- $touser['love_imgs'] = explode(',',$touser['love_imgs']);
- }
- if (!$touser['other_half_imgs']){
- $touser['other_half_imgs'] = [];
- }else{
- $touser['other_half_imgs'] = explode(',',$touser['other_half_imgs']);
- }
- if (!$touser['why_single_imgs']){
- $touser['why_single_imgs'] = [];
- }else{
- $touser['why_single_imgs'] = explode(',',$touser['why_single_imgs']);
- }
- if (!$touser['look_life_imgs']){
- $touser['look_life_imgs'] = [];
- }else{
- $touser['look_life_imgs'] = explode(',',$touser['look_life_imgs']);
- }
- if (!$touser['real_auth_img']){
- $touser['real_auth_img'] = [];
- }else{
- $touser['real_auth_img'] = explode(',',$touser['real_auth_img']);
- }
- if (!$touser['work_auth_img']){
- $touser['work_auth_img'] = [];
- }else{
- $touser['work_auth_img'] = explode(',',$touser['work_auth_img']);
- }
- if (!$touser['education_auth_img']){
- $touser['education_auth_img'] = [];
- }else{
- $touser['education_auth_img'] = explode(',',$touser['education_auth_img']);
- }
- if ($touser['household']){
- $household = explode('-',$touser['household']);
- $touser['household_city'] = $household[1];
- }else{
- $touser['household_city'] = '';
- }
- $v['userinfo'] = $touser;
- }
- $count = count($list);
- return Common::return_success('成功',compact('count','list'));
- }
- /**
- * 我想认识-查看详情
- */
- public static function WantKnowDetail($id){
- $user = app()->session->get('us');
- $info = UserWantKnow::where('id',$id)->find()->toArray();
- $seven = date('Y-m-d H:i:s',strtotime($info['create_at'])+(7*24*60*60));
- $info['seven'] = Common::timeTranRun($seven);
- $times = Common::timeTranRun2($seven);
- $info['day'] = $times['date'];
- $info['hour'] = $times['hour'];
- $info['minute'] = $times['minute'];
- $info['seconds'] = $times['seconds'];
- $info['list'] = UserWantKnowRecord::where('know_id',$id)
- ->where('user_id',$user['id'])
- ->order('sort desc')
- ->all()
- ->toArray();
- $array['info'] = $info;
- return Common::return_success('成功',$info);
- }
- /**
- * 好友列表
- */
- public static function FriendList(){
- $user = app()->session->get('us');
- $array = array();
- //系统消息
- $official = OfficialMessage::where('status',1)
- ->where('is_del',1)
- ->field('id,content,create_at')
- ->select();
- if ($official){
- $official = $official->toArray();
- foreach ($official as $k=>$v){
- $official[$k]['id'] = 'off_'.$v['id'];
- $official[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
- $official[$k]['user_id'] = 0;
- $official[$k]['type'] = 3;
- $official[$k]['title'] = '官方消息';
- $read = OfficialUser::where('message_id',$v['id'])->where('user_id',$user['id'])->count();
- $official[$k]['is_read'] = $read ? 1 : 0;
- }
- }
- $list = Message::where('user_id',$user['id'])
- ->order('id desc')
- ->select();
- if ($list){
- $list = $list->toArray();
- foreach ($list as $k=>$v){
- $list[$k]['create_at'] = date('Y-m-d H:s',strtotime($v['create_at']));
- }
- }
- $list = array_merge($official,$list);
- array_multisort(array_column($list,'create_at'),SORT_DESC,$list);
- $array['message_list'] = $list;
- //获取环信好友ID
- $ids = Common::friend_list('huxuanmao-'.$user['id']);
- //全部好友
- $good_friends = Db::name('user')->whereIn('huanxinID',$ids)
- ->field('id,nickname,headimgurl,age,education,height,work_auth_company_name,graduated_from')
- ->select();
- if ($good_friends){
- foreach ($good_friends as &$v){
- $star = UserStar::where('user_id',$user['id'])->where('to_user_id',$v['id'])->count();
- $v['star'] = $star ? true : false;
- //我是否屏蔽对方
- $shielding_user =ShieldingKnowUsers::where('user_id',$user['id'])->where('to_user_id',$v['id'])->count();
- $v['shielding_to'] = $shielding_user > 0 ? true : false;
- //对方是否屏蔽我
- $shielding_my =ShieldingKnowUsers::where('user_id',$v['id'])->where('to_user_id',$user['id'])->count();
- $v['shielding_my'] = $shielding_my > 0 ? true : false;
- }
- }
- $array['good_friends'] = $good_friends;
- //星标好友
- $toUserIds = UserStar::where('user_id',$user['id'])->column('to_user_id');
- $star_friends = Db::name('user')->whereIn('huanxinID',$ids)
- ->whereIn('id',$toUserIds)
- ->field('id,nickname,headimgurl,age,education,height,work_auth_company_name,graduated_from')
- ->select();
- if ($star_friends){
- foreach ($star_friends as &$v){
- //我是否屏蔽对方
- $shielding_user =ShieldingKnowUsers::where('user_id',$user['id'])->where('to_user_id',$v['id'])->count();
- $v['shielding_to'] = $shielding_user > 0 ? true : false;
- //对方是否屏蔽我
- $shielding_my =ShieldingKnowUsers::where('user_id',$v['id'])->where('to_user_id',$user['id'])->count();
- $v['shielding_my'] = $shielding_my > 0 ? true : false;
- }
- }
- $array['star_friends'] = $star_friends;
- return Common::return_success('成功',$array);
- }
- /**
- * 聊天小图标列表
- */
- public static function IconList(){
- $list = Icon::where('status',1)
- ->field('is_del,status,update_at',true)
- ->where('is_del',1)
- ->all();
- return Common::return_success('成功',$list);
- }
- /**
- * 积分充值
- */
- public static function userRecharge($integral){
- $user = app()->session->get('us');
- $userinfo = self::where('id',$user['id'])->find();
- //获取支付金额
- $pay_money = $integral;
- $wx = new WxPay();//实例化微信torganizationid支付控制器
- $notify_url = 'https://'.$_SERVER['SERVER_NAME'].'/api/pay/pay_check_order';//回调地址
- $config = $wx->retrunconfig();
- $config['notify_url'] = $notify_url;
- $order_no = Common::getNewOrderId($user['id']);
- $body = '订单号' . $order_no;//支付说明
- $total_fee = $pay_money * 100;//支付金额(乘以100)
- Db::startTrans();
- try{
- $data['user_id'] = $user['id'];
- $data['order_no'] = $order_no;
- $data['price'] = $pay_money;
- UserRecharge::create($data);
- $app = Factory::payment($config);
- $order = $app->order->unify([
- 'body' => $body,
- 'out_trade_no' => $order_no,
- 'total_fee' => $total_fee,
- 'trade_type' => "JSAPI", // JSAPI--JSAPI支付(或小程序支付)、NATIVE--Native支付、APP--app支付,MWEB--H5支付
- 'openid' => $userinfo['openid'],
- ]);
- if ($order['return_msg']=='OK'){
- if ($order['result_code']=='FAIL'){
- Db::rollback();
- return Common::return_error($order['err_code_des']);
- }else{
- $order1 = $app->jssdk->bridgeConfig($order['prepay_id']);//执行二次签名返回参数
- $retrun_data['order_no'] = $order_no;
- $retrun_data['pay'] = json_decode($order1,true);
- Db::commit();
- return Common::return_success('成功',$retrun_data);
- }
- } else {
- Db::rollback();
- return Common::return_error($order['return_msg']);
- }
- }catch (Exception $e){
- Db::rollback();
- return Common::return_error($order['return_msg']);
- }
- }
- /**
- * 余额提现
- */
- public static function userWithdraw($money){
- $user = app()->session->get('us');
- $userinfo = self::where('id',$user['id'])->find();
- $withdraw_min_price = Config::get_values('withdraw_min_price'); //最小提现金额
- $withdraw_max_price = Config::get_values('withdraw_max_price'); //最大提现金额
- if ($money < $withdraw_min_price)
- return Common::return_error('最低提现'.$withdraw_min_price.'元');
- if ($money > $withdraw_max_price)
- return Common::return_error('最大提现'.$withdraw_min_price.'元');
- if ($userinfo['integral']<$money)
- return Common::return_error('余额不足');
- if (!$userinfo['wechat_id'])
- return Common::return_error('微信号未设置,请先完善资料');
- $data['user_id'] = $user['id'];
- $order_no = Common::getNewOrderId($user['id']);
- $data['order_no'] = $order_no;
- $data['price'] = $money;
- $poundage_proportion = Config::get_values('poundage_proportion'); //手续费百分比
- $data['poundage_proportion'] = $poundage_proportion;
- $proportion = sprintf("%.2f", $money*($poundage_proportion/100)); //四舍五入保留两位小数点
- $data['proportion'] = $proportion;
- $real_money = $money-$proportion;
- $data['real_money'] = $real_money;
- Db::startTrans();
- try {
- UserWithdraw::create($data);
- User::integral($money,$user['id'],'微信提现'.$money);
- //消息推送
- $openid = User::where('administrator',1)->where('is_del',1)->order('id asc')->limit(1)->value('openid');
- $template_id = "gJRFKgj0PSYrz0Yg0HxMZUH0Sm3r9Uux1mDFOkDBc44";
- $path = "";
- $data = [
- 'first'=>[
- "value"=>'你好,有一笔提现申请未处理',
- "color"=>"#173177"
- ],
- 'keyword1'=>[
- "value"=>$user['nickname'],
- "color"=>"#173177"
- ],
- 'keyword2'=>[
- "value"=>date('Y-m-d H:i:s'),
- "color"=>"#173177"
- ],
- 'keyword3'=>[
- "value"=>$money."元",
- "color"=>"#173177"
- ],
- 'keyword4'=>[
- "value"=>"微信提现",
- "color"=>"#173177"
- ],
- 'remark'=>[
- "value"=>'快去处理吧',
- "color"=>"#173177"
- ]
- ];
- Common::sendTemplateMsg($openid,$template_id,$path,$data);
- Db::commit();
- return Common::return_success('提交成功,等待审核');
- // $opend_id = $userinfo['openid'];
- // if (!$opend_id)
- // return Common::return_error('未绑定微信,无法提现');
- // $wx = new WxMerchPay();
- // $result = $wx->sendMoney($real_money,$opend_id,$order_no,'余额提现');
- // if ($result['return_code']=='SUCCESS' && $result['result_code']=='SUCCESS'){
- // User::integral($money,$user['id'],'微信提现'.$money);
- // UserWithdraw::where('order_no',$order_no)->update(['paid'=>1,'pay_time'=>time(),'return_info'=>json_encode($result,true)]);
- // Db::commit();
- // return Common::return_success('提现成功');
- // }else{
- // UserWithdraw::where('order_no',$order_no)->update(['return_info'=>json_encode($result,true)]);
- // Db::commit();
- // return Common::return_error('提现失败');
- // }
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('提现失败');
- }
- }
- /**
- * 提现记录
- */
- public static function userWithdrawLog(){
- $user = app()->session->get('us');
- $list = UserWithdraw::where('user_id',$user['id'])->select();
- return Common::return_success('成功',$list);
- }
- /**
- * 注销账号
- */
- public static function cancellationAccount(){
- $user = app()->session->get('us');
- $userInfo = self::where('id',$user['id'])->find();
- $userInfo->is_cancellation_account = 0;
- $userInfo->cancellation_time = time();
- if ($userInfo->save()){
- app()->session->clear();
- app()->session->destroy();
- return Common::return_success('注销成功');
- }
- return Common::return_error('注销失败');
- }
- /**
- * 特权到期脚本
- */
- public static function privilegeOverdue(){
- self::where('open_privilege',1)->where('privilege_overdue_time','lt',time())->update(['open_privilege'=>0]);
- }
- /**
- * 每周五24后收藏卡清空
- */
- public static function collectionEmpty(){
- Collection::where('is_effective',1)->update(['is_effective'=>0]);
- }
- /**
- * 判断禁用时间是否到期
- */
- public static function disableOverdue(){
- User::where('status',0)
- ->whereNotNull('due_time')
- ->where('is_del',1)
- ->where('is_cancellation_account',1)
- ->chunk(20,function ($list){
- foreach ($list as &$v){
- if (time()>strtotime($v['due_time'])){
- User::where('id',$v['id'])->update(
- [
- 'status'=>1
- ]
- );
- }
- }
- });
- }
- /**
- * 判断好友申请七天是否过期
- */
- public static function applyOverdue(){
- UserWantKnow::where('state',1)
- ->chunk('20',function ($list){
- foreach ($list as &$v) {
- $notAgreeReturnIntegral = Config::get_values('notAgreeReturnIntegral');
- $seven = strtotime($v['create_at'])+(7*24*60*60);
- if ($seven<time()){
- UserWantKnow::where('id',$v['id'])->update(
- [
- 'state'=>4,
- 'deal_at'=>date('Y-m-d H:i:s'),
- 'refused_why'=>'七天未处理,自动拒绝'
- ]
- );
- //返积分
- $fan_integral = round($v['integral']*($notAgreeReturnIntegral/100));
- User::integral($fan_integral,$v['user_id'],'申请七天未处理返积分',1);
- }
- }
- },'id','asc');
- }
- /**
- * 晚上八点推荐单身广场
- */
- public static function recommended(){
- User::where('is_cancellation_account',1)->where('is_del',1)->where('daily_recommendation_switch',1)
- ->field('id,openid,nickname')
- ->chunk('20',function ($list){
- foreach ($list as &$v){
- $openid = $v['openid'];
- $template_id = "BFPD1LVboI1ZGGj4bdC6shb9Eec0uNGaSo1WYyt127U";
- $path = "";
- $data = [
- 'first'=>[
- "value"=>'平台推荐通知',
- "color"=>"#173177"
- ],
- 'keyword1'=>[
- "value"=>$v['nickname'],
- "color"=>"#173177"
- ],
- 'keyword2'=>[
- "value"=>date('Y-m-d H:i'),
- "color"=>"#173177"
- ],
- 'remark'=>[
- "value"=>'今日份推荐已生成,快去看看吧',
- "color"=>"#173177"
- ]
- ];
- Common::sendTemplateMsg($openid,$template_id,$path,$data);
- }
- },'id','asc');
- }
- }
|