SystemController.class.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class SystemController extends CommonController {
  11. protected function _initialize(){
  12. parent::_initialize();
  13. }
  14. public function upgrade_check()
  15. {
  16. //get_config_by_name($name) ret.status
  17. //S('new_system_cloudversion', array('time' => time() ));
  18. $new_system_cloudversion = S('new_system_cloudversion');
  19. if( !empty($new_system_cloudversion) )
  20. {
  21. $last_time = $new_system_cloudversion['time'];
  22. $now_time = time() - 60 * 1;
  23. if($last_time < $now_time )
  24. {
  25. $data = $this->get_site_version(); // D('Home/Config')->get_config_by_name('site_version');
  26. if( empty($data['result']['version']) )
  27. {
  28. $data['status'] = 0;
  29. }
  30. S('new_system_cloudversion', array('time' => time() ));
  31. }else{
  32. $data = array('status' => 0, 'last_time' => $last_time, 'now_time' => $now_time );
  33. }
  34. }else{
  35. $data = $this->get_site_version(); // D('Home/Config')->get_config_by_name('site_version');
  36. if( empty($data['result']['version']) )
  37. {
  38. $data['status'] = 0;
  39. }
  40. S('new_system_cloudversion', array('time' => time() ));
  41. }
  42. echo json_encode( $data );
  43. die();
  44. }
  45. public function auth_upgrade()
  46. {
  47. $data = $this->get_site_version();
  48. $this->data = $data;
  49. include $this->display();
  50. }
  51. public function get_site_version()
  52. {
  53. $auth_url ="http://pintuan.liofis.com/upgrade_dan.php";
  54. $version_info = M('lionfish_comshop_config')->where( array('name' => 'site_version') )->find();
  55. $version = $version_info['value'];
  56. $cur_release_info = M('lionfish_comshop_config')->where( array('name' => 'site_version') )->find();
  57. $cur_release = $cur_release_info['value'];
  58. $url = D('Home/Front')->get_config_by_name('shop_domain');
  59. $release = $cur_release;
  60. $modname = 'lionfish_comshop';
  61. $domain = trim(preg_replace('/http(s)?:\\/\\//', '', rtrim($url, '/')));
  62. $ip = gethostbyname($_SERVER['HTTP_HOST']);
  63. $resp = http_request($auth_url, array('action' => 'check_version','ip' => $ip,'release' => $release,'version' => $version, 'domain' => $domain) );
  64. $data = @json_decode($resp, true);
  65. $data['cur_version'] = $version;
  66. $data['cur_release'] = $cur_release;
  67. return $data;
  68. }
  69. public function opupdate()
  70. {
  71. $upgrade = $this->update_site_version();
  72. S('cloud:shiziyushop:upgradev2', array('files' => $upgrade['result'], 'version' => $upgrade['result']['version'], 'release' => $upgrade['result']['release']));
  73. $filecount = count($upgrade['result']['admin_file_list'])+count($upgrade['result']['weprogram_file_list']);
  74. //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));
  75. $this->filecount = $filecount;
  76. $this->upgrade = $upgrade;
  77. include $this->display();
  78. }
  79. private function update_site_version()
  80. {
  81. $auth_url ="http://pintuan.liofis.com/upgrade_dan.php";
  82. $url = D('Home/Front')->get_config_by_name('shop_domain');
  83. $version_info = M('lionfish_comshop_config')->where( array('name' => 'site_version') )->find();
  84. $release_info = M('lionfish_comshop_config')->where( array('name' => 'cur_release') )->find();
  85. $version = $version_info['value'];
  86. $release = $release_info['value'];
  87. $modname = 'lionfish_comshop';
  88. $domain = trim(preg_replace('/http(s)?:\\/\\//', '', rtrim($url, '/')));
  89. $ip = gethostbyname($_SERVER['HTTP_HOST']);
  90. $resp = http_request($auth_url, array('action' => 'get_version_file','ip' => $ip,'release' => $release,'version' => $version, 'domain' => $domain) );
  91. $data = @json_decode(gzuncompress($resp), true);
  92. $data['cur_version'] = $version;
  93. $data['cur_release'] = D('Home/Front')->get_config_by_name('cur_release');
  94. return $data;
  95. }
  96. private function get_upgrade_file($file)
  97. {
  98. $auth_url ="http://pintuan.liofis.com/upgrade_dan.php";
  99. //M('lionfish_comshop_config')->where( array('name' => 'site_version') )->save( array('value' => $version) );
  100. $version_info = M('lionfish_comshop_config')->where( array('name' => 'site_version') )->find();
  101. $release_info = M('lionfish_comshop_config')->where( array('name' => 'cur_release') )->find();
  102. $version = $version_info['value'];
  103. $release = $release_info['value'];
  104. //$version = D('Home/Front')->get_config_by_name('site_version');
  105. //$release = D('Home/Front')->get_config_by_name('cur_release');
  106. $url = D('Home/Front')->get_config_by_name('shop_domain');
  107. $modname = 'lionfish_comshop';
  108. $domain = trim(preg_replace('/http(s)?:\\/\\//', '', rtrim($url, '/')));
  109. $ip = gethostbyname($_SERVER['HTTP_HOST']);
  110. $resp = http_request($auth_url, array('action' => 'down_version_file','file' => $file,'ip' => $ip,'release' => $release,'version' => $version, 'domain' => $domain) );
  111. $data = @json_decode(gzuncompress($resp), true);
  112. $data['cur_version'] = $version;
  113. $data['cur_release'] = $release;
  114. return $data;
  115. }
  116. public function do_update()
  117. {
  118. $upgrade = S('cloud:shiziyushop:upgradev2');
  119. $files = $upgrade['files'];
  120. $version = $upgrade['version'];
  121. $release = $upgrade['release'];
  122. $filecount = count($files['admin_file_list'])+count($files['weprogram_file_list']);
  123. if( !empty($files['admin_file_list']) )
  124. {
  125. $file = array_shift($files['admin_file_list']);
  126. $filecount = $filecount -1;
  127. $file_data = $this->get_upgrade_file($file);
  128. //snailsh_shop
  129. $file = str_replace('snailsh_shop/','', $file);
  130. $dirpath = dirname($file);
  131. //SNAILFISH_PATH
  132. if (!is_dir(ROOT_PATH . $dirpath)) {
  133. RecursiveMkdir(ROOT_PATH . $dirpath);
  134. @chmod(ROOT_PATH . $dirpath, 511);
  135. }
  136. $base_file_content = $file_data['result']['base_file_content'];
  137. $content = base64_decode($base_file_content);
  138. $f = @file_put_contents(ROOT_PATH . $file, $content);
  139. if( $f )
  140. {
  141. S('cloud:shiziyushop:upgradev2', array('files' => $files, 'version' => $upgrade['version'],'release' => $upgrade['release']));
  142. echo json_encode( array('code' => 0,'msg' => '更新'.$file.'文件成功,还剩'.$filecount.'个文件') );
  143. die();
  144. }else{
  145. echo json_encode( array('code' => 1,'msg' => $dirpath.' 目录不可写') );
  146. die();
  147. }
  148. }else if( !empty($files['weprogram_file_list']) )
  149. {
  150. $file = array_shift($files['weprogram_file_list']);
  151. $filecount = $filecount -1;
  152. $file_data = $this->get_upgrade_file($file);
  153. //snailsh_shop
  154. $dirpath = dirname($file);
  155. //SNAILFISH_PATH
  156. if (!is_dir(ROOT_PATH .'Data/'.$version.'/'. $dirpath)) {
  157. RecursiveMkdir(ROOT_PATH .'Data/'.$version.'/'. $dirpath);
  158. @chmod(ROOT_PATH .'Data/'.$version.'/'. $dirpath, 511);
  159. }
  160. $base_file_content = $file_data['result']['base_file_content'];
  161. $content = base64_decode($base_file_content);
  162. $f = @file_put_contents(ROOT_PATH .'Data/'.$version.'/'. $file, $content);
  163. if( $f )
  164. {
  165. S('cloud:shiziyushop:upgradev2', array('files' => $files, 'version' => $upgrade['version'],'release' => $upgrade['release']));
  166. echo json_encode( array('code' => 0,'msg' => '更新'.$file.'文件成功,还剩'.$filecount.'个文件') );
  167. die();
  168. }else{
  169. echo json_encode( array('code' => 1,'msg' => 'Data/'.$version.' 目录不可写') );
  170. die();
  171. }
  172. }else if( !empty($files['sql_file']) )
  173. {
  174. $file = $files['sql_file'];
  175. $files['sql_file'] = '';
  176. $filecount = $filecount -1;
  177. $file_data = $this->get_upgrade_file($file);
  178. $dirpath = dirname($file);
  179. if (!is_dir(ROOT_PATH .'Data/'.$version.'/'. $dirpath)) {
  180. RecursiveMkdir(ROOT_PATH .'Data/'.$version.'/'. $dirpath);
  181. @chmod(ROOT_PATH .'Data/'.$version.'/'. $dirpath, 511);
  182. }
  183. $base_file_content = $file_data['result']['base_file_content'];
  184. $content = base64_decode($base_file_content);
  185. $f = @file_put_contents(ROOT_PATH .'Data/'.$version.'/'. $file, $content);
  186. if( $f )
  187. {
  188. include ROOT_PATH .'Data/'.$version.'/'. $file;
  189. M()->execute($sql_content);
  190. S('cloud:shiziyushop:upgradev2', array('files' => $files, 'version' => $upgrade['version'],'release' => $upgrade['release']));
  191. @unlink(ROOT_PATH .'Data/'.$version.'/'. $file);
  192. echo json_encode( array('code' => 0,'msg' => '更新sql文件成功,更新完成') );
  193. die();
  194. }else{
  195. echo json_encode( array('code' => 1,'msg' => 'Data/'.$version.' 目录不可写') );
  196. die();
  197. }
  198. }else{
  199. if( !empty($version) && !empty($release) )
  200. {
  201. M('lionfish_comshop_config')->where( array('name' => 'cur_release') )->save( array('value' => $release) );
  202. M('lionfish_comshop_config')->where( array('name' => 'site_version') )->save( array('value' => $version) );
  203. $c= D('Seller/Config')->get_all_config(true);
  204. }
  205. echo json_encode( array('code' => 2,'msg' => '更新完成') );
  206. die();
  207. }
  208. }
  209. }