108 lines
2.9 KiB
PHP
108 lines
2.9 KiB
PHP
<?php
|
|
namespace app\adminapi\logic\custom;
|
|
|
|
use app\common\model\custom\Custom;
|
|
use app\common\model\custom\CustomContacts;
|
|
use app\common\logic\BaseLogic;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* CustomContacts逻辑
|
|
* Class CustomContactsLogic
|
|
* @package app\adminapi\logic\custom
|
|
*/
|
|
class CustomContactsLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2023/11/11 22:56
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
CustomContacts::create([
|
|
'custom_id' => $params['custom_id'],
|
|
'name' => $params['name'],
|
|
'position' => $params['position'] ?? '',
|
|
'phone' => $params['phone'] ?? '',
|
|
'telephone' => $params['telephone'] ?? '',
|
|
'email' => $params['email'] ?? '',
|
|
'notes' => $params['notes'] ?? '',
|
|
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
|
]);
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2023/11/11 22:56
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
CustomContacts::where('id', $params['id'])->update([
|
|
'custom_id' => $params['custom_id'],
|
|
'name' => $params['name'],
|
|
'position' => $params['position'] ?? '',
|
|
'phone' => $params['phone'] ?? '',
|
|
'telephone' => $params['telephone'] ?? '',
|
|
'email' => $params['email'] ?? '',
|
|
'notes' => $params['notes'] ?? '',
|
|
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
|
]);
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2023/11/11 22:56
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return CustomContacts::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取详情
|
|
* @param $params
|
|
* @return array
|
|
* @author likeadmin
|
|
* @date 2023/11/11 22:56
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
$data = CustomContacts::field('id,custom_id,name,position,phone,telephone,email,notes,annex')->findOrEmpty($params['id'])->toArray();
|
|
$custom = Custom::field('name')->where('id',$data['custom_id'])->findOrEmpty();
|
|
$data['custom_name'] = $custom['name'];
|
|
return $data;
|
|
}
|
|
} |