Idiot 4 years ago
parent
commit
c3f660a8cb

+ 27 - 0
battery/command.php

@@ -0,0 +1,27 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Dean <zxxjjforever@163.com>
+// +----------------------------------------------------------------------
+
+$apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR);
+
+$returnCommands = [];
+
+foreach ($apps as $app) {
+    $commandFile = APP_PATH . $app . '/command.php';
+
+    if (file_exists($commandFile)) {
+        $commands       = include $commandFile;
+
+        $returnCommands = array_merge($returnCommands, $commands);
+    }
+
+}
+
+return $returnCommands;

+ 232 - 0
battery/config.php

@@ -0,0 +1,232 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Dean <zxxjjforever@163.com>
+// +----------------------------------------------------------------------
+if (file_exists(CMF_ROOT . "data/conf/config.php")) {
+    $runtimeConfig = include CMF_ROOT . "data/conf/config.php";
+} else {
+    $runtimeConfig = [];
+}
+$configs = [
+    // +----------------------------------------------------------------------
+    // | 应用设置
+    // +----------------------------------------------------------------------
+    // 应用命名空间
+    'app_namespace'           => 'app',
+    // 应用模式状态
+    'app_status'              => APP_DEBUG ? 'debug' : 'release',
+    // 是否支持多模块
+    'app_multi_module'        => true,
+    // 入口自动绑定模块
+    'auto_bind_module'        => true,
+    // 注册的根命名空间
+    'root_namespace'          => ['cmf' => CMF_PATH, 'plugins' => PLUGINS_PATH, 'themes' => PLUGINS_PATH . '../themes', 'api' => CMF_ROOT . 'api/'],
+    // 扩展函数文件
+    'extra_file_list'         => [CMF_PATH . 'common' . EXT, THINK_PATH . 'helper' . EXT],
+    // 默认输出类型
+    'default_return_type'     => 'html',
+    // 默认AJAX 数据返回格式,可选json xml ...
+    'default_ajax_return'     => 'json',
+    // 默认JSONP格式返回的处理方法
+    'default_jsonp_handler'   => 'jsonpReturn',
+    // 默认JSONP处理方法
+    'var_jsonp_handler'       => 'callback',
+    // 默认时区
+    'default_timezone'        => 'PRC',
+    // 是否开启多语言
+    'lang_switch_on'          => false,
+    // 默认全局过滤方法 用逗号分隔多个
+    'default_filter'          => 'htmlspecialchars',
+    // 默认语言
+    'default_lang'            => 'zh-cn',
+    // 应用类库后缀
+    'class_suffix'            => true,
+    // 控制器类后缀
+    'controller_suffix'       => true,
+    // +----------------------------------------------------------------------
+    // | 模块设置
+    // +----------------------------------------------------------------------
+    // 默认模块名
+    'default_module'          => 'user',
+    // 禁止访问模块
+    'deny_module_list'        => ['common'],
+    // 默认控制器名
+    'default_controller'      => 'Index',
+    // 默认操作名
+    'default_action'          => 'index',
+    // 默认验证器
+    'default_validate'        => '',
+    // 默认的空控制器名
+    'empty_controller'        => 'Error',
+    // 自动搜索控制器
+    'controller_auto_search'  => false,
+    // +----------------------------------------------------------------------
+    // | URL设置
+    // +----------------------------------------------------------------------
+    'pathinfo_depr'           => '/',
+    // URL伪静态后缀
+    'url_html_suffix'         => 'html',
+    // URL普通方式参数 用于自动生成
+    'url_common_param'        => false,
+    // URL参数方式 0 按名称成对解析 1 按顺序解析
+    'url_param_type'          => 0,
+    // 是否开启路由
+    'url_route_on'            => true,
+    // 路由配置文件(支持配置多个)
+    'route_config_file'       => ['route'],
+    // 是否强制使用路由
+    'url_route_must'          => false,
+    // 域名部署
+    'url_domain_deploy'       => false,
+    // 域名根,如thinkphp.cn
+    'url_domain_root'         => '',
+    // 是否自动转换URL中的控制器和操作名
+    'url_convert'             => true,
+    // 默认的访问控制器层
+    'url_controller_layer'    => 'controller',
+    // 表单请求类型伪装变量
+    'var_method'              => '_method',
+    // +----------------------------------------------------------------------
+    // | 模板设置
+    // +----------------------------------------------------------------------
+    'template'                => [
+        // 模板引擎类型 支持 php think 支持扩展
+        'type'            => 'Think',
+        // 视图根目录
+        'view_base'       => '',
+        // 模板路径
+        'view_path'       => '',
+        // 模板后缀
+        'view_suffix'     => 'html',
+        // 模板文件名分隔符
+        'view_depr'       => DS,
+        // 模板引擎普通标签开始标记
+        'tpl_begin'       => '{',
+        // 模板引擎普通标签结束标记
+        'tpl_end'         => '}',
+        // 标签库标签开始标记
+        'taglib_begin'    => '<',
+        // 标签库标签结束标记
+        'taglib_end'      => '>',
+        'taglib_build_in' => 'cmf\lib\taglib\Cmf,cx',
+        'tpl_cache'       => APP_DEBUG ? false : true,
+        'tpl_deny_php'    => false
+    ],
+    // 视图输出字符串内容替换
+    'view_replace_str'        => [],
+    // 默认跳转页面对应的模板文件
+    'dispatch_success_tmpl'   => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
+    'dispatch_error_tmpl'     => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
+    // +----------------------------------------------------------------------
+    // | 异常及错误设置
+    // +----------------------------------------------------------------------
+    // 异常页面的模板文件
+    'exception_tmpl'          => THINK_PATH . 'tpl' . DS . 'think_exception.tpl',
+    // 错误显示信息,非调试模式有效
+    'error_message'           => '页面错误!请稍后再试~',
+    // 显示错误信息
+    'show_error_msg'          => false,
+    // 异常处理handle类 留空使用 \think\exception\Handle
+    'exception_handle'        => '',
+    // +----------------------------------------------------------------------
+    // | 日志设置
+    // +----------------------------------------------------------------------
+    'log'                     => [
+        // 日志记录方式,内置 file socket 支持扩展
+        'type'  => 'File',
+        // 日志保存目录
+        'path'  => LOG_PATH,
+        // 日志记录级别
+        'level' => [],
+    ],
+    // +----------------------------------------------------------------------
+    // | Trace设置 开启 app_trace 后 有效
+    // +----------------------------------------------------------------------
+    'trace'                   => [
+        // 内置Html Console 支持扩展
+        'type' => 'Html',
+    ],
+    // +----------------------------------------------------------------------
+    // | 缓存设置
+    // +----------------------------------------------------------------------
+    'cache'                   => [
+        // 驱动方式
+        'type'   => 'File',
+        // 缓存保存目录
+        'path'   => CACHE_PATH,
+        // 缓存前缀
+        'prefix' => 'battery_',
+        // 缓存有效期 0表示永久缓存
+        'expire' => 0,
+    ],
+    // +----------------------------------------------------------------------
+    // | 会话设置
+    // +----------------------------------------------------------------------
+    'session'                 => [
+        'id'             => '',
+        // SESSION_ID的提交变量,解决flash上传跨域
+        'var_session_id' => '',
+        // SESSION 前缀
+        'prefix'         => 'battery_',
+        // 驱动方式 支持redis memcache memcached
+        'type'           => '',
+        // 是否自动开启 SESSION
+        'auto_start'     => true,
+    ],
+    // +----------------------------------------------------------------------
+    // | Cookie设置
+    // +----------------------------------------------------------------------
+    'cookie'                  => [
+        // cookie 名称前缀
+        'prefix'    => 'battery_',
+        // cookie 保存时间
+        'expire'    => 0,
+        // cookie 保存路径
+        'path'      => '/',
+        // cookie 有效域名
+        'domain'    => '',
+        //  cookie 启用安全传输
+        'secure'    => false,
+        // httponly设置
+        'httponly'  => '',
+        // 是否使用 setcookie
+        'setcookie' => true,
+    ],
+    // +----------------------------------------------------------------------
+    // | 数据库设置
+    // +----------------------------------------------------------------------
+    'database'                => [
+        // 数据库调试模式
+        'debug'           => true,
+        // 数据集返回类型
+        'resultset_type'  => 'collection',
+        // 自动写入时间戳字段
+        'auto_timestamp'  => false,
+        // 时间字段取出后的默认时间格式
+        'datetime_format' => false,
+        // 是否需要进行SQL性能分析
+        'sql_explain'     => false,
+    ],
+    //分页配置
+    'paginate'                => [
+        'type'      => '\cmf\paginator\Bootstrap',
+        'var_page'  => 'page',
+        'list_rows' => 15,
+    ],
+    'queue'                   => [
+        'connector' => '\cmf\queue\connector\Database'
+    ],
+    // +----------------------------------------------------------------------
+    // | CMF 设置
+    // +----------------------------------------------------------------------
+    'cmf_theme_path'          => 'themes/',
+    'cmf_default_theme'       => 'battery',
+
+];
+return array_merge($configs, $runtimeConfig);

