You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/store/model/Maintenance.php

113 lines
3.3 KiB

9 months ago
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\store\model;
use app\common\model\Maintenance as MaintenanceModel;
8 months ago
use think\model\relation\HasOne;
9 months ago
/**
* 文章模型
* Class Article
* @package app\store\model
*/
class Maintenance extends MaintenanceModel
{
/**
* 获取列表
* @param array $param
* @return \think\Paginator
* @throws \think\db\exception\DbException
*/
public function getList(array $param = []): \think\Paginator
{
// 查询参数
$params = $this->setQueryDefaultValue($param, [
'name' => '',
'categoryId' => 0,
'status' => -1,
]);
// 检索查询条件
$filter = [];
!empty($params['name']) && $filter[] = ['name', 'like', "%{$params['name']}%"];
9 months ago
$params['status'] > -1 && $filter[] = ['status', '=', $params['status']];
$params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']];
// 查询列表数据
8 months ago
$data = $this->where($filter)->with(['catImg'])
9 months ago
->where('is_delete', '=', 0)
->order(['sort' => 'asc', 'create_time' => 'desc'])
->paginate(15);
return self::preload($data, ['category']);
}
/**
* 新增记录
* @param array $data
* @return bool
*/
public function add(array $data): bool
{
if (empty($data['name'])) {
$this->error = '请输入保修名称';
return false;
}
/* if (($data['parent_id']) != 0) {
9 months ago
if (empty($data['url'])) {
$this->error = '请输地址';
return false;
}
} */
8 months ago
if (empty($data['img_id'])) {
$this->error = '请上传维修图片';
return false;
9 months ago
}
$data['store_id'] = self::$storeId;
return $this->save($data);
}
/**
* 更新记录
* @param array $data
* @return bool
*/
public function edit(array $data): bool
{
if (empty($data['name'])) {
$this->error = '请输入保修名称';
return false;
}
8 months ago
if (empty($data['img_id'])) {
$this->error = '请上传维修图片';
9 months ago
return false;
}
return $this->save($data) !== false;
}
/**
* 软删除
* @return bool
*/
public function setDelete(): bool
{
return $this->save(['is_delete' => 1]);
}
public static function getTotal(array $where = []): int
{
return (new static)->where($where)->where('is_delete', '=', 0)->count();
}
}