144 lines
4.4 KiB
PHP
144 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\system_store;
|
|
|
|
|
|
use app\common\model\system_store\SystemStore;
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\system_store\SystemStoreStaff;
|
|
use think\facade\Db;
|
|
use Webman\Config;
|
|
|
|
/**
|
|
* 门店列表逻辑
|
|
* 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 {
|
|
$passwordSalt = Config::get('project.unique_identification');
|
|
$password = create_password($params['password'], $passwordSalt);
|
|
$store = SystemStore::create([
|
|
'name' => $params['name'],
|
|
'introduction' => $params['introduction'],
|
|
'phone' => $params['phone'],
|
|
'detailed_address' => $params['detailed_address'],
|
|
'image' => $params['image'],
|
|
'is_show' => $params['is_show'],
|
|
'longitude' => $params['longitude'],
|
|
'latitude' => $params['latitude'],
|
|
'day_start' => $params['day_start'],
|
|
'day_end' => $params['day_end'],
|
|
'province' => $params['province_code'],
|
|
'city' => $params['city_code'],
|
|
'area' => $params['area_code'],
|
|
'street' => $params['street_code'],
|
|
]);
|
|
$taff = [
|
|
'store_id' => $store['id'],
|
|
'account' => $params['phone'],
|
|
'pwd' => $password,
|
|
'avatar' => $params['image'],
|
|
'staff_name' => $params['name'],
|
|
'phone' => $params['phone'],
|
|
'is_admin' => 1,
|
|
'status' => 1,
|
|
|
|
];
|
|
SystemStoreStaff::create($taff);
|
|
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 {
|
|
$store = SystemStore::where('id',$params['id'])->update([
|
|
'name' => $params['name'],
|
|
'introduction' => $params['introduction'],
|
|
'detailed_address' => $params['detailed_address'],
|
|
'image' => $params['image'],
|
|
'is_show' => $params['is_show'],
|
|
'longitude' => $params['longitude'],
|
|
'latitude' => $params['latitude'],
|
|
'day_start' => $params['day_start'],
|
|
'day_end' => $params['day_end'],
|
|
'province' => $params['province_code'],
|
|
'city' => $params['city_code'],
|
|
'area' => $params['area_code'],
|
|
'street' => $params['street_code'],
|
|
]);
|
|
if($params['password']!=''){
|
|
$passwordSalt = Config::get('project.unique_identification');
|
|
$password = create_password($params['password'], $passwordSalt);
|
|
$taff = [
|
|
'pwd' => $password,
|
|
'avatar' => $params['image'],
|
|
'staff_name' => $params['name'],
|
|
];
|
|
SystemStoreStaff::where('store_id', $params['id'])->where('is_admin', 1)->where('account', $params['phone'])->update($taff);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|