Bootstrap

PHP婚恋小程序开发源码支持微信+公众号+APP

随着社会的发展和人们生活节奏的加快,传统的相亲方式已经不能满足现代人的需求。在此背景下,有人想到通过线上小程序的方式来满足更多的人进行相亲,所以在此情况下,婚恋相亲小程序由此出现。婚恋相亲小程序的功能有会员功能,红娘管理,后台系统,支付系统,动态管理,通知管理,私人定制管理等等。

在这么多的功能中,今天选择红娘管理给大家做下详细介绍:

联系TA记录:查看A联系B的记录,需要显示联系人方的ID与手机号,联系人发送的被联系人方的ID与手机号,点击按钮的时间,负责的星座红娘。可以按照红娘或时间段筛选

我的联系方式记录:查看联系的红娘,联系人ID,手机号,发送的手机号与微信号

牵线记录:查看A牵线B的记录,需要显示牵线人的ID与手机号,被牵线人的ID与手机号,点击牵线的时间,负责的星座红娘,可以按照红娘或时间段筛选

会员管理:会员管理所有功能

婚恋相亲小程序开发部分源码分享:

<?php

namespace app\api\controller;

use addons\epay\library\Service;
use app\common\controller\Api;
use app\common\model\Activity;
use app\common\model\AppConfig;
use app\common\model\AppUser;
use app\common\model\ChatRoom;
use app\common\model\FlyerOrder;
use app\common\model\Icon;
use app\common\model\Notice;
use app\common\model\OrderActivity;
use app\common\model\SayCommonRule;
use app\common\model\SayLog;
use app\common\model\SayOrder;
use app\common\model\SayPackage;
use app\common\model\User;
use app\common\model\UserWall as UserWallModel;
use app\common\model\VipExperience;
use app\common\model\VipOrder;
use app\common\model\VipPackage;
use im\Ffs;
use im\Im;
use subscribeMsg\SubscribeMsg;
use think\cache\driver\Redis;
use think\Db;
use think\Env;
use think\Exception;
use think\Log;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['getUserToken','index','activity','vipNotify','activityNotify','sayNotify','updateLngLat','user_wallNotify','getSayConfig','delmsg','getAgr'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $scene = $this->request->param('scene');
        $scene = $scene?$scene : 2; // 1 首页   2 推荐
        $user = $this->auth->getUserinfo();
        $gender = $this->request->param('gender',1);


        $is_eject = 0;
        if ($user){
            $is_eject = VipExperience::retNotEject($user['id']);
        }

        $list = AppUser::getPushUser($user,$gender,$scene);


        $icon = Icon::where('type',1)->field('icon_img,title,href')->select();

        // 个人中心背景
        $center_bg = AppConfig::getValue('center_bg') ;
        $center_bg = fileUrl($center_bg);

        // 如果是首页 需要追加推荐墙数据
        if ($scene == 1){
            $uw_where['order_status'] = 1;
            $city = $this->request->param('city');
            if ($user){
                $uw_where['gender'] = ['<>',$user['gender']];
            }
            $uw_where['live_city'] = $city;
            $date = date('Y-m-d 00:00:00');
            $uw_user_id = UserWallModel::where($uw_where)->where('start_time','=',$date)->limit(9)->column('user_id');

            $uw_list = AppUser::whereIn('id',$uw_user_id)->field('id,nickname,live_address,avatar,birthday,height,photos,job,education,is_completion_data,gender,constellation')->select();
            foreach ($uw_list as $v){
                $list[] = $v;
            }
        }
        $this->success('请求成功',compact('list','icon','is_eject','center_bg'));
    }

    /**
     * 每周活动
     * @throws \think\exception\DbException
     */
    public function activity()
    {
        $data = Activity::get(['status'=>1]);
        $this->success('请求成功',$data);
    }

    /**
     * 参加活动
     * @throws \think\exception\DbException
     */
    public function joinActivity()
    {
        $user_info = $this->auth->getUserinfo();
        $activity_id = input('activity_id');
        $activity = Activity::find($activity_id);

        // 判断是否参加了活动
        $is_join = OrderActivity::where(['user_id'=>$user_info['id'],'activity_id'=>$activity_id,'status'=>1])->count();
        if ($is_join) $this->error('已报名该场活动');

        $gender_key = $user_info['gender'] ? 'male_num' : 'female_num';
        $join_key = $user_info['gender'] ? 'male_join_num' : 'female_join_num';
        if($activity[$join_key] >= $activity[$gender_key]) $this->error('活动人数已达上限');
        $order_num = date("YmdHis") . mt_rand(100000, 999999);
        $param['price'] = $activity['price'];
        $param['user_id'] = $user_info['id'];
        $param['order_num'] = $order_num;
        $param['activity_id'] = $activity_id;
        $model = new OrderActivity();
        $model->data($param);
        $re = $model->save();
        if(!$re) $this->error('操作失败');
        $pay_params = [
            'amount' => $activity['price'],
//            'amount' => 0.01,
            'orderid' => $param['order_num'],
            'type' => "wechat",
            'title' => "已遇蓝桉",
            'notifyurl' => Env::get('app.url').'/api/index/activityNotify',
            'method' => "miniapp",
            'openid' => $user_info['openid'],
        ];
        $response = Service::submitOrder($pay_params);
        $this->success('获取成功',['pay_param' => $response,'order_number' => $order_num]);
    }

    /**
     * 参加活动结果
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function activityResult()
    {
        $order_number = input('order_number');
        $order = OrderActivity::field('id,check_num,check_qr_code,status')->where('order_num',$order_number)->find();
        if (!$order) $this->error('订单不存在');
        if ($order['status'] != 1) $this->error('订单未支付');
        $order['check_qr_code'] = fileUrl($order['check_qr_code']);
        $this->success('获取成功',$order);
    }

    /**
     * 购买会员回调
     *
     */
    public function vipNotify()
    {
        $pay = Service::checkNotify('wechat');
        if (!$pay) {
            Log::error('签名错误');
//            $filename = 'miniprogram_pay_notify_info_'.date('Y-m-d');
//            file_put_contents($filename, $pay.PHP_EOL, FILE_APPEND);
        }
        $data = $pay->verify();
        try {
            $pay_amount = $data['total_fee'] / 100;
            $out_trade_no = $data['out_trade_no'];
            $order = VipOrder::where('order_number',$out_trade_no)->find();
            if (!$order) {
                throw new \Exception('订单不存在');
            }
//            if ($order['price'] != $pay_amount) {
//                throw new \Exception('订单异常');
//            }
            $package = VipPackage::get($order['package_id']);
            if (!$package) {
                throw new \Exception('套餐不存在');
            }

            //如果用户已有会员,有效期就在原有时间上增加
            $user = AppUser::get($order['user_id']);
            $now_expire = $user['vip_expire_time'] && $user['is_vip'] == 1 ? strtotime($user['vip_expire_time']) : time();
            $time_limit = $package['time_limit'];
            $expire = date("Y-m-d H:i:s");

            switch ($package['unit']) {
                case 0:
                    $expire = date("Y-m-d H:i:s",strtotime("+".$time_limit." day",$now_expire));
                    break;
                case 1:
                    $expire = date("Y-m-d H:i:s",strtotime("+".$time_limit." month",$now_expire));
                    break;
                case 2:
                    $expire = date("Y-m-d H:i:s",strtotime("+".$time_limit." year",$now_expire));
                    break;
            }


            $user->is_vip = 1;
            $user->vip_expire_time = $expire;
            $user->save();

            $order->status = 1;
            $order->buy_time = date('Y-m-d H:i:s');
            $order->expire_time = $expire;
            $order->save();
            // 返佣
            FlyerOrder::returnCommission($order,1);

            return $pay->success()->send();
        } catch (\Exception $e) {
            Log::error($e);
        }
    }

    /**
     * 购买say豆回调
     */
    public function sayNotify()
    {
        $pay = Service::checkNotify('wechat');
        if (!$pay) {
            Log::error('签名错误');
        }
        $data = $pay->verify();
        try {
            $pay_amount = $data['total_fee'] / 100;
            $out_trade_no = $data['out_trade_no'];
            $order = SayOrder::where('order_number',$out_trade_no)->find();
            if (!$order) {
                throw new \Exception('订单不存在');
            }
//            if ($order['price'] != $pay_amount) {
//                throw new \Exception('订单异常');
//            }


            SayLog::saveLog($order['user_id'],$order['say_num'],9,'购买say豆');

            $order->status = 1;
            $order->buy_time = date('Y-m-d H:i:s');
            $order->save();

            // 返佣
            FlyerOrder::returnCommission($order,2);


            return $pay->success()->send();
        } catch (\Exception $e) {
            Log::error($e);
        }
    }

    /**
     * 参加活动回调
     */
    public function activityNotify()
    {
        $pay = Service::checkNotify('wechat');
        if (!$pay) {
            Log::error('签名错误');
        }
        $data = $pay->verify();
        try {
            $order = OrderActivity::get(['order_num'=>$data['out_trade_no']]);
//            $order = OrderActivity::get(1);
            //生成核销码,核销二维码
            $check_num = time() . mt_rand(100000, 999999);
            $qr = Common::build($check_num);
//            $qrcode = Common::serverUrl().'/uploads/qrcode/'.$qr;
            $qrcode = '/uploads/qrcode/'.$qr;

            $order->check_num = $check_num;
            $order->check_qr_code = $qrcode;
            $order->status = 1;
            $order->save();

            $user = AppUser::get($order['user_id']);
            //参加活动对应性别人数加1
            $key = $user['gender'] ? 'male_join_num' : 'female_join_num' ;
            Activity::where('id',$order['activity_id'])->setInc($key);

            // 发送订阅消息
            $usr_arr = AppUser::getFieldInfo($order['user_id']);
            $act_info = Activity::where('id',$order['activity_id'])->find();
            $sub_msg_data['name1'] =  $usr_arr['nickname'];
            $sub_msg_data['time4'] =  $act_info['start_time'];
            $sub_msg_data['thing7'] =  $act_info['title'];
            $sub_msg_data['thing3'] =  '恭喜您已成功预约,客服之后会与您联系';
            SubscribeMsg::activityMsg($usr_arr['openid'],$sub_msg_data);
            return $pay->success()->send();
        } catch (\Exception $e) {
            Log::error($e);
        }
    }

    /**
     * 推荐上墙回调
     */
    public function user_wallNotify()
    {
        $pay = Service::checkNotify('wechat');
        if (!$pay) {
            Log::error('签名错误');
        }
        $data = $pay->verify();
        try {
            $out_trade_no = $data['out_trade_no'];

            $order = \app\common\model\UserWall::where('order_number',$out_trade_no)->find();
            if (!$order) {
                throw new \Exception('订单不存在');
            }
            // 获取顺延时间
            $date_arr = \app\common\model\UserWall::getPostponedDate($order);

            $order->order_status = 1;
            $order->buy_time = date('Y-m-d H:i:s');
            $order->postponed_count = $date_arr['postponed_count'];
            $order->start_time = $date_arr['start_time'];
            $order->end_time = $date_arr['end_time'];
            $order->save();
            $msg_time = date('Y年m月d日',strtotime($date_arr['start_time']));
            // 发送消息
            // 创建聊天室
            $room_info = ChatRoom::where(['user_id'=>0,'to_user_id'=>$order['user_id']])->find();
            if (!$room_info){
                $room = new ChatRoom();
                $room->type = 1;
                $room->user_id = 0;
                $room->to_user_id = $order['user_id'];
                $room->status = 2;
                $room->createtime = time();
                $room->last_time = time();
                $room->to_user_id_del = $order['user_id'];
                $room->to_user_del_time = null;
                $room->save();
            }else{
                $room_info->last_time = time();
                $room_info->to_user_id_del = $order['user_id'];
                $room_info->to_user_del_time = null;
                $room_info->save();
            }

            // 上线
            $redis = new Redis();
            $redis->sadd(online_key(),$order['user_id']);

            $msg = "恭喜您已完成预约!您的预约时间是{$msg_time}。在此时间将您的个人形象及信息将展示于我平台【推荐墙】。展示时间为24小时,再次感谢您的预约。";
//            $im = new Im();
//            $im->adminPushMsg($order['user_id'],$msg);

            return $pay->success()->send();
        } catch (\Exception $e) {
            Log::error($e);
        }
    }

    /**
     *  更新经纬度
     */
    public function updateLngLat()
    {
        $lng = $this->request->post('lng');
        $lat = $this->request->post('lat');
        $user = $this->auth->getUserinfo();
        if ($user && $lng && $lat){
            AppUser::where(['id'=>$user['id']])->update(['lng'=>$lng,'lat'=>$lat]);
        }
        $this->success('ok');
    }

    /**
     * 返回配置的say豆
     */
    public function getSayConfig()
    {
        $list = SayCommonRule::field('scene,beans')->select();
        $list = toArray($list);
        $app_config = AppConfig::where('key','in',['release_forum'])->field('value,name')->select();
        $app_config = toArray($app_config);
        foreach ($app_config as $k=>$v){
            $arr['scene'] = $v['name'];
            $arr['beans'] = $v['value'];
            $list[] = $arr;
        }
        $this->success('ok',$list);
    }

    /**
     * 协议
     */
    public function getAgr()
    {
        $data['yh_content'] = config('site.yh_content');
        $data['ys_content'] = config('site.ys_content');

        $this->success('ok',$data);
    }

    /**
     * 公告列表
     */
    public function getNotice()
    {
        $user = $this->auth->getUserinfo();
        $page = $this->request->param('page');
        $size = $this->request->param('size');
        $notice = Notice::order('id desc')
            ->page($page,$size)
            ->select();
        foreach ($notice as $k=>$v){
            // 是否阅读
            $notice[$k]['is_read'] = Notice::isRead($v['id'],$user['id']);

        }
        $data = compact('notice');
        $this->success('ok',$data);
    }

    /**
     * 清空所有用户的会话记录
     */
    public function delmsg()
    {

//        die;
//        $list = AppUser::order('id asc')->select();
//        foreach ($list as $k=>$v){
//            $v->birthday_int = $v['birthday'] ? strtotime($v['birthday']) : 0;
//            $v->save();
//        }
//
//        die;
        $where['is_completion_data']=1;
        $list = AppUser::order('id asc')->where($where)->column('id');
        $tokens = Db::name('user_token_test')->whereIn('user_id',$list)->select();
        $tokens = toArray($tokens);
        foreach ($tokens as $k=>$v){
            $tokens[$k]['nickname'] = AppUser::order('id asc')->where(['id'=>$v['user_id']])->value('nickname');
        }
        dd($tokens);
        /*for ($i=50;$i<57;$i++){
            for($j=50;$j<57;$j++){
                if ($i != $j){
                    $im = new Im();
                    $re = $im->setMsgRead($i.'x',$j.'x');
                    if ($re['ActionStatus'] != 'OK'){
                        d($i.'x-'.$j.'x');
                        d($re);
                    }
                    $im2 = new Im();
                    $re2 = $im2->setMsgRead($i,$j);
                    if ($re2['ActionStatus'] != 'OK'){
                        d($i.'-'.$j);
                        d($re);
                    }
                }
            }
        }*/
        dd();
        /*$where['id'] = ['in','50,1,6'];
        $where['is_completion_data']=1;
        $page = $this->request->param('page');
        $list = AppUser::order('id asc')->where($where)->limit(5)->page($page)->column('id');
        $list2 = AppUser::order('id asc')->where($where)->column('id');
        $count1 = count($list);
        $count2 = count($list2);
        for ($i=0;$i<$count1;$i++){
            for($j=0;$j<$count2;$j++){
                if ($list[$i] != $list2[$j]){
//                    d($list[$i].'x'.$list2[$j].'x');
                    $im = new Im();
                    $re = $im->setMsgRead($list[$i].'x',$list2[$j].'x');
                    $im = new Im();
                    $re = $im->setMsgRead($list[$i],$list2[$j]);
                }
            }
        }*/
        dd($list);
        $list = ChatRoom::where('id','>',0)->select();
        foreach ($list as $info){
//            $im = new Im();

            if ($info['type'] == 1){
//                $im->setMsgRead($info['user_id'],$info['to_user_id']);
//                $im->setMsgRead($info['to_user_id'],$info['user_id']);
                $im->deleteMsg($info['user_id'],$info['to_user_id']);
                $im->deleteMsg($info['to_user_id'],$info['user_id']);
            }else{
//                $im->setMsgRead($info['user_id'].'x',$info['to_user_id'].'x');
//                $im->setMsgRead($info['to_user_id'].'x',$info['user_id'].'x');
//                $im->deleteMsg($info['user_id'].'x',$info['to_user_id'].'x');
//                $im->deleteMsg($info['to_user_id'].'x',$info['user_id'].'x');
            }
//            $info->delete();
        }

        dd($list);
        $list = AppUser::where('id','>',0)->page(1)->limit(5)->select();
        foreach ($list as $user){
            $to_list = AppUser::all();
            foreach ($to_list as $to_user){
//                $im = new Im();
//                $im->deleteMsg($user['id'],$to_user['id']);
//                $im = new Im();
//                $im->deleteMsg($user['id'].'x',$to_user['id'].'x');
            }
        }
        dd($list);
    }


    /**
     * 测试
     */
    public function test()
    {
        $access_token_val = getAccessToken();
        $url = 'https://api.weixin.qq.com/wxa/generate_urllink?access_token='.$access_token_val;
        $param['path'] = 'pages/index/index';
        $param['query'] = 'id='.$this->auth->getUserinfo()['id'];
        $result = httpRequest( $url, json_encode($param),"POST");
        $arr = json_decode($result,true);
        dd($arr);
    }


    /**
     * 获取用户token
     */
    public function getUserToken()
    {
        $id = $this->request->param('id');

        $this->auth->direct($id);
        $token = $this->auth->getToken();
        dd($token);
    }
}

;