stanley-king před 9 roky
rodič
revize
c5894e77e0

+ 1 - 1
admin/config/config.ini.php

@@ -1,6 +1,6 @@
 <?php
 defined('InShopNC') or exit('Access Invalid!');
 
-$config['sys_log'] 			= true;
+$config['sys_log'] = true;
 
 return $config;

+ 4 - 3
admin/control/control.php

@@ -7,8 +7,8 @@
  ***/
 
 defined('InShopNC') or exit('Access Invalid!');
-class SystemControl{
-
+class SystemControl
+{
 	/**
 	 * 管理员资料 name id group
 	 */
@@ -18,7 +18,8 @@ class SystemControl{
 	 * 权限内容
 	 */
 	protected $permission;
-	protected function __construct(){
+	protected function __construct()
+	{
 		Language::read('common,layout');
 		/**
 		 * 验证用户是否登录

+ 1 - 1
admin/control/domain.php

@@ -114,7 +114,7 @@ class domainControl extends SystemControl{
 			$subdomain_length[0] = 3;
 			$subdomain_length[1] = 12;
 		}
-		Tpl::output('subdomain_length',$usbdomain_length);
+		Tpl::output('subdomain_length',$subdomain_length);
 
 		if (chksubmit()){
 			$store_domain_times = intval($_POST['store_domain_times']);//店铺已修改次数

+ 12 - 5
admin/control/index.php

@@ -8,12 +8,15 @@
 
 defined('InShopNC') or exit('Access Invalid!');
 
-class indexControl extends SystemControl{
+class indexControl extends SystemControl
+{
 	public function __construct(){
 		parent::__construct();
 		Language::read('index');
 	}
-	public function indexOp(){
+
+	public function indexOp()
+	{
 		//输出管理员信息
 		Tpl::output('admin_info',$this->getAdminInfo());
 		//输出菜单
@@ -36,8 +39,10 @@ class indexControl extends SystemControl{
 	/**
 	 * 修改密码
 	 */
-	public function modifypwOp(){
-		if (chksubmit()){
+	public function modifypwOp()
+	{
+		if (chksubmit())
+		{
 			if (trim($_POST['new_pw']) !== trim($_POST['new_pw2'])){
 				//showMessage('两次输入的密码不一致,请重新输入');
 				showMessage(Language::get('index_modifypw_repeat_error'));
@@ -60,7 +65,9 @@ class indexControl extends SystemControl{
 			}else{
 				showMessage(Language::get('index_modifypw_fail'));
 			}
-		}else{
+		}
+		else
+		{
 			Language::read('admin');
 			Tpl::showpage('admin.modifypw');
 		}

+ 85 - 0
core/33hao.php

@@ -0,0 +1,85 @@
+<?php
+/**
+ * 运行框架
+ *
+ *
+ *
+ *
+ */
+
+defined('InShopNC') or exit('Access Invalid!');
+if (!@include(BASE_DATA_PATH.'/config/config.ini.php')) exit('config.ini.php isn\'t exists!');
+
+if (file_exists(BASE_PATH.'/config/config.ini.php')){
+	include(BASE_PATH.'/config/config.ini.php');
+}
+global $config;
+//默认平台店铺id
+define('DEFAULT_PLATFORM_STORE_ID', $config['default_store_id']);
+
+define('URL_MODEL',$config['url_model']);
+$auto_site_url = strtolower('http://'.$_SERVER['HTTP_HOST'].implode('/',$tmp_array));
+define(SUBDOMAIN_SUFFIX, $config['subdomain_suffix']);
+define('BASE_SITE_URL', $config['base_site_url']);
+define('SHOP_SITE_URL', $config['shop_site_url']);
+define('CMS_SITE_URL', $config['cms_site_url']);
+define('CIRCLE_SITE_URL', $config['circle_site_url']);
+define('MICROSHOP_SITE_URL', $config['microshop_site_url']);
+define('ADMIN_SITE_URL', $config['admin_site_url']);
+define('MOBILE_SITE_URL', $config['mobile_site_url']);
+define('WAP_SITE_URL', $config['wap_site_url']);
+define('UPLOAD_SITE_URL',$config['upload_site_url']);
+define('RESOURCE_SITE_URL',$config['resource_site_url']);
+define('DELIVERY_SITE_URL',$config['delivery_site_url']);
+
+define('BASE_DATA_PATH',BASE_ROOT_PATH.'/data');
+define('BASE_UPLOAD_PATH',BASE_DATA_PATH.'/upload');
+define('BASE_RESOURCE_PATH',BASE_DATA_PATH.'/resource');
+
+define('CHARSET',$config['db'][1]['dbcharset']);
+define('DBDRIVER',$config['dbdriver']);
+define('SESSION_EXPIRE',$config['session_expire']);
+define('LANG_TYPE',$config['lang_type']);
+define('COOKIE_PRE',$config['cookie_pre']);
+
+define('DBPRE',$config['tablepre']);
+define('DBNAME',$config['db'][1]['dbname']);
+
+$_GET['act'] = $_GET['act'] ? strtolower($_GET['act']) : ($_POST['act'] ? strtolower($_POST['act']) : null);
+$_GET['op']  = $_GET['op'] ? strtolower($_GET['op']) : ($_POST['op'] ? strtolower($_POST['op']) : null);
+
+if (empty($_GET['act'])){
+    require_once(BASE_CORE_PATH.'/framework/core/route.php');
+    new Route($config);
+}
+//统一ACTION
+$_GET['act'] = preg_match('/^[\w]+$/i',$_GET['act']) ? $_GET['act'] : 'index';
+$_GET['op']  = preg_match('/^[\w]+$/i',$_GET['op']) ? $_GET['op'] : 'index';
+
+//对GET POST接收内容进行过滤,$ignore内的下标不被过滤
+$ignore = array('article_content','pgoods_body','doc_content','content','sn_content','g_body','store_description','p_content','groupbuy_intro','remind_content','note_content','ref_url','adv_pic_url','adv_word_url','adv_slide_url','appcode','mail_content');
+if (!class_exists('Security')) require(BASE_CORE_PATH.'/framework/libraries/security.php');
+$_GET = !empty($_GET) ? Security::getAddslashesForInput($_GET,$ignore) : array();
+$_POST = !empty($_POST) ? Security::getAddslashesForInput($_POST,$ignore) : array();
+$_REQUEST = !empty($_REQUEST) ? Security::getAddslashesForInput($_REQUEST,$ignore) : array();
+$_SERVER = !empty($_SERVER) ? Security::getAddSlashes($_SERVER) : array();
+
+//启用ZIP压缩
+if ($config['gzip'] == 1 && function_exists('ob_gzhandler') && $_GET['inajax'] != 1){
+	ob_start('ob_gzhandler');
+}else {
+	ob_start();
+}
+require_once(BASE_CORE_PATH.'/framework/libraries/queue.php');
+require_once(BASE_CORE_PATH.'/framework/function/core.php');
+require_once(BASE_CORE_PATH.'/framework/core/base.php');
+require_once(BASE_CORE_PATH.'/framework/function/goods.php');
+
+if(function_exists('spl_autoload_register')) {
+	spl_autoload_register(array('Base', 'autoload'));
+} else {
+	function __autoload($class) {
+		return Base::autoload($class);
+	}
+}
+?>

+ 155 - 0
core/framework/cache/cache.redis.php

@@ -0,0 +1,155 @@
+<?php
+/**
+ * redis 操作
+ */
+
+defined('InShopNC') or exit('Access Invalid!');
+
+class CacheRedis extends Cache {
+	private $config;
+	private $connected;
+	private $type;
+	private $prefix;
+    public function __construct() {
+    	$this->config = C('redis');
+    	if (empty($this->config['slave'])) $this->config['slave'] = $this->config['master'];
+    	$this->prefix = $this->config['prefix'] ? $this->config['prefix'] : substr(md5($_SERVER['HTTP_HOST']), 0, 6).'_';
+        if ( !extension_loaded('redis') ) {
+            throw_exception('redis failed to load');
+        }
+    }
+
+    private function init_master(){
+    	static $_cache;
+    	if (isset($_cache)){
+    		$this->handler = $_cache;
+    	}else{
+	        $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
+	        $this->handler  = new Redis;
+	        $this->enable = $this->handler->$func($this->config['master']['host'], $this->config['master']['port']);
+	        $_cache = $this->handler;
+            //$_cache->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
+    	}
+    }
+
+    private function init_slave(){
+    	static $_cache;
+    	if (isset($_cache)){
+    		$this->handler = $_cache;
+    	}else{
+	        $func = $this->config['pconnect'] ? 'pconnect' : 'connect';
+	        $this->handler = new Redis;
+	        $this->enable = $this->handler->$func($this->config['slave']['host'], $this->config['slave']['port']);
+	        $_cache = $this->handler;
+            //$_cache->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
+    	}
+    }
+
+    private function isConnected() {
+    	$this->init_master();
+        return $this->enable;
+    }
+
+	public function get($key, $type = ''){
+		$this->init_slave();
+		if (!$this->enable) return false;
+		$this->type = $type;
+		$value = $this->handler->get($this->_key($key));
+
+        return unserialize($value);
+	}
+
+    public function set($key, $value, $prefix = '', $expire = null) {
+    	$this->init_master();
+    	if (!$this->enable) return false;
+    	$this->type = $prefix;
+
+        $value = serialize($value);
+
+        if(is_int($expire)) {
+            $result = $this->handler->setex($this->_key($key), $expire, $value);
+        }else{
+            $result = $this->handler->set($this->_key($key), $value);
+        }
+        return $result;
+    }
+
+    public function hset($name, $prefix, $data) {
+        $this->init_master();
+        if (!$this->enable || !is_array($data) || empty($data)) return false;
+        $this->type = $prefix;
+        foreach ($data as $key => $value) {
+            if ($value[0] == 'exp') {
+                $value[1] = str_replace(' ', '', $value[1]);
+                preg_match('/^[A-Za-z_]+([+-]\d+(\.\d+)?)$/',$value[1],$matches);
+                if (is_numeric($matches[1])) {
+                    $this->hIncrBy($name, $prefix, $key, $matches[1]);
+                }
+                unset($data[$key]);
+            }
+        }
+        if (count($data) == 1) {
+            $this->handler->hset($this->_key($name), key($data),current($data));
+        } elseif (count($data) > 1) {
+            $this->handler->hMset($this->_key($name), $data);
+        }
+    }
+
+    public function hget($name, $prefix, $key = null) {
+        $this->init_slave();
+        if (!$this->enable) return false;
+        $this->type = $prefix;
+        if ($key == '*' || is_null($key)) {
+            return $this->handler->hGetAll($this->_key($name));
+        } elseif (strpos($key,',') != false) {
+            return $this->handler->hmGet($this->_key($name), explode(',',$key));
+        } else {
+            return $this->handler->hget($this->_key($name), $key);
+        }
+    }
+
+    public function hdel($name, $prefix, $key = null) {
+        $this->init_master();
+        if (!$this->enable) return false;
+        $this->type = $prefix;
+        if (is_null($key)) {
+            if (is_array($name)) {
+                return $this->handler->delete(array_walk($array,array(self,'_key')));
+            } else {
+                return $this->handler->delete($this->_key($name));
+            }
+        } else {
+            if (is_array($name)) {
+                foreach ($name as $key => $value) {
+                    $this->handler->hdel($this->_key($name), $key);
+                }
+                return true;
+            } else {
+                return $this->handler->hdel($this->_key($name), $key);
+            }
+        }
+    }
+
+    public function hIncrBy($name, $prefix, $key, $num = 1) {
+        if ($this->hget($name, $prefix,$key) !== false) {
+            $this->handler->hIncrByFloat($this->_key($name), $key, floatval($num));
+        }
+    }
+
+    public function rm($key, $type = '') {
+    	$this->init_master();
+    	if (!$this->enable) return false;
+    	$this->type = $type;
+        return $this->handler->delete($this->_key($key));
+    }
+
+    public function clear() {
+    	$this->init_master();
+    	if (!$this->enable) return false;
+        return $this->handler->flushDB();
+    }
+
+	private function _key($str) {
+		return $this->prefix.$this->type.$str;
+	}
+}

+ 3 - 2
core/framework/core/base.php

@@ -29,7 +29,8 @@ final class Base
 	    }
 
 	    //session start
-	    //self::start_session();	    
+	    self::start_session();
+	    
 	    //output to the template
             
 	    Tpl::output('setting_config',$setting_config);	    
@@ -73,7 +74,7 @@ final class Base
 
 		$nc_config['db']['master'] = $nc_config['db'][1];
 		$setting_config = $nc_config;
-		//$setting = ($setting = rkcache('setting')) ? $setting : rkcache('setting',true);
+		$setting = ($setting = rkcache('setting')) ? $setting : rkcache('setting',true);
 		$setting['shopnc_version'] = 'Copyright 2015</a>';
 		$setting_config = array_merge_recursive($setting,$nc_config);
 	}

+ 2 - 3
core/framework/libraries/cache.php

@@ -21,9 +21,8 @@ class Cache
 	public function connect($type,$args = array()){
 		if (empty($type)) $type = C('cache_open') ? 'redis' : 'file';
 		$type = strtolower($type);
-		//$class = 'Cache'.ucwords($type);
-        
-        $class = ucwords($type);
+		$class = ucwords($type);
+
 		if (!class_exists($class)){
 			import('cache.cache#'.$type);
 		}

+ 152 - 140
core/framework/libraries/tpl.php

@@ -7,156 +7,168 @@
  *
  * @package    tpl
  */
+defined('InShopNC') or exit('Access Invalid!');
 
+class Tpl
+{
+    /**
+     * 单件对象
+     */
+    private static $instance = null;
+    /**
+     * 输出模板内容的数组,其他的变量不允许从程序中直接输出到模板
+     */
+    private static $output_value = array();
+    /**
+     * 模板路径设置
+     */
+    private static $tpl_dir = '';
+    /**
+     * 默认layout
+     */
+    private static $layout_file = 'layout';
 
-defined('InShopNC') or exit('Access Invalid!');
-class Tpl{
-	/**
-	 * 单件对象
-	 */
-	private static $instance = null;
-	/**
-	 * 输出模板内容的数组,其他的变量不允许从程序中直接输出到模板
-	 */
-	private static $output_value = array();
-	/**
-	 * 模板路径设置
-	 */
-	private static $tpl_dir='';
-	/**
-	 * 默认layout
-	 */
-	private static $layout_file = 'layout';
-	
-	private function __construct(){}
-	
-	/**
-	 * 实例化
-	 *
-	 * @return obj
-	 */
-	public static function getInstance(){
-            
-		if (self::$instance === null || !(self::$instance instanceof Tpl)) {
-			//self::$instance = new Tpl();
-		}
-		//return self::$instance;
-	}
-	
-	/**
-	 * 设置模板目录
-	 *
-	 * @param string $dir
-	 * @return bool
-	 */
-	public static function setDir($dir){
-		self::$tpl_dir = $dir;
-		return true;
-	}
-	/**
-	 * 设置布局
-	 *
-	 * @param string $layout
-	 * @return bool
-	 */
-	public static function setLayout($layout){
-		self::$layout_file = $layout;
-		return true;
-	}
-	
-	/**
-	 * 抛出变量
-	 *
-	 * @param mixed $output
-	 * @param  void
-	 */
-	public static function output($output,$input=''){
-		self::getInstance();
-		
-		//self::$output_value[$output] = $input;
-	}
-	
-	/**
-	 * 调用显示模板
-	 *
-	 * @param string $page_name
-	 * @param string $layout
-	 * @param int $time
-	 */
-	public static function showpage($page_name='',$layout='',$time=2000){
-		if (!defined('TPL_NAME')) define('TPL_NAME','default');
-		self::getInstance();
-			if (!empty(self::$tpl_dir)){
-				$tpl_dir = self::$tpl_dir.DS;
-			}
-			//默认是带有布局文件
-			if (empty($layout)){
-				$layout = 'layout'.DS.self::$layout_file.'.php';
-			}else {
-				$layout = 'layout'.DS.$layout.'.php';
-			}
-			$layout_file = BASE_PATH.'/templates/'.TPL_NAME.DS.$layout;
-			$tpl_file = BASE_PATH.'/templates/'.TPL_NAME.DS.$tpl_dir.$page_name.'.php';
-			if (file_exists($tpl_file)){
-				//对模板变量进行赋值
-				$output = self::$output_value;
-				//页头
-				$output['html_title'] = $output['html_title']!='' ? $output['html_title'] :$GLOBALS['setting_config']['site_name'];
-				$output['seo_keywords'] = $output['seo_keywords']!='' ? $output['seo_keywords'] :$GLOBALS['setting_config']['site_name'];
-				$output['seo_description'] = $output['seo_description']!='' ? $output['seo_description'] :$GLOBALS['setting_config']['site_name'];
-				$output['ref_url'] = getReferer();
+    private function __construct()
+    {
+    }
+
+    /**
+     * 实例化
+     *
+     * @return obj
+     */
+    public static function getInstance()
+    {
+        if (self::$instance === null || !(self::$instance instanceof Tpl)) {
+            self::$instance = new Tpl();
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 设置模板目录
+     *
+     * @param string $dir
+     * @return bool
+     */
+    public static function setDir($dir)
+    {
+        self::$tpl_dir = $dir;
+        return true;
+    }
+
+    /**
+     * 设置布局
+     *
+     * @param string $layout
+     * @return bool
+     */
+    public static function setLayout($layout)
+    {
+        self::$layout_file = $layout;
+        return true;
+    }
+
+    /**
+     * 抛出变量
+     *
+     * @param mixed $output
+     * @param  void
+     */
+    public static function output($output, $input = '')
+    {
+        self::getInstance();
+        self::$output_value[$output] = $input;
+    }
+
+    /**
+     * 调用显示模板
+     *
+     * @param string $page_name
+     * @param string $layout
+     * @param int $time
+     */
+    public static function showpage($page_name = '', $layout = '', $time = 2000)
+    {
+        if (!defined('TPL_NAME')) define('TPL_NAME', 'default');
+        self::getInstance();
+        if (!empty(self::$tpl_dir)) {
+            $tpl_dir = self::$tpl_dir . DS;
+        }
 
-				Language::read('common');
-				$lang = Language::getLangContent();
+        //默认是带有布局文件
+        if (empty($layout)) {
+            $layout = 'layout' . DS . self::$layout_file . '.php';
+        } else {
+            $layout = 'layout' . DS . $layout . '.php';
+        }
+
+        $layout_file = BASE_PATH . '/templates/' . TPL_NAME . DS . $layout;
+        $tpl_file = BASE_PATH . '/templates/' . TPL_NAME . DS . $tpl_dir . $page_name . '.php';
+        if (file_exists($tpl_file))
+        {
+            //对模板变量进行赋值
+            $output = self::$output_value;
+            //页头
+            $output['html_title'] = $output['html_title'] != '' ? $output['html_title'] : $GLOBALS['setting_config']['site_name'];
+            $output['seo_keywords'] = $output['seo_keywords'] != '' ? $output['seo_keywords'] : $GLOBALS['setting_config']['site_name'];
+            $output['seo_description'] = $output['seo_description'] != '' ? $output['seo_description'] : $GLOBALS['setting_config']['site_name'];
+            $output['ref_url'] = getReferer();
+
+            Language::read('common');
+            $lang = Language::getLangContent();
+
+            @header("Content-type: text/html; charset=" . CHARSET);
+            //判断是否使用布局方式输出模板,如果是,那么包含布局文件,并且在布局文件中包含模板文件
+            if ($layout != '')
+            {
+                if (file_exists($layout_file)) {
+                    include_once($layout_file);
+                } else {
+                    $error = 'Tpl ERROR:' . 'templates' . DS . $layout . ' is not exists';
+                    throw_exception($error);
+                }
+            } else {
+                include_once($tpl_file);
+            }
+        } else {
+            $error = 'Tpl ERROR:' . 'templates' . DS . $tpl_dir . $page_name . '.php' . ' is not exists';
+            throw_exception($error);
+        }
+    }
 
-				@header("Content-type: text/html; charset=".CHARSET);
-				//判断是否使用布局方式输出模板,如果是,那么包含布局文件,并且在布局文件中包含模板文件
-				if ($layout != ''){
-					if (file_exists($layout_file)){
-						include_once($layout_file);
-					}else {
-						$error = 'Tpl ERROR:'.'templates'.DS.$layout.' is not exists';
-						throw_exception($error);
-					}
-				}else {
-					include_once($tpl_file);
-				}
-			}else {
-				$error = 'Tpl ERROR:'.'templates'.DS.$tpl_dir.$page_name.'.php'.' is not exists';
-				throw_exception($error);
-			}
-	}
-	/**
-	 * 显示页面Trace信息
-	 *
-	 * @return array
-	 */
-    public static function showTrace(){
-    	$trace = array();
-    	//当前页面
-		$trace[Language::get('nc_debug_current_page')] =  $_SERVER['REQUEST_URI'].'<br>';
-    	//请求时间
-        $trace[Language::get('nc_debug_request_time')] =  date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).'<br>';
+    /**
+     * 显示页面Trace信息
+     *
+     * @return array
+     */
+    public static function showTrace()
+    {
+        $trace = array();
+        //当前页面
+        $trace[Language::get('nc_debug_current_page')] = $_SERVER['REQUEST_URI'] . '<br>';
+        //请求时间
+        $trace[Language::get('nc_debug_request_time')] = date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . '<br>';
         //系统运行时间
-        $query_time = number_format((microtime(true)-StartTime),3).'s';
-        $trace[Language::get('nc_debug_execution_time')] = $query_time.'<br>';
-		//内存
-		$trace[Language::get('nc_debug_memory_consumption')] = number_format(memory_get_usage()/1024/1024,2).'MB'.'<br>';
-		//请求方法
-        $trace[Language::get('nc_debug_request_method')] = $_SERVER['REQUEST_METHOD'].'<br>';
+        $query_time = number_format((microtime(true) - StartTime), 3) . 's';
+        $trace[Language::get('nc_debug_execution_time')] = $query_time . '<br>';
+        //内存
+        $trace[Language::get('nc_debug_memory_consumption')] = number_format(memory_get_usage() / 1024 / 1024, 2) . 'MB' . '<br>';
+        //请求方法
+        $trace[Language::get('nc_debug_request_method')] = $_SERVER['REQUEST_METHOD'] . '<br>';
         //通信协议
-        $trace[Language::get('nc_debug_communication_protocol')] = $_SERVER['SERVER_PROTOCOL'].'<br>';
+        $trace[Language::get('nc_debug_communication_protocol')] = $_SERVER['SERVER_PROTOCOL'] . '<br>';
         //用户代理
-        $trace[Language::get('nc_debug_user_agent')] = $_SERVER['HTTP_USER_AGENT'].'<br>';
+        $trace[Language::get('nc_debug_user_agent')] = $_SERVER['HTTP_USER_AGENT'] . '<br>';
         //会话ID
-        $trace[Language::get('nc_debug_session_id')] = session_id().'<br>';
+        $trace[Language::get('nc_debug_session_id')] = session_id() . '<br>';
         //执行日志
-        $log    =   Log::read();
-        $trace[Language::get('nc_debug_logging')]  = count($log)?count($log).Language::get('nc_debug_logging_1').'<br/>'.implode('<br/>',$log):Language::get('nc_debug_logging_2');
-        $trace[Language::get('nc_debug_logging')] = $trace[Language::get('nc_debug_logging')].'<br>';
+        $log = Log::read();
+        $trace[Language::get('nc_debug_logging')] = count($log) ? count($log) . Language::get('nc_debug_logging_1') . '<br/>' . implode('<br/>', $log) : Language::get('nc_debug_logging_2');
+        $trace[Language::get('nc_debug_logging')] = $trace[Language::get('nc_debug_logging')] . '<br>';
         //文件加载
-		$files =  get_included_files();
-		$trace[Language::get('nc_debug_load_files')] = count($files).str_replace("\n",'<br/>',substr(substr(print_r($files,true),7),0,-2)).'<br>';
+        $files = get_included_files();
+        $trace[Language::get('nc_debug_load_files')] = count($files) . str_replace("\n", '<br/>', substr(substr(print_r($files, true), 7), 0, -2)) . '<br>';
         return $trace;
     }
 }

+ 2 - 1
core/framework/libraries/uploadfile.php

@@ -9,7 +9,8 @@
 
 
 defined('InShopNC') or exit('Access Invalid!');
-class UploadFile{
+class UploadFile
+{
 	/**
 	 * 文件存储路径
 	 */

+ 2 - 2
crontab/control/date.php

@@ -407,7 +407,7 @@ class dateControl extends BaseCronControl {
         $update['evaluation_state'] = 2;
         $update = $model_order->editOrder($update,$condition,1000);
         if (!$update) {
-            $this->log('更新实物订单超期不能评价失败'); return;
+            $this->log('更新实物订单超期不能评价失败');break;
         }
 
         //虚拟订单超期未评价自动更新状态,每次最多更新1000个订单
@@ -421,7 +421,7 @@ class dateControl extends BaseCronControl {
         $update['evaluation_state'] = 2;
         $update = $model_order->editOrder($update,$condition,1000);
         if (!$update) {
-            $this->log('更新虚拟订单超期不能评价失败'); return;
+            $this->log('更新虚拟订单超期不能评价失败');break;
         }
     }
 

+ 65 - 0
crontab/crawl/category.php

@@ -0,0 +1,65 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/3
+ * Time: 下午7:22
+ */
+
+class category
+{
+    private $model_cats;
+    private $model_class;
+    private $topcats = NULL;
+
+    public function __construct($topcats)
+    {
+        $this->model_cats = Model('item_cats');
+        $this->model_class = Model('goods_class');
+        $this->topcats = $topcats;
+    }
+
+    private function insert($catdatas)
+    {
+        foreach($catdatas as &$val) {
+            $item = array();
+            $item['gc_id'] = $val['cid'];
+            $item['gc_name'] = $val['name'];
+            $item['type_id'] = 37;
+            $item['type_name'] = '';
+            $item['gc_parent_id'] = $val['parent_cid'];
+            $item['commis_rate'] = 0;
+            $item['gc_sort'] = $val['sort_order'];
+            $item['gc_virtual'] = 0;
+
+            $this->model_class->insert($item);
+            $cids[] = (int)$val['cid'];
+        }
+
+        return $cids;
+    }
+
+    private function insert_all($pcids)
+    {
+        if(empty($pcids)) return;
+
+        foreach ($pcids as $pcid) {
+            $datas = $this->model_cats->field('*')->limit(false)->where(array('parent_cid'=> $pcid))->select();
+            $cids = $this->insert($datas);
+
+            $this->insert_all($cids);
+        }
+    }
+
+    public function proc()
+    {
+        if(empty($this->topcats)) return;
+
+        foreach ($this->topcats as $cid) {
+            $datas = $this->model_cats->field('*')->limit(false)->where(array('cid'=>$cid,'parent_cid'=> 0))->select();
+            $this->insert($datas);
+        }
+
+        $this->insert_all($this->topcats);
+    }
+}

+ 108 - 0
crontab/crawl/class_tree.php

@@ -0,0 +1,108 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/4
+ * Time: 下午5:39
+ */
+class class_tree
+{
+    private $group_class;
+
+    public function __construct()
+    {
+        $this->group_class = $this->load_all();
+
+    }
+
+    public function get_info($cid,&$c_1,&$c_2,&$c_3,&$name)
+    {
+        $c_3 =0;
+        $c_1 = 0;
+        $c_2 = 0;
+
+        $info = $this->group_class[$cid];
+        $name = $info['gc_name'];
+
+        do {
+            $deep = (int)$info['deep'];
+            switch($deep)
+            {
+                case 1: {
+                    $c_1 = $cid;
+                    $n_1 = $info['gc_name'];
+                    break;
+                }
+                case 2: {
+                    $c_2 = $cid;
+                    $n_2 = $info['gc_name'];
+                    break;
+                }
+                case 3: {
+                    $c_3 = $cid;
+                    $n_3 = $info['gc_name'];
+                    break;
+                }
+            }
+            $cid = $info['gc_parent_id'];
+            $info = $this->group_class[$cid];
+        } while($deep > 0);
+    }
+
+    private function write_deep(&$alldata,&$childs,$deep)
+    {
+        if(empty($childs)) return;
+
+        foreach($childs as $cid) {
+            $alldata[$cid]['deep'] = $deep;
+
+            $childex = &$alldata[$cid]['child'];
+            $this->write_deep($alldata, $childex, $deep + 1);
+        }
+    }
+
+    /**
+     * 取分类列表,最多为三级
+     *
+     * @param int $show_deep 显示深度
+     * @param array $condition 检索条件
+     * @return array 数组类型的返回结果
+     */
+    private function load_all()
+    {
+        $mod_cats = Model('goods_class');
+        $class_list = $mod_cats->field('*')->order('gc_parent_id asc,gc_sort asc,gc_id asc')->limit(false)->select();
+
+        $group_class = array();
+        foreach($class_list as $val)
+        {
+            $key = (int)$val['gc_id'];
+            if(empty($group_class[$key])) {
+                $group_class[$key] = $val;
+                $group_class[$key]['child'] = array();
+            }
+        }
+
+        if(empty($group_class[0])) {
+            $group_class[0] = array();
+            $group_class[0]['child'] = array();
+        }
+
+        foreach($class_list as $val)
+        {
+            $cid = (int)$val['gc_id'];
+            $pcid = (int)$val['gc_parent_id'];
+            if($cid == $pcid) continue;
+
+            $parent = &$group_class[$pcid];
+            if (!empty($parent)) {
+                array_push($parent['child'],$cid);
+            }
+        }
+
+        $this->write_deep($group_class,$group_class[0]['child'],1);
+        return $group_class;
+    }
+
+}

+ 54 - 209
crontab/crawl/fetch_goods.php

@@ -1,218 +1,63 @@
 <?php
 
-/*
-* 生成sqe
-* 生成规则:
- 加密的当前时间戳(精确到秒)+4位随机数 18位数字(yyyymmddhhmmss+rrrr)
- 加密算法为 字符串反向 后 各偶数位x=9-x
- 2015-0106-010203-1234
- ->4[3]2[1]3[0]2[0]1[0]6[0]1[0]5[1]0[2]
- ->5[3]7[1]6[0]7[0]8[0]3[0]8[0]4[1]9[2]
-*/
-
-require_once (BASE_CORE_PATH . '/framework/function/http.php');
-require_once (BASE_CRONTAB_PATH . '/transport_data.php');
-
-function init_sqe()
-{	
-    date_default_timezone_set('Etc/GMT-8');
-	$d =  date('YmdHis',time());
-	$r = rand(1000,9999); 
-	$str = strrev($d.$r);
-	$str2 = "";
-	for ($i=0; $i < strlen($str); $i++)
-	{ 
-		if($i % 2 == 0) {
- 			$str2 = $str2.(intval(9-$str[$i]));
-		} else {
-			$str2 = $str2.$str[$i];
-		}
-	}
-	return $str2;
-}
-
-class page_req
-{
-    private $total = '10';
-    private $leftcount;
-    private $dispatch = NULL;
-    
-    private $items = array();
-   
-    static private $page_url = 'http://crm-api.lrlz.com/api_app/api_main.py';
-    static private $page_method = 'api.info.item.list';
-    static private $item_method = 'api.info.item.get';
-    public function __construct()
-    {
-        $this->dispatch = new ModelOperator;
-    }
-    
-    public function proc_page($shopname,$date,$method)
-    {
-        $curpage = 1;
-        $pagesize = 10;
-        
-        do
-        {
-            $params = array('seq' => init_sqe(), 
-                'method' => page_req::$page_method, 
-                'page' => $curpage, 
-                'pagesize' => $pagesize,
-                'nick' => $shopname,
-                'jdp_modified' => $date);
-        
-            $resp = http_request(page_req::$page_url,$params);
-            if(empty($resp)) {
-                break;
-            } 
-            
-            $data = $this->parse_page($resp);
-            if(empty($data)) {
-                break;
-            } 
-            
-            $curpage += 1;
-            $this->leftcount -= count($data);
-            
-            foreach ($data as $num_iid) {
-                echo "$num_iid\r\n";
-                $body = $this->req_item($num_iid);
-                $this->dispatch->$method($num_iid,$body);
-            }
-              
-        } while($this->leftcount > 0);       
-    }
-
-    private function req_item($num_iid)
-    {
-    	$params = array('seq' => init_sqe(), 
-    	                'method' => page_req::$item_method, 
-    	                'num_iid' => $num_iid);
-    	$resp = http_request(page_req::$page_url,$params);
-        $str = iconv("gbk","utf-8",$resp);
-
-    	return $str;
-    }
-
-    private function parse_page($body)
-    {
-        $data = json_decode($body, true);    
-
-    	if($data['success']=="true")
-    	{
-    		$this->total = intval(trim($data['total']));
-            $this->curpage = intval(trim($data["page"]));
-            
-            if(!isset($this->leftcount)) {
-                $this->leftcount = $this->total;
-            }
-            
-    		$infos = $data["info"];
-    		$count = count($infos);
-            
-            $items = array();
-    		for ($i = 0; $i < $count; $i++) {
-                $num_iid = $infos[$i]['num_iid'];
-                array_push($items, $num_iid);
-    		}
-            return $items;
-    	}else{
-    		return NULL;
-    	}
-    }
-}
-
-
-require_once (BASE_DATA_PATH . '/api/taobao/TopClient.php');
-require_once (BASE_DATA_PATH . '/api/taobao/RequestCheckUtil.php');
-require_once (BASE_DATA_PATH . '/api/taobao/request/ItemcatsGetRequest.php');
-
-function get_cid($cid)
-{
-    $c = new TopClient;
-    $req = new ItemcatsGetRequest;
-    $req->setParentCid($cid);
-    //$req->setCids("18957,19562");//($cid);
-    //$req->setDatetime("2000-01-01 00:00:00");
-    $req->setFields("cid,parent_cid,name,is_parent");
-    //$req->setParentCid("50011999");
-    //$resp = $c->execute($req,'6102a03eb7d1a82c0b6f37705ca98d2dbe9df7045dd658190919986');
-    $resp = $c->execute($req,'61006189f905270ab4529ae83e119789649cff4050a1d87820445294');
-}
-
-
-//import catories
-
-class category
-{
-    private $model_cats;
-    private $model_class;
-    private $topcats = NULL;
-
-    public function __construct($topcats)
-    {
-        $this->model_cats = Model('item_cats');
-        $this->model_class = Model('goods_class');
-        $this->topcats = $topcats;
-    }
-
-    private function insert($catdatas)
-    {
-        foreach($catdatas as &$val) {
-            $item = array();
-            $item['gc_id'] = $val['cid'];
-            $item['gc_name'] = $val['name'];
-            $item['type_id'] = 37;
-            $item['type_name'] = '';
-            $item['gc_parent_id'] = $val['parent_cid'];
-            $item['commis_rate'] = 0;
-            $item['gc_sort'] = $val['sort_order'];
-            $item['gc_virtual'] = 0;
-
-            $this->model_class->insert($item);
-            $cids[] = (int)$val['cid'];
-        }
-
-        return $cids;
-    }
-
-    private function insert_all($pcids)
-    {
-        if(empty($pcids)) return;
-
-        foreach ($pcids as $pcid) {
-            $datas = $this->model_cats->field('*')->limit(false)->where(array('parent_cid'=> $pcid))->select();
-            $cids = $this->insert($datas);
-
-            $this->insert_all($cids);
-        }
-    }
-
-    public function proc()
-    {
-        if(empty($this->topcats)) return;
-
-        foreach ($this->topcats as $cid) {
-            $datas = $this->model_cats->field('*')->limit(false)->where(array('cid'=>$cid,'parent_cid'=> 0))->select();
-            $this->insert($datas);
-        }
-
-        $this->insert_all($this->topcats);
-    }
-}
+require_once (BASE_DATA_PATH . '/api/taobao/TopSdk.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/product_importer.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/category.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/tmrequest.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/page_request.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/class_tree.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/pretreat_tmdata.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/spec_attr.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/upload_file.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/upload_control.php');
+
+require_once (BASE_CORE_PATH . '/framework/libraries/uploadfile.php');
+
+
+date_default_timezone_set('Asia/Shanghai');
+
 
 //$cat = new category(array(1801,50010788,50023282));
 //$cat->proc();
 
-//$req = new page_req;
-//$date = "2015-10-15";
-//$req->proc_page("丽人丽妆官方旗舰店",$date,'spec');
+//$modoper->import_goods();
+
+//get_tmdata();
+//handle_db();
+
+//$tmreq = new tmrequest();
+//$tmreq->proc();
+
+//get_tmdata();
+//$treater = new pretreat_tmdata();
+//$treater->proc();
+
+//$spec = new spec_attr();
+//$spec->proc();
+
+$importer = new product_importer();
+$importer->proc();
+
+
+//function upload_image($file)
+//{
+//    $pic_name = '';
+//    $upload = new UploadFile();
+//    $uploaddir = ATTACH_PATH.DS.'store_joinin'.DS;
+//    $upload->set('default_dir',$uploaddir);
+//    $upload->set('allow_type',array('jpg','jpeg','gif','png'));
+//    if (!empty($_FILES[$file]['name'])){
+//        $result = $upload->upfile($file);
+//        if ($result){
+//            $pic_name = $upload->file_name;
+//            $upload->file_name = '';
+//        }
+//    }
+//    return $pic_name;
+//}
+//
+//
+//upload_image(BASE_DATHD_PATH . '/Download/0a006a315a99f917a56bf7c56d18ead1.jpg');
 
-$specex = new ModelOperator;
-$specex->genspec();
 
-echo microtime();
-$specex->add_attribute();
 
-echo "     ";
-echo microtime();

+ 125 - 0
crontab/crawl/page_request.php

@@ -0,0 +1,125 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/3
+ * Time: 下午7:31
+ * 从杭州那边同步获取数据,
+ */
+
+require_once (BASE_CORE_PATH . '/framework/function/http.php');
+class page_req
+{
+    private $total = '10';
+    private $leftcount;
+    private $dispatch = NULL;
+
+    static private $page_url = 'http://crm-api.lrlz.com/api_app/api_main.py';
+    static private $page_method = 'api.info.item.list';
+    static private $item_method = 'api.info.item.get';
+
+    public function __construct() {
+        $this->dispatch = new pretreat_tmdata();
+    }
+
+    public function proc_page($shopname,$date,$method)
+    {
+        $curpage = 1;
+        $pagesize = 10;
+
+        do
+        {
+            $params = array('seq' => $this->init_sqe(),
+                'method' => page_req::$page_method,
+                'page' => $curpage,
+                'pagesize' => $pagesize,
+                'nick' => $shopname,
+                'jdp_modified' => $date);
+
+            $resp = http_request(page_req::$page_url,$params);
+            if(empty($resp)) {
+                break;
+            }
+
+            $data = $this->parse_page($resp);
+            if(empty($data)) {
+                break;
+            }
+
+            $curpage += 1;
+            $this->leftcount -= count($data);
+
+            foreach ($data as $num_iid) {
+                echo "$num_iid\r\n";
+                $body = $this->req_item($num_iid);
+                $this->dispatch->$method($body);
+            }
+
+        } while($this->leftcount > 0);
+    }
+
+    private function req_item($num_iid)
+    {
+        $params = array('seq' => $this->init_sqe(),
+            'method' => page_req::$item_method,
+            'num_iid' => $num_iid);
+        $resp = http_request(page_req::$page_url,$params);
+        $str = iconv("gbk","utf-8",$resp);
+
+        return $str;
+    }
+
+    private function parse_page($body)
+    {
+        $data = json_decode($body, true);
+
+        if($data['success']=="true")
+        {
+            $this->total = intval(trim($data['total']));
+            $this->curpage = intval(trim($data["page"]));
+
+            if(!isset($this->leftcount)) {
+                $this->leftcount = $this->total;
+            }
+
+            $infos = $data["info"];
+            $count = count($infos);
+
+            $items = array();
+            for ($i = 0; $i < $count; $i++) {
+                $num_iid = $infos[$i]['num_iid'];
+                array_push($items, $num_iid);
+            }
+            return $items;
+        }else{
+            return NULL;
+        }
+    }
+
+    /*
+    * 生成sqe
+    * 生成规则:
+     加密的当前时间戳(精确到秒)+4位随机数 18位数字(yyyymmddhhmmss+rrrr)
+     加密算法为 字符串反向 后 各偶数位x=9-x
+     2015-0106-010203-1234
+     ->4[3]2[1]3[0]2[0]1[0]6[0]1[0]5[1]0[2]
+     ->5[3]7[1]6[0]7[0]8[0]3[0]8[0]4[1]9[2]
+    */
+    private function init_sqe()
+    {
+        date_default_timezone_set('Etc/GMT-8');
+        $d =  date('YmdHis',time());
+        $r = rand(1000,9999);
+        $str = strrev($d.$r);
+        $str2 = "";
+        for ($i=0; $i < strlen($str); $i++)
+        {
+            if($i % 2 == 0) {
+                $str2 = $str2.(intval(9-$str[$i]));
+            } else {
+                $str2 = $str2.$str[$i];
+            }
+        }
+        return $str2;
+    }
+}

+ 204 - 0
crontab/crawl/pretreat_tmdata.php

@@ -0,0 +1,204 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/6
+ * Time: 下午9:52
+ */
+
+class pretreat_tmdata
+{
+    private $tm_goods;
+    private $tm_spec;
+    private $tm_props;
+    private $tm_prop_values;
+    private $goods_class;
+
+    public function __construct()
+    {
+        $this->tm_goods = Model('tm_goods');
+        $this->tm_spec = Model('tm_spec');
+        $this->tm_props = Model('tm_props');
+        $this->tm_prop_values = Model('tm_prop_values');
+        $this->goods_class = Model('goods_class');
+    }
+
+    public function proc()
+    {
+        $results = $this->tm_goods->field('body,title,num_iid')->where(array('num_iid' => 14454708036))->limit(false)->select();
+        foreach ($results as $result) {
+            $body = $result['body'];
+            $response = json_decode($body, true);
+            $item = $response['item_seller_get_response']['item'];
+            //$this->parse_tm_product($item);
+            $this->parse_tm_pic($item);
+        }
+    }
+
+    private function parse_propnames($propnames)
+    {
+        $spec_vals = preg_split("/[;]+/", $propnames);
+
+        $ret = array();
+        foreach($spec_vals as $sv)
+        {
+            $data = preg_split("/[:]+/", $sv);
+            if(!empty($data)) {
+                $tmpid = $data[0];
+                $tmpvid = $data[1];
+                $tmpname = $data[2];
+                $tmvname = $data[3];
+
+                $ret[$tmpid]['name'] = $tmpname;
+                $ret[$tmpid]['val'][$tmpvid] = $tmvname;
+            }
+        }
+        return $ret;
+    }
+
+    //根据cid 和 pid 取到规格名称。
+    private function get_tm_props_name($cid,$pid)
+    {
+        $item = $this->tm_props->where(array('cid' => $cid,'pid' => $pid))->limit(false)->select();
+        if(empty($item)) {
+            return NULL;
+        } else {
+            return $item[0]['name'];
+        }
+    }
+
+    private function get_prop_value_name($cid,$pid,$vid)
+    {
+        $items = $this->tm_prop_values->where(array('cid' => $cid,'pid' => $pid,'vid' => $vid))->limit(false)->select();
+        if(empty($items)) {
+            return NULL;
+        } else {
+            return $items[0]['name'];
+        }
+    }
+
+    private function add_props($cid,$prposname)
+    {
+        $prop_names = $this->parse_propnames($prposname);
+        foreach($prop_names as $key => $arval)
+        {
+            $pid = $key;
+            $pname = $this->get_tm_props_name($cid,$pid);
+            if(empty($pname)) {
+                $pname = $arval['name'];
+            }
+            foreach($arval['val'] as $vid => $vname)
+            {
+                $name = $this->get_prop_value_name($cid,$pid,$vid);
+                if(empty($name)) {
+                    $this->tm_prop_values->insert(array('cid' => $cid,'vid' => $vid, 'pid' => $pid, 'name' => $vname));
+                }
+            }
+        }
+    }
+
+    private function get_class_name($cid)
+    {
+        $ret = $this->goods_class->field('gc_name')->where(array('gc_id' => $cid))->find();
+        return $ret['gc_name'];
+    }
+
+
+    private function download($url)
+    {
+        $info = pathinfo($url);
+        $name = md5($url) . '.' . $info['extension'];
+
+        $path = BASE_DATA_PATH . '/Download';
+        $path = $path . '/' . $name;
+        if(!file_exists($path)) {
+            $pic_url = $info['dirname'] . '/' . urlencode($info['basename']);
+            exec("wget -O $path $pic_url");
+        }
+    }
+
+    private function parse_tm_pic($item)
+    {
+        $pics = array();
+        $main_pic = $item['pic_url'];
+        if(!empty($main_pic)) {
+            array_push($pics,$main_pic);
+        }
+
+        $item_imgs = $item['item_imgs'];
+        $item_img = $item_imgs['item_img'];
+
+        foreach ($item_img as $img) {
+            $url = $img['url'];
+            array_push($pics,$url);
+        }
+
+        foreach($pics as $pic) {
+            $this->download($pic);
+        }
+    }
+
+    private function parse_tm_product($item)
+    {
+        $cid = $item['cid'];
+        $num_iid = $item['num_iid'];
+        $title = $item['title'];
+        $outer_id = $item['outer_id'];
+        $sku_id = $item['sku_id'];
+        $this->add_props($cid,$item['props_name']);
+
+        $skus = $item['skus'];
+        if(empty($skus))
+        {
+            $val = array();
+            $val['cid'] = $cid;
+            $val['num_iid'] = $num_iid;
+            $val['sku_id'] = $sku_id;
+            $val['outer_id'] = $outer_id;
+            $val['title'] = $title;
+            $val['class_name'] = $this->get_class_name($cid);
+            $val['detail_url'] = $item['detail_url'];
+            $this->tm_spec->insert($val);
+        }
+        else
+        {
+            foreach ($skus as $skuex)
+            {
+                foreach ($skuex as $sku)
+                {
+                    $val = array();
+                    $val['cid'] = $cid;
+                    $val['num_iid'] = $num_iid;
+                    $val['props_val_name'] = $sku['properties_name'];
+
+                    $val['sku_id'] = empty($sku['sku_id']) ? $sku_id : $sku['sku_id'];
+                    $val['outer_id'] = empty($sku['outer_id']) ? $item['outer_id'] : $sku['outer_id'];
+
+                    //$props = $this->parse_props($sku['properties']);
+                    $prop_names = $this->parse_propnames($sku['properties_name']);
+                    foreach($prop_names as $key => $arval)
+                    {
+                        $pid = $key;
+                        $pname = $this->get_tm_props_name($cid,$pid);
+
+                        foreach($arval['val'] as $vid => $vname)
+                        {
+                            $name = $this->get_prop_value_name($cid,$pid,$vid);
+                            if(empty($name)) {
+                                $this->tm_prop_values->insert(array('cid' => $cid,'vid' => $vid, 'pid' => $pid, 'name' => $vname));
+                            }
+                        }
+                    }
+                    $val['sp_name'] = $pname;
+                    $val['props'] = $pid;
+                    $val['props_val'] = $vid;
+                    $val['title'] = $title;
+                    $val['class_name'] = $this->get_class_name($cid);
+                    $val['detail_url'] = $item['detail_url'];
+
+                    $this->tm_spec->insert($val);
+                }
+            }
+        }
+    }
+}

+ 427 - 0
crontab/crawl/product_importer.php

@@ -0,0 +1,427 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/2
+ * Time: 下午2:59
+ */
+
+require_once(BASE_DATA_PATH . '/model/goods.model.php');
+
+class product_importer
+{
+    private $tm_goods;
+    private $mod_spec;
+    private $mod_spec_value;
+
+    private $mod_type_spec;
+    private $tm_spvid_tpvid; //spec value id => tmall props vid
+
+    private $mod_attribute;
+    private $tm_cpid_attrid;
+    private $mod_attribute_value;
+    private $tm_tvid_attrvid;
+
+    private $mod_goods_common;
+    private $mod_goods;
+    private $mod_goods_images;
+
+    private $cls_tree;
+    private $down_path;
+
+    const store_name = "美宝莲";
+    const store_id = 1;
+
+    public function __construct()
+    {
+        $this->tm_goods = Model('tm_goods');
+
+        $this->mod_spec = Model('spec');
+        $this->mod_good_class = Model('goods_class');
+        $this->mod_spec_value = Model('spec_value');
+
+        $this->mod_type = Model('type');
+        $this->mod_type_spec = Model('type_spec');
+        $this->tm_spvid_tpvid = Model('tm_spvid_tpvid');
+
+        $this->mod_attribute = Model('attribute');
+        $this->tm_cpid_attrid = Model('tm_cpid_attrid');
+        $this->mod_attribute_value = Model('attribute_value');
+        $this->tm_tvid_attrvid = Model('tm_tvid_attrvid');
+        $this->mod_goods_images = Model('goods_images');
+
+        $this->mod_goods = new goodsModel();
+        $this->mod_goods_common = Model('goods_common');
+        $this->cls_tree = new class_tree();
+
+        $this->down_path = BASE_DATA_PATH . '/Download';
+    }
+
+    private function get_tmgoods()
+    {
+        //->where(array('num_iid' => 14454708036))
+        $bodys = $this->tm_goods->field('body,description')->limit(false)->order('num_iid')->select();
+        $result = array();
+
+        foreach($bodys as $body) {
+            $item = json_decode($body['body'],true);
+            $product = array();
+            $product['body'] = $item['item_seller_get_response']['item'];
+            $product['desc'] = $body['description'];
+
+            array_push($result,$product);
+        }
+
+        return $result;
+    }
+
+    private function fill_class($cid,&$general,&$name)
+    {
+        $this->cls_tree->get_info($cid,$cid_1,$cid_2,$cid_3,$name);
+        $general['gc_id'] = $cid;
+        $general['gc_id_1'] = $cid_1;
+        $general['gc_id_2'] = $cid_2;
+        $general['gc_id_3'] = $cid_3;
+    }
+
+    private function  get_sp_name($sp_id)
+    {
+        $items = $this->mod_spec->where(array('sp_id' => $sp_id))->limit(false)->select();
+        foreach($items as $item) {
+            $name = $item['sp_name'];
+            return $name;
+        }
+
+        return '';
+    }
+
+    private function get_specar($typeid)
+    {
+        $items = $this->mod_type_spec->where(array("type_id" => $typeid))->limit(false)->select();
+
+        $ret = array();
+        foreach($items as $item)
+        {
+            $sp_id = $item['sp_id'];
+            $sp_name = $this->get_sp_name($sp_id);
+            $ret[$sp_id] = $sp_name;
+        }
+
+        return $ret;
+    }
+
+    private function get_spec_name($sp_id)
+    {
+        $items = $this->mod_spec->field('sp_name')->where(array('sp_id' => $sp_id))->limit(false)->select();
+        if(empty($items)) {
+            return '';
+        } else {
+            return $items[0]['sp_name'];
+        }
+    }
+
+    /**
+     * @param $spid
+     * @param $spvid
+     * @return mixed
+     */
+    private function get_specval_name($spid, $spvid)
+    {
+        $items = $this->mod_spec_value->field('sp_value_name')->where(array('sp_id' => $spid, 'sp_value_id' => $spvid))->limit(false)->select();
+        if(empty($items)) {
+            return '';
+        } else {
+            return $items[0]['sp_value_name'];
+        }
+    }
+
+    private function get_spvid($cid,$pid,$vid)
+    {
+        $items = $this->tm_spvid_tpvid->field('spvid')->where(array('tpcid' => $cid,'tppid' => $pid,'tpvid' => $vid))->limit(false)->select();
+        if(empty($items)) {
+            return '';
+        } else {
+            return $items[0]['spvid'];
+        }
+    }
+
+    private function get_attrid($cid,$pid)
+    {
+        $items = $this->tm_cpid_attrid->field('attr_id')->where(array('cid' => $cid,'pid' => $pid))->limit(false)->select();
+        if(empty($items)) {
+            return '';
+        } else {
+            return $items[0]['attr_id'];
+        }
+    }
+
+    private function get_attrvid($cid,$pid,$vid)
+    {
+        $items = $this->tm_tvid_attrvid->field('attr_vid')->where(array('tcid' => $cid,'tpid' => $pid,'tvid' => $vid))->limit(false)->select();
+        if(empty($items)) {
+            return '';
+        } else {
+            return $items[0]['attr_vid'];
+        }
+    }
+
+    private function parse_sku_properties($cid,$props,&$spec_name,&$spec_val)
+    {
+        $spec_vals = preg_split("/[;]+/", $props);
+
+        foreach($spec_vals as $sv)
+        {
+            $data = preg_split("/[:]+/", $sv);
+            if(!empty($data)) {
+                $tmpid = $data[0];
+                $tmpvid = $data[1];
+
+                $spvid = $this->get_spvid($cid,$tmpid,$tmpvid);
+
+                $spid = $tmpid;
+                $sp_name = $this->get_spec_name($spid);
+                $spval_name = $this->get_specval_name($spid, $spvid);
+
+                $spec_val[$spid][$spvid] = $spval_name;
+                $spec_name[$spid] = $sp_name;
+            }
+        }
+    }
+
+    private function get_attr_name($attrid)
+    {
+        $items = $this->mod_attribute->table('attribute')->field('attr_name')->where(array('attr_id' => $attrid))->limit(false)->select();
+        if(empty($items)) {
+            return NULL;
+        } else {
+            return $items[0]['attr_name'];
+        }
+    }
+
+    private function get_attr_vname($typeid,$attrid,$attrvid)
+    {
+        $items = $this->mod_attribute_value->table('attribute_value')->field('attr_value_name')->where(array('attr_id' => $attrid,'type_id' => $typeid,'attr_value_id' => $attrvid))->limit(false)->select();
+        if(empty($items)) {
+            return NULL;
+        } else {
+            return $items[0]['attr_value_name'];
+        }
+    }
+
+    private function get_common_attr($cid,$props)
+    {
+        $ar_attr= array();
+
+        $spec_vals = preg_split("/[;]+/", $props);
+        foreach($spec_vals as $sv)
+        {
+            $data = preg_split("/[:]+/", $sv);
+            if(!empty($data)) {
+                $tmpid = $data[0];
+                $tmvid = $data[1];
+
+                $attr_id = $this->get_attrid($cid,$tmpid);
+                $attr_name = $this->get_attr_name($attr_id);
+                $ar_attr[$attr_id]['name'] = $attr_name;
+
+                $attr_vid = $this->get_attrvid($cid,$tmpid,$tmvid);
+
+                $type_id = $cid;
+
+                $attr_vname = $this->get_attr_vname($type_id,$attr_id,$attr_vid);
+                $ar_attr[$attr_id][$attr_vid] = $attr_vname;
+            }
+        }
+
+        return serialize($ar_attr);
+    }
+
+    private function get_common_spec_nameval($cid,$skus,&$spec_name,&$spec_val)
+    {
+        $ar_spec_name = array();
+        $ar_spec_val = array();
+
+        foreach($skus as $skuex)
+        {
+            foreach($skuex as $sku) {
+                $properties = $sku['properties'];
+                $this->parse_sku_properties($cid,$properties,$ar_spec_name,$ar_spec_val);
+            }
+        }
+
+        $spec_name = serialize($ar_spec_name);
+        $spec_val = serialize($ar_spec_val);
+    }
+
+    private function get_goods_spec($cid,$properties,&$goods_spec)
+    {
+        $ar_spec_name = array();
+        $ar_spec_val = array();
+
+        $this->parse_sku_properties($cid,$properties,$ar_spec_name,$ar_spec_val);
+
+        $goods_spec = serialize($ar_spec_name);
+        $spec_val = serialize($ar_spec_val);
+    }
+
+    private function fill_general($cid,$item, &$general,&$name)
+    {
+        $this->fill_class($cid, $general,$name);
+
+        $general['store_id'] = self::store_id;
+        $general['store_name'] = self::store_name;
+        $general['goods_name'] = $item['title'];
+        $general['goods_jingle'] = empty($item['sell_point']) ? '' : $item['sell_point'];
+        $general['goods_price'] = $item['price'];
+        $general['goods_image'] = $item['pic_url'];
+        $general['goods_state'] = 1;
+        $general['goods_verify'] = 1;
+        $general['goods_commend'] = strtolower($item['has_showcase']) ? 1 : 0;
+        $general['goods_vat'] = strtolower($item['has_invoice']) ? 1 : 0;
+        $general['is_virtual'] = strtolower($item['is_virtual']) ? 1 : 0;
+        $general['store_name'] = $item['nick'];
+        $general['goods_serial'] = $item['outer_id'];
+        $general['goods_addtime'] = $item['created'];
+    }
+
+    private function upload_img($file)
+    {
+        $pic_name = '';
+        $upload = new upload_file();
+        $uploaddir = ATTACH_PATH.DS.'store_joinin'.DS;
+        $upload->set('default_dir',$uploaddir);
+        $upload->set('allow_type',array('jpg','jpeg','gif','png'));
+        if (!empty($_FILES[$file]['name'])){
+            $result = $upload->upfile($file);
+            if ($result){
+                $pic_name = $upload->file_name;
+                $upload->file_name = '';
+            }
+        }
+        return $pic_name;
+    }
+
+    private function reset_imgs($imges)
+    {
+        if(empty($imges)) return '';
+
+        $ret = array();
+
+        foreach($imges as $img) {
+            $ret[$img['position']]['url'] = $img['url'];
+        }
+
+        return $ret;
+    }
+
+    private function upload_imges(&$imges,$storeid)
+    {
+        foreach($imges as &$img)
+        {
+            $url = $img['url'];
+            $info = pathinfo($url);
+            $src_name = $this->down_path . '/' . md5($url) . '.' . $info['extension'];
+            $upctl = new upload_control();
+            $upctl->set_store($storeid);
+            $up_name = $upctl->upload_img($src_name);
+            $img['upname'] = $up_name;
+        }
+    }
+
+    private function import_item($item,$desc)
+    {
+        $cid = $item['cid'];
+
+        $general = array();
+        $this->fill_general($cid,$item,$general,$name);
+
+
+        //属于SKU 信息中
+        $skus = &$item['skus'];
+        $typeid = $cid;
+        $goods_common = $general;
+        {
+            $goods_common['type_id'] = $typeid;
+            $goods_common['goods_body'] = $desc;
+            $goods_common['mobile_body'] = $desc;
+            $goods_common['gc_name'] = $name;
+            $goods_common['goods_selltime'] = $item['list_time'];
+            $goods_common['goods_costprice'] = $item['price'];
+            $goods_common['goods_attr'] = $this->get_common_attr($cid,$item['props']);
+
+            if(empty($skus)) {
+                $spec_name = 'N';
+            } else {
+                $this->get_common_spec_nameval($cid,$skus,$spec_name,$spec_val);
+            }
+
+            $goods_common['spec_name'] = $spec_name;
+            $goods_common['spec_value'] = $spec_val;
+
+            $common_id = $this->mod_goods->addGoodsCommon($goods_common);
+            $imgs = $this->reset_imgs($item['item_imgs']['item_img']);
+            $this->upload_imges($imgs,1);
+
+            foreach($imgs as $pos => $img)
+            {
+                $upname = $img['upname'];
+                if(empty($main_pic)) {
+                    $main_pic = $upname;
+                    $default = 1;
+                } else {
+                    $default = 0;
+                }
+
+                $this->mod_goods_images->insert(array('goods_commonid' => $common_id,'store_id' => self::store_id,'goods_image' => $upname,'goods_image_sort' => $pos,'is_default' => $default));
+            }
+
+            $this->mod_goods_common->where(array('goods_commonid' => $common_id))->update(array('goods_image' => $main_pic));
+        }
+
+        if(empty($skus))
+        {
+            $goods = $general;
+
+            $goods['goods_edittime'] = $item['modified'];
+            $goods['goods_serial'] = $item['outer_id'];
+            $goods['goods_price'] = $item['price'];
+            $goods['goods_addtime'] = $item['created'];
+            $goods['goods_storage'] = $item['quantity'];
+            $goods['goods_commonid'] = $common_id;
+
+            $goods['goods_spec'] = 'N';
+            $goods['goods_image'] = $main_pic;
+
+            $this->mod_goods->addGoods($goods);
+        }
+        else
+        {
+            foreach($skus as $skuex)
+            {
+                foreach($skuex as $sku) {
+                    $goods = $general;
+
+                    $goods['goods_edittime'] = $sku['modified'];
+                    $goods['goods_serial'] = $sku['outer_id'];
+                    $goods['goods_price'] = $sku['price'];
+                    $goods['goods_addtime'] = $sku['created'];
+                    $goods['goods_storage'] = $sku['quantity'];
+                    $goods['goods_commonid'] = $common_id;
+                    $this->get_goods_spec($cid,$sku['properties'],$goods_spec);
+                    $goods['goods_spec'] = $goods_spec;
+                    $goods['goods_image'] = $main_pic;
+
+                    $this->mod_goods->addGoods($goods);
+                }
+            }
+        }
+    }
+
+    public function proc()
+    {
+        $items = $this->get_tmgoods();
+        foreach($items as $item) {
+            $this->import_item($item['body'],$item['desc']);
+        }
+    }
+}

+ 23 - 0
crontab/crawl/product_item.php

@@ -0,0 +1,23 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/3
+ * Time: 下午8:29
+ */
+class product_item
+{
+    private $mod_spec_ex;
+
+    public function __construct()
+    {
+        $this->mod_spec_ex = Model("spec_ex");
+    }
+
+    public function proc_item()
+    {
+
+    }
+
+}

+ 278 - 0
crontab/crawl/spec_attr.php

@@ -0,0 +1,278 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/7
+ * Time: 下午1:46
+ */
+class spec_attr
+{
+    private $tm_spec;
+    private $tm_props;
+    private $tm_prop_values;
+
+    private $mod_spec;
+    private $mod_spec_value;
+    private $mod_good_class;
+
+    private $mod_type;
+    private $mod_type_spec;
+    private $tm_spvid_tpvid; //spec value id => tmall props vid
+
+    private $mod_attribute;
+    private $tm_cpid_attrid;
+    private $mod_attribute_value;
+    private $tm_tvid_attrvid;
+
+    const store_name = "美宝莲";
+    const store_id = 1;
+
+    public function __construct()
+    {
+        $this->tm_spec = Model('tm_spec');
+        $this->tm_props = Model('tm_props');
+        $this->tm_prop_values = Model('tm_prop_values');
+
+        $this->mod_good_class = Model('goods_class');
+        $this->mod_spec = Model('spec');
+        $this->mod_type = Model('type');
+        $this->mod_type_spec = Model('type_spec');
+        $this->mod_spec_value = Model('spec_value');
+        $this->tm_spvid_tpvid = Model('tm_spvid_tpvid');
+
+        $this->mod_attribute = Model('attribute');
+        $this->tm_cpid_attrid = Model('tm_cpid_attrid');
+        $this->mod_attribute_value = Model('attribute_value');
+        $this->tm_tvid_attrvid = Model('tm_tvid_attrvid');
+    }
+
+
+    //根据天猫的商品规格,对应生成规格,并做好分类,类型,规格的映射关系
+    public function proc()
+    {
+        $this->add_spec(); //建立规格
+        $this->add_type(); //建立类型,以及 规格与类型 的关系
+        $this->add_type_spec();
+        $this->add_spec_val(); //添加规格值,由于规格值是按照分类走的
+        $this->add_attribute();
+    }
+
+    private function add_spec()
+    {
+        $datas = $this->tm_spec->group('props')->order('props')->limit(false)->select(); //获取所有独立的规格
+        $pids = array();
+        foreach ($datas as $item) {
+            $cid = $item['cid'];
+            $pid = $item['props'];
+            $spec_name = $this->get_tm_props_name($cid, $pid);
+            $sp_id = $this->mod_spec->insert(array('sp_id' => $pid, 'sp_name' => $spec_name));
+            if($sp_id != $pid) {
+                Log::record(__FUNCTION__ . ':' . __LINE__ . "  cannt find prop values from $cid $pid",Log::ERR);
+            } else {
+                array_push($pids, $pid);
+            }
+        }
+    }
+
+    private function add_type()
+    {
+        //通过分类直接建立类型
+        $items = $this->tm_spec->field('cid')->group('cid')->limit(false)->select();
+        foreach($items as $item) {
+            $cid = $item['cid']; // $cid => $typeid 以分类建立类型
+            $cnmae = $this->get_class_name($cid);
+            $this->mod_type->insert(array("type_id" => $cid, "type_name" => $cnmae));
+            $this->mod_good_class->where(array("gc_id" => $cid))->update(array("type_id" => $cid, "type_name" => $cnmae));
+        }
+    }
+
+    private function add_type_spec()
+    {
+        //按照分类建立类型
+        $items = $this->tm_spec->field('cid,props')->group('cid,props')->limit(false)->select();
+        foreach($items as $item) {
+            $cid = $item['cid']; // $cid => $typeid 以分类建立类型
+            $pid = $item['props'];
+            $this->mod_type_spec->insert(array("type_id" => $cid,"sp_id" => $pid));
+        }
+    }
+
+    private function get_prop_name($cid,$pid,$vid)
+    {
+        $items = $this->tm_prop_values->where(array('cid' => $cid,'pid' => $pid,'vid' => $vid))->limit(false)->select();
+        return $items[0]['name'];
+    }
+
+    private function add_spec_val()
+    {
+        $specex = $this->tm_spec->field('cid,props')->group('cid,props')->limit(false)->select();
+        foreach ($specex as $sp)
+        {
+            $cid = $sp["cid"];
+            $pid = $sp["props"];
+
+            $items = $this->get_prop_values($cid,$pid);
+            if(empty($items)) {
+                Log::record(__FUNCTION__ . ':' . __LINE__ . "  cannt find prop values from $cid $pid",Log::ERR);
+            }
+            else
+            {
+                foreach($items as $item)
+                {
+                    $spec_val = array();
+                    $spec_val['sp_id'] = $pid;
+                    $spec_val['sp_value_name'] = $item['name'];
+                    $spec_val['store_id'] = 1;
+                    $spec_val['sp_value_color'] = '#ddd9c3';
+                    $spec_val['gc_id'] = $cid;
+                    $spec_val['sp_value_sort'] = 0;
+
+                    $tm_vid = $item['vid'];
+                    $specval_id = $this->mod_spec_value->insert($spec_val);
+
+                    if($specval_id)
+                    {
+                        $ret = $this->tm_spvid_tpvid->insert(array('spvid' => $specval_id,'tpcid' => $cid, 'tppid' => $pid,'tpvid' => $tm_vid));
+                        if(empty($ret)) {
+                            Log::record(__FUNCTION__ . ':' . __LINE__,Log::ERR);
+                        }
+
+                    } else {
+                        Log::record(__FUNCTION__ . ':' . __LINE__,Log::ERR);
+                    }
+                }
+            }
+        }
+    }
+
+    private function get_class_name($cid)
+    {
+        $item = $this->mod_good_class->where(array('gc_id' => $cid))->limit(false)->select();
+        if(empty($item)) {
+            return NULL;
+        } else {
+            return $item[0]['gc_name'];
+        }
+    }
+
+    //根据cid 和 pid 取到规格名称。
+    private function get_tm_props_name($cid,$pid)
+    {
+        $item = $this->tm_props->where(array('cid' => $cid,'pid' => $pid))->limit(false)->select();
+        if(empty($item)) {
+            return NULL;
+        } else {
+            return $item[0]['name'];
+        }
+    }
+
+    private function get_prop_values($cid,$pid)
+    {
+        $items = $this->tm_prop_values->where(array('cid' => $cid,'pid' => $pid))->limit(false)->select();
+        return $items;
+    }
+
+    private function gen_attr_value($cid,$pid)
+    {
+        $items = $this->tm_prop_values->field('pid,name')->where(array('cid' => $cid,'pid' => $pid))->order('vid')->limit(false)->select();
+
+        $ret = array();
+        foreach($items as $item) {
+            array_push($ret,$item['name']);
+        }
+        return implode(',',$ret);
+    }
+
+    //需要从天猫的数据表里面排除掉 规格 =》 从而得到属性
+    public function add_attribute()
+    {
+        $cids = $this->get_cids();
+        //$cids[] = 50013794;
+
+        foreach($cids as $cid)
+        {
+            $expids = $this->get_specids($cid);
+            $items =$this->tm_props->where(array('cid' => $cid))->limit(false)->select();
+
+            $pids = array();
+            foreach($items as $item)
+            {
+                $pid = $item['pid'];
+
+                if(in_array($pid,$expids)) continue;
+                if(empty($pid)) continue;
+
+                array_push($pids,$pid);
+
+                $name = $item['name'];
+                $multi = strtolower($item['multi']) == 'true' ? true : false;
+                $attr_multi = $multi ? 1 : 0;
+
+                $attr_value = $this->gen_attr_value($cid,$pid);
+                $attrid = $this->mod_attribute->table('attribute')->insert(array( "attr_name" => $name,"type_id" => $cid,'attr_value' => $attr_value, "attr_multi" => $attr_multi,"attr_show" => 1));
+
+                if($attrid)
+                { // 建立shopnc attribute id 与 天猫数据 pid + cid 的对应关系
+                    $rid = $this->tm_cpid_attrid->insert(array("attr_id" => $attrid, "cid" => $cid, "pid" => $pid));
+                    if(empty($rid)) {
+                        throw new Exception('insert error');
+                    } else {
+                        $this->add_attr_value($pid,$cid,$attrid);
+                    }
+                } else {
+                    // add log...
+                }
+
+            }
+        }
+    }
+
+    private function add_attr_value($pid,$cid,$attrid)
+    {
+        Log::record("pid = $pid,cid=$cid,attrid = $attrid");
+
+        $tm_valus = $this->tm_prop_values->field('name,vid')->where(array('pid' => $pid,'cid'=>$cid))->limit(false)->select();
+
+        foreach($tm_valus as $val)
+        {
+            $type_id = $cid;
+            $attr_value_name = $val['name'];
+            $vid = $val['vid'];
+
+            $attr_vid = $this->mod_attribute_value->insert(array("attr_id" => $attrid,"type_id" => $type_id, "attr_value_name" => $attr_value_name));
+            if($attr_vid)
+            {
+                $rid = $this->tm_tvid_attrvid->insert(array('attr_vid' =>$attr_vid,'tcid' => $cid,'tpid' => $pid,'tvid' => $vid));
+                if(empty($rid)) {
+                    throw new Exception('insert tm_tvid_attrvid error');
+                }
+            } else {
+                throw(new Exception("cannot add attribute value."));
+            }
+        }
+    }
+
+    private function get_specids($typeid)
+    {
+        $ret = array();
+        $items = $this->mod_type_spec->field('type_id,sp_id')->where(array('type_id' => $typeid))->limit(false)->select();
+        foreach($items as $item) {
+            array_push($ret,(int)$item['sp_id']);
+        }
+
+        return $ret;
+    }
+
+    private function get_cids()
+    {
+        $cids = array();
+
+        $items = $this->tm_spec->group('cid')->order('cid')->limit(false)->select();
+        foreach ($items as $item) {
+            array_push($cids,$item['cid']);
+        }
+
+        return $cids;
+    }
+}

+ 151 - 0
crontab/crawl/tmrequest.php

@@ -0,0 +1,151 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/3
+ * Time: 下午7:51
+ */
+class tmrequest
+{
+    private $appkey;
+    private $secretKey;
+    private $sessionKey;
+    private $tm_shop;
+    private $tm_goods;
+
+
+    public function __construct()
+    {
+        $this->tm_shop = Model('tm_shop');
+        $this->tm_goods = Model('tm_goods');
+    }
+
+    public function proc()
+    {
+        $items = $this->tm_shop->field('shop_id,shop_name,appKey,sercetCode,sessionKey')->limit(false)->select();
+        foreach($items as $item)
+        {
+            echo "Inof: shop id =".$item["shop_id"]." name=".$item["shop_name"]." appKey=".$item['appKey']." sercetCode=".$item['sercetCode']." sessionKey=".$item['sessionKey']."\r\n";
+
+            $this->appkey = $item['appKey'];
+            $this->secretKey = $item['sercetCode'];
+            $this->sessionKey = $item['sessionKey'];
+
+            $shop_id = $item["shop_id"];
+
+            $sale_items = $this->get_onsale();
+            if(empty($sale_items)) {
+                echo "Error: get product info from taobao err where "."shop id =".$item["shop_id"]." name=".$item["shop_name"]."\r\n";
+            }
+            else
+            {
+                foreach($sale_items as $sale_item)
+                {
+                    $num_iid = $sale_item->num_iid;
+                    $issale = $sale_item->approve_status == "onsale" ? true : false;
+                    if($issale)
+                    {
+                        $body = $this->get_body($num_iid);
+                        $desc = $this->get_desc($num_iid);
+                        if(!empty($body)) {
+                            $this->store_data($body,$desc,$shop_id);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    //添加基础数据。
+    private function store_data($body,$desc,$shop_id)
+    {
+        $response = json_decode($body, true);
+        $item = &$response['item_seller_get_response']['item'];
+        if($item['approve_status'] != 'onsale') {
+            return;
+        }
+
+        $cid = $item['cid'];
+        $num_iid = $item['num_iid'];
+        $title = $item['title'];
+
+
+        //把数据添加到商品临时表里面
+        $iid = $this->tm_goods->insert(array("num_iid" => $num_iid,'shop_id' => $shop_id,'body' => $body,'cid' => $cid,'product_id' =>$item['product_id'],'title' => $title, 'description' => $desc));
+        if(!$iid) {
+            Log::record("Can not insert num_iid=$num_iid into tm_goods table.");
+        }
+    }
+
+    private function get_body($num_iid)
+    {
+        $fields = 'cid,seller_cids,props,input_pids,input_str,pic_url,num,list_time,delist_time,stuff_status,location,
+has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,auto_repost,approve_status,postage_id,product_id,
+item_img, is_virtual,is_taobao,is_ex,is_timing,
+is_3D,score,one_station,second_kill,violation,is_prepay,ww_status,wap_detail_url,cod_postage_id,sell_promise,period_sold_quantity,detail_url,
+num_iid,title,nick,type,sku,
+props_name,created,promoted_service,is_lightning_consignment,is_fenxiao,auction_point,property_alias,volume,
+sell_point,valid_thru,outer_id,
+barcode,sold_quantity,price,post_fee,express_fee,ems_fee,global_stock_type,global_stock_country,prop_img';
+
+        //desc wireless_desc wap_desc
+
+        $c = new TopClient;
+        $c->appkey = $this->appkey;
+        $c->secretKey = $this->secretKey;
+
+        $req = new ItemSellerGetRequest;
+        $req->setFields($fields);
+        $req->setNumIid($num_iid);
+        $resp = $c->execute($req,$body,$this->sessionKey);
+
+        if(!empty($resp)) {
+            $item = &$resp->item;
+            if(!empty($item)) {
+                return $body;
+            }
+        }
+        return false;
+    }
+
+    private function get_desc($num_iid)
+    {
+        $c = new TopClient;
+        $c->appkey = $this->appkey;
+        $c->secretKey = $this->secretKey;
+
+        $req = new ItemSellerGetRequest;
+        $req->setFields("desc");
+        $req->setNumIid($num_iid);
+        $resp = $c->execute($req,$body,$this->sessionKey);
+
+        if(!empty($resp)) {
+            $item = &$resp->item;
+            if(!empty($item)) {
+                return $item->desc;
+            }
+        }
+
+        return false;
+    }
+
+    private function get_onsale()
+    {
+        $c = new TopClient;
+        $c->appkey = $this->appkey;
+        $c->secretKey = $this->secretKey;
+        $req = new ItemsOnsaleGetRequest;
+
+
+        $req->setFields('approve_status,num_iid');
+        $resp = $c->execute($req,$body,$this->sessionKey);
+
+        if(!empty($resp)) {
+            $items = $resp->items->item;
+            return $items;
+        } else {
+            return NULL;
+        }
+    }
+}

+ 100 - 0
crontab/crawl/upload_control.php

@@ -0,0 +1,100 @@
+<?php
+
+class upload_control
+{
+    private $store;
+    private $store_grade;
+
+    public function __construct()
+    {
+
+    }
+        
+    public function set($key,$value) {
+        $this->$key = $value;
+    }
+
+    public function set_store($storeid)
+    {
+        $this->store = $storeid;
+    }
+
+    /**
+     * 读取
+     */
+    public function get($key){
+        return $this->$key;
+    }
+
+    const POST_NAME = 'goods_image';
+    const tmp_file = '/private/var/tmp/phpxxkkdl';
+
+    private function fill_files($filename)
+    {
+        if(file_exists(self::tmp_file)) {
+              unlink(self::tmp_file);
+        }
+        copy($filename,self::tmp_file);
+        if(empty($_FILES['goods_image'])) {
+            $_FILES['goods_image'] = array();
+            $post_info = &$_FILES['goods_image'];
+        }
+        $path_info = pathinfo($filename);
+        $post_info['path'] = $filename;
+        $post_info['name'] = $path_info['basename'];
+        $post_info['type'] = 'image/'.$path_info['extension'];
+        $post_info['error'] = 0;
+        $post_info['size'] = filesize($filename);
+        $post_info['tmp_name'] = self::tmp_file;
+    }
+
+    public function upload_img($file)
+    {
+        // 判断图片数量是否超限
+        $model_album = Model('album');
+
+        // 上传图片
+        $upload = new upload_file();
+        $upload->set('default_dir', ATTACH_GOODS . DS . $this->store . DS . $upload->getSysSetPath());
+        $upload->set('max_size', C('image_max_filesize'));
+
+        $upload->set('thumb_width', GOODS_IMAGES_WIDTH);
+        $upload->set('thumb_height', GOODS_IMAGES_HEIGHT);
+        $upload->set('thumb_ext', GOODS_IMAGES_EXT);
+        $upload->set('fprefix', $this->store);
+        $upload->set('allow_type', array('gif', 'jpg', 'jpeg', 'png'));
+
+        $this->fill_files($file);
+
+        $result = $upload->upfile(upload_control::POST_NAME);
+        if (!$result) {
+            if (strtoupper(CHARSET) == 'GBK') {
+                $upload->error = Language::getUTF8($upload->error);
+            }
+            $output = array();
+            $output['error'] = $upload->error;
+            $output = json_encode($output);
+            exit($output);
+        }
+
+        $img_path = $upload->getSysSetPath() . $upload->file_name;
+
+        // 取得图像大小
+        list($width, $height, $type, $attr) = getimagesize(BASE_UPLOAD_PATH . '/' . ATTACH_GOODS . '/' . $this->store . DS . $img_path);
+
+        // 存入相册
+        $image = explode('.', $_FILES[upload_control::POST_NAME]["name"]);
+        $insert_array = array();
+        $insert_array['apic_name'] = $image['0'];
+        $insert_array['apic_tag'] = '';
+        $insert_array['aclass_id'] = $this->store;//$class_info['aclass_id'];
+        $insert_array['apic_cover'] = $img_path;
+        $insert_array['apic_size'] = intval($_FILES[upload_control::POST_NAME]['size']);
+        $insert_array['apic_spec'] = $width . 'x' . $height;
+        $insert_array['upload_time'] = TIMESTAMP;
+        $insert_array['store_id'] = $this->store;
+        $model_album->addPic($insert_array);
+
+        return $upload->file_name;
+    }
+}

+ 465 - 0
crontab/crawl/upload_file.php

@@ -0,0 +1,465 @@
+
+defined('InShopNC') or exit('Access Invalid!');
+
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/13
+ * Time: 上午10:10
+ */
+class upload_file
+{
+    /**
+     * 文件存储路径
+     */
+    private $save_path;
+    /**
+     * 允许上传的文件类型
+     */
+    private $allow_type=array('gif','jpg','jpeg','bmp','png','swf','tbi');
+    /**
+     * 允许的最大文件大小,单位为KB
+     */
+    private $max_size = '1024';
+    /**
+     * 改变后的图片宽度
+     */
+    private $thumb_width = 0;
+    /**
+     * 改变后的图片高度
+     */
+    private $thumb_height = 0;
+    /**
+     * 生成扩缩略图后缀
+     */
+    private $thumb_ext = false;
+    /**
+     * 允许的图片最大高度,单位为像素
+     */
+    private $upload_file;
+    /**
+     * 是否删除原图
+     */
+    private $ifremove = false;
+    /**
+     * 上传文件名
+     */
+    public $file_name;
+    /**
+     * 上传文件后缀名
+     */
+    private $ext;
+    /**
+     * 上传文件新后缀名
+     */
+    private $new_ext;
+    /**
+     * 默认文件存放文件夹
+     */
+    private $default_dir = ATTACH_PATH;
+    /**
+     * 错误信息
+     */
+    public $error = '';
+    /**
+     * 生成的缩略图,返回缩略图时用到
+     */
+    public $thumb_image;
+    /**
+     * 是否立即弹出错误提示
+     */
+    private $if_show_error = false;
+    /**
+     * 是否只显示最后一条错误
+     */
+    private $if_show_error_one = false;
+    /**
+     * 文件名前缀
+     *
+     * @var string
+     */
+    private $fprefix;
+
+    /**
+     * 是否允许填充空白,默认允许
+     *
+     * @var unknown_type
+     */
+    private $filling = true;
+
+    private $config;
+    /**
+     * 初始化
+     *
+     *	$upload = new UploadFile();
+     *	$upload->set('default_dir','upload');
+     *	$upload->set('max_size',1024);
+     *	//生成4张缩略图,宽高依次如下
+     *	$thumb_width	= '300,600,800,100';
+     *	$thumb_height	= '300,600,800,100';
+     *	$upload->set('thumb_width',	$thumb_width);
+     *	$upload->set('thumb_height',$thumb_height);
+     *	//4张缩略图名称扩展依次如下
+     *	$upload->set('thumb_ext',	'_small,_mid,_max,_tiny');
+     *	//生成新图的扩展名为.jpg
+     *	$upload->set('new_ext','jpg');
+     *	//开始上传
+     *	$result = $upload->upfile('file');
+     *	if (!$result){
+     *		echo '上传成功';
+     *	}
+     *
+     */
+    function __construct(){
+        $this->config['thumb_type'] = C('thumb.cut_type');
+        //加载语言包
+        Language::read('core_lang_index');
+    }
+    /**
+     * 设置
+     *
+     * @param mixed $key
+     * @param mixed $value
+     */
+    public function set($key,$value){
+        $this->$key = $value;
+    }
+    /**
+     * 读取
+     */
+    public function get($key){
+        return $this->$key;
+    }
+    /**
+     * 上传操作
+     *
+     * @param string $field 上传表单名
+     * @return bool
+     */
+    public function upfile($field)
+    {
+
+
+        //上传文件
+        $this->upload_file = $_FILES[$field];
+
+        if ($this->upload_file['tmp_name'] == ""){
+            $this->setError(Language::get('cant_find_temporary_files'));
+            return false;
+        }
+
+        //对上传文件错误码进行验证
+        $error = $this->fileInputError();
+        if (!$error){
+            return false;
+        }
+//        //验证是否是合法的上传文件
+//        if(!is_uploaded_file($this->upload_file['tmp_name'])){
+//            $this->setError(Language::get('upload_file_attack'));
+//            return false;
+//        }
+
+        //验证文件大小
+        if ($this->upload_file['size']==0){
+            $error = Language::get('upload_file_size_none');
+            $this->setError($error);
+            return false;
+        }
+        if($this->upload_file['size'] > $this->max_size*1024){
+            $error = Language::get('upload_file_size_cant_over').$this->max_size.'KB';
+            $this->setError($error);
+            return false;
+        }
+
+        //文件后缀名
+        $tmp_ext = explode(".", $this->upload_file['name']);
+        $tmp_ext = $tmp_ext[count($tmp_ext) - 1];
+        $this->ext = strtolower($tmp_ext);
+
+        //验证文件格式是否为系统允许
+        if(!in_array($this->ext,$this->allow_type)){
+            $error = Language::get('image_allow_ext_is').implode(',',$this->allow_type);
+            $this->setError($error);
+            return false;
+        }
+
+        //检查是否为有效图片
+        if(!$image_info = @getimagesize($this->upload_file['tmp_name'])) {
+            $error = Language::get('upload_image_is_not_image');
+            $this->setError($error);
+            return false;
+        }
+
+        //设置图片路径
+        $this->save_path = $this->setPath();
+
+        //设置文件名称
+        if(empty($this->file_name)) {
+            $this->setFileName();
+        }
+
+        //是否需要生成缩略图
+        $ifresize = false;
+        if ($this->thumb_width && $this->thumb_height && $this->thumb_ext){
+            $thumb_width 	= explode(',',$this->thumb_width);
+            $thumb_height 	= explode(',',$this->thumb_height);
+            $thumb_ext 		= explode(',',$this->thumb_ext);
+            if (count($thumb_width) == count($thumb_height) && count($thumb_height) == count($thumb_ext)) $ifresize = true;
+        }
+
+        //计算缩略图的尺寸
+        if ($ifresize){
+            for ($i=0;$i<count($thumb_width);$i++){
+                $imgscaleto = ($thumb_width[$i] == $thumb_height[$i]);
+                if ($image_info[0] < $thumb_width[$i]) $thumb_width[$i] = $image_info[0];
+                if ($image_info[1] < $thumb_height[$i]) $thumb_height[$i] = $image_info[1];
+                $thumb_wh = $thumb_width[$i]/$thumb_height[$i];
+                $src_wh	 = $image_info[0]/$image_info[1];
+                if ($thumb_wh <= $src_wh){
+                    $thumb_height[$i] = $thumb_width[$i]*($image_info[1]/$image_info[0]);
+                }else{
+                    $thumb_width[$i] = $thumb_height[$i]*($image_info[0]/$image_info[1]);
+                }
+                if ($imgscaleto){
+                    $scale[$i]  = $src_wh > 1 ? $thumb_width[$i] : $thumb_height[$i];
+//					if ($this->config['thumb_type'] == 'gd'){
+//						$scale[$i]  = $src_wh > 1 ? $thumb_width[$i] : $thumb_height[$i];
+//					}else{
+//						$scale[$i]  = $src_wh > 1 ? $thumb_width[$i] : $thumb_height[$i];
+//					}
+                }else{
+                    $scale[$i] = 0;
+                }
+//				if ($thumb_width[$i] == $thumb_height[$i]){
+//					$scale[$i] = $thumb_width[$i];
+//				}else{
+//					$scale[$i] = 0;
+//				}
+            }
+        }
+
+        //是否立即弹出错误
+        if($this->if_show_error){
+            echo "<script type='text/javascript'>alert('". ($this->if_show_error_one ? $error : $this->error) ."');history.back();</script>";
+            die();
+        }
+        if ($this->error != '') return false;
+
+        $u_path = BASE_UPLOAD_PATH.DS.$this->save_path.DS.$this->file_name;
+
+        if(copy($this->upload_file['tmp_name'],$u_path))
+        {
+            //产生缩略图
+            if ($ifresize){
+                $resizeImage	= new ResizeImage();
+                $save_path = rtrim(BASE_UPLOAD_PATH.DS.$this->save_path,'/');
+                for ($i=0;$i<count($thumb_width);$i++){
+                    $resizeImage->newImg($save_path.DS.$this->file_name,$thumb_width[$i],$thumb_height[$i],$scale[$i],$thumb_ext[$i].'.',$save_path,$this->filling);
+                    if ($i==0) {
+                        $resize_image = explode('/',$resizeImage->relative_dstimg);
+                        $this->thumb_image = $resize_image[count($resize_image)-1];
+                    }
+                }
+            }
+
+            //删除原图
+            if ($this->ifremove && is_file(BASE_UPLOAD_PATH.DS.$this->save_path.DS.$this->file_name)) {
+                @unlink(BASE_UPLOAD_PATH.DS.$this->save_path.DS.$this->file_name);
+            }
+            return true;
+        }else {
+            $this->setError(Language::get('upload_file_fail'));
+            return false;
+        }
+//		$this->setErrorFileName($this->upload_file['tmp_name']);
+        return $this->error;
+    }
+    /**
+     * 裁剪指定图片
+     *
+     * @param string $field 上传表单名
+     * @return bool
+     */
+    public function create_thumb($pic_path){
+        if (!file_exists($pic_path)) return ;
+
+        //是否需要生成缩略图
+        $ifresize = false;
+        if ($this->thumb_width && $this->thumb_height && $this->thumb_ext){
+            $thumb_width 	= explode(',',$this->thumb_width);
+            $thumb_height 	= explode(',',$this->thumb_height);
+            $thumb_ext 		= explode(',',$this->thumb_ext);
+            if (count($thumb_width) == count($thumb_height) && count($thumb_height) == count($thumb_ext)) $ifresize = true;
+        }
+        $image_info = @getimagesize($pic_path);
+        //计算缩略图的尺寸
+        if ($ifresize){
+            for ($i=0;$i<count($thumb_width);$i++){
+                $imgscaleto = ($thumb_width[$i] == $thumb_height[$i]);
+                if ($image_info[0] < $thumb_width[$i]) $thumb_width[$i] = $image_info[0];
+                if ($image_info[1] < $thumb_height[$i]) $thumb_height[$i] = $image_info[1];
+                $thumb_wh = $thumb_width[$i]/$thumb_height[$i];
+                $src_wh	 = $image_info[0]/$image_info[1];
+                if ($thumb_wh <= $src_wh){
+                    $thumb_height[$i] = $thumb_width[$i]*($image_info[1]/$image_info[0]);
+                }else{
+                    $thumb_width[$i] = $thumb_height[$i]*($image_info[0]/$image_info[1]);
+                }
+                if ($imgscaleto){
+                    $scale[$i]  = $src_wh > 1 ? $thumb_width[$i] : $thumb_height[$i];
+                }else{
+                    $scale[$i] = 0;
+                }
+            }
+        }
+        //产生缩略图
+        if ($ifresize){
+            $resizeImage	= new ResizeImage();
+            $save_path = rtrim(BASE_UPLOAD_PATH.DS.$this->save_path,'/');
+            for ($i=0;$i<count($thumb_width);$i++){
+//				$resizeImage->newImg($save_path.DS.$this->file_name,$thumb_width[$i],$thumb_height[$i],$scale[$i],$thumb_ext[$i].'.',$save_path,$this->filling);
+                $resizeImage->newImg($pic_path,$thumb_width[$i],$thumb_height[$i],$scale[$i],$thumb_ext[$i].'.',dirname($pic_path),$this->filling);
+            }
+        }
+    }
+    /**
+     * 获取上传文件的错误信息
+     *
+     * @param string $field 上传文件数组键值
+     * @return string 返回字符串错误信息
+     */
+    private function fileInputError()
+    {
+        switch($this->upload_file['error']) {
+            case 0:
+                //文件上传成功
+                return true;
+                break;
+
+            case 1:
+                //上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值
+                $this->setError(Language::get('upload_file_size_over'));
+                return false;
+                break;
+
+            case 2:
+                //上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值
+                $this->setError(Language::get('upload_file_size_over'));
+                return false;
+                break;
+
+            case 3:
+                //文件只有部分被上传
+                $this->setError(Language::get('upload_file_is_not_complete'));
+                return false;
+                break;
+
+            case 4:
+                //没有文件被上传
+                $this->setError(Language::get('upload_file_is_not_uploaded'));
+                return false;
+                break;
+
+            case 6:
+                //找不到临时文件夹
+                $this->setError(Language::get('upload_dir_chmod'));
+                return false;
+                break;
+
+            case 7:
+                //文件写入失败
+                $this->setError(Language::get('upload_file_write_fail'));
+                return false;
+                break;
+
+            default:
+                return true;
+        }
+    }
+
+    /**
+     * 设置存储路径
+     *
+     * @return string 字符串形式的返回结果
+     */
+    public function setPath(){
+        /**
+         * 判断目录是否存在,如果不存在 则生成
+         */
+        if (!is_dir(BASE_UPLOAD_PATH.DS.$this->default_dir)){
+            $dir = $this->default_dir;
+            $dir_array = explode(DS,$dir);
+            $tmp_base_path = BASE_UPLOAD_PATH;
+            foreach ($dir_array as $k => $v){
+                $tmp_base_path = $tmp_base_path.DS.$v;
+                if(!is_dir($tmp_base_path)){
+                    if (!@mkdir($tmp_base_path,0755,true)){
+                        $this->setError('创建目录失败,请检查是否有写入权限');
+                        return false;
+                    }
+                }
+            }
+            unset($dir,$dir_array,$tmp_base_path);
+        }
+
+        //设置权限
+        @chmod(BASE_UPLOAD_PATH.DS.$this->default_dir,0755);
+
+        //判断文件夹是否可写
+        if(!is_writable(BASE_UPLOAD_PATH.DS.$this->default_dir)) {
+            $this->setError(Language::get('upload_file_dir').$this->default_dir.Language::get('upload_file_dir_cant_touch_file'));
+            return false;
+        }
+        return $this->default_dir;
+    }
+
+    /**
+     * 设置文件名称 不包括 文件路径
+     *
+     * 生成(从2000-01-01 00:00:00 到现在的秒数+微秒+四位随机)
+     */
+    private function setFileName(){
+        $tmp_name = sprintf('%010d',time() - 946656000)
+            . sprintf('%03d', microtime() * 1000)
+            . sprintf('%04d', mt_rand(0,9999));
+        $this->file_name = (empty ( $this->fprefix ) ? '' : $this->fprefix . '_')
+            . $tmp_name . '.' . ($this->new_ext == '' ? $this->ext : $this->new_ext);
+    }
+
+    /**
+     * 设置错误信息
+     *
+     * @param string $error 错误信息
+     * @return bool 布尔类型的返回结果
+     */
+    private function setError($error){
+        $this->error = $error;
+    }
+
+    /**
+     * 根据系统设置返回商品图片保存路径
+     */
+    public function getSysSetPath()
+    {
+        switch(C('image_dir_type')) {
+            case "1":
+                //按文件类型存放,例如/a.jpg
+                $subpath = "";
+                break;
+            case "2":
+                //按上传年份存放,例如2011/a.jpg
+                $subpath = date("Y",time()) . "/";
+                break;
+            case "3":
+                //按上传年月存放,例如2011/04/a.jpg
+                $subpath = date("Y",time()) . "/" . date("m",time()) . "/";
+                break;
+            case "4":
+                //按上传年月日存放,例如2011/04/19/a.jpg
+                $subpath = date("Y",time()) . "/" . date("m",time()) . "/" . date("d",time()) . "/";
+        }
+        return $subpath;
+    }
+}

+ 3 - 2
data/api/taobao/top/TopClient.php

@@ -7,7 +7,7 @@ class TopClient
 
 	public $gatewayUrl = "http://gw.api.taobao.com/router/rest";
 
-	public $format = "xml";
+	public $format = "json";
 
 	public $connectTimeout;
 
@@ -130,7 +130,7 @@ class TopClient
 		$logger->log($logData);
 	}
 
-	public function execute($request, $session = null,$bestUrl = null)
+	public function execute($request,&$body,$session = null,$bestUrl = null)
 	{
 		$result =  new ResultSet(); 
 		if($this->checkRequest) {
@@ -182,6 +182,7 @@ class TopClient
 		try
 		{
 			$resp = $this->curl($requestUrl, $apiParams);
+			$body = $resp;
 		}
 		catch (Exception $e)
 		{

+ 60 - 71
data/config/config.ini.php

@@ -1,74 +1,63 @@
 <?php
+// defined('InShopNC') or exit('Access Invalid!');
 
-function config_init()
-{
-	$ret = array();
-        
-	$ret['base_site_url']       = 'http://shopnc.yage.com';
-	$ret['shop_site_url'] 		= 'http://shopnc.yage.com/shop';
-	$ret['cms_site_url'] 		= 'http://shopnc.yage.com/cms';
-	$ret['microshop_site_url'] 	= 'http://shopnc.yage.com/microshop';
-	$ret['circle_site_url'] 	= 'http://shopnc.yage.com/circle';
-	$ret['admin_site_url'] 		= 'http://shopnc.yage.com/admin';
-	$ret['mobile_site_url'] 	= 'http://shopnc.yage.com/mobile';
-	$ret['wap_site_url'] 		= 'http://shopnc.yage.com/wap';
-	$ret['chat_site_url'] 		= 'http://shopnc.yage.com/chat';
-	$ret['node_site_url'] 		= 'http://127.0.0.1:8090';
-	$ret['upload_site_url']		= 'http://shopnc.yage.com/data/upload';
-	$ret['resource_site_url']	= 'http://shopnc.yage.com/data/resource';
-	$ret['version'] 		= '201502020388';
-	$ret['setup_date']		= '2015-08-22 15:52:34';
-	$ret['gip'] 			= 0;
-	$ret['dbdriver']		= 'mysqli';
-	$ret['tablepre']		= '33hao_';
+$config = array();
+$config['base_site_url']        = 'http://shopnc.yage.com';
+$config['shop_site_url'] 		= 'http://shopnc.yage.com/shop';
+$config['cms_site_url'] 		= 'http://shopnc.yage.com/cms';
+$config['microshop_site_url'] 	= 'http://shopnc.yage.com/microshop';
+$config['circle_site_url'] 		= 'http://shopnc.yage.com/circle';
+$config['admin_site_url'] 		= 'http://shopnc.yage.com/admin';
+$config['mobile_site_url'] 		= 'http://shopnc.yage.com/mobile';
+$config['wap_site_url'] 		= 'http://shopnc.yage.com/wap';
+$config['chat_site_url'] 		= 'http://shopnc.yage.com/chat';
+$config['node_site_url'] 		= 'http://127.0.0.1:8090';
+$config['upload_site_url']		= 'http://shopnc.yage.com/data/upload';
+$config['resource_site_url']	= 'http://shopnc.yage.com/data/resource';
+$config['version'] 		= '201502020388';
+$config['setup_date'] 	= '2015-08-22 15:52:34';
+$config['gip'] 			= 0;
+$config['dbdriver'] 	= 'mysqli';
+$config['tablepre']		= '33hao_';
+$config['db']['1']['dbhost']       = '127.0.0.1';
+$config['db']['1']['dbport']       = '3306';
+$config['db']['1']['dbuser']       = 'root';
+$config['db']['1']['dbpwd']        = '55668899';
+$config['db']['1']['dbname']       = '33hao';
+$config['db']['1']['dbcharset']    = 'UTF-8';
+$config['db']['slave']                  = $config['db']['master'];
+$config['session_expire'] 	= 3600;
+$config['lang_type'] 		= 'zh_cn';
+$config['cookie_pre'] 		= '6B0C_';
+$config['thumb']['cut_type'] = 'gd';
+$config['thumb']['impath'] = '';
 
-	$ret['db']['1']['dbhost']       = '127.0.0.1';
-	$ret['db']['1']['dbport']       = '3306';
-	$ret['db']['1']['dbuser']       = 'root';
-	$ret['db']['1']['dbpwd']        = '55668899';
-	$ret['db']['1']['dbname']       = '33hao';
-	$ret['db']['1']['dbcharset']    = 'UTF-8';
-	
-	$ret['db']['slave']				= $ret['db']['master'];
-
-	$ret['session_expire'] 	= 3600;
-	$ret['lang_type'] 		= 'zh_cn';
-	$ret['cookie_pre'] 		= '6B0C_';
-	$ret['thumb']['cut_type'] = 'gd';
-	$ret['thumb']['impath'] = '';
-	$ret['cache']['type'] 			= 'file';
-
-	$ret['redis']['prefix']      	= 'nc_';
-	$ret['redis']['master']['port']     	= 6379;
-	$ret['redis']['master']['host']     	= '127.0.0.1';
-	$ret['redis']['master']['pconnect'] 	= 0;
-	$ret['redis']['slave']      	    = array();
-
-	//$ret['fullindexer']['open']      = false;
-	//$ret['fullindexer']['appname']   = '33hao';
-	
-	$ret['debug'] 			= false;
-	$ret['default_store_id'] = '1';
-	//如果开始伪静态,这里设置为true
-	$ret['url_model'] = false;
-	//如果店铺开启二级域名绑定的,这里填写主域名如baidu.com
-	$ret['subdomain_suffix'] = '';
-	//$ret['session_type'] = 'redis';
-	//$ret['session_save_path'] = 'tcp://127.0.0.1:6379';
-	$ret['node_chat'] = true;
-	//流量记录表数量,为1~10之间的数字,默认为3,数字设置完成后请不要轻易修改,否则可能造成流量统计功能数据错误
-	$ret['flowstat_tablenum'] = 3;
-	$ret['sms']['gwUrl'] = 'http://sdkhttp.eucp.b2m.cn/sdk/SDKService';
-	$ret['sms']['serialNumber'] = '';
-	$ret['sms']['password'] = '';
-	$ret['sms']['sessionKey'] = '';
-	$ret['queue']['open'] = false;
-	$ret['queue']['host'] = '127.0.0.1';
-	$ret['queue']['port'] = 6379;
-	$ret['cache_open'] = true;
-	$ret['delivery_site_url'] = 'http://shopnc.yage.com/delivery';
-    
-    //短信配置
-	$ret['mobile_host_type'] = 3;
-	return $ret;
-}
+$config['cache']['type'] 			= 'redis';//'file';
+$config['redis']['prefix']      	= 'nc_';
+$config['redis']['master']['port']     	= 6379;
+$config['redis']['master']['host']     	= '127.0.0.1';
+$config['redis']['master']['pconnect'] 	= 0;
+$config['redis']['slave']      	    = array();
+//$config['fullindexer']['open']      = false;
+//$config['fullindexer']['appname']   = '33hao';
+$config['debug'] 			= true;
+$config['default_store_id'] = '1';
+//如果开始伪静态,这里设置为true
+$config['url_model'] = false;
+//如果店铺开启二级域名绑定的,这里填写主域名如baidu.com
+$config['subdomain_suffix'] = '';
+//$config['session_type'] = 'redis';
+//$config['session_save_path'] = 'tcp://127.0.0.1:6379';
+$config['node_chat'] = true;
+//流量记录表数量,为1~10之间的数字,默认为3,数字设置完成后请不要轻易修改,否则可能造成流量统计功能数据错误
+$config['flowstat_tablenum'] = 3;
+$config['sms']['gwUrl'] = 'http://sdkhttp.eucp.b2m.cn/sdk/SDKService';
+$config['sms']['serialNumber'] = '';
+$config['sms']['password'] = '';
+$config['sms']['sessionKey'] = '';
+$config['queue']['open'] = false;
+$config['queue']['host'] = '127.0.0.1';
+$config['queue']['port'] = 6379;
+$config['cache_open'] = true;
+$config['delivery_site_url']    = 'http://shopnc.yage.com/delivery';
+return $config;

+ 2 - 1
data/model/goods.model.php

@@ -6,7 +6,8 @@
  */
 defined('InShopNC') or exit('Access Invalid!');
 
-class goodsModel extends Model{
+class goodsModel extends Model
+{
     public function __construct(){
         parent::__construct('goods');
     }

+ 3 - 3
data/model/spec.model.php

@@ -5,11 +5,11 @@
  * 
  *
  *
- 
  */
 defined('InShopNC') or exit('Access Invalid!');
 
-class specModel extends Model {
+class specModel extends Model
+{
     public function __construct() {
         parent::__construct('spec');
     }
@@ -129,7 +129,7 @@ class specModel extends Model {
 		$sp_id = $this->insert($param);
 
         if (!$sp_id) {
-        return false;
+        	return false;
         } else {
             return true;
 		}

+ 13 - 7
data/model/transport.model.php

@@ -9,8 +9,8 @@
  */
 defined('InShopNC') or exit('Access Invalid!');
 
-class transportModel extends Model {
-
+class transportModel extends Model
+{
 	public function __construct(){
 		parent::__construct();
 	}
@@ -148,10 +148,14 @@ class transportModel extends Model {
 	 * @param 运费模板内容 $extend
 	 * @return number 总运费
 	 */
-	private function calc_unit($area_id, $num, $extend){
-		if (!empty($extend) && is_array($extend)){
-			foreach ($extend as $v) {
-				if (strpos($v['area_id'],",".$area_id.",") !== false){
+	private function calc_unit($area_id, $num, $extend)
+	{
+		if (!empty($extend) && is_array($extend))
+		{
+			foreach ($extend as $v)
+			{
+				if (strpos($v['area_id'],",".$area_id.",") !== false)
+				{
 					if ($num <= $v['snum']){
 						//在首件数量范围内
 						$calc_total = $v['sprice'];
@@ -160,7 +164,9 @@ class transportModel extends Model {
 						$calc_total = sprintf('%.2f',($v['sprice'] + ceil(($num-$v['snum'])/$v['xnum'])*$v['xprice']));
 					}
 				}
-				if ($v['is_default']==1){
+
+				if ($v['is_default']==1)
+				{
 					if ($num <= $v['snum']){
 						//在首件数量范围内
 						$calc_default_total = $v['sprice'];

+ 4 - 2
data/model/upload.model.php

@@ -9,7 +9,8 @@
  */
 defined('InShopNC') or exit('Access Invalid!');
 
-class uploadModel{
+class uploadModel
+{
 	/**
 	 * 列表
 	 *
@@ -33,7 +34,8 @@ class uploadModel{
 	 * @param int $id 记录ID
 	 * @return string 字符串类型的返回结果
 	 */
-	private function _condition($condition){
+	private function _condition($condition)
+	{
 		$condition_str = '';
 
 		if ($condition['upload_type'] != ''){

+ 5 - 3
fcgi_run.php

@@ -25,15 +25,17 @@ function run_fcgi()
         $log_file->fwrite("end fcgi_accept\r\n");
         define('StartTime',microtime(true));
         define('TIMESTAMP',time());
-        
-        printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");        
+
+        printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
+
         try
         {
             init_request();
             $file = request_helper::script_file();
             if(is_file($file)) {
-                include $file;
+                //include $file;
             }
+            echo 'xxx';
         } catch (Exception $ex) {
             echo $ex->getTraceAsString();
         }

+ 3 - 1
fooder.php

@@ -6,6 +6,7 @@ define('BASE_CORE_PATH',BASE_ROOT_PATH.'/core');
 define('BASE_DATA_PATH',BASE_ROOT_PATH.'/data');
 define('BASE_MOBILE_PATH',BASE_ROOT_PATH.'/mobile');
 define('BASE_CRONTAB_PATH',BASE_ROOT_PATH.'/crontab');
+define('BASE_UPLOAD_PATH',BASE_DATA_PATH.'/upload');
 
 
 require_once(BASE_MOBILE_PATH . '/util/errcode.php');
@@ -28,8 +29,9 @@ require_once(BASE_CORE_PATH.'/framework/libraries/log.php');
 require_once(BASE_CORE_PATH.'/framework/db/mysql.php');
 require_once(BASE_CORE_PATH.'/framework/function/goods.php');
 require_once(BASE_CORE_PATH . '/framework/libraries/validate.php');
+require_once(BASE_CORE_PATH.'/framework/libraries/resizeimage.php');
 
-$config = config_init();
+//$config = config_init();
 
 define('OS_TYPE','MAC');
 //define('OS_TYPE','LINUX');

+ 19 - 1
global.php

@@ -8,10 +8,28 @@
 
 error_reporting(E_ALL & ~E_NOTICE);
 
+
+define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
+
+/**
+ * 安装判断
+ */
+if (!is_file(BASE_ROOT_PATH."/install/lock") && is_file(BASE_ROOT_PATH."/install/index.php")){
+    if (ProjectName != 'shop'){
+        @header("location: ../install/index.php");
+    }else{
+        @header("location: install/index.php");
+    }
+    exit;
+}
+
+define('BASE_CORE_PATH',BASE_ROOT_PATH.'/core');
+define('BASE_DATA_PATH',BASE_ROOT_PATH.'/data');
 define('DS','/');
 define('InShopNC',true);
 
-
+define('StartTime',microtime(true));
+define('TIMESTAMP',time());
 
 define('DIR_SHOP','shop');
 define('DIR_CMS','cms');

+ 1 - 1
run.php

@@ -16,7 +16,7 @@ if($gfcgi_run == 0) { //模拟请求
     define('StartTime', microtime(true));
     define('TIMESTAMP', time());
     Base::run_test();
-    $file = BASE_CRONTAB_PATH . '/fetch_goods.php';   
+    $file = BASE_CRONTAB_PATH . '/crawl/fetch_goods.php';
     include $file;
 }
 ?>

+ 2 - 1
shop/control/control.php

@@ -7,7 +7,8 @@
 
 defined('InShopNC') or exit('Access Invalid!');
 
-class Control{
+class Control
+{
     /**
      * 检查短消息数量
      *

+ 4 - 2
shop/control/store_goods_add.php

@@ -8,7 +8,8 @@
 
 
 defined('InShopNC') or exit ('Access Invalid!');
-class store_goods_addControl extends BaseSellerControl {
+class store_goods_addControl extends BaseSellerControl
+{
     /**
      * 三方店铺验证,商品数量,有效期
      */
@@ -507,7 +508,8 @@ class store_goods_addControl extends BaseSellerControl {
     /**
      * 上传图片
      */
-    public function image_uploadOp() {
+    public function image_uploadOp()
+    {
         // 判断图片数量是否超限
         $model_album = Model('album');
         $album_limit = $this->store_grade['sg_album_limit'];

+ 1 - 0
shop/index.php

@@ -6,6 +6,7 @@
  * *  */
 define('APP_ID','shop');
 define('BASE_PATH',str_replace('\\','/',dirname(__FILE__)));
+
 if (!@include(dirname(dirname(__FILE__)).'/global.php')) exit('global.php isn\'t exists!');
 if (!@include(BASE_PATH.'/control/control.php')) exit('control.php isn\'t exists!');
 if (!@include(BASE_CORE_PATH.'/33hao.php')) exit('33hao.php isn\'t exists!');