Selaa lähdekoodia

Merge branch 'master' of http://git.meme100.com:10180/yigao/qpapi

junghwi 6 vuotta sitten
vanhempi
commit
a60d0b272c

+ 149 - 0
app/Http/Controllers/Admin/ActivityController.php

@@ -0,0 +1,149 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use App\Http\Models\GameUrlData;
+use App\Http\Models\Activity;
+use App\Models\GameUrl;
+use App\Models\Activity as ActivityDatabase;
+use Illuminate\Http\Request;
+use App\Http\Controllers\PublicController;
+
+/**
+ * 活动管理类
+ */
+class ActivityController extends PublicController
+{
+
+
+    /**
+     * 视图加载
+     *
+     * @access public
+     * @return array
+     */
+    public function index()
+    {
+        return view('admin.activity.index');
+
+    }//end index()
+
+
+    /**
+     * 数据获取
+     *
+     * @access public
+     * @param  mixed $request 参数.
+     * @return array
+     */
+    public function data(Request $request)
+    {
+        $activityModel = new Activity;
+        $getActivityWhere = [];
+        // 查询参数.
+        if (empty($request->get('activity_title')) !== true) {
+            $getActivityWhere['activity_title'] = $request->get('activity_title');
+        }
+        // 查询参数.
+        if (strlen($request->get('activity_delete'))) {
+            $getActivityWhere['activity_delete'] = $request->get('activity_delete');
+        }
+
+        // 查询数据.
+        $res = $activityModel->getAllActivity($getActivityWhere, $request->get('limit', 30));
+        // 返回参数.
+        $data = [
+            'code'  => 0,
+            'msg'   => '正在请求中...',
+            'count' => $res['total'],
+            'data'  => $res['data'],
+        ];
+        return response()->json($data);
+
+    }//end data()
+
+
+    /**
+     * 视图加载
+     *
+     * @access public
+     * @return array
+     */
+    public function create()
+    {
+        return view('admin.gameUrl.create');
+
+    }//end create()
+
+
+    /**
+     * 添加数据
+     *
+     * @access public
+     * @param  mixed $request 参数.
+     * @return array
+     */
+    public function store(Request $request)
+    {
+        $data = $request->only(['gameUrl_name', 'gameUrl_type', 'gameUrl_url', 'gameUrl_data']);
+
+        if ( GameUrl::insert($data)) {
+            return redirect()->to(route('admin.gameUrl'))->with(['status'=>'添加成功']);
+        }
+        return redirect()->to(route('admin.gameUrl'))->withErrors('系统错误');
+
+    }//end store()
+
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function edit($id)
+    {
+        $gameUrlModel = new GameUrl;
+        $gameUrl = $gameUrlModel->where(['gameUrl_id' => $id])->first();
+        return view('admin.gameUrl.edit',compact('gameUrl'));
+    }
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request)
+    {
+        $gameUrlModel = new GameUrl;
+        $gameUrl = $gameUrlModel->where(['gameUrl_id' => $request->get('gameUrl_id')]);
+        $data = $request->only(['gameUrl_name', 'gameUrl_type', 'gameUrl_url', 'gameUrl_data']);
+
+        if ($gameUrl->update($data)){
+            return redirect()->to(route('admin.gameUrl'))->with(['status'=>'更新成功']);
+        }
+        return redirect()->to(route('admin.gameUrl'))->withErrors('系统错误');
+    }
+
+
+    /**
+     * 删除
+     *
+     * @access public
+     * @param  mixed $request 参数.
+     * @return array
+     */
+    public function destroy(Request $request)
+    {
+        $ids = $request->get('ids');
+        $status = $request->get('status') == 0 ? 1 : 0;
+        if (empty($ids)){
+            return response()->json(['code'=>1,'msg'=>'请选择删除项']);
+        }
+        if (ActivityDatabase::whereIn('activity_identity',$ids)->update(['activity_delete'=>$status])){
+            return response()->json(['code'=>0,'msg'=>'删除成功']);
+        }
+        return response()->json(['code'=>1,'msg'=>'删除失败']);
+    }
+}

+ 1 - 1
app/Http/Controllers/PublicController.php

@@ -81,4 +81,4 @@ class PublicController extends Controller
     }
 
 
-}
+}

+ 52 - 0
app/Http/Controllers/Sys/ActivityController.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Http\Controllers\Sys;
+
+use Illuminate\Http\Request;
+use App\Http\Controllers\Controller;
+use \App\Http\Models;
+use \Exception;
+
+/**
+ * 活动管理类
+ */
+class ActivityController extends Controller
+{
+
+
+    /**
+     * 活动查询
+     *
+     * @access public
+     * @param mixed $req 数据传输
+     * @return array JsonString
+     */
+    public function activityList(Request $req)
+    {
+        $code = -2;
+        $msg = '操作失败';
+        try {
+            $activityModel = new Models\Activity;
+            $activityWhere = [];
+            if (empty($req->input('type')) === false) {
+                $activityWhere['activity_type'] = $req->input('type');
+            }
+
+            if (empty($req->input('label')) === false) {
+                $activityWhere['activity_label'] = $req->input('label');
+            }
+
+            $activityData = $activityModel->getActivity($activityWhere);
+
+            $msg = '成功';
+            $code = 1;
+
+            return toJson($code, $msg, $activityData);
+        } catch (Exception $e) {
+            return toJson($code, $msg, []);
+        }
+
+    }//end activityList()
+
+
+}

+ 91 - 0
app/Http/Models/Activity.php

@@ -0,0 +1,91 @@
+<?php
+
+namespace App\Http\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use \App\Models;
+
+/**
+ * 活动管理模型类
+ */
+class Activity extends Model
+{
+
+
+    /**
+     * 获取活动
+     *
+     * @access public
+     * @param mixed $where 查询条件
+     * @return String
+     */
+    public function getActivity($where)
+    {
+        $activityModel = new Models\Activity;
+        $select = [
+            'activity_title',
+            'activity_content',
+            'activity_beginTime',
+            'activity_endTime',
+            'activity_type',
+            'activity_label',
+            'activity_money',
+            'activity_identity',
+        ];
+        $where = $where;
+        $where['activity_delete'] = 0;
+        $newTime = date('Y-m-d H:i:s');
+        $result = $activityModel
+            ->select($select)
+            ->where($where)
+            ->where('activity_beginTime', '<=', $newTime)
+            ->where('activity_endTime', '>', $newTime)
+            ->orderBy('activity_beginTime', 'asc')
+            ->get();
+
+        return $result;
+
+    }//end getActivity()
+
+
+    /**
+     * 获取所有活动
+     *
+     * @access public
+     * @param mixed $where 查询条件
+     * @param mixed $paginate 分页
+     * @return String
+     */
+    public function getAllActivity($where, $paginate)
+    {
+        // 获取游戏地址数据.
+        $activityModel = new Models\Activity;
+        $select = [
+            'activity_title',
+            'activity_content',
+            'activity_delete',
+            'activity_type',
+            'activity_label',
+            'activity_money',
+            'activity_data',
+            'activity_data',
+            'activity_identity',
+            'activity_beginTime',
+            'activity_endTime',
+        ];
+        $getActivity = $activityModel->select($select);
+        if (empty($where) === false) {
+            $getActivity = $getActivity->where($where);
+        }
+
+        $getActivity = $getActivity
+            ->orderBy('activity_beginTime','asc')
+            ->paginate($paginate)
+            ->toArray();
+
+        return $getActivity;
+
+    }//end getActivity()
+
+
+}

