Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

李洋 / 消息系统

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • CMS-Message
  • app
  • Http
  • Controllers
  • MessageController.php
MessageController.php 27.2 KB
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
1 2 3 4 5 6 7 8 9 10
<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2017/11/22
 * Time: 19:24
 */

namespace App\Http\Controllers;

李洋's avatar
1、权限系统配置文件
a3d6785e
 
李洋 committed 7 years ago
11
use ClassPreloader\Config;
李洋's avatar
全部历史消息 改版
f9f4dc87
 
李洋 committed 6 years ago
12
use function GuzzleHttp\Psr7\str;
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
13 14 15 16
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use RedisDB;
李洋's avatar
全部历史消息 改版
f9f4dc87
 
李洋 committed 6 years ago
17
use Carbon\Carbon;
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

function CheckActive($menus, &$arr, $url)
{
    for ($i = 0; $i < count($menus); $i++) {
        $menu = $menus[$i];
        array_push($arr, $i);

        if (isset($menu->href) && ($menu->href == $url || ($menu->href == '/' && $url == '//')))
            return true;
        if (isset($menu->childs) && count($menu->childs) > 0) {
            $ret = CheckActive($menu->childs, $arr, $url);
            if ($ret)
                return $ret;
        }
        array_pop($arr);
    }
    return false;
}

function createMenuReal($menus, $active, $level)
{
    $subclass = ($level == 0) ? 'nav-second-level' : 'nav-third-level';

    $ret = '';
    for ($ii = 0; $ii < ($level == 0 ? 1 : 2); $ii++) {
        for ($i = 0; $i < count($menus); $i++) {
            $menu = $menus[$i];
            $act = (count($active) > $level && $active[$level] == $i) ? true : false;
            $actclass = $act ? ' class="active"' : '';
            $actmenu = $act ? ' in' : '';

            if (isset($menu->childs) && count($menu->childs) > 0) {
                if ($ii != 0 && $level > 0)
                    continue;
                $ret .= '<li' . $actclass . '><a><i class="'
                    . $menu->class . '"></i><span class="nav-label">'
                    . $menu->title . '</span><span class="fa arrow"></span></a>'
                    . '<ul class="nav ' . $subclass . ' collapse' . $actmenu . '">'
                    . createMenuReal($menu->childs, $act ? $active : [], $level + 1)
                    . '</ul></li>';
            } else {
                if ($ii != 1 && $level > 0)
                    continue;
                $ret .= '<li' . $actclass . '><a href="' . $menu->href . '"><i class="' .
                    $menu->class . '"></i><span class="nav-label">' . $menu->title . '</span></a></li>';
            }
        }
    }

    return $ret;
}

function createMenu($menus, $url)
{
    $actives = [];
    $ret = CheckActive($menus, $actives, $url);
    if (!$ret)
        $actives = [];
    return createMenuReal($menus, $actives, 0);
}

function Crumbs($menus, $uri)
{
    $actives = [];
    CheckActive($menus, $actives, $uri);
    $ret = '';
    foreach ($actives as $k => $v) {
        if ($k == count($actives) - 1) {
            $ret .= '<li class="active"><a>' . $menus[$actives[0]]->childs[$actives[1]]->title . '</a></li>';
        } else {
            $ret .= '<li><a href="#">' . $menus[$actives[0]]->title . '</a></li>';
        }
    }
    return $ret;
}

Joneq's avatar
新增通知管理-完成通知管理的基本页面开发
bce5ae4f
 
Joneq committed 2 years ago
94 95 96
//TODO 上线之后去除注释这个notice ,5。0版本的缺陷 https://blog.csdn.net/weixin_44251615/article/details/93710829
ini_set("error_reporting","E_ALL & ~E_NOTICE");

李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
97 98 99 100 101 102 103 104
class MessageController extends Controller
{
    private function templateData(Request $request, $id, $viewid)
    {
        $uri = '/' . $request->path();
        $paths = [["title" => "消息管理系统", "href" => '/database/']];
        $username = $request->user->email;
        $useremail = $request->user->email;
李洋's avatar
配置调整
d44c7c60
 
李洋 committed 7 years ago
105
        $menuconfig = DB::table('config')->where('config_id', $this->getConfigId())->first();
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
        $menus = [];
        if ($menuconfig && !($menus = json_decode($menuconfig->config_data)))
            $menus = [];


        $referer = $this->get_referer($request);
        $data = [
            'id' => $id,
            'title' => '消息管理系统',
            'header' => $request->user->header,
            'uri' => $uri,
            'paths' => $paths,
            'username' => $username,
            'useremail' => $useremail,
            'menus' => $menus,
            'options' => '[]',
            'referer' => $referer,
        ];
        return view($viewid, $data);
    }

