94 lines
3.3 KiB
PHP
94 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* @copyright Copyright (c) 2023-2024 美天智能科技
|
|
* @author 李志强
|
|
* @link http://www.meteteme.com
|
|
*/
|
|
declare(strict_types=1);
|
|
namespace app\api\controller;
|
|
|
|
use app\api\BaseController;
|
|
use think\facade\Db;
|
|
|
|
class Business extends BaseController
|
|
{
|
|
//添加联系人
|
|
public function add_contact()
|
|
{
|
|
$param = get_params();
|
|
if (request()->isPost()) {
|
|
$has = Db::name('Businesscontact')->where(['contact' => $param['contact'], 'phone' => $param['phone'], 'business_id' => $param['business_id']])->find();
|
|
if (!empty($has)) {
|
|
to_assign(1, '该联系人已经存在');
|
|
}
|
|
$param['admin_id'] = $this->uid;
|
|
$param['create_time'] = time();
|
|
$res = Db::name('Businesscontact')->strict(false)->field(true)->insert($param);
|
|
if ($res) {
|
|
$log_data = array(
|
|
'module' => 'businesscontact',
|
|
'field' => 'contact',
|
|
'action' => 'add',
|
|
'admin_id' => $this->uid,
|
|
'new_content' => $param['contact'],
|
|
'create_time' => time(),
|
|
);
|
|
Db::name('Log')->strict(false)->field(true)->insert($log_data);
|
|
return to_assign(0, "添加联系人成功!");
|
|
}
|
|
}
|
|
}
|
|
|
|
//编辑联系人
|
|
public function edit_contact()
|
|
{
|
|
$param = get_params();
|
|
print_r($param);
|
|
if (request()->isPost()) {
|
|
$param['admin_id'] = $this->uid;
|
|
$param['update_time'] = time();
|
|
$res = Db::name('Businesscontact')->where('id', $param['id'])->strict(false)->field(true)->update($param);
|
|
// $res = Db::name('Businesscontact')->where('id',$param['id'])->strict(false)->field(true)->update($param);
|
|
if ($res) {
|
|
$log_data = array(
|
|
'module' => 'businesscontact',
|
|
'field' => 'contact',
|
|
'action' => 'edit',
|
|
'admin_id' => $this->uid,
|
|
'new_content' => $param['contact'],
|
|
'update_time' => time(),
|
|
);
|
|
Db::name('Log')->strict(false)->field(true)->insert($log_data);
|
|
return to_assign(0, "修改联系人成功!");
|
|
}
|
|
}
|
|
}
|
|
|
|
//删除联系人
|
|
public function delete_contact()
|
|
{
|
|
if (request()->isDelete()) {
|
|
$id = get_params("id");
|
|
$time = time();
|
|
$module = 'Business';
|
|
$detail = Db::name('Businesscontact')->where('id', $id)->find();
|
|
if (Db::name('Businesscontact')->where('id', $id)->update(['delete_time' => $time]) !== false) {
|
|
$log_data = array(
|
|
'field' => 'contact',
|
|
'action' => 'delete',
|
|
'admin_id' => $this->uid,
|
|
'new_content' => $detail['contact'],
|
|
'create_time' => $time,
|
|
'module' => $module,
|
|
|
|
);
|
|
Db::name('Log')->strict(false)->field(true)->insert($log_data);
|
|
return to_assign(0, "删除成功");
|
|
} else {
|
|
return to_assign(0, "删除失败");
|
|
}
|
|
} else {
|
|
return to_assign(1, "错误的请求");
|
|
}
|
|
}
|
|
} |