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

185
app/mobile/controller/Ad.php Executable file
View File

@@ -0,0 +1,185 @@
<?php
namespace app\mobile\controller;
use think\Lang;
use think\Loader;
use think\Config;
use app\common\controller\BaseController;
class Ad extends BaseController {
public function tags($tags = '', $num = 1) {
if ($tags) {
$nocache = $this->request->param('nocache', 0);
$cacheTag = 'ad-' . md5($tags);
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
if (empty($htmlbody)) {
$list = Loader::model('Ad')->getList(['stat' => ['eq', 0], 'tags' => $tags], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
if (empty($list)) {
$this->cacheTag('adTag')->set($cacheTag, "<!--\r\ndocument.write(\"<!--403-->\");\r\n-->\r\n");
exit;
}
$htmlbody = '';
$expire = 3600;
foreach ($list as $row) {
$adbody = '';
if ($row['timeset'] == 0) {
$adbody = $row['normbody'];
$exp = 0;
} else {
$ntime = time();
if ($ntime > $row['endtime'] || $ntime < $row['starttime']) {
$adbody = $row['expbody'];
$exp = $ntime < $row['starttime'] ? $row['starttime'] - $ntime : 0;
} else {
$adbody = $row['normbody'];
$exp = $row['endtime'] - $ntime;
}
}
$expire = $exp > 0 && $exp < $expire ? $exp : $expire;
$adbody = str_replace('"', '\"', $adbody);
$adbody = str_replace("\r", "\\r", $adbody);
$adbody = str_replace("\n", "\\n", $adbody);
$htmlbody .= "<!--\r\ndocument.write(\"{$adbody}\");\r\n-->\r\n";
//print_r($htmlbody);exit;
}
$this->cacheTag('adTag')->set($cacheTag, $htmlbody, $expire);
}
echo $htmlbody;
exit;
}
exit(' Error! ');
}
public function tagsli($tags = '', $num = 1) {
if ($tags) {
$nocache = $this->request->param('nocache', 0);
$cacheTag = 'ad-' . md5($tags);
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
if (empty($htmlbody)) {
$list = Loader::model('Ad')->getList(['stat' => ['eq', 0], 'tags' => $tags], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
if (empty($list)) {
$this->cacheTag('adTag')->set($cacheTag, "<!--\r\ndocument.write(\"<!--405-->\");\r\n-->\r\n");
exit;
}
$htmlbody = '';
$expire = 3600;
foreach ($list as $k => $row) {
$adbody = '';
if ($row['timeset'] == 0) {
$adbody = $row['normbody'];
$exp = 0;
} else {
$ntime = time();
if ($ntime > $row['endtime'] || $ntime < $row['starttime']) {
$adbody = $row['expbody'];
$exp = $ntime < $row['starttime'] ? $row['starttime'] - $ntime : 0;
} else {
$adbody = $row['normbody'];
$exp = $row['endtime'] - $ntime;
}
}
$expire = $exp > 0 && $exp < $expire ? $exp : $expire;
$adbody = str_replace('"', '\"', $adbody);
$adbody = str_replace("\r", "\\r", $adbody);
$adbody = str_replace("\n", "\\n", $adbody);
$htmlbody .= "<!--\r\ndocument.write(\"<li class=\\\"li" . ($k + 2) . "\\\">{$adbody}</li>\");\r\n-->\r\n";
//print_r($htmlbody);exit;
}
$this->cacheTag('adTag')->set($cacheTag, $htmlbody, $expire);
}
echo $htmlbody;
exit;
}
exit(' Error! ');
}
public function index($id = 0) {
if ($id > 0) {
$nocache = $this->request->param('nocache', 0);
$cacheTag = 'ad-' . $id;
$adbody = $nocache ? '' : $this->cacheGet($cacheTag);
if (empty($adbody)) {
$row = Loader::model('Ad')->where(['stat' => ['eq', 0], 'id' => $id])->find();
if (empty($row)) {
$this->cacheTag('adTag')->set($cacheTag, "<!--\r\ndocument.write(\"<!--406-->\");\r\n-->\r\n");
exit;
}
$adbody = '';
if ($row['timeset'] == 0) {
$adbody = $row['normbody'];
$expire = 0;
} else {
$ntime = time();
if ($ntime > $row['endtime'] || $ntime < $row['starttime']) {
$adbody = $row['expbody'];
$expire = $ntime < $row['starttime'] ? $row['starttime'] - $ntime : 0;
} else {
$adbody = $row['normbody'];
$expire = $row['endtime'] - $ntime;
}
}
$adbody = str_replace('"', '\"', $adbody);
$adbody = str_replace("\r", "\\r", $adbody);
$adbody = str_replace("\n", "\\n", $adbody);
$adbody = "<!--\r\ndocument.write(\"{$adbody}\");\r\n-->\r\n";
$this->cacheTag('adTag')->set($cacheTag, $adbody, $expire);
}
echo $adbody;
exit;
}
exit(' Error! ');
}
public function cat($id = '', $num = 1) {
if ($id) {
$nocache = $this->request->param('nocache', 0);
$cacheTag = 'ad-' . $id;
$htmlbody = $nocache ? '' : $this->cacheGet($cacheTag);
if (empty($htmlbody)) {
$list = Loader::model('Ad')->getList(['stat' => ['eq', 0], 'typeid' => $id], ['sort' => 'asc', 'id' => 'desc'], ['id', 'typeid', 'name', 'sort', 'tags', 'timeset', 'starttime', 'endtime', 'normbody', 'expbody'], $num);
if (empty($list)) {
$this->cacheTag('adTag')->set($cacheTag, "<!--\r\ndocument.write(\"<!--407-->\");\r\n-->\r\n");
exit;
}
$htmlbody = '';
$expire = 3600;
foreach ($list as $row) {
$adbody = '';
if ($row['timeset'] == 0) {
$adbody = $row['normbody'];
$exp = 0;
} else {
$ntime = time();
if ($ntime > $row['endtime'] || $ntime < $row['starttime']) {
$adbody = $row['expbody'];
$exp = $ntime < $row['starttime'] ? $row['starttime'] - $ntime : 0;
} else {
$adbody = $row['normbody'];
$exp = $row['endtime'] - $ntime;
}
}
$expire = $exp > 0 && $exp < $expire ? $exp : $expire;
$adbody = str_replace('"', '\"', $adbody);
$adbody = str_replace("\r", "\\r", $adbody);
$adbody = str_replace("\n", "\\n", $adbody);
$htmlbody .= "<!--\r\ndocument.write(\"{$adbody}\");\r\n-->\r\n";
}
$this->cacheTag('adTag')->set($cacheTag, $htmlbody, $expire);
}
echo $htmlbody;
exit;
}
exit(' Error! ');
}
public function previewjs($id) {
$id = intval($id);
if ($id > 0) {
echo '<script src="' . url('index/ad/index', ['id' => $id]) . '?nocache=1" language="javascript"></script>';
}
exit();
}
}

119
app/mobile/controller/Agents.php Executable file
View File

@@ -0,0 +1,119 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
use think\Session;
class Agents extends BaseController {
public function agents() {
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['company'] == '')
return $this->json(403-2, 'Company name cannot be empty');
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['country'] == '')
return $this->json(403-5, 'Distribution region 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'] : '';
$insert_data = [
'company' => $data['company'],
'uri' => $data['uri'],
'name' => $data['name'],
'last_name' => $data['last_name'],
'email' => $data['email'],
'phone' => trim($data['phone']),
'country' => $data['country'],
'interest' => $data['interested'],
'is_inventory' => $data['is_inventory'],
'createtime' => date("Y-m-d H:i:s"),
'siteid' => $this->siteid,
'country_code' => $this->country_code,
'refer' => $referer,
'url' => $url,
'channel' => $channel,
'keyword' => $keyword,
'ip' => $fed['ip'],
'state' => $fed['country'],
'province' => $fed['province'],
'city' => $fed['city'],
'drvice' => $fed['drive'],
'user_agent' => $fed['system']." ".$fed['brower'],
];
$result = model('agents')->insert($insert_data);
if (!$result)
return $this->json(201, 'Failure to submit');
return $this->json(200, 'ok');
}
}

View File

@@ -0,0 +1,361 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-07-25
* Time: 11:43
*/
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
use think\validate;
class Antifake extends BaseController
{
// public function anti_fake_inlet()
// {
// echo '系统维护中,请稍后再试!';exit;
// }
public function anti_fake_inlet()
{
$this->redirect("https://anti-fake-checking.com/index");
// $jssdk=new \JsSdk\JsSdk('wx0d4ac6d59abca442','489aaf23cf26f63346e1b456cb264099');
// $jssdk=new \JsSdk\JsSdk('wx0d4ac6d59abca442','c482b3f5d1354533e9e14ad294016551');
$jssdk=new \JsSdk\JsSdk('wxc0d2e35e015dd0fc','fe931c45ce3513d195c689de9ec1696f');
$signPackage = $jssdk->getSignPackage();
$this->assign('singpackage',$signPackage);
return $this->view->fetch('anti_fake_inlet');
}
public function index()
{
$this->redirect("https://anti-fake-checking.com/index");
return $this->view->fetch();
}
public function anti_fake_sninput()
{
$this->redirect("https://anti-fake-checking.com/index");
return $this->view->fetch();
}
public function anti_fake_input()
{
$this->redirect("https://anti-fake-checking.com/index");
return $this->view->fetch();
}
public function anti_fake_scan_snresult()
{
if(!request()->isAjax()){
$this->assign('sn',$this->request->get('qrresult'));
//return $this->fetch();
}
$post = $this->request->get();
// dump($post);
$fake = $post['qrresult'];
$fake = substr($fake,strripos($fake,",")+1);
$fake = str_replace('-','',$fake);
$ssd = Loader::model('Ssd');
$where = ['sn' => $fake];
$arr = $ssd->where($where)->find();
if ($arr) {
$data = $arr;//dump($data['sn']);die;
$data['result'] = 1;
$this->assign('data', $data);
//return json($data);
} else {
$postdata = ['sn'=>$fake];
$postdata = http_build_query($postdata);
$sn = CurlRequest('http://mes.orico.com.cn:8081/content/mes/web/api/fwm.aspx', $postdata);
$sn = json_decode($sn, true);
// $sn = json_decode($sn, true);//dump($sn);die;
if ($sn['result'] == 1) {
$data['sn'] = $fake;
$data['fake'] = '';
$data['specifications_and_models'] = $sn['specifications_and_models'];
$data['69_code'] = $sn['69_code'];
$data['production_date'] = $sn['production_date'];
$data['Customer_name'] = $sn['Customer_name'];
$data['delivery_time'] = $sn['delivery_time'];
$data['department'] = $sn['department'];
$data['made_up_articles_name'] = $sn['made_up_articles_name'];
$data['chicktime'] = date("Y-m-d H:i:s");
$time = strtotime($data['delivery_time']);
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+5year", $time));
$bm = ['速卖通运营部','速卖通运营部','美国新蛋','海外亚马逊','ODM项目部','子品牌事业部','B2B营销中心','海外渠道部'];
// if(in_array($data['department'],$bm)){
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+1 month",strtotime($data['mendtime'])));
// }
$data['material_ID'] = $sn['material_ID'];
$where = ['sku'=>$data['specifications_and_models']];
$productid = Loader::model('product_sku')->where($where)->find();
$img = Loader::model('product_two_img')->where(['product_id'=>$productid['product_id']])->find();
$img = $img['image_url'];
$data['img']=$img;
$add = $ssd->save($data);
$data['result'] = $sn['result'];
$this->assign('data',$data);
//return json($data);
} else {
$data['sn']=$fake;
$data['result'] = $sn['result'];
$this->assign('data',$data);
// return json($data);
}
}
return $this->fetch();
}
public function anti_fake_scan_result()
{
if(!request()->isAjax()){
$this->assign('sn',$this->request->get('qrresult'));
//return $this->fetch();
}
$post = $this->request->get();
$fake = $post['qrresult'];
$ssd = Loader::model('Ssd');
$where = ['fake' => $fake];
$arr = $ssd->where($where)->find();
if ($arr) {
$data = $arr;//dump($data['sn']);die;
$data['result'] = 1;
$data['first'] = 0;
$this->assign('data', $data);
//return json($data);
} else {
$postdata = ['fwm'=>$fake];
$postdata = http_build_query($postdata);
$sn = CurlRequest('http://mes.orico.com.cn:8081/content/mes/web/api/fwm.aspx', $postdata);
$sn = json_decode($sn, true);
// $sn = json_decode($sn, true);
if ($sn['result'] == 1) {
$data['sn'] = $sn['serial_number'];
$data['fake'] = $fake;
$data['specifications_and_models'] = $sn['specifications_and_models'];
$data['69_code'] = $sn['69_code'];
$data['production_date'] = $sn['production_date'];
$data['Customer_name'] = $sn['Customer_name'];
$data['delivery_time'] = $sn['delivery_time'];
$data['department'] = $sn['department'];
$data['made_up_articles_name'] = $sn['made_up_articles_name'];
$data['chicktime'] = date("Y-m-d H:i:s");
$time = strtotime($data['delivery_time']);
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+5year", $time));
$bm = ['速卖通运营部','速卖通运营部','美国新蛋','海外亚马逊','ODM项目部','子品牌事业部','B2B营销中心','海外渠道部'];
if(in_array($data['department'],$bm)){
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+1 month",strtotime($data['mendtime'])));
}
$data['material_ID'] = $sn['material_ID'];
$where = ['sku'=>$data['specifications_and_models']];
$productid = Loader::model('product_sku')->where($where)->find();
$img = Loader::model('product_two_img')->where(['product_id'=>$productid['product_id']])->find();
$img = $img['image_url'];
$data['img']=$img;
$add = $ssd->save($data);
$data['result'] = $sn['result'];
$data['first'] = 1;
$this->assign('data',$data);
//return json($data);
} else {
$data['fake']=$fake;
$data['first'] = 0;
$data['result'] = $sn['result'];
$this->assign('data',$data);
// return json($data);
}
}
return $this->fetch();
}
public function anti_fake_snresult()
{
if ($_POST) {
$post = $this->request->post();
if($post['sn']==''){
$this->error('请输入SN码');
}
//$this->verify_check($post['captcha'], 'authcode') || $this->error('验证码有误', url('fake/index'));
$snnum = $post['sn'];
$ssd = Loader::model('Ssd');
$where = ['sn' => $post['sn']];
$arr = $ssd->where($where)->find();
if ($arr) {
$data = $arr;//dump($data['sn']);die;
$data['result'] = 1;
$this->assign('data', $data);
} else {
$sn = https_request('http://mes.orico.com.cn:8081/content/mes/web/api/fwm.aspx', $snnum);
$sn = json_decode($sn, true);
//$sn = json_decode($sn, true);
if ($sn['result'] == 1) {
$data['sn'] = $sn['serial_number'];
$data['fake'] = '';
$data['specifications_and_models'] = $sn['specifications_and_models'];
$data['69_code'] = $sn['69_code'];
$data['production_date'] = $sn['production_date'];
$data['Customer_name'] = $sn['Customer_name'];
$data['delivery_time'] = $sn['delivery_time'];
$data['department'] = $sn['department'];
$data['made_up_articles_name'] = $sn['made_up_articles_name'];
$data['chicktime'] = date("Y-m-d H:i:s");
$time = strtotime($data['delivery_time']);
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+5year", $time));
$bm = ['速卖通运营部','速卖通运营部','美国新蛋','海外亚马逊','ODM项目部','子品牌事业部','B2B营销中心','海外渠道部'];
if(in_array($data['department'],$bm)){
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+1 month",strtotime($data['mendtime'])));
}
$data['material_ID'] = $sn['material_ID'];
$where = ['sku'=>$data['specifications_and_models']];
$productid = Loader::model('product_sku')->where($where)->find();
$img = Loader::model('product_two_img')->where(['product_id'=>$productid['product_id']])->find();
$img = $img['image_url'];
$data['img']=$img;
$add = $ssd->save($data);
$data['result'] = $sn['result'];
$this->assign('data',$data);
} else {
$data['sn']=$snnum;
$data['result'] = $sn['result'];
$this->assign('data',$data);
}
}
}
return $this->fetch();
}
public function anti_fake_result()
{
if ($_POST) {
$post = $this->request->post();
if($post['fake']==''){
$this->error('请输入防伪码');
}
//$this->verify_check($post['captcha'], 'authcode') || $this->error('验证码有误', url('fake/index'));
$fake = $post['fake'];
$ssd = Loader::model('Ssd');
$where = ['fake' => $fake];
$arr = $ssd->where($where)->find();
if ($arr) {
$data = $arr;//dump($data['sn']);die;
$data['result'] = 1;
$this->assign('data', $data);
} else {
$sn = https_request('http://mes.orico.com.cn:8081/content/mes/web/api/fwm.aspx', $fake);
$sn = json_decode($sn, true);
//$sn = json_decode($sn, true);//dump($sn);die;
if ($sn['result'] == 1) {
$data['sn'] = $sn['serial_number'];
$data['fake'] = $fake;
$data['specifications_and_models'] = $sn['specifications_and_models'];
$data['69_code'] = $sn['69_code'];
$data['production_date'] = $sn['production_date'];
$data['Customer_name'] = $sn['Customer_name'];
$data['delivery_time'] = $sn['delivery_time'];
$data['department'] = $sn['department'];
$data['made_up_articles_name'] = $sn['made_up_articles_name'];
$data['chicktime'] = date("Y-m-d H:i:s");
$time = strtotime($data['delivery_time']);
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+5year", $time));
$bm = ['速卖通运营部','速卖通运营部','美国新蛋','海外亚马逊','ODM项目部','子品牌事业部','B2B营销中心','海外渠道部'];
if(in_array($data['department'],$bm)){
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+1 month",strtotime($data['mendtime'])));
}
$data['material_ID'] = $sn['material_ID'];
$where = ['sku'=>$data['specifications_and_models']];
$productid = Loader::model('product_sku')->where($where)->find();
$img = Loader::model('product_two_img')->where(['product_id'=>$productid['product_id']])->find();
$img = $img['image_url'];
$data['img']=$img;
$add = $ssd->save($data);
$data['result'] = $sn['result'];
$this->assign('data',$data);
} else {
$data['fake']=$fake;
$data['result'] = $sn['result'];
$this->assign('data',$data);
}
}
}
return $this->fetch();
}
public function anti_fake_sn()
{
//if ($_POST) {
//$post = $this->request->post();
//if($post['sn']==''){
// $this->error('请输入SN码');
//}
//$this->verify_check($post['captcha'], 'authcode') || $this->error('验证码有误', url('fake/index'));
$fake = 'Q929T1Y3';
$postdata = ['sn'=>$fake];
$postdata = http_build_query($postdata);
$sn = https_request('http://mes.orico.com.cn:8081/content/mes/web/api/fwm.aspx', $fake);
//$sn = CurlRequest('http://mes.orico.com.cn:8081/content/mes/web/api/fwm.aspx', $postdata);
$sn = json_decode($sn, true);
echo "<pre>=="; print_r($sn);die;
//$sn = json_decode($sn, true);
if ($sn['result'] == 1) {
$data['sn'] = $sn['serial_number'];
$data['fake'] = '';
$data['specifications_and_models'] = $sn['specifications_and_models'];
$data['69_code'] = $sn['69_code'];
$data['production_date'] = $sn['production_date'];
$data['Customer_name'] = $sn['Customer_name'];
$data['delivery_time'] = $sn['delivery_time'];
$data['department'] = $sn['department'];
$data['made_up_articles_name'] = $sn['made_up_articles_name'];
$data['chicktime'] = date("Y-m-d H:i:s");
$time = strtotime($data['delivery_time']);
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+5year", $time));
$bm = ['速卖通运营部','速卖通运营部','美国新蛋','海外亚马逊','ODM项目部','子品牌事业部','B2B营销中心','海外渠道部'];
if(in_array($data['department'],$bm)){
$data['mendtime'] = date('Y-m-d H:i:s', strtotime("+1 month",strtotime($data['mendtime'])));
}
$data['material_ID'] = $sn['material_ID'];
$where = ['sku'=>$data['specifications_and_models']];
$productid = Loader::model('product_sku')->where($where)->find();
$img = Loader::model('product_two_img')->where(['product_id'=>$productid['product_id']])->find();
$img = $img['image_url'];
$data['img']=$img;
$add = $ssd->save($data);
$data['result'] = $sn['result'];
$this->assign('data',$data);
} else {
$data['sn']=$snnum;
$data['result'] = $sn['result'];
$this->assign('data',$data);
}
//}
return $this->fetch();
}
}