    public function index(Request $request)
    {
        $uri = '/' . $request->path();
        $paths = [["title" => "首页", "href" => '/database/']];
        $username = $request->user->email;
        $useremail = $request->user->email;
李洋's avatar
配置调整
d44c7c60
 
李洋 committed 7 years ago
133
        $menuconfig = DB::table('config')->where('config_id', $this->getConfigId())->first();
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
        $menus = [];
        if ($menuconfig && !($menus = json_decode($menuconfig->config_data)))
            $menus = [];


        $referer = $this->get_referer($request);
        $data = [
            'header' => $request->user->header,
            'uri' => $uri,
            'paths' => $paths,
            'username' => $username,
            'useremail' => $useremail,
            'menus' => $menus,
            'options' => '[]',
            'referer' => $referer,
        ];
        return view('index', $data);
    }

    public function message(Request $request, $id = 0)
    {
        return $this->templateData($request, $id, 'message');
    }

    public function info(Request $request, $id = 0)
    {
        return $this->$id($request, $id, 'common');
    }

    public function get_referer($request)
    {
        // echo $request->headers->get('referer') . "\n";
        $pos = strpos($request->headers->get('referer'), 'info');
        $referer = 0;
        if ($pos === false)
            $referer = 0;
        else
            $referer = 1;
        // echo "referer:" . $referer . "\n";
        return $referer;
    }


    //-------------------------------模块-------------------------------

