This commit is contained in:
2024-10-29 14:04:59 +08:00
commit 48bf3e6f33
2839 changed files with 762707 additions and 0 deletions

573
app/api/common.php Executable file
View File

@@ -0,0 +1,573 @@
<?php
use think\Loader;
use think\Config;
use think\Request;
use \app\common\model\ProductBkImage;
/**
* 把两个日期格式的字符串转化成unix时间戳,然后相减获得时间戳差,最后判断剩余时间,生成类似(2小时30分钟20秒前发布)这样的时间格式。
* $time_s int 起始日期的Unix时间
* $time_n int 当前日期的Unix时间
*/
define('COUNTRY_CODE', 'ZH');
function getHMStime($time_s, $time_n) {
//$time_s = strtotime($time_s);
//$time_n = strtotime($time_n);
//$time_n = time();
$strtime = '';
$time = $time_n - $time_s;
if ($time >= 86400) {
return $strtime = date('Y-m-d H:i', $time_s);
}
if ($time >= 3600) {
$strtime .= intval($time / 3600) . '小时';
$time = $time % 3600;
} else {
$strtime .= '';
}
if ($time >= 60) {
$strtime .= intval($time / 60) . '分钟';
$time = $time % 60;
} else {
$strtime .= '';
}
if ($time > 0) {
$strtime .= intval($time) . '秒前';
} else {
$strtime = '时间错误';
}
return $strtime;
}
/**
* 计算剩余天时分。
* $unixEndTime string 终止日期的Unix时间
*/
function getDHMtime($unixEndTime = 0) {
if ($unixEndTime <= time()) { // 如果过了活动终止日期
return '0天0时0分';
}
// 使用当前日期时间到活动截至日期时间的毫秒数来计算剩余天时分
$time = $unixEndTime - time();
$days = 0;
if ($time >= 86400) { // 如果大于1天
$days = (int) ($time / 86400);
$time = $time % 86400; // 计算天后剩余的毫秒数
}
$xiaoshi = 0;
if ($time >= 3600) { // 如果大于1小时
$xiaoshi = (int) ($time / 3600);
$time = $time % 3600; // 计算小时后剩余的毫秒数
}
$fen = (int) ($time / 60); // 剩下的毫秒数都算作分
return $days . '天' . $xiaoshi . '时' . $fen . '分';
}
function getDifferentProduct($type, $limit = 12, $where = array(), $order = array()) {
if (empty($limit)) {
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
}
$arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);//print_r($where);die;
$arg_field = ['id', 'cid', 'name', 'shortname', 'sort', 'ishot', 'isnew', 'recommend', 'viewcount', 'tags', 'description', 'picture', 'picture_back', 'bk_img', 'bk_img_back','list_bk_img', 'createtime'];
$bkinfo = ['id','product_id','image_url','image_bk_color','image_color','original_url'];
switch ($type) {
case 'recommend':
// $arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['recommend'] = 1;
$bkid = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);//print_r($bkid);die;
$id = '';
$result = '';
foreach ($bkid as $v){
$where= $id['product_id'] = $v['id'];//print_r($where);die;
$arr = Loader::model('ProductBkImg')->getList($where, array_merge($order), $bkinfo, $limit);
$result[]= $arr;
}
$result['info'] = $bkid;
//print_r($result);die;
break;
case 'headline':
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['headline'] = 1;
$result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
case 'ishot':
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['ishot'] = 1;
$result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
case 'isnew':
$arg_order['sort'] = 'asc';
$arg_order ['id'] = 'desc';
$arg_where['isnew'] = 1;
$result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
default:
if (!empty($order)) {
$arg_order = $order;
}
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$result = Loader::model('Product')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
}
return $result;
}
function getDifferentArticle($type, $limit = 12, $where = array(), $order = array()) {
if (empty($limit)) {
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
}
$arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);
//$arg_where['is_onsale'] = 1;
$arg_field = ['id', 'cid', 'name', 'sort', 'headline', 'ishot', 'recommend', 'zancount', 'viewcount', 'description', 'picture', 'createtime'];
switch ($type) {
case 'recommend':
$arg_order['createtime'] = 'desc';
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['recommend'] = 1;
$result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
case 'headline':
$arg_order['createtime'] = 'desc';
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['headline'] = 1;
$result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
case 'ishot':
$arg_order['createtime'] = 'desc';
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['ishot'] = 1;
$result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
default:
$arg_order['createtime'] = 'desc';
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
}
return $result;
}
function getDifferentVideo($type, $limit = 12, $where = array(), $order = array()) {
if (empty($limit)) {
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
}
$arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);
//$arg_where['is_onsale'] = 1;
$arg_field = ['id', 'cid', 'name', 'sort', 'headline', 'ishot', 'recommend', 'viewcount', 'videopath', 'videourl', 'description', 'picture', 'createtime'];
switch ($type) {
case 'recommend':
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['recommend'] = 1;
$result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
$arg_where['headline'] = 1;
if (Config ::get('news_headline')) {
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
} else {
$arg_order['id'] = 'desc';
}
case 'headline':
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['headline'] = 1;
$result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
case 'ishot':
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['ishot'] = 1;
$result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
default:
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
}
return $result;
}
function getDifferentDownload($type, $limit = 12, $where = array(), $order = array()) {
if (empty($limit)) {
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
}
$arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);
//$arg_where['is_onsale'] = 1;
$arg_field = ['id', 'cid', 'name', 'sort', 'headline', 'ishot', 'recommend', 'app_model', 'support_os', 'format', 'viewcount', 'downloadcount', 'description', 'picture', 'tags', 'downloadpath', 'downloadpath64', 'createtime'];
switch ($type) {
case 'recommend':
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['recommend'] = 1;
$result = Loader::model('Download')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
$arg_where['headline'] = 1;
if (Config ::get('news_headline')) {
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
} else {
$arg_order['id'] = 'desc';
}
case 'headline':
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['headline'] = 1;
$result = Loader::model('Download')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
case 'ishot':
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$arg_where['ishot'] = 1;
$result = Loader::model('Download')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
default:
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$result = Loader::model('Download')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
}
return $result;
}
function getProductChildCate($pid, $limit = 12, $where = array(), $order = array()) {
$argc_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);
$argc_field = ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'isshow', 'recommend', 'picture', 'createtime'];
$argc_order['sort'] = 'asc';
$argc_order['id'] = 'desc';
$argc_where['pid'] = $pid;
$result = Loader::model('ProductCategory')->getList($argc_where, array_merge($argc_order, $order), $argc_field, $limit);
return $result;
}
function getArticleChildCate($pid, $limit = 12, $where = array(), $order = array()) {
$argc_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);
$argc_field = ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'isshow', 'recommend', 'picture', 'createtime'];
$argc_order['sort'] = 'asc';
$argc_order['id'] = 'desc';
$argc_where['pid'] = $pid;
$result = Loader::model('ArticleCategory')->getList($argc_where, array_merge($argc_order, $order), $argc_field, $limit);
return $result;
}
function getCateProduct($cid, $limit = 12, $where = array(), $haschild = false, $order = array()) {
$arg_where = array_merge(['p.stat' => 0,'p.is_show' => 0, 'c.stat' => 0, 'p.country_code' => COUNTRY_CODE], $where);
$arg_field = ['p.id', 'p.cid', 'p.name', 'p.shortname', 'p.sort', 'p.ishot', 'p.isnew', 'p.recommend', 'p.viewcount', 'p.tags', 'p.description', 'p.picture','p.list_bk_img', 'p.picture_back', 'p.createtime', 'p.createtime', 'c.name' => 'categoryname', 'c.id' => 'categoryid'];
$arg_order['p.sort'] = 'asc';
$arg_order['p.id'] = 'desc';
if ($haschild && $cid) {
$cidarray = Loader::model('ProductCategory')->getChildIDArray($cid);
$arg_where['p.cid'] = ['in', $cidarray];
} else {
$arg_where['p.cid'] = $cid;
}
$result = Loader::model('Product')->getCateProductList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
return
$result;
}
function getCateoneProduct($cid, $limit = 12, $where = array(), $haschild = false, $order = array()) {
$arg_where = array_merge(['p.stat' => 0, 'c.stat' => 0, 'p.is_show' => 0, 'p.country_code' => COUNTRY_CODE], $where);
$arg_field = ['p.bk_img_back_color','p.bk_img_color','p.picture_back_color','p.picture_color','p.id', 'p.cid', 'p.name', 'p.shortname', 'p.sort', 'p.ishot', 'p.isnew','p.brand_id', 'p.recommend', 'p.viewcount', 'p.tags','p.list_bk_img', 'p.description', 'p.picture', 'p.picture_back', 'p.createtime', 'p.createtime', 'c.name' => 'categoryname', 'c.id' => 'categoryid'];
$arg_order['p.id'] = 'desc';
$arg_order['p.sort'] = 'asc';
if ($haschild && $cid) {
$cidarray = Loader::model('ProductCategory')->getChildIDArray($cid);
$arg_where['p.cid'] = ['in', $cidarray];
// tiaoshi($arg_where);die;
} else {
$arg_where['p.cid'] = $cid;
}
$result = Loader::model('Product')->getCateProductList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
// echo \think\Db::table('Product')->getLastSql();die;
// 获取二级图片
foreach ($result as $key => $value) {
$res = model('ProductTwoImg')->field('image_url,image_bk_color,image_color,original_url,product_id,id,image_color')->where(['product_id' => $value['id'], 'stat' => 0])->select();
// echo model('ProductTwoImg')->getLastSql();die;
$result[$key]['product_two_img'] = $res;
}
// tiaoshi($result);die;
return $result;
}
function getCateArticle($cid, $limit = 12, $where = array(), $haschild = false, $order = array()) {
$arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);
$arg_field = ['id', 'cid', 'name', 'sort', 'headline', 'ishot', 'recommend', 'viewcount', 'description', 'picture', 'createtime'];
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
if ($haschild && $cid) {
$cidarray = Loader::model('ArticleCategory')->getChildIDArray($cid);
$arg_where['cid'] = ['in', $cidarray];
} else {
$arg_where['cid'] = $cid;
}
$result = Loader::model('Article')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
return $result;
}
function getCateVideo($cid, $limit = 12, $where = array(), $haschild = false, $order = array()) {
$arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);
$arg_field = ['id', 'cid', 'name', 'product', 'sort', 'headline', 'ishot', 'recommend', 'tags', 'playcount', 'description', 'picture', 'videopath', 'createtime'];
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
if ($haschild && $cid) {
$cidarray = Loader::model('VideoCategory')->getChildIDArray($cid);
$arg_where['cid'] = ['in', $cidarray];
} else {
$arg_where['cid'] = $cid;
} $result = Loader::model('Video')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
return $result;
}
function getBannerList($tid = 0, $limit = 12, $where = array(), $field = array('*'), $order = array()) {
$arg_where = array_merge(['stat' => 0, 'country_code' => COUNTRY_CODE], $where);
$arg_order = ['sort' => 'asc', 'id' => 'desc'];
$arg_field = $field;
if ($tid) {
$arg_where['typeid'] = $tid;
}
$result = Loader::model('Banner')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
return $result;
}
function getBanner($id = 0) {
$result = Loader::model('Banner')->getRow($id);
return $result;
}
function getFlink($tid = 0, $limit = 12, $where = array(), $field = array('*'), $order = array()) {
$arg_where = array_merge(['stat' => 0], $where);
$arg_order = ['sort' => 'asc', 'id' => 'desc'];
$arg_field = $field;
if ($tid) {
$arg_where['typeid'] = $tid;
}
$result = Loader::model('Flink')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
return $result;
}
function getQuestion($limit = 12, $where = array(), $order = array()) {
if (empty($limit)) {
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
}
$arg_where = array_merge(['stat' => 0], $where);
$arg_field = ['*'];
$arg_order = ['sort' =>
'asc', 'id' => 'desc'];
$result = Loader::model('Question')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
return $result;
}
// function getProduct($id = 0) {
// $result = Loader::model('Product')->getRow(['id'=> $id], ['id', 'name']);
// return $result;
// }
function getProductCount($cid, $where = array(), $haschild = false) {
$arg_where = array_merge(['stat' =>0, 'is_show'=>0,'country_code' => COUNTRY_CODE], $where);
if ($haschild && $cid) {
$cidarray = Loader::model('ProductCategory')->getChildIDArray($cid);
$arg_where['cid'] = ['in', $cidarray];
} else {
$arg_where['cid'] = $cid;
}
$result = Loader::model('Product')->where($arg_where)->count();
return $result;
}
// function getArticleCategory($id = 0) {
// $result = Loader::model('ArticleCategory')->getRow(['id' => $id], ['id', 'name']);
// return $result;
// }
function getSinglepageChild($pid, $limit = 12, $where = array(), $order = array()) {
$argc_where = array_merge(['stat' => 0], $where);
$argc_field = ['id', 'pid', 'name', 'description', 'sort', 'isshow', 'recommend', 'picture', 'content', 'createtime'];
$argc_order['sort'] = 'asc';
$argc_order['id'] = 'desc';
$argc_where['pid'] = $pid;
$result = Loader:: model('Singlepage')->getList($argc_where, array_merge($argc_order, $order), $argc_field, $limit);
return $result;
}
function getSinglepage($id = 0) {
$result = Loader::model('Singlepag e')->getRow($id, ['id', 'pid', 'name', 'description', 'sort', 'isshow', 'recommend', 'picture', 'content', 'createtime']);
return $result;
}
function getDifferentPinglun($type, $limit = 12, $where = array(), $order = array()) {
if (empty($limit)) {
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
}
$arg_where = array_merge(['stat' => 0, 'display' => 1], $where);
$arg_field = ['id', 'pid', 'customer_id', 'cname', 'content_id', 'typeid', 'ishot', 'content', 'tx', 'createtime', 'ip', 'display'];
switch ($type) {
case 'ishot':
$arg_order['id'] = 'desc';
$arg_where['ishot'] = 1;
$result = Loader::model('Pinglun')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
default:
if (!empty($order)) {
$arg_order = $order;
}
$arg_order['sort'] = 'asc';
$arg_order['id'] = 'desc';
$result = Loader::model('Pinglun')->getList($arg_where, array_merge($arg_order, $order), $arg_field, $limit);
break;
}
return $result;
}
function getBkImag($type, $limit = 12, $where = array(), $order = array()){
/*$result = \app\common\model\Product::where("recommend",1)->field('id,cid')->with("ProductImg")->limit($limit)->select();*/
//print_r($type);die;
$where = ['recommend'=>1,'stat'=>0, 'country_code' => COUNTRY_CODE];
$result = \app\common\model\Product::where($where)
->field('id,cid,name,shortname')
->with(["ProductImg"=>function($query){
/** @var $query \think\db\Query */
$query->field('image_url,image_bk_color,image_color,original_url,product_id,id');
}])
// ->where('id', 130)
->order('id desc')
->select();
/** @var $result array */
$result = collection($result)->toArray();
return $result;
}
function getSonCategoryProduct($parent_id)
{
if (empty($parent_id)) {
return "无父ID";
}
$where = ['recommend'=>1,'stat'=>0, 'is_show' => 0];
$result = \app\common\model\Product::where('cid', 'in', function ($query) use ($parent_id) {
/** @var $query \think\db\Query */
$query->table('cod_product_category')->where('pid', $parent_id)->field('id');
})->with(["ProductImg"=>function($query){
/** @var $query \think\db\Query */
$query->field('image_url,image_bk_color,image_color,original_url,product_id,id');
}])->where($where)
->field('id,cid,name,shortname')
->select();
if (!empty($result)) {
$result = collection($result)->toArray();
}
return $result;
}
function getCateColor($cid, $limit, $where = array(), $haschild = false, $order = array()) {
$where = ['stat'=>0,'cid'=>$cid, 'country_code' => COUNTRY_CODE, 'is_show' => 0];
$result = \app\common\model\Product::where($where)
->field('id,cid,name,brand_id')
->with(["ProductTwoImg"=>function($query){
/** @var $query \think\db\Query */
$query->where('stat',0)->field('image_url,image_bk_color,image_color,original_url,product_id,id,image_color');
}])
->limit($limit)
->order($order)
->select();
/** @var $result array */
$result = collection($result)->toArray();
return $result;
}
function getProductReated($id,$limit = 12, $where = array(), $haschild = false, $order = array()){
$where = ['product_id'=>$id,'stat'=>0, 'country_code' => COUNTRY_CODE];//print_r($where);die;
$result = Loader::model('ProductTwoImg')->where($where)->field('image_url')->select();
$result = collection($result)->toArray();//var_dump($result);die;
return $result;
}
/*没有上级分类的爆款查询*/
function getCategoryProduct($parent_id)
{//print_r($parent_id);die;
if (empty($parent_id)) {
return "无父ID";
}
$where = ['recommend'=>1,'stat'=>0,'cid'=>$parent_id, 'is_show' => 0];
$result = \app\common\model\Product::where($where)
->field('id,cid,name,shortname')
->with(["ProductImg"=>function($query){
/** @var $query \think\db\Query */
$query->field('image_url,image_bk_color,image_color,original_url,product_id,id');
}])
// ->limit('sort')
->order('id desc')
->select();
/** @var $result array */
$result = collection($result)->toArray();
return $result;
}
/*没有上级的产品查询*/
function getProductColor($pid,$limit){
if(empty($pid)){
return "无父级ID";
}
$where = ['stat'=>0,'is_show'=>0,'cid'=>$pid, 'country_code' => COUNTRY_CODE];
$result = \app\common\model\Product::where($where)
->field('id,cid,name,shortname')
->with(["ProductTwoImg"=>function($query){
/** @var $query \think\db\Query */
$query->where('stat',0)->field('image_url,image_bk_color,image_color,original_url,product_id,id,image_color');
}])
->limit($limit)
->order('id desc')
->select();
/** @var $result array */
$result = collection($result)->toArray();//print_r($result);die;
return $result;
}
// 判断是否手机端官网
/*function isMobile() {
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
if (isset($_SERVER['HTTP_VIA'])) {
// 找不到为flase,否则为true
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
}
// 脑残法,判断手机发送的客户端标志,兼容性有待提高。其中'MicroMessenger'是电脑微信
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$clientkeywords = array('nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile','MicroMessenger');
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
return true;
}
}
// 协议法,因为有可能不准确,放到最后判断
if (isset ($_SERVER['HTTP_ACCEPT'])) {
// 如果只支持wml并且不支持html那一定是移动设备
// 如果支持wml和html但是wml在html之前则是移动设备
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
return true;
}
}
return false;
}*/

