作者 何书鹏
1 个管道 的构建 通过 耗费 1 秒

职位排序

... ... @@ -72,43 +72,4 @@ class Job extends Backend
return $this->view->fetch();
}
/**
* 置顶
*/
public function top($ids = null)
{
if($ids) {
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
$params = $this->request->param();
$params['top_time'] = $params['is_top'] == '1' ? time() : 0;
Db::startTrans();
try {
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (\think\Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('操作失败');
}
$this->success('操作成功');
}
}
}
... ...
... ... @@ -21,7 +21,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'is_top desc,top_time desc,weigh',
sortName: 'weigh',
columns: [
[
{checkbox: true},
... ... @@ -38,48 +38,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'people_num', title: __('People_num')},
{field: 'address', title: __('Address'), operate: 'LIKE'},
{field: 'weigh', title: __('Weigh')},
//操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
{
field: 'operate',
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'top',
text: '置顶',
title: '置顶',
classname: 'btn btn-xs btn-primary btn-ajax',
icon: 'fa fa-long-arrow-up',
url: 'job/top?job_id={id}&is_top=1',
visible: function (row) {
if(row.is_top == '0'){
return true;
}
},
success: function (data) {
table.bootstrapTable('refresh');
}
},
{
name: 'top',
text: '取消置顶',
title: '取消置顶',
classname: 'btn btn-xs btn-danger btn-ajax',
icon: 'fa fa-long-arrow-down',
url: 'job/top?job_id={id}&is_top=0',
visible: function (row) {
if(row.is_top == '1'){
return true;
}
},
success: function (data) {
table.bootstrapTable('refresh');
}
}
],
formatter: Table.api.formatter.operate
}
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
... ...