123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337 |
- <?php
- /**
- * lionfish 商城系统
- *
- *
- * @author fish
- *
- */
- namespace Seller\Controller;
- class SystemController extends CommonController {
-
- protected function _initialize(){
- parent::_initialize();
- }
-
- public function upgrade_check()
- {
-
- //get_config_by_name($name) ret.status
-
- //S('new_system_cloudversion', array('time' => time() ));
-
- $new_system_cloudversion = S('new_system_cloudversion');
-
- if( !empty($new_system_cloudversion) )
- {
- $last_time = $new_system_cloudversion['time'];
-
- $now_time = time() - 60 * 1;
-
- if($last_time < $now_time )
- {
- $data = $this->get_site_version(); // D('Home/Config')->get_config_by_name('site_version');
-
- if( empty($data['result']['version']) )
- {
- $data['status'] = 0;
- }
-
- S('new_system_cloudversion', array('time' => time() ));
- }else{
-
- $data = array('status' => 0, 'last_time' => $last_time, 'now_time' => $now_time );
- }
-
- }else{
-
- $data = $this->get_site_version(); // D('Home/Config')->get_config_by_name('site_version');
-
- if( empty($data['result']['version']) )
- {
- $data['status'] = 0;
- }
-
- S('new_system_cloudversion', array('time' => time() ));
-
- }
-
-
- echo json_encode( $data );
- die();
- }
-
-
- public function auth_upgrade()
- {
-
- $data = $this->get_site_version();
-
- $this->data = $data;
- include $this->display();
- }
-
- public function get_site_version()
- {
- $auth_url ="http://pintuan.liofis.com/upgrade_dan.php";
-
-
- $version_info = M('lionfish_comshop_config')->where( array('name' => 'site_version') )->find();
-
- $version = $version_info['value'];
-
- $cur_release_info = M('lionfish_comshop_config')->where( array('name' => 'site_version') )->find();
-
- $cur_release = $cur_release_info['value'];
-
- $url = D('Home/Front')->get_config_by_name('shop_domain');
- $release = $cur_release;
-
-
- $modname = 'lionfish_comshop';
- $domain = trim(preg_replace('/http(s)?:\\/\\//', '', rtrim($url, '/')));
- $ip = gethostbyname($_SERVER['HTTP_HOST']);
-
-
-
- $resp = http_request($auth_url, array('action' => 'check_version','ip' => $ip,'release' => $release,'version' => $version, 'domain' => $domain) );
-
- $data = @json_decode($resp, true);
-
-
- $data['cur_version'] = $version;
- $data['cur_release'] = $cur_release;
-
- return $data;
- }
-
- public function opupdate()
- {
-
- $upgrade = $this->update_site_version();
-
-
-
- S('cloud:shiziyushop:upgradev2', array('files' => $upgrade['result'], 'version' => $upgrade['result']['version'], 'release' => $upgrade['result']['release']));
-
-
- $filecount = count($upgrade['result']['admin_file_list'])+count($upgrade['result']['weprogram_file_list']);
-
- //show_json(1, array('result' => 1, 'version' => $upgrade['version'], 'release' => $upgrade['release'], 'filecount' => count($files), 'database' => !empty($database), 'upgrades' => !empty($upgrade['upgrades']), 'log' => $log, 'templatefiles' => $templatefiles));
-
- $this->filecount = $filecount;
- $this->upgrade = $upgrade;
-
- include $this->display();
- }
-
-
- private function update_site_version()
- {
-
- $auth_url ="http://pintuan.liofis.com/upgrade_dan.php";
-
-
- $url = D('Home/Front')->get_config_by_name('shop_domain');
-
- $version_info = M('lionfish_comshop_config')->where( array('name' => 'site_version') )->find();
- $release_info = M('lionfish_comshop_config')->where( array('name' => 'cur_release') )->find();
-
- $version = $version_info['value'];
- $release = $release_info['value'];
-
- $modname = 'lionfish_comshop';
-
- $domain = trim(preg_replace('/http(s)?:\\/\\//', '', rtrim($url, '/')));
- $ip = gethostbyname($_SERVER['HTTP_HOST']);
-
- $resp = http_request($auth_url, array('action' => 'get_version_file','ip' => $ip,'release' => $release,'version' => $version, 'domain' => $domain) );
- $data = @json_decode(gzuncompress($resp), true);
-
- $data['cur_version'] = $version;
- $data['cur_release'] = D('Home/Front')->get_config_by_name('cur_release');
-
-
-
-
-
-
- return $data;
- }
-
- private function get_upgrade_file($file)
- {
- $auth_url ="http://pintuan.liofis.com/upgrade_dan.php";
-
- //M('lionfish_comshop_config')->where( array('name' => 'site_version') )->save( array('value' => $version) );
-
- $version_info = M('lionfish_comshop_config')->where( array('name' => 'site_version') )->find();
- $release_info = M('lionfish_comshop_config')->where( array('name' => 'cur_release') )->find();
-
- $version = $version_info['value'];
- $release = $release_info['value'];
- //$version = D('Home/Front')->get_config_by_name('site_version');
- //$release = D('Home/Front')->get_config_by_name('cur_release');
-
- $url = D('Home/Front')->get_config_by_name('shop_domain');
-
- $modname = 'lionfish_comshop';
- $domain = trim(preg_replace('/http(s)?:\\/\\//', '', rtrim($url, '/')));
- $ip = gethostbyname($_SERVER['HTTP_HOST']);
-
- $resp = http_request($auth_url, array('action' => 'down_version_file','file' => $file,'ip' => $ip,'release' => $release,'version' => $version, 'domain' => $domain) );
-
- $data = @json_decode(gzuncompress($resp), true);
-
- $data['cur_version'] = $version;
- $data['cur_release'] = $release;
-
- return $data;
- }
-
-
- public function do_update()
- {
-
-
- $upgrade = S('cloud:shiziyushop:upgradev2');
- $files = $upgrade['files'];
- $version = $upgrade['version'];
- $release = $upgrade['release'];
-
-
-
- $filecount = count($files['admin_file_list'])+count($files['weprogram_file_list']);
-
-
-
- if( !empty($files['admin_file_list']) )
- {
- $file = array_shift($files['admin_file_list']);
- $filecount = $filecount -1;
-
- $file_data = $this->get_upgrade_file($file);
-
-
-
- //snailsh_shop
- $file = str_replace('snailsh_shop/','', $file);
- $dirpath = dirname($file);
-
- //SNAILFISH_PATH
- if (!is_dir(ROOT_PATH . $dirpath)) {
- RecursiveMkdir(ROOT_PATH . $dirpath);
- @chmod(ROOT_PATH . $dirpath, 511);
- }
-
- $base_file_content = $file_data['result']['base_file_content'];
-
- $content = base64_decode($base_file_content);
-
-
- $f = @file_put_contents(ROOT_PATH . $file, $content);
-
- if( $f )
- {
- S('cloud:shiziyushop:upgradev2', array('files' => $files, 'version' => $upgrade['version'],'release' => $upgrade['release']));
-
- echo json_encode( array('code' => 0,'msg' => '更新'.$file.'文件成功,还剩'.$filecount.'个文件') );
- die();
- }else{
-
-
- echo json_encode( array('code' => 1,'msg' => $dirpath.' 目录不可写') );
- die();
- }
-
- }else if( !empty($files['weprogram_file_list']) )
- {
- $file = array_shift($files['weprogram_file_list']);
- $filecount = $filecount -1;
-
- $file_data = $this->get_upgrade_file($file);
-
- //snailsh_shop
-
- $dirpath = dirname($file);
-
-
- //SNAILFISH_PATH
- if (!is_dir(ROOT_PATH .'Data/'.$version.'/'. $dirpath)) {
-
-
- RecursiveMkdir(ROOT_PATH .'Data/'.$version.'/'. $dirpath);
- @chmod(ROOT_PATH .'Data/'.$version.'/'. $dirpath, 511);
- }
-
- $base_file_content = $file_data['result']['base_file_content'];
-
- $content = base64_decode($base_file_content);
-
- $f = @file_put_contents(ROOT_PATH .'Data/'.$version.'/'. $file, $content);
- if( $f )
- {
- S('cloud:shiziyushop:upgradev2', array('files' => $files, 'version' => $upgrade['version'],'release' => $upgrade['release']));
- echo json_encode( array('code' => 0,'msg' => '更新'.$file.'文件成功,还剩'.$filecount.'个文件') );
- die();
- }else{
-
- echo json_encode( array('code' => 1,'msg' => 'Data/'.$version.' 目录不可写') );
- die();
- }
-
- }else if( !empty($files['sql_file']) )
- {
- $file = $files['sql_file'];
- $files['sql_file'] = '';
-
- $filecount = $filecount -1;
-
- $file_data = $this->get_upgrade_file($file);
-
- $dirpath = dirname($file);
-
- if (!is_dir(ROOT_PATH .'Data/'.$version.'/'. $dirpath)) {
- RecursiveMkdir(ROOT_PATH .'Data/'.$version.'/'. $dirpath);
-
- @chmod(ROOT_PATH .'Data/'.$version.'/'. $dirpath, 511);
- }
-
- $base_file_content = $file_data['result']['base_file_content'];
-
- $content = base64_decode($base_file_content);
-
-
- $f = @file_put_contents(ROOT_PATH .'Data/'.$version.'/'. $file, $content);
-
- if( $f )
- {
- include ROOT_PATH .'Data/'.$version.'/'. $file;
- M()->execute($sql_content);
- S('cloud:shiziyushop:upgradev2', array('files' => $files, 'version' => $upgrade['version'],'release' => $upgrade['release']));
- @unlink(ROOT_PATH .'Data/'.$version.'/'. $file);
- echo json_encode( array('code' => 0,'msg' => '更新sql文件成功,更新完成') );
- die();
- }else{
- echo json_encode( array('code' => 1,'msg' => 'Data/'.$version.' 目录不可写') );
- die();
- }
-
- }else{
- if( !empty($version) && !empty($release) )
- {
- M('lionfish_comshop_config')->where( array('name' => 'cur_release') )->save( array('value' => $release) );
- M('lionfish_comshop_config')->where( array('name' => 'site_version') )->save( array('value' => $version) );
-
- $c= D('Seller/Config')->get_all_config(true);
- }
-
- echo json_encode( array('code' => 2,'msg' => '更新完成') );
- die();
- }
- }
-
-
- }
|