更新命名问题
This commit is contained in:
@@ -11,12 +11,57 @@ namespace app\information\controller;
|
||||
use app\base\BaseController;
|
||||
use app\model\Information as InformationList;
|
||||
use app\business_info\validate\InformationCheck;
|
||||
use Error;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class Index extends BaseController
|
||||
{
|
||||
// 查询 IP 地址
|
||||
public function ipquery($ip)
|
||||
{
|
||||
$url = "https://cn.apihz.cn/api/ip/chaapi.php?ip={$ip}&id=10001344&key=3cffc3ad20630afffe65c3b908d6ebd4";
|
||||
$response = @file_get_contents($url);
|
||||
if ($response) {
|
||||
$ipData = json_decode($response, true);
|
||||
if ($ipData && isset($ipData['ip'])) {
|
||||
$q = "{$ipData['msg']}({$ipData['ip']})";
|
||||
if (is_string($q)) {
|
||||
return $q;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '接口每分钟查询次数用完,请稍后再试';
|
||||
}
|
||||
|
||||
public function translateToChinese($q)
|
||||
{
|
||||
$id = 10001344;
|
||||
$key = '3cffc3ad20630afffe65c3b908d6ebd4 ';
|
||||
|
||||
// 构造请求URL
|
||||
$url = "https://cn.apihz.cn/api/zici/fanyiapihz.php?id=" . $id . "&key=" . $key . "&words=" . $q . "&ytype=1&etype=2&htype=0";
|
||||
|
||||
//调试输出语句
|
||||
var_dump($url);
|
||||
|
||||
// 发送请求并获取响应
|
||||
$response = @file_get_contents($url);
|
||||
|
||||
// 处理响应
|
||||
if ($response) {
|
||||
$data = json_decode($response, true);
|
||||
if (isset($data['translation'][0])) {
|
||||
return $data['translation'][0]; // 返回翻译结果
|
||||
}
|
||||
}
|
||||
|
||||
// 返回错误信息
|
||||
return $q;
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
@@ -28,21 +73,23 @@ class Index extends BaseController
|
||||
->order('id desc')
|
||||
->paginate($rows, false, ['query' => $param])
|
||||
->each(function ($item, $key) {
|
||||
$bi = Db::name('Information')->where(['id' => $item->id])->find();
|
||||
|
||||
// 获取对应product id的name
|
||||
$product = Db::name('Product')->where(['id' => $bi['product']])->find();
|
||||
$productName = $product ? $product['name'] : '';
|
||||
|
||||
$item->name = $bi['name'];
|
||||
$item->email = $bi['email'];
|
||||
$item->phone = $bi['phone'];
|
||||
$item->message = $bi['message'];
|
||||
$item->product = $productName; // 将产品名称传递给前端
|
||||
$item->company = $bi['company'];
|
||||
$item->create_time = $bi['create_time'];
|
||||
$item->update_time = $bi['update_time'];
|
||||
$item->delete_time = $bi['delete_time'];
|
||||
// 这里简化查询逻辑,避免重复查询
|
||||
$item->product = Db::name('Product')->where('id', $item->product)->value('name') ?: '';
|
||||
$item->ip = $this->ipquery($item->ip); // 调用 ipquery 方法查询 IP 数据
|
||||
switch ($item->status) {
|
||||
case 0:
|
||||
$item->status = '新商机';
|
||||
break;
|
||||
case 1:
|
||||
$item->status = '已跟进';
|
||||
break;
|
||||
case 2:
|
||||
$item->status = '已转化';
|
||||
break;
|
||||
case 3:
|
||||
$item->status = '已关闭';
|
||||
break;
|
||||
}
|
||||
})
|
||||
->filter(function ($item) {
|
||||
return $item->delete_time === null;
|
||||
@@ -60,7 +107,7 @@ class Index extends BaseController
|
||||
try {
|
||||
// 查询数据,分页设置每页10条
|
||||
$list = Db::name('Information')
|
||||
// ->field('id, title, content, create_time, update_time') // 选择所需字段
|
||||
// ->field('id, title, content, create_time, update_time') // 选择所需字段
|
||||
->order('id desc') // 按 id 倒序排序
|
||||
->paginate(10); // 每页10条记录
|
||||
|
||||
@@ -186,54 +233,12 @@ class Index extends BaseController
|
||||
$param = get_params();
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$detail = (new InformationList())->detail($id);
|
||||
// print_r($id);
|
||||
// print_r($id);
|
||||
if (empty($detail)) {
|
||||
return to_assign(1, '2.信息不存在');
|
||||
return to_assign(1, '无法查询到详情信息');
|
||||
} else {
|
||||
if ($this->uid != $detail['admin_id']) { // 当前登录用户必须是上传者才能查看
|
||||
return to_assign(1, '您没权限查看该信息');
|
||||
}
|
||||
$role_uid = [$detail['admin_id'], $detail['director_uid']];
|
||||
$role_edit = 'edit';
|
||||
$view_uid = $role_uid;
|
||||
// if (!empty($detail['check_admin_ids'])) {
|
||||
// $view_uid = array_merge($role_uid, explode(",", $detail['check_admin_ids']));
|
||||
// }
|
||||
if (!in_array($this->uid, $view_uid) && $detail['is_open'] == 1) {
|
||||
return to_assign(1, '您没权限查看该信息');
|
||||
}
|
||||
$contact_array = Db::name('Businesscontact')
|
||||
->field('i.id,i.business_id,i.contact,i.post,i.phone,i.email,i.wechat,i.qq,a.name as admin_name')
|
||||
->alias('i')
|
||||
->join('Admin a', 'i.admin_id = a.id', 'LEFT')
|
||||
->join('Information b', 'i.business_id = b.id', 'LEFT')
|
||||
->order('i.create_time desc')
|
||||
->where(array('i.business_id' => $id))
|
||||
->where('i.delete_time', null)
|
||||
->select()->toArray();
|
||||
|
||||
$file_array = Db::name('FileInterfix')
|
||||
->field('i.id,i.topic_id,i.admin_id,f.name,f.filesize,f.filepath,a.name as admin_name')
|
||||
->alias('i')
|
||||
->join('File f', 'i.file_id = f.id', 'LEFT')
|
||||
->join('Admin a', 'i.admin_id = a.id', 'LEFT')
|
||||
->order('i.create_time desc')
|
||||
->where(array('i.topic_id' => $id, 'i.module' => 'picbed'))
|
||||
->select()->toArray();
|
||||
|
||||
$link_array = Db::name('LinkInterfix')
|
||||
->field('i.id,i.topic_id,i.admin_id,i.desc,i.url,a.name as admin_name')
|
||||
->alias('i')
|
||||
->join('Admin a', 'i.admin_id = a.id', 'LEFT')
|
||||
->order('i.create_time desc')
|
||||
->where(array('i.topic_id' => $id, 'i.module' => 'picbed', 'delete_time' => 0))
|
||||
->select()->toArray();
|
||||
View::assign('detail', $detail);
|
||||
View::assign('contact_array', $contact_array);
|
||||
View::assign('file_array', $file_array);
|
||||
View::assign('link_array', $link_array);
|
||||
View::assign('role_edit', $role_edit);
|
||||
View::assign('id', $id);
|
||||
// print_r($detail);
|
||||
return view();
|
||||
}
|
||||
}
|
||||
@@ -267,4 +272,5 @@ class Index extends BaseController
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user