multi-store/app/admin/logic/system_store/SystemStoreLogic.php

106 lines
2.5 KiB
PHP

<?php
namespace app\admin\logic\system_store;
use app\common\model\system_store\SystemStore;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 门店列表逻辑
* Class SystemStoreLogic
* @package app\admin\logic\system_store
*/
class SystemStoreLogic extends BaseLogic
{
/**
* @notes 添加门店列表
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 17:45
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
SystemStore::create([
'name' => $params['name'],
'introduction' => $params['introduction'],
'phone' => $params['phone'],
'detailed_address' => $params['detailed_address'],
'image' => $params['image'],
'is_show' => $params['is_show']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑门店列表
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 17:45
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
SystemStore::where('id', $params['id'])->update([
'name' => $params['name'],
'introduction' => $params['introduction'],
'phone' => $params['phone'],
'detailed_address' => $params['detailed_address'],
'image' => $params['image'],
'latitude' => $params['latitude'],
'longitude' => $params['longitude'],
'is_show' => $params['is_show']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除门店列表
* @param array $params
* @return bool
* @author admin
* @date 2024/05/31 17:45
*/
public static function delete(array $params): bool
{
return SystemStore::destroy($params['id']);
}
/**
* @notes 获取门店列表详情
* @param $params
* @return array
* @author admin
* @date 2024/05/31 17:45
*/
public static function detail($params): array
{
return SystemStore::findOrEmpty($params['id'])->toArray();
}
}