12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298 |
- <?php
- namespace app\common\model;
- use app\common\library\WxPay;
- use EasyWeChat\Factory;
- use think\Model;
- use app\common\library\Common;
- use think\Db;
- /**
- * 互选池
- */
- class ElectPool Extends Model
- {
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'TIMESTAMP';
- // 定义时间戳字段名
- protected $createTime = 'create_at';
- protected $updateTime = 'update_at';
- /**
- * 创建互选池
- */
- public static function createElectPool($data,$pool_id){
- $user = app()->session->get('us');
- $data['user_id'] = $user['id'];
- if ($pool_id){
- $pool = self::where('id',$pool_id)->where('is_dissolution',1)->where('user_id',$user['id'])->find();
- if (!$pool)
- return Common::return_error('互选池不存在');
- }else{
- $data['password'] = mt_rand(1000, 9999);
- }
- Db::startTrans();
- try {
- if (!$pool_id){
- $pool = self::create($data);
- //群主加入互选池
- $da['pool_id'] = $pool->id;
- $da['user_id'] = $user['id'];
- ElectPoolMembers::create($da);
- Db::commit();
- $elect_pool = Db::name('ElectPool')->where('id',$pool->id)->find();
- return Common::return_success('创建成功',$elect_pool);
- }else{
- self::where('id',$pool_id)->update($data);
- Db::commit();
- $elect_pool = Db::name('ElectPool')->where('id',$pool_id)->find();
- return Common::return_success('编辑成功',$elect_pool);
- }
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 首页互选池列表
- */
- public static function poolList($city,$keywords,$Nowpage,$limits){
- $count = self::byWhere($city,$keywords)->count();
- if (!$count){
- $city = '广州市';
- $count = self::byWhere($city,$keywords)->count();
- }
- $list = self::byWhere($city,$keywords)->page($Nowpage, $limits)->select();
- foreach ($list as $k=>$v){
- $list[$k]['education'] = explode(',',$v['education']);
- $list[$k]['pool_have_user'] = self::checkUserToPool($v['id']) ? true : false;
- }
- $data['count'] = $count;
- $data['list'] = $list;
- return Common::return_success('成功',$data);
- }
- /**
- * where条件
- */
- public static function byWhere($city,$keywords){
- $user = app()->session->get('us');
- $audit = Config::get_values('audit');
- $is_audit = $audit == 1 ? 0 : 1;
- $model = Db::name('ElectPool');
- //$model = $model->where('id','100615');
- $model = $model->where('is_audit',$is_audit);
- if ($keywords){
- $model = $model->where('name','like','%'.$keywords.'%');
- }else{
- if ($city){
- $model = $model->where('city','like','%'.$city.'%');
- }
- }
- $model = $model->where('is_dissolution',1);
- if ($user){
- $model = $model->orderRaw("user_id=".$user['id']." desc,now_number desc");
- }else{
- $model = $model->order('now_number desc');
- }
- return $model;
- }
- /**
- * 我创建的和加入的互选池
- */
- public static function myCreateJoinPool($city,$Nowpage,$limits){
- $count = self::byWhere2($city)
- ->alias('a')
- ->join('ElectPool b','a.pool_id=b.id')
- ->count();
- $data['count'] = $count;
- if ($count){
- $list = self::byWhere2($city)
- ->alias('a')
- ->field('b.*')
- ->join('ElectPool b','a.pool_id=b.id')
- ->page($Nowpage, $limits)
- ->select()
- ->toArray();
- foreach ($list as $k=>$v){
- $list[$k]['education'] = explode(',',$v['education']);
- $list[$k]['pool_have_user'] = self::checkUserToPool($v['id']) ? true : false;
- }
- }else{
- $list = [];
- }
- $data['list'] = $list;
- return Common::return_success('成功',$data);
- }
- /**
- * where条件
- */
- public static function byWhere2($city){
- $user = app()->session->get('us');
- $model = new ElectPoolMembers();
- // if ($city){
- // $model = $model->where('b.city','like','%'.$city.'%');
- // }
- $model = $model->where('a.user_id',$user['id'])->where('b.is_dissolution',1)
- ->orderRaw("b.user_id=".$user['id']." desc,now_number desc");
- return $model;
- }
- /**
- * 互选池详情页
- */
- public static function poolDetail($pool_id){
- $detail = Db::name('ElectPool')->where('id',$pool_id)->where('is_dissolution',1)->find();
- if (!$detail)
- return Common::return_error('互选池不存在或已解散');
- $detail['education'] = explode(',',$detail['education']);
- $detail['pool_have_user'] = self::checkUserToPool($pool_id) ? true : false;
- return Common::return_success('成功',$detail);
- }
- /**
- * 判断用户是否在互选池中
- */
- public static function checkUserToPool($pool_id){
- $user = app()->session->get('us');
- if (!$user)
- return false;
- $hive = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user['id'])->count();
- if (!$hive)
- return false;
- return true;
- }
- /**
- * 进入互选池
- */
- public static function intoPool($pool_id,$password=''){
- $user = app()->session->get('us');
- //判断是否完善资料
- $audit = Config::get_values('audit');
- if ($audit==1){
- if (!User::checkUserIformationPerfect($user['id'])){
- return Common::return_error('未完善资料,无法进入');
- }
- }
- //互选池资料
- $pool_detail = Db::name('ElectPool')->where('id',$pool_id)->where('is_dissolution',1)->find();
- if (!$pool_detail)
- return Common::return_error('互选池不存在或已解散');
- $member = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user['id'])->count();
- if ($pool_detail['type']==2){
- //如果已经在互选池中,不再判断密码
- if (!$member){
- if (!$password)
- return Common::return_error('密码为空');
- if ($password != $pool_detail['password'])
- return Common::return_error('密码不正确');
- }
- }
- //判断是否是被群主移出的
- $is_remove = ElectPoolRemovedUser::where('pool_id',$pool_id)->where('user_id',$user['id'])->count();
- if ($is_remove)
- return Common::return_error('被群主移出,无法再进入');
- if ($pool_detail['group_number']!=0){
- if (!$member){
- $all_count = ElectPoolMembers::where('pool_id',$pool_id)
- ->count();
- if ($all_count>=$pool_detail['group_number'])
- return Common::return_error('群人数已满,无法加入');
- }
- }
- $pool_detail['education'] = explode(',',$pool_detail['education']);
- $userinfo = User::get($user['id']);
- if ($userinfo['sex']==1)
- $sex = 2;
- else
- $sex = 1;
- $count = ElectPoolMembers::where('a.pool_id',$pool_id)
- ->alias('a')
- ->where('b.sex',$sex)
- ->join('User b','a.user_id=b.id')
- ->count();
- if ($count){
- $list = ElectPoolMembers::where('a.pool_id',$pool_id)
- ->alias('a')
- ->where('b.sex',$sex)
- ->join('User b','a.user_id=b.id')
- ->field('a.user_id,b.nickname,b.headimgurl,b.height,b.graduated_from,b.date_of_birth')
- ->order('a.id desc')
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['like_count'] = UserWantKnow::where('to_user_id',$v['user_id'])->count();
- $list[$k]['year'] = date('Y',strtotime($v['date_of_birth']));
- }
- }else
- $list = [];
- $data['count'] = $count;
- $data['list'] = $list;
- //进入互选池
- if (!$member){
- $da['pool_id'] = $pool_id;
- $da['user_id'] = $user['id'];
- Db::startTrans();
- try {
- ElectPoolMembers::create($da);
- self::where('id',$pool_id)->setInc('now_number'); //数量加1
- Db::commit();
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('进入失败');
- }
- }
- return Common::return_success('成功',compact('pool_detail','data'));
- }
- /**
- * 获取互选池异性用户列表
- */
- public static function poolUserList($pool_id,$Nowpage,$limits){
- $user = app()->session->get('us');
- $userinfo = User::get($user['id']);
- $sex = $userinfo['sex']==1 ? 2 : 1;
- $work_auth_status = $userinfo['work_auth_status'];
- $work_auth_company_name = $userinfo['work_auth_company_name'];
- $count = ElectPoolMembers::where('a.pool_id',$pool_id)
- ->alias('a')
- ->where('b.sex',$sex)
- ->where('b.stealth_switch',1)
- ->where('b.is_cancellation_account',1)
- ->where('b.is_del',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('b.work_auth_company_name like "%'.$work_auth_company_name.'%" and b.shielding_colleagues_switch=1 or b.work_auth_company_name not like "%'.$work_auth_company_name.'%" or b.work_auth_company_name=""');
- }
- })
- ->join('User b','a.user_id=b.id')
- ->count();
- if ($count){
- $list = ElectPoolMembers::where('a.pool_id',$pool_id)
- ->alias('a')
- ->where('b.sex',$sex)
- ->where('b.stealth_switch',1)
- ->where('b.is_cancellation_account',1)
- ->where('b.is_del',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('b.work_auth_company_name like "%'.$work_auth_company_name.'%" and b.shielding_colleagues_switch=1 or b.work_auth_company_name not like "%'.$work_auth_company_name.'%" or b.work_auth_company_name=""');
- }
- })
- ->join('User b','a.user_id=b.id')
- ->field('a.user_id,b.*')
- ->order('a.id desc')
- ->page($Nowpage,$limits)
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['like_count'] = UserWantKnow::where('to_user_id',$v['user_id'])->count();
- $list[$k]['year'] = date('Y',strtotime($v['date_of_birth']));
- if ($v['household']){
- $household = explode('-',$v['household']);
- $list[$k]['household_city'] = isset($household[1]) ? $household[1] : '';;
- }else{
- $list[$k]['household_city'] = '';
- }
- if (!$v['introduce_myself_imgs']) {
- $list[$k]['introduce_myself_imgs'] = [];
- }else{
- $list[$k]['introduce_myself_imgs'] = explode(',',$v['introduce_myself_imgs']);
- }
- if (!$v['family_background_imgs']) {
- $list[$k]['family_background_imgs'] = [];
- }else{
- $list[$k]['family_background_imgs'] = explode(',',$v['family_background_imgs']);
- }
- if (!$v['interests_hobbies_imgs']) {
- $list[$k]['interests_hobbies_imgs'] = [];
- }else{
- $list[$k]['interests_hobbies_imgs'] = explode(',',$v['interests_hobbies_imgs']);
- }
- if (!$v['love_imgs']){
- $list[$k]['love_imgs'] = [];
- }else{
- $list[$k]['love_imgs'] = explode(',',$v['love_imgs']);
- }
- if (!$v['imgs']){
- $list[$k]['imgs'] = [];
- }else{
- $list[$k]['imgs'] = explode(',',$v['imgs']);
- }
- if (!$v['label']){
- $list[$k]['label'] = [];
- }else{
- $list[$k]['label'] = explode(',',$v['label']);
- }
- if (!$v['other_half_imgs']){
- $list[$k]['other_half_imgs'] = [];
- }else{
- $list[$k]['other_half_imgs'] = explode(',',$v['other_half_imgs']);
- }
- if (!$v['why_single_imgs']){
- $list[$k]['why_single_imgs'] = [];
- }else{
- $list[$k]['why_single_imgs'] = explode(',',$v['why_single_imgs']);
- }
- if (!$v['look_life_imgs']){
- $list[$k]['look_life_imgs'] = [];
- }else{
- $list[$k]['look_life_imgs'] = explode(',',$v['look_life_imgs']);
- }
- }
- }else
- $list = [];
- $data['count'] = $count;
- $data['list'] = $list;
- return Common::return_success('成功',$data);
- }
- /**
- * 退出互选池
- */
- public static function exitPool($pool_id){
- $user = app()->session->get('us');
- //互选池资料
- $pool_detail = Db::name('ElectPool')->where('id',$pool_id)->where('is_dissolution',1)->find();
- if (!$pool_detail)
- return Common::return_error('互选池不存在或已解散');
- $member = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user['id'])->count();
- if (!$member)
- return Common::return_error('不在互选池中');
- Db::startTrans();
- try {
- ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user['id'])->delete();
- self::where('id',$pool_id)->setDec('now_number'); //数量减1
- Db::commit();
- return Common::return_success('退出成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('退出失败');
- }
- }
- /**
- * 查看用户资料
- */
- public static function SelUser($user_id){
- $user = app()->session->get('us');
- $touser = Db::name('User')->where('id',$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']);
- if (isset($household[1])){
- $touser['household_city'] = $household[1];
- }else{
- $touser['household_city'] = '';
- }
- }else{
- $touser['household_city'] = '';
- }
- if (!$user){
- $touser['is_want_know'] = false;
- $touser['is_integral_contact'] = false;
- $touser['wechat_id'] = "";
- $touser['is_collection'] = false;
- $touser['is_shielding'] = false;
- $touser['apply_state'] = false;
- $touser['star_switch'] = false;
- $touser['star'] = false;
- }else{
- //查看我是否已经喜欢过
- $want_know = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
- $touser['is_want_know'] = $want_know ? true : false;
- //查看是否已经获取了联系方式
- $integral_record = IntegralContactRecord::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
- $touser['is_integral_contact'] = $integral_record ? true : false;
- //查看对方是否也喜欢我
- $want_know2 = UserWantKnow::where('user_id',$user_id)->where('to_user_id',$user['id'])->count();
- if (!$integral_record){
- if (!$want_know || !$want_know2)
- $touser['wechat_id'] = "";
- }
- //查看是否收藏了对方
- $collection = Collection::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('is_effective',1)->count();
- $touser['is_collection'] = $collection > 0 ? true : false;
- //对方是否把你屏蔽
- $info = ShieldingKnowUsers::where('user_id',$user_id)->where('to_user_id',$user['id'])->count();
- $touser['is_shielding'] = $info > 0 ? true : false;
- //查看申请状态
- $apply = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
- if (!$apply){
- $touser['apply_state'] = false;
- }else{
- $touser['apply_state'] = true;
- }
- //星标开关
- $star = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
- $touser['star_switch'] = $star > 0 ? true : false;
- //是否星标好友
- $star2 = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
- $touser['star'] = $star2 ? true : false;
- }
- return Common::return_success('成功',$touser);
- }
- /**
- * 查看申请
- */
- public static function SelApply($user_id){
- $user = app()->session->get('us');
- $touser = Db::name('User')->where('id',$user_id)->find();
- if (!$touser)
- return Common::return_error('用户不存在');
- $array = [];
- //查看我是否申请了对方
- $know = UserWantKnow::where('user_id',$user['id'])
- ->where('to_user_id',$user_id)
- ->whereNotIn('state','3,4,5')
- ->order('id desc')
- ->limit(1)
- ->field('id,leave_message,state,create_at')
- ->find();
- if ($know){
- $know = $know->toArray();
- $seven = date('Y-m-d H:i:s',strtotime($know['create_at'])+(7*24*60*60));
- $know['seven'] = Common::timeTranRun($seven);
- $know['list'] = UserWantKnowRecord::where('know_id',$know['id'])
- ->where('user_id',$user['id'])
- ->order('sort desc')
- ->field('id,content,create_at')
- ->select()->toArray();
- $array['type'] = 1;
- $array['info'] = $know;
- }else{
- $know = UserWantKnow::where('user_id',$user_id)
- ->where('to_user_id',$user['id'])
- ->whereNotIn('state','3,4,5')
- ->order('id desc')
- ->limit(1)
- ->field('id,leave_message,state,create_at')
- ->find();
- if ($know){
- $know = $know->toArray();
- $seven = date('Y-m-d H:i:s',strtotime($know['create_at'])+(7*24*60*60));
- $times = Common::timeTranRun2($seven);
- $know['day'] = $times['date'];
- $know['hour'] = $times['hour'];
- $know['minute'] = $times['minute'];
- $know['seconds'] = $times['seconds'];
- $know['list'] = UserWantKnowRecord::where('know_id',$know['id'])
- ->where('user_id',$user['id'])
- ->order('sort desc')
- ->field('id,content,create_at')
- ->select()->toArray();
- $array['type'] = 2;
- $array['info'] = $know;
- //判断是否有查看申请过
- $apply = UserWantKnowRecord::where('know_id',$know['id'])->where('user_id',$user['id'])->where('content','查看申请')->count();
- if (!$apply){
- UserWantKnowRecord::create(
- [
- 'know_id'=>$know['id'],
- 'user_id'=>$user['id'],
- 'content'=>'查看申请',
- 'sort'=>2
- ]
- );
- UserWantKnowRecord::create(
- [
- 'know_id'=>$know['id'],
- 'user_id'=>$user['id'],
- 'content'=>'等待处理',
- 'sort'=>3
- ]
- );
- UserWantKnowRecord::create(
- [
- 'know_id'=>$know['id'],
- 'user_id'=>$user_id,
- 'content'=>'对方查看了你的申请',
- 'sort'=>3
- ]
- );
- }
- }else{
- return Common::return_error('对方已取消');
- }
- }
- return Common::return_success('成功',$array);
- }
- /**
- * 终止申请
- */
- public static function TerminationApply($id){
- $user = app()->session->get('us');
- $info = UserWantKnow::where('id',$id)->where('user_id',$user['id'])->where('state',1)->find();
- $info = $info->toArray();
- if (!$info)
- return Common::return_error('申请不存在');
- Db::startTrans();
- try {
- UserWantKnow::where('id',$id)->update(
- [
- 'state'=>5,
- 'deal_at'=>date('Y-m-d H:i:s')
- ]
- );
- //记录
- UserWantKnowRecord::create(
- [
- 'know_id'=>$id,
- 'user_id'=>$user['id'],
- 'content'=>'终止申请',
- 'sort'=>4
- ]
- );
- UserWantKnowRecord::create(
- [
- 'know_id'=>$id,
- 'user_id'=>$info['to_user_id'],
- 'content'=>'终止申请',
- 'sort'=>4
- ]
- );
- //返积分(如果被拒绝过)
- $notAgreeReturnIntegral = Config::get_values('notAgreeReturnIntegral');
- $fan_integral = round($info['integral']*($notAgreeReturnIntegral/100));
- User::integral($fan_integral,$info['user_id'],'终止申请返积分',1);
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 同意申请
- */
- public static function AgreeApply($id){
- $user = app()->session->get('us');
- $info = UserWantKnow::where('id',$id)->where('to_user_id',$user['id'])->where('state',1)->find();
- if (!$info)
- return Common::return_error('申请不存在');
- $info = $info->toArray();
- Db::startTrans();
- try {
- UserWantKnow::where('id',$id)->update(
- [
- 'state'=>2,
- 'deal_at'=>date('Y-m-d H:i:s')
- ]
- );
- //记录
- UserWantKnowRecord::create(
- [
- 'know_id'=>$id,
- 'user_id'=>$info['user_id'],
- 'content'=>'同意申请',
- 'sort'=>5
- ]
- );
- UserWantKnowRecord::create(
- [
- 'know_id'=>$id,
- 'user_id'=>$info['to_user_id'],
- 'content'=>'同意申请',
- 'sort'=>5
- ]
- );
- //消息推送
- $openid = User::where('id',$info['user_id'])->value('openid');
- $template_id = "pF9lZHPpNpt7tudXDYiIbwLk5Y5G6qmKm6mHLnQWjTU";
- $path = "";
- $data = [
- 'first'=>[
- "value"=>'你好,您的好友申请已通过!',
- "color"=>"#173177"
- ],
- 'keyword1'=>[
- "value"=>'好友申请',
- "color"=>"#173177"
- ],
- 'keyword2'=>[
- "value"=>'通过',
- "color"=>"#173177"
- ],
- 'remark'=>[
- "value"=>'你申请的好友申请已通过,请查看',
- "color"=>"#173177"
- ]
- ];
- Common::sendTemplateMsg($openid,$template_id,$path,$data);
- $openid2 = User::where('id',$info['to_user_id'])->value('openid');
- $template_id2 = "Sz1eunRAh_jKR0_94dZU4jJB2WuRGqG0kyzsA-WYCLk";
- $path2 = "";
- $data2 = [
- 'first'=>[
- "value"=>'通过审核!',
- "color"=>"#173177"
- ],
- 'keyword1'=>[
- "value"=>date('Y-m-d H:i'),
- "color"=>"#173177"
- ],
- 'keyword2'=>[
- "value"=>User::where('id',$info['user_id'])->value('nickname'),
- "color"=>"#173177"
- ],
- 'remark'=>[
- "value"=>'好友申请已通过,请查看',
- "color"=>"#173177"
- ]
- ];
- Common::sendTemplateMsg($openid2,$template_id2,$path2,$data2);
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 拒绝申请
- */
- public static function RefuseApply($id,$refused_why){
- $user = app()->session->get('us');
- $info = UserWantKnow::where('id',$id)->where('to_user_id',$user['id'])->where('state',1)->find();
- if (!$info)
- return Common::return_error('申请不存在');
- $info = $info->toArray();
- Db::startTrans();
- try {
- UserWantKnow::where('id',$id)->update(
- [
- 'state'=>3,
- 'refused_why'=>$refused_why,
- 'deal_at'=>date('Y-m-d H:i:s')
- ]
- );
- //记录
- UserWantKnowRecord::create(
- [
- 'know_id'=>$id,
- 'user_id'=>$info['user_id'],
- 'content'=>'拒绝申请',
- 'sort'=>5
- ]
- );
- UserWantKnowRecord::create(
- [
- 'know_id'=>$id,
- 'user_id'=>$info['to_user_id'],
- 'content'=>'拒绝申请',
- 'sort'=>5
- ]
- );
- $openid = User::where('id',$info['user_id'])->value('openid');
- $template_id = "sib_d0XQVMn-pSjFNmqMEs4JltmhNnSBbu21DqswzHs";
- $path = "";
- $data = [
- 'first'=>[
- "value"=>'你好,您的好友申请被拒绝!',
- "color"=>"#173177"
- ],
- 'keyword1'=>[
- "value"=>$refused_why,
- "color"=>"#173177"
- ],
- 'keyword2'=>[
- "value"=>date('Y-m-d H:i'),
- "color"=>"#173177"
- ],
- 'remark'=>[
- "value"=>'你申请的好友申请未通过',
- "color"=>"#173177"
- ]
- ];
- Common::sendTemplateMsg($openid,$template_id,$path,$data);
- //返积分(如果被拒绝过)
- $notAgreeReturnIntegral = Config::get_values('notAgreeReturnIntegral');
- $fan_integral = round($info['integral']*($notAgreeReturnIntegral/100));
- User::integral($fan_integral,$info['user_id'],'拒绝申请返积分',1);
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 屏蔽用户
- */
- public static function shieldingKnowUser($to_user_id,$switch){
- $user = app()->session->get('us');
- Db::startTrans();
- $info = ShieldingKnowUsers::where('user_id',$user['id'])->where('to_user_id',$to_user_id)->find();
- try {
- if ($switch==1){
- if (!$info){
- ShieldingKnowUsers::create(
- [
- 'user_id'=>$user['id'],
- 'to_user_id'=>$to_user_id
- ]
- );
- }
- }else{
- if ($info){
- ShieldingKnowUsers::where('id',$info['id'])->delete();
- }
- }
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 不合适
- */
- public static function DontFit($user_id){
- $user = app()->session->get('us');
- $info = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('state',2)->find();
- if (!$info){
- $info = UserWantKnow::where('to_user_id',$user['id'])->where('user_id',$user_id)->where('state',2)->find();
- if (!$info)
- return Common::return_error('非好友');
- }
- $info = $info->toArray();
- Db::startTrans();
- try {
- UserWantKnow::where('id',$info['id'])->update(
- [
- 'state'=>4,
- 'deal_at'=>date('Y-m-d H:i:s'),
- 'refused_why'=>'不合适'
- ]
- );
- UserWantKnowRecord::create(
- [
- 'know_id'=>$info['id'],
- 'user_id'=>$info['to_user_id'],
- 'content'=>'不合适',
- 'sort'=>6
- ]
- );
- UserWantKnowRecord::create(
- [
- 'know_id'=>$info['id'],
- 'user_id'=>$info['user_id'],
- 'content'=>'不合适',
- 'sort'=>6
- ]
- );
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 星标聊天开关
- */
- public static function SetStar($user_id,$switch){
- $user = app()->session->get('us');
- Db::startTrans();
- $info = UserStar::where('user_id',$user['id'])->where('to_user_id',$user_id)->find();
- try {
- if ($switch==1){
- if (!$info){
- UserStar::create(
- [
- 'user_id'=>$user['id'],
- 'to_user_id'=>$user_id
- ]
- );
- }
- }else{
- if ($info){
- UserStar::where('id',$info['id'])->delete();
- }
- }
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 想认识
- */
- public static function wantKnow($user_id,$pool_id,$leave_message){
- $user = app()->session->get('us');
- $userinfo = User::get($user['id']);
- $touser = Db::name('User')->where('id',$user_id)->find();
- if (!$touser)
- return Common::return_error('用户不存在');
- //判断是否完善资料
- if (!User::checkUserIformationPerfect($user['id']))
- return Common::return_error('未完善资料,无法获取');
- $integral = Config::get_values('want_know_integral'); //扣除的积分
- if ($userinfo['integral'] < $integral)
- return Common::return_error('积分不足');
- //查看我是否已经喜欢过
- $want_know = UserWantKnow::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
- if ($want_know)
- return Common::return_error('已经认识过');
- $data['user_id'] = $user['id'];
- $data['to_user_id'] = $user_id;
- $data['pool_id'] = $pool_id;
- Db::startTrans();
- try {
- User::integral($integral,$user['id'],'想查看 '.$touser['nickname'].'资料');
- $data['integral'] = $integral;
- $knowid = UserWantKnow::create($data);
- //消息推送
- // $openid = User::where('id',$user_id)->value('openid');
- $openid = User::where('administrator',1)->where('is_del',1)->order('id asc')->limit(1)->value('openid');
- $template_id = "W5AkhY0RnEFj74WwO5qwYRR5-JIuhzjHr5NMb9pACwc";
- $path = "";
- $data = [
- 'first'=>[
- "value"=>'你有一待处理事项',
- "color"=>"#173177"
- ],
- 'keyword1'=>[
- "value"=>'临沂金叶',
- "color"=>"#173177"
- ],
- 'keyword2'=>[
- "value"=>$userinfo['nickname']."(".$userinfo['phone'].")喜欢了".$touser['nickname']."(".$touser['phone'].")",
- "color"=>"#173177"
- ],
- 'remark'=>[
- "value"=>'快去处理吧',
- "color"=>"#173177"
- ]
- ];
- Common::sendTemplateMsg($openid,$template_id,$path,$data);
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 付费查看提交
- */
- public static function payCheck($user_id){
- $user = app()->session->get('us');
- $userinfo = User::get($user['id']);
- $touser = Db::name('User')->where('id',$user_id)->find();
- if (!$touser)
- return Common::return_error('用户不存在');
- $info = PayCheck::where('user_id',$user['id'])->where('to_user_id',$user_id)->where('paid',1)->find();
- if ($info)
- return Common::return_error('已经付费查看过');
- //获取支付金额
- $pay_money = Config::get_values('pay_check_money');
- $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['to_user_id'] = $user_id;
- $data['order_no'] = $order_no;
- $data['price'] = $pay_money;
- $get_check_money = Config::get_values('get_check_money');
- $get_price = sprintf("%.2f",substr(sprintf("%.3f", ($pay_money*($get_check_money/100))), 0, -2));
- $data['get_price'] = $get_price;
- PayCheck::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 integralContact($user_id,$pool_id){
- $user = app()->session->get('us');
- $userinfo = User::get($user['id']);
- $touser = Db::name('User')->where('id',$user_id)->find();
- if (!$touser)
- return Common::return_error('用户不存在');
- //判断是否完善资料
- if (!User::checkUserIformationPerfect($user['id']))
- return Common::return_error('未完善资料,无法获取');
- if ($touser['is_integral_to_phone'] == 2)
- return Common::return_error('用户设置不允许使用积分获取联系方式');
- $integral = Config::get_values('integral_contact');
- if ($userinfo['integral'] < $integral)
- return Common::return_error('积分不足');
- //查看我是否已经购买过
- $integral_record = IntegralContactRecord::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
- if ($integral_record)
- return Common::return_error('已经购买过');
- $data['user_id'] = $user['id'];
- $data['to_user_id'] = $user_id;
- $data['pool_id'] = $pool_id;
- $data['integral'] = $integral;
- Db::startTrans();
- try {
- IntegralContactRecord::create($data);
- //扣除积分
- User::integral($integral,$user['id'],'获取 '.$touser['nickname'].' 的联系方式');
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 群主解散互选池
- */
- public static function dissolutionPool($pool_id){
- $user = app()->session->get('us');
- $pool = self::where('id',$pool_id)->where('is_dissolution',1)->where('user_id',$user['id'])->find();
- if (!$pool)
- return Common::return_error('互选池不存在');
- Db::startTrans();
- try {
- $pool->is_dissolution = 0;
- $pool->save();
- //通知群成员
- $user_ids = ElectPoolMembers::where('pool_id',$pool_id)->column('user_id');
- if ($user_ids){
- foreach ($user_ids as $k=>$v){
- //系统消息
- Message::create_message($v,'群主已解散 '. $pool['name'] .' 互选池');
- }
- }
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 群主移出互选池用户
- */
- public static function removeUser($pool_id,$user_id){
- $user = app()->session->get('us');
- $pool = self::where('id',$pool_id)->where('is_dissolution',1)->where('user_id',$user['id'])->find();
- if (!$pool)
- return Common::return_error('互选池不存在');
- //用户是否在群里
- $group = ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user_id)->count();
- if (!$group)
- return Common::return_error('用户已不在互选池中');
- Db::startTrans();
- try {
- ElectPoolMembers::where('pool_id',$pool_id)->where('user_id',$user_id)->delete();
- $data['pool_id'] = $pool_id;
- $data['user_id'] = $user_id;
- ElectPoolRemovedUser::create($data);
- self::where('id',$pool_id)->setDec('now_number'); //数量减1
- //系统消息
- Message::create_message($user_id,'您被群主移出 '. $pool['name'] .' 互选池');
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 分享
- */
- public static function share($type,$link_id){
- $user = app()->session->get('us');
- switch ($type){
- case 1:
- $share_count_day = Config::get_values('share_applet_count_day'); //一天分享几次有积分
- $share_integral = Config::get_values('share_applet_integral'); //分享一次获得多少积分
- $title = '分享小程序获得积分';
- break;
- case 2:
- $share_count_day = Config::get_values('share_pool_count_day'); //一天分享几次有积分
- $share_integral = Config::get_values('share_pool_integral'); //分享一次获得多少积分
- $title = '分享互选池获得积分';
- break;
- case 3:
- $share_count_day = Config::get_values('share_myinfo_count_day'); //一天分享几次有积分
- $share_integral = Config::get_values('share_myinfo_integral'); //分享一次获得多少积分
- $title = '分享个人资料获得积分';
- break;
- case 4:
- $share_count_day = Config::get_values('share_others_count_day'); //一天分享几次有积分
- $share_integral = Config::get_values('share_others_integral'); //分享一次获得多少积分
- $title = '分享他人资料获得积分';
- break;
- default:
- $share_count_day = 0; //一天分享几次有积分
- $share_integral = 0; //分享一次获得多少积分
- break;
- }
- //获取用户今日分享次数
- $day = date('Y-m-d');
- $share_count = UserShareLog::where('user_id',$user['id'])->where('day',$day)->where('type',$type)->count();
- Db::startTrans();
- try {
- //分享记录表
- $data['user_id'] = $user['id'];
- $data['day'] = $day;
- $data['type'] = $type;
- $data['link_id'] = $link_id;
- //分享获得积分
- if ($share_count_day>$share_count){
- //加积分
- User::integral($share_integral,$user['id'], $title,1);
- }else{
- $share_integral = 0;
- }
- $data['integral'] = $share_integral;
- UserShareLog::create($data);
- Db::commit();
- return Common::return_success('成功',$share_integral);
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- /**
- * 举报用户
- */
- public static function reportUser($pool_id,$user_id,$item_type,$content,$imgs){
- $user = app()->session->get('us');
- if ($imgs)
- $imgs = implode(',',$imgs);
- Db::startTrans();
- try {
- //举报记录表
- $data['pool_id'] = $pool_id;
- $data['user_id'] = $user['id'];
- $data['to_user_id'] = $user_id;
- $data['item_type'] = $item_type;
- $data['content'] = $content;
- $data['imgs'] = $imgs;
- UserReport::create($data);
- Db::commit();
- return Common::return_success('成功');
- }catch (Exception $e) {
- Db::rollback();
- return Common::return_error('失败');
- }
- }
- }
|