作者 Cool
1 个管道 的构建 通过 耗费 7 秒

后台订单列表新增聊天记录查看

  1 +<?php
  2 +
  3 +namespace app\admin\controller;
  4 +
  5 +use app\common\controller\Backend;
  6 +
  7 +/**
  8 + * 融云聊天记录管理
  9 + *
  10 + * @icon fa fa-circle-o
  11 + */
  12 +class OrderChat extends Backend
  13 +{
  14 +
  15 + /**
  16 + * OrderChat模型对象
  17 + * @var \app\admin\model\OrderChat
  18 + */
  19 + protected $model = null;
  20 +
  21 + public function _initialize()
  22 + {
  23 + parent::_initialize();
  24 + $this->model = new \app\admin\model\OrderChat;
  25 + $this->view->assign("typeList", $this->model->getTypeList());
  26 + }
  27 +
  28 + /**
  29 + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32 + */
  33 +
  34 +
  35 + /**
  36 + * 查看
  37 + */
  38 + public function index($ids = null)
  39 + {
  40 + //当前是否为关联查询
  41 + $this->relationSearch = true;
  42 + //设置过滤方法
  43 + $this->request->filter(['strip_tags', 'trim']);
  44 + if ($this->request->isAjax())
  45 + {
  46 + //如果发送的来源是Selectpage,则转发到Selectpage
  47 + if ($this->request->request('keyField'))
  48 + {
  49 + return $this->selectpage();
  50 + }
  51 + $order_where = [
  52 + 'order_chat.order_id' => $ids
  53 + ];
  54 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  55 + $total = $this->model
  56 + ->with(['order','user','teacher'])
  57 + ->where($where)
  58 + ->where($order_where)
  59 + ->order($sort, $order)
  60 + ->count();
  61 +
  62 + $list = $this->model
  63 + ->with(['order','user','teacher'])
  64 + ->where($where)
  65 + ->where($order_where)
  66 + ->order($sort, $order)
  67 + ->limit($offset, $limit)
  68 + ->select();
  69 +
  70 + foreach ($list as $row) {
  71 +
  72 + $row->getRelation('order')->visible(['status']);
  73 + $row->getRelation('user')->visible(['nickname']);
  74 + $row->getRelation('teacher')->visible(['nickname']);
  75 + }
  76 + $list = collection($list)->toArray();
  77 + $result = array("total" => $total, "rows" => $list);
  78 +
  79 + return json($result);
  80 + }
  81 + $this->assignconfig('ids',$ids);
  82 + return $this->view->fetch();
  83 + }
  84 +}
  1 +<?php
  2 +
  3 +return [
  4 + 'Order_id' => '订单id',
  5 + 'Chat_id' => '群聊id',
  6 + 'Send_id' => '发送人',
  7 + 'Receive_id' => '接收人',
  8 + 'Type' => '消息类型',
  9 + 'Type 1' => '文字',
  10 + 'Type 2' => '图片',
  11 + 'Type 3' => '文件',
  12 + 'Text' => '文字',
  13 + 'Image' => '图片',
  14 + 'File' => '文件',
  15 + 'Createtime' => '发送时间',
  16 +];
  1 +<?php
  2 +
  3 +namespace app\admin\model;
  4 +
  5 +use think\Model;
  6 +
  7 +
  8 +class OrderChat extends Model
  9 +{
  10 +
  11 +
  12 +
  13 +
  14 +
  15 + // 表名
  16 + protected $name = 'order_chat';
  17 +
  18 + // 自动写入时间戳字段
  19 + protected $autoWriteTimestamp = 'int';
  20 +
  21 + // 定义时间戳字段名
  22 + protected $createTime = 'createtime';
  23 + protected $updateTime = 'updatetime';
  24 + protected $deleteTime = false;
  25 +
  26 + // 追加属性
  27 + protected $append = [
  28 + 'type_text'
  29 + ];
  30 +
  31 +
  32 +
  33 + public function getTypeList()
  34 + {
  35 + return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
  36 + }
  37 +
  38 +
  39 + public function getTypeTextAttr($value, $data)
  40 + {
  41 + $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  42 + $list = $this->getTypeList();
  43 + return isset($list[$value]) ? $list[$value] : '';
  44 + }
  45 +
  46 +
  47 +
  48 +
  49 + public function order()
  50 + {
  51 + return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
  52 + }
  53 +
  54 + public function user()
  55 + {
  56 + return $this->belongsTo('User', 'send_id', 'id', [], 'LEFT')->setEagerlyType(0);
  57 + }
  58 +
  59 + public function teacher()
  60 + {
  61 + return $this->belongsTo('User', 'receive_id', 'id', [], 'LEFT')->setEagerlyType(0);
  62 + }
  63 +}
  1 +<?php
  2 +
  3 +namespace app\admin\validate;
  4 +
  5 +use think\Validate;
  6 +
  7 +class OrderChat extends Validate
  8 +{
  9 + /**
  10 + * 验证规则
  11 + */
  12 + protected $rule = [
  13 + ];
  14 + /**
  15 + * 提示消息
  16 + */
  17 + protected $message = [
  18 + ];
  19 + /**
  20 + * 验证场景
  21 + */
  22 + protected $scene = [
  23 + 'add' => [],
  24 + 'edit' => [],
  25 + ];
  26 +
  27 +}