+ 18 - 0
battery/database.php

@@ -0,0 +1,18 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Dean <zxxjjforever@163.com>
+// +----------------------------------------------------------------------
+
+if(file_exists(CMF_ROOT."data/conf/database.php")){
+    $database=include CMF_ROOT."data/conf/database.php";
+}else{
+    $database=[];
+}
+
+return $database;

+ 18 - 0
battery/debug.php

@@ -0,0 +1,18 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Dean <zxxjjforever@163.com>
+// +----------------------------------------------------------------------
+
+return [
+    // 应用调试模式
+    'app_debug' => true,
+    // 应用Trace
+    'app_trace' => false,
+
+];

+ 70 - 0
battery/portal/common.php

@@ -0,0 +1,70 @@
+<?php
+
+use think\Db;
+use cmf\lib\Storage;
+use think\Config;
+
+
+function getErrCode($key = 0)
+{
+    $info = array(
+        0 => '请求失败',
+        1 => '请求成功',
+        10001 => '未登录'
+    );
+    return $info[$key];
+}
+
+/**
+ * 判断前台用户是否登录
+ * @return boolean
+ */
+function battery_is_user_login()
+{
+    $sessionUser = session('battery_user');
+    return !empty($sessionUser);
+}
+
+/**
+ * 更新当前登录前台用户的信息
+ * @param array $user 前台用户的信息
+ */
+function battery_update_current_user($user){
+    session('battery_user', $user);
+}
+/**
+ * 获取当前登录的前台用户的信息,未登录时,返回false
+ * @return array|boolean
+ */
+function battery_get_current_user()
+{
+    $sessionUser = session('battery_user');
+    if (!empty($sessionUser)) {
+        unset($sessionUser['battery_user_pass']); // 销毁敏感数据
+        return $sessionUser;
+    } else {
+        return false;
+    }
+}
+
+function curl_get_contents($url){
+    $ch=curl_init();
+    curl_setopt($ch, CURLOPT_URL, $url);                //设置访问的url地址
+    // curl_setopt($ch,CURLOPT_HEADER,1);               //是否显示头部信息
+    curl_setopt($ch, CURLOPT_TIMEOUT, 30);               //设置超时
+    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);   //用户访问代理 User-Agent
+    curl_setopt($ch, CURLOPT_REFERER,$_SERVER['HTTP_HOST']);        //设置 referer
+    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);          //跟踪301
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        //返回结果
+    $r=curl_exec($ch);
+    curl_close($ch);
+    return $r;
+}
+
+function hcw_get_md5($str='')
+{
+    return md5('xlC0TSdijC2ESHQD'.$str);
+}
+

+ 24 - 0
battery/portal/config.php

@@ -0,0 +1,24 @@
+<?php
+$kp8j0kqnqfu43f4q=require_once (CMF_ROOT .'/data/conf/kp8j0kqnqfu43f4q.php');
+return [
+    'kp8j0kqnqfu43f4q' =>$kp8j0kqnqfu43f4q,
+
+    //创蓝短信Config---Stard
+    'CL_API_SEND_URL' =>'http://sms.253.com/msg/send/json',
+    'CL_API_BALANCE_QUERY_URL' =>'http://sms.253.com/msg/balance/json',
+    'CL_API_ACCOUNT' =>'N8593123',
+    'CL_API_PASSWORD' =>'lsdxV2eHvC86f0',
+    'CL_VERIFICODO_SIGN_PREFIX' =>'【乐车天下】',
+    //END---创蓝短信Config
+
+    //微信配置
+    'WX_APPID' =>'wx47b51bd81ab60834',
+    'WX_APPSECRET' =>'a38aa0e30fe9ebdfe53465ea4f734ab9',
+    'WX_DATA_AUTH_KEY' =>'vUDtTYyerNFkJ1wH',
+    //微信配置
+
+    'pingzf_apikey'=> 'sk_live_SKO04KiX9SCSqHKefDbbPOu9',//回跳地址
+    'pingzf_appid'=> 'app_5WnXDGTenrzHij94',//回跳地址
+    'pingzf_success_url'=> 'http://api.che7jiang.com/api/callback/Redirect0e1t9fcue2pjsnhl/index',//回跳地址
+    'pingzf_callback_url'=> 'http://api.che7jiang.com/api/callback/Pingzfk40rh4sx0qkdstll/callbacks8NinfY7QF97DuwF',//支付回调
+];

+ 257 - 0
battery/portal/controller/BaseController.php