+ 16 - 0
app/Models/Activity.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * activity
+ */
+class Activity extends Model
+{
+
+    protected $table = 'activity';
+
+
+}

+ 1 - 1
app/Models/Agent.php

@@ -5,7 +5,7 @@ namespace App\Models;
 use Illuminate\Database\Eloquent\Model;
 
 /**
- * 数据库gameUrl模型类
+ * 数据库agent模型类
  */
 class Agent extends Model
 {

+ 1 - 1
app/Models/GameMoney.php

@@ -5,7 +5,7 @@ namespace App\Models;
 use Illuminate\Database\Eloquent\Model;
 
 /**
- * 数据库gameUrl模型类
+ * 数据库gameMoney模型类
  */
 class GameMoney extends Model
 {

+ 1 - 1
app/Models/MembersDetailed.php

@@ -5,7 +5,7 @@ namespace App\Models;
 use Illuminate\Database\Eloquent\Model;
 
 /**
- * 数据库gameUrl模型类
+ * 数据库membersDetailed模型类
  */
 class MembersDetailed extends Model
 {

+ 1 - 1
app/Models/MoneyDetails.php

@@ -5,7 +5,7 @@ namespace App\Models;
 use Illuminate\Database\Eloquent\Model;
 
 /**
- * 数据库gameUrl模型类
+ * 数据库moneyDetails模型类
  */
 class MoneyDetails extends Model
 {

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
public/static/admin/layuiadmin/modules/sample.js


+ 40 - 0
resources/views/admin/activity/_form.blade.php

@@ -0,0 +1,40 @@
+{{csrf_field()}}
+<div class="layui-form-item">
+    <label for="" class="layui-form-label">游戏地址指向名</label>
+    <div class="layui-input-inline">
+        <input type="text" name="gameUrl_name" value="{{ $gameUrl->gameUrl_name ?? old('gameUrl_name') }}" lay-verify="required" placeholder="请输入游戏地址指向名" class="layui-input" >
+    </div>
+</div>
+
+<div class="layui-form-item">
+    <label for="" class="layui-form-label">游戏地址指向类型</label>
+    <div class="layui-input-inline">
+        <input type="text" name="gameUrl_type" value="{{$gameUrl->gameUrl_type??old('gameUrl_type')}}" required="required" placeholder="请输入游戏地址指向类型" class="layui-input">
+    </div>
+</div>
+
+<div class="layui-form-item">
+    <label for="" class="layui-form-label">游戏地址</label>
+    <div class="layui-input-inline">
+        <input type="text" name="gameUrl_url" value="{{ $gameUrl->gameUrl_url ?? old('gameUrl_url') }}" lay-verify="required"  placeholder="请输入游戏地址" class="layui-input" style="width: 600px">
+    </div>
+    <br/>
+    <div class="layui-form-mid layui-word-aux" style="padding: 20px 0 !important; margin-left: -200px;">实例:http://www.kaiyou.com/InApi-index/dobusiness</div>
+</div>
+
+<div class="layui-form-item">
+    <label for="" class="layui-form-label">所需参数</label>
+    <div class="layui-input-inline">
+        <input type="text" name="gameUrl_data" value="{{ $gameUrl->gameUrl_data ?? old('gameUrl_data') }}" lay-verify="required"  placeholder="请输入所需参数" class="layui-input" style="width: 750px">
+    </div>
+    <br/>
+    <div class="layui-form-mid layui-word-aux" style="padding: 20px 0 !important; margin-left: -200px;">实例:{"agent":"test1agent","method":"gb"}</div>
+</div>
+
+
+<div class="layui-form-item">
+    <div class="layui-input-block">
+        <button type="submit" class="layui-btn" lay-submit="" lay-filter="formDemo">确 认</button>
+        <a  class="layui-btn" href="{{route('admin.gameUrl')}}" >返 回</a>
+    </div>
+</div>

+ 69 - 0
resources/views/admin/activity/_js.blade.php

@@ -0,0 +1,69 @@
+<style>
+    #layui-upload-box li{
+        width: 120px;
+        height: 100px;
+        float: left;
+        position: relative;
+        overflow: hidden;
+        margin-right: 10px;
+        border:1px solid #ddd;
+    }
+    #layui-upload-box li img{
+        width: 100%;
+    }
+    #layui-upload-box li p{
+        width: 100%;
+        height: 22px;
+        font-size: 12px;
+        position: absolute;
+        left: 0;
+        bottom: 0;
+        line-height: 22px;
+        text-align: center;
+        color: #fff;
+        background-color: #333;
+        opacity: 0.6;
+    }
+    #layui-upload-box li i{
+        display: block;
+        width: 20px;
+        height:20px;
+        position: absolute;
+        text-align: center;
+        top: 2px;
+        right:2px;
+        z-index:999;
+        cursor: pointer;
+    }
+</style>
+<script>
+    layui.use(['upload'],function () {
+        var upload = layui.upload
+        //普通图片上传
+        var uploadInst = upload.render({
+            elem: '#uploadPic'
+            ,url: '{{ route("admin.uploadImg") }}'
+            ,multiple: false
+            ,data:{"_token":"{{ csrf_token() }}"}
+            ,before: function(obj){
+                //预读本地文件示例,不支持ie8
+                /*obj.preview(function(index, file, result){
+                 $('#layui-upload-box').append('<li><img src="'+result+'" /><p>待上传</p></li>')
+                 });*/
+                obj.preview(function(index, file, result){
+                    $('#layui-upload-box').html('<li><img src="'+result+'" /><p>上传中</p></li>')
+                });
+
+            }
+            ,done: function(res){
+                //如果上传失败
+                if(res.code == 0){
+                    $("#iconUrl").val(res.url);
+                    $('#layui-upload-box li p').text('上传成功');
+                    return layer.msg(res.msg,{icon:6});
+                }
+                return layer.msg(res.msg,{icon:5});
+            }
+        });
+    });
+</script>

+ 18 - 0
resources/views/admin/activity/create.blade.php

@@ -0,0 +1,18 @@
+@extends('admin.base')
+
+@section('content')
+    <div class="layui-card">
+        <div class="layui-card-header layuiadmin-card-header-auto">
+            <h2>添加数据</h2>
+        </div>
+        <div class="layui-card-body">
+            <form class="layui-form" action="{{route('admin.gameUrl.store')}}" method="post">
+                @include('admin.gameUrl._form')
+            </form>
+        </div>
+    </div>
+@endsection
+
+@section('script')
+    @include('admin.gameUrl._js')
+@endsection

+ 20 - 0
resources/views/admin/activity/edit.blade.php

@@ -0,0 +1,20 @@
+@extends('admin.base')
+
+@section('content')
+    <div class="layui-card">
+        <div class="layui-card-header layuiadmin-card-header-auto">
+            <h2>更新</h2>
+        </div>
+        <div class="layui-card-body">
+            <form class="layui-form" action="{{route('admin.gameUrl.update',['gameUrl'=>$gameUrl])}}" method="post">
+                <input type="hidden" name="gameUrl_id" value="{{$gameUrl->gameUrl_id}}">
+                {{method_field('put')}}
+                @include('admin.gameUrl._form')
+            </form>
+        </div>
+    </div>
+@endsection
+
+@section('script')
+    @include('admin.gameUrl._js')
+@endsection

+ 185 - 0
resources/views/admin/activity/index.blade.php

