Files
2024-10-29 14:04:59 +08:00

119 lines
4.4 KiB
PHP
Executable File

<?php
namespace app\us\controller;
use think\Loader;
use think\Cookie;
use think\Config;
use think\Session;
class Bulk extends BaseController {
public function Bulk() {
return $this->view->fetch();
}
public function detail($id = 0) {
if ($id > 0) {
return $this->fetch();
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id) {
/*$view = Cookie::get('articleview', 'history'); //print_r($history);exit;
if (empty($view) || $view != $id) {
Loader::model('Article')->where(['id' => $id])->setInc('viewcount');
Cookie::set('articleview', $id, ['prefix' => 'history', 'expire' => 3600]);
}*/
}
protected function historyarticle($id) {
/*$article = Cookie::get('article', 'history'); //print_r($history);exit;
if (isset($article) && !empty($article)) {
$article_ids = explode(',', $article);
if ($article_ids[0] != $id) {
array_unshift($article_ids, $id);
$article_ids = array_unique($article_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$article_ids = array_slice($article_ids, 0, $num);
while (count($article_ids) > $num) {
array_pop($article_ids);
}
Cookie::set('article', implode(',', $article_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('article', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}*/
}
public function create()
{
$data = $this->request->post();
if (empty($data) || !is_array($data))
return $this->json(403, 'Data error ');
if ($data['name'] == '' && $data['last_name'])
return $this->json(403-3, 'Your name cannot be empty');
if ($data['email'] == '')
return $this->json(403-4, 'Email cannot be empty');
// if ($data['buy_source'] == '')
// return $this->json(-5, '购买渠道不能为空');
/*if ($data['customer_telephone'] != '' && !preg_match("/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/", $data['customer_telephone']))
return $this->json(-6, 'Phone format error ');*/
if ($data['email'] != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['email']))
return $this->json(403-6, 'Email Address format error');
$referer = isset($data['refer']) ? $data['refer'] : '';
$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$searchFeed = getKeywords($referer);
$channel = isset($searchFeed['channel']) ? $searchFeed['channel'] : '';
$keyword = isset($searchFeed['search']) ? $searchFeed['search'] : '';
$fed = visitLog();
$insert_data = [
'company' => isset($data['company']) ? $data['company'] : '',
'first_name' => $data['name'],
'last_name' => isset($data['last_name']) ?$data['last_name'] : '',
'email' => $data['email'],
'phone' => isset($data['last_name']) ? $data['phone'] : '',
'country' => isset($data['last_name']) ? $data['country'] : '',
'interested' => isset($data['last_name']) ? $data['interested'] : '',
'message' => $data['message'],
'ip' => get_ip(),
'refer_url' => $_SERVER["HTTP_REFERER"],
'createtime' => date("Y-m-d H:i:s"),
'siteid' => $this->siteid,
'country_code' => $this->country_code,
'refer' => $referer,
'url' => $url,
'channels' => $channel,
'keyword' => $keyword,
'state' => $fed['country'],
'province' => $fed['province'],
'city' => $fed['city'],
'drvice' => $fed['drive'],
'user_agent' => $fed['system']." ".$fed['brower'],
];
$result = model('Bulk')->insert($insert_data);
if (!$result)
return $this->json(201, 'Failure to submit');
return $this->json(200, 'ok');
}
}