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 21.6 KB
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2017/11/22
 * Time: 19:24
 */

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use RedisDB;

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;
}

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;
        $menuconfig = DB::table('config')->where('config_id', 4)->first();
        $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
1111
d4a2163b
 
李洋 committed 7 years ago
127
        $menuconfig = DB::table('config')->where('config_id', 4)->first();
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
128 129 130 131 132 133 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
        $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
176
    private function templatelist(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
177 178
    {
        Csrf($request);
李洋's avatar
完成除了所有消息列表的搜索功能
8da67cd9
 
李洋 committed 7 years ago
179 180
        $search_desc = $request->input('search_desc');
        $search_channel = $request->input('search_channel');
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
181

李洋's avatar
完成除了所有消息列表的搜索功能
8da67cd9
 
李洋 committed 7 years ago
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        $cnt = DB::connection('message');
        //自动发送模板数据
        //1.首次进页面无搜索条件
        if($search_desc==null && $search_channel==null)
        {
            $info = $cnt->table('lie_msg_tpl')->where('source_type','1')->paginate(20);
            $search_channel = 0;
            $search_desc = '';
        }else//2.有搜索条件
        {
            //渠道里没有0,所以如果没选,将此条件剔除掉
            if(0==$search_channel)
            {
                $info = $cnt->table('lie_msg_tpl')->where('source_type','1')->where('description','like',"%$search_desc%")->paginate(20);
            }else
            {
                $info = $cnt->table('lie_msg_tpl')->where('source_type','1')->where('channels','like',"%$search_channel%")->where('description','like',"%$search_desc%")->paginate(20);
            }
        }
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

        //构建model
        foreach ($info as $tpl)
        {
            //将消息渠道从 数字字符串转化为汉字字符串 用于用户展示
            $tpl->show_channels_str = $this->changeNumberStrToChineseStr(['站内信','短信','邮箱','微信通知'],$tpl->channels);

            //取出渠道站内信和邮件title 放到info中
            $inner_title = $cnt->table('lie_msg_channel_tpl')->select('title')
                ->where('tpl_id',$tpl->tpl_id)->where('channel_type',1)->first();
            $email_title = $cnt->table('lie_msg_channel_tpl')->select('title')
                ->where('tpl_id',$tpl->tpl_id)->where('channel_type',3)->first();
            $tpl->title = '-';
            if(!empty($inner_title->title))
            {
                $tpl->title = $inner_title->title;
            }else if(!empty($email_title->title))
            {
                $tpl->title = $email_title->title;
            }
        }
李洋's avatar
列条添加分页、添加搜索
a97ffbb4
 
李洋 committed 7 years ago
222 223 224 225 226 227 228
        $msg_channels=[
            '全部',
            '站内信',
            '短信',
            '邮件',
            '微信通知'
        ];
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
229 230 231 232
        $data=[
            'title'=>'asd',
            'id'=>$id,
            'info'=>$info,
李洋's avatar
列条添加分页、添加搜索
a97ffbb4
 
李洋 committed 7 years ago
233
            'msg_channels'=>$msg_channels,
李洋's avatar
完成除了所有消息列表的搜索功能
8da67cd9
 
李洋 committed 7 years ago
234 235
            'search_desc'=>$search_desc,
            'search_channel'=>$search_channel,
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
236 237 238 239 240
        ];
        return view($viewid, $data);
    }

    // 人工发送历史消息列表
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
241
    private function manualhistorylist(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
242 243
    {
        Csrf($request);
李洋's avatar
完成除了所有消息列表的搜索功能
8da67cd9
 
李洋 committed 7 years ago
244 245 246 247 248
        //搜索条件
        $search_desc = $request->input('search_desc');
        $search_channel = $request->input('search_channel');
        $search_sendtime = $request->input('search_sendtime');

李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
249
        $db = DB::connection('message');
李洋's avatar
完成除了所有消息列表的搜索功能
8da67cd9
 
李洋 committed 7 years ago
250 251 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
        //1.首次进页面无搜索条件
        if(null==$search_desc && null==$search_channel && null==$search_sendtime)
        {
            $info = $db->table('lie_msg_log')->groupBy('tpl_id')->having('source_type','=',2)->get();
            $search_channel = 0;
            $search_desc = '';
            $search_sendtime = '';
        }else//2.有搜索条件
        {
            //渠道里没有0,所以如果没选,将此条件剔除掉
            if(0==$search_channel)
            {
                $info = $db->table('lie_msg_log')->groupBy('lie_msg_log.tpl_id')->having('lie_msg_log.source_type','=',2)
                    ->where('lie_msg_log.expect_send_time',$search_sendtime)
                    ->join('lie_msg_tpl','lie_msg_log.tpl_id','=','lie_msg_tpl.tpl_id')
                    ->where('lie_msg_tpl.description','like',"%$search_desc%")->get();
            }else
            {
                $info = $db->table('lie_msg_log')->groupBy('lie_msg_log.tpl_id')->having('lie_msg_log.source_type','=',2)
                    ->join('lie_msg_tpl','lie_msg_log.tpl_id','=','lie_msg_tpl.tpl_id')
                    ->where('lie_msg_log.expect_send_time',$search_sendtime)
                    ->where('lie_msg_tpl.channels','like',"%$search_channel%")
                    ->where('lie_msg_tpl.description','like',"%$search_desc%")->get();
            }
        }

        //构建model
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
        foreach ($info as $log)
        {
            //将消息渠道从 数字字符串转化为汉字字符串 用于用户展示
            $find_tpl = $db->table('lie_msg_tpl')->where('tpl_id',$log->tpl_id)->first();
            $log->channels_str = $this->changeNumberStrToChineseStr(['站内信','短信','邮箱','微信通知'],$find_tpl->channels);
            $log->description = $find_tpl->description;

            //取出渠道站内信和邮件title 放到info中
            $inner_title = $db->table('lie_msg_channel_tpl')->select('title')
                ->where('tpl_id',$log->tpl_id)->where('channel_type',1)->first();
            $email_title = $db->table('lie_msg_channel_tpl')->select('title')
                ->where('tpl_id',$log->tpl_id)->where('channel_type',3)->first();
            $log->title = '-';
            if(!empty($inner_title->title))
            {
                $log->title = $inner_title->title;
            }else if(!empty($email_title->title))
            {
                $log->title = $email_title->title;
            }
        }

李洋's avatar
列条添加分页、添加搜索
a97ffbb4
 
李洋 committed 7 years ago
299 300 301 302 303 304 305
        $msg_channels=[
            '全部',
            '站内信',
            '短信',
            '邮件',
            '微信通知'
        ];
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
306 307 308 309

        $data=[
            'title'=>'asd',
            'id'=>$id,
李洋's avatar
列条添加分页、添加搜索
a97ffbb4
 
李洋 committed 7 years ago
310 311
            'info'=>$info,
            'msg_channels'=>$msg_channels,
李洋's avatar
完成除了所有消息列表的搜索功能
8da67cd9
 
李洋 committed 7 years ago
312 313 314
            'search_desc'=>$search_desc,
            'search_channel'=>$search_channel,
            'search_sendtime'=>$search_sendtime,
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
315 316 317 318 319 320
        ];

        return view($viewid, $data);
    }

    // 所有历史消息
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
321
    private function allhistorylist(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
322 323
    {
        Csrf($request);
李洋's avatar
完成搜索
42bcfda6
 
李洋 committed 7 years ago
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
        //搜索条件
        $search_id = $request->input('search_id');
        $search_user = $request->input('search_user');
        $search_sendtime = $request->input('search_sendtime');
        $search_channel = $request->input('search_channel');
        $search_status = $request->input('search_status');

        $db = DB::connection('message');
        if($search_id==null && $search_user==null && $search_sendtime==null && $search_channel==null && $search_status==null)
        {
            $info = $db->table('lie_msg_log')->paginate(20);
            $search_id = '';
            $search_user = '';
            $search_sendtime = '';
            $search_channel = 0;
            $search_status = 0;
        }else
        {
            //select option是否为0,为0则不查
            if($search_channel==0 && $search_status!=0)
            {
                $info = $db->table('lie_msg_log')
                    ->where('log_id','like',"%$search_id%")->where('obj_user','like',"%$search_user%")
                    ->where('expect_send_time',$search_sendtime)
                    ->where('status',$search_status)->paginate(20);
            }elseif($search_channel!=0 && $search_status==0)
            {
                $info = $db->table('lie_msg_log')
                    ->where('log_id','like',"%$search_id%")->where('obj_user','like',"%$search_user%")
                    ->where('expect_send_time',$search_sendtime)->where('channel_type',$search_channel)
                    ->paginate(20);
            }elseif($search_channel==0 && $search_status==0)
            {
                $info = $db->table('lie_msg_log')
                    ->where('log_id','like',"%$search_id%")->where('obj_user','like',"%$search_user%")
                    ->where('expect_send_time',$search_sendtime)->paginate(20);
            }else
            {
                $info = $db->table('lie_msg_log')
                    ->where('log_id','like',"%$search_id%")->where('obj_user','like',"%$search_user%")
                    ->where('expect_send_time',$search_sendtime)->where('channel_type',$search_channel)
                    ->where('status',$search_status)->paginate(20);
            }
        }

李洋's avatar
列条添加分页、添加搜索
a97ffbb4
 
李洋 committed 7 years ago
369 370 371 372 373 374 375
        $msg_channels = [
            '全部',
            '站内信',
            '短信',
            '邮件',
            '微信通知'
        ];
李洋's avatar
完成搜索
42bcfda6
 
李洋 committed 7 years ago
376

李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
377 378 379
        $data=[
            'title'=>'asd',
            'id'=>$id,
李洋's avatar
列条添加分页、添加搜索
a97ffbb4
 
李洋 committed 7 years ago
380
            'info'=>$info,
李洋's avatar
完成搜索
42bcfda6
 
李洋 committed 7 years ago
381 382 383 384 385 386
            'msg_channels'=>$msg_channels,
            'search_id'=>$search_id,
            'search_user'=>$search_user,
            'search_sendtime'=>$search_sendtime,
            'search_channel'=>$search_channel,
            'search_status'=>$search_status,
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
387 388 389 390 391 392
        ];

        return view($viewid, $data);
    }

    // 新增编辑消息模板
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
393
    private function addtemplate(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
394 395
    {
        Csrf($request);
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
396 397
        $rq_tpl_id = $request->input('tpl_id');
        $db = DB::connection('message');
李洋's avatar
update api
fc0928a2
 
李洋 committed 7 years ago
398
        //是否包含某一渠道
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
399 400 401 402
        $isContainInner = '';
        $isContainSMS = '';
        $isContainEmail = '';
        $isContainWechatNotify = '';
李洋's avatar
update api
fc0928a2
 
李洋 committed 7 years ago
403 404 405 406 407
        //渠道模板id
        $inner_chn_tpl_id = '';
        $sms_chn_tpl_id = '';
        $email_chn_tpl_id = '';
        $wechatNotify_chn_tpl_id = '';
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
408 409

        if(!empty($rq_tpl_id))
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
410
        {
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
411
            //通过tpl_id找到模板的渠道们 和 描述等
李洋's avatar
update api
fc0928a2
 
李洋 committed 7 years ago
412
            $info = $db->table('lie_msg_tpl')->select('tpl_id','description','channels','msg_type','creater')->where('tpl_id',$rq_tpl_id)->first();
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
413

李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
414 415 416 417 418 419 420
            //通过找到的 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();
                $channel_tpls[$channel_type] = $channel_tpl_obj;
李洋's avatar
update api
fc0928a2
 
李洋 committed 7 years ago
421 422 423 424 425 426 427 428 429 430 431 432 433 434
                //将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
update code
3678e212
 
李洋 committed 7 years ago
435 436 437 438 439 440 441 442
            }
            $info->channel_tpls = $channel_tpls;

            //判断包含的消息渠道(用于展示消息渠道)(利用之前分割字符串得到的数组)
            $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
443
        }
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
444 445 446 447 448 449 450 451 452

        if(empty($info))
        {
            $info = (object)null;
            $info->tpl_id = '';
            $info->description = '';
            $info->channels ='';
            $info->channel_tpls = [];
            $info->msg_type = '';
李洋's avatar
update api
fc0928a2
 
李洋 committed 7 years ago
453
            $info->creater = '';
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
454 455 456 457 458 459 460 461 462 463 464
        }

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

李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
465 466 467
        $data=[
            'title'=>'asd',
            'id'=>$id,
李洋's avatar
update code
3678e212
 
李洋 committed 7 years ago
468 469 470 471 472 473
            'info'=>$info,
            'msg_type'=>$msg_type,
            'isContainInner'=>$isContainInner,
            'isContainSMS'=>$isContainSMS,
            'isContainEmail'=>$isContainEmail,
            'isContainWechatNotify'=>$isContainWechatNotify,
李洋's avatar
update api
fc0928a2
 
李洋 committed 7 years ago
474 475 476 477
            'inner_chn_tpl_id'=>$inner_chn_tpl_id,
            'sms_chn_tpl_id'=>$sms_chn_tpl_id,
            'email_chn_tpl_id'=>$email_chn_tpl_id,
            'wechatNotify_chn_tpl_id'=>$wechatNotify_chn_tpl_id,
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
478 479 480 481 482 483
        ];

        return view($viewid, $data);
    }

    // 添加手动发送消息(会创建模板)
李洋's avatar
1、为大小写敏感的Linux做修改。fuck
ffbff372
 
李洋 committed 7 years ago
484
    private function sendmanualmessage(Request $request, $id, $viewid)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
485 486
    {
        Csrf($request);
李洋's avatar
update code
90eb7c01
 
李洋 committed 7 years ago
487 488 489
        $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
490
        $db = DB::connection('message');
李洋's avatar
update code
51d18a21
 
李洋 committed 7 years ago
491 492 493 494
        $isContainInner = '';
        $isContainSMS = '';
        $isContainEmail = '';
        $isContainWechatNotify = '';
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
495

李洋's avatar
update code
90eb7c01
 
李洋 committed 7 years ago
496 497
        //编辑时传过来log_id  选择模板时传过来tpl_id
        if(!empty($rq_log_id) || !empty($rq_tpl_id))
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
498
        {
李洋's avatar
update code
90eb7c01
 
李洋 committed 7 years ago
499 500 501 502 503 504 505 506 507 508
            //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
509
                $info->expect_send_time = '';
李洋's avatar
update code
90eb7c01
 
李洋 committed 7 years ago
510
            }
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527

            //通过tpl_id找到模板的渠道们 和 描述
            $desc_and_channels = $db->table('lie_msg_tpl')->select('description','channels','msg_type')->where('tpl_id',$info->tpl_id)->first();
            $info->desc = $desc_and_channels->description;
            $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();
                $channel_tpls[$channel_type] = $channel_tpl_obj;
            }
            $info->channel_tpls = $channel_tpls;
李洋's avatar
update code
51d18a21
 
李洋 committed 7 years ago
528 529 530 531 532 533

            //判断包含的消息渠道(用于展示消息渠道)(利用之前分割字符串得到的数组)
            $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
534 535
        }

李洋's avatar
update code
51d18a21
 
李洋 committed 7 years ago
536
        //找出所有模板(给选择模板用)
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
        $all_msg_tpl = $db->table('lie_msg_tpl')->select('tpl_id','description')->get();

        if(empty($info))
        {
            $info = (object)null;
            $info->tpl_id = '';
            $info->obj_user = '';
            $info->actual_send_time = '';
            $info->expect_send_time = '';
            $info->desc = '';
            $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
567 568 569 570 571
            'all_msg_tpl'=>$all_msg_tpl,
            'isContainInner'=>$isContainInner,
            'isContainSMS'=>$isContainSMS,
            'isContainEmail'=>$isContainEmail,
            'isContainWechatNotify'=>$isContainWechatNotify,
李洋's avatar
Initial commit
60b5dc25
 
李洋 committed 7 years ago
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
        ];

        return view($viewid, $data);
    }



    //--------------------------------------------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;
    }
}