1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345 |
- <?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;
- $touser['is_pay'] = 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;
- }
- //查看是否已经支付
- $is_pay = UserPay::where('user_id',$user['id'])->where('to_user_id',$user_id)->count();
- if (!$is_pay){
- $touser['is_pay'] = false;
- }else{
- $touser['is_pay'] = 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 wantKnowPay($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('用户不存在');
- $pay = UserPay::where('user_id',$user['id'])->where('to_user_id',$user_id)->find();
- if ($pay)
- return Common::return_error('已经支付过');
- $integral = Config::get_values('want_know_integral'); //扣除的积分
- if ($userinfo['integral'] < $integral)
- return Common::return_error('积分不足');
- $data['user_id'] = $user['id'];
- $data['to_user_id'] = $user_id;
- Db::startTrans();
- try {
- $get_check_money = Config::get_values('get_check_money');
- // $get_price = sprintf("%.2f",substr(sprintf("%.3f", ($integral*($get_check_money/100))), 0, -2));
- $get_price = round($integral*($get_check_money/100));
- $data['get_price'] = $get_price;
- $data['integral'] = $integral;
- User::integral($integral,$user['id'],'想查看 '.$touser['nickname'].'资料');
- User::integral($get_price,$user_id,'被查看资料',1);
- UserPay::create($data);
- 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 {
- $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 = "pages/userInfo/index?id=".$user['id']."&administrator=1";
- $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('失败');
- }
- }
- }
|