30
app/api/config.php Executable file
View File

@@ -0,0 +1,30 @@
<?php
return [
//管理员用户ID
'user_administrator' => 0,
//是否启用布局
'template' => [
'layout_on' => false,
'layout_name' => 'public/layout',
// 模板路径
//'view_path' => __DIR__ . '/view/',
// 模板后缀
'view_suffix' => 'phtml',
// 模板文件名分隔符
//'view_depr' => DS,
],
'view_replace_str' => [
'__PUBLIC__' => '/frontend',
//'__TEMPLATE__' => '/public/static',wqeqwe
'__PREFIX__' => '',
// '__ORICOROOT__' => 'http://us.orico.cc',
'__ORICOROOT__' => 'https://www.orico.com.cn'
],
//分页配置
'paginate' => [
'type' => '\pagination\FrontPagination',
'var_page' => 'page',
'list_rows' => 12,
],
];

View File

@@ -0,0 +1,33 @@
<?php
namespace app\api\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
use app\common\controller\BaseController as Controller;
//<!--#include file="([0-9a-zA-Z/._-]+?)\.html" -->
class BaseController extends Controller {
//当前用户
protected $customer_id = 0;
protected $country_code = 'US';
public function __construct() {
parent::__construct();
}
// 初始化
protected function _initialize() {
parent::_initialize();
$this->country_code = 'US';
$this->customer_id = is_session_login('customer');
}
}