@@ -0,0 +1,185 @@
+@extends('admin.base')
+
+@section('content')
+    <div class="layui-card">
+        <div class="layui-card-header layuiadmin-card-header-auto">
+            <div class="layui-btn-group ">
+                {{--@can('message.activity.destroy')
+                    <button class="layui-btn layui-btn-sm layui-btn-danger" id="listDelete">更改状态</button>
+                @endcan--}}
+                @can('message.activity.create')
+                    <a class="layui-btn layui-btn-sm" href="{{ route('admin.activity.create') }}">添加</a>
+                @endcan
+                <button class="layui-btn layui-btn-sm" id="memberSearch">搜索</button>
+                <button class="layui-btn layui-btn-sm" id="memberSearchOn">上线</button>
+                <button class="layui-btn layui-btn-sm" id="memberSearchOff">下线</button>
+            </div>
+            <div class="layui-form">
+
+                <div class="layui-input-inline">
+                    <input type="text" name="activity_title" id="activity_title" placeholder="活动主题" class="layui-input">
+                </div>
+
+            </div>
+        </div>
+
+        <div class="layui-card-body">
+            <table id="dataTable" lay-filter="dataTable"></table>
+            <script type="text/html" id="activity_delete">
+                @{{ d.activity_delete === 0 ? '<p style="color: lawngreen">上线</p>' : '<p style="color: red">下线</p>' }}
+            </script>
+            {{--<script type="text/html" id="info">
+                <div>
+                    <a style="cursor:pointer; color: #4141ef;" onclick="showInfo()">查看详情</a>
+                    <div class="layui-layer layui-layer-page layui-layer-prompt" id="layui-layer1" type="page" times="1"
+                         showtime="0" contype="string" style="display: none">
+                        <div class="layui-layer-title" style="cursor: move;">活动详情:@{{ d.activity_title}}</div>
+                        <div id="" class="layui-layer-content">
+                            <p>
+                                活动内容:
+                            </p>
+                            <p style="width: 100%; height: 70px; padding: 0 20px 0 20px;">
+                                @{{ d.activity_content}}
+                            </p>
+                            <p>
+                                活动数据:
+                            </p>
+                            <p style="height: 70px; padding: 0 20px 0 20px;">
+                                @{{ d.activity_data}}
+                            </p>
+                        </div>
+                        <span class="layui-layer-setwin">
+                            <a class="layui-layer-ico layui-layer-close layui-layer-close1" href="javascript:;" onclick="hideInfo()">
+                            </a>
+                        </span>
+                    </div>
+                </div>
+            </script>--}}
+            <script type="text/html" id="options">
+                <div class="layui-btn-group">
+                    @can('message.activity.edit')
+                        <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
+                    @endcan
+                    @can('message.activity.destroy')
+                        <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">更改状态</a>
+                    @endcan
+                </div>
+            </script>
+            {{--<script type="text/html" id="avatar">
+                <a href="@{{d.avatar}}" target="_blank" title="点击查看"><img src="@{{d.avatar}}" alt="" width="28" height="28"></a>
+            </script>--}}
+        </div>
+    </div>
+@endsection
+
+@section('script')
+    @can('message.activity')
+        <script>
+            /*function showInfo() {
+                $("#layui-layer1").css({"z-index":"19891015", "top":"49px", "left":"378.5px", "display": "block", "width": "500px"});
+            }
+            function hideInfo() {
+                $("#layui-layer1").css({"display": "none"});
+            }*/
+            layui.use(['layer','table','form'],function () {
+                var layer = layui.layer;
+                var form = layui.form;
+                var table = layui.table;
+                //用户表格初始化
+                var dataTable = table.render({
+                    elem: '#dataTable'
+                    ,height: 500
+                    ,url: "{{ route('admin.activity.data') }}" //数据接口
+                    ,where:{model:"activity"}
+                    ,page: true //开启分页
+                    ,cols: [[ //表头
+                        {checkbox: true,fixed: true}
+                        ,{field: 'activity_title', title: '活动主题'}
+                        ,{field: 'activity_content', title: '活动内容'}
+                        ,{field: 'activity_data', title: '活动数据'}
+                        ,{field: 'activity_beginTime', title: '活动开始'}
+                        ,{field: 'activity_endTime', title: '活动结束'}
+                        ,{field: 'activity_delete', title: '状态', width: 60, toolbar: '#activity_delete'}
+                        ,{field: 'activity_money', title: '购买金额'}
+                        ,{field: 'info', title: '详情', toolbar: '#info'}
+
+                        ,{fixed: 'right', width: 120, align:'center', toolbar: '#options'}
+                    ]]
+                });
+
+                //监听工具条
+                table.on('tool(dataTable)', function(obj){ //注:tool是工具条事件名,dataTable是table原始容器的属性 lay-filter="对应的值"
+                    var data = obj.data //获得当前行数据
+                        ,layEvent = obj.event; //获得 lay-event 对应的值
+                    if(layEvent === 'del'){
+                        layer.confirm('确认更改状态吗?', function(index){
+                            $.post("{{ route('admin.activity.destroy') }}",{_method:'delete',ids:[data.activity_identity],status:data.activity_delete},function (result) {
+                                if (result.code==0){
+                                    var activity_title = $("#activity_title").val();
+                                    dataTable.reload({
+                                        where:{activity_title:activity_title},
+                                        page:{curr:1}
+                                    })
+                                }
+                                layer.close(index);
+                                layer.msg(result.msg)
+                            });
+                        });
+                    } else if(layEvent === 'edit'){
+                        location.href = '/admin/activity/'+data.activity_identity+'/edit';
+                    }
+                });
+
+                //按钮批量删除
+                $("#listDelete").click(function () {
+                    var ids = []
+                    var hasCheck = table.checkStatus('dataTable')
+                    var hasCheckData = hasCheck.data
+                    if (hasCheckData.length>0){
+                        $.each(hasCheckData,function (index,element) {
+                            ids.push(element.activity_identity)
+                        })
+                    }
+                    if (ids.length>0){
+                        layer.confirm('确认更改状态吗?', function(index){
+                            $.post("{{ route('admin.activity.destroy') }}",{_method:'delete',ids:ids},function (result) {
+                                if (result.code==0){
+                                    dataTable.reload()
+                                }
+                                layer.close(index);
+                                layer.msg(result.msg)
+                            });
+                        })
+                    }else {
+                        layer.msg('请选择更改状态项')
+                    }
+                })
+                //搜索
+                $("#memberSearch").click(function () {
+                    var activity_title = $("#activity_title").val();
+                    dataTable.reload({
+                        where:{activity_title:activity_title},
+                        page:{curr:1}
+                    })
+                })
+                //搜索
+                $("#memberSearchOn").click(function () {
+                    dataTable.reload({
+                        where:{activity_delete:0},
+                        page:{curr:1}
+                    })
+                })
+                //搜索
+                $("#memberSearchOff").click(function () {
+                    dataTable.reload({
+                        where:{activity_delete:1},
+                        page:{curr:1}
+                    })
+                })
+            })
+        </script>
+    @endcan
+@endsection
+
+
+

+ 1 - 1
resources/views/admin/index/index2.blade.php

@@ -590,4 +590,4 @@
     <script>
         layui.use(['index', 'sample']);
     </script>
-@endsection
+@endsection

+ 17 - 0
routes/admin.php

