123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- <?php
- namespace app\store\controller\enterprise;
- use app\store\controller\Controller;
- use app\store\model\enterprise\EnterpriseNews;
- use app\store\model\enterprise\EnterpriseSite;
- use app\store\model\Goods as GoodsModel;
- use think\facade\View;
- class BrandHonor extends Controller
- {
- private $brandModel;
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- $this->brandModel = new EnterpriseSite();
- }
- /**
- * 获取独立配置
- * @return array
- */
- public function setting(){
- $form = $this->postForm('form');
- if ($this->brandModel->addOne($form)){
- return $this->renderSuccess();
- }
- return $this->renderError('系统繁忙');
- }
- /**
- * 其他配置批量设置
- * @return array
- */
- public function settingBatch(){
- $form = $this->postForm('form');
- if ($this->brandModel->addBatch($form)){
- return $this->renderSuccess();
- }
- return $this->renderError('系统繁忙');
- }
- /**
- * 获取单个配置
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function gettting(){
- $ctype = $this->request->get('ctype',1);
- $model = new EnterpriseSite();
- $list = $model->getSetting($ctype);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 其他配置批量获取
- * @return array
- */
- public function getttingBatch(){
- $model = new EnterpriseSite();
- $list = $model->getSettingBacth();
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 获取目录下的所有文件路径
- * @param $path
- * @return array
- */
- private function getDir($path)
- {
- //判断目录是否为空
- if(!file_exists($path)) {
- return [];
- }
- $files = scandir($path);
- $fileItem = [];
- foreach($files as $v) {
- $newPath = $path .DIRECTORY_SEPARATOR . $v;
- if(is_dir($newPath) && $v != '.' && $v != '..') {
- $fileItem = array_merge($fileItem, $this->getDir($newPath));
- }else if(is_file($newPath)){
- $fileItem[] = $newPath;
- }
- }
- return $fileItem;
- }
- /**
- * 获取当前目录下的所有子目录
- * @param $path
- * @return array
- */
- private function getDirPathes($path)
- {
- //判断目录是否为空
- if(!file_exists($path)) {
- return [];
- }
- $files = scandir($path);
- $dirItem = [];
- foreach($files as $v) {
- $newPath = $path .DIRECTORY_SEPARATOR . $v;
- if(is_dir($newPath) && $v != '.' && $v != '..') {
- array_push($dirItem,$newPath);
- }
- }
- return $dirItem;
- }
- /**
- * 递归删除目录
- * @param $dir
- * @return bool
- */
- private function deleteDirFile($dir)
- {
- $flag = false; //默认没删除成功runtime目录
- //判断是不是文件夹
- if (is_dir($dir)) {
- // 打开目录流 成功返回一个资源类型 目录句柄 否则false
- if ($handle = opendir($dir)) {
- while (($file = readdir($handle)) !== false) {
- // 在php中删除一个文件夹的前提是该文件夹为空
- if ($file != '.' && $file != '..') {
- if (is_dir($dir . DIRECTORY_SEPARATOR . $file)) {
- // 子内容是目录
- $this->deleteDirFile($dir . DIRECTORY_SEPARATOR . $file);
- } else {
- // 子内容是文件
- unlink($dir . DIRECTORY_SEPARATOR . $file);
- }
- }
- }
- closedir($handle);
- $flag = true;
- if (rmdir($dir)) {
- $flag = true;
- }
- }
- } else {
- $flag = true;
- }
- return $flag;
- }
- /**
- * 删除目录下的文件
- * @param $dir
- * @return bool
- */
- private function deleteOneDirFile($dir)
- {
- $flag = false; //默认没删除成功runtime目录
- //判断是不是文件夹
- if (is_dir($dir)) {
- // 打开目录流 成功返回一个资源类型 目录句柄 否则false
- if ($handle = opendir($dir)) {
- while (($file = readdir($handle)) !== false) {
- // 在php中删除一个文件夹的前提是该文件夹为空
- if (is_file($dir . DIRECTORY_SEPARATOR . $file) && $file != '.' && $file != '..' && $file != '.gitignore' && $file != 'header.html' && $file != 'footer.html') {
- if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
- // 子内容是文件
- unlink($dir . DIRECTORY_SEPARATOR . $file);
- }
- }
- }
- closedir($handle);
- $flag = true;
- }
- } else {
- $flag = true;
- }
- return $flag;
- }
- /**
- * 一键生成官网纯静态页面
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function genAllPureHtml(){
- //清空将要操作的目录
- /* $clearAssetsDir = public_path('ysc_official/assets');
- $flag0 = $this->deleteDirFile($clearAssetsDir);
- if ($flag0 == false){
- return $this->renderError('系统繁忙');
- }*/
- //清空将要操作的目录
- $clearOldDir = public_path('ysc_official');
- $flag = $this->deleteOneDirFile($clearOldDir);
- if ($flag == false){
- return $this->renderError('系统繁忙');
- }
- //创建需要的目录
- /* $newsDir = $clearOldDir.'assets/enterprise';
- if (!is_dir($newsDir)){
- mkdir($newsDir,0755,true);
- }
- //迁移等级目录和文件主要是静态文件
- $path = public_path('assets')."enterprise";
- $fileItems = $this->getDir($path);
- $dirItems = $this->getDirPathes($path);
- $search = public_path();
- $replace = public_path('ysc_official');
- foreach ($dirItems as $dir){
- $newsDir = str_replace($search,$replace,$dir);
- if (!is_dir($newsDir)){
- mkdir($newsDir,0755,true);
- }
- }
- foreach ($fileItems as $item){
- $newFile = str_replace($search,$replace,$item);
- copy($item,$newFile);
- }*/
- $replace = public_path('ysc_official');
- $model = new EnterpriseSite();
- //$ysc_official_path = public_path('ysc_official');
- //首页 todo
- $newsModel = new EnterpriseNews();
- $indexSeo = $model->getSetting(3);
- $newsTop = $newsModel->getItems(1);
- foreach ($newsTop as &$news){
- $news['contents'] = addslashes($news['contents']);//富文本里面的url带有双引号,需转义
- }
- $html = View::fetch('index', [
- 'news' => "'".json_encode($newsTop,JSON_UNESCAPED_UNICODE)."'"
- ,'title'=>$indexSeo['title']
- ,'keywords'=>$indexSeo['keywords']
- ,'desc'=>$indexSeo['desc']
- ]);
- ob_start();
- $path = $replace.'index.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //品牌荣誉
- $honor = $model->getSetting(1);
- $html = View::fetch('brand', ['honors' => "'".$honor['contents']."'"]);
- ob_start();
- $path = $replace.'brand.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //新闻动态页
- $newsAll = $newsModel->getItems();
- foreach ($newsAll as &$news){
- $news['contents'] = addslashes($news['contents']);//富文本里面的url带有双引号,需转义
- }
- $html = View::fetch('notice', ['news' => "'".json_encode($newsAll)."'"]);
- ob_start();
- $path = $replace.'notice.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //新闻详情页 todo
- foreach ($newsAll as $i=>$item){
- $html = View::fetch('noticeDetail', ['title' =>'"'.$item['title'].'"','time'=>'"'.$item['create_time'].'"',
- 'source'=>'"'.$item['sources'].'"','author'=>'"'.$item['author'].'"','contents'=>'"'.$item['contents'].'"']);
- ob_start();
- $path = $replace.'noticeDetail'.$i .'.html';
- if (file_exists($path)){
- unlink($path);
- }
- file_put_contents($path,$html);
- ob_end_clean();
- }
- //产品介绍
- $goodsModel = new GoodsModel;
- $allGoods = $goodsModel->getListNoPage();
- $goods = [];
- $productSeo = $model->getSetting(4);
- foreach ($allGoods as $good){
- $temp['imgUrl'] = $good['images'][0]['file']['preview_url'];
- $temp['price'] = $good['goods_price_min'];
- $temp['title'] = $good['goods_name'];
- $goods[] = $temp;
- }
- $html = View::fetch('goods', ['goods' => "'".json_encode($goods,JSON_UNESCAPED_UNICODE)."'"
- ,'title'=>$productSeo['title']
- ,'keywords'=>$productSeo['keywords']
- ,'desc'=>$productSeo['desc']
- ]);
- ob_start();
- $path = $replace.'goods.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //招商加盟
- $honor = $model->getSetting(2);
- $html = View::fetch('bussiness', ['coopers' => "'".$honor['contents']."'"]);
- ob_start();
- $path = $replace.'bussiness.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //联系我们
- $honor = $model->getSetting(5);
- $html = View::fetch('contact', ['coopers' => "'".$honor['contents']."'"
- ,'title'=>$honor['title']
- ,'keywords'=>$honor['keywords']
- ,'desc'=>$honor['desc']
- ]);
- ob_start();
- $path = $replace.'contact.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //指定文件用户
- @chgrp($replace,'web');
- @chown($replace,'web'); // specify user by name
- //生成h5静态页面
- $this->genAllPureH5();
- return $this->renderSuccess();
- }
- /**
- * 一键生成官网纯静态页面
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- private function genAllPureH5(){
- /* //清空将要操作的目录
- $clearAssetsDir = public_path('h5/assets');
- $flag0 = $this->deleteDirFile($clearAssetsDir);
- if ($flag0 == false){
- return $this->renderError('系统繁忙');
- }*/
- //清空将要操作的目录
- $clearOldDir = public_path('h5');
- $flag = $this->deleteOneDirFile($clearOldDir);
- if ($flag == false){
- return $this->renderError('系统繁忙');
- }
- //创建需要的目录
- /* $newsDir = $clearOldDir.'assets/h5';
- if (!is_dir($newsDir)){
- mkdir($newsDir,0755,true);
- }*/
- //迁移等级目录和文件主要是静态文件
- /* $path = public_path('assets')."h5";
- $fileItems = $this->getDir($path);
- $dirItems = $this->getDirPathes($path);
- $search = public_path();
- $replace = public_path('h5');
- foreach ($dirItems as $dir){
- $newsDir = str_replace($search,$replace,$dir);
- if (!is_dir($newsDir)){
- mkdir($newsDir,0755,true);
- }
- }
- foreach ($fileItems as $item){
- $newFile = str_replace($search,$replace,$item);
- copy($item,$newFile);
- }*/
- $replace = public_path('h5');
- $model = new EnterpriseSite();
- //$ysc_official_path = public_path('ysc_official');
- //首页 todo
- $newsModel = new EnterpriseNews();
- $indexSeo = $model->getSetting(3);
- $newsTop = $newsModel->getItems(1);
- foreach ($newsTop as &$news){
- $news['contents'] = addslashes($news['contents']);//富文本里面的url带有双引号,需转义
- }
- $html = View::fetch('indexh5', [
- 'news' => "'".json_encode($newsTop,JSON_UNESCAPED_UNICODE)."'"
- ,'title'=>$indexSeo['title']
- ,'keywords'=>$indexSeo['keywords']
- ,'desc'=>$indexSeo['desc']
- ]);
- ob_start();
- $path = $replace.'index.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //品牌荣誉
- $honor = $model->getSetting(1);
- $html = View::fetch('brandh5', ['honors' => "'".$honor['contents']."'"]);
- ob_start();
- $path = $replace.'brand.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //新闻动态页
- $newsAll = $newsModel->getItems();
- foreach ($newsAll as &$news){
- $news['contents'] = addslashes($news['contents']);//富文本里面的url带有双引号,需转义
- }
- $html = View::fetch('noticeh5', ['news' => "'".json_encode($newsAll)."'"]);
- ob_start();
- $path = $replace.'notice.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //新闻详情页 todo
- foreach ($newsAll as $i=>$item){
- $html = View::fetch('noticeDetailh5', ['title' =>'"'.$item['title'].'"','time'=>'"'.$item['create_time'].'"',
- 'source'=>'"'.$item['sources'].'"','author'=>'"'.$item['author'].'"','contents'=>'"'.$item['contents'].'"']);
- ob_start();
- $path = $replace.'noticeDetail'.$i .'.html';
- if (file_exists($path)){
- unlink($path);
- }
- file_put_contents($path,$html);
- ob_end_clean();
- }
- //产品介绍
- $goodsModel = new GoodsModel;
- $allGoods = $goodsModel->getListNoPage();
- $goods = [];
- $productSeo = $model->getSetting(4);
- foreach ($allGoods as $good){
- $temp['imgUrl'] = $good['images'][0]['file']['preview_url'];
- $temp['price'] = $good['goods_price_min'];
- $temp['title'] = $good['goods_name'];
- $goods[] = $temp;
- }
- $html = View::fetch('goodsh5', ['goods' => "'".json_encode($goods,JSON_UNESCAPED_UNICODE)."'"
- ,'title'=>$productSeo['title']
- ,'keywords'=>$productSeo['keywords']
- ,'desc'=>$productSeo['desc']
- ]);
- ob_start();
- $path = $replace.'goods.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //招商加盟
- $honor = $model->getSetting(2);
- $html = View::fetch('bussinessh5', ['coopers' => "'".$honor['contents']."'"]);
- ob_start();
- $path = $replace.'bussiness.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //联系我们
- $honor = $model->getSetting(5);
- $html = View::fetch('contacth5', ['coopers' => "'".$honor['contents']."'"
- ,'title'=>$honor['title']
- ,'keywords'=>$honor['keywords']
- ,'desc'=>$honor['desc']
- ]);
- ob_start();
- $path = $replace.'contact.html';
- file_put_contents($path,$html);
- ob_end_clean();
- //指定文件用户
- @chgrp($replace,'web');
- @chown($replace,'web'); // specify user by name
- return true;
- //return $this->renderSuccess();
- }
- }
|