@@ -8,23 +8,14 @@ @@ -8,23 +8,14 @@
8 <div id="toolbar" class="toolbar"> 8 <div id="toolbar" class="toolbar">
9 <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> 9 <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
10 <!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('order/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>--> 10 <!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('order/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
11 - <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('order/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>  
12 - <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('order/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>  
13 - <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('order/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>  
14 -  
15 - <div class="dropdown btn-group {:$auth->check('order/multi')?'':'hide'}">  
16 - <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>  
17 - <ul class="dropdown-menu text-left" role="menu">  
18 - <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>  
19 - <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>  
20 - </ul>  
21 - </div> 11 +<!-- <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('order/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>-->
  12 +<!-- <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('order/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
22 13
23 14
24 </div> 15 </div>
25 <table id="table" class="table table-striped table-bordered table-hover table-nowrap" 16 <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
26 - data-operate-edit="{:$auth->check('order/edit')}"  
27 - data-operate-del="{:$auth->check('order/del')}" 17 + data-operate-edit=""
  18 + data-operate-del=""
28 width="100%"> 19 width="100%">
29 </table> 20 </table>
30 </div> 21 </div>
  1 +<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-order_id" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value="">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('Chat_id')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-chat_id" data-rule="required" data-source="chat/index" class="form-control selectpage" name="row[chat_id]" type="text" value="">
  13 + </div>
  14 + </div>
  15 + <div class="form-group">
  16 + <label class="control-label col-xs-12 col-sm-2">{:__('Send_id')}:</label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <input id="c-send_id" data-rule="required" data-source="send/index" class="form-control selectpage" name="row[send_id]" type="text" value="">
  19 + </div>
  20 + </div>
  21 + <div class="form-group">
  22 + <label class="control-label col-xs-12 col-sm-2">{:__('Receive_id')}:</label>
  23 + <div class="col-xs-12 col-sm-8">
  24 + <input id="c-receive_id" data-rule="required" data-source="receive/index" class="form-control selectpage" name="row[receive_id]" type="text" value="">
  25 + </div>
  26 + </div>
  27 + <div class="form-group">
  28 + <label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
  29 + <div class="col-xs-12 col-sm-8">
  30 +
  31 + <select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
  32 + {foreach name="typeList" item="vo"}
  33 + <option value="{$key}" {in name="key" value="1"}selected{/in}>{$vo}</option>
  34 + {/foreach}
  35 + </select>
  36 +
  37 + </div>
  38 + </div>
  39 + <div class="form-group">
  40 + <label class="control-label col-xs-12 col-sm-2">{:__('Text')}:</label>
  41 + <div class="col-xs-12 col-sm-8">
  42 + <input id="c-text" data-rule="required" class="form-control" name="row[text]" type="text" value="">
  43 + </div>
  44 + </div>
  45 + <div class="form-group">
  46 + <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
  47 + <div class="col-xs-12 col-sm-8">
  48 + <div class="input-group">
  49 + <input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="">
  50 + <div class="input-group-addon no-border no-padding">
  51 + <span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
  52 + <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
  53 + </div>
  54 + <span class="msg-box n-right" for="c-image"></span>
  55 + </div>
  56 + <ul class="row list-inline plupload-preview" id="p-image"></ul>
  57 + </div>
  58 + </div>
  59 + <div class="form-group">
  60 + <label class="control-label col-xs-12 col-sm-2">{:__('File')}:</label>
  61 + <div class="col-xs-12 col-sm-8">
  62 + <div class="input-group">
  63 + <input id="c-file" data-rule="required" class="form-control" size="50" name="row[file]" type="text" value="">
  64 + <div class="input-group-addon no-border no-padding">
  65 + <span><button type="button" id="plupload-file" class="btn btn-danger plupload" data-input-id="c-file" data-multiple="false" data-preview-id="p-file"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
  66 + <span><button type="button" id="fachoose-file" class="btn btn-primary fachoose" data-input-id="c-file" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
  67 + </div>
  68 + <span class="msg-box n-right" for="c-file"></span>
  69 + </div>
  70 + <ul class="row list-inline plupload-preview" id="p-file"></ul>
  71 + </div>
  72 + </div>
  73 + <div class="form-group layer-footer">
  74 + <label class="control-label col-xs-12 col-sm-2"></label>
  75 + <div class="col-xs-12 col-sm-8">
  76 + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  77 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  78 + </div>
  79 + </div>
  80 +</form>
  1 +<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Order_id')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <input id="c-order_id" data-rule="required" data-source="order/index" class="form-control selectpage" name="row[order_id]" type="text" value="{$row.order_id|htmlentities}">
  7 + </div>
  8 + </div>
  9 + <div class="form-group">
  10 + <label class="control-label col-xs-12 col-sm-2">{:__('Chat_id')}:</label>
  11 + <div class="col-xs-12 col-sm-8">
  12 + <input id="c-chat_id" data-rule="required" data-source="chat/index" class="form-control selectpage" name="row[chat_id]" type="text" value="{$row.chat_id|htmlentities}">
  13 + </div>
  14 + </div>
  15 + <div class="form-group">
  16 + <label class="control-label col-xs-12 col-sm-2">{:__('Send_id')}:</label>
  17 + <div class="col-xs-12 col-sm-8">
  18 + <input id="c-send_id" data-rule="required" data-source="send/index" class="form-control selectpage" name="row[send_id]" type="text" value="{$row.send_id|htmlentities}">
  19 + </div>
  20 + </div>
  21 + <div class="form-group">
  22 + <label class="control-label col-xs-12 col-sm-2">{:__('Receive_id')}:</label>
  23 + <div class="col-xs-12 col-sm-8">
  24 + <input id="c-receive_id" data-rule="required" data-source="receive/index" class="form-control selectpage" name="row[receive_id]" type="text" value="{$row.receive_id|htmlentities}">
  25 + </div>
  26 + </div>
  27 + <div class="form-group">
  28 + <label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
  29 + <div class="col-xs-12 col-sm-8">
  30 +
  31 + <select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
  32 + {foreach name="typeList" item="vo"}
  33 + <option value="{$key}" {in name="key" value="$row.type"}selected{/in}>{$vo}</option>
  34 + {/foreach}
  35 + </select>
  36 +
  37 + </div>
  38 + </div>
  39 + <div class="form-group">
  40 + <label class="control-label col-xs-12 col-sm-2">{:__('Text')}:</label>
  41 + <div class="col-xs-12 col-sm-8">
  42 + <input id="c-text" data-rule="required" class="form-control" name="row[text]" type="text" value="{$row.text|htmlentities}">
  43 + </div>
  44 + </div>
  45 + <div class="form-group">
  46 + <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
  47 + <div class="col-xs-12 col-sm-8">
  48 + <div class="input-group">
  49 + <input id="c-image" data-rule="required" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">
  50 + <div class="input-group-addon no-border no-padding">
  51 + <span><button type="button" id="plupload-image" class="btn btn-danger plupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
  52 + <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
  53 + </div>
  54 + <span class="msg-box n-right" for="c-image"></span>
  55 + </div>
  56 + <ul class="row list-inline plupload-preview" id="p-image"></ul>
  57 + </div>
  58 + </div>
  59 + <div class="form-group">
  60 + <label class="control-label col-xs-12 col-sm-2">{:__('File')}:</label>
  61 + <div class="col-xs-12 col-sm-8">
  62 + <div class="input-group">
  63 + <input id="c-file" data-rule="required" class="form-control" size="50" name="row[file]" type="text" value="{$row.file|htmlentities}">
  64 + <div class="input-group-addon no-border no-padding">
  65 + <span><button type="button" id="plupload-file" class="btn btn-danger plupload" data-input-id="c-file" data-multiple="false" data-preview-id="p-file"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
  66 + <span><button type="button" id="fachoose-file" class="btn btn-primary fachoose" data-input-id="c-file" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
  67 + </div>
  68 + <span class="msg-box n-right" for="c-file"></span>
  69 + </div>
  70 + <ul class="row list-inline plupload-preview" id="p-file"></ul>
  71 + </div>
  72 + </div>
  73 + <div class="form-group layer-footer">
  74 + <label class="control-label col-xs-12 col-sm-2"></label>
  75 + <div class="col-xs-12 col-sm-8">
  76 + <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
  77 + <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
  78 + </div>
  79 + </div>
  80 +</form>
  1 +<div class="panel panel-default panel-intro">
  2 + {:build_heading()}
  3 +
  4 + <div class="panel-body">
  5 + <div id="myTabContent" class="tab-content">
  6 + <div class="tab-pane fade active in" id="one">
  7 + <div class="widget-body no-padding">
  8 + <div id="toolbar" class="toolbar">
  9 + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  10 + <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('order_chat/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
  11 +
  12 +
  13 + </div>
  14 + <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
  15 + data-operate-edit=""
  16 + data-operate-del="{:$auth->check('order_chat/del')}"
  17 + width="100%">
  18 + </table>
  19 + </div>
  20 + </div>
  21 +
  22 + </div>
  23 + </div>
  24 +</div>
此 diff 太大无法显示。
@@ -43,6 +43,19 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -43,6 +43,19 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
43 {field: 'id', title: __('按钮组'), table: table, events: Table.api.events.operate, buttons: 43 {field: 'id', title: __('按钮组'), table: table, events: Table.api.events.operate, buttons:
44 [ 44 [
45 { 45 {
  46 + text: '聊天记录',
  47 + title: '聊天记录',
  48 + icon: 'fa fa-list',
  49 + classname: 'btn btn-xs btn-primary btn-dialog',
  50 + url: 'order_chat/index',
  51 + extend: 'data-area=\'["80%","80%"]\'',
  52 + hidden:function(row){
  53 + if(row.status != 2){
  54 + return true;
  55 + }
  56 + },
  57 + },
  58 + {
46 text: '学生评价', 59 text: '学生评价',
47 title: '评价内容详情', 60 title: '评价内容详情',
48 icon: 'fa fa-list', 61 icon: 'fa fa-list',
  1 +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2 +
  3 + var Controller = {
  4 + index: function () {
  5 + // 初始化表格参数配置
  6 + Table.api.init({
  7 + extend: {
  8 + index_url: 'order_chat/index' + '/ids/' + Config.ids + location.search,
  9 + add_url: 'order_chat/add',
  10 + edit_url: 'order_chat/edit',
  11 + del_url: 'order_chat/del',
  12 + multi_url: 'order_chat/multi',
  13 + table: 'order_chat',
  14 + }
  15 + });
  16 +
  17 + var table = $("#table");
  18 +
  19 + // 初始化表格
  20 + table.bootstrapTable({
  21 + url: $.fn.bootstrapTable.defaults.extend.index_url,
  22 + pk: 'id',
  23 + sortName: 'id',
  24 + columns: [
  25 + [
  26 + {checkbox: true},
  27 + {field: 'id', title: __('Id')},
  28 + {field: 'chat_id', title: __('Chat_id')},
  29 + {field: 'user.nickname', title: __('Send_id')},
  30 + {field: 'teacher.nickname', title: __('Receive_id')},
  31 + {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
  32 + {field: 'text', title: __('Text')},
  33 + {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  34 + {field: 'file', title: __('File'), operate: false, formatter: Table.api.formatter.url},
  35 + {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  36 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  37 + ]
  38 + ]
  39 + });
  40 +
  41 + // 为表格绑定事件
  42 + Table.api.bindevent(table);
  43 + },
  44 + add: function () {
  45 + Controller.api.bindevent();
  46 + },
  47 + edit: function () {
  48 + Controller.api.bindevent();
  49 + },
  50 + api: {
  51 + bindevent: function () {
  52 + Form.api.bindevent($("form[role=form]"));
  53 + }
  54 + }
  55 + };
  56 + return Controller;
  57 +});