projectmanager/app/api/controller/Businessinfo.php
2025-06-25 11:52:01 +08:00

118 lines
4.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @copyright Copyright (c)
* @company 美天智能科技
* @author 李志强
* @link http://www.meteteme.com
*/
declare(strict_types=1);
namespace app\api\controller;
use app\api\BaseController;
use think\facade\Db;
class BusinessInfo extends BaseController
{
//商机填写接口
public function bifill()
{
// 允许来自kd.meteteme.top的跨域请求
header('Access-Control-Allow-Origin: https://kd.meteteme.top');
header('Access-Control-Allow-Origin: http://test1.mete.com/');
header('Access-Control-Allow-Headers: Content-Type');
// 获取表单数据
$name = isset($_POST['name']) ? $_POST['name'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$ip = isset($_POST['ip']) ? $_POST['ip'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$product = isset($_POST['product']) ? $_POST['product'] : '';
$company = isset($_POST['company']) ? $_POST['company'] : '';
$create_time = time();
// 判断表单数据是否完整
if ($name && $message && $product) {
// 向数据库插入数据
$result = Db::name('Information')->insert([
'name' => $name,
'email' => $email,
'phone' => $phone,
'ip' => $ip,
'message' => $message,
'product' => $product,
'company' => $company,
'create_time' => $create_time,
]);
// 判断插入结果
if ($result) {
$webhook = 'https://oapi.dingtalk.com/robot/send?access_token=c39726abd36659f92442847430eda90bebb360c438270f7c05bea388f1c8168c';
$title = '**有新的商机生成!**';
$line = '------------------------------';
$companynames = '公司名称:' . $company;
$names = '联 系 人 ' . $name;
$contents = '请及时进入项管系统查看!';
$times = '创建日期:' . date('Y-m-d H:i:s', $create_time);
$data = array(
'msgtype' => 'actionCard',
'actionCard' => array(
'title' => $title,
'text' => $title . "\n\n" . $companynames . "\n\n" . $names . "\n\n" . $times,
'btnOrientation' => '0',
'btns' => [
[
'title' => '查看商机',
'actionURL' => 'dingtalk://dingtalkclient/page/link?url=' . urlencode('https://project.meteteme.com/business_info/index/index') . '&pc_slide=false'
]
]
)
);
$options = array(
'http' => array(
'header' => "Content-type: application/json",
'method' => 'POST',
'content' => json_encode($data),
)
);
$context = stream_context_create($options);
$result = file_get_contents($webhook, false, $context);
// return json(['code' => 0, 'msg' => '留言提交成功!']);
return json([
'code' => 0,
'msg' => '留言提交成功!',
'data' => [
'name' => $name,
'email' => $email,
'phone' => $phone,
'ip' => $ip,
'message' => $message,
'product' => $product,
'company' => $company,
'create_time' => date('Y-m-d H:i:s', $create_time)
]
]);
} else {
return json(['code' => 1, 'msg' => '留言提交失败!']);
}
} else {
return json(['code' => 2, 'msg' => '请填写完整的表单数据!']);
}
}
//获取产品信息
public function product_info()
{
// 查询Product表中的所有产品信息
$products = Db::name('Product')->field('id, name')->select();
// 返回产品信息数组给前端包括id和name
return json(['code' => 0, 'msg' => '获取产品信息成功', 'data' => $products]);
}
}