dlh_test_server/app/admin/logic/NewGoodsLogic.php

82 lines
2.1 KiB
PHP
Raw Normal View History

2024-08-03 10:04:14 +08:00
<?php
namespace app\admin\logic;
use app\common\basics\Logic;
use app\common\model\NewGoods;
class NewGoodsLogic extends Logic
{
public static function lists($get)
{
$where = [];
if (!empty($get['title']) and $get['title']) {
$where[] = ['title', 'like', '%' . $get['title'] . '%'];
}
$model = new NewGoods();
$lists = $model->with(['goods' => function ($query) use ($where) {
$query->where($where);
}])
->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 = NewGoods::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 = NewGoods::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 = NewGoods::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 = NewGoods::where(['id' => $id])->update(['delete_time' => time()]);
if ($result) {
return true;
}
return false;
}
}