196
app/mobile/controller/Article.php Executable file
View File

@@ -0,0 +1,196 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
class Article extends BaseController {
public function lists() {
$arg_where = ['a.country_code' => $this->country_code];
$arg_order = ['a.id' => 'desc'];
$search = array();
$skeyword = $this->request->get('name', '', 'urldecode,strval');
if ($skeyword != '') {
$search['skeyword'] = $skeyword;
$arg_where['a.name'] =['like', '%' . $search['skeyword'] . '%'];
$search['name'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
}
$cate_list = model('article_category')->where(['country_code' => $this->country_code, 'pid' => 0, 'isshow' => 1, 'stat' => 0])->order(['sort' => 'asc'])->select();
$arg_where['a.cid'] = reset($cate_list)['id'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.jump_link','a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.writer', 'a.source', 'a.viewcount', 'a.zancount', 'a.commentcount', 'a.description', 'a.picture', 'a.tags', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Article')->getCateArticleLists($arg_where, $arg_order, $arg_field, 12);
//echo Loader::model('Article')->getLastSql(); die;
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
'category' => ['id' => reset($cate_list)['id'], 'name' => '新闻资讯'],
];
$value['cate_list'] = $cate_list;
$value['seo_title'] = config('article_seo_title')? : config('website_seo_title');
$value['seo_keyword'] = config('article_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('article_seo_description')? : config('website_seo_description');
$this->assign($value);
$this->assign('search',$search);
return $this->fetch();
}
public function catelists($id = 0) {
if ($id > 0) {
$category = Loader::model('ArticleCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$arg_where = ['cid' => $id, 'a.country_code' => $this->country_code];
$skeyword = $this->request->get('name', '', 'urldecode,strval');
if ($skeyword != '') {
$skeyword = trim($skeyword);
$search['skeyword'] = $skeyword;
$arg_where['a.name'] = ['like', '%' . $search['skeyword'] . '%'];
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
$value['search'] = $search;
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.jump_link', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.writer', 'a.source', 'a.viewcount', 'a.zancount', 'a.commentcount', 'a.description', 'a.picture', 'a.tags', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Article')->getCateArticleLists($arg_where, $arg_order, $arg_field, 8);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
//echo "<pre>=="; print_r($dataObject);die;
$cate_list = model('article_category')->where(['country_code' => $this->country_code, 'pid' => 0, 'isshow' => 1, 'stat' => 0])->order(['sort' => 'asc'])->select();
$value['cate_list'] = $cate_list;
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function detail($id = 0) {
if ($id > 0) {
//$jssdk=new \JsSdk\JsSdk('wx0d4ac6d59abca442','8103022bb6ed902eb5c685800a78fd51');
//$signPackage = $jssdk->getSignPackage();
//$this->assign('singpackage',$signPackage);
$article = Loader::model('Article')->getRow($id);
if (empty($article)) {
return exception('数据有误,请检查后再操作');
}
$category = Loader::model('ArticleCategory')->getRow($article['cid']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$template = $category['tempdetail'];
//$prev_detail = Loader::model('Article')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
//$next_detail = Loader::model('Article')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
$value = [
'detail' => $article,
//'addarticle' => $addarticle,
'category' => $category,
//'prev_detail' => $prev_detail,
//'next_detail' => $next_detail,
];
$arg_where = ['content_id' => $id, 'stat' => 0, 'display' => 1];
$arg_order = ['id' => 'desc'];
$arg_field = ['*'];
$dataObject = Loader::model('Pinglun')->getPageList($arg_where, $arg_order, $arg_field, 4);
$list = $dataObject->items();
foreach ($list as $key => $v) {
$list[$key]['headimg'] = '';
$result = Loader::model('customer')->where(['stat' => 0, 'id' => 23])->field('picture')->find();
if (!empty($result) && isset($result['picture'])) {
$list[$key]['headimg'] = $result['picture'];
}
}
$value['list'] = $dataObject->isEmpty() ? null : $list;
$value['total'] = $dataObject->total();
$value['seo_title'] = $article['seo_title']? : $article['name'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $article['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $article['seo_description']? : config('website_seo_description');
$this->assign($value);
$this->viewcount($id);
return $this->fetch($template);
} else {
return exception('数据有误,请检查后再操作');
}
}
public function zan($id = 0) {
$id = intval($id);
if ($id > 0) {
$article = Loader::model('Article')->getRow(['id' => $id], ['id', 'zancount']);
if (empty($article)) {
return $this->json(-1, '该新闻不存在');
}
$article['zancount'] = $article['zancount'] + 1;
$result = $article->save();
if ($result) {
return $this->json(1, '点赞成功',$article['zancount']);
} else {
return $this->json(-1, '点赞失败');
}
}
return $this->json(-1, 'id错误');
}
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]);
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace app\mobile\controller;
use think\Lang;
use think\Loader;
use think\Config;
use app\common\controller\BaseController;
class Authcode extends BaseController {
public function index($id = "") {
$verify = new \verify\Verify((array) Config::get('captcha'));
return $verify->entry($id);
}
/**
* 验证码
*/
public function check($code, $id = '') {
return $this->verify_check($code, $id);
}
/**
* 验证码
*/
public function verify($id = '') {
return $this->verify_build($id);
}
}

View File

@@ -0,0 +1,325 @@
<?php
namespace app\mobile\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
use think\Cookie;
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 = 'ZH';
public function __construct() {
parent::__construct();
}
// 初始化
protected function _initialize() {
parent::_initialize();
if ($this->check_true_login())
{
$customer_info = json_decode(Cookie::get('c'), true);
$this->view->assign('customer_info', $customer_info);
$this->customer_id = $customer_info['id'];
$this->customer_info = $customer_info;
}
else
{
$this->_logout();
}
$this->view->assign('seo_title', (string) Config::get('website_seo_title'));
$this->view->assign('seo_keyword', (string) Config::get('website_seo_keyword'));
$this->view->assign('seo_description', (string) Config::get('website_seo_description'));
//$this->categoryList = $this->cacheGet('productCategoryList');
if (empty($this->productCategory)) {
$this->categoryList = Loader::model('ProductCategory')->getList(['stat' => 0, 'siteid' => $this->siteid,'isshow'=>1, 'country_code' => $this->country_code], ['sort' => 'asc', 'id' => 'asc'], ['id', 'pid', 'haschild', 'name', 'shortname', 'sort', 'description', 'isshow', 'recommend', 'picture', 'm_icon', 'image', 'icon']);
$this->cacheTag('ProductCategoryTag')->set('productCategoryList', $this->categoryList);
}
$this->productCategory = $this->list_to_tree($this->categoryList);
// tiaoshi($this->productCategory);die;
if ($this->cacheHas('country_list')) {
$this->country_list = $this->cacheGet('country_list');
} else {
$this->country_list = model('country')->where(['stat' => 0])->order(['sort' => 'asc'])->select();
$this->cacheSet('country_list', $this->country_list, 3600);
}
$website_email = (string) Config::get('website_email');
$this->view->assign('website_email', $website_email);
$website_phone = (string) Config::get('website_phone');
$this->view->assign('website_phone', $website_phone);
//搜索推荐产品
$search_views = Loader::model('Product')->where(['stat' => 0, 'siteid' => $this->siteid,'is_show'=>0, 'country_code' => $this->country_code])->limit(3)->order(['sort' => 'asc'])->select();
$this->view->assign('popular_list', $search_views);
//$historyList = getBannerList(79, 5);
$historyList = Loader::model('banner')->getList(['typeid'=>100,'stat' => 0, 'country_code' => COUNTRY_CODE], ['sort' => 'asc', 'id' => 'desc'], array('*'), 3);
$this->view->assign('historyList', $historyList);
//导航
$navigation =self::navInit();
$this->nav_header = $navigation['header'];
$this->nav_footer = $navigation['footer'];
$this->assign('nav_header', $this->nav_header);
$this->assign('nav_footer', $this->nav_footer);
$product_country_code = "products_".strtolower($this->country_code)."_color";
$productColor = config($product_country_code);
$this->view->assign('productColor', $productColor);
$this->view->assign('productCategory', $this->productCategory);
$this->view->assign('allCategoryList', $this->categoryList);
}
protected function buildTree($data, $pid = 0)
{
$tree = [];
foreach ($data as $val) {
if ($val['pid'] == $pid) {
$children = $this->buildTree($data, $val['id']);
if (!empty($children)) {
$val['items'] = $children;
}
$tree[] = $val;
}
}
return $tree;
}
/**
* nasNavigation 获取并组装nas专题页的top导航和footer
*/
protected function nasNavigation()
{
$navs = Loader::model('Navigation')->field([
'id',
'pid',
'name',
'url',
'value',
'data_type',
'is_new_window_open',
])
->where('stat', '=', 0)
->where('nav_type', '=', 'tops_nas_header')
->where('country_code', '=', $this->country_code)
->order('sort')
->select();
$navs_array = collection($navs)->toArray();
$header = $this->NavDataDealWith($navs_array);
$this->assign('nav_header', $this->buildTree($header));
}
//导航初始化
private function navInit(){
// 读取缓存数据
//$header = $this->cacheGet('cache_common_nav_header_key');
//$footer = $this->cacheGet('cache_common_nav_footer_key');
// 导航模型
$field = array('id', 'pid', 'name', 'url', 'value', 'data_type', 'is_new_window_open');
// 缓存没数据则从数据库重新读取,顶部菜单
//if(empty($header))
//{
$headerData = Loader::model('Navigation')->field($field)->where(array('nav_type'=>'header', 'stat'=>0, 'pid'=>0, 'country_code' => COUNTRY_CODE))->order('sort')->select();
$header = self::navDataDealWith($headerData);
if(!empty($header))
{
foreach($header as &$v)
{
$childData = Loader::model('Navigation')->field($field)->where(array('nav_type'=>'header', 'stat'=>0, 'pid'=>$v['id'], 'country_code' => COUNTRY_CODE))->order('sort')->select();
$v['items'] = self::navDataDealWith($childData);
}
}
// $this->cacheSet('cache_common_nav_header_key', $header, 3600);
// }
// 底部导航
//if(empty($footer))
// {
$footerdata = Loader::model('Navigation')->field($field)->where(array('nav_type'=>'footer', 'stat'=>0, 'pid'=>0, 'country_code' => COUNTRY_CODE))->order('sort')->select();
$footer = self::navDataDealWith($footerdata);
if(!empty($footer))
{
foreach($footer as &$v)
{
$childData = Loader::model('Navigation')->field($field)->where(array('nav_type'=>'footer', 'stat'=>0, 'pid'=>$v['id'], 'country_code' => COUNTRY_CODE))->order('sort')->select();
$v['items'] = self::navDataDealWith($childData);
}
}
// $this->cacheSet('cache_common_nav_footer_key', $footer, 3600);
//}
return [
'header' => $header,
'footer' => $footer,
];
}
/**
* [NavDataDealWith 导航数据处理]
* @author martin
* @version 0.0.1
* @datetime 2023-11-23T21:36:46+0800
* @param [array] $data [需要处理的数据]
* @return [array] [处理好的数据]
*/
public function NavDataDealWith($data)
{
if(!empty($data) && is_array($data))
{
foreach($data as $k=>&$v)
{
// url处理
switch($v['data_type'])
{
// 文章分类
case 'article':
$v['url'] = 'article/detail/'.$v['value'].'.html';
break;
// 博客
case 'blog':
$v['url'] = 'blog/detail/id/'.$v['value'].'.html';
break;
// 商品分类
case 'goods_category':
$category = Loader::model('ProductCategory')->getRow(['stat' => 0, 'id' => $v['value'], 'country_code' => $this->country_code], null, ['id' => 'asc']);
if($category['pid'] == 0) {
$v['url'] = 'product/catelists/id/'.$v['value'].'.html';
}
else{
$v['url'] = 'product/subcatelists/id/'.$v['value'].'.html';
}
break;
}
$data[$k] = $v;
}
}
return $data;
}
/**
* 节点遍历
* @param $list
* @param string $pk
* @param string $pid
* @param string $child
* @param int $root
* return array
*/
protected function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = 'child', $root = 0) {
//header('content-type:text/html;charset=utf-8;');
// 创建Tree
$tree = [];
if (is_array($list)) {
// 创建基于主键的数组引用
$refer = [];
foreach ($list as $key => $data) {
$list[$key] = $data->toArray();
$refer[$data[$pk]] = & $list[$key];
}
foreach ($list as $key => $data) {
// 判断是否存在parent
$parentId = $data[$pid];
if ($root == $parentId) {
$tree[] = & $list[$key];
} else {
if (isset($refer[$parentId])) {
$parent = & $refer[$parentId];
$parent[$child][] = & $list[$key];
}
}
}
}
return $tree;
}
private function check_login_token($customer_id, $curr_time, $p)
{
$expire = 86400 * 30;
if (time() - $curr_time > $expire)
return false;
$temp_p = $this->make_pwd($customer_id, $curr_time);
if ($temp_p !== $p)
{
return false;
}
return true;
}
protected function set_login_token($customer_info)
{
$curr_time = time();
$p = $this->make_pwd($customer_info['id'], $curr_time);
$customer_info['telephone'] = $customer_info['telephone'] != '' ? substr_replace($customer_info['telephone'], '****', 3, 4) : '';
$customer_info['email'] = $customer_info['email'] != '' ? substr_replace($customer_info['email'], '****', 2, 6) : '';
$customer_info['have_pwd'] = $customer_info['password'] != '' ? 1 : 0;
unset($customer_info['password']);
$customer_info['ct'] = $curr_time;
$customer_info['p'] = $p;
$expire = 86400 * 30;
Cookie::init(['expire' => $expire]);
Cookie::set('c', $customer_info);
}
private function make_pwd($customer_id, $curr_time)
{
$salt = 'Orico2019.';
$p = md5(md5($customer_id . $curr_time . $salt));
return $p;
}
private function check_login()
{
return Cookie::has('c');
}
protected function check_true_login()
{
// 校验用户是否登录,且校验cookie合法性
if (!$this->check_login())
{
return false;
}
$customer_info = json_decode(Cookie::get('c'), true);
$ct = isset($customer_info['ct']) ? $customer_info['ct'] : '';
$p = isset($customer_info['p']) ? $customer_info['p'] : '';
return $this->check_login_token($customer_info['id'], $ct, $p);
}
protected function _logout()
{
if (Cookie::has('c'))
Cookie::delete('c');
$this->customer_id = 0;
}
}

156
app/mobile/controller/Blog.php Executable file
View File

@@ -0,0 +1,156 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
use think\Db;
class Blog extends BaseController {
public function blog() {
$data = $this->request->param();
$arg_where = ['siteid' => $this->siteid,'stat' => 1, 'country_code' => $this->country_code,'public_time'=>['<=',date("Y-m-d")]];
$search = array();
if (isset($data['name']) && $data['name'] != ''){
$arg_where['title'] = ['like', "%$data[name]%"];
$search['name'] = $data['name'];
}
$arg_order = ['is_top'=>'desc','id' => 'desc'];
$arg_field = ['*'];
$dataObject = Loader::model('blog')->getBlogLists($arg_where, $arg_order, $arg_field, 12);
//echo Loader::model('blog')->getLastsql();
//echo "<pre>====22222222======"; print_r($dataObject);die;
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
$value['seo_title'] = config('article_seo_title')? : config('website_seo_title_us');
$value['seo_keyword'] = config('article_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('article_seo_description')? : config('website_seo_description');
$this->assign($value);
$this->assign('search',$search);
return $this->fetch();
}
public function detail($id = 0) {
if ($id > 0) {
$blog = Loader::model('Blog')->getRow($id);
if (empty($blog)) {
return exception('数据有误,请检查后再操作');
}
$arg_where = ['blog_remark.b_id' => $id, 'blog_remark.stat' => 1];
$arg_order = ['blog_remark.id' => 'desc'];
$arg_field = ['blog_remark.*'];
$dataObject = Loader::model('blog')->getRemarkList($arg_where, $arg_order, $arg_field, 10);
$value['list'] = $dataObject->isEmpty() ? null : $dataObject->items();
$value['total'] = $dataObject->total();
$value['page'] = $dataObject->render();
$value['seo_title'] = $blog['seo_title']? : $blog['title'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $blog['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $blog['seo_description']? : config('website_seo_description');
$this->assign($value);
$this->assign('blog', $blog);
$this->viewcount($id);
//return $this->fetch($template);
$disCount = $dataObject->isEmpty() ? null : count($dataObject->items());
if($disCount) {
$counts = get_rand_number(1,10,$disCount);
$this->assign('counts', $counts);
}
$curUrl = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$this->assign('curUrl', $curUrl);
//echo "<pre>====6666======".$id; print_r($dataObject); die;
return $this->fetch();
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id) {
$view = Cookie::get('blogview', 'history'); //print_r($history);exit;
if (empty($view) || $view != $id) {
Loader::model('blog')->where(['id' => $id])->setInc('visit_count');
Cookie::set('blogview', $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]);
}*/
}
//添加评论 2021-06-01 Martin
public function addcomment()
{
$data = $this->request->post();
if (empty($data) || !is_array($data))
return $this->json(403, 'Data error ');
if (trim($data['name']) == '')
return $this->json(403-2, 'Name cannot be empty');
if (trim($data['email']) == '')
return $this->json(403-4, 'Email cannot be empty');
if (trim($data['comment']) == '')
return $this->json(403-5, 'Comment 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');
$insert_data = [
'b_id' => trim($data['b_id']),
'name' => trim($data['name']),
'email' => trim($data['email']),
'content' => trim($data['comment']),
'add_time' => date("Y-m-d H:i:s",time()),
'siteid' => $this->siteid,
'country_code' => $this->country_code,
];
$result = model('blog_remark')->insert($insert_data);
if (!$result)
return $this->json(201, 'Failure to submit');
return $this->json(200, 'ok');
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
use think\validate;
class Collection extends BaseController {
public function add_collection()
{
$data = $this->request->post();
if ($this->customer_id <= 0)
{
$param = [];
if (isset($data['curr_url']))
{
$param['url'] = $data['curr_url'];
}
return $this->json(-1000, '请先登录', $param);
}
if (empty($data) || !is_array($data))
{
return $this->json(-1, '数据格式错误');
}
$where = [
'customer_id' => $this->customer_id,
'type' => $data['type'],
'coll_id' => $data['coll_id'],
'stat' => 0
];
$is_collection = model('collection')->where($where)->find();
if (!empty($is_collection))
{
return $this->json(200, '已经收藏过啦');
}
$insert_data = [
'customer_id' => $this->customer_id,
'type' => $data['type'],
'coll_id' => $data['coll_id'],
'create_time' => time(),
'stat' => 0
];
$result = model('collection')->insert($insert_data);
if (!$result)
{
return $this->json(-2, '收藏失败,请稍后再试');
}
return $this->json(200, '收藏成功');
}
public function cancel_collection()
{
$data = $this->request->post();
if ($this->customer_id <= 0)
{
$param = [];
if (isset($data['curr_url']))
{
$param['url'] = $data['curr_url'];
}
return $this->json(-1000, '请先登录', $param);
}
if (empty($data) || !is_array($data))
{
return $this->json(-1, '数据格式错误');
}
$where = [
'customer_id' => $this->customer_id,
'type' => $data['type'],
];
if (!is_array($data['coll_id']))
{
$where['coll_id'] = $data['coll_id'];
}
else
{
$where['coll_id'] = ['in', $data['coll_id']];
}
$result = model('collection')->where($where)->update(['stat' => 1]);
if (!$result)
{
return $this->json(-2, '取消失败,请稍后再试');
}
return $this->json(200, '取消成功');
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2018-12-10
* Time: 13:48
*/
namespace app\mobile\controller;
use think\Controller;
use think\Session;
class Country extends Controller
{
public function index(){
// session_start();
$ct= session('cit',$_GET['cit']);
$ct = session('cit');
if($ct){
$this->success('修改成功');
}else{
$this->error('修改国家失败');
}
}
}

View File

@@ -0,0 +1,578 @@
<?php
namespace app\mobile\controller;
use think\Cookie;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
use think\Validate;
use think\Cache;
class Customer extends BaseController {
public function login() {
if ($this->customer_id > 0)
$this->redirect(url('mobile/customer/personal'));
return view();
}
public function quick_login() {
if ($this->customer_id > 0)
$this->redirect(url('mobile/customer/personal'));
return view();
}
public function register() {
if ($this->customer_id > 0)
$this->redirect(url('mobile/customer/personal'));
return view();
}
public function personal() {
if ($this->customer_id <= 0)
$this->redirect(url('mobile/customer/login'));
return view();
}
public function forgetpwd()
{
return view();
}
# 用旧密码改新密码
public function update_pwd()
{
$data = $this->request->post();
if (empty($data) || $this->customer_id <= 0)
{
return $this->json(-1, '数据错误');
}
if ($this->customer_info['have_pwd'])
{
$customer_info = model('customer')->where(['id' => $this->customer_id])->find();
if (md5($data['old_password']) != $customer_info['password'])
{
return $this->json(-2, '旧密码错误');
}
}
$update_data = [
'password' => md5($data['password']),
'salt' => $data['password']
];
$result = model('customer')->where(['id' => $this->customer_id])->update($update_data);
if (!$result)
{
return $this->json(-4, '修改密码失败');
}
$customer_info = model('customer')->getBasicInfo($this->customer_id);
$this->set_login_token($customer_info);
return $this->json(200, '修改密码成功');
}
# 用手机号/邮箱改密码
public function update_forget_pwd()
{
$data = $this->request->post();
if (empty($data))
{
return $this->json(-1, '数据错误');
}
if (isset($data['telephone']))
{
$flag = 1;
if (!preg_match("/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/", $data['telephone']))
{
return $this->json(-2, '手机号格式错误');
}
$captcha = $this->cacheGet('regtel' . $data['telephone'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-3, '验证码错误');
}
}
else
{
return $this->json(-100, '邮箱暂不可用');
$flag = 2;
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['email']))
{
return $this->json(-4, '邮箱格式错误');
}
$captcha = $this->cacheGet('regemail' . $data['email'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-5, '验证码错误');
}
}
if (!preg_match("/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*-.]+$)[a-zA-Z\d!@#$%^&*-.]{8,20}$/", $data['password']))
{
return $this->json(-6, '密码必须包含8-20个字符,且至少包含两种类型字符');
}
if ($flag == 1)
{
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
if (empty($customer_info))
{
return $this->json(-7, '该手机号未注册');
}
$update_data = [
'password' => md5($data['password']),
'salt' => $data['password']
];
$result = model('customer')->where(['telephone' => $data['telephone']])->update($update_data);
}
else
{
$customer_info = model('customer')->getBasicInfoByEmail($data['email']);
if (empty($customer_info))
{
return $this->json(-8, '该邮箱未注册');
}
$update_data = [
'password' => md5($data['password']),
'salt' => $data['password']
];
$result = model('customer')->where(['email' => $data['email']])->update($update_data);
}
if (!$result)
{
return $this->json(-9, '修改密码失败,稍后再试');
}
$this->_logout();
return $this->json(200, '修改密码成功');
}
public function bind_email()
{
$data = $this->request->post();
if (empty($data) || $this->customer_id <= 0)
{
return $this->json(-1, '数据错误');
}
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['email']))
{
return $this->json(-2, '邮箱格式错误');
}
$customer_info = model('customer')->where(['email' => $data['email']])->find();
if (!empty($customer_info))
{
return $this->json(-3, '邮箱已被使用');
}
$update_data = [
'email' => $data['email']
];
$result = model('customer')->where(['id' => $this->customer_id])->update($update_data);
if (!$result)
{
return $this->json(-3, '绑定邮箱失败,请稍后再试');
}
$customer_info = model('customer')->getBasicInfo($this->customer_id);
$this->set_login_token($customer_info);
return $this->json(200, '绑定邮箱成功');
}
# 旧手机号改新手机号
public function update_tel()
{
$data = $this->request->post();
// tiaoshi($data);die;
if (empty($data) || $this->customer_id <= 0)
{
return $this->json(-1, '数据错误');
}
$customer_info = model('customer')->where(['id' => $this->customer_id])->find();
if ($customer_info['telephone'] != $data['old_telephone'])
{
return $this->json(-2, '旧手机号错误');
}
if (!preg_match("/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/", $data['new_telephone']))
{
return $this->json(-3, '手机号格式错误');
}
$captcha = $this->cacheGet('regtel' . $data['new_telephone'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-4, '验证码错误');
}
$update_data = [
'telephone' => $data['new_telephone']
];
$result = model('customer')->where(['id' => $this->customer_id])->update($update_data);
if (!$result)
{
return $this->json(-5, '修改失败');
}
$new_customer_info = model('customer')->getBasicInfo($this->customer_id);
$this->set_login_token($new_customer_info);
return $this->json(200, '修改成功');
}
public function new_register()
{
if ($this->customer_id > 0)
return $this->json(-10001, '已经登录过');
$data = $this->request->post();
if (empty($data))
{
return $this->json(-1, '数据错误');
}
$customer = model('customer')->where(['telephone' => $data['telephone'], 'stat' => 0])->find();
if (!empty($customer))
return $this->json(-2, '该手机号已注册');
$captcha = $this->cacheGet('regtel' . $data['telephone'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-4, '验证码错误');
}
$firstname = 'ORICO' . rand(10000000, 99999999);
$insert_data = [
'firstname' => $firstname,
'telephone' => $data['telephone'],
'addtime' => time()
];
$customer_id = model('customer')->insertGetId($insert_data);
if (!$customer_id)
{
return $this->json(-100, '注册失败');
}
$customer_info = model('customer')->getBasicInfo($customer_id);
$this->set_login_token($customer_info);
return $this->json(200, '注册成功');
}
public function new_login()
{
if ($this->customer_id > 0)
return $this->json(-10001, '已经登录过');
$data = $this->request->post();
if (empty($data))
{
return $this->json(-1, '数据错误');
}
if (isset($data['password']))
{
// 密码登录
if (preg_match("/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/", $data['username']))
{
$where = ['telephone' => $data['username']];
}
elseif (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['username']))
{
$where = ['email' => $data['username']];
}
else
{
return $this->json(-2, '账号格式错误');
}
$where['stat'] = 0;
$customer_info = model('customer')->where($where)->field('id, firstname, picture, sex, email, telephone, qq, birthday, password')->find();
if (empty($customer_info))
{
return $this->json(-3, '账号未注册');
}
if ($customer_info['password'] != md5($data['password']))
{
return $this->json(-4, '账号或密码错误');
}
}
else
{
// 短信验证码登录
$captcha = $this->cacheGet('regtel' . $data['telephone'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-5, '验证码错误');
}
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
if (empty($customer_info))
{
// 未注册直接入库
$firstname = 'ORICO' . rand(10000000, 99999999);
$insert_data = [
'firstname' => $firstname,
'telephone' => $data['telephone'],
];
$customer_id = model('customer')->insertGetId($insert_data);
if (!$customer_id)
{
return $this->json(-6, '登录失败');
}
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
}
}
$this->set_login_token($customer_info);
return $this->json(200, '登录成功');
}
public function new_logout()
{
$this->_logout();
return $this->json(200, 'ok');
}
/**
* 前台用户登录
*/
public function check_login() {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->json(-1, '未知错误');
}
// $code = $this->cacheGet('regtel' . $data['telephone']);
// if ($code != $data['code']) {
// return $this->json(-1, '短信验证码不正确');
// }
$validate = Loader::validate('customer');
if (!$validate->scene('login')->check($data)) {
return $this->json(-1, $validate->getError());
}
// 登录成功
$user = model('customer')->getBasicInfoByTelephone($data['telephone']);
$curr_time = time();
$token = $this->set_token($user['id'], $curr_time);
$data = [
'user_info' => $user,
'curr_time' => $curr_time,
'token' => $token,
];
return $this->json(1, '登录成功', $data);
}
public function check_register() {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->json(-1, '未知错误');
}
// $code = $this->cacheGet('regtel' . $data['telephone']);
// if ($code != $data['code']) {
// return $this->json(-1, '短信验证码不正确');
// }
$validate = Loader::validate('customer');
if (!$validate->scene('register')->check($data)) {
return $this->json(-1, $validate->getError());
}
// tiaoshi($data);die;
$addtime = time();
$set = [
'group_id' => 1,
'telephone' => $data['telephone'],
'firstname' => isset($data['firstname']) ? $data['firstname'] : '',
// 'lastname' => isset($data['lastname']) ? $data['lastname'] : '',
// 'newsletter' => isset($data['newsletter']) ? $data['newsletter'] : 0,
'salt' => $data['password'],
'password' => md5($data['password']),
'stat' => 0,
'safe' => 1,
'code' => '',
// 'item' => isset($data['item']) ? $data['item'] : 0,
// 'token' => isset($data['token']) ? $data['token'] : '',
// 'wishlist' => isset($data['wishlist']) ? $data['wishlist'] : '',
// 'ip' => isset($data['ip']) ? $data['ip'] : '',
// 'fenxiang' => isset($data['fenxiang']) ? $data['fenxiang'] : 0,
// 'guanzhu' => isset($data['guanzhu']) ? $data['guanzhu'] : 0,
// 'hangye' => isset($data['hangye']) ? $data['hangye'] : '',
// 'zhiye' => isset($data['zhiye']) ? $data['zhiye'] : '',
// 'sex' => isset($data['sex']) ? $data['sex'] : '',
// 'birthday' => isset($data['birthday']) ? $data['birthday'] : '',
// 'qq' => isset($data['qq']) ? $data['qq'] : '',
'addtime' => $addtime,
// 'custom_field' => json_encode([]),
];
$result = Loader::model('Customer')->insertRow($set);
if ($result && $customer_id = $result->getData('id')) {
$user = model('customer')->getBasicInfo($customer_id);
$curr_time = time();
$token = $this->set_token($customer_id, $curr_time);
$data = [
'user_info' => $user,
'curr_time' => $curr_time,
'token' => $token,
];
return $this->json(1, '注册成功', $data);
} else {
return $this->json(-1, '注册失败');
}
}
public function sendsms() {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->json(-1, '未知错误');
}
if (isset($data['login']) && $data['login'])
{
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
if (empty($customer_info))
{
return $this->json(-101, '手机号未注册');
}
}
else if (isset($data['register']) && $data['register'])
{
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
if (!empty($customer_info))
{
return $this->json(-102, '手机号已注册');
}
}
$validaterule = [
'telephone' => ['regex' => '^1[345789]\d{9}$'],
];
$validatemsg = [
'telephone.regex' => '手机格式错误',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
return $this->json(-2, $valid_result);
}
$mobile = $data['telephone'];
$curr_date = date('Y-m-d');
// 当前手机号今天是否发送过验证码
$is_send = Cache::get($mobile . $curr_date, '');
if ($is_send) {
// 如果发过,自增一次
Cache::inc($mobile . $curr_date);
} else {
// 如果今天第一次发短信
$expire = 86400;
Cache::set($mobile . $curr_date, 1, $expire);
}
// 当天发送数量
$today_send_count = Cache::get($mobile . $curr_date);
// if ($today_send_count > 10) {
// return $this->json(-102, '每天发送验证码不能超过10次');
// }
//$mobile = $data['telephone'];
//$code = mt_rand(10000, 99999);
//$this->cacheSet('regtel' . $mobile, $code, 300);
//return $this->success($code);
//获取对象,如果上面没有引入命名空间,可以这样实例化:$sms = new \alisms\SendSms()
$sms = new \alisms\SendSms();
//设置关键的四个配置参数其实配置参数应该写在公共或者模块下的config配置文件中然后在获取使用这里我就直接使用了。
$sms->accessKeyId = (string) Config::get('sms_accesskeyid');
$sms->accessKeySecret = (string) Config::get('sms_accesskeysecret');
$sms->signName = (string) Config::get('sms_signname');
$sms->templateCode = (string) Config::get('sms_templatecode');
//模板参数自定义了随机数你可以在这里保存在缓存或者cookie等设置有效期以便逻辑发送后用户使用后的逻辑处理
$code = mt_rand(10000, 99999);
$this->cacheSet('regtel' . $mobile, $code, 300);
$templateParam = array('code' => $code);
$m = $sms->send($mobile, $templateParam);
//类中有说明默认返回的数组格式如果需要json在自行修改类或者在这里将$m转换后在输出
if ($m['Code'] == 'OK') {
return $this->json(200, $m['Message']);
} else {
return $this->json(-1, $m['Message']);
}
}
/*个人中心*/
public function my_collection()
{
if ($this->customer_id <= 0)
{
$this->redirect('mobile/customer/login.html');
}
$param = $this->request->param();
// tiaoshi($param);die;
$where = ['a.stat' => 0, 'b.stat' => 0, 'a.customer_id' => $this->customer_id];
if (isset($param['cid']))
{
$cid_arr = model('product_category')->getChildIDArray($param['cid']);
$where['b.cid'] = ['in', $cid_arr];
$cid = $param['cid'];
}
else
{
$cid = 0;
}
$field = ['b.id', 'b.cid', 'b.name', 'b.shortname', 'b.isnew', 'b.ishot', 'b.recommend', 'b.viewcount', 'b.brand_id'];
$order = ['a.id' => 'desc'];
$list = model('collection')->getList($where, $order, $field, 10);
// echo model('collection')->getLastSql();die;
foreach ($list as $key => $value) {
$product_two_img = model('product_two_img')->where(['product_id' => $value['id']])->find();
$list[$key]['product_two_img'] = $product_two_img['image_url'];
}
$data = [
'list' => $list->isEmpty() ? null : $list->items(),
'page' => $list->render(),
'cid' => $cid
];
$this->assign($data);
return $this->fetch();
}
}

View File

@@ -0,0 +1,581 @@
<?php
namespace app\mobile\controller;
use think\Cookie;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
use think\Validate;
use think\Cache;
class Customer extends BaseController {
public function login() {
if ($this->customer_id > 0)
$this->redirect(url('mobile/customer/personal'));
return view();
}
public function quick_login() {
if ($this->customer_id > 0)
$this->redirect(url('mobile/customer/personal'));
return view();
}
public function register() {
if ($this->customer_id > 0)
$this->redirect(url('mobile/customer/personal'));
return view();
}
public function personal() {
if ($this->customer_id <= 0)
$this->redirect(url('mobile/customer/login'));
return view();
}
public function forgetpwd()
{
return view();
}
# 用旧密码改新密码
public function update_pwd()
{
$data = $this->request->post();
if (empty($data) || $this->customer_id <= 0)
{
return $this->json(-1, '数据错误');
}
if ($this->customer_info['have_pwd'])
{
$customer_info = model('customer')->where(['id' => $this->customer_id])->find();
if (md5($data['old_password']) != $customer_info['password'])
{
return $this->json(-2, '旧密码错误');
}
}
$update_data = [
'password' => md5($data['password']),
'salt' => $data['password']
];
$result = model('customer')->where(['id' => $this->customer_id])->update($update_data);
if (!$result)
{
return $this->json(-4, '修改密码失败');
}
$customer_info = model('customer')->getBasicInfo($this->customer_id);
$this->set_login_token($customer_info);
return $this->json(200, '修改密码成功');
}
# 用手机号/邮箱改密码
public function update_forget_pwd()
{
$data = $this->request->post();
if (empty($data))
{
return $this->json(-1, '数据错误');
}
if (isset($data['telephone']))
{
$flag = 1;
if (!preg_match("/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/", $data['telephone']))
{
return $this->json(-2, '手机号格式错误');
}
$captcha = $this->cacheGet('regtel' . $data['telephone'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-3, '验证码错误');
}
}
else
{
return $this->json(-100, '邮箱暂不可用');
$flag = 2;
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['email']))
{
return $this->json(-4, '邮箱格式错误');
}
$captcha = $this->cacheGet('regemail' . $data['email'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-5, '验证码错误');
}
}
if (!preg_match("/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/", $data['password']))
{
return $this->json(-6, '密码必须包含8-20个字符,且包含数字和字母');
}
if ($flag == 1)
{
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
if (empty($customer_info))
{
return $this->json(-7, '该手机号未注册');
}
$update_data = [
'password' => md5($data['password']),
'salt' => $data['password']
];
$result = model('customer')->where(['telephone' => $data['telephone']])->update($update_data);
}
else
{
$customer_info = model('customer')->getBasicInfoByEmail($data['email']);
if (empty($customer_info))
{
return $this->json(-8, '该邮箱未注册');
}
$update_data = [
'password' => md5($data['password']),
'salt' => $data['password']
];
$result = model('customer')->where(['email' => $data['email']])->update($update_data);
}
if (!$result)
{
return $this->json(-9, '修改密码失败,稍后再试');
}
$this->_logout();
return $this->json(200, '修改密码成功');
}
public function bind_email()
{
$data = $this->request->post();
if (empty($data) || $this->customer_id <= 0)
{
return $this->json(-1, '数据错误');
}
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['email']))
{
return $this->json(-2, '邮箱格式错误');
}
$customer_info = model('customer')->where(['email' => $data['email']])->find();
if (!empty($customer_info))
{
return $this->json(-3, '邮箱已被使用');
}
$update_data = [
'email' => $data['email']
];
$result = model('customer')->where(['id' => $this->customer_id])->update($update_data);
if (!$result)
{
return $this->json(-3, '绑定邮箱失败,请稍后再试');
}
$customer_info = model('customer')->getBasicInfo($this->customer_id);
$this->set_login_token($customer_info);
return $this->json(200, '绑定邮箱成功');
}
# 旧手机号改新手机号
public function update_tel()
{
$data = $this->request->post();
// tiaoshi($data);die;
if (empty($data) || $this->customer_id <= 0)
{
return $this->json(-1, '数据错误');
}
$customer_info = model('customer')->where(['id' => $this->customer_id])->find();
if ($customer_info['telephone'] != $data['old_telephone'])
{
return $this->json(-2, '旧手机号错误');
}
if (!preg_match("/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/", $data['new_telephone']))
{
return $this->json(-3, '手机号格式错误');
}
$captcha = $this->cacheGet('regtel' . $data['new_telephone'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-4, '验证码错误');
}
$update_data = [
'telephone' => $data['new_telephone']
];
$result = model('customer')->where(['id' => $this->customer_id])->update($update_data);
if (!$result)
{
return $this->json(-5, '修改失败');
}
$new_customer_info = model('customer')->getBasicInfo($this->customer_id);
$this->set_login_token($new_customer_info);
return $this->json(200, '修改成功');
}
public function new_register()
{
if ($this->customer_id > 0)
return $this->json(-10001, '已经登录过');
$data = $this->request->post();
tiaoshi($data);die;
if (empty($data))
{
return $this->json(-1, '数据错误');
}
$validate = Loader::validate('customer');
if (!$validate->scene('register_by_telephone')->check($data))
{
return $this->json(-2, $validate->getError());
}
$captcha = $this->cacheGet('regtel' . $data['telephone'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-4, '验证码错误');
}
$firstname = 'ORICO' . rand(10000000, 99999999);
$insert_data = [
'firstname' => $firstname,
'telephone' => $data['telephone'],
'addtime' => time()
];
$customer_id = model('customer')->insertGetId($insert_data);
if (!$customer_id)
{
return $this->json(-100, '注册失败');
}
$customer_info = model('customer')->getBasicInfo($customer_id);
$this->set_login_token($customer_info);
return $this->json(200, '注册成功');
}
public function new_login()
{
if ($this->customer_id > 0)
return $this->json(-10001, '已经登录过');
$data = $this->request->post();
if (empty($data))
{
return $this->json(-1, '数据错误');
}
if (isset($data['password']))
{
// 密码登录
if (preg_match("/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/", $data['username']))
{
$where = ['telephone' => $data['username']];
}
elseif (preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['username']))
{
$where = ['email' => $data['username']];
}
else
{
return $this->json(-2, '账号格式错误');
}
$where['stat'] = 0;
$customer_info = model('customer')->where($where)->field('id, firstname, picture, sex, email, telephone, qq, birthday, password')->find();
if (empty($customer_info))
{
return $this->json(-3, '账号未注册');
}
if ($customer_info['password'] != md5($data['password']))
{
return $this->json(-4, '账号或密码错误');
}
}
else
{
// 短信验证码登录
$captcha = $this->cacheGet('regtel' . $data['telephone'], 'error');
if ($captcha != $data['captcha'])
{
return $this->json(-5, '验证码错误');
}
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
if (empty($customer_info))
{
// 未注册直接入库
$firstname = 'ORICO' . rand(10000000, 99999999);
$insert_data = [
'firstname' => $firstname,
'telephone' => $data['telephone'],
];
$customer_id = model('customer')->insertGetId($insert_data);
if (!$customer_id)
{
return $this->json(-6, '登录失败');
}
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
}
}
$this->set_login_token($customer_info);
return $this->json(200, '登录成功');
}
public function new_logout()
{
$this->_logout();
return $this->json(200, 'ok');
}
/**
* 前台用户登录
*/
public function check_login() {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->json(-1, '未知错误');
}
// $code = $this->cacheGet('regtel' . $data['telephone']);
// if ($code != $data['code']) {
// return $this->json(-1, '短信验证码不正确');
// }
$validate = Loader::validate('customer');
if (!$validate->scene('login')->check($data)) {
return $this->json(-1, $validate->getError());
}
// 登录成功
$user = model('customer')->getBasicInfoByTelephone($data['telephone']);
$curr_time = time();
$token = $this->set_token($user['id'], $curr_time);
$data = [
'user_info' => $user,
'curr_time' => $curr_time,
'token' => $token,
];
return $this->json(1, '登录成功', $data);
}
public function check_register() {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->json(-1, '未知错误');
}
// $code = $this->cacheGet('regtel' . $data['telephone']);
// if ($code != $data['code']) {
// return $this->json(-1, '短信验证码不正确');
// }
$validate = Loader::validate('customer');
if (!$validate->scene('register')->check($data)) {
return $this->json(-1, $validate->getError());
}
// tiaoshi($data);die;
$addtime = time();
$set = [
'group_id' => 1,
'telephone' => $data['telephone'],
'firstname' => isset($data['firstname']) ? $data['firstname'] : '',
// 'lastname' => isset($data['lastname']) ? $data['lastname'] : '',
// 'newsletter' => isset($data['newsletter']) ? $data['newsletter'] : 0,
'salt' => $data['password'],
'password' => md5($data['password']),
'stat' => 0,
'safe' => 1,
'code' => '',
// 'item' => isset($data['item']) ? $data['item'] : 0,
// 'token' => isset($data['token']) ? $data['token'] : '',
// 'wishlist' => isset($data['wishlist']) ? $data['wishlist'] : '',
// 'ip' => isset($data['ip']) ? $data['ip'] : '',
// 'fenxiang' => isset($data['fenxiang']) ? $data['fenxiang'] : 0,
// 'guanzhu' => isset($data['guanzhu']) ? $data['guanzhu'] : 0,
// 'hangye' => isset($data['hangye']) ? $data['hangye'] : '',
// 'zhiye' => isset($data['zhiye']) ? $data['zhiye'] : '',
// 'sex' => isset($data['sex']) ? $data['sex'] : '',
// 'birthday' => isset($data['birthday']) ? $data['birthday'] : '',
// 'qq' => isset($data['qq']) ? $data['qq'] : '',
'addtime' => $addtime,
// 'custom_field' => json_encode([]),
];
$result = Loader::model('Customer')->insertRow($set);
if ($result && $customer_id = $result->getData('id')) {
$user = model('customer')->getBasicInfo($customer_id);
$curr_time = time();
$token = $this->set_token($customer_id, $curr_time);
$data = [
'user_info' => $user,
'curr_time' => $curr_time,
'token' => $token,
];
return $this->json(1, '注册成功', $data);
} else {
return $this->json(-1, '注册失败');
}
}
public function sendsms() {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->json(-1, '未知错误');
}
if (isset($data['login']) && $data['login'])
{
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
if (empty($customer_info))
{
return $this->json(-101, '手机号未注册');
}
}
else if (isset($data['register']) && $data['register'])
{
$customer_info = model('customer')->getBasicInfoByTelephone($data['telephone']);
if (!empty($customer_info))
{
return $this->json(-102, '手机号已注册');
}
}
$validaterule = [
'telephone' => ['regex' => '^1[345789]\d{9}$'],
];
$validatemsg = [
'telephone.regex' => '手机格式错误',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
return $this->json(-2, $valid_result);
}
$mobile = $data['telephone'];
$curr_date = date('Y-m-d');
// 当前手机号今天是否发送过验证码
$is_send = Cache::get($mobile . $curr_date, '');
if ($is_send) {
// 如果发过,自增一次
Cache::inc($mobile . $curr_date);
} else {
// 如果今天第一次发短信
$expire = 86400;
Cache::set($mobile . $curr_date, 1, $expire);
}
// 当天发送数量
$today_send_count = Cache::get($mobile . $curr_date);
if ($today_send_count > 10) {
return $this->json(-102, '每天发送验证码不能超过10次');
}
//$mobile = $data['telephone'];
//$code = mt_rand(10000, 99999);
//$this->cacheSet('regtel' . $mobile, $code, 300);
//return $this->success($code);
//获取对象,如果上面没有引入命名空间,可以这样实例化:$sms = new \alisms\SendSms()
$sms = new \alisms\SendSms();
//设置关键的四个配置参数其实配置参数应该写在公共或者模块下的config配置文件中然后在获取使用这里我就直接使用了。
$sms->accessKeyId = (string) Config::get('sms_accesskeyid');
$sms->accessKeySecret = (string) Config::get('sms_accesskeysecret');
$sms->signName = (string) Config::get('sms_signname');
$sms->templateCode = (string) Config::get('sms_templatecode');
//模板参数自定义了随机数你可以在这里保存在缓存或者cookie等设置有效期以便逻辑发送后用户使用后的逻辑处理
$code = mt_rand(10000, 99999);
$this->cacheSet('regtel' . $mobile, $code, 300);
$templateParam = array('code' => $code);
$m = $sms->send($mobile, $templateParam);
//类中有说明默认返回的数组格式如果需要json在自行修改类或者在这里将$m转换后在输出
if ($m['Code'] == 'OK') {
return $this->json(200, $m['Message']);
} else {
return $this->json(-1, $m['Message']);
}
}
/*个人中心*/
public function my_collection()
{
if ($this->customer_id <= 0)
{
$this->redirect('mobile/customer/login.html');
}
$param = $this->request->param();
// tiaoshi($param);die;
$where = ['a.stat' => 0, 'b.stat' => 0, 'a.customer_id' => $this->customer_id];
if (isset($param['cid']))
{
$cid_arr = model('product_category')->getChildIDArray($param['cid']);
$where['b.cid'] = ['in', $cid_arr];
$cid = $param['cid'];
}
else
{
$cid = 0;
}
$field = ['b.id', 'b.cid', 'b.name', 'b.shortname', 'b.isnew', 'b.ishot', 'b.recommend', 'b.viewcount', 'b.brand_id'];
$order = ['a.id' => 'desc'];
$list = model('collection')->getList($where, $order, $field, 10);
// echo model('collection')->getLastSql();die;
foreach ($list as $key => $value) {
$product_two_img = model('product_two_img')->where(['product_id' => $value['id']])->find();
$list[$key]['product_two_img'] = $product_two_img['image_url'];
}
$data = [
'list' => $list->isEmpty() ? null : $list->items(),
'page' => $list->render(),
'cid' => $cid
];
$this->assign($data);
return $this->fetch();
}
}