@@ -260,4 +260,21 @@ Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['aut
     Route::get('message/noticeAdd', 'MessageController@noticeAdd')->name('admin.message.noticeAdd')->middleware('permission:message.message.noticeAdd');
     Route::post('message/noticeStore', 'MessageController@noticeStore')->name('admin.message.noticeStore')->middleware('permission:message.message.noticeStore');
 
+
+    //活动
+    Route::group(['middleware' => 'permission:message.activity'], function () {
+
+        Route::get('activity/data', 'ActivityController@data')->name('admin.activity.data');
+        Route::get('activity', 'ActivityController@index')->name('admin.activity');
+        //添加
+        Route::get('activity/create', 'ActivityController@create')->name('admin.activity.create')->middleware('permission:message.activity.create');
+        Route::post('activity/store', 'ActivityController@store')->name('admin.activity.store')->middleware('permission:message.activity.create');
+        //编辑
+        Route::get('activity/{id}/edit', 'ActivityController@edit')->name('admin.activity.edit')->middleware('permission:message.activity.edit');
+        Route::put('activity/update', 'ActivityController@update')->name('admin.activity.update')->middleware('permission:message.activity.edit');
+        //删除
+        Route::delete('activity/destroy', 'ActivityController@destroy')->name('admin.activity.destroy')->middleware('permission:message.activity.destroy');
+
+
+    });
 });

+ 7 - 8
websockServ/app/lib/DB_pool.php

@@ -10,7 +10,7 @@ namespace app\lib;
 
 
 /**
- *  swoole 数据库连接池 BY 凌晨
+ *  swoole 数据库连接池 BY Vali
  * 'worker_num' => 20, //worker进程数量
  * 'task_worker_num' => 10, //task进程数量 即为维持的MySQL连接的数量
  * 'daemonize'=> 1,          //设置守护进程
@@ -41,10 +41,10 @@ class DB_pool
         $this->worker_num = 5;
         $this->task_worker_num = 5;
         $this->dispatch_mode = 2;
-        $this->daemonize = 1;
+        $this->daemonize = true ;
         $this->max_request = 10000;
-        $filename = date("Y-m-d", time());
-        $this->log_file = "../logs/mysqlpoole_" . $filename . '.log';
+        $filename = date("Ymd", time());
+        $this->log_file = "../logs/DB_pool_err_" . $filename . '.log';
         $this->serv = new \swoole\server($this->host, $this->server_port);
         $this->serv->set(array(
             'worker_num' => $this->worker_num,
@@ -53,9 +53,6 @@ class DB_pool
             'daemonize' => $this->daemonize,
             'log_file' => $this->log_file,
             'dispatch_mode' => $this->dispatch_mode,
-            'package_max_length'=> 4 * 1024 *1024,
-            'buffer_output_size'=> 4 * 1024 *1024,
-            'socket_buffer_size' => 8 * 1024 *1024
         ));
 
         $this->db_type = $config['db_type'] ? $config['db_type'] : 'mysql';
@@ -134,7 +131,9 @@ class DB_pool
             if (in_array($link->errorCode(), [2013, 2006])) {//错误码为2013,或者2006,则重连数据库,重新执行sql
                 $link = null;
                 goto HELL;
-            } else {
+            }
+            $errinfoArr = $link->errorInfo();
+            if (!($errinfoArr['0']=='00000' && $errinfoArr['1'] =='' &&  $errinfoArr['2']=='')){
                 $data['status'] = 'false';
                 $data['data'] = $link->errorInfo();
                 $this->serv->finish(json_encode($data, 256));

+ 1 - 1
websockServ/app/lib/DataPack.php

@@ -35,7 +35,7 @@ class DataPack
             self::Create($array);
         }
         $ret = [
-            'id' => self::UUID(),
+            'id' => isset(self::$Datas['id']) ? self::$Datas['id'] : self::UUID(),
             'fr' => isset(self::$Datas['from']) ? self::$Datas['from'] : 0,
             'to' => isset(self::$Datas['to']) ? self::$Datas['to'] : 0,
             'ct' => time(),

+ 6 - 1
websockServ/app/lib/Mconsts.php

@@ -30,7 +30,12 @@ defined('ON_OPEN') or define("ON_OPEN", 'ON_OPEN');
 defined('TIME_RSYNC_KEY') or define("TIME_RSYNC_KEY", 'TIME_RSYNC_KEY');                     //时间同步的写获取者
 
 defined('MSG_REDIS_SUBSCRIBE') or define("MSG_REDIS_SUBSCRIBE", 'MSG_REDIS_SUBSCRIBE');      //redis 消息订阅key
-defined('MSG_INDEX') or define("MSG_INDEX", 'MSG_INDEX_QIPAI');                                     //redis 消息订阅key首页中奖消息
+
+defined('MSG_BOARD') or define("MSG_BOARD", 'MSG_BOARD');                                     //通用广播消息队列键名
+defined('MSG_TO_ONE_USER') or define("MSG_TO_ONE_USER", 'MSG_TO_ONE_USER');                   //通用单用户消息队列键名
+defined('DO_TICK_USER') or define("DO_TICK_USER", 'DO_TICK_USER');                             //需要提下线的单用户消息队列键名
+defined('USER_BLACK_HASH') or define("USER_BLACK_HASH", 'USER_BLACK_HASH');                    //用户黑名单,不能连上线 has表
+
 ////
 
 

+ 14 - 16
websockServ/app/lib/wclient/PacketHandler.php

@@ -1,5 +1,7 @@
 <?php
-namespace  app\lib\wclient;
+
+namespace app\lib\wclient;
+
 /**
  * Created by PhpStorm.
  * User: marsnowxiao
@@ -8,7 +10,8 @@ namespace  app\lib\wclient;
  */
 use app\lib\wclient\WebSocketFrame as WebSocketFrame;
 
