| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com
- * =========================================================
- */
- namespace app\model\system;
- use app\model\BaseModel;
- use extend\api\HttpClient;
- use think\facade\Cache;
- use think\facade\Db;
- class Upgrade extends BaseModel
- {
- private $url;
- private $cert = '';
- public function __construct($code = '')
- {
- $this->cert = defined('NIUSHOP_AUTH_CODE') ? NIUSHOP_AUTH_CODE : '';
- $this->url = 'https://api.niushop.com';
- }
- /**
- * post 服务器请求
- */
- private function doPost($post_url, $post_data)
- {
- $post_data[ 'code' ] = $this->cert;
- $httpClient = new HttpClient();
- $res = $httpClient->post($this->url . $post_url . "?url=" . "http://hlnweb.cn", $post_data);
- return $res;
- }
- /**
- * 在线下载文件
- * @param $param
- */
- public function test()
- {
- $result = $this->doPost('/upgrade/upgrade/test', []);//授权
- return $result;
- }
- /**
- * 获取可升级的版本信息
- */
- public function getSystemUpgradeInfo()
- {
- $app_info = config('info');
- $addon_array = array_map('basename', glob('addon/*', GLOB_ONLYDIR));
- $plugin_info = [];
- foreach ($addon_array as $addon) {
- $addon_info_path = "addon/{$addon}/config/info.php";
- if (file_exists($addon_info_path)) {
- $info = include_once $addon_info_path;
- $plugin_info[] = [
- 'code' => $info[ 'name' ],
- // 'version_no' => "520221109001",
- // 'version_name' => "5.1.0",
- 'version_no' => $info[ 'version_no' ],
- 'version_name' => $info[ 'version' ],
- ];
- }
- }
- $post_data = [
- 'app_info' => [
- 'code' => $app_info[ 'name' ],
- 'version_no' => $app_info[ 'version_no' ],
- 'version_name' => $app_info[ 'version' ],
- ],
- 'plugin_info' => $plugin_info
- ];
- $res = $this->doPost('/upgrade/upgrade/updateinfo', $post_data);
- $res = json_decode($res, true);
- //处理返回数据
- if (!empty($res) && $res[ 'code' ] == 0) {
- //整合系统和插件数据
- $app_data = $res[ 'data' ][ 'app_data' ];
- $client_data = $res[ 'data' ][ 'client_data' ];
- $plugin_data = $res[ 'data' ][ 'plugin_data' ];
- $install_data = $res[ 'data' ][ 'install_data' ];
- $data = [];
- if ($app_data[ 'code' ] == 0) {
- $app_data[ 'data' ][ 'action' ] = 'upgrade';
- $app_data[ 'data' ][ 'action_name' ] = '升级';
- $app_data[ 'data' ][ 'type' ] = 'system';
- $app_data[ 'data' ][ 'type_name' ] = '系统';
- $data[] = $app_data[ 'data' ];
- }
- foreach ($client_data as $key => $val) {
- if ($val[ 'code' ] == 0) {
- $val[ 'data' ][ 'action' ] = 'download';
- $val[ 'data' ][ 'action_name' ] = '下载';
- $val[ 'data' ][ 'type' ] = 'client';
- $val[ 'data' ][ 'type_name' ] = '客户端';
- $data[] = $val[ 'data' ];
- }
- }
- foreach ($plugin_data as $key => $val) {
- if ($val[ 'code' ] == 0) {
- $val[ 'data' ][ 'action' ] = 'upgrade';
- $val[ 'data' ][ 'action_name' ] = '升级';
- $val[ 'data' ][ 'type' ] = 'addon';
- $val[ 'data' ][ 'type_name' ] = '插件';
- $data[] = $val[ 'data' ];
- }
- }
- foreach ($install_data as $key => $val) {
- if ($val[ 'code' ] == 0) {
- $val[ 'data' ][ 'action' ] = 'install';
- $val[ 'data' ][ 'action_name' ] = '安装';
- $val[ 'data' ][ 'type' ] = 'addon';
- $val[ 'data' ][ 'type_name' ] = '插件';
- $data[] = $val[ 'data' ];
- }
- }
- //处理更新说明的换行
- foreach ($data as $key => $val) {
- foreach ($val[ 'scripts' ] as $k => $v) {
- $val[ 'scripts' ][ $k ][ 'description' ] = str_replace("\n", '<br/>', $v[ 'description' ]);
- }
- $data[ $key ] = $val;
- }
- $res[ 'data' ] = $data;
- }
- return $res;
- }
- /**
- * 在线下载文件
- * @param $param
- */
- public function download($param)
- {
- $data = array (
- "file_token" => $param[ "token" ]
- );
- $result = $this->doPost('/upgrade/upgrade/download', $data);//授权
- if (empty($result)) {
- return $this->error();
- }
- $result = json_decode($result, true);
- return $result;
- }
- /**
- * 获取授权信息
- * @return bool|mixed|string
- */
- public function authInfo()
- {
- $app_info = config('info');
- $data = array (
- "product_key" => $app_info[ 'name' ],
- );
- //$re = $this->doPost('/upgrade/auth/info', $data);
- $re = '{"code":0,"message":"操作成功","data":{"product_name":"单商户V5","auth_type":0,"devolution_code":"OTJiY2NDNhZmYMzIxN2Q1ZThhZDk=","product_key":"B2C_V4","devolution_url":"baidu.cn","devolution_version_name":"单商户V5多门店版","account_num":0,"devolution_type":"公司","devolution_attribution":"南京有限公司","devolution_name":"张三","devolution_phone":"18100330067","devolution_date":1650333854,"devolution_expire_date":1681869854,"newest_version":"5.2.0"},"timestamp":1665930286}';
- $re = json_decode($re, true);
- $re['data']['devolution_url']=$_SERVER['HTTP_HOST'];
- $re['data']['devolution_expire_date']=4085435181;
- $re['data']['devolution_attribution']="致壹科技";
- return $re;
- }
- /**
- * 获取所有插件
- * @return array|mixed
- */
- public function getAuthPlugin()
- {
- $result = $this->doPost('/upgrade/auth/plugin', []);//授权
- if (empty($result))
- return $this->error();
- $result = json_decode($result, true);
- return $result;
- }
- /**
- * 查询所有表
- */
- public function getDatabaseList()
- {
- $databaseList = Db::query("SHOW TABLE STATUS");
- return $databaseList;
- }
- /******************************* 升级日志相关 start *****************************/
- /**
- * 添加升级日志
- * @param $data
- * upgrade_time 升级时间
- * version_info 升级的版本信息
- * backup_root 备份文件和sql的根目录
- * download_root 下载文件和sql的根目录
- * @return array
- */
- public function addUpgradeLog($data)
- {
- $res = model('sys_upgrade_log')->add($data);
- if ($res == false) {
- return $this->error('', 'UNKNOW_ERROR');
- } else {
- return $this->success();
- }
- }
- /**
- * 修改日志
- * @return array
- */
- public function editUpgradeLog($data, $condition)
- {
- $res = model('sys_upgrade_log')->update($data, $condition);
- if ($res == false) {
- return $this->error('', 'UNKNOW_ERROR');
- } else {
- return $this->success();
- }
- }
- /**
- * 获取升级日志信息
- * @param $condition
- * @param string $field
- * @return array
- */
- public function getUpgradeLogInfo($condition, $field = '*')
- {
- $info = model('sys_upgrade_log')->getInfo($condition, $field);
- if (!empty($info)) {
- $info[ 'version_info' ] = json_decode($info[ 'version_info' ], true);
- }
- return $info;
- }
- /**
- * 获取升级分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getUpgradeLogPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('sys_upgrade_log')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
- /**
- * 获取升级日志列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getUpgradeLogList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('sys_upgrade_log')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
- /**
- * 删除升级日志
- * @param $condition
- * @return array
- */
- public function deleteUpgradeLog($condition)
- {
- $log_list = model('sys_upgrade_log')->getList($condition, '*', 'upgrade_time asc');
- try {
- foreach ($log_list as $log) {
- $backup_root = $log[ 'backup_root' ];
- if (is_dir($backup_root)) {
- unlink($backup_root);
- }
- }
- model('sys_upgrade_log')->delete($condition);
- return $this->success();
- } catch (\Exception $e) {
- return $this->error('', $e->getMessage());
- }
- }
- /******************************* 升级日志相关 end *****************************/
- public function getVersionLog($page, $page_size)
- {
- $app_info = config('info');
- $post_data = [
- 'page_index' => $page,
- 'page_size' => $page_size,
- 'product_key' => $app_info[ 'name' ]
- ];
- $re = $this->doPost('/upgrade/upgrade/versionPage', $post_data);
- $re = json_decode($re, true);
- if (!empty($re[ 'data' ])) {
- //处理返回数据
- $return_data = [];
- foreach ($re[ 'data' ][ 'list' ] as $key => $val) {
- $val[ 'version_desc' ] = str_replace("\n", '<br/>', $val[ 'version_desc' ]);
- $day = date('Y-m-d', $val[ 'create_time' ]);
- $day_time = strtotime($day);
- $return_data[ $day_time ][] = $val;
- }
- $temp_arr = [];
- foreach ($return_data as $key => $value) {
- $temp_arr[] = [ 'list' => $value, 'time' => $key, 'format_time' => date('Y-m-d', $key) ];
- }
- $re[ 'data' ][ 'list' ] = $temp_arr;
- } else {
- $re[ 'data' ][ 'list' ] = [];
- }
- return $re;
- }
- /**
- * 获取所有插件
- * @return array|mixed
- */
- public function getPluginGoodsList()
- {
- $addon_list = Cache::get('website_addon_list');
- if (empty($addon_list)) {
- $app_info = config('info');
- $data = array (
- "product_key" => $app_info[ 'name' ],
- );
- $result = $this->doPost('/upgrade/auth/allplugin', $data);//授权
- if (empty($result))
- return $this->error();
- $result = json_decode($result, true);
- Cache::set('website_addon_list', $result[ 'data' ], 3 * 24 * 60 * 60);
- return $result[ 'data' ];
- } else {
- return $addon_list;
- }
- }
- /**
- * 下载uniapp
- * @param $version
- * @return array|mixed
- */
- public function downloadUniapp($version)
- {
- $data = array (
- "version" => $version
- );
- $result = $this->doPost('/upgrade/upgrade/downloaduniapp', $data);//授权
- if (empty($result))
- return $this->error();
- $result = json_decode($result, true);
- return $result;
- }
- /**
- * 获取应用更新日志
- * @return mixed
- */
- public function getUpdateLog()
- {
- $app_info = config('info');
- $post_data = [
- 'product_key' => $app_info[ 'name' ]
- ];
- $re = $this->doPost('/upgrade/upgrade/updateLog', $post_data);
- $re = json_decode($re, true);
- return $re;
- }
- }
|