View File

@@ -0,0 +1,351 @@
<?php
namespace app\mobile\controller;
use think\Config;
use think\Cookie;
use think\Loader;
class Download extends BaseController
{
public function search($id = 0)
{
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['a.siteid' => $this->siteid];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['a.name'] = ['like', '%' . $skeyword . '%'];
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
}
if ($id > 0) {
$category = Loader::model('DownloadCategory')->getRow($id);
}
$dataObject = Loader::model('Download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
$value['downloadCategory'] = $downloadCategory;
$value['skeyword'] = $skeyword;
$value['category'] = $category;
$value['seo_title'] = config('download_seo_title') ?: config('website_seo_title');
$value['seo_keyword'] = config('download_seo_keyword') ?: config('website_seo_keyword');
$value['seo_description'] = config('download_seo_description') ?: config('website_seo_description');
$this->assign($value);
return $this->fetch('catelists');
}
public function catelists()
{
$arg_where = [
'a.siteid' => $this->siteid,
'c.id' => 1,
];
$skeyword = $this->request->get('skeyword', '', 'urldecode,strval');
if ($skeyword != '') {
$skeyword = trim($skeyword);
$search['skeyword'] = $skeyword;
$arg_where['a.name|a.app_model'] = ['like', '%' . $search['skeyword'] . '%'];
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
$value['search'] = $search;
}
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
// echo \think\Db::table('download')->getLastSql(), '<hr>';
// tiaoshi($dataObject->items());die;
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
// tiaoshi($downloadCategory);die;
$value['downloadCategory'] = $downloadCategory;
$value['skeyword'] = '';
$this->assign($value);
return $this->fetch();
}
public function detail($id = 0)
{
if ($id > 0) {
$detail = Loader::model('Download')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
//$adddownload = Loader::model('DownloadAddition')->getRowAddition(['aid' => $detail['id']]);
$category = Loader::model('DownloadCategory')->getRow($detail['cid']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$prev_detail = Loader::model('Download')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
$next_detail = Loader::model('Download')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
$value = [
'detail' => $detail,
//'adddownload' => $adddownload,
'category' => $category,
'prev_detail' => $prev_detail,
'next_detail' => $next_detail,
];
$value['seo_title'] = $detail['seo_title'] ?: $detail['name'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $detail['seo_keyword'] ?: config('website_seo_keyword');
$value['seo_description'] = $detail['seo_description'] ?: config('website_seo_description');
$this->assign($value);
$this->viewcount($id);
return $this->fetch();
} else {
return exception('数据有误,请检查后再操作');
}
}
public function download($id = 0, $bit = 0)
{
$id = intval($id);
$bit = intval($bit);
if ($id > 0) {
$detail = Loader::model('Download')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
$docDir = request()->server('DOCUMENT_ROOT');
$rootDir = request()->root();
$directory = $docDir . $rootDir;
$downloadpath = explode(',', $detail['downloadpath']);
//$downloadpath64 = explode(',', $detail['downloadpath64']);
if (empty($downloadpath[$bit])) {
return exception('数据有误,请检查后再操作');
}
$fileinfo = pathinfo($downloadpath[$bit]);
$download = $directory . $downloadpath[$bit]; // 文件要下载的地址
Loader::model('Download')->updateRow(['downloadcount' => \think\Db::raw('`downloadcount`+1')], ['id' => $id]);
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fileinfo['basename']);
header('Content-Length: ' . filesize($download));
readfile($download);
exit();
} else {
return exception('数据有误,请检查后再操作');
}
}
public function dlcount($id = 0)
{
$id = intval($id);
if ($id > 0) {
$download = Loader::model('Download')->getRow(['id' => $id], ['id', 'downloadcount']);
if (empty($download)) {
return $this->error('Error');
}
$download['downloadcount'] = $download['downloadcount'] + 1;
$result = $download->save();
if ($result) {
return $this->success('Download', null, $download['downloadcount']);
} else {
return $this->error('Download Error');
}
}
return $this->error('Error');
}
public function prodownload($id = 0)
{
if ($id > 0) {
$detail = Loader::model('ProductDl')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
$docDir = request()->server('DOCUMENT_ROOT');
$rootDir = request()->root();
$directory = $docDir . $rootDir;
$fileinfo = pathinfo($detail['dl_url']);
$download = $directory . $detail['dl_url']; // 文件要下载的地址
//在session里面存ip和id 查这个上次访问时间
$ip = $this->get_real_ip();
$name = 'ip_' . $ip . '_' . $id;
$time = time();
$dl = session($name);
//如果没有则创建session
if ($dl == '') {
$dl = session($name, $time);
}
$a = 180 - (time() - $dl);
if ($dl && time() - $dl < 180) {
return $this->error('操作过于频繁,请' . $a . '秒后再试');
}
$dl = session($name, $time);
Loader::model('ProductDl')->updateRow(['dl_count' => \think\Db::raw('`dl_count`+1')], ['id' => $id]);
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fileinfo['basename']);
header('Content-Length: ' . filesize($download));
readfile($download);
exit();
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id)
{
$view = Cookie::get('downloadview', 'history'); //print_r($history);exit;
if (empty($view) || $view != $id) {
Loader::model('Download')->where(['id' => $id])->setInc('viewcount');
Cookie::set('downloadview', $id, ['prefix' => 'history', 'expire' => 3600]);
}
}
protected function historydownload($id)
{
$download = Cookie::get('download', 'history'); //print_r($history);exit;
if (isset($download) && !empty($download)) {
$download_ids = explode(',', $download);
if ($download_ids[0] != $id) {
array_unshift($download_ids, $id);
$download_ids = array_unique($download_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$download_ids = array_slice($download_ids, 0, $num);
while (count($download_ids) > $num) {
array_pop($download_ids);
}
Cookie::set('download', implode(',', $download_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('download', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
}
public function catelists_down($id = 0)
{
//dump($id);die;
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('DownloadCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
$value['downloadCategory'] = $downloadCategory;
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['skeyword'] = '';
$value['category'] = $category;
$value['seo_title'] = $category['seo_title'] ?: config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword'] ?: config('website_seo_keyword');
$value['seo_description'] = $category['seo_description'] ?: config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function index($id = 0)
{
//dump($id);die;
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('DownloadCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
$value['downloadCategory'] = $downloadCategory;
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['skeyword'] = '';
$value['category'] = $category;
$value['seo_title'] = $category['seo_title'] ?: config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword'] ?: config('website_seo_keyword');
$value['seo_description'] = $category['seo_description'] ?: config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
function get_real_ip()
{
$ip = false;
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode(', ', $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) {
array_unshift($ips, $ip);
$ip = FALSE;
}
for ($i = 0; $i < count($ips); $i++) {
if (!eregi('^(10│172.16│192.168).', $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
public function dlsearch($id)
{
$where = ['id' => $id];
$view = Loader::model('Download')->where($where)->find();
$category = Loader::model('DownloadCategory')->getRow();
$this->assign('view',$view);
$this->assign('category',$category);
return $this->fetch();
}
}

View File

@@ -0,0 +1,296 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
class Download extends BaseController {
public function search($id = 0) {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_where = ['a.siteid' => $this->siteid];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
if (!empty($skeyword)) {
$skeyword = trim($skeyword);
$arg_where['a.name'] = ['like', '%' . $skeyword . '%'];
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
}
if ($id > 0) {
$category = Loader::model('DownloadCategory')->getRow($id);
}
$dataObject = Loader::model('Download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
$value['downloadCategory'] = $downloadCategory;
$value['skeyword'] = $skeyword;
$value['category'] = $category;
$value['seo_title'] = config('download_seo_title')? : config('website_seo_title');
$value['seo_keyword'] = config('download_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('download_seo_description')? : config('website_seo_description');
$this->assign($value);
return $this->fetch('catelists');
}
public function catelists($id = 0) {
//dump($id);die;
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('DownloadCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
$value['downloadCategory'] = $downloadCategory;
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['skeyword'] = '';
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function detail($id = 0) {
if ($id > 0) {
$detail = Loader::model('Download')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
//$adddownload = Loader::model('DownloadAddition')->getRowAddition(['aid' => $detail['id']]);
$category = Loader::model('DownloadCategory')->getRow($detail['cid']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$prev_detail = Loader::model('Download')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
$next_detail = Loader::model('Download')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
$value = [
'detail' => $detail,
//'adddownload' => $adddownload,
'category' => $category,
'prev_detail' => $prev_detail,
'next_detail' => $next_detail,
];
$value['seo_title'] = $detail['seo_title']? : $detail['name'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $detail['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $detail['seo_description']? : config('website_seo_description');
$this->assign($value);
$this->viewcount($id);
return $this->fetch();
} else {
return exception('数据有误,请检查后再操作');
}
}
public function download($id = 0, $bit = 0) {
$id = intval($id);
$bit = intval($bit);
if ($id > 0) {
$detail = Loader::model('Download')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
$docDir = request()->server('DOCUMENT_ROOT');
$rootDir = request()->root();
$directory = $docDir . $rootDir;
$downloadpath = explode(',', $detail['downloadpath']);
//$downloadpath64 = explode(',', $detail['downloadpath64']);
if (empty($downloadpath[$bit])) {
return exception('数据有误,请检查后再操作');
}
$fileinfo = pathinfo($downloadpath[$bit]);
$download = $directory . $downloadpath[$bit]; // 文件要下载的地址
Loader::model('Download')->updateRow(['downloadcount' => \think\Db::raw('`downloadcount`+1')], ['id' => $id]);
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fileinfo['basename']);
header('Content-Length: ' . filesize($download));
readfile($download);
exit();
} else {
return exception('数据有误,请检查后再操作');
}
}
public function dlcount($id = 0) {
$id = intval($id);
if ($id > 0) {
$download = Loader::model('Download')->getRow(['id' => $id], ['id', 'downloadcount']);
if (empty($download)) {
return $this->error('Error');
}
$download['downloadcount'] = $download['downloadcount'] + 1;
$result = $download->save();
if ($result) {
return $this->success('Download', null, $download['downloadcount']);
} else {
return $this->error('Download Error');
}
}
return $this->error('Error');
}
public function prodownload($id = 0) {
if ($id > 0) {
$detail = Loader::model('ProductDl')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
$docDir = request()->server('DOCUMENT_ROOT');
$rootDir = request()->root();
$directory = $docDir . $rootDir;
$fileinfo = pathinfo($detail['dl_url']);
$download = $directory . $detail['dl_url']; // 文件要下载的地址
Loader::model('ProductDl')->updateRow(['dl_count' => \think\Db::raw('`dl_count`+1')], ['id' => $id]);
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $fileinfo['basename']);
header('Content-Length: ' . filesize($download));
readfile($download);
exit();
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id) {
$view = Cookie::get('downloadview', 'history'); //print_r($history);exit;
if (empty($view) || $view != $id) {
Loader::model('Download')->where(['id' => $id])->setInc('viewcount');
Cookie::set('downloadview', $id, ['prefix' => 'history', 'expire' => 3600]);
}
}
protected function historydownload($id) {
$download = Cookie::get('download', 'history'); //print_r($history);exit;
if (isset($download) && !empty($download)) {
$download_ids = explode(',', $download);
if ($download_ids[0] != $id) {
array_unshift($download_ids, $id);
$download_ids = array_unique($download_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$download_ids = array_slice($download_ids, 0, $num);
while (count($download_ids) > $num) {
array_pop($download_ids);
}
Cookie::set('download', implode(',', $download_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('download', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
}
public function catelists_down($id = 0) {
//dump($id);die;
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('DownloadCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
$value['downloadCategory'] = $downloadCategory;
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['skeyword'] = '';
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function index($id = 0) {
//dump($id);die;
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('DownloadCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.app_model', 'a.support_os', 'a.format', 'a.viewcount', 'a.downloadcount', 'a.description', 'a.picture', 'a.tags', 'a.downloadpath', 'a.downloadpath64', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Download')->getCateDownloadLists($arg_where, $arg_order, $arg_field, 12);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
'page' => $dataObject->render(),
];
if ($this->request->isAjax()) {
return $this->result($value, true, '下载列表');
}
$downloadCategory = Loader::model('DownloadCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'pid' => 2], ['sort', 'id']);
$value['downloadCategory'] = $downloadCategory;
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['skeyword'] = '';
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
}

316
app/mobile/controller/Group.php Executable file
View File

@@ -0,0 +1,316 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2018-09-21
* Time: 17:36
*/
namespace app\mobile\controller;
use think\Loader;
class Group extends BaseController
{
public function index(){
return $this->view->fetch();
}
public function odm(){
return $this->view->fetch();
}
public function special(){
return $this->view->fetch();
}
public function h_speed(){
return $this->view->fetch();
}
public function job(){
return $this->view->fetch();
}
public function policy(){
return $this->view->fetch();
}
public function culture(){
return $this->view->fetch();
}
public function decennial(){
return $this->view->fetch();
}
public function Contact()
{
$banners = Loader::model("Banner")->alias('b')->field([
'b.id',
'b.typeid',
'bt.name' => 'typename',
'bt.description' => 'typedesc',
'b.name',
'b.categoryid',
'b.url',
'b.picture',
'b.alt',
'b.style',
'b.description' => 'desc',
'b.descolor',
'b.btncolor',
'b.videourl',
])
->join('banner_type bt', 'bt.stat= 0 and bt.id=b.typeid')
->where('b.stat', '=', 0)
->where('b.typeid', '=', 122)
->order(['sort' => 'asc', 'id' => 'asc'])
->select();
$data = [];
foreach ($banners as $val) {
$link = $val['url'];
if (empty($val['url']) && !empty($val['categoryid'])) {
$link = url_rewrite('productsub', ['id' => $val['categoryid']]);
}
$data[] = [
'id' => $val['id'],
'name' => $val['name'],
'link' => $link,
'picture' => $val['picture'],
'alt' => $val['alt'],
'style' => $val['style'],
'desc' => $val['desc'],
'desc_color' => $val['descolor'],
'btn_color' => $val['btncolor'],
'video_url' => $val['videourl'],
];
}
$this->assign('data', $data);
return $this->view->fetch();
}
public function faq(){
return $this->view->fetch();
}
public function honor(){
return $this->view->fetch();
}
public function industry(){
return $this->view->fetch();
}
public function weare(){
return $this->view->fetch();
}
public function wewill(){
return $this->view->fetch();
}
public function vision(){
return $this->view->fetch();
}
public function distributor2023(){
return $this->view->fetch();
}
public function introduction(){
return $this->view->fetch();
}
public function business(){
return $this->view->fetch();
}
public function rdcenter(){
return $this->view->fetch();
}
public function brand(){
return $this->view->fetch();
}
public function achievement(){
return $this->view->fetch();
}
public function mileage(){
return $this->view->fetch();
}
public function search(){
return $this->view->fetch();
}
public function transparent(){
return $this->view->fetch();
}
public function distributor(){
return $this->view->fetch();
}
public function headset(){
return $this->view->fetch();
}
public function socket(){
return $this->view->fetch();
}
public function charger(){
return $this->view->fetch();
}
public function fan(){
return $this->view->fetch();
}
public function ufo(){
return $this->view->fetch();
}
public function ssd(){
return $this->view->fetch();
}
public function thunderbolt_3(){
return $this->view->fetch();
}
public function stripe(){
return $this->view->fetch();
}
public function pssd(){
return $this->view->fetch();
}
public function series_95(){
return $this->view->fetch();
}
public function backup(){
return $this->view->fetch();
}
public function download(){
$keywords_pa = $this->request->param();
$keywords = '';
$map['stat'] = 0;
$map['cid'] = 43;
if ( !empty($keywords_pa['keywords']) ) {
$keywords = $keywords_pa['keywords'];
$map['name|app_model'] = array('like',"%$keywords%");
}
$downloads = model('download')->where($map)->select();
$this->assign('downloads',$downloads);
$this->assign('keywords',$keywords);
return $this->view->fetch();
}
public function report()
{
/* if ($this->customer_id <= 0)
$this->redirect('/login.html');*/
return $this->view->fetch();
}
public function create_report()
{
if ($this->customer_id <= 0)
return $this->json(-100, '请先登录');
$data = $this->request->post();
if (empty($data) || !is_array($data))
return $this->json(-1, '数据错误');
if ($data['product_name'] == '')
return $this->json(-2, '产品名称不能为空');
if ($data['product_model'] == '')
return $this->json(-3, '产品型号不能为空');
if ($data['product_manufacturer'] == '')
return $this->json(-4, '厂商不能为空');
// 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, '手机格式错误');
if ($data['customer_email'] != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/", $data['customer_email']))
return $this->json(-7, '邮箱格式错误');
$insert_data = [
'customer_id' => $this->customer_id,
'product_name' => $data['product_name'],
'product_model' => $data['product_model'],
'product_manufacturer' => $data['product_manufacturer'],
'buy_source' => $data['buy_source'],
'product_price' => floatval($data['product_price']),
'customer_name' => $data['customer_name'],
'customer_email' => $data['customer_email'],
'customer_telephone' => $data['customer_telephone'],
'description' => $data['description'],
'create_time' => time(),
];
$result = model('report')->insert($insert_data);
if (!$result)
return $this->json(-8, '提交失败');
return $this->json(200, 'ok');
}
public function question()
{
$data = $this->request->param();
$where = [
'a.stat' => 0,
'a.country_code' => $this->country_code,
];
$cid = isset($data['cid']) ? $data['cid'] : 0;
if ($cid)
$where['a.cid'] = $cid;
$search['keyword'] = '';
if (isset($data['keyword']) && $data['keyword'] != '')
{
$where['a.title'] = ['like', '%' . $data['keyword'] . '%'];
$search['keyword'] = $data['keyword'];
}
$order = [
'a.sort' => 'asc',
'a.id' => 'desc'
];
$field = ['a.*', 'b.name' => 'cate_name'];
$question_list = model('question')->alias('a')->join('question_category b', 'a.cid = b.id', 'LEFT')->where($where)->order($order)->field($field)->paginate(4);
// echo model('question')->getLastSql();die;
// tiaoshi($question_list->items());die;
$question_catelist = model('question_category')->where(['stat' => 0])->select();
$value = [
'question_list' => $question_list->isEmpty() ? null : $question_list->items(),
'page' => $question_list->render(),
'cid' => $cid,
'search' => $search,
'question_catelist' => $question_catelist
];
$this->assign($value);
return view();
}
public function question_detail()
{
$id = $this->request->param('id');
$question = model('question')->where(['id' => $id, 'stat' => 0])->find();
if (empty($question))
return $this->error('没有该问题');
// tiaoshi($question);die;
$this->assign('question', $question);
return $this->view->fetch();
}
}

View File

@@ -0,0 +1,17 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2018-09-21
* Time: 17:36
*/
namespace app\index\controller;
class Group extends BaseController
{
public function index(){
return $this->view->fetch();
}
}

113
app/mobile/controller/Index.php Executable file
View File

@@ -0,0 +1,113 @@
<?php
namespace app\mobile\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\TransDb;
class Index extends BaseController {
public function index() {
// 如果是手机端进官网
if (isMobile()) {
if ($_SERVER['HTTP_HOST']=="www.orico.cc" || $_SERVER['HTTP_HOST']=="orico.cc") {
return $this->redirect("http://www.orico.cc/usmobile");
}
}
else{
return $this->redirect("http://www.orico.com.cn");
}
/*
if ($_SERVER['HTTP_HOST']=="www.oricogroup.com" && $_SERVER['HTTP_HOST']=="oricogroup.com" ){
if($this->lang=='zh-cn'){
return $this->fetch('/index');
}else{
return $this->redirect("http://www.oricogroup.com/us");
}
}elseif($_SERVER['HTTP_HOST']=="www.orico.cc" || $_SERVER['HTTP_HOST']=="orico.cc"){
return $this->redirect("http://www.orico.cc/us");
}*/
$lebel_list = getDifferentProduct("recommend",12);
$this->assign('recomment_items',$lebel_list);
$blog_list = getArticleList();
$this->assign('blog_list',$blog_list);
$faqData = getFaqList();
$this->assign('faqData',$faqData);
return $this->fetch('/index');
}
public function info(){
echo "\nstart: ".date("Y-m-d H:i:s")."\n";
$TransDb = new TransDb();
$TransDb->selectAllStruct("ProductCategory");
//$getDb = $TransDb->getkv();
echo "\nend :".date("Y-m-d H:i:s")."\n";
dump($TransDb);
// phpinfo();
}
public function feedback() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error('未知错误');
}
$this->verify_check($data['authcode'], 'yanzhengma') || $this->error('验证码不正确');
$validaterule = [
'name' => 'require',
'subject' => 'require',
'contact' => 'require',
'content' => 'require',
];
$validatemsg = [
'name.require' => '名称不能为空',
'subject.require' => '主题不能为空',
'contact.require' => '联系方式不能为空',
'content.require' => '内容不能为空',
];
if (empty($data['way'])) {
return $this->error('请选择正确的联系方式');
} else {
if ($data['way'] == 'E-mail') {
$validaterule['contact'] = 'email';
$validatemsg['contact.email'] = '联系方式格式不正确';
}
if ($data['way'] == 'tel') {
$validaterule['contact'] = ['regex' => '^1[345789]\d{9}$|^([0-9]{3,4}-?)?[0-9]{7,8}$'];
$validatemsg['contact.regex'] = '联系方式格式不正确';
}
}
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$set = [
'feedback_type' => isset($data['feedback_type']) ? $data['feedback_type'] : '',
'name' => isset($data['name']) ? $data['name'] : 'Name',
'subject' => isset($data['subject']) ? $data['subject'] : '',
'content' => isset($data['content']) ? $data['content'] : '',
'way' => isset($data['way']) ? $data['way'] : '',
'contact' => isset($data['contact']) ? $data['contact'] : '',
'addtime' => date('Y-m-d H:i:s'),
];
$model = Loader::model('Msgform')->insertRow($set);
if ($model && $model->getData('id')) {
return $this->success('成功!成功!等待管理员查看', url('/'));
} else {
return $this->error('操作失败');
}
}
return $this->result(['code' => false, 'msg' => '未知错误'], false, '未知错误');
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace app\index\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\TransDb;
class Index extends BaseController {
public function index() {
return $this->fetch('/index');
}
public function info(){
echo "\nstart: ".date("Y-m-d H:i:s")."\n";
$TransDb = new TransDb();
$TransDb->setkv("myTest","这就是一个测试",true);
$getDb = $TransDb->getkv("myTest");
echo "\nend :".date("Y-m-d H:i:s")."\n";
dump($getDb);
// phpinfo();
}
public function feedback() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error('未知错误');
}
$this->verify_check($data['authcode'], 'yanzhengma') || $this->error('验证码不正确');
$validaterule = [
'name' => 'require',
'subject' => 'require',
'contact' => 'require',
'content' => 'require',
];
$validatemsg = [
'name.require' => '名称不能为空',
'subject.require' => '主题不能为空',
'contact.require' => '联系方式不能为空',
'content.require' => '内容不能为空',
];
if (empty($data['way'])) {
return $this->error('请选择正确的联系方式');
} else {
if ($data['way'] == 'E-mail') {
$validaterule['contact'] = 'email';
$validatemsg['contact.email'] = '联系方式格式不正确';
}
if ($data['way'] == 'tel') {
$validaterule['contact'] = ['regex' => '^1[345789]\d{9}$|^([0-9]{3,4}-?)?[0-9]{7,8}$'];
$validatemsg['contact.regex'] = '联系方式格式不正确';
}
}
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$set = [
'feedback_type' => isset($data['feedback_type']) ? $data['feedback_type'] : '',
'name' => isset($data['name']) ? $data['name'] : 'Name',
'subject' => isset($data['subject']) ? $data['subject'] : '',
'content' => isset($data['content']) ? $data['content'] : '',
'way' => isset($data['way']) ? $data['way'] : '',
'contact' => isset($data['contact']) ? $data['contact'] : '',
'addtime' => date('Y-m-d H:i:s'),
];
$model = Loader::model('Msgform')->insertRow($set);
if ($model && $model->getData('id')) {
return $this->success('成功!成功!等待管理员查看', url('/'));
} else {
return $this->error('操作失败');
}
}
return $this->result(['code' => false, 'msg' => '未知错误'], false, '未知错误');
}
}

View File

@@ -0,0 +1,90 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
use think\validate;
class Pinglun extends BaseController {
public function lists($type = '', $cid = 0) {
$arg_where = ['stat' => 0, 'display' => 1];
if ($type) {
$arg_where['typeid'] = $type;
}
if ($cid) {
$arg_where['content_id'] = $cid;
}
$arg_order = ['id' => 'desc'];
$arg_field = ['*'];
$dataObject = Loader::model('Pinglun')->getPageList($arg_where, $arg_order, $arg_field, 12);
//header('content-type:text/html;charset=utf-8;');
$value['list'] = $dataObject->isEmpty() ? null : $dataObject->items();
$value['page'] = $dataObject->render();
$value['total'] = $dataObject->total();
if ($this->request->isAjax()) {
return $this->result($value, 'pinglun', true);
}
$value['cid'] = $cid;
$value['type'] = ucfirst($type);
$value['seo_title'] = config('article_seo_title')? : config('website_seo_title');
$value['seo_keyword'] = config('article_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('article_seo_description')? : config('website_seo_description');
$this->assign($value);
return $this->fetch('pinglun');
}
public function add() {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->json(-3, '未知错误');
}
if (!$this->check_token($data['id'], $data['time'], $data['token'])) {
return $this->json(-101, 'token过期');
}
// $row = Loader::model('Pinglun')->getRow(['customer_id' => $data['id']], null, ['id' => 'desc']);
// if ($row && $row['id']) {
// $createtime = strtotime($row['createtime']);
// if (time() - $createtime < 60) {
// return $this->json(-2,'您已评论过了请不要重复评论');
// }
// }
// 验证....
$validate = Loader::validate('pinglun');
if (!$validate->scene('add')->check($data)) {
return $this->json(-1, $validate->getError());
}
$addtime = date('Y-m-d H:i:s');
$txarr = [1, 2, 3, 4, 5];
shuffle($txarr);
$set = [
'customer_id' => $data['id'],
'cname' => $data['firstname'],
'typeid' => isset($data['typeid']) ? $data['typeid'] : 'Article',
'pid' => isset($data['pid']) ? $data['pid'] : 0,
'content_id' => isset($data['cid']) ? $data['cid'] : 0,
'content' => $data['content'],
'tx' => $txarr[0],
'stat' => 0,
'createtime' => $addtime,
'lasttime' => $addtime,
];
$model = Loader::model('Pinglun')->insert($set);
if ($model) {
isset($data['cid']) ? Loader::model('Article')->where(['id' => $data['cid']])->setInc('commentcount') : '';
return $this->json(1, '评论成功!');
} else {
return $this->json(-5, '操作失败');
}
}
}

364
app/mobile/controller/Product.php Executable file
View File

@@ -0,0 +1,364 @@
<?php
namespace app\mobile\controller;
use think\Collection;
use think\Db;
use think\Loader;
use think\Cookie;
use think\Config;
class Product extends BaseController {
public function lists($id = 0) {
$category = Loader::model('ProductCategory')->getRow(['stat' => 0, 'pid' => 0], null, ['id' => 'asc']);
// header("content-type: text/html; charset=utf8");
// dump(json_decode(json_encode($category), true));die;
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$value = [
'category' => $category,
];
$value['seo_title'] = config('product_seo_title')? : config('website_seo_title');
$value['seo_keyword'] = config('product_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('product_seo_description')? : config('website_seo_description');
$this->assign($value);
return $this->fetch('catelists');
}
public function catelists($id = 0) {
$arg_where = ['a.siteid' => $this->siteid, 'country_code' => $this->country_code];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('ProductCategory')->getRow($id);
}
//echo "<pre>=="; print_r($category); exit;
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
// 手机端热门产品
$hot_tags = 'hot_category_id_' . $category['id'];
$hot_product_where = ['typeid' => 6, 'stat' => 0, 'tags' => $hot_tags];
$hot_product_order = ['sort' => 'asc'];
$hot_product = Loader::model('ad')->where($hot_product_where)->order($hot_product_order)->limit(4)->select();
$value = [
'category' => $category,
];
$value['hot_product'] = empty($hot_product) ? "" : $hot_product;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
//echo "--".$template."<pre>=="; print_r($value);exit;
return $this->fetch('catelists');
}
public function subcatelists($id = 0) {
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('ProductCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$child = model('product_category')->where(['stat' => 0, 'isshow' => 1, 'pid' => $id])->find();
if (!empty($child)) {
// 有下级分类
$subproductCategory = $this->list_to_tree($this->categoryList, 'id', 'pid', 'child', $id);
$cate_ids = array();
foreach($subproductCategory as $kc => $subCategory){
$cate_ids[] = $subCategory['id'];
}
$cate_id = implode(",", $cate_ids);
} else {
// 如果是最低级分类
$subproductCategory = $this->list_to_tree($this->categoryList, 'id', 'pid', 'child', $category['pid']);
$cate_id = $category['id'];
}
// 获取分类下的所有产品
$where = ['stat' => 0, 'country_code' => $this->country_code];
$where['cid'] = ['in', $cate_id];
$where = ['stat' => 0, 'cid' => $cate_id];
$order = ['sort' => 'asc', 'id' => 'desc'];
$where['is_show'] = 0;
$field = ['id, name, brand_id'];
$product = Loader::model('product')->where($where)->field($field)->order($order)->select();
foreach ($product as $k => $v) {
$product[$k]['product_two_img'] = [];
$product[$k]['product_two_img'] = Loader::model('product_two_img')->where(['product_id' => $v['id'], 'stat' => 0])->select();
}
$value['product'] = $product;
$value['subproductCategory'] = $subproductCategory;
$value['pid'] = $id;
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function ajaxcatelists($id = 0) {
$arg_where = ['p.stat' => 0, 'c.stat' => 0, 'p.siteid' => $this->siteid];
$id = intval($id);
if ($id > 0) {
if (0) {
$ids = Loader::model('ProductCategory')->getChildIDArray(4);
$arg_where['cid'] = ['in', $ids];
} else {
$arg_where['cid'] = $id;
}
$category = Loader::model('ProductCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$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.picture_back', 'p.createtime', 'p.createtime', 'c.name' => 'categoryname', 'c.id' => 'categoryid'];
$arg_order['p.sort'] = 'asc';
$arg_order['p.id'] = 'desc';
$dataObject = Loader::model('Product')->getCateProductLists($arg_where, $arg_order, $arg_field, 8);
if ($dataObject->isEmpty()) {
$value = ['list' => null];
} else {
$this->assign(['list' => $dataObject->items(), 'category' => $category,]);
$value = ['list' => $this->fetch()];
}
return $this->result($value, true, '分类列表');
}
public function detail($id = 0, $color = '') {
if ($id > 0) {
$detail = Loader::model('Product')->where(['stat' => 0, 'is_show' => 0, 'country_code' => $this->country_code, 'id' => $id])->find();
/*if ($this->customer_id > 0)
{
// 如果登录成功判断用户是否收藏该产品
$customer_info = json_decode(Cookie::get('c'), true);
if (empty($customer_info))
{
$detail['is_collection'] = 0;
}
else
{
$where = [
'customer_id' => $customer_info['id'],
'type' => 1,
'coll_id' => $detail['id'],
'stat' => 0
];
$result = model('collection')->where($where)->find();
if ($result)
{
$detail['is_collection'] = 1;
}
else
{
$detail['is_collection'] = 0;
}
}
}
else
{
$detail['is_collection'] = 0;
}*/
if(empty($detail)){
//return exception('该产品已下架,请检查后再操作');
return $this->error('该产品已下架,请检查后再操作');
}
$detail['is_collection'] = 0;
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
$category = Loader::model('ProductCategory')->getRow($detail['cid']);
$cid = Loader::model('ProductCategory')->getRow($category['pid']);
$pid = Loader::model('ProductCategory')->getRow($cid['pid']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$template = $category['tempdetail'];
$detail['product_two_img'] = model('product_two_img')->where(['stat' => 0, 'product_id' => $id])->select();
$value = [
'detail' => $detail,
'category' => $category,
'pid' =>$pid,
'cid'=>$cid
//'prev_detail' => $prev_detail,
//'next_detail' => $next_detail,
];
$value['product_attr'] = is_null(json_decode($detail['product_attr'])) ? $detail['product_attr'] : json_decode($detail['product_attr']);
$tmp_product_images = Loader::model('ProductImage')->getList(array('product_id' => $detail['id'],'stat' => 0, 'country_code' => $this->country_code), ['image_sort' => 'asc', 'id' => 'asc'], ['id', 'product_id', 'image_url', 'image_sort', 'image_desc', 'image_color']);
// $value['product_dls'] = Loader::model('ProductDl')->getList(array('product_id' => $detail['id']), ['dl_sort' => 'asc', 'id' => 'desc'], ['id', 'product_id', 'dl_url', 'dl_sort', 'dl_name', 'dl_type']);
// $value['product_questions'] = Loader::model('Question')->getList(array('product' => $detail['id']), ['sort' => 'asc', 'id' => 'asc'], ['id', 'name', 'product', 'sort', 'headline', 'recommend', 'description', 'createtime']);
$product_relateds = Loader::model('Product')->getRelatedProductList(array('pr.product_id' => $detail['id']), ['pr.related_sort' => 'asc', 'pr.id' => 'asc',], ['p.id', 'p.name', 'p.shortname', 'p.picture', 'p.sort', 'p.ishot', 'p.list_bk_img','p.isnew', 'p.recommend', 'p.description', 'p.createtime', 'p.brand_id','pr.id' => 'related_id', 'pr.related_product_id', 'pr.related_sort', 'pr.related_desc']);
foreach ($product_relateds as $k => $v) {
$res = Loader::model('product_two_img')->where(['product_id' => $v['id'], 'stat' => 0])->find();
$product_relateds[$k]['product_two_img'] = $res;
}
$product_images = [];
$attributes = [];
foreach ($tmp_product_images as $k => $v) {
//兼容新旧两种版附加图、相册属性及图片
if (is_string($v['image_url']) && json_decode($v['image_url'])) {
$v['image_url'] = json_decode($v['image_url'], true); //多图Json格式
$v['image_color'] = json_decode($v['image_color'], true); //多属性规则: 颜色,尺码,排序等
if(isset($value['product_attr']) && is_array($value['product_attr'])){
foreach($value['product_attr'] as $ka => $attr){
$attributes[$attr][] = $v['image_color'][$ka][$attr];
}
}
$product_images[] = $v;
}
//原版, 仅支持颜色属性
else{
$image_color = $v['image_color'];
$pos = strrpos($image_color, '/');
$key = substr($image_color, $pos + 1, strpos($image_color, '.') - $pos - 1);
$product_images[$key][] = $v;
}
}
foreach($attributes as $attrbute => $attrValue) {
$attributes[$attrbute] = array_unique($attrValue);
}
//echo "<pre>++"; print_r($attributes);
$value['attributes'] = $attributes;
/*foreach ($tmp_product_images as $k => $v) {
$image_color = $v['image_color'];
$pos = strrpos($image_color, '/');
$key = substr($image_color, $pos + 1, strpos($image_color, '.') - $pos - 1);
$product_images[$key][] = $v;
}*/
$value['product_images'] = $product_images;
$value['product_relateds'] = $product_relateds;
$value['seo_title'] = $detail['seo_title']? : $detail['name'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $detail['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $detail['seo_description']? : config('website_seo_description');
$value['color'] = $color;
//评论数据获取
$where = [
'product_id' => $detail['id']
];
$count = db('shopselle')->where($where)->count();
$list = db('shopselle')->where($where)->paginate(4,$count);
foreach ($list as $k => $v){
$v['pics'] = json_decode($v['pics']);
$list[$k] = $v;
}
$page = $list->render();
$this->assign('page',$page);
$this->assign('list',$list);
$this->assign('count',$count);
$this->assign($value);
$this->viewcount($id);
return $this->fetch($template);
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id) {
$view = Cookie::get('productview', 'history');
if (empty($view) || $view != $id) {
Loader::model('Product')->where(['id' => $id])->setInc('viewcount');
Cookie::set('productview', $id, ['prefix' => 'history', 'expire' => 3600]);
}
}
protected function historyproduct($id) {
$product = Cookie::get('product', 'history'); //print_r($history);exit;
if (isset($product) && !empty($product)) {
$product_ids = explode(',', $product);
if ($product_ids[0] != $id) {
array_unshift($product_ids, $id);
$product_ids = array_unique($product_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$product_ids = array_slice($product_ids, 0, $num);
while (count($product_ids) > $num) {
array_pop($product_ids);
}
Cookie::set('product', implode(',', $product_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('product', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
}
/********新品展示 *********/
public function newarrival() {
$value = Loader::model('Product')->getNewItemLists(array(),['t.sort' => 'asc', 't.id' => 'asc',], ['p.id', 'p.name', 'p.shortname', 'p.picture', 'p.sort', 'p.ishot', 'p.list_bk_img','p.isnew', 'p.recommend', 'p.description','p.brand_id', 'p.createtime', 't.id' => 'category_id', 't.name'=>'category_name', 't.sort']);
//分类分组
$newProduct = array();
foreach($value as $key => $item) {
$newProduct[$item['category_id']]['category_id'] = $item['category_id'];
$newProduct[$item['category_id']]['category_name'] = $item['category_name'];
$newProduct[$item['category_id']]['list'][] = $item;
}
//echo "<pre>---"; print_r($productCategory);die; //echo "<pre>=="; print_r($productCategory);die;
$this->assign('newProduct',$newProduct);
$value['category'] = "New Product";
$value['seo_title'] = $value['category']? : config('website_seo_title_us');
$value['seo_keyword'] = $value['category']? : config('website_seo_keyword');
$value['seo_description'] = $value['category']? : config('website_seo_description');
$this->assign($value);
return $this->fetch('new');
}
}

View File

@@ -0,0 +1,188 @@
<?php
namespace app\index\controller;
use think\Loader;
use think\Cookie;
use think\Config;
class Product extends BaseController {
public function lists($id = 0) {
$category = Loader::model('ProductCategory')->getRow(['stat' => 0, 'pid' => 0], null, ['id' => 'asc']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$value = [
'category' => $category,
];
$value['seo_title'] = config('product_seo_title')? : config('website_seo_title');
$value['seo_keyword'] = config('product_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('product_seo_description')? : config('website_seo_description');
$this->assign($value);
return $this->fetch('catelists');
}
public function catelists($id = 0) {
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('ProductCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
// $arg_order = ['a.id' => 'desc'];
// $arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
// $dataObject = Loader::model('Product')->getCateProductLists($arg_where, $arg_order, $arg_field, 12);
// $value = [
// 'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
// 'page' => $dataObject->render(),
// ];
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function subcatelists($id = 0) {
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('ProductCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$subproductCategory = $this->list_to_tree($this->categoryList, 'id', 'pid', 'child', $id);
$value = ['subproductCategory' => $subproductCategory];
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function ajaxcatelists($id = 0) {
$arg_where = ['p.stat' => 0, 'c.stat' => 0, 'p.siteid' => $this->siteid];
$id = intval($id);
if ($id > 0) {
if (0) {
$ids = Loader::model('ProductCategory')->getChildIDArray(4);
$arg_where['cid'] = ['in', $ids];
} else {
$arg_where['cid'] = $id;
}
$category = Loader::model('ProductCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$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.picture_back', 'p.createtime', 'p.createtime', 'c.name' => 'categoryname', 'c.id' => 'categoryid'];
$arg_order['p.sort'] = 'asc';
$arg_order['p.id'] = 'desc';
$dataObject = Loader::model('Product')->getCateProductLists($arg_where, $arg_order, $arg_field, 8);
if ($dataObject->isEmpty()) {
$value = ['list' => null];
} else {
$this->assign(['list' => $dataObject->items(), 'category' => $category,]);
$value = ['list' => $this->fetch()];
}
return $this->result($value, true, '分类列表');
}
public function detail($id = 0, $color = '') {
if ($id > 0) {
$detail = Loader::model('Product')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
$addproduct = Loader::model('ProductAddition')->getRow(['aid' => $detail['id']]); //print_r($addproduct);exit;
$category = Loader::model('ProductCategory')->getRow($detail['cid']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$template = $category['tempdetail'];
//$prev_detail = Loader::model('Product')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
//$next_detail = Loader::model('Product')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
$value = [
'detail' => $detail,
'addproduct' => $addproduct,
'category' => $category,
//'prev_detail' => $prev_detail,
//'next_detail' => $next_detail,
];
$value['product_images'] = Loader::model('ProductImage')->getList(array('product_id' => $detail['id']), ['image_sort' => 'asc', 'id' => 'asc'], ['id', 'product_id', 'image_url', 'image_sort', 'image_desc', 'image_color']);
$value['product_dls'] = Loader::model('ProductDl')->getList(array('product_id' => $detail['id']), ['dl_sort' => 'asc', 'id' => 'desc'], ['id', 'product_id', 'dl_url', 'dl_sort', 'dl_name', 'dl_type']);
$value['product_questions'] = Loader::model('Question')->getList(array('product' => $detail['id']), ['sort' => 'asc', 'id' => 'asc'], ['id', 'name', 'product', 'sort', 'headline', 'recommend', 'description', 'createtime']);
//$value['product_relates'] = Loader::model('Product')->getList(array('cid' => $detail['cid'], 'id' => ['neq', $detail['id']]), ['sort' => 'asc', 'id' => 'asc'], ['id', 'name', 'shortname', 'picture', 'sort', 'ishot', 'isnew', 'recommend', 'description', 'createtime']);
$value['product_attrs'] = Loader::model('ProductAttr')->getProductAttrLists(['product_id' => $detail['id']], ['id' => 'desc'], ['pa.id', 'pa.attribute_id', 'pa.value', 'pa.price', 'a.name', 'a.type'], 120);
$value['product_relateds'] = Loader::model('Product')->getRelatedProductList(array('pr.product_id' => $detail['id']), ['pr.related_sort' => 'asc', 'pr.id' => 'asc',], ['p.id', 'p.name', 'p.shortname', 'p.picture', 'p.sort', 'p.ishot', 'p.isnew', 'p.recommend', 'p.description', 'p.createtime', 'pr.id' => 'related_id', 'pr.related_product_id', 'pr.related_sort', 'pr.related_desc']);
$value['seo_title'] = $detail['seo_title']? : $detail['name'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $detail['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $detail['seo_description']? : config('website_seo_description');
$value['color'] = $color;
$this->assign($value);
$this->viewcount($id);
return $this->fetch($template);
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id) {
$view = Cookie::get('productview', 'history'); //print_r($history);exit;
if (empty($view) || $view != $id) {
Loader::model('Product')->where(['id' => $id])->setInc('viewcount');
Cookie::set('productview', $id, ['prefix' => 'history', 'expire' => 3600]);
}
}
protected function historyproduct($id) {
$product = Cookie::get('product', 'history'); //print_r($history);exit;
if (isset($product) && !empty($product)) {
$product_ids = explode(',', $product);
if ($product_ids[0] != $id) {
array_unshift($product_ids, $id);
$product_ids = array_unique($product_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$product_ids = array_slice($product_ids, 0, $num);
while (count($product_ids) > $num) {
array_pop($product_ids);
}
Cookie::set('product', implode(',', $product_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('product', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
}
}

View File

@@ -0,0 +1,162 @@
<?php
namespace app\index\controller;
use think\Loader;
use think\Cookie;
use think\Config;
class Product extends BaseController {
public function lists($id = 0) {
// echo 'asdf';die;
$category = Loader::model('ProductCategory')->getRow(['stat' => 0, 'pid' => 0], null, ['id' => 'asc']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$value = [
'category' => $category,
];
$value['seo_title'] = config('product_seo_title')? : config('website_seo_title');
$value['seo_keyword'] = config('product_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('product_seo_description')? : config('website_seo_description');//print_r($category);die;
$this->assign($value);
return $this->fetch('catelists');
}
public function catelists($id = 0) {
// echo 'asdf';die;
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('ProductCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
// $arg_order = ['a.id' => 'desc'];
// $arg_field = ['a.*', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
// $dataObject = Loader::model('Product')->getCateProductLists($arg_where, $arg_order, $arg_field, 12);
// $value = [
// 'list' => $dataObject->isEmpty() ? null : $dataObject->items(), //$dataObject->getCollection()->toArray()
// 'page' => $dataObject->render(),
// ];
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function subcatelists($id = 0) {
$arg_where = ['a.siteid' => $this->siteid];
if ($id > 0) {
$arg_where['cid'] = $id;
$category = Loader::model('ProductCategory')->getRow($id);
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$subproductCategory = $this->list_to_tree($this->categoryList, 'id', 'pid', 'child', $id);
$value = ['subproductCategory' => $subproductCategory];
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
$value['category'] = $category;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function detail($id = 0, $color = '') {
if ($id > 0) {
$detail = Loader::model('Product')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
$addproduct = Loader::model('ProductAddition')->getRow(['aid' => $detail['id']]); //print_r($addproduct);exit;
$category = Loader::model('ProductCategory')->getRow($detail['cid']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
$template = $category['tempdetail'];
//$prev_detail = Loader::model('Product')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
//$next_detail = Loader::model('Product')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
$value = [
'detail' => $detail,
'addproduct' => $addproduct,
'category' => $category,
//'prev_detail' => $prev_detail,
//'next_detail' => $next_detail,
];
$value['product_images'] = Loader::model('ProductImage')->getList(array('product_id' => $detail['id']), ['image_sort' => 'asc', 'id' => 'asc'], ['id', 'product_id', 'image_url', 'image_sort', 'image_desc', 'image_color']);
$value['product_dls'] = Loader::model('ProductDl')->getList(array('product_id' => $detail['id']), ['dl_sort' => 'asc', 'id' => 'desc'], ['id', 'product_id', 'dl_url', 'dl_sort', 'dl_name', 'dl_type']);
$value['product_questions'] = Loader::model('Question')->getList(array('product' => $detail['id']), ['sort' => 'asc', 'id' => 'asc'], ['id', 'name', 'product', 'sort', 'headline', 'recommend', 'description', 'createtime']);
//$value['product_relates'] = Loader::model('Product')->getList(array('cid' => $detail['cid'], 'id' => ['neq', $detail['id']]), ['sort' => 'asc', 'id' => 'asc'], ['id', 'name', 'shortname', 'picture', 'sort', 'ishot', 'isnew', 'recommend', 'description', 'createtime']);
$value['product_attrs'] = Loader::model('ProductAttr')->getProductAttrLists(['product_id' => $detail['id']], ['id' => 'desc'], ['pa.id', 'pa.attribute_id', 'pa.value', 'pa.price', 'a.name', 'a.type'], 120);
$value['product_relateds'] = Loader::model('Product')->getRelatedProductList(array('pr.product_id' => $detail['id']), ['pr.related_sort' => 'asc', 'pr.id' => 'asc',], ['p.id', 'p.name', 'p.shortname', 'p.picture', 'p.sort', 'p.ishot', 'p.isnew', 'p.recommend', 'p.description', 'p.createtime', 'pr.id' => 'related_id', 'pr.related_product_id', 'pr.related_sort', 'pr.related_desc']);
$value['seo_title'] = $detail['seo_title']? : $detail['name'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $detail['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $detail['seo_description']? : config('website_seo_description');
$value['color'] = $color;
$this->assign($value);
$this->viewcount($id);
return $this->fetch($template);
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id) {
$view = Cookie::get('productview', 'history'); //print_r($history);exit;
if (empty($view) || $view != $id) {
Loader::model('Product')->where(['id' => $id])->setInc('viewcount');
Cookie::set('productview', $id, ['prefix' => 'history', 'expire' => 3600]);
}
}
protected function historyproduct($id) {
$product = Cookie::get('product', 'history'); //print_r($history);exit;
if (isset($product) && !empty($product)) {
$product_ids = explode(',', $product);
if ($product_ids[0] != $id) {
array_unshift($product_ids, $id);
$product_ids = array_unique($product_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$product_ids = array_slice($product_ids, 0, $num);
while (count($product_ids) > $num) {
array_pop($product_ids);
}
Cookie::set('product', implode(',', $product_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('product', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* Created by PhpStorm.
* User: ORICO
* Date: 2019-01-23
* Time: 15:17
*/
namespace app\mobile\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
class Qqlogin extends BaseController
{
public function index(){
include_once ("../extend/API/qqConnectAPI.php");
$qc = new \QC();
$qc->qq_login();
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Config;
use think\Db;
class Search extends BaseController {
public function index() {
$skeyword = $this->request->get('skeyword', '', 'urldecode,strval');
$search = [];
if ($skeyword != '') {
$skeyword = trim($skeyword);
$search['skeyword'] = $skeyword;
$arg_where['name|brand_id|keyword'] = ['like', '%' . $search['skeyword'] . '%'];
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
}
$arg_where['stat'] = 0;
$arg_where['country_code'] = $this->country_code;
$arg_where['is_show'] = 0;
$dataObject = Loader::model('Product')->field(['id', 'name', 'description', 'list_bk_img' => 'picture', 'createtime','brand_id', "'productdetail'" => 'link'])->where($arg_where)->paginate(6);
$value = [
'list' => $dataObject->isEmpty() ? null : $dataObject->items(),
'page' => $dataObject->render(),
];
$value['search'] = $search;
$this->assign($value);
return $this->fetch();
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Config;
class Singlepage extends BaseController {
public function detail($id = 0, $view = '') {
if ($id > 0) {
$singlepage = Loader::model('Singlepage')->getRow($id);
if (empty($singlepage)) {
return exception('数据有误,请检查后再操作');
}
$value['singlepage'] = $singlepage;
$value['seo_title'] = $singlepage['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $singlepage['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $singlepage['seo_description']? : config('website_seo_description');
$this->assign($value);
if ($view) {
return $this->fetch($view);
} else {
return $this->fetch();
}
}
return exception('数据有误,请检查后再操作');
}
}

256
app/mobile/controller/TopsNas.php Executable file
View File

@@ -0,0 +1,256 @@
<?php
namespace app\mobile\controller;
use think\Loader;
class TopsNas extends BaseController
{
public function _initialize()
{
parent::_initialize();
parent::nasNavigation();
}
private function getBanners($typeids)
{
$banners = Loader::model("Banner")->alias('b')->field([
'b.id',
'b.typeid',
'bt.name' => 'typename',
'bt.description' => 'typedesc',
'b.name',
'b.categoryid',
'b.url',
'b.picture',
'b.alt',
'b.style',
'b.description' => 'desc',
'b.descolor',
'b.btncolor',
'b.videourl',
])
->join('banner_type bt', 'bt.stat= 0 and bt.id=b.typeid')
->where('b.stat', '=', 0)
->where('b.typeid', 'in', $typeids)
->order(['sort' => 'asc', 'id' => 'asc'])
->select();
$chucks = [];
foreach ($banners as $val) {
if (empty($chucks['typeid_' . $val['typeid']])) {
$chucks['typeid_' . $val['typeid']]['id'] = $val['typeid'];
$chucks['typeid_' . $val['typeid']]['name'] = $val['typename'];
$chucks['typeid_' . $val['typeid']]['desc'] = $val['typedesc'];
$chucks['typeid_' . $val['typeid']]['banners'] = [];
}
$link = $val['url'];
if (empty($val['url']) && !empty($val['categoryid'])) {
$link = url_rewrite('productsub', ['id' => $val['categoryid']]);
}
$chucks['typeid_' . $val['typeid']]['banners'][] = [
'id' => $val['id'],
'name' => $val['name'],
'link' => $link,
'picture' => $val['picture'],
'alt' => $val['alt'],
'style' => $val['style'],
'desc' => $val['desc'],
'desc_color' => $val['descolor'],
'btn_color' => $val['btncolor'],
'video_url' => $val['videourl'],
];
}
return $chucks;
}
/**
* nas专题页首页
*/
public function index()
{
$chucks = $this->getBanners([113, 114, 115, 116, 117, 118]);
$data = [
'swiper' => $chucks['typeid_113'],
'product' => $chucks['typeid_114'],
'video' => $chucks['typeid_115'],
'plan' => $chucks['typeid_116'],
'weline' => $chucks['typeid_117'],
'download' => $chucks['typeid_118'],
];
$this->assign("data", $data);
return $this->fetch();
}
/**
* nas新品公测
*/
public function beta()
{
return $this->fetch();
}
/**
* nas 客户合作
*/
public function cooperation()
{
$chucks = $this->getBanners([123, 124, 125]);
$data = [
'image_text' => $chucks['typeid_123'],
'advantage' => $chucks['typeid_124'],
'expectation' => $chucks['typeid_125'],
];
$data['advantage']['banners'] = array_chunk($data['advantage']['banners'], 2);
$this->assign("data", $data);
return $this->fetch();
}
/**
* getProductSeries 获取产品系列
*/
private function getProductSeries()
{
return Loader::model('ProductSeries')
->field([
'id',
'name',
])
->where('stat', '=', 0)
->where('isshow', '=', 1)
->order(['id' => 'asc', 'sort' => 'asc'])
->select();
}
/**
* getCategoryTree 获取特定文章分类树
*/
private function getCategoryTree($cid = 36)
{
// 设备
$category = Loader::model('ArticleCategory')
->field([
'id',
'pid',
'name',
])
->where('isshow', '=', 1)
->where('country_code', '=', $this->country_code)
->order(['sort' => 'asc'])
->select();
$category_array = collection($category)->toArray();
$category_tree = $this->buildTree($category_array, $cid);
return $category_tree;
}
/**
* getCategoryChildren 获取子孙分类id
*/
private function getCategoryChildren($category)
{
return \think\Db::query("
SELECT t2.id
FROM (
SELECT
@r AS _id, (SELECT @r := GROUP_CONCAT(id) FROM cod_article_category WHERE FIND_IN_SET(pid, _id)) AS parent_id
FROM
(SELECT @r := $category) vars, cod_article_category h
WHERE @r <> 0) t1
JOIN cod_article_category t2
ON FIND_IN_SET(t2.pid, t1._id)
ORDER BY t2.id;
");
}
/**
* getProductSeriesIdMaps 获取文章系列型号
*/
private function getProductSeriesIdMaps($article)
{
$series = [];
$array_items = array_column($article, 'product_series');
array_walk($array_items, function ($val) use (&$series) {
$series = array_merge($series, explode(',', $val));
});
if (!empty($series)) {
$product_series = Loader::model('ProductSeries')
->where('id', 'in', array_unique($series))
->column('name', 'id');
foreach ($article as $key => $val) {
$p_series = explode(',', $val['product_series']);
$p_item = [];
foreach ($p_series as $k => $v) {
if (!empty($product_series[$v])) {
$p_item[] = $product_series[$v];
}
}
$article[$key]['product_series'] = $p_item;
}
}
return $article;
}
/**
* guide 使用教程
*/
public function guide()
{
$params = [
'keywords' => input('get.keywords'),
'series' => input('get.series'),
'device' => input('get.device', 38),
'category' => input('get.category'),
'page' => input('get.page', 1),
'size' => input('get.size', 10),
];
// 型号
$this->assign('series', $this->getProductSeries());
// 设备
$this->assign('category', $this->getCategoryTree(36));
// 文章列表
$article = Loader::model('Article')
->field([
'id',
'name',
'description',
'product_series',
'content',
])
->where('stat', '=', 0)
->where('country_code', '=', $this->country_code)
->where(function ($query) use ($params) {
if (!empty($params['keywords'])) {
$query->where(function ($q) use ($params) {
$q->where('name', 'like', '%' . $params['keywords'] . '%')
->whereOr(sprintf('MATCH(content) AGAINST("%s" IN BOOLEAN MODE)', $params['keywords']));
});
}
if (!empty($params['device']) && empty($params['category'])) {
$params['category'] = $params['device'];
}
$children = $this->getCategoryChildren($params['category']);
$categorys = array_merge([$params['category']], array_column($children, 'id'));
$query->where('cid', 'in', $categorys);
if (!empty($params['series'])) {
$query->where(sprintf('find_in_set(%s, `product_series`)', $params['series']));
}
})
->order(['id' => 'desc', 'sort' => 'desc'])
->paginate($params['size']);
$list = $this->getProductSeriesIdMaps($article->items());
$this->assign('list', $list);
$this->assign('page', $article->render());
return $this->fetch();
}
}

142
app/mobile/controller/User.php Executable file
View File

@@ -0,0 +1,142 @@
<?php
namespace app\mobile\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
class User extends BaseController {
// 初始化
protected function _initialize() {
parent::_initialize();
if ($this->customer_id <= 0) {
abort(redirect(url('/login')));
}
}
public function index() {
$row = Loader::model('Customer')->getRow(['id' => $this->customer_id]);
if (empty($row)) {
return exception('数据有误,请检查后再操作');
}
$value['hangye'] = (array) Config::get('website_hangye');
$value['zhiye'] = (array) Config::get('website_zhiye');
$value['customer'] = $row;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
// //验证规则
// $validaterule = ['birthday' => 'require|date',];
// //验证提示信息
// $validatemsg = ['birthday.date' => '生日不是日期格式',];
// $valid_result = $this->validate($data, $validaterule, $validatemsg);
// if (true !== $valid_result) {
// // 验证失败 输出错误信息
// return $this->error($valid_result);
// }
$data['id'] = $this->customer_id;
$model = Loader::model('Customer')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function resetpwd() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'password' => 'require|min:6|max:32',
'repassword' => 'require|confirm:password',
];
//验证提示信息
$validatemsg = [
'password.require' => '密码不能为空',
'password.min' => '密码不少于6个字符',
'password.max' => '密码不多于32个字符',
'repassword.require' => '确认密码不能为空',
'repassword.confirm' => '两次密码不相符',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$row = Loader::model('Customer')->getRow(['id' => $this->customer_id]);
if (empty($row)) {
return $this->error('数据有误,请检查后再操作');
}
$data['id'] = $this->customer_id;
$model = Loader::model('Customer')->updatePassword($data);
if ($model && $model->getData('id')) {
return $this->success('修改密码成功');
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function resetemail() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = ['email' => 'email|unique:customer,email',];
//验证提示信息
$validatemsg = [
'email.email' => '邮箱格式错误',
'email.unique' => '邮箱已经被使用',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$row = Loader::model('Customer')->getRow(['id' => $this->customer_id]);
if (empty($row)) {
return $this->error('数据有误,请检查后再操作');
}
$model = Loader::model('Customer')->update(['email' => $data['email'], 'id' => $this->customer_id]);
if ($model && $model->getData('id')) {
return $this->success('修改邮箱成功');
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function resettx() {
if ($this->request->isPost()) {
$data = $this->request->post();
$txarr = range(0, 5);
shuffle($txarr);
$data['picture'] = '/uploads/user/ns' . $txarr[0] . '.jpg';
$data['id'] = $this->customer_id;
$model = Loader::model('Customer')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), null, ['picture' => $data['picture']]);
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

View File

@@ -0,0 +1,142 @@
<?php
namespace app\mobile\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\Session;
class User extends BaseController {
// 初始化
protected function _initialize() {
parent::_initialize();
if ($this->customer_id <= 0) {
abort(redirect(url('/login')));
}
}
public function index() {
$row = Loader::model('Customer')->getRow(['id' => $this->customer_id]);
if (empty($row)) {
return exception('数据有误,请检查后再操作');
}
$value['hangye'] = (array) Config::get('website_hangye');
$value['zhiye'] = (array) Config::get('website_zhiye');
$value['customer'] = $row;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
// //验证规则
// $validaterule = ['birthday' => 'require|date',];
// //验证提示信息
// $validatemsg = ['birthday.date' => '生日不是日期格式',];
// $valid_result = $this->validate($data, $validaterule, $validatemsg);
// if (true !== $valid_result) {
// // 验证失败 输出错误信息
// return $this->error($valid_result);
// }
$data['id'] = $this->customer_id;
$model = Loader::model('Customer')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function resetpwd() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = [
'password' => 'require|min:6|max:32',
'repassword' => 'require|confirm:password',
];
//验证提示信息
$validatemsg = [
'password.require' => '密码不能为空',
'password.min' => '密码不少于6个字符',
'password.max' => '密码不多于32个字符',
'repassword.require' => '确认密码不能为空',
'repassword.confirm' => '两次密码不相符',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$row = Loader::model('Customer')->getRow(['id' => $this->customer_id]);
if (empty($row)) {
return $this->error('数据有误,请检查后再操作');
}
$data['id'] = $this->customer_id;
$model = Loader::model('Customer')->updatePassword($data);
if ($model && $model->getData('id')) {
return $this->success('修改密码成功');
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function resetemail() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
//验证规则
$validaterule = ['email' => 'email|unique:customer,email',];
//验证提示信息
$validatemsg = [
'email.email' => '邮箱格式错误',
'email.unique' => '邮箱已经被使用',
];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$row = Loader::model('Customer')->getRow(['id' => $this->customer_id]);
if (empty($row)) {
return $this->error('数据有误,请检查后再操作');
}
$model = Loader::model('Customer')->update(['email' => $data['email'], 'id' => $this->customer_id]);
if ($model && $model->getData('id')) {
return $this->success('修改邮箱成功');
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function resettx() {
if ($this->request->isPost()) {
$data = $this->request->post();
$txarr = range(0, 5);
shuffle($txarr);
$data['picture'] = '/uploads/user/ns' . $txarr[0] . '.jpg';
$data['id'] = $this->customer_id;
$model = Loader::model('Customer')->updateRow($data);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), null, ['picture' => $data['picture']]);
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}

138
app/mobile/controller/Video.php Executable file
View File

@@ -0,0 +1,138 @@
<?php
namespace app\mobile\controller;
use think\Loader;
use think\Cookie;
use think\Config;
class Video extends BaseController {
public function lists() {
$videoCategory = Loader::model('VideoCategory')->getList(['siteid' => $this->siteid, 'isshow' => 1, 'stat' => 0, 'country_code' => $this->country_code], ['sort', 'id'], ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'm_icon', 'm_bg', 'isshow', 'recommend', 'picture', 'image1', 'image2', 'classtype', 'url']);
unset($videoCategory[7]);
$value = [
'videoCategory' => $videoCategory,
];
$value['seo_title'] = config('video_seo_title')? : config('website_seo_title');
$value['seo_keyword'] = config('video_seo_keyword')? : config('website_seo_keyword');
$value['seo_description'] = config('video_seo_description')? : config('website_seo_description');
$this->assign($value);
return $this->fetch();
}
public function catelists($id = 0) {
$arg_where = ['a.siteid' => $this->siteid, 'a.country_code' => $this->country_code];
$id = intval($id);
if ($id > 0) {
$category = Loader::model('VideoCategory')->getRow($id);
if ($category['haschild']) {
$ids = Loader::model('VideoCategory')->getChildIDArray($id);
$arg_where['cid'] = ['in', $ids];
} else {
$arg_where['cid'] = $id;
}
}
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
unset($category['siteid']);
$value['category'] = $category;
switch ($category['classtype']) {
case 2:
$template = $category['templist'];
$arg_order = ['a.id' => 'desc'];
$arg_field = ['a.id', 'a.cid', 'a.name', 'a.sort', 'a.headline', 'a.ishot', 'a.recommend', 'a.viewcount', 'a.videopath', 'a.videourl', 'a.description', 'a.picture', 'a.createtime', 'c.id' => 'categoryid', 'c.name' => 'categoryname'];
$dataObject = Loader::model('Video')->getCateVideoLists($arg_where, $arg_order, $arg_field, 2);
$value['list'] = $dataObject->isEmpty() ? null : $dataObject->items();
$value['page'] = $dataObject->render();
if ($this->request->isAjax()) {
return $this->result($value, true, '视频列表');
}
$videoCategory = Loader::model('VideoCategory')->getList(['siteid' => $this->siteid, 'stat' => 0, 'isshow' => 1, 'country_code' => $this->country_code], ['sort', 'id'], ['id', 'pid', 'haschild', 'name', 'shortname', 'description', 'sort', 'isshow', 'm_icon', 'm_bg', 'recommend', 'picture', 'image1', 'image2', 'classtype', 'url']);
$value['videoCategory'] = $videoCategory;
break;
case 3:
header('location:' . $category['url']);
exit;
break;
default:
$template = $category['tempindex'];
break;
}
// // 该分类下的热门视频列表
// $hot_video_where = ['c.id' => $id, 'c.stat' => 0, 'ishot' => 1];
// $hot_video_order = ['a.id' => 'desc'];
// $hot_video_field = ['a.*', 'c.name' => 'cname'];
// $hot_video = Loader::model('video')->getCateVideoList($hot_video_where, $hot_video_order, $hot_video_field, 2);
// $value['hot_video'] = $hot_video;
$value['seo_title'] = $category['seo_title']? : config('website_seo_title');
$value['seo_keyword'] = $category['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $category['seo_description']? : config('website_seo_description');
$this->assign($value);
return $this->fetch($template);
}
public function detail($id = 0) {
if ($id > 0) {
$detail = Loader::model('Video')->getRow($id);
if (empty($detail)) {
return exception('数据有误,请检查后再操作');
}
//$addvideo = Loader::model('VideoAddition')->getRowAddition(['aid' => $detail['id']]);
$category = Loader::model('VideoCategory')->getRow($detail['cid']);
if (empty($category)) {
return exception('数据有误,请检查后再操作');
}
//$prev_detail = Loader::model('Video')->getRow(['id' => ['gt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'asc']);
//$next_detail = Loader::model('Video')->getRow(['id' => ['lt', $id], 'cid' => $category['id'], 'stat' => 0], ['id', 'name'], ['id' => 'desc']);
$value = [
'detail' => $detail,
//'addvideo' => $addvideo,
'category' => $category,
//'prev_detail' => $prev_detail,
//'next_detail' => $next_detail,
];
$value['seo_title'] = $detail['seo_title']? : $detail['name'] . '-' . config('website_seo_title');
$value['seo_keyword'] = $detail['seo_keyword']? : config('website_seo_keyword');
$value['seo_description'] = $detail['seo_description']? : config('website_seo_description');
$this->assign($value);
$this->viewcount($id);
return $this->fetch();
} else {
return exception('数据有误,请检查后再操作');
}
}
protected function viewcount($id) {
$view = Cookie::get('videoview', 'history'); //print_r($history);exit;
if (empty($view) || $view != $id) {
Loader::model('Video')->where(['id' => $id])->setInc('viewcount');
Cookie::set('videoview', $id, ['prefix' => 'history', 'expire' => 3600]);
}
}
protected function historyvideo($id) {
$video = Cookie::get('video', 'history'); //print_r($history);exit;
if (isset($video) && !empty($video)) {
$video_ids = explode(',', $video);
if ($video_ids[0] != $id) {
array_unshift($video_ids, $id);
$video_ids = array_unique($video_ids);
$num = Config::get('history_number') > 0 ? Config::get('history_number') : 10;
//$video_ids = array_slice($video_ids, 0, $num);
while (count($video_ids) > $num) {
array_pop($video_ids);
}
Cookie::set('video', implode(',', $video_ids), ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
} else {
Cookie::set('video', $id, ['prefix' => 'history', 'setcookie' => true, 'expire' => 3600 * 24 * 30]);
}
}
}