    // 消息模板列表
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
180
    private function templatelist(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
181
    {
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
182 183 184 185 186 187 188
        //获取权限
        $perms_arr = ['template_check','template_create','template_edit'];
        $res_perm = $this->getUserPerms($request,$perms_arr);
        $template_check = $res_perm['template_check'];
        $template_create = $res_perm['template_create'];
        $template_edit = $res_perm['template_edit'];

李洋's avatar
消息模板改版 包括列表页 和 新增/编辑页
915e5bdd
 
李洋 committed 6 years ago
189 190 191 192
        $conditions = $request->input();
        $info = [];
        $db = DB::connection('message');
        if (!empty($conditions['page']) && !empty($conditions['limit'])){
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
193 194
            $info = $db->table('lie_msg_tpl as mt')->select('mt.tpl_id', 'mt.channels', 'mt.description', 'mt.ex_str', 'mc.cls_id', 'mc.name', 'mc.depth', 'mc.id_path', 'mc.parent_id', 'mc.parent_name')
                ->leftjoin('lie_msg_classify as mc','mc.cls_id','=','mt.cls_id')
李洋's avatar
消息模板改版 包括列表页 和 新增/编辑页
915e5bdd
 
李洋 committed 6 years ago
195 196 197 198 199 200 201
                ->where(function($query) use($conditions){
                    if (!empty($conditions['msg_key'])){
                        $query->where('mt.description','like','%'.$conditions['msg_key'].'%');
                    }
                    if (!empty($conditions['msg_channel'])){
                        $query->where('mt.channels','like','%'.$conditions['msg_channel'].'%');
                    }
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
202 203
                    if (!empty($conditions['msg_cls'])){
                        $query->where('mc.parent_id',$conditions['msg_cls']);
李洋's avatar
消息模板改版 包括列表页 和 新增/编辑页
915e5bdd
 
李洋 committed 6 years ago
204
                    }
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
205 206
                    if (!empty($conditions['msg_sub_cls'])){
                        $query->where('mc.cls_id',$conditions['msg_sub_cls']);
李洋's avatar
消息模板改版 包括列表页 和 新增/编辑页
915e5bdd
 
李洋 committed 6 years ago
207
                    }
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
208 209
//                    $query->where('mc.depth', 3);
                    $query->where('mt.status', 0);
李洋's avatar
消息模板改版 包括列表页 和 新增/编辑页
915e5bdd
 
李洋 committed 6 years ago
210 211 212 213 214 215 216
                })
                ->where('source_type',1)
                ->orderby('tpl_id','desc')
                ->paginate($conditions['limit'],['*'],'page',$conditions['page'])->toArray();

            foreach ($info['data'] as &$item){
                $item = objectToArray($item);
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
217 218
                $item['cls_name'] = !empty($item['parent_name'])?$item['parent_name']:'' ;
                $item['sub_cls_name'] = !empty($item['name'])?$item['name']:'' ;
李洋's avatar
消息模板改版 包括列表页 和 新增/编辑页
915e5bdd
 
李洋 committed 6 years ago
219
                $item['show_channels_str'] = $this->changeNumberStrToChineseStr(['站内信','短信','邮箱','微信通知','钉钉消息'],$item['channels']);
李洋's avatar
完成除了所有消息列表的搜索功能
8da67cd9
 
李洋 committed 7 years ago
220
            }
李洋's avatar
消息模板改版 包括列表页 和 新增/编辑页
915e5bdd
 
李洋 committed 6 years ago
221 222
            unset($item);
            return json_encode(['code'=>0,'count'=>$info['total'],'msg'=>'success','data'=>$info['data']]);
李洋's avatar
完成除了所有消息列表的搜索功能
8da67cd9
 
李洋 committed 7 years ago
223
        }
李洋's avatar
所有历史消息
21e6707a
 
李洋 committed 6 years ago
224

李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
225 226
        //消息模板一级分类
        $clses = $this->getClassify($db);
孙龙's avatar
优化后台
1ad003fd
 
孙龙 committed 6 years ago
227

李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
228 229 230 231
        $data=[
            'title'=>'asd',
            'id'=>$id,
            'info'=>$info,
李洋's avatar
消息模板改版 包括列表页 和 新增/编辑页
915e5bdd
 
李洋 committed 6 years ago
232
            'clses'=>$clses,
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
233 234 235 236

            'template_check'=>$template_check,
            'template_create'=>$template_create,
            'template_edit'=>$template_edit
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
237 238 239 240 241
        ];
        return view($viewid, $data);
    }

    // 人工发送历史消息列表
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
242
    private function manualhistorylist(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
243 244
    {
        Csrf($request);
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
245 246 247 248 249 250 251
        //获取权限
        $perms_arr = ['manualhistorylist_check','manualmessage_edit','manualmessage_send'];
        $res_perm = $this->getUserPerms($request,$perms_arr);
        $manualhistorylist_check = $res_perm['manualhistorylist_check'];
        $manualmessage_edit = $res_perm['manualmessage_edit'];
        $manualmessage_send = $res_perm['manualmessage_send'];

李洋's avatar
11
dc0254a5
 
李洋 committed 6 years ago
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
        $conditions = $request->input();
        if(!empty($conditions['page']) && !empty($conditions['limit'])){
            $items = DB::connection('message')->table('lie_msg_log as ml')
                ->leftjoin('lie_msg_tpl as mt','ml.tpl_id','=','mt.tpl_id')
                ->select('ml.log_id','ml.title','mt.description','ml.channel_type','ml.actual_send_time','ml.obj_user')
                ->where(function($query) use($conditions){
                    if(!empty($conditions['msg_tpl_description']))
                    {
                        $query->where('mt.description','like','%'.$conditions['msg_tpl_description'].'%');
                    }
                    if(!empty($conditions['start_time']))
                    {
                        $query->where('ml.actual_send_time','>=',strtotime($conditions['start_time']));
                    }
                    if(!empty($conditions['end_time']))
                    {
                        $query->where('ml.actual_send_time','<=',strtotime($conditions['end_time'])+86400);
                    }
                    if(!empty($conditions['msg_channels']))
                    {
                        $query->where('ml.channel_type',$conditions['msg_channels']);
                    }
                })
                ->groupBy('mt.tpl_id')
                ->orderBy('ml.log_id','desc')
                ->paginate($conditions['limit'],['*'],'page',$conditions['page'])->toArray();
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
278

李洋's avatar
11
dc0254a5
 
李洋 committed 6 years ago
279 280 281 282
            foreach ($items['data'] as &$item){
                $item = objectToArray($item);
                $item['actual_send_time_str'] = !empty($item['actual_send_time'])?Carbon::createFromTimestamp(strval($item['actual_send_time']))->toDateTimeString():'';
                $item['channel_type_str'] = Config('msgconfig.msg_channels')[$item['channel_type']];
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
283
            }
李洋's avatar
11
dc0254a5
 
李洋 committed 6 years ago
284 285
            unset($item);
            return json_encode(['code'=>0,'count'=>$items['total'],'msg'=>'success','data'=>$items['data']]);
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
286 287 288 289 290
        }

        $data=[
            'title'=>'asd',
            'id'=>$id,
李洋's avatar
11
dc0254a5
 
李洋 committed 6 years ago
291
            'info'=>[],
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
292 293 294 295

            'manualhistorylist_check'=>$manualhistorylist_check,
            'manualmessage_edit'=>$manualmessage_edit,
            'manualmessage_send'=>$manualmessage_send
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
296 297 298 299 300 301
        ];

        return view($viewid, $data);
    }

    // 所有历史消息
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
302
    private function allhistorylist(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
303
    {
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
304 305 306 307
        $perms_arr = ['allhistorylist_check'];
        $res_perm = $this->getUserPerms($request,$perms_arr);
        $allhistorylist_check = $res_perm['allhistorylist_check'];

李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
308
        $db = DB::connection('message');
李洋's avatar
全部历史消息 改版
f9f4dc87
 
李洋 committed 6 years ago
309 310
        $conditions = $request->input();
        if(!empty($conditions['page']) && !empty($conditions['limit'])){
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
311
            $items = $db->table('lie_msg_log as ml')
李洋's avatar
全部历史消息 改版
f9f4dc87
 
李洋 committed 6 years ago
312
                ->leftjoin('lie_msg_tpl as mt','ml.tpl_id','=','mt.tpl_id')
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
313 314
                ->leftjoin('lie_msg_classify as mc','mc.cls_id','=','mt.cls_id')
                ->select('ml.log_id','ml.status','ml.obj_user','ml.source_type','ml.tpl_id','ml.channel_type','ml.create_time','ml.expect_send_time','ml.actual_send_time','ml.title','ml.content','ml.wechat_tpl_id','mt.ex_str','mc.name','mc.parent_id','mc.depth','mc.parent_name','mc.cls_id')
李洋's avatar
全部历史消息 改版
f9f4dc87
 
李洋 committed 6 years ago
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
                ->where(function($query) use($conditions){
                    if(!empty($conditions['msg_tpl_desc']))
                    {
                        $query->where('mt.ex_str','like','%'.$conditions['msg_tpl_desc'].'%');
                    }
                    if(!empty($conditions['start_time']))
                    {
                        $query->where('ml.actual_send_time','>=',strtotime($conditions['start_time']));
                    }
                    if(!empty($conditions['end_time']))
                    {
                        $query->where('ml.actual_send_time','<=',strtotime($conditions['end_time'])+86400);
                    }
                    if(!empty($conditions['user_account']))
                    {
                        $query->where('ml.obj_user','like','%'.$conditions['user_account'].'%');
                    }
                    if(!empty($conditions['msg_channels']))
                    {
                        $query->where('ml.channel_type',$conditions['msg_channels']);
                    }
                    if(!empty($conditions['msg_status']))
                    {
                        $query->where('ml.status',$conditions['msg_status']);
                    }
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
340 341
                    if (!empty($conditions['msg_cls'])){
                        $query->where('mc.parent_id',$conditions['msg_cls']);
李洋's avatar
所有历史消息
21e6707a
 
李洋 committed 6 years ago
342
                    }
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
343 344
                    if (!empty($conditions['msg_sub_cls'])){
                        $query->where('mc.cls_id',$conditions['msg_sub_cls']);
李洋's avatar
所有历史消息
21e6707a
 
李洋 committed 6 years ago
345
                    }
李洋's avatar
11
dc0254a5
 
李洋 committed 6 years ago
346 347 348
                })
//                ->groupBy('ml.log_id')  //todo:这里要改一下  想下怎么改   用mysql作groupby+分页
                ->orderBy('ml.log_id','desc')
李洋's avatar
全部历史消息 改版
f9f4dc87
 
李洋 committed 6 years ago
349 350 351 352 353 354 355 356 357
                ->paginate($conditions['limit'],['*'],'page',$conditions['page'])->toArray();

            foreach ($items['data'] as &$item){
                $item = objectToArray($item);
                $item['create_time_str'] = !empty($item['create_time'])?Carbon::createFromTimestamp(strval($item['create_time']))->toDateTimeString():'';
                $item['actual_send_time_str'] = !empty($item['actual_send_time'])?Carbon::createFromTimestamp(strval($item['actual_send_time']))->toDateTimeString():'';
                $item['status_str'] = Config('msgconfig.msg_status')[$item['status']];
                $item['channel_type_str'] = Config('msgconfig.msg_channels')[$item['channel_type']];
                $item['msg_tpl_str'] = $item['ex_str'];
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
358 359
                $item['cls_name'] = !empty($item['parent_name'])?$item['parent_name']:'' ;
                $item['sub_cls_name'] = !empty($item['name'])?$item['name']:'' ;
李洋's avatar
完成搜索
42bcfda6
 
李洋 committed 7 years ago
360
            }
李洋's avatar
全部历史消息 改版
f9f4dc87
 
李洋 committed 6 years ago
361 362
            unset($item);
            return json_encode(['code'=>0,'count'=>$items['total'],'msg'=>'success','data'=>$items['data']]);
李洋's avatar
完成搜索
42bcfda6
 
李洋 committed 7 years ago
363 364
        }

李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
365 366
        //消息模板一级分类
        $clses = $this->getClassify($db);
李洋's avatar
所有历史消息
21e6707a
 
李洋 committed 6 years ago
367

李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
368 369 370
        $data=[
            'title'=>'asd',
            'id'=>$id,
李洋's avatar
全部历史消息 改版
f9f4dc87
 
李洋 committed 6 years ago
371
            'info'=>[],
李洋's avatar
所有历史消息
21e6707a
 
李洋 committed 6 years ago
372
            'clses'=>$clses,
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
373 374

            'allhistorylist_check'=>$allhistorylist_check
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
375 376 377 378 379 380
        ];

        return view($viewid, $data);
    }

    // 新增编辑消息模板
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
381
    private function addtemplate(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
382
    {
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
383 384 385 386
        $perms_arr = ['template_create'];
        $res_perm = $this->getUserPerms($request,$perms_arr);
        $template_create = $res_perm['template_create'];

李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
387 388
        $rq_tpl_id = $request->input('tpl_id');
        $db = DB::connection('message');
李洋's avatar
添加消息模板类别
4260a4a7
 
李洋 committed 6 years ago
389 390

        //消息模板一级分类
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
391
        $msg_tpl_clses = $this->getClassify($db);
李洋's avatar
添加消息模板类别
4260a4a7
 
李洋 committed 6 years ago
392 393 394

        //消息模板二级分类
        $msg_tpl_sub_clses = [];
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
395 396

        if(!empty($rq_tpl_id))
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
397
        {
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
398
            //通过tpl_id找到模板的渠道们 和 描述等
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
399 400
            $info = $db->table('lie_msg_tpl as mt')->select('mt.tpl_id','mt.description','mt.channels','mt.msg_type','mt.creater','mt.source_type','mt.obj_user','mt.ex_str','mc.parent_id','mc.parent_name','mc.cls_id','mc.name')
                ->leftjoin('lie_msg_classify as mc','mt.cls_id','=','mc.cls_id')
李洋's avatar
添加消息模板类别
4260a4a7
 
李洋 committed 6 years ago
401 402 403 404
                ->where('tpl_id',$rq_tpl_id)->first();

            //获取消息模板二级分类
            if (!empty($info->cls_id)){
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
405 406
                $msg_tpl_sub_cls = $db->table('lie_msg_classify')->select('cls_id','name')
                    ->where('parent_id',$info->parent_id)->get();
李洋's avatar
添加消息模板类别
4260a4a7
 
李洋 committed 6 years ago
407
                foreach ($msg_tpl_sub_cls as $k=>$v){
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
408
                    $msg_tpl_sub_clses[$v->cls_id] = $v->name;
李洋's avatar
添加消息模板类别
4260a4a7
 
李洋 committed 6 years ago
409 410
                }
            }
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
411 412 413 414 415 416
            //通过找到的 channels 去渠道模板表里 把每个channel找出来
            $tpl_channels_arr = explode(',',$info->channels);
            $channel_tpls = [];
            foreach ($tpl_channels_arr as $channel_type)
            {
                $channel_tpl_obj = $db->table('lie_msg_channel_tpl')->where('tpl_id',$info->tpl_id)->where('channel_type',$channel_type)->first();
李洋's avatar
微信
86ebc545
 
李洋 committed 7 years ago
417

李洋's avatar
update api
fc0928a2
 
李洋 committed 7 years ago
418 419 420 421 422 423 424 425 426 427 428 429 430
                //将channel_tpl_id赋给正确的变量中
                if($channel_type==1)
                {
                    $inner_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
                }elseif($channel_type==2)
                {
                    $sms_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
                }elseif($channel_type==3)
                {
                    $email_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
                }elseif($channel_type==4)
                {
                    $wechatNotify_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
李洋's avatar
微信
86ebc545
 
李洋 committed 7 years ago
431 432
                    //将head 和 tail从content中解析出来
                    $channel_tpl_obj->content = json_decode($channel_tpl_obj->content,true);
李洋's avatar
1111
964b032b
 
李洋 committed 7 years ago
433 434
                }else{
                    $ding_chn_tpl_id = $channel_tpl_obj->channel_tpl_id;
李洋's avatar
update api
fc0928a2
 
李洋 committed 7 years ago
435
                }
李洋's avatar
微信
86ebc545
 
李洋 committed 7 years ago
436
                $channel_tpls[$channel_type] = $channel_tpl_obj;
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
437 438 439 440
            }
            $info->channel_tpls = $channel_tpls;
        }

李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
441 442 443
        $data=[
            'title'=>'asd',
            'id'=>$id,
李洋's avatar
添加消息模板类别
4260a4a7
 
李洋 committed 6 years ago
444 445 446 447 448 449 450 451 452 453
            'info'=>!empty($info)?$info:(object)null,
            'inner_chn_tpl_id'=>!empty($inner_chn_tpl_id)?$inner_chn_tpl_id:'',
            'sms_chn_tpl_id'=>!empty($sms_chn_tpl_id)?$sms_chn_tpl_id:'',
            'email_chn_tpl_id'=>!empty($email_chn_tpl_id)?$email_chn_tpl_id:'',
            'wechatNotify_chn_tpl_id'=>!empty($wechatNotify_chn_tpl_id)?$wechatNotify_chn_tpl_id:'',
            'ding_chn_tpl_id'=>!empty($ding_chn_tpl_id)?$ding_chn_tpl_id:'',
            'tpl_channels_arr'=>!empty($tpl_channels_arr)?$tpl_channels_arr:[],
            'template_create' => $template_create,
            'msg_tpl_clses'=>$msg_tpl_clses,
            'msg_tpl_sub_clses'=>$msg_tpl_sub_clses
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
454 455 456 457 458 459
        ];

        return view($viewid, $data);
    }

    // 添加手动发送消息(会创建模板)
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
460
    private function sendmanualmessage(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
461 462
    {
        Csrf($request);
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
463 464 465 466 467

        $perms_arr = ['manualmessage_send'];
        $res_perm = $this->getUserPerms($request,$perms_arr);
        $manualmessage_send = $res_perm['manualmessage_send'];

李洋's avatar
1、列表添加查看操作
b36bbb3a
 
李洋 committed 7 years ago
468 469 470 471 472 473 474 475 476
        //为所有历史消息的操作类型赋值
        $op_type = '';
        if(empty($request['op_type']))
        {
            $op_type = 2;
        }else
        {
            $op_type = $request['op_type'];
        }
李洋's avatar
update code
90eb7c01
 
李洋 committed 7 years ago
477 478 479
        $rq_log_id = $request->input('log_id');
        //发送人工消息改变了模板的选择时会传过来tpl_id
        $rq_tpl_id = $request->input('tpl_id');
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
480
        $db = DB::connection('message');
李洋's avatar
update code
51d18a21
 
李洋 committed 7 years ago
481 482 483 484
        $isContainInner = '';
        $isContainSMS = '';
        $isContainEmail = '';
        $isContainWechatNotify = '';
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
485

李洋's avatar
update code
90eb7c01
 
李洋 committed 7 years ago
486 487
        //编辑时传过来log_id  选择模板时传过来tpl_id
        if(!empty($rq_log_id) || !empty($rq_tpl_id))
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
488
        {
李洋's avatar
update code
90eb7c01
 
李洋 committed 7 years ago
489 490 491 492 493 494 495 496 497 498
            //1.编辑
            if(!empty($rq_log_id))
            {
                $log_id = $rq_log_id;
                $info = $db->table('lie_msg_log')->select('tpl_id','obj_user','expect_send_time')->where('log_id',$log_id)->first();
            }else//2.选择模板
            {
                $info = (object)null;
                $info->tpl_id = $rq_tpl_id;
                $info->obj_user = '';
李洋's avatar
手动发消息接口联调
cfe21d14
 
李洋 committed 7 years ago
499
                $info->expect_send_time = '';
李洋's avatar
update code
90eb7c01
 
李洋 committed 7 years ago
500
            }
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
501 502

            //通过tpl_id找到模板的渠道们 和 描述
孙龙's avatar
批量上传 导入发送消息 邮件
88f7fb89
 
孙龙 committed 6 years ago
503
            $desc_and_channels = $db->table('lie_msg_tpl')->select('description','ex_str','channels','msg_type',"cls_id")->where('tpl_id',$info->tpl_id)->first();
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
504
            $info->desc = $desc_and_channels->description;
李洋's avatar
1、消息描述加中文
ec3a2067
 
李洋 committed 7 years ago
505
            $info->ex_str = $desc_and_channels->ex_str;
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
506 507 508 509 510 511 512 513 514 515
            $info->channels_str = $this->changeNumberStrToChineseStr(['站内信','短信','邮箱','微信通知'],$desc_and_channels->channels);
            $info->channels = $desc_and_channels->channels;
            $info->msg_type = $desc_and_channels->msg_type;

            //通过找到的 channels 去渠道模板表里 把每个channel找出来
            $tpl_channels_arr = explode(',',$info->channels);
            $channel_tpls = [];
            foreach ($tpl_channels_arr as $channel_type)
            {
                $channel_tpl_obj = $db->table('lie_msg_channel_tpl')->where('tpl_id',$info->tpl_id)->where('channel_type',$channel_type)->first();
李洋's avatar
微信
86ebc545
 
李洋 committed 7 years ago
516 517 518 519 520
                if($channel_type==4)
                {
                    //将head 和 tail从content中解析出来
                    $channel_tpl_obj->content = json_decode($channel_tpl_obj->content,true);
                }
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
521 522 523
                $channel_tpls[$channel_type] = $channel_tpl_obj;
            }
            $info->channel_tpls = $channel_tpls;
李洋's avatar
update code
51d18a21
 
李洋 committed 7 years ago
524

孙龙's avatar
批量上传 导入发送消息 邮件
88f7fb89
 
孙龙 committed 6 years ago
525 526 527 528 529
            if($desc_and_channels->cls_id){
                $msg_class = $db->table('lie_msg_classify')->where("cls_id",$desc_and_channels->cls_id)->first();
                if($msg_class) $info->msg_class = $msg_class;
            }

李洋's avatar
update code
51d18a21
 
李洋 committed 7 years ago
530 531 532 533 534
            //判断包含的消息渠道(用于展示消息渠道)(利用之前分割字符串得到的数组)
            $isContainInner = in_array('1',$tpl_channels_arr);
            $isContainSMS = in_array('2',$tpl_channels_arr);
            $isContainEmail = in_array('3',$tpl_channels_arr);
            $isContainWechatNotify = in_array('4',$tpl_channels_arr);
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
535 536
        }

李洋's avatar
update code
51d18a21
 
李洋 committed 7 years ago
537
        //找出所有模板(给选择模板用)
孙龙's avatar
批量上传 导入发送消息 邮件
88f7fb89
 
孙龙 committed 6 years ago
538
        $all_msg_tpl = $db->table('lie_msg_tpl')->select('tpl_id','ex_str','description')->orderBy("tpl_id","desc")->get();
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
539 540 541 542 543 544 545 546 547

        if(empty($info))
        {
            $info = (object)null;
            $info->tpl_id = '';
            $info->obj_user = '';
            $info->actual_send_time = '';
            $info->expect_send_time = '';
            $info->desc = '';
李洋's avatar
1、消息描述加中文
ec3a2067
 
李洋 committed 7 years ago
548
            $info->ex_str = '';
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
            $info->channels_str = '';
            $info->channels ='';
            $info->channel_tpls = [];
            $info->msg_type = '';
        }

        //消息类型枚举
        $msg_type = [
            '请选择',
            '公告',
            '活动',
            '新闻',
            '其他'
        ];

        $data=[
            'title'=>'asd',
            'id'=>$id,
            'info'=>$info,
            'msg_type'=>$msg_type,
李洋's avatar
update code
51d18a21
 
李洋 committed 7 years ago
569 570 571 572 573
            'all_msg_tpl'=>$all_msg_tpl,
            'isContainInner'=>$isContainInner,
            'isContainSMS'=>$isContainSMS,
            'isContainEmail'=>$isContainEmail,
            'isContainWechatNotify'=>$isContainWechatNotify,
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
574

李洋's avatar
1、列表添加查看操作
b36bbb3a
 
李洋 committed 7 years ago
575 576
            'manualmessage_send'=>$manualmessage_send,
            'op_type'=>$op_type
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
577 578 579 580
        ];
        return view($viewid, $data);
    }

李洋's avatar
添加 新增/编辑 消息模板分类功能
9438ddbd
 
李洋 committed 6 years ago
581 582 583
    //添加分类
    private function addclassify(Request $request,$id,$viewId){
        $db = DB::connection('message');
李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
584
        $info = $this->getClassify($db);
李洋's avatar
添加 新增/编辑 消息模板分类功能
9438ddbd
 
李洋 committed 6 years ago
585 586 587 588 589 590 591
        $data = [
            'title' => 'asd',
            'id'    => $id,
            'info'  => $info
            ];
        return view($viewId, $data);
    }
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
592

李洋's avatar
消息模板分类
26db6e8a
 
李洋 committed 6 years ago
593 594 595 596 597 598 599 600 601 602 603 604 605
    private function getClassify($db) {
        $info = [];
        $infos = $db->table('lie_msg_classify')->select('cls_id','name')->where('depth',2)->where('status', 1)->get();
        if (!empty($infos)){
            foreach ($infos as &$in){
                $in = objectToArray($in);
                $info[$in['cls_id']] = $in['name'];
            }
            unset($in);
        }
        return $info;
    }

李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
    //--------------------------------------------inner methods-----------------------------------------

    //数字字符串转为对应中文字符串  eg:1,2,3-->站内信,短信,邮件
    /*
     * return: 会返回一个跟传入数字字符串对应的汉字字符串,不对数据源造成影响
     * param 1:对比源:用于作对比及提取汉字
     * param 2:目标数字字符串(默认用','分割)
     */
    private function changeNumberStrToChineseStr($compareArr,$numberStr)
    {
        $chineseStr = '';
        $tpl_channels_arr = explode(',',$numberStr);
        if(count($tpl_channels_arr)>0 && count($compareArr)>0)
        {
            for ($i=0;$i<count($tpl_channels_arr);$i++)
            {
                for($j=0;$j<count($compareArr);$j++)
                {
                    if($tpl_channels_arr[$i]-1==$j)
                    {
                        $chineseStr .= $compareArr[$j].',';
                        break;
                    }
                }
            }
        }
        return $chineseStr;
    }
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
634 635 636 637 638

    private function getUserPerms(Request $request,$perms_arr)
    {
        $perms_str = implode(',',$perms_arr);
        $uid = $request->user->userId;
李洋's avatar
配置调整
d44c7c60
 
李洋 committed 7 years ago
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660

        $bid = "";
        $perm_url = "";

        //区分环境
        $current_domain = $_SERVER['HTTP_HOST'];
        if($current_domain === Config('msgconfig.domain_local'))
        {
            $bid = Config('msgconfig.perm_bid_local');
            $perm_url = Config('msgconfig.perm_domain_local');
        }
        elseif ($current_domain === Config('msgconfig.domain_sz'))
        {
            $bid = Config('msgconfig.perm_bid_sz');
            $perm_url = Config('msgconfig.perm_domain_sz');
        }
        elseif ($current_domain === Config('msgconfig.domain_release'))
        {
            $bid = Config('msgconfig.perm_bid_release');
            $perm_url = Config('msgconfig.perm_domain_release');
        }

李洋's avatar
1、权限系统配置文件
a3d6785e
 
李洋 committed 7 years ago
661
        $url = $perm_url."/api/check/$uid/$bid/?perms=$perms_str";
李洋's avatar
添加权限控制
1fe18552
 
李洋 committed 7 years ago
662 663 664 665 666 667
        $res = json_decode(curl($url),true);
        if(!$res['retcode'])
        {
            return $res['data']['perms'];
        }
    }
李洋's avatar
配置调整
d44c7c60
 
李洋 committed 7 years ago
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686

    //根据当前域名获取config_id
    private function getConfigId()
    {
        $current_domain = $_SERVER['HTTP_HOST'];

        if($current_domain === Config('msgconfig.domain_local'))
        {
            return Config('msgconfig.config_id_local');
        }
        elseif ($current_domain === Config('msgconfig.domain_sz'))
        {
            return Config('msgconfig.config_id_sz');
        }
        elseif ($current_domain === Config('msgconfig.domain_release'))
        {
            return Config('msgconfig.config_id_release');
        }
    }
Joneq's avatar
新增通知管理-完成通知管理的基本页面开发
bce5ae4f
 
Joneq committed 2 years ago
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718



    //----------------------------------------通知管理----------------------------------------//
    // 系统更新管理
    private function systemUpdate(Request $request, $id, $viewid)
    {
        $data=[
            'id'=>$id,
        ];
        return view('common', $data);
    }

    //系统宣讲管理
    private function systemPreaching(Request $request, $id, $viewid)
    {
        $data=[
            'id'=>$id,
        ];
        return view('common', $data);
    }

    //系统公告管理
    private function systemBulletin(Request $request, $id, $viewid)
    {
        $data=[
            'id'=>$id,
        ];
        return view('common', $data);
    }


李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
719
}