@@ -0,0 +1,257 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Powerless < wzxaini9@gmail.com>
+// +----------------------------------------------------------------------
+namespace battery\portal\controller;
+
+
+use battery\portal\model\RedisModel;
+use think\Controller;
+use think\View;
+use think\Request;
+use think\Config;
+
+class BaseController extends Controller
+{
+    public function __construct(Request $request = null)
+    {
+        if (is_null($request)) {
+            $request = Request::instance();
+        }
+
+        $this->request = $request;
+
+        $this->_initializeView();
+        $this->view = View::instance(Config::get('template'), Config::get('view_replace_str'));
+
+
+        // 控制器初始化
+        $this->_initialize();
+
+        // 前置操作方法
+        if ($this->beforeActionList) {
+            foreach ($this->beforeActionList as $method => $options) {
+                is_numeric($method) ?
+                    $this->beforeAction($options) :
+                    $this->beforeAction($method, $options);
+            }
+        }
+    }
+
+
+    public function setTitleName($title='默认'){
+        $this->assign('title_name',$title);
+    }
+
+    public function _initialize()
+    {
+        // 监听home_init
+        hook('home_init');
+        parent::_initialize();
+        $siteInfo = cmf_get_site_info();
+        View::share('site_info', $siteInfo);
+    }
+
+    public function _initializeView()
+    {
+        $cmfThemePath    = config('cmf_theme_path');
+        $cmfDefaultTheme = cmf_get_current_theme();
+
+        $themePath = "{$cmfThemePath}{$cmfDefaultTheme}";
+
+        $root = cmf_get_root();
+        //使cdn设置生效
+        $cdnSettings = cmf_get_option('cdn_settings');
+        if (empty($cdnSettings['cdn_static_root'])) {
+            $viewReplaceStr = [
+                '__ROOT__'     => $root,
+                '__TMPL__'     => "{$root}/{$themePath}",
+                '__STATIC__'   => "{$root}/static",
+                '__WEB_ROOT__' => $root
+            ];
+        } else {
+            $cdnStaticRoot  = rtrim($cdnSettings['cdn_static_root'], '/');
+            $viewReplaceStr = [
+                '__ROOT__'     => $root,
+                '__TMPL__'     => "{$cdnStaticRoot}/{$themePath}",
+                '__STATIC__'   => "{$cdnStaticRoot}/static",
+                '__WEB_ROOT__' => $cdnStaticRoot
+            ];
+        }
+
+        $viewReplaceStr = array_merge(config('view_replace_str'), $viewReplaceStr);
+        config('template.view_base', "{$themePath}/");
+        config('view_replace_str', $viewReplaceStr);
+
+        $themeErrorTmpl = "{$themePath}/error.html";
+        if (file_exists_case($themeErrorTmpl)) {
+            config('dispatch_error_tmpl', $themeErrorTmpl);
+        }
+
+        $themeSuccessTmpl = "{$themePath}/success.html";
+        if (file_exists_case($themeSuccessTmpl)) {
+            config('dispatch_success_tmpl', $themeSuccessTmpl);
+        }
+
+
+    }
+
+    /**
+     * 加载模板输出
+     * @access protected
+     * @param string $template 模板文件名
+     * @param array $vars 模板输出变量
+     * @param array $replace 模板替换
+     * @param array $config 模板参数
+     * @return mixed
+     */
+    protected function fetch($template = '', $vars = [], $replace = [], $config = [])
+    {
+        $template = $this->parseTemplate($template);
+        $more     = $this->getThemeFileMore($template);
+        $this->assign('theme_vars', $more['vars']);
+        $this->assign('theme_widgets', $more['widgets']);
+        $content = parent::fetch($template, $vars, $replace, $config);
+
+        $designingTheme = session('admin_designing_theme');
+
+        if ($designingTheme) {
+            $app        = $this->request->module();
+            $controller = $this->request->controller();
+            $action     = $this->request->action();
+
+            $output = <<<hello
+<script>
+var _themeDesign=true;
+var _themeTest="test";
+var _app='{$app}';
+var _controller='{$controller}';
+var _action='{$action}';
+var _themeFile='{$more['file']}';
+parent.simulatorRefresh();
+</script>
+hello;
+
+            $pos = strripos($content, '</body>');
+            if (false !== $pos) {
+                $content = substr($content, 0, $pos) . $output . substr($content, $pos);
+            } else {
+                $content = $content . $output;
+            }
+        }
+
+
+        return $content;
+    }
+
+    /**
+     * 自动定位模板文件
+     * @access private
+     * @param string $template 模板文件规则
+     * @return string
+     */
+    private function parseTemplate($template)
+    {
+        // 分析模板文件规则
+        $request = $this->request;
+        // 获取视图根目录
+        if (strpos($template, '@')) {
+            // 跨模块调用
+            list($module, $template) = explode('@', $template);
+        }
+
+        $viewBase = config('template.view_base');
+
+        if ($viewBase) {
+            // 基础视图目录
+            $module = isset($module) ? $module : $request->module();
+            $path   = $viewBase . ($module ? $module . DS : '');
+        } else {
+            $path = isset($module) ? APP_PATH . $module . DS . 'view' . DS : config('template.view_path');
+        }
+
+        $depr = config('template.view_depr');
+        if (0 !== strpos($template, '/')) {
+            $template   = str_replace(['/', ':'], $depr, $template);
+            $controller = cmf_parse_name($request->controller());
+            if ($controller) {
+                if ('' == $template) {
+                    // 如果模板文件名为空 按照默认规则定位
+                    $template = str_replace('.', DS, $controller) . $depr . cmf_parse_name($request->action(true));
+                } elseif (false === strpos($template, $depr)) {
+                    $template = str_replace('.', DS, $controller) . $depr . $template;
+                }
+            }
+        } else {
+            $template = str_replace(['/', ':'], $depr, substr($template, 1));
+        }
+        return $path . ltrim($template, '/') . '.' . ltrim(config('template.view_suffix'), '.');
+    }
+
+    /**
+     * 获取模板文件变量
+     * @param string $file
+     * @param string $theme
+     * @return array
+     */
+    private function getThemeFileMore($file, $theme = "")
+    {
+
+        //TODO 增加缓存
+        $theme = empty($theme) ? cmf_get_current_theme() : $theme;
+
+
+
+        $themePath = config('cmf_theme_path');
+        $file      = str_replace('\\', '/', $file);
+        $file      = str_replace('//', '/', $file);
+        $themeFile = str_replace(['.html', '.php', $themePath . $theme . "/"], '', $file);
+
+
+
+        $vars    = [];
+        $widgets = [];
+
+
+        return ['vars' => $vars, 'widgets' => $widgets, 'file' => $themeFile];
+    }
+
+
+     public function isLogin()
+    {
+        if (hcw_is_user_login()) {
+
+        } else {
+            $code=10001;
+            $this->result(null,$code,getErrCode($code),'JSON');
+        }
+    }
+
+    //设置缓存
+    public function setRedis($tag,$value,$extime=0){
+        $redisModel=new RedisModel();
+        $redisModel->set($tag,$value,$extime);
+    }
+
+
+
+    public function  jsonSuccess($data,$msg='请求成功'){
+
+        $this->result($data,1,$msg,'JSON');
+    }
+
+    public function  jsonError($data,$msg='请求失败'){
+
+        $this->result($data,0,$msg,'JSON');
+    }
+//    public function check
+
+
+
+}

