83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\admin\controller;
|
|
|
|
use app\BaseController;
|
|
use think\facade\Db;
|
|
use think\facade\View;
|
|
use think\Request;
|
|
|
|
class GoodsOffshelfController extends BaseController
|
|
{
|
|
/**
|
|
* 显示下架日志列表
|
|
*/
|
|
public function log(Request $request)
|
|
{
|
|
$query = [];
|
|
|
|
// 处理搜索条件
|
|
if ($goodsId = $request->param('goods_id')) {
|
|
$query[] = ['goods_id', '=', $goodsId];
|
|
}
|
|
|
|
$startTime = $request->param('start_time');
|
|
$endTime = $request->param('end_time');
|
|
|
|
if ($startTime) {
|
|
$query[] = ['create_time', '>=', strtotime($startTime)];
|
|
}
|
|
|
|
if ($endTime) {
|
|
$query[] = ['create_time', '<=', strtotime($endTime . ' 23:59:59')];
|
|
}
|
|
|
|
// 查询数据
|
|
$list = Db::name('goods_offshelf_log')
|
|
->alias('a')
|
|
->join('goods g', 'a.goods_id = g.id', 'left')
|
|
->field('a.*, g.title as goods_title, g.status as goods_status')
|
|
->where($query)
|
|
->order('a.id desc')
|
|
->paginate(15);
|
|
|
|
$count = $list->total();
|
|
|
|
// 处理数据
|
|
foreach ($list as &$item) {
|
|
$item['create_time_text'] = date('Y-m-d H:i:s', $item['create_time']);
|
|
}
|
|
|
|
View::assign('list', $list);
|
|
View::assign('count', $count);
|
|
View::assign('page', $list->render());
|
|
|
|
return View::fetch();
|
|
}
|
|
|
|
/**
|
|
* 标记下架日志为已读
|
|
*/
|
|
public function read()
|
|
{
|
|
// 获取当前显示的所有未读记录并标记为已读
|
|
Db::name('goods_offshelf_log')
|
|
->where('is_read', 0)
|
|
->update(['is_read' => 1]);
|
|
|
|
return json(['status' => 1, 'msg' => '标记成功']);
|
|
}
|
|
|
|
/**
|
|
* 获取未读下架日志的数量
|
|
*/
|
|
public function getUnreadCount()
|
|
{
|
|
$count = Db::name('goods_offshelf_log')
|
|
->where('is_read', 0)
|
|
->count();
|
|
|
|
return json(['status' => 1, 'count' => $count]);
|
|
}
|
|
}
|