作者 xwp
1 个管道 的构建 通过 耗费 10 秒

评价逻辑

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
*
*
* @icon fa fa-circle-o
*/
class CourseSignStartSet extends Backend
{
/**
* CourseSignStartSet模型对象
* @var \app\admin\model\CourseSignStartSet
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\CourseSignStartSet;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->with(['store','course'])
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->with(['store','course'])
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
$list = collection($list)->toArray();
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
... ...
<?php
return [
'Id' => 'id',
'Course_sign_id' => '报名',
'Course_star' => '课程评价',
'Teacher_star' => '教师评价',
'Service_star' => '服务评价',
'Content' => '内容',
'Pic' => '图片',
'User_id' => '用户',
'Course_id' => '课程',
'Store_id' => '门店',
'Create_time' => '评价时间'
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class CourseSignStartSet extends Model
{
// 表名
protected $name = 'course_sign_start_set';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
public function course()
{
return $this->belongsTo('Course', 'course_id','id',[],'left')->setEagerlyType(1);
}
public function store()
{
return $this->belongsTo('Store', 'store_id','id',[],'left')->setEagerlyType(1);
}
}
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class CourseSignStartSet extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<!--<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Course_sign_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-course_sign_id" data-rule="required" data-source="course/sign/index" class="form-control selectpage" name="row[course_sign_id]" type="text" value="">
</div>
</div>-->
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Course_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-course_star" class="form-control" step="0.1" name="row[course_star]" type="number">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Teacher_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-teacher_star" class="form-control" step="0.1" name="row[teacher_star]" type="number">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Service_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-service_star" class="form-control" step="0.1" name="row[service_star]" type="number">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Content')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-content" class="form-control" name="row[content]" type="number">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pic')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-pic" class="form-control" size="50" name="row[pic]" type="text">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-files" class="btn btn-danger plupload" data-input-id="c-pic" data-mimetype="*" data-multiple="true" data-preview-id="p-files"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-files" class="btn btn-primary fachoose" data-input-id="c-pic" data-mimetype="*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-pic"></span>
</div>
<!--ul需要添加 data-template和data-name属性,并一一对应且唯一 -->
<ul class="row list-inline plupload-preview" id="p-files" data-template="introtpl" data-name="row[intro]"></ul>
<!--请注意 ul和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏-->
<!--这里自定义图片预览的模板 开始-->
<script type="text/html" id="introtpl">
<li class="col-xs-3">
<a href="<%=fullurl%>" data-url="<%=url%>" target="_blank" class="thumbnail">
<img src="<%=fullurl%>" class="img-responsive">
</a>
<a href="javascript:;" class="btn btn-danger btn-xs btn-trash"><i class="fa fa-trash"></i></a>
</li>
</script>
<!--这里自定义图片预览的模板 结束-->
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Course_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-course_id" data-source="course/index" class="form-control selectpage" name="row[course_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Store_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-store_id" data-source="store/index" class="form-control selectpage" name="row[store_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('名字')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-username" class="form-control" name="row[username]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('头像')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-cover" data-rule="required" class="form-control" size="1" name="row[weChat_pic]"
type="text" value="">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-files-cover" class="btn btn-danger plupload"
data-input-id="c-cover" data-mimetype="*" data-multiple="false"
data-preview-id="p-files-cover"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-files-cover" class="btn btn-primary fachoose"
data-input-id="c-cover" data-mimetype="*" data-multiple="false"><i
class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-cover"></span>
</div>
<!--ul需要添加 data-template和data-name属性,并一一对应且唯一 -->
<ul class="row list-inline plupload-preview" id="p-files-cover" data-template="introtpl-cover"
data-name="row[intro]"></ul>
<!--这里自定义图片预览的模板 开始-->
<script type="text/html" id="introtpl-cover">
<li class="col-xs-3">
<a href="<%=fullurl%>" data-url="<%=url%>" target="_blank" class="thumbnail">
<img src="<%=fullurl%>" class="img-responsive">
</a>
<a href="javascript:;" class="btn btn-danger btn-xs btn-trash"><i class="fa fa-trash"></i></a>
</li>
</script>
<!--这里自定义图片预览的模板 结束-->
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-create_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:date('Y-m-d H:i:s')}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Course_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-course_star" data-rule="required" class="form-control" step="0.1" name="row[course_star]" type="number" value="{$row.course_star|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Teacher_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-teacher_star" data-rule="required" class="form-control" step="0.1" name="row[teacher_star]" type="number" value="{$row.teacher_star|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Service_star')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-service_star" data-rule="required" class="form-control" step="0.1" name="row[service_star]" type="number" value="{$row.service_star|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Content')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-content" data-rule="required" class="form-control" name="row[content]" type="number" value="{$row.content|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Pic')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-pic" class="form-control" size="50" name="row[pic]" type="text" value="{$row.pic|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-files" class="btn btn-danger plupload" data-input-id="c-pic" data-mimetype="*" data-multiple="true" data-preview-id="p-files"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-files" class="btn btn-primary fachoose" data-input-id="c-pic" data-mimetype="*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-pic"></span>
</div>
<!--ul需要添加 data-template和data-name属性,并一一对应且唯一 -->
<ul class="row list-inline plupload-preview" id="p-files" data-template="introtpl" data-name="row[intro]"></ul>
<!--请注意 ul和textarea间不能存在其它任何元素,实际开发中textarea应该添加个hidden进行隐藏-->
<!--这里自定义图片预览的模板 开始-->
<script type="text/html" id="introtpl">
<li class="col-xs-3">
<a href="<%=fullurl%>" data-url="<%=url%>" target="_blank" class="thumbnail">
<img src="<%=fullurl%>" class="img-responsive">
</a>
<a href="javascript:;" class="btn btn-danger btn-xs btn-trash"><i class="fa fa-trash"></i></a>
</li>
</script>
<!--这里自定义图片预览的模板 结束-->
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Course_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-course_id" data-rule="required" data-source="course/index" class="form-control selectpage" name="row[course_id]" type="text" value="{$row.course_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Store_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-store_id" data-rule="required" data-source="store/index" class="form-control selectpage" name="row[store_id]" type="text" value="{$row.store_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('名字')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-username" class="form-control" name="row[username]" type="text" value="{$row.username|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('头像')}:</label>
<div class="col-xs-12 col-sm-8">
<div class="input-group">
<input id="c-cover" data-rule="required" class="form-control" size="1" name="row[weChat_pic]" type="text" value="{$row.weChat_pic|htmlentities}">
<div class="input-group-addon no-border no-padding">
<span><button type="button" id="plupload-files-cover" class="btn btn-danger plupload"
data-input-id="c-cover" data-mimetype="*" data-multiple="false"
data-preview-id="p-files-cover"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
<span><button type="button" id="fachoose-files-cover" class="btn btn-primary fachoose"
data-input-id="c-cover" data-mimetype="*" data-multiple="false"><i
class="fa fa-list"></i> {:__('Choose')}</button></span>
</div>
<span class="msg-box n-right" for="c-cover"></span>
</div>
<!--ul需要添加 data-template和data-name属性,并一一对应且唯一 -->
<ul class="row list-inline plupload-preview" id="p-files-cover" data-template="introtpl-cover"
data-name="row[intro]"></ul>
<!--这里自定义图片预览的模板 开始-->
<script type="text/html" id="introtpl-cover">
<li class="col-xs-3">
<a href="<%=fullurl%>" data-url="<%=url%>" target="_blank" class="thumbnail">
<img src="<%=fullurl%>" class="img-responsive">
</a>
<a href="javascript:;" class="btn btn-danger btn-xs btn-trash"><i class="fa fa-trash"></i></a>
</li>
</script>
<!--这里自定义图片预览的模板 结束-->
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-create_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{$row.create_time}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('course_sign_start_set/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('course_sign_start_set/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('course_sign_start_set/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!-- <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('course_sign_start_set/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>
<div class="dropdown btn-group {:$auth->check('course_sign_start_set/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
<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>
<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>
</ul>
</div>-->
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('course_sign_start_set/edit')}"
data-operate-del="{:$auth->check('course_sign_start_set/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -305,14 +305,36 @@ class Course extends Api
//查询评价
$star = new \app\admin\model\CourseSignStart();
$star = $star->where(['course_id'=>$id])->order('create_time','desc')->select();
foreach ($star as &$k){
$star1 = $star->with('user')->where(['course_id'=>$id])->order('create_time','desc')->select();
foreach ($star1 as &$k){
$banner = explode(",", $k['pic']);
foreach ($banner as &$v){
$v = cdnurl($v,true);
}
$k['pic'] = $banner;
$k['username'] = $k['user']['username'];
$k['weChat_pic'] = isset($k['user']['weChat_pic'])?cdnurl($k['user']['weChat_pic'],true):'';
}
unset($k);
//查询评价
$star = new \app\admin\model\CourseSignStartSet();
$star2 = $star->where(['course_id'=>$id])->order('create_time','desc')->select();
foreach ($star2 as &$kk){
$banner = explode(",", $kk['pic']);
foreach ($banner as &$vv){
$vv = cdnurl($vv,true);
}
$kk['pic'] = $banner;
$kk['weChat_pic'] = cdnurl($kk['weChat_pic'],true);
}
unset($kk);
$star = $star1+$star2;
foreach ($star as $key => $row) {
$create_time[$key] = $row['create_time'];
}
array_multisort($create_time, SORT_DESC, $star);
$course['star'] = $star;
... ... @@ -581,7 +603,7 @@ class Course extends Api
}
$course = new \app\admin\model\CourseSignStart();
$course = $course->where(['course_sign_id'=>$id])->select();
$course = $course->with('user')->where(['course_sign_id'=>$id])->select();
foreach ($course as &$k){
$banner = explode(",", $k['pic']);
... ... @@ -589,7 +611,10 @@ class Course extends Api
$v = cdnurl($v,true);
}
$k['pic'] = $banner;
$k['username'] = $k['user']['username'];
$k['weChat_pic'] = isset($k['user']['weChat_pic'])?cdnurl($k['user']['weChat_pic'],true):'';
}
unset($k);
$this->success('请求成功',$course);
}
... ...
... ... @@ -427,6 +427,7 @@ class User extends Api
$address = $this->request->request('address');
$is_default = $this->request->request('is_default');
$code = $this->request->request('code');
$weChat_pic = $this->request->request('weChat_pic');
if (!$user_id) {
$this->error(__('Invalid parameters'));
... ... @@ -467,6 +468,7 @@ class User extends Api
$data['birthday'] = $birthday;
$data['area'] = $area;
$data['address'] = $address;
$data['weChat_pic'] = $weChat_pic;
$data['is_default'] = $is_default;
$user->save($data,['id'=>$user_id]);
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'course_sign_start_set/index' + location.search,
add_url: 'course_sign_start_set/add',
edit_url: 'course_sign_start_set/edit',
del_url: 'course_sign_start_set/del',
multi_url: 'course_sign_start_set/multi',
table: 'course_sign_start_set',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
/* {field: 'course_sign_id', title: __('Course_sign_id')},*/
{field: 'course_star', title: __('Course_star'), operate:'BETWEEN'},
{field: 'teacher_star', title: __('Teacher_star'), operate:'BETWEEN'},
{field: 'service_star', title: __('Service_star'), operate:'BETWEEN'},
{field: 'content', title: __('Content')},
{field: 'pic', title: __('Pic'), formatter: function (value) {
var arr = value.split(',');
var html = '';
for(var i = 0; i < arr.length; i++) {
html += '<a href="javascript:"><img class="img-sm img-center" src="'+Fast.api.cdnurl(arr[i])+'"></a>'
}
return html;
},events: Table.api.events.image},
{field: 'username', title: __('名字')},
{field: 'weChat_pic', title: __('头像'), formatter: function (value) {
var arr = value.split(',');
var html = '';
for(var i = 0; i < arr.length; i++) {
html += '<a href="javascript:"><img class="img-sm img-center" src="'+Fast.api.cdnurl(arr[i])+'"></a>'
}
return html;
},events: Table.api.events.image},
{field: 'course.name', title: __('Course_id')},
{field: 'store.name', title: __('Store_id')},
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange'},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...