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.
69 lines
1.6 KiB
69 lines
1.6 KiB
<?php
|
|
|
|
namespace app\store\model\server;
|
|
|
|
use app\common\model\server\Server as ServerModel;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\DbException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
|
|
class Server extends ServerModel
|
|
{
|
|
|
|
/**
|
|
* @notes:新增
|
|
* @param $data
|
|
* @return bool
|
|
* @author: wanghousheng
|
|
*/
|
|
public function add($data): bool
|
|
{
|
|
$data['store_id'] = self::$storeId;
|
|
return $this->save($data);
|
|
}
|
|
|
|
/**
|
|
* @notes:编辑
|
|
* @param $data
|
|
* @return bool
|
|
* @author: wanghousheng
|
|
*/
|
|
public function edit($data): bool
|
|
{
|
|
// 是否删除图片
|
|
!isset($data['image_id']) && $data['image_id'] = 0;
|
|
return $this->save($data) !== false;
|
|
}
|
|
|
|
/**
|
|
* @notes:删除
|
|
* @param array $serverId
|
|
* @return bool
|
|
* @author: wanghousheng
|
|
*/
|
|
public function remove(array $serverId): bool
|
|
{
|
|
try {
|
|
return static::whereIn('server_id', $serverId)->select()->delete();
|
|
} catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改服务状态
|
|
* @param array $serverIds 商品id集
|
|
* @param bool $state 为true表示上架
|
|
* @return bool|false
|
|
*/
|
|
public function setStatus(array $serverIds, bool $state): bool
|
|
{
|
|
// 批量更新记录
|
|
return static::updateBase(['status' => $state ? 1 : 2], [['server_id', 'in', $serverIds]]);
|
|
}
|
|
|
|
public function getDetail(int $serverId)
|
|
{
|
|
return static::detail($serverId, ['image', 'category']);
|
|
}
|
|
} |