Commit 18d0b9f0 by 朱继来

添加品牌黑名单

parent 85b02fff
......@@ -17,6 +17,7 @@ use App\Model\UserSampleApplyModel;
use App\Model\UserSampleInviteModel;
use App\Model\OrderItemsModel;
use App\Model\UserGroupModel;
use App\Model\BrandBlackListModel;
class ApiController extends Controller
{
......@@ -237,4 +238,32 @@ class ApiController extends Controller
$this->ExportLayui($UserGroupModel->lists($request));
}
// 获取品牌黑名单
public function ApiBrandBlackList($request)
{
$BrandBlackListModel = new BrandBlackListModel;
$this->ExportLayui($BrandBlackListModel->lists($request));
}
// 新增/编辑品牌黑名单
public function ApiSetBrandBlackList($request)
{
$BrandBlackListModel = new BrandBlackListModel;
$this->Export($BrandBlackListModel->setBlackList($request));
}
// 删除品牌黑名单
public function ApiDelBrandBlackList($request)
{
$BrandBlackListModel = new BrandBlackListModel;
$this->Export($BrandBlackListModel->delBlackList($request));
}
// 启用/禁用品牌黑名单
public function ApiActionBrandBlackList($request)
{
$BrandBlackListModel = new BrandBlackListModel;
$this->Export($BrandBlackListModel->action($request));
}
}
......@@ -308,4 +308,11 @@ class WebController extends Controller
return view('web', $data);
}
// 品牌黑名单
public function brandBlackList($request, $data, $id)
{
$data['title'] = '黑名单列表';
return view('web', $data);
}
}
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;
use Request;
use DB;
class BrandBlackListModel extends Model
{
protected $connection = 'order';
protected $table = 'lie_brand_blacklist';
protected $primaryKey = 'id';
protected $guarded = ['id'];
public $timestamps = true;
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
/** * @param \DateTime|int $value * @return false|int * @author dividez */
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
}
// 黑名单列表
public function lists($request, $export='')
{
$page = $request->input('page', 1);
$limit = $request->input('limit', 10);
$map['brand_name'] = $request->input('brand_name', ''); // 品牌名称
$map['com_name'] = $request->input('com_name', ''); // 公司名称
$map['status'] = $request->input('status', ''); // 状态
$map['begin_time'] = $request->input('begin_time', '') ? strtotime($request->input('begin_time')) : '';
$map['end_time'] = $request->input('end_time', '') ? strtotime($request->input('end_time')) + 86399 : '';
$list = $this->where(function($query) use ($map) {
// 品牌名称
if ($map['brand_name']) {
$query->where('brand_name', 'like', $map['brand_name'].'%');
}
})->where(function($query) use ($map) {
// 公司名称
if ($map['com_name']) {
$query->where('com_name', 'like', $map['com_name'].'%');
}
})->where(function($query) use ($map) {
// 状态
if ($map['status']) {
$query->where('status', '=', $map['status']);
}
})->where(function($query) use ($map) {
// 创建时间
if(!empty($map['begin_time']) && !empty($map['end_time'])) {
$query->whereBetween('create_time', [$map['begin_time'], $map['end_time']]);
}
else if(!empty($map['begin_time'])) {
$query->where('create_time', '>=', $map['begin_time']);
}
else if(!empty($map['end_time'])) {
$query->where('create_time', '<=', $map['end_time']);
}
})
->orderBy('create_time', 'desc')
->orderBy('id', 'desc');
if ($export) {
$list = $list->get()->toArray();
if (empty($list)) {
echo '<script>alert("导出数据为空");history.go(-1);</script>';die;
}
return $list;
} else {
$list = $list->paginate($limit, ['*'], 'page', $page)->toArray();
return [0, '获取成功', $list['data'], $list['total']];
}
}
// 新增、编辑
public function setBlackList($request)
{
$id = $request->input('id', 0);
$data['brand_name'] = $request->input('brand_name', '');
$data['com_name'] = $request->input('com_name', '');
$res = $this->where($data)->first();
if ($res) return [-3, '数据已存在'];
if ($id) { // 编辑
$res = $this->where('id', $id)->update($data);
if ($res === false) return [-2, '编辑失败'];
} else {
$res = $this->create($data);
if ($res === false) return [-1, '新增失败'];
$id = $res->id;
}
Redis::hset('brand_blacklist', $id, json_encode($data)); // 设置缓存
return [0, '操作成功'];
}
// 删除
public function delBlackList($request)
{
$id = $request->input('id', 0);
if (!$id) return [-1, '参数缺失'];
$res = $this->where('id', $id)->delete();
if ($res === false) return [-2, '删除失败'];
Redis::hdel('brand_blacklist', $id); // 删除缓存
return [0, '删除成功'];
}
// 启用/禁用品牌黑名单
public function action($request)
{
$id = $request->input('id', 0);
$status = $request->input('status', 1);
if (!$id) return [-1, '参数缺失'];
$res = $this->where('id', $id)->update(['status' => $status]);
if ($res === false) return [-2, '操作失败'];
if ($status == 1) { // 启用
$blacklist = $this->find($id);
$data['brand_name'] = $blacklist['brand_name'];
$data['com_name'] = $blacklist['com_name'];
Redis::hset('brand_blacklist', $id, json_encode($data)); // 设置缓存
} else {
Redis::hdel('brand_blacklist', $id); // 删除缓存
}
return [0, '操作成功'];
}
}
\ No newline at end of file
layui.use(['form', 'table', 'laydate'], function(){
var form = layui.form;
var table = layui.table;
var laydate = layui.laydate;
laydate.render({
elem: '#begin_time' //指定元素
});
laydate.render({
elem: '#end_time' //指定元素
});
var renderTable = function () {
table.render({
id: 'list'
,elem: '#blacklist'
,url: '/api/ApiBrandBlackList' //数据接口
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,cols: [[ //表头
{title: '序号', type: 'numbers', fixed: 'left', width: 80}
,{field: 'id', title: 'ID', width: 100}
,{field: 'brand_name', title: '品牌名称', width: 320}
,{field: 'com_name', title: '公司名称', width: 320}
,{field: 'status', title: '状态', templet: '#status', width: 200}
,{field: 'create_time', title: '创建时间', width: 180}
,{field: 'update_time', title: '更新时间', width: 180}
,{title: '操作', align:'center', fixed: 'right', toolbar: '#list_action', width: 218}
]]
,limit: 10
,limits: [10, 20, 50,]
});
}
renderTable();
form.on('submit(load)', function(data) {
//执行重载
table.reload('list', {
page: {
curr: 1
}
,where: data.field
});
return false;
});
// 新增
$('.add').click(function() {
$('.set-brand-name').val('');
$('.set-com-name').val('');
blacklist_set('新增黑名单');
})
function blacklist_set(title)
{
layer.open({
area: ['400px'],
title: title,
type: 1,
content: $('#black-action'),
btn: ['确认', '取消'],
yes: function(index) {
var brand_name = $('.set-brand-name').val();
var com_name = $('.set-com-name').val();
if (!brand_name) {
layer.tips('请输入品牌名称', $('.set-brand-name'));
return false;
}
if (!com_name) {
layer.tips('请输入公司名称', $('.set-com-name'));
return false;
}
$.ajax({
url : '/api/ApiSetBrandBlackList',
type: 'post',
data: $('.blacklist-form').serialize(),
dataType: 'json',
success: function(resp) {
if (resp.errcode == 0) {
layer.close(index);
layer.msg(resp.errmsg);
renderTable(); // 重新加载table
return false;
}
layer.msg(resp.errmsg);
},
error: function(err) {
console.log(err)
}
})
layer.msg(title+'中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
return false;
},
cancel: function(index) {
layer.close(index);
}
})
}
// tool操作
table.on('tool(blacklist)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var url = '';
var title = '';
var content = '';
var datax = {};
datax.id = data.id;
if(layEvent === 'edit') {
$('.set-id').val(data.id);
$('.set-brand-name').val(data.brand_name);
$('.set-com-name').val(data.com_name);
blacklist_set('编辑黑名单');
return false;
} else if (layEvent === 'del') {
url = '/api/ApiDelBrandBlackList';
title = '删除黑名单';
content = '<div style="margin: 40px;">确定删除该黑名单吗?</div>';
} else if (layEvent === 'enable') {
url = '/api/ApiActionBrandBlackList';
title = '启用黑名单';
content = '<div style="margin: 40px;">确定启用该黑名单吗?</div>';
datax.status = 1;
} else if (layEvent === 'forbid') {
url = '/api/ApiActionBrandBlackList';
title = '禁用黑名单';
content = '<div style="margin: 40px;">确定禁用该黑名单吗?</div>';
datax.status = -1;
}
layer.open({
area: ['400px', '200px'],
title: title,
type: 1,
content: content,
btn: ['确认', '取消'],
yes: function(index) {
$.ajax({
url : url,
type: 'post',
data: datax,
dataType: 'json',
success: function(resp) {
if (resp.errcode == 0) {
layer.close(index);
layer.msg(resp.errmsg);
renderTable(); // 重新加载table
return false;
}
layer.msg(resp.errmsg);
},
error: function(err) {
console.log(err)
}
})
layer.msg(title+'中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
return false;
},
cancel: function(index) {
layer.close(index);
}
})
if (layEvent == 'edit') {
$('.kefu-email').val(data.email);
}
});
});
\ No newline at end of file
......@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{config('website.webTitle')}} | {{$title}}</title>
<title>订单管理系统 | {{$title}}</title>
<script>document.domain="{{ config('website.domain') }}";</script>
<link href="/js/layui/css/layui.css" rel="stylesheet">
<link href="/css/admin.css" rel="stylesheet">
......
<form class="layui-form layui-box" method="post">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">品牌名称</label>
<div class="layui-input-inline">
<input type="text" name="brand_name" placeholder="填写品牌名称" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">公司名称</label>
<div class="layui-input-inline">
<input type="text" name="com_name" placeholder="填写公司名称" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">状态</label>
<div class="layui-input-inline">
<select name="status" lay-verify="" lay-search>
<option value=""></option>
<option value="1">启用</option>
<option value="-1">禁用</option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">创建时间</label>
<div class="layui-input-inline">
<input type="text" name="begin_time" value="" autocomplete="off" placeholder="选择开始时间" class="layui-input" id="begin_time" readonly>
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" name="end_time" value="" autocomplete="off" placeholder="选择结束时间" class="layui-input" id="end_time" readonly>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-btn-container" style="text-align: center; margin-top: 10px;">
<button lay-submit lay-filter="load" class="layui-btn" data-type="search">搜索</button>
<!-- <button type="button" class="layui-btn layui-btn-normal export">导出</button> -->
<a class="layui-btn layui-btn-normal add">新增</a>
</div>
</div>
</form>
<table id="blacklist" lay-filter="blacklist"></table>
<script type="text/html" id="status">
@{{# if (d.status == 1) { }}
<div style="color:green;">启用</div>
@{{# } else { }}
<div style="color:#ccc;">禁用</div>
@{{# } }}
</script>
<script type="text/html" id="list_action">
@{{# if (d.status == 1) { }}
<a class="btn btn-xs btn-warning" lay-event="edit">编辑</a>
<a class="btn btn-xs btn-outline btn-danger" lay-event="forbid">禁用</a>
<a class="btn btn-xs btn-danger" lay-event="del">删除</a>
@{{# } else { }}
<a class="btn btn-xs btn-outline btn-info" lay-event="enable">启用</a>
@{{# } }}
</script>
<style>
#black-action{ display: none; }
#black-action form{ margin-top: 20px; }
#black-action .layui-input-inline{ width: 240px; }
</style>
<div id="black-action">
<form class="layui-form layui-box blacklist-form">
<input type="hidden" name="id" value="" class="set-id">
<div class="layui-item">
<div class="layui-input-inline" style="width: 100%">
<label class="layui-form-label">品牌名称</label>
<div class="layui-input-inline">
<input type="text" name="brand_name" placeholder="品牌名称" autocomplete="off" class="layui-input set-brand-name">
</div>
</div>
</div>
<div class="layui-item">
<div class="layui-input-inline" style="width: 100%">
<label class="layui-form-label">公司名称</label>
<div class="layui-input-inline">
<input type="text" name="com_name" placeholder="公司名称" autocomplete="off" class="layui-input set-com-name">
</div>
</div>
</div>
</div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment