115 lines
3.4 KiB
PHP
115 lines
3.4 KiB
PHP
<?php
|
|
namespace app\adminapi\logic\custom;
|
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\custom\Custom;
|
|
use app\common\model\custom\CustomFollow;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* CustomFollow逻辑
|
|
* Class CustomFollowLogic
|
|
* @package app\adminapi\logic\custom_follow
|
|
*/
|
|
class CustomFollowLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2023/11/12 13:40
|
|
*/
|
|
public static function add(array $params,$admin_id): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
CustomFollow::create([
|
|
'custom_id' => $params['custom_id'],
|
|
'name' => $params['name'],
|
|
'date' => !empty($params['date']) ? strtotime($params['date']) : 0,
|
|
'types' => $params['types'],
|
|
'description' => $params['description'] ?? '',
|
|
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
|
|
'coordinate' => $params['coordinate'] ?? '',
|
|
'executor' => $params['executor'] ?? '',
|
|
'next_follow_date' => !empty($params['next_follow_date']) ? strtotime($params['next_follow_date']) : 0,
|
|
'add_user' => $admin_id,
|
|
'update_user' => $admin_id
|
|
]);
|
|
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/12 13:40
|
|
*/
|
|
public static function edit(array $params,$admin_id): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
CustomFollow::where('id', $params['id'])->update([
|
|
'custom_id' => $params['custom_id'],
|
|
'name' => $params['name'],
|
|
'date' => !empty($params['date']) ? strtotime($params['date']) : 0,
|
|
'types' => $params['types'],
|
|
'description' => $params['description'] ?? '',
|
|
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
|
'coordinate' => $params['coordinate'] ?? '',
|
|
'executor' => $params['executor'] ?? '',
|
|
'next_follow_date' => !empty($params['next_follow_date']) ? strtotime($params['next_follow_date']) : 0,
|
|
'update_user' => $admin_id,
|
|
'update_time' => time()
|
|
]);
|
|
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/12 13:40
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return CustomFollow::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取详情
|
|
* @param $params
|
|
* @return array
|
|
* @author likeadmin
|
|
* @date 2023/11/12 13:40
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
$data = CustomFollow::field('id,custom_id,name,date,types,description,annex,coordinate,next_follow_date,executor')->findOrEmpty($params['id']);
|
|
$custom = Custom::field('name,master_name')->where('id',$data['custom_id'])->findOrEmpty();
|
|
$data['custom_name'] = $custom['name'];
|
|
$data['custom_master_name'] = $custom['master_name'];
|
|
return $data->toArray();
|
|
}
|
|
} |