View File

@@ -0,0 +1,95 @@
<?php
//declare (strict_types = 1);
namespace app\api\controller;
class KafkaProducer
{
private $topic_name = 'log-const-total-data'; // kafka队列 topic
private $username = 'dolog'; // 队列账号
private $password = 'kafka_log_Aa-1221'; // 队列密码
private $brokerList = '127.0.0.1:9092';
public function send()
{
$data = request()->post();
$sign_data['action_logs'] = $data['action_logs'];
$sign_data['api_logs'] = $data['api_logs'];
$sign_data['lg_logs_view'] = $data['lg_logs_view'];
$sign_data['lg_task_queue'] = $data['lg_task_queue'];
$sign = $this->getSign($sign_data);
if ( empty($data['sign']) ) {
return error('签名为空');
}
if ( $sign !== $data['sign'] ) {
return error('签名错误');
}
if ( empty($data['action_logs']) && empty($data['api_logs']) && empty($data['lg_logs_view']) && empty($data['lg_task_queue']) ) {
return error('日志内容为空');
}
if ( !empty($data['action_logs']) ) {
$action_logs = unserialize($data['action_logs']);
}
if ( !empty($data['api_logs']) ) {
$api_logs = unserialize($data['api_logs']);
}
if ( !empty($data['lg_logs_view']) ) {
$lg_logs_view = unserialize($data['lg_logs_view']);
}
if ( !empty($data['lg_task_queue']) ) {
$lg_task_queue = unserialize($data['lg_task_queue']);
}
$do_add_logs = [['logs_action'=>$action_logs],['logs_api'=>$api_logs],['logs_view'=>$lg_logs_view],['task_queue'=>$lg_task_queue]];
$message = json_encode($do_add_logs);
$topic = $this->topic_name;
try{
$this->producer($message, $topic);
return success('日志写入成功');
}catch(Exception $e){
return error('日志写入失败');
}
}
/*
* 签名
* */
public function getSign($param)
{
ksort($param);
$signStr = "logsmonitor";
$secretKey = 'logsmonitorscretlist';
foreach ( $param as $key => $value ) {
$signStr = $signStr . $key . "=" . $value . "&";
}
$signStr = substr($signStr, 0, -1);
$signature = base64_encode(hash_hmac("sha1", $signStr, $secretKey, true));
return $signature;
}
public function producer($message, $topic = 'log-const-total-data')
{
$conf = new \RdKafka\Conf();
$conf->set('sasl.mechanisms', 'PLAIN');
$conf->set('security.protocol', 'sasl_plaintext');
$conf->set('sasl.username', $this->username);
$conf->set('sasl.password', $this->password);
$conf->set('socket.keepalive.enable', 'true'); // socket不操持保持长连
$conf->set('log.connection.close', 'false'); // 静默所有自发断开连接日志
$conf->set('metadata.broker.list', $this->brokerList);
$producer = new \RdKafka\Producer($conf);
$topic = $producer->newTopic($topic);
$topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($message));
$producer->poll(0);
$result = $producer->flush(10000);
if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) {
throw new Exception('Was unable to flush, messages might be lost!');
}
}
}

