multi-store/app/common/logic/DeliveryServiceLogic.php
2024-06-06 16:45:14 +08:00

79 lines
2.2 KiB
PHP

<?php
namespace app\common\logic;
use app\common\model\system_store\DeliveryService;
use app\common\service\FileService;
use Webman\Config;
class DeliveryServiceLogic extends BaseLogic
{
public function add($params)
{
try {
$model = new DeliveryService();
$model->setAttrs($params);
$model->store_id = request()->adminInfo['store_id'];
$defaultAvatar = config('project.default_image.admin_avatar');
$model->avatar = !empty($model['avatar']) ? FileService::setFileUrl($model['avatar']) : $defaultAvatar;
$model->save();
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
public function edit($id, $params)
{
try {
$model = DeliveryService::find($id);
if (empty($model)) {
throw new \Exception('数据不存在');
}
$model->setAttrs($params);
$defaultAvatar = config('project.default_image.admin_avatar');
$model->avatar = !empty($model['avatar']) ? FileService::setFileUrl($model['avatar']) : $defaultAvatar;
$model->save();
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
public function delete($id)
{
try {
$model = DeliveryService::find($id);
if (empty($model)) {
throw new \Exception('数据不存在');
}
$model->delete();
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
public function detail($id)
{
$model = DeliveryService::find($id);
if (empty($model)) {
throw new \Exception('数据不存在');
}
return $model->toArray();
}
public function status($id)
{
try {
$model = DeliveryService::find($id);
if (empty($model)) {
throw new \Exception('数据不存在');
}
$model->status = $model->status == 1 ? 0 : 1;
$model->save();
} catch (\Exception $exception) {
throw new \Exception($exception->getMessage());
}
}
}