-class PacketHandler {
+class PacketHandler
+{
     const GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
     const TOKEN_LENGHT = 16;
     const maxPacketSize = 2000000;
@@ -32,15 +35,15 @@ class PacketHandler {
         return base64_encode($randomString);
     }
 
-    public function buildHandShakeRequest($host, $port)
+    public function buildHandShakeRequest($host, $port, $getParas)
     {
         $this->key = static::generateToken(self::TOKEN_LENGHT);
 
-        return "GET / HTTP/1.1" . "\r\n" .
+        return "GET /{$getParas} HTTP/1.1" . "\r\n" .
             "Origin: null" . "\r\n" .
             "Host: {$host}:{$port}" . "\r\n" .
             "Sec-WebSocket-Key: {$this->key}" . "\r\n" .
-            "User-Agent: SwooleWebsocketClient"."/0.1.4" . "\r\n" .
+            "User-Agent: SwooleWebsocketClient" . "/0.1.4" . "\r\n" .
             "Upgrade: Websocket" . "\r\n" .
             "Connection: Upgrade" . "\r\n" .
             "Sec-WebSocket-Protocol: wamp" . "\r\n" .
@@ -60,7 +63,7 @@ class PacketHandler {
             }
         }
 
-        return (isset($headerInfo['Sec-WebSocket-Accept']) && $headerInfo['Sec-WebSocket-Accept'] == base64_encode(pack('H*', sha1($this->key.self::GUID))));
+        return (isset($headerInfo['Sec-WebSocket-Accept']) && $headerInfo['Sec-WebSocket-Accept'] == base64_encode(pack('H*', sha1($this->key . self::GUID))));
     }
 
     public function processDataFrame(&$packet)
@@ -87,33 +90,28 @@ class PacketHandler {
         $length = $handle & 0x7f;
         $index++;
         //126 short
-        if ($length == 0x7e)
-        {
+        if ($length == 0x7e) {
             if (strlen($packet) < $index + 2)
                 return null;
             //2 byte
             $handle = unpack('nl', substr($packet, $index, 2));
             $index += 2;
             $length = $handle['l'];
-        }
-        //127 int64
-        elseif ($length > 0x7e)
-        {
+        } //127 int64
+        elseif ($length > 0x7e) {
             if (strlen($packet) < $index + 8)
                 return null;
             //8 byte
             $handle = unpack('Nh/Nl', substr($packet, $index, 8));
             $index += 8;
             $length = $handle['l'];
-            if ($length > static::maxPacketSize)
-            {
+            if ($length > static::maxPacketSize) {
                 throw new \Exception("frame length is too big.\n");
             }
         }
 
         //mask-key: int32
-        if ($mask)
-        {
+        if ($mask) {
             if (strlen($packet) < $index + 4)
                 return null;
             $mask = array_map('ord', str_split(substr($packet, $index, 4)));

+ 6 - 4
websockServ/app/lib/wclient/WebSocketClient.php

@@ -11,6 +11,7 @@ class WebSocketClient
     private $state;
     private $host;
     private $port;
+    private $getParas;
     private $handler;
     private $buffer;
     private $openCb;
@@ -41,17 +42,18 @@ class WebSocketClient
         $this->buffer = "";
     }
 
-    public function connect($host, $port)
+    public function connect($host, $port, $getParas = '', $timeout = 0.5, $flag = 0)
     {
         $this->host = $host;
         $this->port = $port;
-        $this->client->connect($host, $port);
+        $this->getParas = $getParas;
+        $this->client->connect($host, $port, $timeout, $flag);
     }
 
     public function sendHandShake()
     {
         $this->state = static::HANDSHAKING;
-        $request = $this->handler->buildHandShakeRequest($this->host, $this->port);
+        $request = $this->handler->buildHandShakeRequest($this->host, $this->port, $this->getParas);
         $this->client->send($request);
     }
 
@@ -150,7 +152,7 @@ class WebSocketClient
                 return;
         }
         $data = \swoole_websocket_server::pack($data, $_type);
-        $this->client->send($data);
+        return $this->client->send($data);
     }
 
     public function getTcpClient()

+ 44 - 19
websockServ/app/logic/MyServerV2.php

@@ -27,8 +27,19 @@ class MyServerV2
 
     public function __construct()
     {
-        $this->serv = new \swoole_websocket_server("0.0.0.0", 9090);
-        $this->serv->set(GlobConfigs::getKey('swoolev2'));
+        $config = GlobConfigs::getKey('swoole');
+        $this->serv = new \swoole_websocket_server($config['host'], $config['port']);
+        $this->serv->set($config['sets']);
+
+        //内存表(用户uid和fd的双向映射表)
+        $fd_table = new \swoole_table($config['maxUsers']);
+        $fd_table->column("uid", \swoole_table::TYPE_INT, 4);
+        $fd_table->create();
+        $user_table = new \swoole_table($config['maxUsers']);
+        $user_table->column("fid", \swoole_table::TYPE_INT, 4);
+        $user_table->create();
+        $this->serv->ftable = $fd_table;
+        $this->serv->utable = $user_table;
 
         $this->serv->on('Start', array($this, 'onStart'));
         $this->serv->on('WorkerStart', array($this, 'onWorkerStart'));
@@ -137,9 +148,9 @@ class MyServerV2
 
     public function onMessage($serv, $frame)
     {
-        if ( strtolower($frame->data->data)  == '{"type":"ping"}'){
-                $serv->send($frame->fd,'{"type":"pong"}');
-                return ;
+        if (strtolower($frame->data->data) == '{"type":"ping"}') {
+            $serv->send($frame->fd, '{"type":"pong"}');
+            return;
         }
         Wlog::getInstance()->WriteLog($frame);
         $serv->task($frame);
@@ -147,7 +158,7 @@ class MyServerV2
 
     public function onOpen($serv, $request)
     {
-        Wlog::getInstance()->WriteLog(['onOpenData',$request]);
+        //Wlog::getInstance()->WriteLog(['onOpenData', $request]);
         $token = isset($request->get['token']) ? $request->get['token'] : '';
         //$uid = isset($request->get['uid']) ? $request->get['uid'] : '';
         $fd = $request->fd;
@@ -156,21 +167,29 @@ class MyServerV2
             return;
         }
         $token_uid = $uid = intval($this->workRedis->hget(MAPS_TOKEN_UID, md5($token)));
-        if (empty($token) || !$token_uid ) {
+        if (empty($token) || !$token_uid) {
             $serv->push($request->fd, DataPack::toJson(['mtype' => 'system_msg', 'stype' => 'invalid_token', 'data' => ['msg' => '无效的token']]));
             $serv->disconnect($request->fd);
             return;
         }
 
-        $oldfid = $this->workRedis->hget(MAPS_UID_FID, $uid);
-        if ($oldfid != '' && $oldfid != $fd && $serv->exist($oldfid)) {
-            $serv->push($oldfid, DataPack::toJson(['mtype' => 'system_msg', 'stype' => 'force_logout', 'data' => [ 'msg' => '你已在其它地方登陆,本次退出!']]));
-            $serv->disconnect($oldfid);
+        //管理员账号可以多连
+        $adminconfig = GlobConfigs::getKey('admin_conf');
+        if ($adminconfig['admin_uid'] != $uid) {
+            $oldfid = $this->workRedis->hget(MAPS_UID_FID, $uid);
+            if ($oldfid != '' && $oldfid != $fd && $serv->exist($oldfid)) {
+                $serv->push($oldfid, DataPack::toJson(['mtype' => 'system_msg', 'stype' => 'force_logout', 'data' => ['msg' => '你已在其它地方登陆,本次退出!']]));
+                $serv->disconnect($oldfid);
+            }
+
+            $this->workRedis->hset(MAPS_UID_FID, $uid, $fd);
+            $this->workRedis->hset(MAPS_FID_UID, $fd, $uid);
+            $serv->ftable->set($fd, ['uid' => $uid]);
+            $serv->utable->set($uid, ['fid' => $fd]);
         }
 
-        $this->workRedis->hset(MAPS_UID_FID, $uid, $fd);
-        $this->workRedis->hset(MAPS_FID_UID, $fd, $uid);
-        $serv->push($fd, DataPack::toJson(['mtype' => 'system_msg', 'stype' => 'well_come', 'data' => [ 'msg' => '成功接入']]));
+
+        $serv->push($fd, DataPack::toJson(['mtype' => 'system_msg', 'stype' => 'well_come', 'data' => ['msg' => '成功接入']]));
     }
 
     public function onTask($serv, \Swoole\Server\Task $task)
@@ -179,7 +198,7 @@ class MyServerV2
             Wlog::getInstance()->WriteLog($task, 1, $serv->worker_id);
             CmdProxy::getInstance()->ParaCMD($serv, $task);
         } catch (\Exception $e) {
-            Wlog::getInstance()->WriteLog(['onTask error:',$task,$e->getCode() . ' ' . $e->getMessage()], 3, $serv->worker_id);
+            Wlog::getInstance()->WriteLog(['onTask error:', $task, $e->getCode() . ' ' . $e->getMessage()], 3, $serv->worker_id);
             echo "发生异常." . $e->getCode() . ' ' . $e->getMessage() . "\n";
         }
     }
@@ -191,8 +210,14 @@ class MyServerV2
     public function onClose($serv, $fd, $from_id)
     {
         $uid = $this->workRedis->hget("MAPS_FID_UID", $fd);
-        $this->workRedis->hdel(MAPS_UID_FID, $uid);
-        $this->workRedis->hdel(MAPS_FID_UID, $fd);
+        $adminconfig = GlobConfigs::getKey('admin_conf');
+        if ($adminconfig['admin_uid'] != $uid) {
+            $this->workRedis->hdel(MAPS_UID_FID, $uid);
+            $this->workRedis->hdel(MAPS_FID_UID, $fd);
+
+            $serv->ftable->del($fd);
+            $serv->utable->del($uid);
+        }
         echo "ClientFd:{$fd} -- uid:{$uid} close connection!\n";
     }
 
@@ -327,8 +352,8 @@ class MyServerV2
             $redis->del(MAPS_FID_UID);
             //$redis->del(MAPS_TOKEN_UID);
             //$redis->del(MAPS_UID_TOKEN);
-            $redis->hset(MAPS_UID_TOKEN,$adminconf['admin_uid'],$adminconf['md5']);
-            $redis->hset(MAPS_TOKEN_UID,$adminconf['md5'],$adminconf['admin_uid']);
+            $redis->hset(MAPS_UID_TOKEN, $adminconf['admin_uid'], $adminconf['md5']);
+            $redis->hset(MAPS_TOKEN_UID, $adminconf['md5'], $adminconf['admin_uid']);
             $redis->exec();
             $redis->close();
         }

+ 122 - 30
websockServ/app/logic/SubServer.php

@@ -25,20 +25,16 @@ class SubServer
 
     public function __construct()
     {
-        $this->configs = GlobConfigs::getKey('swoolev_subserv');
+        $this->configs = GlobConfigs::getKey('swoole_subserv');
         $this->serv = new \swoole_websocket_server($this->configs['host'], $this->configs['port']);
-
-        unset($this->configs['host']);
-        unset($this->configs['port']);
-        $this->serv->set($this->configs);
+        $this->serv->set($this->configs['sets']);
 
         $this->serv->on('Start', array($this, 'onStart'));
         $this->serv->on('WorkerStart', array($this, 'onWorkerStart'));
         $this->serv->on('message', array($this, 'onMessage'));
         $this->serv->on('close', array($this, 'onClose'));
         $this->serv->on('open', array($this, 'onOpen'));
-        $this->serv->on('task', array($this, 'onTask'));
-        $this->serv->on('Finish', array($this, 'onFinish'));
+
 
         return $this->serv->start();
     }
@@ -61,9 +57,28 @@ class SubServer
 
         if ($worker_id == 0) {
             $serv->tick(1000, function () use ($serv, $worker_id) {
-                $msg_index_aray = $this->getIndexMsg();
+                $msg_index_aray = $this->getBoardMsg();
                 if (!empty($msg_index_aray)) {
-                    $this->sendIndexMsg($msg_index_aray);
+                    $this->SendMsgComm('msg_board', $msg_index_aray);
+                }
+            });
+        }
+
+        if ($worker_id == 1) {
+            $serv->tick(1000, function () use ($serv, $worker_id) {
+                $msg_user_array = $this->getSingMsg();
+                if (!empty($msg_user_array)) {
+                    $this->SendMsgComm('msg_to_one_user', $msg_user_array);
+                    //$this->sendSingMsg($msg_user_array);
+                }
+            });
+        }
+        
+        if ($worker_id == 2) {
+            $serv->tick(5000, function () use ($serv, $worker_id) {
+                $msg_tick_array = $this->getDoTick();
+                if (!empty($msg_tick_array)) {
+                    $this->SendMsgComm('do_tick', $msg_tick_array);
                 }
             });
         }
@@ -77,7 +92,6 @@ class SubServer
         if ($this->workRedis) {
             $this->workRedis->close();
         }
-
     }
 
 
@@ -91,15 +105,6 @@ class SubServer
 
     }
 
-    public function onTask($serv, \Swoole\Server\Task $task)
-    {
-
-    }
-
-    public function onFinish($serv, $task_id, $data)
-    {
-    }
-
     public function onClose($serv, $fd, $from_id)
     {
 
@@ -152,27 +157,115 @@ class SubServer
 
     ////////////////////////
     //去redis里找 msg_index 是否有数据,有取出来,
-    private function getIndexMsg()
+    private function getBoardMsg()
+    {
+        $redis = $this->workRedis;
+        $len = $redis->LLEN(MSG_BOARD);
+
+        if ($len <= 0) {
+            return;
+        }
+        $datas = [];
+        while ($now = $redis->rpop(MSG_BOARD)) {
+            if (empty($now)) {
+                break;
+            }
+            $now = json_decode($now, true);
+            if (!isset($now['stype']) || empty($now['stype'])) {
+                Wlog::getInstance()->WriteLog(['数据格式误,没有stype字段[subserver]', $now]);
+                continue;
+            }
+            if (!isset($now['data'])) {
+                Wlog::getInstance()->WriteLog(['数据格式误,没有data字段[subserver]', $now]);
+                continue;
+            }
+            $datas[] = $now;
+        }
+
+        return $datas;
+    }
+
+
+    private function getSingMsg()
     {
         $redis = $this->workRedis;
-        $len = $redis->LLEN(MSG_INDEX);
+        $len = $redis->LLEN(MSG_TO_ONE_USER);
 
-        if ($len <=0 ) {
+        if ($len <= 0) {
             return;
         }
+
         $datas = [];
-        while ($now = $redis->rpop(MSG_INDEX)) {
+        while ($now = $redis->rpop(MSG_TO_ONE_USER)) {
             if (empty($now)) {
                 break;
             }
+            $now = json_decode($now, true);
+            if (!isset($now['mtype']) || empty($now['mtype'])) {
+                Wlog::getInstance()->WriteLog(['数据格式误,没有mtype字段[subserver]', $now]);
+                continue;
+            }
+
+            if (!isset($now['stype']) || empty($now['stype'])) {
+                Wlog::getInstance()->WriteLog(['数据格式误,没有stype字段[subserver]', $now]);
+                continue;
+            }
+            if (!isset($now['data'])) {
+                Wlog::getInstance()->WriteLog(['数据格式误,没有data字段[subserver]', $now]);
+                continue;
+            }
+
+            if (!isset($now['to']) || empty($now['to'])) {
+                Wlog::getInstance()->WriteLog(['数据格式误,没有to字段或为空[subserver]', $now]);
+                continue;
+            }
+
+            if (!isset($now['from'])) {
+                Wlog::getInstance()->WriteLog(['数据格式误,没有from字段[subserver]', $now]);
+                continue;
+            }
+
+            $now['confirm'] = (isset($now['confirm']) && $now['confirm'] == 1) ? 1 : 0;
+
             $datas[] = $now;
         }
+        return $datas;
+    }
+
+    private function getDoTick()
+    {
+        $redis = $this->workRedis;
+        $len = $redis->LLEN(DO_TICK_USER);
+
+        if ($len <= 0) {
+            return;
+        }
 
+        $datas = [];
+        while ($now = $redis->rpop(DO_TICK_USER)) {
+            if (empty($now)) {
+                break;
+            }
+            $allArray = json_decode($now, true);
+            if (!is_array($allArray)) {
+                Wlog::getInstance()->WriteLog(['数据格式误,不是全法数组[subserver-getDoTick]', $now]);
+            }
+            foreach ($allArray as $one) {
+                if (!isset($one['uid']) || empty($one['uid'])) {
+                    Wlog::getInstance()->WriteLog(['数据格式误,没有uid字段[subserver-getDoTick]', $now]);
+                    continue;
+                }
+                if (!isset($one['msg'])) {
+                    Wlog::getInstance()->WriteLog(['数据格式误,没有msg字段[subserver-getDoTick]', $now]);
+                    continue;
+                }
+                $datas[] = $one;
+            }
+        }
         return $datas;
     }
 
-    ///如果有msg_index数据,就通知服务端下发
-    private function sendIndexMsg($msg_index_aray)
+    private function SendMsgComm($act, $msgArray)
     {
         $conf = GlobConfigs::getKey('admin_conf');
         $token = $conf['admin_token'];
@@ -181,19 +274,18 @@ class SubServer
 
         $arr = [
             'cmd' => 'subserv',
-            'act' => 'index_msg',
-            'data' => $msg_index_aray,
+            'act' => $act,
+            'data' => $msgArray,
             'time' => time(),
             'token' => '',
         ];
         $str = json_encode($arr, 256);
-        $r = $client->send($str);
-        $reciv = $client->receive();
+        $client->send($str);
+        $client->receive();
         $client->close();
 
         unset($client);
     }
-    /////////////////////////
 
 
 }

+ 26 - 15
websockServ/app/logic/cmdpro/CmdInf.php

@@ -1,5 +1,6 @@
 <?php
-namespace  app\logic\cmdpro;
+
+namespace app\logic\cmdpro;
 /**
  * Created by PhpStorm.
  * User: Administrator
@@ -29,10 +30,12 @@ data:
 
 use app\lib\DataPack;
 use app\lib\Wlog;
+use app\lib\GlobConfigs;
 
 class   CmdInf
 {
-    public function paraCmd($serv, \Swoole\Server\Task $task){
+    public function paraCmd($serv, \Swoole\Server\Task $task)
+    {
         $fd = $task->data->fd;
         $dataPack = json_decode($task->data->data, true);
         $method = isset($dataPack['act']) ? $dataPack['act'] : '';
@@ -42,34 +45,42 @@ class   CmdInf
             return;
         }
 
-        try{
-            return $this->$method($serv,$task);
-        }catch (\Exception $e){
-            echo "发生异常或错误:".$e->getFile().' '.$e->getLine().' '.$e->getCode().' '.$e->getMessage()."\r\n";
-            return ;
+        try {
+            return $this->$method($serv, $task);
+        } catch (\Exception $e) {
+            echo "发生异常或错误:" . $e->getFile() . ' ' . $e->getLine() . ' ' . $e->getCode() . ' ' . $e->getMessage() . "\r\n";
+            return;
         }
 
     }
 
     //单发
-    public function sendTo($serv,$fd,$dataString,$close=false)
+    public function sendTo($serv, $fd, $dataString, $close = false)
     {
-        $serv->push($fd,$dataString);
-        if ($close){
+        $serv->push($fd, $dataString);
+        if ($close) {
             $serv->disconnect($fd);
         }
         return true;
     }
 
     //在线广播
-    public function onlineBroad($serv,$dataString){
-        foreach($serv->connections as $fd)
-        {
-            $serv->push($fd,$dataString);
+    public function onlineBroad($serv, $dataString)
+    {
+        foreach ($serv->connections as $fd) {
+            $serv->push($fd, $dataString);
         }
     }
 
-
+    //用uid发
+    public function sendToUid($serv, $uid, $dataString, $close = false)
+    {
+        $fd = intval($serv->utable->get($uid,'fid'));
+        if ($fd) {
+            return $this->sendTo($serv, $fd, $dataString, $close);
+        }
+        return false;
+    }
 
 
 }

+ 59 - 7
websockServ/app/logic/cmdpro/CmdSubser.php

@@ -5,29 +5,81 @@
  * Date: 2019/5/21
  * Time: 16:57
  */
+
 namespace app\logic\cmdpro;
 
 use app\lib\DataPack;
+use app\lib\Wlog;
 use app\logic\cmdpro\CmdInf as CmdInf;
 
-class CmdSubser  extends CmdInf
+class CmdSubser extends CmdInf
 {
     public function index_msg($serv, $task)
     {
-        go(function()use($serv,$task){
+        go(function () use ($serv, $task) {
             $pack = json_decode($task->data->data, true);
             $msgarr = $pack['data'];
-            if (!is_array($msgarr)){
-                return ;
+            if (!is_array($msgarr)) {
+                return;
             }
-            foreach ($msgarr as $msg){
-                $msg = DataPack::toJson(['mtype'=>'system_msg','stype'=>'index_msg','data'=>$msg]);
-                $this->onlineBroad($serv, $msg );
+            foreach ($msgarr as $msg) {
+                $msg = DataPack::toJson(['mtype' => 'system_msg', 'stype' => 'index_msg', 'data' => $msg]);
+                $this->onlineBroad($serv, $msg);
             }
         });
     }
 
+    public function msg_board($serv, $task)
+    {
+        go(function () use ($serv, $task) {
+            $pack = json_decode($task->data->data, true);
+            $msgarr = $pack['data'];
+            if (!is_array($msgarr)) {
+                return;
+            }
+            foreach ($msgarr as $msg) {
+                $stype = $msg['stype'];
+                $data = $msg['data'];
+                $msg = DataPack::toJson(['mtype' => 'system_msg', 'stype' => $stype, 'data' => $data]);
+                $this->onlineBroad($serv, $msg);
+            }
+        });
+    }
 
+    public function msg_to_one_user($serv, $task)
+    {
+        go(function () use ($serv, $task) {
+            $pack = json_decode($task->data->data, true);
+            $msgarr = $pack['data'];
+            if (!is_array($msgarr)) {
+                return;
+            }
+            foreach ($msgarr as $msg) {
+                $msgJson = DataPack::toJson($msg);
+                $this->sendToUid($serv, $msg['to'], $msgJson);
+            }
+        });
+    }
+
+    public function do_tick($serv, $task)
+    {
+        $pack = json_decode($task->data->data, true);
+        $datas = $pack['data'];
+        if (!is_array($datas)) {
+            Wlog::getInstance()->WriteLog("无效的数据格式dotick:" . $task->data->data);
+            return;
+        }
+        foreach ($datas as $key => $val) {
+            $uid = $val['uid'];
+            $msg = $val['msg'];
+            $fid = $serv->utable->get($uid, 'fid');
+            if ($fid) {
+                $this->sendTo($serv, $fid, $msg);
+                $serv->disconnect($fid);
+            }
+        }
+        return true;
+    }
 
 
 }

+ 27 - 4
websockServ/commands/clientws1.php

@@ -14,12 +14,21 @@ use  app\lib\wclient\WebSocketClient ;
 
 
 $client = new WebSocketClient();
+$timerId = 0 ;
 
-$client->on("open",function ($client) {
+$client->on("open",function ($client) use ($timerId)  {
     $fd = $client->getTcpClient()->sock;
     echo "fd: $fd is open\n";
     $msg = '{"cmd":"test","act":"broad","data":"你好,朋友们!","time":1558492565,"token":"aasasfa"}';
-    $client->send($msg);
+
+    $timerId = Swoole\Timer::tick(3000,function()use($msg,$client){
+           $ret = $client->send($msg);
+           if (!$ret){
+               $client->close();
+       }
+    });
+    setTimeid($timerId);
+
 });
 
 $client->on("message", function ($client, $frame) {
@@ -28,12 +37,26 @@ $client->on("message", function ($client, $frame) {
 });
 
 
-$client->on("close", function ($client) {
+$client->on("close", function ($client)use ($timerId) {
+    if (getTimeid()){
+        Swoole\Timer::clear(getTimeid());
+    }
     $fd = $client->getTcpClient()->sock;
     echo "fd: $fd is closed\n";
 });
 
-$client->connect("192.168.2.200", 9090);
+function  setTimeid($id){
+    global  $timerId ;
+    $timerId = $id ;
+}
+
+function  getTimeid(){
+    global  $timerId ;
+    return $timerId  ;
+}
+$config = \app\lib\GlobConfigs::getKey('admin_conf');
+$url = "?token=".$config['admin_token'];
+$client->connect("192.168.2.200", 9090, $url , 0.5 , true);
 
 
 

+ 2 - 1
websockServ/commands/clientws2.php

@@ -15,7 +15,8 @@ require __DIR__.'/../vendor/autoload.php';
 
 use WebSocket\Client as Client;
 
-$client = new Client("ws://192.168.2.200:9090");
+$url = "?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJib3JuIiwiaWF0IjoxNTU5MDI3Mzk1LCJleHAiOjE1NTkwMzQ1OTUsIm5iZiI6MTU1OTAyNzQ1NSwic3ViIjoxMCwianRpIjoiOGVlODI5Y2QtNjM3Mi1iNjUyLTYxYWItMWY3YWViYTNhODM0In0.eLuHFc5uhTAc87DVCAnTKzRloZS0n79jYWTYE9ea7E0";
+$client = new Client("ws://192.168.2.200:9090/".$url);
 
 
 $str = '{"cmd":"test","act":"broad","data":"你好,朋友们!","time":1558492565,"token":"aasasfa"}';

+ 2 - 6
websockServ/commands/mysql_poole_client_test.php

@@ -15,29 +15,25 @@ require __DIR__.'/../vendor/autoload.php';
 $config  = \app\lib\GlobConfigs::getKey('pgsqlpoole');
 
 $client    = new swoole_client(SWOOLE_SOCK_TCP);
-$client->set(array(
-    'socket_buffer_size'     => 1024*1024*8, //2M缓存区
-));
 $rts= $client->connect('192.168.2.200', $config['poole_port'], 10) or die("连接失败");//链接mysql客户端
 
 if (!$rts){
     die("连接发生错误,操作中止\n");
 }
 
-$sql =("select  * from members where id=57");
+$sql =("select  * from members where id=57111");
 $client->send($sql);
 $resdata = $client->recv();
 print_r(json_decode($resdata,true)) ;
 
 
-$sql ="update  members  set  name='12-".rand(100,500)."'  where id=57";
+$sql ="update  members  set  name='12-".rand(100,500)."'  where id=57000";
 $client->send($sql);
 $resdata = $client->recv();
 print_r(json_decode($resdata,true)) ;
 
 $sql ="select  * from \"districts\" where id=1";
 $client->send($sql);
-$client->waitall();
 $resdata = $client->recv();
 print_r(json_decode($resdata,true)) ;
 

+ 33 - 46
websockServ/configs/configs.php

@@ -30,6 +30,8 @@ $tmp_config = [
             'collation' => 'utf8_unicode_ci',
             'prefix' => ''
         ],
+
+        //redis配置
         'redis' => [
             'host' => '192.168.2.200',
             'port' => 26379,
@@ -41,44 +43,37 @@ $tmp_config = [
         'swoole' => [
             'host' => '0.0.0.0',
             'port' => '9090',
-            'worker_num' => 2,
-            'daemonize' => true,
-            'max_request' => 50,
-            'task_enable_coroutine' => true,
-            'dispatch_mode' => 2,
-            'debug_mode' => 1,
-            'task_worker_num' => 5,
-            'log_file' => '../logs/err.log',
-        ],
-        //数据库代理连接池
-        'swoolev2' => [
-            'host' => '0.0.0.0',
-            'port' => '9091',
-            'worker_num' => 2,
-            'daemonize' => true,
-            'max_request' => 5000,
-            'task_enable_coroutine' => true,
-            'dispatch_mode' => 2,
-            'debug_mode' => 1,
-            'task_worker_num' => 10,
-            'log_file' => '../logs/errv2.log',
+            'maxUsers' => 4096,
+            'sets' => [
+                'worker_num' => 2,
+                'daemonize' => true,
+                'max_request' => 50,
+                'task_enable_coroutine' => true,
+                'dispatch_mode' => 2,
+                'debug_mode' => 1,
+                'task_worker_num' => 5,
+                'log_file' => '../logs/swoole_'.date("Ymd").'.log',
+            ],
         ],
+
         //子进程业务
-        'swoolev_subserv' => [
+        'swoole_subserv' => [
             'host' => '0.0.0.0',
             'port' => '9092',
-            'worker_num' => 2,
-            'daemonize' => true,
-            'max_request' => 5000,
-            'task_enable_coroutine' => true,
-            'dispatch_mode' => 2,
-            'debug_mode' => 1,
-            'task_worker_num' => 1,
-            'log_file' => '../logs/errv3.log',
+            'sets'=>[
+                'worker_num' => 3,
+                'daemonize' => true,
+                'max_request' => 5000,
+                'task_enable_coroutine' => true,
+                'dispatch_mode' => 2,
+                'debug_mode' => 1,
+                'log_file' => '../logs/swoole_subserv_'.date("Ymd").'.log',
+            ],
         ],
 
-        'pgsqlpoole'=>[
-            'poole_host' => '0.0.0.0' ,
+        //数据库代理配置--pgsql
+        'pgsqlpoole' => [
+            'poole_host' => '0.0.0.0',
             'poole_port' => 9091,
 
             'db_type' => 'pgsql',
@@ -88,8 +83,9 @@ $tmp_config = [
             'db_user' => 'kaiyou',
             'db_pwd' => '123456',
         ],
-        'mysqlpoole'=>[
-            'poole_host' => '0.0.0.0' ,
+        //数据库代理配置--mysql
+        'mysqlpoole' => [
+            'poole_host' => '0.0.0.0',
             'poole_port' => 9091,
 
             'db_type' => 'mysql',
@@ -99,21 +95,12 @@ $tmp_config = [
             'db_user' => 'vali',
             'db_pwd' => '1234',
         ],
-        'commpoole'=>[
-            'poole_host' => '0.0.0.0' ,
-            'poole_port' => 9091,
 
-            'db_type' => 'mysql',
-            'db_host' => '192.168.2.200',
-            'db_port' => 3306,
-            'db_name' => 'ds_cms',
-            'db_user' => 'vali',
-            'db_pwd' => '1234',
-        ],
-        'admin_conf' =>[
+        //管理员使用的
+        'admin_conf' => [
             'url' => 'ws://192.168.2.200:9090',
             'admin_uid' => 999999999,
-            'md5'=>'70d8d42d4307e63702b25ddef0129f72',
+            'md5' => '70d8d42d4307e63702b25ddef0129f72',
             'admin_token' => 'aaminaeyJhb34G6i6JIU6I1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJib3JuIiwiaWF0IjoxNTU4NTk1MjgxLCJleHAiOjE1NTg2MDI0ODEsIm5iZiI6MTU1ODU5NTM0MSwic3ViIjo3NiwianRpIjoiNWIwYjlkNjMtYmQ5My1kNTBkLTA1NzgtZGU0NDEyYjFmZjBlIn0.jaYz1IcJJxNCaEF-ELCcE6JjbFSjKPl0p-whJ76dV1w',
         ],
     ],

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä