80 lines
2.0 KiB
PHP
80 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic;
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\HotList;
|
|
|
|
class HotListLogic extends Logic
|
|
{
|
|
public static function lists($get)
|
|
{
|
|
$where = [];
|
|
if (!empty($get['name']) and $get['name']) {
|
|
$where[] = ['g.name', 'like', '%' . $get['name'] . '%'];
|
|
}
|
|
|
|
$model = new HotList();
|
|
$lists = $model->with(['goods'])
|
|
->where('delete_time', 0)
|
|
->paginate([
|
|
'page' => $get['page'],
|
|
'list_rows' => $get['limit'],
|
|
'var_page' => 'page'
|
|
])->toArray();;
|
|
return ['count' => $lists['total'], 'lists' => $lists['data']];
|
|
}
|
|
|
|
// 获取详情
|
|
public static function detail($id)
|
|
{
|
|
$result = HotList::with('goods')->where(['id' => $id, 'delete_time' => 0])->find();
|
|
return $result;
|
|
}
|
|
|
|
// 添加表单信息
|
|
public static function create($form)
|
|
{
|
|
if (!empty($form['sort']) && !is_numeric($form['sort'])) {
|
|
return ['code' => -1, 'msg' => '请输入整数'];
|
|
}
|
|
|
|
$result = HotList::create([
|
|
'goods_id' => $form['goods_id'],
|
|
'sort' => $form['sort'],
|
|
'create_time' => time()
|
|
]);
|
|
|
|
if ($result) {
|
|
return ['code' => 1, 'msg' => '添加成功'];
|
|
}
|
|
|
|
return ['code' => -1, 'msg' => '添加失败'];
|
|
}
|
|
|
|
// 修改表单信息
|
|
public static function edit($form)
|
|
{
|
|
$result = HotList::where(['id' => $form['id']])->update([
|
|
'goods_id' => $form['goods_id'],
|
|
'sort' => $form['sort'],
|
|
'update_time' => time()
|
|
]);
|
|
|
|
if ($result) {
|
|
return ['code' => 1, 'msg' => '修改成功'];
|
|
}
|
|
|
|
return ['code' => -1, 'msg' => '修改失败'];
|
|
}
|
|
|
|
// 删除文章
|
|
public static function del($id)
|
|
{
|
|
$result = HotList::where(['id' => $id])->update(['delete_time' => time()]);
|
|
if ($result) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
} |