+ 110 - 0
battery/portal/controller/BatteryBaseController.php

@@ -0,0 +1,110 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Powerless < wzxaini9@gmail.com>
+// +----------------------------------------------------------------------
+namespace battery\portal\controller;
+
+
+use think\Config;
+use think\Request;
+
+class BatteryBaseController extends BaseController
+{
+
+    function __construct(Request $request)
+    {
+        $wx_openid=$this->battery_openid_check();
+        if($wx_openid){
+            $this->battery_wx_autologin($wx_openid);
+        }
+        $filterInfo=$request->module().'|'.$request->controller().'|'.$request->action();
+        $arrayAction=array(
+            'portal|Brand|index',//模块|控制器|方法
+            'portal|Brand|goods',//模块|控制器|方法
+            'portal|Brand|details',//模块|控制器|方法
+            'portal|Brand|searchbrand',//模块|控制器|方法
+            'portal|Brand|searchseries',//模块|控制器|方法
+            'portal|Brand|searchyear',//模块|控制器|方法
+            'portal|Brand|searchmodel',//模块|控制器|方法
+            'portal|Brand|getpay',//模块|控制器|方法
+            'portal|Brand|payorder',//模块|控制器|方法
+        );
+        $isFilter=false;
+        if(in_array($filterInfo,$arrayAction)){
+            $isFilter=true;
+        }
+        if (battery_is_user_login()||$isFilter) {
+            //已经登录时直接跳到首页
+        } else {
+            $this->redirect('login/index');
+        }
+        parent::__construct($request);
+    }
+
+
+    function battery_wx_autologin($openid)
+    {
+//        if ($openid) {
+//            $hcwBaseModel=new HcwBaseModel();
+//            $where['wx_md5']=md5($openid);
+//            $info=$hcwBaseModel->name('user')->where($where)->find();
+//            if ($info) {
+//                battery_update_current_user($info);
+//            }else{
+//                battery_update_current_user(null);
+//            }
+//        }
+    }
+
+    function battery_openid_check()
+    {
+        if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {//检测是否微信浏览器
+            $wx_appid=Config::get('WX_APPID');
+            $wx_appsecret=Config::get('WX_APPSECRET');
+            $wx_data_auth_key=Config::get('WX_DATA_AUTH_KEY');
+            if (cookie('openid')) {//已有cookie,验证有效性
+                $openidsign = md5(cookie('openid'), $wx_data_auth_key);
+                if (!cookie('openidsign') or $openidsign != cookie('openidsign')) {//未通过openid验证,注销重新检测
+                    cookie('openid', null);
+                    cookie('openidsign', null);
+                    battery_update_current_user(null);
+                } else {
+                    return cookie('openid');
+                }
+            } else {//跳转获取
+                $request = Request::instance();
+                $data=$request->param();
+
+
+                if (!isset($data['code'])) {
+                    $redirect_uri = url('index/index','',true,true);
+                    $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $wx_appid . '&redirect_uri=' . $redirect_uri . '&response_type=code&scope=snsapi_userinfo&state=login#wechat_redirect';
+                    $this->redirect($url);
+                } else {
+                    $code = $data['code'];
+                    $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' .$wx_appid . '&secret=' . $wx_appsecret . '&code=' . $code . '&grant_type=authorization_code';
+                    // curl获取prepay_id
+                    $result = curl_get_contents($url);
+                    $result = json_decode($result, true);
+                    $openid = $result['openid'];
+                    cookie('openid', $openid, 604800);
+                    $openidsign = md5($openid, $wx_data_auth_key);
+                    cookie('openidsign', $openidsign, 604800);
+                    return $openid;
+                }
+            }
+        }
+    }
+    public function setTitleName($title='默认'){
+        $this->assign('title_name',$title);
+    }
+
+
+
+}

+ 425 - 0
battery/portal/controller/BrandController.php