630
app/api/controller/Sync.php Executable file
View File

@@ -0,0 +1,630 @@
<?php
namespace app\api\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\TransDb;
class Sync extends BaseController {
private $topic_name = 'orico-inquiry-data'; // kafka队列 topic
private $groupid = 'OricoInquiry_Queue'; // 队列group
private $brokers = '218.76.52.20:9092'; // kafka broker
//多服务器地址
//$rk->addBrokers("127.0.0.1:9092,127.0.0.2:9092");
private $username = 'OricoInquiry'; // 队列账号
private $password = 'kafka_orico_inquiry-f2b211-1221'; // 队列密码
private $retries = 3; // 程序异常重试次数
protected function configure()
{
// 指令配置
$this->setName('NewKafkaConsumer')
->setDescription('the NewKafkaConsumer command');
}
private function init_search(&$search){
$search['name'] = '';
$search['timebegin'] = '';
$search['timeend'] = '';
}
//Kafka 消息日志
public function send()
{
$data = request()->post();
$sign_data['action_logs'] = $data['action_logs'];
$sign_data['api_logs'] = $data['api_logs'];
$sign_data['lg_logs_view'] = $data['lg_logs_view'];
$sign_data['lg_task_queue'] = $data['lg_task_queue'];
$sign = $this->getSign($sign_data);
if ( empty($data['sign']) ) {
return error('签名为空');
}
if ( $sign !== $data['sign'] ) {
return error('签名错误');
}
if ( empty($data['action_logs']) && empty($data['api_logs']) && empty($data['lg_logs_view']) && empty($data['lg_task_queue']) ) {
return error('日志内容为空');
}
if ( !empty($data['action_logs']) ) {
$action_logs = unserialize($data['action_logs']);
}
if ( !empty($data['api_logs']) ) {
$api_logs = unserialize($data['api_logs']);
}
if ( !empty($data['lg_logs_view']) ) {
$lg_logs_view = unserialize($data['lg_logs_view']);
}
if ( !empty($data['lg_task_queue']) ) {
$lg_task_queue = unserialize($data['lg_task_queue']);
}
$do_add_logs = [['logs_action'=>$action_logs],['logs_api'=>$api_logs],['logs_view'=>$lg_logs_view],['task_queue'=>$lg_task_queue]];
$message = json_encode($do_add_logs);
$topic = $this->topic_name;
try{
$this->producer($message, $topic);
return success('日志写入成功');
}catch(Exception $e){
return error('日志写入失败');
}
}
/*
* 签名
* */
public function getSign($param)
{
ksort($param);
$signStr = "logsmonitor";
$secretKey = 'logsmonitorscretlist';
foreach ( $param as $key => $value ) {
$signStr = $signStr . $key . "=" . $value . "&";
}
$signStr = substr($signStr, 0, -1);
$signature = base64_encode(hash_hmac("sha1", $signStr, $secretKey, true));
return $signature;
}
//Kafka 创建生产者
public function producer($message, $topic = 'orico-inquiry-data')
{
$conf = new \RdKafka\Conf();
$conf->set('sasl.mechanisms', 'PLAIN');
$conf->set('security.protocol', 'sasl_plaintext');
$conf->set('sasl.username', $this->username);
$conf->set('sasl.password', $this->password);
$conf->set('socket.keepalive.enable', 'true'); // socket不操持保持长连
$conf->set('log.connection.close', 'false'); // 静默所有自发断开连接日志
$conf->set('metadata.broker.list', $this->brokers);
$producer = new \RdKafka\Producer($conf);
$topic = $producer->newTopic($topic);
$topic->produce(RD_KAFKA_PARTITION_UA, 0, json_encode($message));
$producer->poll(0);
// sleep(2);
$result = $producer->flush(10000);
if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) {
throw new Exception('Was unable to flush, messages might be lost!');
}
return 1;
}
//Become a Distributor/Reseller 成为代理/经销商
public function Distributor(){
$agent = Db('agents');
$data = $this->request->param();
$arg_where = ['stat' => ['in','0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['name|interest|phone'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['createtime'], ['<=', $time]);
}
}
// $list = $agent->where($arg_where)->select();
//$count = count($list);
$list = $agent->where($arg_where)->order('id DESC')->select();
//$page = $list->render();
$dataFeed = array();
// dump($list);exit;
try {
foreach($list as $key =>$item) {
$feedBack = array();
$feedBack['name'] = $item['name']." ".$item['last_name'];
$feedBack['phone'] = $item['phone'];
$feedBack['email'] = $item['email'];
$feedBack['website'] = $item['uri'];
$feedBack['company'] = $item['company'];
$feedBack['country_timezone_id'] = $item['state'];
$feedBack['create_time'] = $item['createtime'];
$feedBack['industry'] = '';
$feedBack['bbs_account'] = '';
$feedBack['inquiry_subject'] = '';
$feedBack['inquiry_content'] = '';
$feedBack['interest_products'] = $item['interest'];
$feedBack['inquiry_source_page'] = $item['url'];
$feedBack['agent_country'] = $item['country'];
$feedBack['feedback_refer'] = $item['refer'];
$feedBack['feedback_ip'] = $item['ip'];
$feedBack['feedback_country'] = $item['state'];
$feedBack['feedback_province'] = $item['province'];
$feedBack['feedback_city'] = $item['city'];
$feedBack['inquiry_device'] = $item['drvice'];
$feedBack['feedback_type'] = 1;
$dataFeed['lg_task_queue'][] = array(
'database'=>'orico_cms',//数据库
'module'=>'customer',//模块
'worked'=>'add',//事务
'data_feed'=>json_encode($feedBack),//数据
'create_time'=>date("Y-m-d H:i:s"),//执行开始时间
'end_time'=>'',//执行结束时间
'elapsed_time'=>'',//耗时
'stat'=>2,//状态
'create_uid' =>'1',//数据提交人ID
//'sql'=>'',//消息为执行SQL语句
'api_url'=>'https://dev.crm.api.f2b211.com/admin/v2_0/inquiry',//消费请求调用接口
'token'=>'efbdb6337a837ecfd36240276b74108c',//消费请求调用接口令牌
'method'=>'POST',//消费请求试GET、POST
'post_data'=>json_encode($feedBack),//消费请求传参
);
}
$dataFeed['database'] = 'orico_cms';
$dataFeed['dotype'] = 'queue';
print_r($this->producer($dataFeed));
} catch (\Exception $e) {
echo $e->getMessage();
}
/*try{
$this->producer($message, $topic);
return success('日志写入成功');
}catch(Exception $e){
return error('日志写入失败');
}
/*while($rk->getOutQlen() > 0) {
$rk->poll(50);
}*/
//echo json_encode($feedBack);
}
public function Odm(){
$bulk = Db('bulk');
$data = $this->request->param();
$arg_where = ['stat' => ['in','0,1'], 'country_code' =>$this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['first_name|last_name|interested|phone'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['createtime'], ['<=', $time]);
}
}
//$where = ['stat'=>0];
$list = $bulk->where($arg_where)->order('id DESC')->select();
//$count = count($list);
//$list = $bulk->where($arg_where)->order('id DESC')->paginate(20,$count);
//$page = $list->render();
$feedBack = array();
try {
foreach($list as $key =>$item) {
$feedBack['website'] = '';
$feedBack['bbs_account'] = '';
$feedBack['industry'] = '';
$feedBack['inquiry_subject'] = '';
$feedBack['agent_country'] = '';
$feedBack['name'] = $item['first_name']." ".$item['last_name'];
$feedBack['phone'] = $item['phone'];
$feedBack['email'] = $item['email'];
$feedBack['company'] = $item['company'];
$feedBack['country_timezone_id'] = $item['country'];
$feedBack['create_time'] = $item['createtime'];
$feedBack['interest_products'] = $item['interested'];
$feedBack['inquiry_content'] = $item['message'];
$feedBack['inquiry_source_page'] = $item['refer_url'];
$feedBack['feedback_refer'] = $item['refer'];
$feedBack['feedback_ip'] = $item['ip'];
$feedBack['feedback_country'] = $item['state'];
$feedBack['feedback_province'] = $item['province'];
$feedBack['feedback_city'] = $item['city'];
$feedBack['inquiry_device'] = $item['drvice'];
$feedBack['feedback_type'] = 2;
$dataFeed['lg_task_queue'][] = array(
'database'=>'orico_cms',//数据库
'module'=>'customer',//模块
'worked'=>'add',//事务
'data_feed'=>json_encode($feedBack),//数据
'create_time'=>date("Y-m-d H:i:s"),//执行开始时间
'end_time'=>'',//执行结束时间
'elapsed_time'=>'',//耗时
'stat'=>2,//状态
'create_uid' =>'1',//数据提交人ID
//'sql'=>'',//消息为执行SQL语句
'api_url'=>'https://dev.crm.api.f2b211.com/admin/v2_0/inquiry',//消费请求调用接口
'token'=>'efbdb6337a837ecfd36240276b74108c',//消费请求调用接口令牌
'method'=>'POST',//消费请求试GET、POST
'post_data'=>json_encode($feedBack),//消费请求传参
);
}
$dataFeed['database'] = 'orico_cms';
$dataFeed['dotype'] = 'queue';
print_r($this->producer($dataFeed));
} catch (\Exception $e) {
echo $e->getMessage();
}
}
//OEM&ODM Service OEM/ODM服务
public function Bulk(){
$BulkInquiry = Db('bulk_inquiry');
$data = $this->request->param();
$arg_where = ['stat' => ['in','0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['first_name']) && $data['first_name'] != ''){
$arg_where['first_name|last_name|interest|phone'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['createtime'], ['<=', $time]);
}
}
//
//$where = ['stat'=>0];
$list = $BulkInquiry->where($arg_where)->order('id DESC')->select();
//$count = count($list);
//$list = $BulkInquiry->where($arg_where)->order('id DESC')->paginate(20,$count);
try {
$feedBack = array();
foreach($list as $key =>$item) {
$feedBack['website'] = '';
$feedBack['bbs_account'] = '';
$feedBack['country_timezone_id'] = '';
$feedBack['industry'] = '';
$feedBack['inquiry_subject'] = '';
$feedBack['agent_country'] = '';
$feedBack['name'] = $item['first_name']." ".$item['last_name'];
$feedBack['phone'] = $item['phone'];
$feedBack['email'] = $item['email'];
$feedBack['company'] = $item['company'];
$feedBack['create_time'] = $item['createtime'];
$feedBack['interest_products'] = $item['interest'];
$feedBack['inquiry_content'] = $item['message'];
$feedBack['inquiry_source_page'] = $item['url'];
$feedBack['feedback_refer'] = $item['refer'];
$feedBack['feedback_ip'] = $item['ip'];
$feedBack['feedback_country'] = $item['state'];
$feedBack['feedback_province'] = $item['province'];
$feedBack['feedback_city'] = $item['city'];
$feedBack['inquiry_device'] = $item['drvice'];
$feedBack['feedback_type'] = 2;
$dataFeed['lg_task_queue'][] = array(
'database'=>'orico_cms',//数据库
'module'=>'customer',//模块
'worked'=>'add',//事务
'data_feed'=>json_encode($feedBack),//数据
'create_time'=>date("Y-m-d H:i:s"),//执行开始时间
'end_time'=>'',//执行结束时间
'elapsed_time'=>'',//耗时
'stat'=>2,//状态
'create_uid' =>'1',//数据提交人ID
//'sql'=>'',//消息为执行SQL语句
'api_url'=>'https://dev.crm.api.f2b211.com/admin/v2_0/inquiry',//消费请求调用接口
'token'=>'efbdb6337a837ecfd36240276b74108c',//消费请求调用接口令牌
'method'=>'POST',//消费请求试GET、POST
'post_data'=>json_encode($feedBack),//消费请求传参
);
}
$dataFeed['database'] = 'orico_cms';
$dataFeed['dotype'] = 'queue';
print_r($this->producer($dataFeed));
} catch (\Exception $e) {
echo $e->getMessage();
}
}
//Bulk Buy 批量采购
public function Inquiry(){
$inquiry = Db('inquiry');
$data = $this->request->param();
$arg_where = ['stat' => ['in','0,1'], 'country_code' => $this->country_code];
$search = [];
$this->init_search($search);
if (isset($data['name']) && $data['name'] != ''){
$arg_where['first_name|last_name|inquiry|phone'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
if ((isset($data['timebegin']) && $data['timebegin'] != '') || (isset($data['timeend']) && $data['timeend'] != '')){
// 时间有一个不为空就初始化
$arg_where['createtime'] = [];
if (isset($data['timebegin']) && $data['timebegin'] != '')
{
$time = $data['timebegin'];
array_push($arg_where['createtime'], ['>=', $time]);
$search['timebegin'] = $data['timebegin'];
}
else{
array_push($arg_where['createtime'], ['>=', "0000-00-00"]);
}
if (isset($data['timeend']) && $data['timeend'] != '')
{
$time = $data['timeend'];
array_push($arg_where['createtime'], ['<=', $time]);
$search['timeend'] = $data['timeend'];
}
else{
$time = date('Y-m-d H:i:s',strtotime('+1 month'));
array_push($arg_where['createtime'], ['<=', $time]);
}
}
$list = $inquiry->where($arg_where)->order('id DESC')->select();
//$count = count($list);
//$list = $inquiry->where($arg_where)->order('id DESC')->paginate(20,$count);
try {
$feedBack = array();
foreach($list as $key =>$item) {
$feedBack['website'] = '';
$feedBack['bbs_account'] = '';
$feedBack['agent_country'] = '';
$feedBack['name'] = $item['first_name']." ".$item['last_name'];
$feedBack['phone'] = $item['phone'];
$feedBack['email'] = $item['email'];
$feedBack['company'] = $item['company'];
$feedBack['country_timezone_id'] = $item['country'];
$feedBack['create_time'] = $item['createtime'];
$feedBack['industry'] = $item['industry'];
$feedBack['create_time'] = $item['createtime'];
$feedBack['inquiry_subject'] = $item['interested'];
$feedBack['interest_products'] = $item['model'];
$feedBack['inquiry_content'] = $item['inquiry'];
$feedBack['inquiry_source_page'] = $item['murl'];
$feedBack['feedback_refer'] = $item['refer'];
$feedBack['feedback_ip'] = $item['ip'];
$feedBack['feedback_country'] = $item['state'];
$feedBack['feedback_province'] = $item['province'];
$feedBack['feedback_city'] = $item['city'];
$feedBack['inquiry_device'] = $item['drvice'];
$feedBack['feedback_type'] = 0;
$dataFeed['lg_task_queue'][] = array(
'database'=>'orico_cms',//数据库
'module'=>'customer',//模块
'worked'=>'add',//事务
'data_feed'=>json_encode($feedBack),//数据
'create_time'=>date("Y-m-d H:i:s"),//执行开始时间
'end_time'=>'',//执行结束时间
'elapsed_time'=>'',//耗时
'stat'=>2,//状态
'create_uid' =>'1',//数据提交人ID
//'sql'=>'',//消息为执行SQL语句
'api_url'=>'https://dev.crm.api.f2b211.com/admin/v2_0/inquiry',//消费请求调用接口
'token'=>'efbdb6337a837ecfd36240276b74108c',//消费请求调用接口令牌
'method'=>'POST',//消费请求试GET、POST
'post_data'=>json_encode($feedBack),//消费请求传参
);
}
$dataFeed['database'] = 'orico_cms';
$dataFeed['dotype'] = 'queue';
print_r($this->producer($dataFeed));
} catch (\Exception $e) {
echo $e->getMessage();
}
}
//Contact 反馈所有类型问题
public function Msgform() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['feedback_type' => ['in','Pre-sales Inquiry,OEM&ODM Service,Become a Distributor/Reseller,Bulk Buy,Media Cooperation'],'stat' => ['eq', 0]];
$arg_order = ['id' => 'desc'];
$arg_field = ['*'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['cname|content'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
} else {
$search['skeyword'] = '';
}
$dataObject = Loader::model('Msgform')->getPageList($arg_where, $arg_order, $arg_field, 12);
$list=$dataObject->isEmpty() ? null : $dataObject->items(); //$dataObject->getCollection()->toArray()
$feedBack = array();
$feedType = array(
"Pre-sales Inquiry" => 0,
"Become a Distributor/Reseller" => 1,
"OEM&ODM Service" => 2,
"Bulk Buy" => 3,
"Media Cooperation" => 4,
"After Sales Support" =>5 ,
);
try {
foreach($list as $key =>$item) {
$feedBack['name'] = $item['name'];
$feedBack['website'] = '';
$feedBack['bbs_account'] = '';
$feedBack['interest_products'] = '';
$feedBack['agent_country'] = '';
$feedBack['phone'] = '';
$feedBack['email'] = $item['contact'];
$feedBack['company'] = '';
$feedBack['country_timezone_id'] = $item['country'];
$feedBack['industry'] = '';
$feedBack['create_time'] = $item['createtime'];
$feedBack['inquiry_subject'] = $item['subject'];
$feedBack['inquiry_content'] = $item['content'];
$feedBack['inquiry_source_page'] = $item['url'];
$feedBack['feedback_refer'] = $item['refer'];
$feedBack['feedback_ip'] = $item['ip'];
$feedBack['feedback_country'] = $item['state'];
$feedBack['feedback_province'] = $item['province'];
$feedBack['feedback_city'] = $item['city'];
$feedBack['inquiry_device'] = $item['drvice'];
$feedBack['feedback_type'] = isset($feedType[$item['feedback_type']]) ? trim($feedType[$item['feedback_type']]): '';
$dataFeed['lg_task_queue'][] = array(
'database'=>'orico_cms',//数据库
'module'=>'customer',//模块
'worked'=>'add',//事务
'data_feed'=>json_encode($feedBack),//数据
'create_time'=>date("Y-m-d H:i:s"),//执行开始时间
'end_time'=>'',//执行结束时间
'elapsed_time'=>'',//耗时
'stat'=>2,//状态
'create_uid' =>'1',//数据提交人ID
//'sql'=>'',//消息为执行SQL语句
'api_url'=>'https://dev.crm.api.f2b211.com/admin/v2_0/inquiry',//消费请求调用接口
'token'=>'efbdb6337a837ecfd36240276b74108c',//消费请求调用接口令牌
'method'=>'POST',//消费请求试GET、POST
'post_data'=>json_encode($feedBack),//消费请求传参
);
}
$dataFeed['database'] = 'orico_cms';
$dataFeed['dotype'] = 'queue';
print_r($this->producer($dataFeed));
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}

View File

@@ -0,0 +1,116 @@
<?php
//declare (strict_types = 1);
namespace app\api\controller;
use think\Loader;
use think\Cookie;
use think\Config;
use think\Session;
class TrackProducer extends BaseController
{
private $topic_name = 'log-const-total-data'; // kafka队列 topic
private $username = 'dolog'; // 队列账号
private $password = 'kafka_log_Aa-1221'; // 队列密码
private $brokerList = '127.0.0.1:9092';
public function etime()
{
$data = request()->get();
$useragent = $_SERVER['HTTP_USER_AGENT'];
$ip = get_ip();
$address = GetIpLookup($ip);
//echo $ip."<pre>=="; print_r($address);die;
$url = getpageurl();
$keywords =getKeywords($url);
$curUrl = parse_url($url);
$host = $curUrl['host'];
$feed = array(
"items" => 'ORICO Official',
"forum" => $controller,
"forum_code" => $controller,
"url" => $url,
"refer" => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $url,
"channel" => isset($keywords['channel']) ? $keywords['channel'] : $host,
"channel_type" => isset($keywords['channel']) ?$keywords['channel'] :'1',
"keyword" => isset($keywords['search']) ?$keywords['search'] :'',
"start_time" => date("y-m-d H:i:s"),
"ip" => $ip,
"country" => isset($address['country']) ? $address['country'] :'',
"province" => isset($address['province']) ? $address['province'] :'',
"city" => isset($address['city']) ? $address['city'] :'',
"drive" => isMobile() ? "H5": "PC",
"system" => getOs($useragent),
"brower" => getBroswer($useragent),
"uuid" => $data['uuid'],
"end_time" => date("y-m-d H:i:s"),
"elapsed_time" => $data['dt'],
);
$feed = http_build_query($feed);
$result = CurlRequest('https://producer.datamaster.cc/api/v1/browser_logs/send', $feed);
$res = json_decode($result, true);
return $this->json(200, 'ok');
}
public function records()
{
$data = $this->request->post();
if (empty($data) || !is_array($data))
return $this->json(-1, 'Data error ');
$useragent = $data['user_agent'];
$ip = get_ip();
$address = GetIpLookup($ip);
//echo $ip."<pre>=="; print_r($address);die;
$url = $data['url'];
$keywords =getKeywords($url);
$arr_url = parse_url($url);
$content = pregReplaceImg($data['content'],'https://'.$arr_url['host']);
$fds = array(
"items" => 'ORICO Official',
"forum" => $data['forum'],
"forum_code" => $data['forum'],
"url" => $data['url'],
"refer" =>isset($data['refer']) ? $data['refer'] : $arr_url['host'],
"channel" => isset($keywords['channel']) ? $keywords['channel'] : $arr_url['host'],
"channel_type" => isset($keywords['channel']) ?$keywords['channel'] :'1',
"keyword" => isset($keywords['search']) ?$keywords['search'] :'',
"start_time" => date("y-m-d H:i:s"),
"ip" => $ip,
"country" => isset($address['country']) ? $address['country'] :'',
"province" => isset($address['province']) ? $address['province'] :'',
"city" => isset($address['city']) ? $address['city'] :'',
"content" => $content,
"drive" => $data['drive'],
"event_type" => $data['event_type'],
"system" => getOs($useragent),
"brower" => getBroswer($useragent),
);
$feeds = http_build_query($fds);
$result = CurlRequest('https://producer.datamaster.cc/api/v1/action_logs/send', $feeds);
$res = json_decode($result, true);
return $this->json(200, 'ok');
}
}

15
app/api/tags.php Executable file
View File

@@ -0,0 +1,15 @@
<?php
/**
* 行为扩展
*/
return [
'module_init' => [
'app\\common\\behavior\\SystemConfig',
],
'action_begin' => [
],
'user_behavior' => [
]
];