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

573 lines
24 KiB
PHP
Executable File

<?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;
}*/