@@ -0,0 +1,425 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Powerless < wzxaini9@gmail.com>
+// +----------------------------------------------------------------------
+namespace battery\portal\controller;
+
+
+use battery\portal\model\BatteryBaseModel;
+use battery\portal\model\PingZfPlatform;
+use battery\portal\model\SdPlatform;
+use think\Config;
+use think\Request;
+use think\Validate;
+class BrandController extends BatteryBaseController
+{
+
+
+    function index(){
+
+        $this->setTitleName('自助选车');
+       
+        return $this->fetch();
+    }
+
+
+    function searchBrand(){
+
+        $sdPlatform=new SdPlatform();
+        $info=$sdPlatform->searchBrand();
+        if($info['status']){
+            $this->success('请求成功','',$info['info']);
+        }else{
+            $this->error('获取失败');
+        }
+    }
+
+    function searchSeries(){
+        $validate = new Validate([
+            'name'          => 'require',
+        ]);
+        $validate->message([
+            'name.require'          => '品牌名称',
+        ]);
+
+        $data = $this->request->param();
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $sdPlatform=new SdPlatform();
+        $info=$sdPlatform->searchSeries(trim($data['name']));
+        if($info['status']){
+            $this->success('请求成功','',$info['info']);
+        }else{
+            $this->error('获取失败');
+        }
+    }
+
+    function searchYear(){
+        $validate = new Validate([
+            'name'          => 'require',
+            'type'          => 'require',
+        ]);
+        $validate->message([
+            'name.require'          => '品牌名称',
+            'type.require'          => '车辆类型',
+        ]);
+
+        $data = $this->request->param();
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $sdPlatform=new SdPlatform();
+        $info=$sdPlatform->searchYear(trim($data['name']),trim($data['type']));
+        if($info['status']){
+            $this->success('请求成功','',$info['info']);
+        }else{
+            $this->error('获取失败');
+        }
+    }
+    function searchModel(){
+        $validate = new Validate([
+            'name'          => 'require',
+            'type'          => 'require',
+            'year'          => 'require',
+        ]);
+        $validate->message([
+            'name.require'          => '品牌名称',
+            'type.require'          => '车辆类型',
+            'year.require'          => '车辆类型',
+        ]);
+
+        $data = $this->request->param();
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $sdPlatform=new SdPlatform();
+        $info=$sdPlatform->searchModel(trim($data['name']),trim($data['type']),trim($data['year']));
+        if($info['status']){
+            $this->success('请求成功','',$info['info']);
+        }else{
+            $this->error('获取失败');
+        }
+    }
+
+    function goods(){
+        $validate = new Validate([
+            'name'          => 'require',
+            'type'          => 'require',
+            'year'          => 'require',
+            'model'          => 'require',
+            'carid'          => 'require',
+        ]);
+        $validate->message([
+            'name.require'          => '品牌名称',
+            'type.require'          => '车辆类型',
+            'year.require'          => '车辆类型',
+            'model.require'          => '车辆类型',
+            'carid.require'          => '车辆类型',
+        ]);
+
+        $data = $this->request->param();
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $sdPlatform=new SdPlatform();
+        $info=$sdPlatform->weblcMatch(trim($data['carid']));
+        $sdata=array();
+        if($info['status']){
+            $sdata=$info['info'];
+        }
+        $this->setTitleName('电瓶上门安装');
+        $this->assign('carname', trim($data['name']));
+        $this->assign('cartype', trim($data['type']));
+        $this->assign('caryear', trim($data['year']));
+        $this->assign('carmodel', trim($data['model']));
+        $this->assign('datalist', $sdata);
+
+        return $this->fetch();
+    }
+
+
+
+
+
+
+
+function getpay(){
+        $validate = new Validate([
+            'name'          => 'require',
+            'type'          => 'require',
+            'year'          => 'require',
+            'model'          => 'require',
+            'gid'          => 'require',
+        ]);
+        $validate->message([
+            'name.require'          => '品牌名称',
+            'type.require'          => '车辆类型',
+            'year.require'          => '车辆年份',
+            'model.require'          => '车辆型号',
+            'gid.require'          => '商品ID',
+        ]);
+        $data = $this->request->param();
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $batteryBaseModel = new BatteryBaseModel();
+        $goodWhere['gid']=$data['gid'];
+        $good=$batteryBaseModel->name('good')->where($goodWhere)->order('id DESC')->find();
+        if(!$good){
+            $this->error('获取商品失败');
+        }
+        $morderid = 'T' . $this->getOrderId();
+        $time=time();
+        $md5=md5($morderid.'rWY27jftsCVkawzmUtNi2b53niWbTopU');
+        $orderData = array(
+            'order_id' => $morderid,
+            'gid' => intval($data['gid']),
+            'amount' => $good->price,
+            'create_time' => $time,
+            'up_time' => $time,
+            'brief' => '电池',
+            'car_name' => trim($data['name']),
+            'car_type' => trim($data['type']),
+            'car_year' => trim($data['year']),
+            'car_model' =>trim($data['model']),
+            'ip' => get_client_ip(),
+            'md5' => $md5
+        );
+        $tag=$batteryBaseModel->name('order')->insert($orderData);
+        if($tag){
+            $this->success('请求成功','',$md5);
+        }else{
+            $this->error('获取失败');
+        }
+
+
+    }
+
+    function details(){
+        $validate = new Validate([
+            'token'          => 'require',
+
+        ]);
+        $validate->message([
+            'token.require'          => '参数异常',
+        ]);
+        $data = $this->request->param();
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $this->setTitleName('订单确认');
+        $batteryBaseModel=new BatteryBaseModel();
+        $where['md5']=$data['token'];
+        $order=$batteryBaseModel->name('order')->where($where)->find();
+        if($order){
+            $order->amount=bcdiv($order->amount,100,2);
+            $weekArr=array("日","一","二","三","四","五","六");
+            $days=array();
+
+            for($i=0;$i<35;$i++){
+                $days[$i]['time']=date("m-d",strtotime('+'.$i.'day'));
+                $days[$i]['time_date']=date("Y-m-d",strtotime('+'.$i.'day'));
+                if ($i==0) {
+                    $days[$i]['week']= '今';
+                    $days[$i]['class']= 'jin';
+                }else{
+                    $days[$i]['week']= $weekArr[date("w",strtotime('+'.$i.'day'))];
+                }
+            }
+
+            $setdata=array();
+            $str='';
+            foreach ($days as $key=>$v){
+                $str=$str."<td class=\"tb_item\" onclick=\"selecttime(this)\" data-time=\"{$v['time_date']}\">
+                                    <div >{$v['time']}</div>
+                                    <div class=\"tb_item_time\">{$v['week']}</div>
+                                </td>";
+                if((($key+1)%7)==0){
+                    $html="<tr>".$str."</tr>";
+                    array_push($setdata,array('html'=>$html));
+                    $str='';
+                }
+            }
+            $this->assign('order', $order);
+            $this->assign('weekinfo', $setdata);
+            $this->assign('token', trim($data['token']));
+            return $this->fetch();
+        }else{
+            $this->error('订单信息不存在');
+        }
+
+    }
+
+    //账单明细
+    function payorder()
+    {
+        $validate = new Validate([
+            'token'          => 'require',
+            'province'          => 'require',
+            'city'          => 'require',
+            'area'          => 'require',
+            'user_name'          => 'require',
+            'user_phone'          => 'require',
+            'user_addr'          => 'require',
+            'select_time'          => 'require',
+        ]);
+        $validate->message([
+            'token.require'          => '参数异常',
+            'province.require'          => '用户姓名',
+            'city.require'          => '用户姓名',
+            'area.require'          => '用户姓名',
+            'user_name.require'          => '用户姓名',
+            'user_phone.require'          => '收款手机号',
+            'user_addr.require'          => '用户地址',
+            'select_time.require'          => '预约时间',
+        ]);
+
+        //TODO 手机校验没做
+        $data = $this->request->param();
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $select_time=strtotime($data['select_time']);
+        if($select_time<=0||$select_time<time()){
+            $this->error('预约时间有误');
+        }
+        $channel_id='alipay_wap';
+        $where['md5']=$data['token'];
+        $batteryBaseModel=new BatteryBaseModel();
+        $batteryBaseModel->startTrans();
+
+        $order=$batteryBaseModel->name('order')->where($where)->lock(true)->find();
+
+        $time=time();
+        if($order){
+            $isNotAddr=false;
+            $addrss_id=0;
+            if($order->addrss_id===0){
+                $isNotAddr=true;
+                $addmd5=md5($data['province'].$data['city'].$data['area'].$data['user_name'].$data['user_phone'].$data['user_addr']);
+                $addWhere['md5']=$addmd5;
+                $addrss=$batteryBaseModel->name('addrss')->where($addWhere)->find();
+                if(!$addrss){
+                    $dataAdd = array(
+                        'name' => $data['user_name'],
+                        'phone' => $data['user_phone'],
+                        'province' => $data['province'],
+                        'city' => $data['city'],
+                        'area' => $data['area'],
+                        'content' => $data['user_addr'],
+                        'create_time' => $time,
+                        'md5' => $addmd5
+                    );
+                    $addtag=$batteryBaseModel->name('addrss')->insert($dataAdd);
+                    if(!$addtag){
+                        $batteryBaseModel->rollback();
+                        $this->error('下单失败1004');
+                    }else{
+                        $addrss_id=$batteryBaseModel->getLastInsID();
+                    }
+
+                }else{
+                    $addrss_id=$addrss->id;
+                }
+            }
+            $paywhere['order_id']=$order->id;
+            $payorder=$batteryBaseModel->name('pay_order')->where($paywhere)->lock(true)->find();
+            if($payorder){
+                $this->success('请求成功','',$payorder->pay_data);
+            }else{
+                if($isNotAddr){
+                    $orderUp['addrss_id']=$addrss_id;
+                }
+                $orderUp['select_time']=$select_time;
+                $batteryBaseModel->name('order')->where($where)->update($orderUp);
+                $dataPay = array(
+                    'order_id' => $order->id,
+                    'order_num' => $order->order_id,
+                    'create_time' => $time,
+                    'up_time' => $time,
+                    'channel_id' => 1,
+//                    'price' => $order->amount,
+                    'price' => 1,
+                    'md5' => md5( $order->id . $order->order_id . 'rWY27jftsCVkawzmUtNi2b53niWbTopU')
+                );
+                $tagPay = $batteryBaseModel->name('pay_order')->insert($dataPay);
+                if($tagPay){
+                    $pingZfPlatform=new PingZfPlatform();
+                    $dataPay['success_url']=url('portal/brand','',true,true);
+                    $info=$pingZfPlatform->createCharge($dataPay,'电池上门服务','alipay_wap',get_client_ip(),'');
+                    if ($info) {
+                        $upDataPay['up_time'] = time();
+                        switch ($channel_id) {
+                            case 'alipay_wap':
+                                $upDataPay['pay_data'] = json_encode($info);
+                                break;
+                        }
+                        $upwhere['id'] = $batteryBaseModel->getLastInsID();
+                        $tagPay1 = $batteryBaseModel->name('pay_order')->where($upwhere)->update($upDataPay);
+                        if($tagPay1){
+                            $batteryBaseModel->commit();
+                            $this->success('请求成功','',$upDataPay['pay_data']);
+                        }else{
+                            $batteryBaseModel->rollback();
+                            $this->error('下单失败1002');
+                        }
+                    }else{
+                        $batteryBaseModel->rollback();
+                        $this->error('下单失败1003');
+                    }
+                }else{
+                    $batteryBaseModel->rollback();
+                    $this->error('下单失败1001');
+                }
+            }
+
+        }else{
+            $batteryBaseModel->rollback();
+            $this->error('查询订单失败');
+        }
+    }
+
+
+    function submint(){
+        $validate = new Validate([
+            'token'          => 'require',
+        ]);
+        $validate->message([
+            'token.require'          => '参数异常',
+        ]);
+        $data = $this->request->param();
+        if (!$validate->check($data)) {
+            $this->error($validate->getError());
+        }
+        $this->setTitleName('订单确认');
+        $batteryBaseModel=new BatteryBaseModel();
+        $where['md5']=$data['token'];
+
+        $order=$batteryBaseModel->name('order')->where($where)->find();
+
+        if($order){
+            return $this->fetch();
+
+        }else{
+            $this->error('订单信息不存在');
+        }
+    }
+
+    private function getOrderId($prefix = '300')
+    {
+        return $prefix . (strtotime(date('YmdHis', time()))) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999));
+    }
+    
+    
+    
+
+
+
+}

+ 14 - 0
battery/portal/model/BatteryBaseModel.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace battery\portal\model;
+
+use think\Model;
+
+
+class BatteryBaseModel extends Model
+{
+    protected $connection = 'kp8j0kqnqfu43f4q';
+
+
+    
+}

+ 92 - 0
battery/portal/model/PingZfPlatform.php

@@ -0,0 +1,92 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: liukun
+ * Date: 2018/9/28
+ * Time: 下午12:32
+ */
+namespace battery\portal\model;
+
+
+use think\Config;
+
+class PingZfPlatform
+{
+    function __construct()
+    {
+        vendor('pingzf.init');
+        \Pingpp\Pingpp::setApiKey(Config::get('pingzf_apikey'));
+        \Pingpp\Pingpp::setPrivateKeyPath('../data/conf/pingzf_rsa_private_key.pem');
+        //设置自定义 CA 证书路径
+        \Pingpp\Pingpp::$caBundle = '/path/to/cacert.pem';
+    }
+    function get_client_ipx()
+    {
+        $cip = "unknown";
+        if ($_SERVER['REMOTE_ADDR'])
+        {
+            $cip = $_SERVER['REMOTE_ADDR'];
+        }
+        elseif (getenv("REMOTE_ADDR"))
+        {
+            $cip = getenv("REMOTE_ADDR");
+        }
+        return $cip;
+}
+    //支付
+    function createCharge($pay='',$goodname='',$channel='',$ip,$openid=''){
+
+        $pingZFdata=array(
+            'order_no'  => $pay['order_num'],
+            'amount'    => $pay['price'],
+            'app'       => array('id' => Config::get('pingzf_appid')),
+            'channel'   => $channel,
+            'extra'     => $channel,
+            'time_expire'   =>$pay['create_time']+1800 ,//默认30分钟有效期
+            'currency'  => 'cny',
+            'client_ip' => $ip,
+            'subject'   => $goodname,
+            'body'      => $goodname
+        );
+        switch ($channel){
+            case 'wx_pub':
+                $pingZFdata['extra']=array(
+                    'open_id'=>$openid?$openid:''
+                );
+                break;
+            case 'alipay_wap':
+                $pingZFdata['extra']=array(
+                    'success_url'=>$pay['success_url']?$pay['success_url']:''
+                );
+                break;
+
+        }
+        $info=\Pingpp\Charge::create($pingZFdata);
+       
+        return $info;
+    }
+    
+    
+
+
+    //退款
+    function createRefund($pay=''){
+
+        $jsonRefund=json_decode($pay->success_data,true);;
+        $ch = \Pingpp\Charge::retrieve($jsonRefund['data']['object']['id']);
+        $re = $ch->refunds->create(
+            array('description'=>'退款')
+        );
+        return $re;
+    }
+
+    //取消待支付退款
+    function createReverse($pay=''){
+        $jsonRefund=json_decode($pay->pay_data,true);;
+        $charge = \Pingpp\Charge::reverse($jsonRefund['id']);
+        return $charge;
+    }
+
+
+
+}

+ 23 - 0
battery/portal/model/RedisModel.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace battery\portal\model;
+
+use think\cache\driver\Redis;
+
+class RedisModel extends Redis
+{
+    protected $options = [
+        'host'       => 'localhost',
+        'port'       => 6379,
+        'password'   => '',
+        'select'     => 0,
+        'timeout'    => 0,
+        'expire'     => 0,
+        'persistent' => false,
+        'prefix'     => 'battery_',
+    ];
+    
+
+    
+    
+}

+ 399 - 0
battery/portal/model/SdPlatform.php

@@ -0,0 +1,399 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: liukun
+ * Date: 2018/9/28
+ * Time: 下午12:32
+ */
+
+namespace battery\portal\model;
+
+use think\Config;
+class SdPlatform
+{
+
+    var $url='http://mo2oceshi.sudianwang.com/index.php/WebInter/';
+    var $zh='test';
+    var $pwd='test17810';
+    var $safecode='testqwijdnshlena';
+    var $extime='172800';
+
+
+    //电瓶匹配
+    function weblcMatch($car_id=0){
+        $rinfo=array('status'=>0,'info'=>'');
+        $arrinfo=array(
+            'sign'=>md5($this->zh.$this->pwd.$this->safecode),
+            'car_id'=>$car_id,
+        );
+        $post_data=array(
+            'result'=>json_encode($arrinfo),
+        );
+        $result=$this->curl($this->url.'WeblcMatch',$post_data);
+
+        if($result['code']===0){
+            $rinfo['status']=1;
+            $rinfo['info']= $result['data'];
+            if(count($rinfo['info'])>0){
+                $batteryBaseModel=new BatteryBaseModel();
+                $time=time();
+                foreach ($rinfo['info'] as $v){
+                    $price=bcmul($v['price'],100,0);
+                    $md5=md5($v['battery_brand'].$v['battery_model'].$price.$v['id'].'1');
+                    $whrer=array();
+                    $whrer['md5']=$md5;
+                    $batteryBaseModel->startTrans();
+                    $order=$batteryBaseModel->name('good')->where($whrer)->find();
+                    $batteryBaseModel->commit();
+                    if(!$order){
+                        $insert=array(
+                            'brand'=>$v['battery_brand'],
+                            'model'=>$v['battery_model'],
+                            'price'=>$price,
+                            'create_time'=>$time,
+                            'gid'=>$v['id'],
+                            'md5'=>$md5,
+                        );
+                        $batteryBaseModel->name('good')->insert($insert);
+                    }
+
+                }
+
+            }
+
+        }
+        return $rinfo;
+    }
+
+
+    //获取品牌列表
+    function searchBrand()
+    {
+        $rinfo=array('status'=>0,'info'=>'');
+
+//        $redisModel=new RedisModel();
+//        $redinfo=$redisModel->get('searchBrand');
+//        if($redinfo){
+//            $rinfo['status']=1;
+//            $rinfo['info']= $redinfo;
+//            return;
+//        }
+
+        $arrinfo=array(
+                'sign'=>md5($this->zh.$this->pwd.$this->safecode),
+        );
+        $post_data=array(
+            'result'=>json_encode($arrinfo),
+        );
+        $result=$this->curl($this->url.'WebSearchBrand',$post_data);
+
+        if($result['code']===0){
+            $rinfo['status']=1;
+            $sdata=$this->getGroupData($result['data']);
+//            $redisModel->set('searchBrand',$sdata,$this->extime);
+            $rinfo['info']= $sdata;
+        }
+        return $rinfo;
+
+    }
+
+    //获取车型列表
+    function searchSeries($name='')
+    {
+        $rinfo=array('status'=>0,'info'=>'');
+//        $redisModel=new RedisModel();
+//        $tag=md5('searchSeries'.$name);
+//        $redinfo=$redisModel->get($tag);
+//        if($redinfo){
+//            $rinfo['status']=1;
+//            $rinfo['info']= $redinfo;
+//            return;
+//        }
+
+
+        $arrinfo=array(
+            'sign'=>md5($this->zh.$this->pwd.$this->safecode),
+            'brand'=>$name,
+        );
+        $post_data=array(
+            'result'=>json_encode($arrinfo),
+        );
+        $result=$this->curl($this->url.'WebSearchSeries',$post_data);
+
+        if($result['code']===0){
+            $rinfo['status']=1;
+//            $redisModel->set($tag,$result['data'],$this->extime);
+            $rinfo['info']= $result['data'];
+        }
+        return $rinfo;
+
+    }
+
+    //获取车型列表
+    function searchYear($name='',$type='')
+    {
+        $rinfo=array('status'=>0,'info'=>'');
+//        $redisModel=new RedisModel();
+//        $tag=md5('searchYear'.$name.$type);
+//        $redinfo=$redisModel->get($tag);
+//        if($redinfo){
+//            $rinfo['status']=1;
+//            $rinfo['info']= $redinfo;
+//            return;
+//        }
+        $arrinfo=array(
+            'sign'=>md5($this->zh.$this->pwd.$this->safecode),
+            'brand'=>$name,
+            'series'=>$type,
+        );
+        $post_data=array(
+            'result'=>json_encode($arrinfo),
+        );
+        $result=$this->curl($this->url.'WebSearchYear',$post_data);
+
+        if($result['code']===0){
+            $rinfo['status']=1;
+//            $redisModel->set($tag,$result['data'],$this->extime);
+            $rinfo['info']= $result['data'];
+        }
+        return $rinfo;
+
+    }
+
+
+    //获取车型列表
+    function searchModel($name='',$type='',$year='')
+    {
+        $rinfo=array('status'=>0,'info'=>'');
+//        $redisModel=new RedisModel();
+//        $tag=md5('searchModel'.$name.$type.$year);
+//        $redinfo=$redisModel->get($tag);
+//        if($redinfo){
+//            $rinfo['status']=1;
+//            $rinfo['info']= $redinfo;
+//            return;
+//        }
+        $arrinfo=array(
+            'sign'=>md5($this->zh.$this->pwd.$this->safecode),
+            'brand'=>$name,
+            'series'=>$type,
+            'year'=>$year,
+        );
+        $post_data=array(
+            'result'=>json_encode($arrinfo),
+        );
+        $result=$this->curl($this->url.'WebSearchModel',$post_data);
+
+        if($result['code']===0){
+            $rinfo['status']=1;
+//            $redisModel->set($tag,$result['data'],$this->extime);
+            $rinfo['info']= $result['data'];
+        }
+        return $rinfo;
+
+    }
+
+    //获取车型列表
+    function searchGood($name='',$type='')
+    {
+        $rinfo=array('status'=>0,'info'=>'');
+        $arrinfo=array(
+            'sign'=>md5($this->zh.$this->pwd.$this->safecode),
+            'brand'=>$name,
+            'series'=>$type,
+        );
+        $post_data=array(
+            'result'=>json_encode($arrinfo),
+        );
+        $result=$this->curl($this->url.'WebSearchYear',$post_data);
+
+        if($result['code']===0){
+            $rinfo['status']=1;
+            $rinfo['info']= $result['data'];
+        }
+        return $rinfo;
+
+    }
+
+
+    //用于字母归组
+    private function getGroupData($data){
+        $data = $this->groupByInitials($data, 'brand');
+        $arrat=array();
+        foreach ($data as $key=>$v){
+
+            array_push($arrat,array('name'=>$key,'list'=>$data[$key]));
+
+        }
+        return $arrat;
+    }
+
+    /**
+     * 二维数组根据首字母分组排序
+     * @param array $data  二维数组
+     * @param string $targetKey 首字母的键名
+     * @return array    根据首字母关联的二维数组
+     */
+    public function groupByInitials(array $data, $targetKey = 'name')
+    {
+        $data = array_map(function ($item) use ($targetKey) {
+            return array_merge($item, [
+                'initials' => $this->getInitials($item[$targetKey]),
+            ]);
+        }, $data);
+        $data = $this->sortInitials($data);
+        return $data;
+    }
+
+    /**
+     * 按字母排序
+     * @param array $data
+     * @return array
+     */
+    public function sortInitials(array $data)
+    {
+        $sortData = [];
+        foreach ($data as $key => $value) {
+            $sortData[$value['initials']][] = $value;
+        }
+        ksort($sortData);
+        return $sortData;
+    }
+
+    /**
+     * 获取首字母
+     * @param string $str 汉字字符串
+     * @return string 首字母
+     */
+    public function getInitials($str)
+    {
+        if (empty($str)) {return '';}
+        $fchar = ord($str{0});
+        if ($fchar >= ord('A') && $fchar <= ord('z')) {
+            return strtoupper($str{0});
+        }
+
+        $s1 = iconv('UTF-8', 'gb2312', $str);
+        $s2 = iconv('gb2312', 'UTF-8', $s1);
+        $s = $s2 == $str ? $s1 : $str;
+        $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
+        if ($asc >= -20319 && $asc <= -20284) {
+            return 'A';
+        }
+
+        if ($asc >= -20283 && $asc <= -19776) {
+            return 'B';
+        }
+
+        if ($asc >= -19775 && $asc <= -19219) {
+            return 'C';
+        }
+
+        if ($asc >= -19218 && $asc <= -18711) {
+            return 'D';
+        }
+
+        if ($asc >= -18710 && $asc <= -18527) {
+            return 'E';
+        }
+
+        if ($asc >= -18526 && $asc <= -18240) {
+            return 'F';
+        }
+
+        if ($asc >= -18239 && $asc <= -17923) {
+            return 'G';
+        }
+
+        if ($asc >= -17922 && $asc <= -17418) {
+            return 'H';
+        }
+
+        if ($asc >= -17417 && $asc <= -16475) {
+            return 'J';
+        }
+
+        if ($asc >= -16474 && $asc <= -16213) {
+            return 'K';
+        }
+
+        if ($asc >= -16212 && $asc <= -15641) {
+            return 'L';
+        }
+
+        if ($asc >= -15640 && $asc <= -15166) {
+            return 'M';
+        }
+
+        if ($asc >= -15165 && $asc <= -14923) {
+            return 'N';
+        }
+
+        if ($asc >= -14922 && $asc <= -14915) {
+            return 'O';
+        }
+
+        if ($asc >= -14914 && $asc <= -14631) {
+            return 'P';
+        }
+
+        if ($asc >= -14630 && $asc <= -14150) {
+            return 'Q';
+        }
+
+        if ($asc >= -14149 && $asc <= -14091) {
+            return 'R';
+        }
+
+        if ($asc >= -14090 && $asc <= -13319) {
+            return 'S';
+        }
+
+        if ($asc >= -13318 && $asc <= -12839) {
+            return 'T';
+        }
+
+        if ($asc >= -12838 && $asc <= -12557) {
+            return 'W';
+        }
+
+        if ($asc >= -12556 && $asc <= -11848) {
+            return 'X';
+        }
+
+        if ($asc >= -11847 && $asc <= -11056) {
+            return 'Y';
+        }
+
+        if ($asc >= -11055 && $asc <= -10247) {
+            return 'Z';
+        }
+
+        return null;
+    }
+
+
+
+
+
+
+
+
+    private function curl($target,$post_data){
+        $post_data=http_build_query($post_data);
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_URL, $target);
+        curl_setopt($curl, CURLOPT_HEADER, false);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($curl, CURLOPT_NOBODY, true);
+        curl_setopt($curl, CURLOPT_NOBODY, true);
+        curl_setopt($curl, CURLOPT_POST, true);
+        curl_setopt($curl, CURLOPT_TIMEOUT, 10);          //单位 秒,也
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
+        $return_str = curl_exec($curl);
+        $result=json_decode($return_str,true);
+        curl_close($curl);
+        return $result;
+    }
+
+}

+ 18 - 0
battery/release.php

@@ -0,0 +1,18 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Dean <zxxjjforever@163.com>
+// +----------------------------------------------------------------------
+
+return [
+    // 应用调试模式
+    'app_debug' => false,
+    // 应用Trace
+    'app_trace' => false,
+
+];

+ 18 - 0
battery/route.php

@@ -0,0 +1,18 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Dean <zxxjjforever@163.com>
+// +----------------------------------------------------------------------
+
+if (file_exists(CMF_ROOT . "data/conf/route.php")) {
+    $runtimeRoutes = include CMF_ROOT . "data/conf/route.php";
+} else {
+    $runtimeRoutes = [];
+}
+
+return $runtimeRoutes;

+ 43 - 0
battery/tags.php

@@ -0,0 +1,43 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: Dean <zxxjjforever@163.com>
+// +----------------------------------------------------------------------
+
+// 应用行为扩展定义文件
+return [
+    // 应用初始化
+    'app_init'    => [
+        'cmf\\behavior\\InitHookBehavior',
+    ],
+    // 应用开始
+    'app_begin'   => [
+        'cmf\\behavior\\LangBehavior',
+    ],
+    // 模块初始化
+    'module_init' => [
+        'cmf\\behavior\\InitAppHookBehavior',
+    ],
+//    // 操作开始执行
+//    'action_begin' => [],
+//    // 视图内容过滤
+//    'view_filter'  => [],
+//    // 日志写入
+//    'log_write'    => [],
+//    //日志写入完成
+//    'log_write_done'=>[],
+//    // 应用结束
+//    'app_end'      => [],
+    // 应用开始
+//    'admin_init'  => [
+//        'cmf\\behavior\\AdminLangBehavior',
+//    ],
+//    'home_init'   => [
+//        'cmf\\behavior\\HomeLangBehavior',
+//    ]
+];