79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
namespace app\common\model;
|
|
|
|
use think\Model;
|
|
use think\facade\Db;
|
|
|
|
class DiamondProducts extends Base
|
|
{
|
|
//设置主键
|
|
protected $pk = 'id';
|
|
//设置表名
|
|
protected $table = 'diamond_products';
|
|
//设置自动时间戳
|
|
protected $autoWriteTimestamp = true;
|
|
protected $createTime = 'created_at';
|
|
protected $updateTime = 'updated_at';
|
|
|
|
/**
|
|
* 获取钻石商品列表
|
|
* @param array $where 条件
|
|
* @param int $page 页码
|
|
* @param int $limit 每页数据量
|
|
* @return array
|
|
*/
|
|
public static function getList($where = [], $page = 1, $limit = 10)
|
|
{
|
|
$query = self::where($where);
|
|
$count = $query->count();
|
|
$list = $query->order('sort_order asc')
|
|
->page($page, $limit)
|
|
->select()
|
|
->toArray();
|
|
|
|
return ['list' => $list, 'count' => $count];
|
|
}
|
|
|
|
/**
|
|
* 添加钻石商品
|
|
* @param array $data 商品数据
|
|
* @return int|string
|
|
*/
|
|
public static function add($data)
|
|
{
|
|
$model = new self;
|
|
$model->save($data);
|
|
return $model->id;
|
|
}
|
|
|
|
/**
|
|
* 修改钻石商品
|
|
* @param int $id 商品ID
|
|
* @param array $data 商品数据
|
|
* @return bool
|
|
*/
|
|
public static function edit($id, $data)
|
|
{
|
|
return self::where('id', $id)->update($data);
|
|
}
|
|
|
|
/**
|
|
* 删除钻石商品
|
|
* @param int $id 商品ID
|
|
* @return bool
|
|
*/
|
|
public static function del($id)
|
|
{
|
|
return self::where('id', $id)->delete();
|
|
}
|
|
|
|
/**
|
|
* 获取钻石商品详情
|
|
* @param int $id 商品ID
|
|
* @return array|Model|null
|
|
*/
|
|
public static function getInfo($id)
|
|
{
|
|
return self::where('id', $id)->find();
|
|
}
|
|
}
|