Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
朱继来
/
后台订单管理
This project
Loading...
Sign in
Toggle navigation
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
Commit
f5ab63cc
authored
Oct 26, 2021
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
调整
parent
dae9a55b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
153 additions
and
152 deletions
app/Model/BrandBlackListModel.php
app/Model/BrandBlackListModel.php
View file @
f5ab63cc
<?php
<?php
namespace
App\Model
;
namespace
App\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Facades\Redis
;
use
Illuminate\Support\Facades\Redis
;
use
Request
;
use
Request
;
use
DB
;
use
DB
;
class
BrandBlackListModel
extends
Model
class
BrandBlackListModel
extends
Model
{
{
protected
$connection
=
'
order'
;
protected
$connection
=
'
web'
;
protected
$table
=
'lie_brand_blacklist'
;
protected
$table
=
'lie_brand_blacklist'
;
protected
$primaryKey
=
'id'
;
protected
$primaryKey
=
'id'
;
protected
$guarded
=
[
'id'
];
protected
$guarded
=
[
'id'
];
public
$timestamps
=
true
;
public
$timestamps
=
true
;
const
CREATED_AT
=
'create_time'
;
const
CREATED_AT
=
'create_time'
;
const
UPDATED_AT
=
'update_time'
;
const
UPDATED_AT
=
'update_time'
;
/** * @param \DateTime|int $value * @return false|int * @author dividez */
/** * @param \DateTime|int $value * @return false|int * @author dividez */
public
function
fromDateTime
(
$value
)
public
function
fromDateTime
(
$value
)
{
{
return
strtotime
(
parent
::
fromDateTime
(
$value
));
return
strtotime
(
parent
::
fromDateTime
(
$value
));
}
}
// 黑名单列表
// 黑名单列表
public
function
lists
(
$request
,
$export
=
''
)
public
function
lists
(
$request
,
$export
=
''
)
{
{
$page
=
$request
->
input
(
'page'
,
1
);
$page
=
$request
->
input
(
'page'
,
1
);
$limit
=
$request
->
input
(
'limit'
,
10
);
$limit
=
$request
->
input
(
'limit'
,
10
);
$map
[
'brand_name'
]
=
$request
->
input
(
'brand_name'
,
''
);
// 品牌名称
$map
[
'brand_name'
]
=
$request
->
input
(
'brand_name'
,
''
);
// 品牌名称
$map
[
'com_name'
]
=
$request
->
input
(
'com_name'
,
''
);
// 公司名称
$map
[
'com_name'
]
=
$request
->
input
(
'com_name'
,
''
);
// 公司名称
$map
[
'status'
]
=
$request
->
input
(
'status'
,
''
);
// 状态
$map
[
'status'
]
=
$request
->
input
(
'status'
,
''
);
// 状态
$map
[
'begin_time'
]
=
$request
->
input
(
'begin_time'
,
''
)
?
strtotime
(
$request
->
input
(
'begin_time'
))
:
''
;
$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
:
''
;
$map
[
'end_time'
]
=
$request
->
input
(
'end_time'
,
''
)
?
strtotime
(
$request
->
input
(
'end_time'
))
+
86399
:
''
;
$list
=
$this
->
where
(
function
(
$query
)
use
(
$map
)
{
$list
=
$this
->
where
(
function
(
$query
)
use
(
$map
)
{
// 品牌名称
// 品牌名称
if
(
$map
[
'brand_name'
])
{
if
(
$map
[
'brand_name'
])
{
$query
->
where
(
'brand_name'
,
'like'
,
$map
[
'brand_name'
]
.
'%'
);
$query
->
where
(
'brand_name'
,
'like'
,
$map
[
'brand_name'
]
.
'%'
);
}
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 公司名称
// 公司名称
if
(
$map
[
'com_name'
])
{
if
(
$map
[
'com_name'
])
{
$query
->
where
(
'com_name'
,
'like'
,
$map
[
'com_name'
]
.
'%'
);
$query
->
where
(
'com_name'
,
'like'
,
$map
[
'com_name'
]
.
'%'
);
}
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 状态
// 状态
if
(
$map
[
'status'
])
{
if
(
$map
[
'status'
])
{
$query
->
where
(
'status'
,
'='
,
$map
[
'status'
]);
$query
->
where
(
'status'
,
'='
,
$map
[
'status'
]);
}
}
})
->
where
(
function
(
$query
)
use
(
$map
)
{
})
->
where
(
function
(
$query
)
use
(
$map
)
{
// 创建时间
// 创建时间
if
(
!
empty
(
$map
[
'begin_time'
])
&&
!
empty
(
$map
[
'end_time'
]))
{
if
(
!
empty
(
$map
[
'begin_time'
])
&&
!
empty
(
$map
[
'end_time'
]))
{
$query
->
whereBetween
(
'create_time'
,
[
$map
[
'begin_time'
],
$map
[
'end_time'
]]);
$query
->
whereBetween
(
'create_time'
,
[
$map
[
'begin_time'
],
$map
[
'end_time'
]]);
}
}
else
if
(
!
empty
(
$map
[
'begin_time'
]))
{
else
if
(
!
empty
(
$map
[
'begin_time'
]))
{
$query
->
where
(
'create_time'
,
'>='
,
$map
[
'begin_time'
]);
$query
->
where
(
'create_time'
,
'>='
,
$map
[
'begin_time'
]);
}
}
else
if
(
!
empty
(
$map
[
'end_time'
]))
{
else
if
(
!
empty
(
$map
[
'end_time'
]))
{
$query
->
where
(
'create_time'
,
'<='
,
$map
[
'end_time'
]);
$query
->
where
(
'create_time'
,
'<='
,
$map
[
'end_time'
]);
}
}
})
})
->
orderBy
(
'create_time'
,
'desc'
)
->
orderBy
(
'create_time'
,
'desc'
)
->
orderBy
(
'id'
,
'desc'
);
->
orderBy
(
'id'
,
'desc'
);
if
(
$export
)
{
if
(
$export
)
{
$list
=
$list
->
get
()
->
toArray
();
$list
=
$list
->
get
()
->
toArray
();
if
(
empty
(
$list
))
{
if
(
empty
(
$list
))
{
echo
'<script>alert("导出数据为空");history.go(-1);</script>'
;
die
;
echo
'<script>alert("导出数据为空");history.go(-1);</script>'
;
die
;
}
}
return
$list
;
return
$list
;
}
else
{
}
else
{
$list
=
$list
->
paginate
(
$limit
,
[
'*'
],
'page'
,
$page
)
->
toArray
();
$list
=
$list
->
paginate
(
$limit
,
[
'*'
],
'page'
,
$page
)
->
toArray
();
return
[
0
,
'获取成功'
,
$list
[
'data'
],
$list
[
'total'
]];
return
[
0
,
'获取成功'
,
$list
[
'data'
],
$list
[
'total'
]];
}
}
}
}
// 新增、编辑
// 新增、编辑
public
function
setBlackList
(
$request
,
$brand_name
=
''
,
$com_name
=
''
)
public
function
setBlackList
(
$request
,
$brand_name
=
''
,
$com_name
=
''
)
{
{
$id
=
$request
->
input
(
'id'
,
0
);
$id
=
$request
->
input
(
'id'
,
0
);
$data
[
'brand_name'
]
=
$brand_name
?
$brand_name
:
$request
->
input
(
'brand_name'
,
''
);
$data
[
'brand_name'
]
=
$brand_name
?
$brand_name
:
$request
->
input
(
'brand_name'
,
''
);
$data
[
'com_name'
]
=
$com_name
?
$com_name
:
$request
->
input
(
'com_name'
,
''
);
$data
[
'com_name'
]
=
$com_name
?
$com_name
:
$request
->
input
(
'com_name'
,
''
);
$res
=
$this
->
where
(
$data
)
->
first
();
$res
=
$this
->
where
(
$data
)
->
first
();
if
(
$res
)
return
[
-
3
,
'数据已存在'
];
if
(
$res
)
return
[
-
3
,
'数据已存在'
];
if
(
$id
)
{
// 编辑
if
(
$id
)
{
// 编辑
$res
=
$this
->
where
(
'id'
,
$id
)
->
update
(
$data
);
$res
=
$this
->
where
(
'id'
,
$id
)
->
update
(
$data
);
if
(
$res
===
false
)
return
[
-
2
,
'编辑失败'
];
if
(
$res
===
false
)
return
[
-
2
,
'编辑失败'
];
}
else
{
}
else
{
$res
=
$this
->
create
(
$data
);
$res
=
$this
->
create
(
$data
);
if
(
$res
===
false
)
return
[
-
1
,
'新增失败'
];
if
(
$res
===
false
)
return
[
-
1
,
'新增失败'
];
$id
=
$res
->
id
;
$id
=
$res
->
id
;
}
}
Redis
::
hset
(
'brand_blacklist'
,
$id
,
json_encode
(
$data
));
// 设置缓存
Redis
::
hset
(
'brand_blacklist'
,
$id
,
json_encode
(
$data
));
// 设置缓存
return
[
0
,
'操作成功'
];
return
[
0
,
'操作成功'
];
}
}
// 删除
// 删除
public
function
delBlackList
(
$request
)
public
function
delBlackList
(
$request
)
{
{
$id
=
$request
->
input
(
'id'
,
0
);
$id
=
$request
->
input
(
'id'
,
0
);
if
(
!
$id
)
return
[
-
1
,
'参数缺失'
];
if
(
!
$id
)
return
[
-
1
,
'参数缺失'
];
$res
=
$this
->
where
(
'id'
,
$id
)
->
delete
();
$res
=
$this
->
where
(
'id'
,
$id
)
->
delete
();
if
(
$res
===
false
)
return
[
-
2
,
'删除失败'
];
if
(
$res
===
false
)
return
[
-
2
,
'删除失败'
];
Redis
::
hdel
(
'brand_blacklist'
,
$id
);
// 删除缓存
Redis
::
hdel
(
'brand_blacklist'
,
$id
);
// 删除缓存
return
[
0
,
'删除成功'
];
return
[
0
,
'删除成功'
];
}
}
// 启用/禁用品牌黑名单
// 启用/禁用品牌黑名单
public
function
action
(
$request
)
public
function
action
(
$request
)
{
{
$id
=
$request
->
input
(
'id'
,
0
);
$id
=
$request
->
input
(
'id'
,
0
);
$status
=
$request
->
input
(
'status'
,
1
);
$status
=
$request
->
input
(
'status'
,
1
);
if
(
!
$id
)
return
[
-
1
,
'参数缺失'
];
if
(
!
$id
)
return
[
-
1
,
'参数缺失'
];
$res
=
$this
->
where
(
'id'
,
$id
)
->
update
([
'status'
=>
$status
]);
$res
=
$this
->
where
(
'id'
,
$id
)
->
update
([
'status'
=>
$status
]);
if
(
$res
===
false
)
return
[
-
2
,
'操作失败'
];
if
(
$res
===
false
)
return
[
-
2
,
'操作失败'
];
if
(
$status
==
1
)
{
// 启用
if
(
$status
==
1
)
{
// 启用
$blacklist
=
$this
->
find
(
$id
);
$blacklist
=
$this
->
find
(
$id
);
$data
[
'brand_name'
]
=
$blacklist
[
'brand_name'
];
$data
[
'brand_name'
]
=
$blacklist
[
'brand_name'
];
$data
[
'com_name'
]
=
$blacklist
[
'com_name'
];
$data
[
'com_name'
]
=
$blacklist
[
'com_name'
];
Redis
::
hset
(
'brand_blacklist'
,
$id
,
json_encode
(
$data
));
// 设置缓存
Redis
::
hset
(
'brand_blacklist'
,
$id
,
json_encode
(
$data
));
// 设置缓存
}
else
{
}
else
{
Redis
::
hdel
(
'brand_blacklist'
,
$id
);
// 删除缓存
Redis
::
hdel
(
'brand_blacklist'
,
$id
);
// 删除缓存
}
}
return
[
0
,
'操作成功'
];
return
[
0
,
'操作成功'
];
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment