Browse Source

update config

Wan Xin 9 năm trước cách đây
mục cha
commit
fc20c61bcd
100 tập tin đã thay đổi với 5252 bổ sung5252 xóa
  1. 6 6
      .gitignore
  2. 0 0
      admin/config/config.ini.php
  3. 0 0
      admin/control/adv.php
  4. 95 95
      admin/control/bonus.php
  5. 0 0
      admin/control/flea.php
  6. 0 0
      admin/control/goods_class.php
  7. 0 0
      admin/control/index.php
  8. 0 0
      admin/control/mb_ad.php
  9. 0 0
      admin/control/mb_special.php
  10. 0 0
      admin/control/predeposit.php
  11. 0 0
      admin/control/web_api.php
  12. 0 0
      admin/include/menu.php
  13. 0 0
      admin/language/zh_cn/web_config.php
  14. 235 235
      admin/templates/default/bonus.bonus_type_form.php
  15. 70 70
      admin/templates/default/bonus.bonus_type_list.php
  16. 0 0
      admin/templates/default/css/skin_0.css
  17. 0 0
      admin/templates/default/css/skin_1.css
  18. 0 0
      admin/templates/default/images/mobile/mpat.png
  19. 0 0
      admin/templates/default/mb_special_item.edit.php
  20. 0 0
      admin/templates/default/mb_special_item.module_adv_list.php
  21. 0 0
      admin/templates/default/mb_special_item.module_goods.php
  22. 54 54
      admin/templates/default/mb_special_item.module_home5.php
  23. 0 0
      admin/templates/default/web_config.index.php
  24. 0 0
      admin/templates/default/web_focus.edit.php
  25. 0 0
      admin/templates/default/web_sale.edit.php
  26. 3 3
      admin/templates/default/web_upload_sale.php
  27. 2 2
      alter.sql
  28. 10 10
      bat.sh
  29. 0 0
      core/33hao.php
  30. 0 0
      core/framework/cache/cache.cacheredis.php
  31. 0 0
      core/framework/core/base.php
  32. 0 0
      core/framework/db/mysql.php
  33. 0 0
      core/framework/db/mysqli.php
  34. 0 0
      core/framework/function/build.php
  35. 0 0
      core/framework/function/ftp.php
  36. 0 0
      core/framework/function/goods.php
  37. 95 95
      core/framework/function/http.php
  38. 0 0
      core/framework/libraries/language.php
  39. 0 0
      core/framework/libraries/model.php
  40. 0 0
      core/framework/libraries/sms.php
  41. 0 0
      core/framework/libraries/tpl.php
  42. 0 0
      core/framework/libraries/validate.php
  43. 0 0
      core/lrlz.php
  44. 126 126
      crontab/crawl/body_filter.php
  45. 136 136
      crontab/crawl/brand_operator.php
  46. 129 129
      crontab/crawl/category.php
  47. 111 111
      crontab/crawl/class_tree.php
  48. 18 18
      crontab/crawl/fetch_config.php
  49. 84 84
      crontab/crawl/fetch_goods.php
  50. 110 110
      crontab/crawl/importer_check.php
  51. 125 125
      crontab/crawl/page_request.php
  52. 267 267
      crontab/crawl/pretreat_tmdata.php
  53. 671 671
      crontab/crawl/product_importer.php
  54. 45 45
      crontab/crawl/product_item.php
  55. 85 85
      crontab/crawl/skumatcher.php
  56. 275 275
      crontab/crawl/spec_attr.php
  57. 397 397
      crontab/crawl/spec_attr_parser.php
  58. 84 84
      crontab/crawl/tm_pagereq.php
  59. 150 150
      crontab/crawl/tmrequest.php
  60. 281 281
      crontab/crawl/transport_data.php
  61. 100 100
      crontab/crawl/upload_control.php
  62. 462 462
      crontab/crawl/upload_file.php
  63. 54 54
      data/api/smsapi/yuntx/SendSMS.php
  64. 33 33
      data/api/taobao/test.php
  65. 43 43
      data/api/taobao/top/ApplicationVar.php
  66. 186 186
      data/api/taobao/top/ClusterTopClient.php
  67. 23 23
      data/api/taobao/top/HttpdnsGetRequest.php
  68. 213 213
      data/api/taobao/top/SpiUtils.php
  69. 42 42
      data/api/taobao/top/TopLogger.php
  70. 0 0
      data/api/taobao/top/httpdns.conf
  71. 26 26
      data/api/wxpay/cert/apiclient_cert.pem
  72. 28 28
      data/api/wxpay/cert/apiclient_key.pem
  73. 1 1
      data/config/config.ini.php
  74. 0 0
      data/logic/buy.logic.php
  75. 0 0
      data/logic/buy_1.logic.php
  76. 138 138
      data/logic/delivery.logic.php
  77. 31 31
      data/model/bonus_type.model.php
  78. 0 0
      data/model/db.model.php
  79. 0 0
      data/model/express.model.php
  80. 0 0
      data/model/goods_attr_index.model.php
  81. 0 0
      data/model/goods_class.model.php
  82. 0 0
      data/model/goods_gift.model.php
  83. 0 0
      data/model/goods_info_by_url.model.php
  84. 0 0
      data/model/groupbuy.model.php
  85. 0 0
      data/model/invoice.model.php
  86. 0 0
      data/model/live_groupbuy.model.php
  87. 0 0
      data/model/order.model.php
  88. 0 0
      data/model/p_xianshi_goods.model.php
  89. 0 0
      data/model/search.model.php
  90. 0 0
      data/model/store_class.model.php
  91. 0 0
      data/model/store_msg_read.model.php
  92. 0 0
      data/model/type.model.php
  93. 55 55
      data/model/user_bonus.model.php
  94. 0 0
      data/model/web_config.model.php
  95. 0 0
      data/resource/web_config/web_index.js
  96. 43 43
      debug_run.php
  97. 58 58
      fcgi_run.php
  98. 34 34
      fooder.php
  99. 18 18
      gcidfiller.php
  100. 0 0
      index.php

+ 6 - 6
.gitignore

@@ -1,6 +1,6 @@
-.DBStore/*
-/data/Download/*
-/data/log/*
-/data/session/*
-/data/upload/*
-/data/config/config.ini.php
+.DBStore/*
+/data/Download/*
+/data/log/*
+/data/session/*
+/data/upload/*
+/data/config/config.ini.php

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


+ 0 - 0
admin/control/adv.php


+ 95 - 95
admin/control/bonus.php

@@ -1,96 +1,96 @@
-<?php
-/**
- * 红包管理
- *
- *
- *
- ***/
-defined('InShopNC') or exit('Access Invalid!');
-class bonusControl extends SystemControl
-{
-    public function __construct(){
-        parent::__construct();
-    }
-
-    public function bonus_typeOp()
-    {
-        $bonus_type = Model('bonus_type');
-        $bonus_list = $bonus_type->getAll();
-        Tpl::output('bonus_list', $bonus_list) ;
-        $this->show_menu('bonus','bonus_type_list');
-        Tpl::showpage('bonus.bonus_type_list');
-    }
-
-    public function bonus_type_addOp() {
-        $this->show_menu('bonus','bonus_type_add');
-        $this->bonus_form();
-    }
-
-    public function bonus_type_editOp() {
-        $id = $_GET['id'];
-        $this->show_menu('type','bonus_type_edit');
-        $this->bonus_form($id);
-    }
-
-    public function bonus_type_saveOp()
-    {
-        $type_id = $_POST['type_id'] ? $_POST['type_id'] : 0;
-        $bonus_value = array(
-            'type_name' => $_POST['hb_words'],
-            'send_type' => $_POST['send_type'],
-            'send_start_date' => strtotime(trim($_POST['send_start_date'])),
-            'send_end_date' => strtotime(trim($_POST['send_end_date'])),
-            'use_start_date' => strtotime(trim($_POST['use_start_date'])),
-            'use_end_date' => strtotime(trim($_POST['use_end_date']))
-        );
-        $bonus_type = Model('bonus_type');
-        $bonus_type->save($bonus_value, $type_id);
-        if(intval($_POST['send_type']) === 1)
-        {
-            $bonus_file = $_FILES['bonus_file'];
-            if($bonus_file && !empty($bonus_file['name']))
-            {
-                if ($bonus_file['tmp_name'] == ""){
-                    $this->setError('上传失败,请联系服务器管理员。');
-                    return false;
-                }
-                $bonus_file_content = file_get_contents($bonus_file['tmp_name']);
-                $bonus = Model('user_bonus');
-                $bonus->loadFile($bonus_file_content);
-            }
-        }
-        $this->bonus_typeOp();
-    }
-
-    private function bonus_form($id = 0)
-    {
-        Tpl::output('id', $id);
-        if($id > 0){
-            $bonus_type = Model('bonus_type');
-            $bonus_type_data = $bonus_type->get($id);
-            Tpl::output('data', $bonus_type_data[0]);
-        }
-        Tpl::showpage('bonus.bonus_type_form');
-    }
-
-    private function show_menu($menu_type,$menu_key='')
-    {
-        $menu_array = array();
-        switch ($menu_type) {
-            case 'bonus':
-                $menu_array = array(
-                    1=>array('menu_key'=>'bonus_type_list','menu_name'=>'已发红包', 'menu_url'=>'index.php?act=bonus&op=bonus_type'),
-                    2=>array('menu_key'=>'bonus_type_add','menu_name'=>'添加定向红包', 'menu_url'=>'index.php?act=bonus&op=bonus_type_add'),
-                    3=>array('menu_key'=>'bonus_type_add_random','menu_name'=>'添加随机红包', 'menu_url'=>'index.php?act=bonus&op=bonus_type_add_random'),
-                );
-                break;
-            case 'type':
-                $menu_array = array(
-                    1=>array('menu_key'=>'bonus_type_edit','menu_name'=>'编辑红包', 'menu_url'=>'index.php?act=bonus&op=bonus_type_edit')
-                );
-                break;
-        }
-        Tpl::output('menu',$menu_array);
-        Tpl::output('menu_key',$menu_key);
-    }
+<?php
+/**
+ * 红包管理
+ *
+ *
+ *
+ ***/
+defined('InShopNC') or exit('Access Invalid!');
+class bonusControl extends SystemControl
+{
+    public function __construct(){
+        parent::__construct();
+    }
+
+    public function bonus_typeOp()
+    {
+        $bonus_type = Model('bonus_type');
+        $bonus_list = $bonus_type->getAll();
+        Tpl::output('bonus_list', $bonus_list) ;
+        $this->show_menu('bonus','bonus_type_list');
+        Tpl::showpage('bonus.bonus_type_list');
+    }
+
+    public function bonus_type_addOp() {
+        $this->show_menu('bonus','bonus_type_add');
+        $this->bonus_form();
+    }
+
+    public function bonus_type_editOp() {
+        $id = $_GET['id'];
+        $this->show_menu('type','bonus_type_edit');
+        $this->bonus_form($id);
+    }
+
+    public function bonus_type_saveOp()
+    {
+        $type_id = $_POST['type_id'] ? $_POST['type_id'] : 0;
+        $bonus_value = array(
+            'type_name' => $_POST['hb_words'],
+            'send_type' => $_POST['send_type'],
+            'send_start_date' => strtotime(trim($_POST['send_start_date'])),
+            'send_end_date' => strtotime(trim($_POST['send_end_date'])),
+            'use_start_date' => strtotime(trim($_POST['use_start_date'])),
+            'use_end_date' => strtotime(trim($_POST['use_end_date']))
+        );
+        $bonus_type = Model('bonus_type');
+        $bonus_type->save($bonus_value, $type_id);
+        if(intval($_POST['send_type']) === 1)
+        {
+            $bonus_file = $_FILES['bonus_file'];
+            if($bonus_file && !empty($bonus_file['name']))
+            {
+                if ($bonus_file['tmp_name'] == ""){
+                    $this->setError('上传失败,请联系服务器管理员。');
+                    return false;
+                }
+                $bonus_file_content = file_get_contents($bonus_file['tmp_name']);
+                $bonus = Model('user_bonus');
+                $bonus->loadFile($bonus_file_content);
+            }
+        }
+        $this->bonus_typeOp();
+    }
+
+    private function bonus_form($id = 0)
+    {
+        Tpl::output('id', $id);
+        if($id > 0){
+            $bonus_type = Model('bonus_type');
+            $bonus_type_data = $bonus_type->get($id);
+            Tpl::output('data', $bonus_type_data[0]);
+        }
+        Tpl::showpage('bonus.bonus_type_form');
+    }
+
+    private function show_menu($menu_type,$menu_key='')
+    {
+        $menu_array = array();
+        switch ($menu_type) {
+            case 'bonus':
+                $menu_array = array(
+                    1=>array('menu_key'=>'bonus_type_list','menu_name'=>'已发红包', 'menu_url'=>'index.php?act=bonus&op=bonus_type'),
+                    2=>array('menu_key'=>'bonus_type_add','menu_name'=>'添加定向红包', 'menu_url'=>'index.php?act=bonus&op=bonus_type_add'),
+                    3=>array('menu_key'=>'bonus_type_add_random','menu_name'=>'添加随机红包', 'menu_url'=>'index.php?act=bonus&op=bonus_type_add_random'),
+                );
+                break;
+            case 'type':
+                $menu_array = array(
+                    1=>array('menu_key'=>'bonus_type_edit','menu_name'=>'编辑红包', 'menu_url'=>'index.php?act=bonus&op=bonus_type_edit')
+                );
+                break;
+        }
+        Tpl::output('menu',$menu_array);
+        Tpl::output('menu_key',$menu_key);
+    }
 }

+ 0 - 0
admin/control/flea.php


+ 0 - 0
admin/control/goods_class.php


+ 0 - 0
admin/control/index.php


+ 0 - 0
admin/control/mb_ad.php


+ 0 - 0
admin/control/mb_special.php


+ 0 - 0
admin/control/predeposit.php


+ 0 - 0
admin/control/web_api.php


+ 0 - 0
admin/include/menu.php


+ 0 - 0
admin/language/zh_cn/web_config.php


+ 235 - 235
admin/templates/default/bonus.bonus_type_form.php

@@ -1,236 +1,236 @@
-<?php defined('InShopNC') or exit('Access Invalid!');?>
-
-<div class="page">
-    <!-- 页面导航 -->
-    <div class="fixed-bar">
-        <div class="item-title">
-            <h3>红包管理</h3>
-            <ul class="tab-base">
-                <?php   foreach($output['menu'] as $menu) {  if($menu['menu_key'] == $output['menu_key']) { ?>
-                    <li><a href="JavaScript:void(0);" class="current"><span><?php echo $menu['menu_name'];?></span></a></li>
-                <?php }  else { ?>
-                    <li><a href="<?php echo $menu['menu_url'];?>" ><span><?php echo $menu['menu_name'];?></span></a></li>
-                <?php  } }  ?>
-            </ul>
-            </ul>
-        </div>
-    </div>
-
-    <div class="fixed-empty"></div>
-    <form id="type_form" method="post" enctype="multipart/form-data" action="index.php?act=bonus&op=bonus_type_save">
-        <input type="hidden" name="type_id" value="<?php echo $output['id'];?>"/>
-        <table class="table tb-type2">
-            <tbody>
-
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="sender">发送者名称</label></td>
-            </tr>
-            <tr class="noborder">
-                <td class="vatop rowform"><input type="text" id="sender" name="sender" class="txt" value="<?php echo  isset($output['data'])? $output['data']['sender'] : '';?>"></td>
-                <td class="vatop tips"></td>
-            </tr>
-
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="hb_words">祝福语</label></td>
-            </tr>
-            <tr class="noborder">
-                <td class="vatop rowform"><input type="text" id="hb_words" name="hb_words" class="txt" value="<?php echo  isset($output['data'])? $output['data']['hb_words'] : '';?>"></td>
-                <td class="vatop tips"></td>
-            </tr>
-
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="h5_link">H5链接</label></td>
-            </tr>
-            <tr class="noborder">
-                <td class="vatop rowform"><input type="text" id="h5_link" name="h5_link" class="txt" value="<?php echo  isset($output['data'])? $output['data']['h5_link'] : '';?>"></td>
-                <td class="vatop tips"></td>
-            </tr>
-
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="link_param">链接参数</label></td>
-            </tr>
-
-
-            <tr class="noborder">
-                <td class="vatop rowform"><input type="text" id="link_param" name="link_param" class="txt" value="<?php echo  isset($output['data'])? $output['data']['link_param'] : '';?>"></td>
-                <td class="vatop tips"></td>
-            </tr>
-
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="send_type">发放方式</label></td>
-            </tr>
-            <tr class="noborder">
-                <td class="vatop rowform">
-                    <input type="radio" id="send_type" name="send_type" value="1" checked><label>发放给特定用户</label>
-                </td>
-                <td class="vatop tips"></td>
-            </tr>
-            <tr class="noborder">
-                <td class="required" colspan="2"><label>上传CSV文件</label></td>
-            </tr>
-
-            <tr class="noborder">
-                <td class="vatop rowform">
-                    <span class="type-file-box">
-                        <input type="file" class="type-file-file" id="bonus_file" name="bonus_file" size="30" hidefocus="true" nc_type="upload_bonus_file" title="选择文件">
-                    </span>
-                </td>
-                <td class="vatop tips"></td>
-            </tr>
-
-
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="send_start_date">开始发放时间</label></td>
-            </tr>
-            <tr class="noborder">
-                <td class="vatop rowform"><input type="text" id="send_start_date" name="send_start_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['send_start_date']) : '';?>"></td>
-                <td class="vatop tips"></td>
-            </tr>
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="send_end_date">结束发放时间</label></td>
-            </tr>
-            <tr class="noborder">
-                <td class="vatop rowform"><input type="text" id="send_end_date" name="send_end_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['send_end_date']) : '';?>"></td>
-                <td class="vatop tips"></td>
-            </tr>
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="use_start_date">开始使用时间</label></td>
-            </tr>
-            <tr class="noborder">
-                <td class="vatop rowform"><input type="text" id="use_start_date" name="use_start_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['use_start_date']) : '';?>"></td>
-                <td class="vatop tips"></td>
-            </tr>
-            <tr class="noborder">
-                <td class="required" colspan="2"><label class="validation" for="use_end_date">结束使用时间</label></td>
-            </tr>
-            <tr class="noborder">
-                <td class="vatop rowform"><input type="text" id="use_end_date" name="use_end_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['use_end_date']) : '';?>"></td>
-                <td class="vatop tips"></td>
-            </tr>
-            </tbody>
-            <tfoot>
-            <tr class="tfoot">
-                <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
-            </tr>
-            </tfoot>
-        </table>
-    </form>
-</div>
-<link type="text/css" rel="stylesheet" href="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/themes/ui-lightness/jquery.ui.css";?>"/>
-<script src="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/jquery.ui.js";?>"></script>
-<script src="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/i18n/zh-CN.js";?>" charset="utf-8"></script>
-<script>
-    //按钮先执行验证再提交表单
-    $(function(){$("#submitBtn").click(function(){
-        if($("#type_form").valid()){
-            $("#type_form").submit();
-        }
-    });
-    });
-    $(document).ready(function(){
-        $("#send_start_date").datepicker();
-        $("#send_end_date").datepicker();
-        $("#use_start_date").datepicker();
-        $("#use_end_date").datepicker();
-        $("#pass_name").datepicker();
-        $("#h5").datepicker();
-        $("#h5_url").datepicker();
-
-        $("#type_form").validate({
-            errorPlacement: function(error, element){
-                error.appendTo(element.parent().parent().prev().find('td:first'));
-            },
-            rules : {
-                sender: {
-                    required : true
-                },
-                hb_words: {
-                    required : true
-                },
-                h5_link: {
-                    required : true
-                },
-                link_param: {
-                    required : true
-                },
-                type_name: {
-                    required : true
-                },
-                send_start_date: {
-                    required : true,
-                    date      : false
-                },
-                send_end_date: {
-                    required : true,
-                    date      : false
-                },
-                use_start_date: {
-                    required : true,
-                    date      : false
-                },
-                use_end_date: {
-                    required : true,
-                    date      : false
-                },
-                _name: {
-                    required : true,
-                    date      : false
-                },
-                h5: {
-                    required : true,
-                    date      : false
-                },
-                h5_url: {
-                    required : true,
-                    date      : false
-                }
-            },
-            messages : {
-                sender: {
-                    required : '发送者名称不能为空'
-                },
-                hb_words: {
-                    required : '祝福语不能为空'
-                },
-                h5_link: {
-                    required : 'H5链接不能为空'
-                },
-                link_param: {
-                    required : '链接参数不能为空'
-                },
-                type_name: {
-                    required : '红包名称不能为空'
-                },
-                send_start_date: {
-                    required : '开始发放时间不能为空'
-                },
-                send_end_date: {
-                    required : '结束发放时间不能为空>'
-                },
-                use_start_date: {
-                    required : '开始使用时间不能为空'
-                },
-                use_end_date: {
-                    required : '结束使用时间不能为空'
-                },
-                pass_name: {
-                    required : '发送者不能为空'
-                },
-                h5: {
-                    required : 'h5链接不能为空'
-                },
-                h5_url: {
-                    required : '链接参数不能为空'
-                }
-            }
-        });
-    });
-
-    $(function(){
-        var textButton="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='' class='type-file-button' />"
-        $(textButton).insertBefore("#bonus_file");
-        $("#bonus_file").change(function(){
-            $("#textfield1").val($("#bonus_file").val());
-        });
-    });
+<?php defined('InShopNC') or exit('Access Invalid!');?>
+
+<div class="page">
+    <!-- 页面导航 -->
+    <div class="fixed-bar">
+        <div class="item-title">
+            <h3>红包管理</h3>
+            <ul class="tab-base">
+                <?php   foreach($output['menu'] as $menu) {  if($menu['menu_key'] == $output['menu_key']) { ?>
+                    <li><a href="JavaScript:void(0);" class="current"><span><?php echo $menu['menu_name'];?></span></a></li>
+                <?php }  else { ?>
+                    <li><a href="<?php echo $menu['menu_url'];?>" ><span><?php echo $menu['menu_name'];?></span></a></li>
+                <?php  } }  ?>
+            </ul>
+            </ul>
+        </div>
+    </div>
+
+    <div class="fixed-empty"></div>
+    <form id="type_form" method="post" enctype="multipart/form-data" action="index.php?act=bonus&op=bonus_type_save">
+        <input type="hidden" name="type_id" value="<?php echo $output['id'];?>"/>
+        <table class="table tb-type2">
+            <tbody>
+
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="sender">发送者名称</label></td>
+            </tr>
+            <tr class="noborder">
+                <td class="vatop rowform"><input type="text" id="sender" name="sender" class="txt" value="<?php echo  isset($output['data'])? $output['data']['sender'] : '';?>"></td>
+                <td class="vatop tips"></td>
+            </tr>
+
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="hb_words">祝福语</label></td>
+            </tr>
+            <tr class="noborder">
+                <td class="vatop rowform"><input type="text" id="hb_words" name="hb_words" class="txt" value="<?php echo  isset($output['data'])? $output['data']['hb_words'] : '';?>"></td>
+                <td class="vatop tips"></td>
+            </tr>
+
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="h5_link">H5链接</label></td>
+            </tr>
+            <tr class="noborder">
+                <td class="vatop rowform"><input type="text" id="h5_link" name="h5_link" class="txt" value="<?php echo  isset($output['data'])? $output['data']['h5_link'] : '';?>"></td>
+                <td class="vatop tips"></td>
+            </tr>
+
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="link_param">链接参数</label></td>
+            </tr>
+
+
+            <tr class="noborder">
+                <td class="vatop rowform"><input type="text" id="link_param" name="link_param" class="txt" value="<?php echo  isset($output['data'])? $output['data']['link_param'] : '';?>"></td>
+                <td class="vatop tips"></td>
+            </tr>
+
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="send_type">发放方式</label></td>
+            </tr>
+            <tr class="noborder">
+                <td class="vatop rowform">
+                    <input type="radio" id="send_type" name="send_type" value="1" checked><label>发放给特定用户</label>
+                </td>
+                <td class="vatop tips"></td>
+            </tr>
+            <tr class="noborder">
+                <td class="required" colspan="2"><label>上传CSV文件</label></td>
+            </tr>
+
+            <tr class="noborder">
+                <td class="vatop rowform">
+                    <span class="type-file-box">
+                        <input type="file" class="type-file-file" id="bonus_file" name="bonus_file" size="30" hidefocus="true" nc_type="upload_bonus_file" title="选择文件">
+                    </span>
+                </td>
+                <td class="vatop tips"></td>
+            </tr>
+
+
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="send_start_date">开始发放时间</label></td>
+            </tr>
+            <tr class="noborder">
+                <td class="vatop rowform"><input type="text" id="send_start_date" name="send_start_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['send_start_date']) : '';?>"></td>
+                <td class="vatop tips"></td>
+            </tr>
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="send_end_date">结束发放时间</label></td>
+            </tr>
+            <tr class="noborder">
+                <td class="vatop rowform"><input type="text" id="send_end_date" name="send_end_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['send_end_date']) : '';?>"></td>
+                <td class="vatop tips"></td>
+            </tr>
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="use_start_date">开始使用时间</label></td>
+            </tr>
+            <tr class="noborder">
+                <td class="vatop rowform"><input type="text" id="use_start_date" name="use_start_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['use_start_date']) : '';?>"></td>
+                <td class="vatop tips"></td>
+            </tr>
+            <tr class="noborder">
+                <td class="required" colspan="2"><label class="validation" for="use_end_date">结束使用时间</label></td>
+            </tr>
+            <tr class="noborder">
+                <td class="vatop rowform"><input type="text" id="use_end_date" name="use_end_date"  class="txt date" readonly="readonly" value="<?php echo  isset($output['data'])? date('Y-m-d', $output['data']['use_end_date']) : '';?>"></td>
+                <td class="vatop tips"></td>
+            </tr>
+            </tbody>
+            <tfoot>
+            <tr class="tfoot">
+                <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
+            </tr>
+            </tfoot>
+        </table>
+    </form>
+</div>
+<link type="text/css" rel="stylesheet" href="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/themes/ui-lightness/jquery.ui.css";?>"/>
+<script src="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/jquery.ui.js";?>"></script>
+<script src="<?php echo RESOURCE_SITE_URL."/js/jquery-ui/i18n/zh-CN.js";?>" charset="utf-8"></script>
+<script>
+    //按钮先执行验证再提交表单
+    $(function(){$("#submitBtn").click(function(){
+        if($("#type_form").valid()){
+            $("#type_form").submit();
+        }
+    });
+    });
+    $(document).ready(function(){
+        $("#send_start_date").datepicker();
+        $("#send_end_date").datepicker();
+        $("#use_start_date").datepicker();
+        $("#use_end_date").datepicker();
+        $("#pass_name").datepicker();
+        $("#h5").datepicker();
+        $("#h5_url").datepicker();
+
+        $("#type_form").validate({
+            errorPlacement: function(error, element){
+                error.appendTo(element.parent().parent().prev().find('td:first'));
+            },
+            rules : {
+                sender: {
+                    required : true
+                },
+                hb_words: {
+                    required : true
+                },
+                h5_link: {
+                    required : true
+                },
+                link_param: {
+                    required : true
+                },
+                type_name: {
+                    required : true
+                },
+                send_start_date: {
+                    required : true,
+                    date      : false
+                },
+                send_end_date: {
+                    required : true,
+                    date      : false
+                },
+                use_start_date: {
+                    required : true,
+                    date      : false
+                },
+                use_end_date: {
+                    required : true,
+                    date      : false
+                },
+                _name: {
+                    required : true,
+                    date      : false
+                },
+                h5: {
+                    required : true,
+                    date      : false
+                },
+                h5_url: {
+                    required : true,
+                    date      : false
+                }
+            },
+            messages : {
+                sender: {
+                    required : '发送者名称不能为空'
+                },
+                hb_words: {
+                    required : '祝福语不能为空'
+                },
+                h5_link: {
+                    required : 'H5链接不能为空'
+                },
+                link_param: {
+                    required : '链接参数不能为空'
+                },
+                type_name: {
+                    required : '红包名称不能为空'
+                },
+                send_start_date: {
+                    required : '开始发放时间不能为空'
+                },
+                send_end_date: {
+                    required : '结束发放时间不能为空>'
+                },
+                use_start_date: {
+                    required : '开始使用时间不能为空'
+                },
+                use_end_date: {
+                    required : '结束使用时间不能为空'
+                },
+                pass_name: {
+                    required : '发送者不能为空'
+                },
+                h5: {
+                    required : 'h5链接不能为空'
+                },
+                h5_url: {
+                    required : '链接参数不能为空'
+                }
+            }
+        });
+    });
+
+    $(function(){
+        var textButton="<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='' class='type-file-button' />"
+        $(textButton).insertBefore("#bonus_file");
+        $("#bonus_file").change(function(){
+            $("#textfield1").val($("#bonus_file").val());
+        });
+    });
 </script>

+ 70 - 70
admin/templates/default/bonus.bonus_type_list.php

@@ -1,70 +1,70 @@
-<?php defined('InShopNC') or exit('Access Invalid!');?>
-
-<div class="page">
-    <!-- 页面导航 -->
-    <div class="fixed-bar">
-        <div class="item-title">
-            <h3>红包管理</h3>
-            <ul class="tab-base">
-                <?php   foreach($output['menu'] as $menu) {  if($menu['menu_key'] == $output['menu_key']) { ?>
-                    <li><a href="JavaScript:void(0);" class="current"><span><?php echo $menu['menu_name'];?></span></a></li>
-                <?php }  else { ?>
-                    <li><a href="<?php echo $menu['menu_url'];?>" ><span><?php echo $menu['menu_name'];?></span></a></li>
-                <?php  } }  ?>
-            </ul>
-            </ul>
-        </div>
-    </div>
-
-    <div class="fixed-empty"></div>
-    <table class="table tb-type2" id="prompt">
-        <tbody>
-        <tr class="space odd">
-            <th class="nobg" colspan="12">
-                <div class="title">
-                    <h5><?php echo $lang['nc_prompts'];?></h5>
-                    <span class="arrow"></span>
-                </div>
-            </th>
-        </tr>
-        <tr>
-            <td><ul>
-                    <li>点击编辑链接修改红包类型数据</li>
-                </ul></td>
-        </tr>
-        </tbody>
-    </table>
-
-    <table class="table tb-type2">
-        <thead>
-        <tr class="thead">
-            <th class="w96">红包名称</th>
-            <th class="w96">发放类型</th>
-            <th class="w96">开始发放时间</th>
-            <th class="w96">结束发放时间</th>
-            <th class="w96">开始使用时间</th>
-            <th class="w96">结束使用时间</th>
-            <th class="w48">操作</th>
-        </tr>
-        </thead>
-        <tbody id="treet1">
-        <?php if(!empty($output['bonus_list']) && is_array($output['bonus_list'])){ ?>
-        <?php foreach($output['bonus_list'] as $k => $v){ ?>
-        <tr class="hover edit row">
-            <td><?php echo $v['type_name'];?></td>
-            <td><?php
-                if(intval($v['send_type']) === 1){
-                    echo '发放给特定用户';
-                }
-                ?></td>
-            <td><?php echo date('Y-m-d', $v['send_start_date']);?></td>
-            <td><?php echo date('Y-m-d',$v['send_end_date']);?></td>
-            <td><?php echo date('Y-m-d',$v['use_start_date']);?></td>
-            <td><?php echo date('Y-m-d',$v['use_end_date']);?></td>
-            <td><a href="index.php?act=bonus&op=bonus_type_edit&id=<?php echo $v['type_id'];?>">编辑</a></td>
-        </tr>
-        <?php }  ?>
-        <?php }  ?>
-        </tbody>
-    </table>
-</div>
+<?php defined('InShopNC') or exit('Access Invalid!');?>
+
+<div class="page">
+    <!-- 页面导航 -->
+    <div class="fixed-bar">
+        <div class="item-title">
+            <h3>红包管理</h3>
+            <ul class="tab-base">
+                <?php   foreach($output['menu'] as $menu) {  if($menu['menu_key'] == $output['menu_key']) { ?>
+                    <li><a href="JavaScript:void(0);" class="current"><span><?php echo $menu['menu_name'];?></span></a></li>
+                <?php }  else { ?>
+                    <li><a href="<?php echo $menu['menu_url'];?>" ><span><?php echo $menu['menu_name'];?></span></a></li>
+                <?php  } }  ?>
+            </ul>
+            </ul>
+        </div>
+    </div>
+
+    <div class="fixed-empty"></div>
+    <table class="table tb-type2" id="prompt">
+        <tbody>
+        <tr class="space odd">
+            <th class="nobg" colspan="12">
+                <div class="title">
+                    <h5><?php echo $lang['nc_prompts'];?></h5>
+                    <span class="arrow"></span>
+                </div>
+            </th>
+        </tr>
+        <tr>
+            <td><ul>
+                    <li>点击编辑链接修改红包类型数据</li>
+                </ul></td>
+        </tr>
+        </tbody>
+    </table>
+
+    <table class="table tb-type2">
+        <thead>
+        <tr class="thead">
+            <th class="w96">红包名称</th>
+            <th class="w96">发放类型</th>
+            <th class="w96">开始发放时间</th>
+            <th class="w96">结束发放时间</th>
+            <th class="w96">开始使用时间</th>
+            <th class="w96">结束使用时间</th>
+            <th class="w48">操作</th>
+        </tr>
+        </thead>
+        <tbody id="treet1">
+        <?php if(!empty($output['bonus_list']) && is_array($output['bonus_list'])){ ?>
+        <?php foreach($output['bonus_list'] as $k => $v){ ?>
+        <tr class="hover edit row">
+            <td><?php echo $v['type_name'];?></td>
+            <td><?php
+                if(intval($v['send_type']) === 1){
+                    echo '发放给特定用户';
+                }
+                ?></td>
+            <td><?php echo date('Y-m-d', $v['send_start_date']);?></td>
+            <td><?php echo date('Y-m-d',$v['send_end_date']);?></td>
+            <td><?php echo date('Y-m-d',$v['use_start_date']);?></td>
+            <td><?php echo date('Y-m-d',$v['use_end_date']);?></td>
+            <td><a href="index.php?act=bonus&op=bonus_type_edit&id=<?php echo $v['type_id'];?>">编辑</a></td>
+        </tr>
+        <?php }  ?>
+        <?php }  ?>
+        </tbody>
+    </table>
+</div>

+ 0 - 0
admin/templates/default/css/skin_0.css


+ 0 - 0
admin/templates/default/css/skin_1.css


+ 0 - 0
admin/templates/default/images/mobile/mpat.png


+ 0 - 0
admin/templates/default/mb_special_item.edit.php


+ 0 - 0
admin/templates/default/mb_special_item.module_adv_list.php


+ 0 - 0
admin/templates/default/mb_special_item.module_goods.php


+ 54 - 54
admin/templates/default/mb_special_item.module_home5.php

@@ -1,54 +1,54 @@
-<?php defined('InShopNC') or exit('Access Invalid!');?>
-      <?php if($item_edit_flag) { ?>
-<table class="table tb-type2" id="prompt">
-    <tbody>
-      <tr class="space odd">
-        <th colspan="12" class="nobg"> <div class="title nomargin">
-            <h5><?php echo $lang['nc_prompts'];?></h5>
-            <span class="arrow"></span> </div>
-        </th>
-      </tr>
-      <tr>
-        <td><ul>
-            <li>鼠标移动到内容上出现编辑按钮可以对内容进行修改</li>
-            <li>操作完成后点击保存编辑按钮进行保存</li>
-          </ul></td>
-      </tr>
-    </tbody>
-  </table>
-  <?php } ?>
-<div class="index_block home5">
-      <?php if($item_edit_flag) { ?>
-  <h3>模型版块布局E</h3>
-  <?php } ?>
-  <div class="title">
-    <?php if($item_edit_flag) { ?>
-    <h5>标题:</h5>
-    <input id="home1_title" type="text" class="txt w200" name="item_data[title]" value="<?php echo $item_data['title'];?>">
-    <?php } else { ?>
-    <span><?php echo $item_data['title'];?></span>
-    <?php } ?>
-  </div>
-  <div nctype="item_content" class="content">
-    <?php if($item_edit_flag) { ?>
-      <h5>内容:</h5>
-    <?php } ?>
-    <?php if(!empty($item_data['item']) && is_array($item_data['item'])) {?>
-      <?php foreach($item_data['item'] as $item_key => $item_value) {?>
-        <div nctype="item_image" class="item"> <img nctype="image" src="<?php echo getMbSpecialImageUrl($item_value['image']);?>" alt="">
-          <?php if($item_edit_flag) { ?>
-            <input nctype="image_name" name="item_data[item][<?php echo $item_key;?>][image]" type="hidden" value="<?php echo $item_value['image'];?>">
-            <input nctype="image_type" name="item_data[item][<?php echo $item_key;?>][type]" type="hidden" value="<?php echo $item_value['type'];?>">
-            <input nctype="image_data" name="item_data[item][<?php echo $item_key;?>][data]" type="hidden" value="<?php echo $item_value['data'];?>">
-            <a nctype="btn_del_item_image" href="javascript:;" class="a1"><i class="icon-trash"></i>删除</a>
-            <a nctype="btn_edit_item_image" href="javascript:;" class="a2"><i class="icon-edit"></i>编辑</a>
-          <?php } ?>
-        </div>
-        <br>
-      <?php } ?>
-    <?php } ?>
-  </div>
-  <?php if($item_edit_flag) { ?>
-    <a nctype="btn_add_item_image" class="btn-add" data-desc="640*240" href="javascript:;">添加新的图片</a>
-  <?php } ?>
-</div>
+<?php defined('InShopNC') or exit('Access Invalid!');?>
+      <?php if($item_edit_flag) { ?>
+<table class="table tb-type2" id="prompt">
+    <tbody>
+      <tr class="space odd">
+        <th colspan="12" class="nobg"> <div class="title nomargin">
+            <h5><?php echo $lang['nc_prompts'];?></h5>
+            <span class="arrow"></span> </div>
+        </th>
+      </tr>
+      <tr>
+        <td><ul>
+            <li>鼠标移动到内容上出现编辑按钮可以对内容进行修改</li>
+            <li>操作完成后点击保存编辑按钮进行保存</li>
+          </ul></td>
+      </tr>
+    </tbody>
+  </table>
+  <?php } ?>
+<div class="index_block home5">
+      <?php if($item_edit_flag) { ?>
+  <h3>模型版块布局E</h3>
+  <?php } ?>
+  <div class="title">
+    <?php if($item_edit_flag) { ?>
+    <h5>标题:</h5>
+    <input id="home1_title" type="text" class="txt w200" name="item_data[title]" value="<?php echo $item_data['title'];?>">
+    <?php } else { ?>
+    <span><?php echo $item_data['title'];?></span>
+    <?php } ?>
+  </div>
+  <div nctype="item_content" class="content">
+    <?php if($item_edit_flag) { ?>
+      <h5>内容:</h5>
+    <?php } ?>
+    <?php if(!empty($item_data['item']) && is_array($item_data['item'])) {?>
+      <?php foreach($item_data['item'] as $item_key => $item_value) {?>
+        <div nctype="item_image" class="item"> <img nctype="image" src="<?php echo getMbSpecialImageUrl($item_value['image']);?>" alt="">
+          <?php if($item_edit_flag) { ?>
+            <input nctype="image_name" name="item_data[item][<?php echo $item_key;?>][image]" type="hidden" value="<?php echo $item_value['image'];?>">
+            <input nctype="image_type" name="item_data[item][<?php echo $item_key;?>][type]" type="hidden" value="<?php echo $item_value['type'];?>">
+            <input nctype="image_data" name="item_data[item][<?php echo $item_key;?>][data]" type="hidden" value="<?php echo $item_value['data'];?>">
+            <a nctype="btn_del_item_image" href="javascript:;" class="a1"><i class="icon-trash"></i>删除</a>
+            <a nctype="btn_edit_item_image" href="javascript:;" class="a2"><i class="icon-edit"></i>编辑</a>
+          <?php } ?>
+        </div>
+        <br>
+      <?php } ?>
+    <?php } ?>
+  </div>
+  <?php if($item_edit_flag) { ?>
+    <a nctype="btn_add_item_image" class="btn-add" data-desc="640*240" href="javascript:;">添加新的图片</a>
+  <?php } ?>
+</div>

+ 0 - 0
admin/templates/default/web_config.index.php


+ 0 - 0
admin/templates/default/web_focus.edit.php


+ 0 - 0
admin/templates/default/web_sale.edit.php


+ 3 - 3
admin/templates/default/web_upload_sale.php

@@ -1,4 +1,4 @@
-<?php defined('InShopNC') or exit('Access Invalid!');?>
-<script type="text/javascript">
-	parent.set_sale_img("<?php echo $output['pic_name'];?>");
+<?php defined('InShopNC') or exit('Access Invalid!');?>
+<script type="text/javascript">
+	parent.set_sale_img("<?php echo $output['pic_name'];?>");
 </script>

+ 2 - 2
alter.sql

@@ -1,2 +1,2 @@
-alter table 33hao.33hao_goods_common add `goods_mobile_name` varchar(50);
-alter table 33hao.33hao_goods add `goods_mobile_name` varchar(50);    
+alter table 33hao.33hao_goods_common add `goods_mobile_name` varchar(50);
+alter table 33hao.33hao_goods add `goods_mobile_name` varchar(50);    

+ 10 - 10
bat.sh

@@ -1,11 +1,11 @@
-
-#!/bin/bash
-
-date
-
-for k in $( seq 1 100 )
-do
-	php run.php
-done
-
+
+#!/bin/bash
+
+date
+
+for k in $( seq 1 100 )
+do
+	php run.php
+done
+
 date

+ 0 - 0
core/33hao.php


+ 0 - 0
core/framework/cache/cache.cacheredis.php


+ 0 - 0
core/framework/core/base.php


+ 0 - 0
core/framework/db/mysql.php


+ 0 - 0
core/framework/db/mysqli.php


+ 0 - 0
core/framework/function/build.php


+ 0 - 0
core/framework/function/ftp.php


+ 0 - 0
core/framework/function/goods.php


+ 95 - 95
core/framework/function/http.php

@@ -1,95 +1,95 @@
-<?php
-
-/**
- * http请求函数
- *
- * 
- *
- */
-
-defined('InShopNC') or exit('Access Invalid!');
-
-function http_request($url, $params = array(), $method = 'GET', $multi = false, $extheaders = array()) 
-{
-    if (!function_exists('curl_init')) {  
-        return NULL;
-    }
-
-    $method = strtoupper($method);
-    $ci = curl_init();
-    curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
-    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 3);
-    curl_setopt($ci, CURLOPT_TIMEOUT, 3);
-    curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
-    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
-    curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
-    curl_setopt($ci, CURLOPT_HEADER, false);
-    $headers = (array) $extheaders;
-    switch ($method) 
-    {
-        case 'POST':
-            curl_setopt($ci, CURLOPT_POST, TRUE);
-            if (!empty($params)) 
-            {
-                if ($multi) 
-                {
-                    foreach ($multi as $key => $file) {
-                        $params[$key] = '@' . $file;
-                    }
-                    curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
-                    $headers[] = 'Expect: ';
-                } 
-                else 
-                {
-                    curl_setopt($ci, CURLOPT_POSTFIELDS, http_build_query($params));
-                }
-            }
-            break;
-        case 'DELETE':
-        case 'GET':
-            $method == 'DELETE' && curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
-            if (!empty($params)) {
-                $url = $url . (strpos($url, '?') ? '&' : '?')
-                        . (is_array($params) ? http_build_query($params) : $params);
-            }
-            echo $url;
-            break;
-    }
-    curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
-    curl_setopt($ci, CURLOPT_URL, $url);
-    if ($headers) {
-        curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
-    }
-
-    $response = curl_exec($ci);
-    curl_close($ci);
-    return $response;
-}
-
-function http_post_data($url, $body, $headers = array())
-{
-    if (!function_exists('curl_init')) {
-        return NULL;
-    }
-
-    $ci = curl_init();
-    curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
-    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 3);
-    curl_setopt($ci, CURLOPT_TIMEOUT, 3);
-    curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
-    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
-    curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
-    curl_setopt($ci, CURLOPT_HEADER, false);
-
-    curl_setopt($ci, CURLOPT_POSTFIELDS, $body);
-
-    curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
-    curl_setopt($ci, CURLOPT_URL, $url);
-    if ($headers) {
-        curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
-    }
-
-    $response = curl_exec($ci);
-    curl_close($ci);
-    return $response;
-}
+<?php
+
+/**
+ * http请求函数
+ *
+ * 
+ *
+ */
+
+defined('InShopNC') or exit('Access Invalid!');
+
+function http_request($url, $params = array(), $method = 'GET', $multi = false, $extheaders = array()) 
+{
+    if (!function_exists('curl_init')) {  
+        return NULL;
+    }
+
+    $method = strtoupper($method);
+    $ci = curl_init();
+    curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
+    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 3);
+    curl_setopt($ci, CURLOPT_TIMEOUT, 3);
+    curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
+    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
+    curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
+    curl_setopt($ci, CURLOPT_HEADER, false);
+    $headers = (array) $extheaders;
+    switch ($method) 
+    {
+        case 'POST':
+            curl_setopt($ci, CURLOPT_POST, TRUE);
+            if (!empty($params)) 
+            {
+                if ($multi) 
+                {
+                    foreach ($multi as $key => $file) {
+                        $params[$key] = '@' . $file;
+                    }
+                    curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
+                    $headers[] = 'Expect: ';
+                } 
+                else 
+                {
+                    curl_setopt($ci, CURLOPT_POSTFIELDS, http_build_query($params));
+                }
+            }
+            break;
+        case 'DELETE':
+        case 'GET':
+            $method == 'DELETE' && curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
+            if (!empty($params)) {
+                $url = $url . (strpos($url, '?') ? '&' : '?')
+                        . (is_array($params) ? http_build_query($params) : $params);
+            }
+            echo $url;
+            break;
+    }
+    curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
+    curl_setopt($ci, CURLOPT_URL, $url);
+    if ($headers) {
+        curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
+    }
+
+    $response = curl_exec($ci);
+    curl_close($ci);
+    return $response;
+}
+
+function http_post_data($url, $body, $headers = array())
+{
+    if (!function_exists('curl_init')) {
+        return NULL;
+    }
+
+    $ci = curl_init();
+    curl_setopt($ci, CURLOPT_USERAGENT, 'PHP-SDK OAuth2.0');
+    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 3);
+    curl_setopt($ci, CURLOPT_TIMEOUT, 3);
+    curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
+    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
+    curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
+    curl_setopt($ci, CURLOPT_HEADER, false);
+
+    curl_setopt($ci, CURLOPT_POSTFIELDS, $body);
+
+    curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
+    curl_setopt($ci, CURLOPT_URL, $url);
+    if ($headers) {
+        curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
+    }
+
+    $response = curl_exec($ci);
+    curl_close($ci);
+    return $response;
+}

+ 0 - 0
core/framework/libraries/language.php


+ 0 - 0
core/framework/libraries/model.php


+ 0 - 0
core/framework/libraries/sms.php


+ 0 - 0
core/framework/libraries/tpl.php


+ 0 - 0
core/framework/libraries/validate.php


+ 0 - 0
core/lrlz.php


+ 126 - 126
crontab/crawl/body_filter.php

@@ -1,126 +1,126 @@
-
-<?php
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/1/21
- * Time: 下午3:34
- */
-
-
-class body_filder
-{
-    private $goods_common;
-    static $save_path = BASE_DATA_PATH . '/upload/detail';
-    static $down_path = BASE_DATA_PATH . '/Download/detail';
-
-    static $req_path = 'http://p.lrlz.com/data/upload/detail/';
-    //static $req_path = 'http://localhost/data/upload/detail/';
-
-    public function __construct()
-    {
-        $this->goods_common = Model('goods_common');
-    }
-
-    private function filter_gif($val)
-    {
-//        $style = '/\s+style\s*=\s*\"{1}[^\"]*\"{1}/i';
-//        $val = preg_replace($style,'',$val);
-
-        $gif = '/<img\s+[^>]*spaceball.gif\"[^>]*>/i';
-        $val = preg_replace($gif,'',$val);
-
-        return $val;
-    }
-
-    private function download($url,$path)
-    {
-        $info = pathinfo($url);
-
-        if(!file_exists($path)) {
-            $pic_url = $info['dirname'] . '/' . urlencode($info['basename']);
-            exec("wget -O $path $pic_url");
-        }
-
-        if(file_exists($path))
-        {
-            if(filesize($path) > 0) {
-                return true;
-            } else {
-                unlink($path);
-                return false;
-            }
-        } else {
-            return false;
-        }
-    }
-
-
-    //
-    private function filterex($val,$commid)
-    {
-        $style = '/\s*<img\s*[^>]*src\s*=\s*\"([^>\"]*)\"\s*[^>]*>/i';
-        $val = preg_match_all($style,$val,$match);
-        if(!empty($val) && $val > 0)
-        {
-            $html = '';
-            $num = 1;
-            foreach($match[1] as $url)
-            {
-                $info = pathinfo($url);
-                if(empty($info['extension'])) continue;
-
-                $name = md5($url) . '.' . $info['extension'];
-                $path = self::$down_path . '/' . $name;
-
-                if(file_exists($path) || $this->download($url,$path))
-                {
-                    $name = "{$commid}-{$num}.{$info['extension']}";
-                    $newpath = self::$save_path . "/{$name}";
-
-                    if(file_exists($newpath)) {
-                        unlink($newpath);
-                    }
-                    copy($path,$newpath);
-
-                    ++$num;
-                    $html .= "<img src=\"" . self::$req_path . "{$name}\">";
-                }
-            }
-
-            return $html;
-        } else {
-            return false;
-        }
-    }
-
-    public function fillbody()
-    {
-        $tm_goods = Model('tm_goods');
-
-        $items = $tm_goods->field('num_iid,description')->limit(false)->select();
-        foreach($items as $val)
-        {
-            $num_iid = $val['num_iid'];
-            $body = $val['description'];
-            $this->goods_common->where(array('num_iid' => $num_iid))->update(array('goods_body' => $body));
-        }
-    }
-
-    public function proc()
-    {
-        $goods = $this->goods_common->field('goods_commonid,goods_body')->limit(false)->select();
-        foreach($goods as $val)
-        {
-            $body = $val['goods_body'];
-            $comm_id = $val['goods_commonid'];
-            $body = $this->filter_gif($body);
-            $body = $this->filterex($body,$comm_id);
-            if(!empty($body)) {
-                $this->goods_common->where(array('goods_commonid' => $comm_id))->update(array('goods_body' => $body));
-            }
-        }
-    }
-}
-
-
+
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/1/21
+ * Time: 下午3:34
+ */
+
+
+class body_filder
+{
+    private $goods_common;
+    static $save_path = BASE_DATA_PATH . '/upload/detail';
+    static $down_path = BASE_DATA_PATH . '/Download/detail';
+
+    static $req_path = 'http://p.lrlz.com/data/upload/detail/';
+    //static $req_path = 'http://localhost/data/upload/detail/';
+
+    public function __construct()
+    {
+        $this->goods_common = Model('goods_common');
+    }
+
+    private function filter_gif($val)
+    {
+//        $style = '/\s+style\s*=\s*\"{1}[^\"]*\"{1}/i';
+//        $val = preg_replace($style,'',$val);
+
+        $gif = '/<img\s+[^>]*spaceball.gif\"[^>]*>/i';
+        $val = preg_replace($gif,'',$val);
+
+        return $val;
+    }
+
+    private function download($url,$path)
+    {
+        $info = pathinfo($url);
+
+        if(!file_exists($path)) {
+            $pic_url = $info['dirname'] . '/' . urlencode($info['basename']);
+            exec("wget -O $path $pic_url");
+        }
+
+        if(file_exists($path))
+        {
+            if(filesize($path) > 0) {
+                return true;
+            } else {
+                unlink($path);
+                return false;
+            }
+        } else {
+            return false;
+        }
+    }
+
+
+    //
+    private function filterex($val,$commid)
+    {
+        $style = '/\s*<img\s*[^>]*src\s*=\s*\"([^>\"]*)\"\s*[^>]*>/i';
+        $val = preg_match_all($style,$val,$match);
+        if(!empty($val) && $val > 0)
+        {
+            $html = '';
+            $num = 1;
+            foreach($match[1] as $url)
+            {
+                $info = pathinfo($url);
+                if(empty($info['extension'])) continue;
+
+                $name = md5($url) . '.' . $info['extension'];
+                $path = self::$down_path . '/' . $name;
+
+                if(file_exists($path) || $this->download($url,$path))
+                {
+                    $name = "{$commid}-{$num}.{$info['extension']}";
+                    $newpath = self::$save_path . "/{$name}";
+
+                    if(file_exists($newpath)) {
+                        unlink($newpath);
+                    }
+                    copy($path,$newpath);
+
+                    ++$num;
+                    $html .= "<img src=\"" . self::$req_path . "{$name}\">";
+                }
+            }
+
+            return $html;
+        } else {
+            return false;
+        }
+    }
+
+    public function fillbody()
+    {
+        $tm_goods = Model('tm_goods');
+
+        $items = $tm_goods->field('num_iid,description')->limit(false)->select();
+        foreach($items as $val)
+        {
+            $num_iid = $val['num_iid'];
+            $body = $val['description'];
+            $this->goods_common->where(array('num_iid' => $num_iid))->update(array('goods_body' => $body));
+        }
+    }
+
+    public function proc()
+    {
+        $goods = $this->goods_common->field('goods_commonid,goods_body')->limit(false)->select();
+        foreach($goods as $val)
+        {
+            $body = $val['goods_body'];
+            $comm_id = $val['goods_commonid'];
+            $body = $this->filter_gif($body);
+            $body = $this->filterex($body,$comm_id);
+            if(!empty($body)) {
+                $this->goods_common->where(array('goods_commonid' => $comm_id))->update(array('goods_body' => $body));
+            }
+        }
+    }
+}
+
+

+ 136 - 136
crontab/crawl/brand_operator.php

@@ -1,137 +1,137 @@
-<?php
-
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/1/14
- * Time: 下午6:10
- */
-class brand_operator
-{
-    private $tm_prop_values;
-    private $cls_tree;
-    private $mod_brand;
-    private $tm_goods;
-    private $mod_goods_common;
-    private $mod_goods;
-
-    const brand_pid = 20000;
-
-    public function __construct()
-    {
-        $this->tm_goods = Model('tm_goods');
-        $this->tm_prop_values = Model('tm_prop_values');
-        $this->cls_tree = new class_tree();
-        $this->mod_brand = Model('brand');
-        $this->mod_goods_common = Model('goods_common');
-        $this->mod_goods = Model('goods');
-    }
-
-    private function brand_exist($name)
-    {
-        $result = $this->mod_brand->field('brand_id')->where(array('brand_tm_name' => array('like',"%{$name}%")))->select();
-
-        if(empty($result) || count($result) == 0) {
-            return false;
-        } else {
-            return true;
-        }
-    }
-
-    public function create()
-    {
-        $brands = $this->tm_prop_values->field('id,cid,name')->where(array('pid' => self::brand_pid))->group('name')->select();
-
-        foreach($brands as $val)
-        {
-            $name = $val['name'];
-            $cid = $val['cid'];
-            if($this->brand_exist($name)) continue;
-
-            if($this->cls_tree->get_info($cid,$c_1,$c_2,$c_3,$cls_name))
-            {
-                $ret = $this->mod_brand->insert(array('brand_name' => $name,'brand_tm_name' => $name,'brand_class' => $cls_name));
-                if($ret == false) {
-                    Log::record("insert brand error brand_name = brand_tm_name = {$name}",Log::ERR);
-                } else {
-                    Log::record("brand_name = {$name} brand_class = {$cls_name}.",Log::DEBUG);
-                }
-            }
-        }
-    }
-
-    private function get_brand($propnames,&$brand_name)
-    {
-        $ret = $this->brand_name($propnames);
-        if(!array_key_exists(self::brand_pid,$ret)) {
-            return false;
-        } else {
-            foreach($ret[self::brand_pid]['val'] as $key => $val) {
-                $brand_name = $val;
-                break;
-            }
-        }
-        if(isset($brand_name) && !empty($brand_name))
-        {
-            $result = $this->mod_brand->where(array('brand_tm_name' => array('like',"%{$brand_name}%")))->select();
-            if(!empty($result) && count($result) > 0) {
-                return $result[0]['brand_id'];
-            }
-        }
-
-        return false;
-    }
-
-
-
-    public function update_brand()
-    {
-        $results = $this->tm_goods->field('body,title,num_iid')->limit(false)->select();
-        foreach ($results as $result)
-        {
-            $num_iid = $result['num_iid'];
-            $body = $result['body'];
-            $response = json_decode($body, true);
-            $item = $response['item_seller_get_response']['item'];
-            $props_name = $item['props_name'];
-            $brand_id = $this->get_brand($props_name,$brand_name);
-
-            if($brand_id)
-            {
-                $ret = $this->mod_goods_common->where(array('num_iid' => $num_iid))->update(array('brand_id' => $brand_id,'brand_name' => $brand_name));
-                if($ret == false) {
-                    Log::record("update goods_common brand error: num_iid={$num_iid},brand_id={$brand_id},brand_name={$brand_name}");
-                } else {
-                    $ret = $this->mod_goods->where(array('num_iid' => $num_iid))->update(array('brand_id' => $brand_id));
-                }
-            } else {
-                Log::record("update goods_common brand error: cannot find brand_id num_iid={$num_iid}");
-            }
-        }
-    }
-
-    /**
-     * @param $propnames
-     * @return array
-     */
-    private function brand_name($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;
-    }
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/1/14
+ * Time: 下午6:10
+ */
+class brand_operator
+{
+    private $tm_prop_values;
+    private $cls_tree;
+    private $mod_brand;
+    private $tm_goods;
+    private $mod_goods_common;
+    private $mod_goods;
+
+    const brand_pid = 20000;
+
+    public function __construct()
+    {
+        $this->tm_goods = Model('tm_goods');
+        $this->tm_prop_values = Model('tm_prop_values');
+        $this->cls_tree = new class_tree();
+        $this->mod_brand = Model('brand');
+        $this->mod_goods_common = Model('goods_common');
+        $this->mod_goods = Model('goods');
+    }
+
+    private function brand_exist($name)
+    {
+        $result = $this->mod_brand->field('brand_id')->where(array('brand_tm_name' => array('like',"%{$name}%")))->select();
+
+        if(empty($result) || count($result) == 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public function create()
+    {
+        $brands = $this->tm_prop_values->field('id,cid,name')->where(array('pid' => self::brand_pid))->group('name')->select();
+
+        foreach($brands as $val)
+        {
+            $name = $val['name'];
+            $cid = $val['cid'];
+            if($this->brand_exist($name)) continue;
+
+            if($this->cls_tree->get_info($cid,$c_1,$c_2,$c_3,$cls_name))
+            {
+                $ret = $this->mod_brand->insert(array('brand_name' => $name,'brand_tm_name' => $name,'brand_class' => $cls_name));
+                if($ret == false) {
+                    Log::record("insert brand error brand_name = brand_tm_name = {$name}",Log::ERR);
+                } else {
+                    Log::record("brand_name = {$name} brand_class = {$cls_name}.",Log::DEBUG);
+                }
+            }
+        }
+    }
+
+    private function get_brand($propnames,&$brand_name)
+    {
+        $ret = $this->brand_name($propnames);
+        if(!array_key_exists(self::brand_pid,$ret)) {
+            return false;
+        } else {
+            foreach($ret[self::brand_pid]['val'] as $key => $val) {
+                $brand_name = $val;
+                break;
+            }
+        }
+        if(isset($brand_name) && !empty($brand_name))
+        {
+            $result = $this->mod_brand->where(array('brand_tm_name' => array('like',"%{$brand_name}%")))->select();
+            if(!empty($result) && count($result) > 0) {
+                return $result[0]['brand_id'];
+            }
+        }
+
+        return false;
+    }
+
+
+
+    public function update_brand()
+    {
+        $results = $this->tm_goods->field('body,title,num_iid')->limit(false)->select();
+        foreach ($results as $result)
+        {
+            $num_iid = $result['num_iid'];
+            $body = $result['body'];
+            $response = json_decode($body, true);
+            $item = $response['item_seller_get_response']['item'];
+            $props_name = $item['props_name'];
+            $brand_id = $this->get_brand($props_name,$brand_name);
+
+            if($brand_id)
+            {
+                $ret = $this->mod_goods_common->where(array('num_iid' => $num_iid))->update(array('brand_id' => $brand_id,'brand_name' => $brand_name));
+                if($ret == false) {
+                    Log::record("update goods_common brand error: num_iid={$num_iid},brand_id={$brand_id},brand_name={$brand_name}");
+                } else {
+                    $ret = $this->mod_goods->where(array('num_iid' => $num_iid))->update(array('brand_id' => $brand_id));
+                }
+            } else {
+                Log::record("update goods_common brand error: cannot find brand_id num_iid={$num_iid}");
+            }
+        }
+    }
+
+    /**
+     * @param $propnames
+     * @return array
+     */
+    private function brand_name($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;
+    }
 }

+ 129 - 129
crontab/crawl/category.php

@@ -1,129 +1,129 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 15/11/3
- * Time: 下午7:22
- */
-
-class category
-{
-    private $tm_cats;
-    private $goods_class;
-    private $tm_goods;
-
-    public function __construct()
-    {
-        $this->tm_cats = Model('tm_cats');
-        $this->goods_class = Model('goods_class');
-        $this->tm_goods = Model('tm_goods');
-    }
-
-    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->goods_class->insert($item);
-            $cids[] = (int)$val['cid'];
-        }
-
-        return $cids;
-    }
-
-    private function insert_all($pcids)
-    {
-        if(empty($pcids)) return;
-
-        foreach ($pcids as $pcid) {
-            $datas = $this->tm_cats->field('*')->limit(false)->where(array('parent_cid'=> $pcid))->select();
-            $cids = $this->insert($datas);
-
-            $this->insert_all($cids);
-        }
-    }
-
-    private function get_cids()
-    {
-        $items = $this->tm_goods->group('cid')->field('cid')->limit(false)->select();
-
-        $cids = array();
-        foreach($items as $val) {
-            array_push($cids,$val['cid']);
-        }
-        return $cids;
-    }
-    public function proc()
-    {
-        $cids = $this->get_cids();
-        foreach($cids as $cid) {
-            $this->import_leaf($cid);
-        }
-    }
-
-    private function get_goods_cidinfo($cid)
-    {
-        $items = $this->goods_class->field('*')->where(array('gc_id' => $cid))->limit(false)->select();
-
-        if(empty($items)) {
-            return NULL;
-        } else {
-            return $items[0];
-        }
-    }
-
-    private function get_tm_cidinfo($cid)
-    {
-        $items = $this->tm_cats->field('*')->where(array('cid' => $cid))->limit(false)->select();
-
-        if(empty($items)) {
-            return NULL;
-        } else {
-            return $items[0];
-        }
-    }
-
-    private function import_leaf($cid)
-    {
-        if($cid == 0 || !empty($this->get_goods_cidinfo($cid))) {
-            return;
-        }
-        else
-        {
-            $val = $this->get_tm_cidinfo($cid);
-
-            $item['gc_id'] = $val['cid'];
-            $item['gc_name'] = $val['name'];
-            $item['gc_parent_id'] = $val['parent_cid'];
-            $item['commis_rate'] = 0;
-            $item['gc_sort'] = $val['sort_order'];
-            $item['gc_virtual'] = 0;
-
-            $id = $this->goods_class->insert($item);
-            if($id == false) {
-                Log::record("insert cid = {$cid} error.",Log::ERR);
-            }
-            $this->import_leaf($item['gc_parent_id']);
-        }
-    }
-
-    public function procex()
-    {
-        if(empty($this->topcats)) return;
-
-        foreach ($this->topcats as $cid) {
-            $datas = $this->tm_cats->field('*')->limit(false)->where(array('cid'=>$cid,'parent_cid'=> 0))->select();
-            $this->insert($datas);
-        }
-
-        $this->insert_all($this->topcats);
-    }
-}
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/3
+ * Time: 下午7:22
+ */
+
+class category
+{
+    private $tm_cats;
+    private $goods_class;
+    private $tm_goods;
+
+    public function __construct()
+    {
+        $this->tm_cats = Model('tm_cats');
+        $this->goods_class = Model('goods_class');
+        $this->tm_goods = Model('tm_goods');
+    }
+
+    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->goods_class->insert($item);
+            $cids[] = (int)$val['cid'];
+        }
+
+        return $cids;
+    }
+
+    private function insert_all($pcids)
+    {
+        if(empty($pcids)) return;
+
+        foreach ($pcids as $pcid) {
+            $datas = $this->tm_cats->field('*')->limit(false)->where(array('parent_cid'=> $pcid))->select();
+            $cids = $this->insert($datas);
+
+            $this->insert_all($cids);
+        }
+    }
+
+    private function get_cids()
+    {
+        $items = $this->tm_goods->group('cid')->field('cid')->limit(false)->select();
+
+        $cids = array();
+        foreach($items as $val) {
+            array_push($cids,$val['cid']);
+        }
+        return $cids;
+    }
+    public function proc()
+    {
+        $cids = $this->get_cids();
+        foreach($cids as $cid) {
+            $this->import_leaf($cid);
+        }
+    }
+
+    private function get_goods_cidinfo($cid)
+    {
+        $items = $this->goods_class->field('*')->where(array('gc_id' => $cid))->limit(false)->select();
+
+        if(empty($items)) {
+            return NULL;
+        } else {
+            return $items[0];
+        }
+    }
+
+    private function get_tm_cidinfo($cid)
+    {
+        $items = $this->tm_cats->field('*')->where(array('cid' => $cid))->limit(false)->select();
+
+        if(empty($items)) {
+            return NULL;
+        } else {
+            return $items[0];
+        }
+    }
+
+    private function import_leaf($cid)
+    {
+        if($cid == 0 || !empty($this->get_goods_cidinfo($cid))) {
+            return;
+        }
+        else
+        {
+            $val = $this->get_tm_cidinfo($cid);
+
+            $item['gc_id'] = $val['cid'];
+            $item['gc_name'] = $val['name'];
+            $item['gc_parent_id'] = $val['parent_cid'];
+            $item['commis_rate'] = 0;
+            $item['gc_sort'] = $val['sort_order'];
+            $item['gc_virtual'] = 0;
+
+            $id = $this->goods_class->insert($item);
+            if($id == false) {
+                Log::record("insert cid = {$cid} error.",Log::ERR);
+            }
+            $this->import_leaf($item['gc_parent_id']);
+        }
+    }
+
+    public function procex()
+    {
+        if(empty($this->topcats)) return;
+
+        foreach ($this->topcats as $cid) {
+            $datas = $this->tm_cats->field('*')->limit(false)->where(array('cid'=>$cid,'parent_cid'=> 0))->select();
+            $this->insert($datas);
+        }
+
+        $this->insert_all($this->topcats);
+    }
+}

+ 111 - 111
crontab/crawl/class_tree.php

@@ -1,112 +1,112 @@
-<?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];
-
-        if(empty($info)) {
-            return false;
-        }
-        $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);
-
-        return true;
-    }
-
-    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;
-    }
+<?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];
+
+        if(empty($info)) {
+            return false;
+        }
+        $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);
+
+        return true;
+    }
+
+    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;
+    }
 }

+ 18 - 18
crontab/crawl/fetch_config.php

@@ -1,18 +1,18 @@
-<?php
-
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/1/18
- * Time: 下午8:00
- */
-
-class fetch_config
-{
-    const store_name = '熊猫美妆';
-    //const store_id = 3;
-    const store_id = 6;
-    const goods_state = 0;
-    //const tmp_file = '/private/var/tmp/phpxxkkdl';
-    const tmp_file = '/tmp/phpxxkkdl';
-}
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/1/18
+ * Time: 下午8:00
+ */
+
+class fetch_config
+{
+    const store_name = '熊猫美妆';
+    //const store_id = 3;
+    const store_id = 6;
+    const goods_state = 0;
+    //const tmp_file = '/private/var/tmp/phpxxkkdl';
+    const tmp_file = '/tmp/phpxxkkdl';
+}

+ 84 - 84
crontab/crawl/fetch_goods.php

@@ -1,84 +1,84 @@
-<?php
-
-define('InShopNC',true);
-defined('InShopNC') or exit('Access Invalid!');
-
-require_once (BASE_DATA_PATH . '/api/taobao/TopSdk.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/TopClient.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/ResultSet.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/RequestCheckUtil.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/TopLogger.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/SpiUtils.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/ApplicationVar.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/HttpdnsGetRequest.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/request/ItemSellerGetRequest.php');
-require_once (BASE_DATA_PATH . '/api/taobao/top/request/ItemsOnsaleGetRequest.php');
-
-require_once (BASE_CRONTAB_PATH . '/crawl/fetch_config.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/spec_attr_parser.php');
-require_once (BASE_CRONTAB_PATH . '/crawl/upload_file.php');
-require_once (BASE_CRONTAB_PATH . '/crawl/upload_control.php');
-require_once (BASE_CRONTAB_PATH . '/crawl/tm_pagereq.php');
-require_once(BASE_CRONTAB_PATH . '/crawl/brand_operator.php');
-require_once(BASE_CRONTAB_PATH . '/crawl/importer_check.php');
-require_once(BASE_CRONTAB_PATH . '/crawl/body_filter.php');
-
-
-
-
-
-//require_once (BASE_CORE_PATH . '/framework/libraries/uploadfile.php');
-//require_once (BASE_CRONTAB_PATH . '/crawl/skumatcher.php');
-
-
-date_default_timezone_set('Asia/Shanghai');
-
-function is_excids($cid)
-{
-    //50023728 赠品
-    //50023725 邮费
-    //50025832 搭配商品
-    static $cids = array(50023725,50023728,50025832,121284001,50011150);
-    return in_array($cid,$cids);
-}
-
-function not_null($str)
-{
-    return (empty($str)) ? '' : $str;
-}
-
-//$tmreq = new tmrequest();
-//$tmreq->proc();
-
-
-//
-//$cat = new category();
-//$cat->proc();
-//
-//$treater = new pretreat_tmdata();
-//$treater->proc(false);
-//
-//
-//$spec = new spec_attr_parser();
-//$spec->proc();
-//
-//$importer = new product_importer();
-//$importer->proc_shop();
-
-//$brander = new brand_operator();
-//$brander->create();
-//$brander->update_brand();
-
-//$ichecker = new importer_check();
-//$ichecker->proc();
-
-$filter = new body_filder();
-$filter->fillbody();
-$filter->proc();
+<?php
+
+define('InShopNC',true);
+defined('InShopNC') or exit('Access Invalid!');
+
+require_once (BASE_DATA_PATH . '/api/taobao/TopSdk.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/TopClient.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/ResultSet.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/RequestCheckUtil.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/TopLogger.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/SpiUtils.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/ApplicationVar.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/HttpdnsGetRequest.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/request/ItemSellerGetRequest.php');
+require_once (BASE_DATA_PATH . '/api/taobao/top/request/ItemsOnsaleGetRequest.php');
+
+require_once (BASE_CRONTAB_PATH . '/crawl/fetch_config.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/spec_attr_parser.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/upload_file.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/upload_control.php');
+require_once (BASE_CRONTAB_PATH . '/crawl/tm_pagereq.php');
+require_once(BASE_CRONTAB_PATH . '/crawl/brand_operator.php');
+require_once(BASE_CRONTAB_PATH . '/crawl/importer_check.php');
+require_once(BASE_CRONTAB_PATH . '/crawl/body_filter.php');
+
+
+
+
+
+//require_once (BASE_CORE_PATH . '/framework/libraries/uploadfile.php');
+//require_once (BASE_CRONTAB_PATH . '/crawl/skumatcher.php');
+
+
+date_default_timezone_set('Asia/Shanghai');
+
+function is_excids($cid)
+{
+    //50023728 赠品
+    //50023725 邮费
+    //50025832 搭配商品
+    static $cids = array(50023725,50023728,50025832,121284001,50011150);
+    return in_array($cid,$cids);
+}
+
+function not_null($str)
+{
+    return (empty($str)) ? '' : $str;
+}
+
+//$tmreq = new tmrequest();
+//$tmreq->proc();
+
+
+//
+//$cat = new category();
+//$cat->proc();
+//
+//$treater = new pretreat_tmdata();
+//$treater->proc(false);
+//
+//
+//$spec = new spec_attr_parser();
+//$spec->proc();
+//
+//$importer = new product_importer();
+//$importer->proc_shop();
+
+//$brander = new brand_operator();
+//$brander->create();
+//$brander->update_brand();
+
+//$ichecker = new importer_check();
+//$ichecker->proc();
+
+$filter = new body_filder();
+$filter->fillbody();
+$filter->proc();

+ 110 - 110
crontab/crawl/importer_check.php

@@ -1,111 +1,111 @@
-<?php
-
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/1/19
- * Time: 下午10:50
- */
-class importer_check
-{
-    private $goods;
-    private $goods_common;
-    private $goods_images;
-    private $album_pic;
-
-    public function __construct()
-    {
-        $this->goods = Model('goods');
-        $this->goods_common = Model('goods_common');
-        $this->goods_images = Model('goods_images');
-        $this->album_pic = Model('album_pic');
-    }
-
-    private function check_goods($comm_id)
-    {
-        $goods = $this->goods->field('goods_id,color_id')->where(array('goods_commonid' => $comm_id))->limit(false)->select();
-        if(empty($goods)) {
-            return false;
-        }
-
-        if(count($goods) == 0) {
-            return false;
-        }
-
-        return $goods;
-    }
-
-    private function check_goods_common($comm_id)
-    {
-        $goods = $this->goods_common->field('goods_commonid')->where(array('goods_commonid' => $comm_id))->select();
-        if(empty($goods)) {
-            return false;
-        }
-
-        if(count($goods) == 0) {
-            return false;
-        }
-
-        return $goods;
-    }
-
-    private function check_images($comm_id)
-    {
-        $goods = $this->goods_images->field('goods_image_id,color_id')->where(array('goods_commonid' => $comm_id))->group('filesig')->limit(false)->select();
-        if(empty($goods)) {
-            return false;
-        }
-
-        if(count($goods) == 0) {
-            return false;
-        }
-
-        return $goods;
-    }
-
-    public function proc()
-    {
-        $commonids = $this->goods_common->field('goods_commonid')->limit(false)->select();
-        if(empty($commonids)) {
-            Log::record("cannot find any goods from goods_common table.",Log::DEBUG);
-            return;
-        }
-
-        foreach($commonids as $val)
-        {
-            $cid = $val['goods_commonid'];
-            $goods = $this->check_goods($cid);
-            $images = $this->check_images($cid);
-
-            if($goods == false || $images == false) {
-                $this->goods_common->where(array('goods_commonid' => $cid))->delete();
-                $this->goods->where(array('goods_commonid' => $cid))->delete();
-                $this->goods_images->where(array('goods_commonid' => $cid))->delete();
-
-                Log::record("delete goods when goods_commonid = {$cid}",Log::DEBUG);
-            }
-        }
-
-        $commonids = $this->goods->field('goods_commonid')->group('goods_commonid')->limit(false)->select();
-
-        if(empty($commonids)) {
-            Log::record("cannot find any goods_commonid from goods table.",Log::DEBUG);
-            return;
-        }
-
-        foreach($commonids as $val)
-        {
-            $cid = $val['goods_commonid'];
-            $goods  = $this->check_goods_common($cid);
-            $images = $this->check_images($cid);
-
-            if($goods == false || $images == false) {
-                $this->goods_common->where(array('goods_commonid' => $cid))->delete();
-                $this->goods->where(array('goods_commonid' => $cid))->delete();
-                $this->goods_images->where(array('goods_commonid' => $cid))->delete();
-
-                Log::record("delete goods when goods_commonid = {$cid}",Log::DEBUG);
-            }
-        }
-    }
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/1/19
+ * Time: 下午10:50
+ */
+class importer_check
+{
+    private $goods;
+    private $goods_common;
+    private $goods_images;
+    private $album_pic;
+
+    public function __construct()
+    {
+        $this->goods = Model('goods');
+        $this->goods_common = Model('goods_common');
+        $this->goods_images = Model('goods_images');
+        $this->album_pic = Model('album_pic');
+    }
+
+    private function check_goods($comm_id)
+    {
+        $goods = $this->goods->field('goods_id,color_id')->where(array('goods_commonid' => $comm_id))->limit(false)->select();
+        if(empty($goods)) {
+            return false;
+        }
+
+        if(count($goods) == 0) {
+            return false;
+        }
+
+        return $goods;
+    }
+
+    private function check_goods_common($comm_id)
+    {
+        $goods = $this->goods_common->field('goods_commonid')->where(array('goods_commonid' => $comm_id))->select();
+        if(empty($goods)) {
+            return false;
+        }
+
+        if(count($goods) == 0) {
+            return false;
+        }
+
+        return $goods;
+    }
+
+    private function check_images($comm_id)
+    {
+        $goods = $this->goods_images->field('goods_image_id,color_id')->where(array('goods_commonid' => $comm_id))->group('filesig')->limit(false)->select();
+        if(empty($goods)) {
+            return false;
+        }
+
+        if(count($goods) == 0) {
+            return false;
+        }
+
+        return $goods;
+    }
+
+    public function proc()
+    {
+        $commonids = $this->goods_common->field('goods_commonid')->limit(false)->select();
+        if(empty($commonids)) {
+            Log::record("cannot find any goods from goods_common table.",Log::DEBUG);
+            return;
+        }
+
+        foreach($commonids as $val)
+        {
+            $cid = $val['goods_commonid'];
+            $goods = $this->check_goods($cid);
+            $images = $this->check_images($cid);
+
+            if($goods == false || $images == false) {
+                $this->goods_common->where(array('goods_commonid' => $cid))->delete();
+                $this->goods->where(array('goods_commonid' => $cid))->delete();
+                $this->goods_images->where(array('goods_commonid' => $cid))->delete();
+
+                Log::record("delete goods when goods_commonid = {$cid}",Log::DEBUG);
+            }
+        }
+
+        $commonids = $this->goods->field('goods_commonid')->group('goods_commonid')->limit(false)->select();
+
+        if(empty($commonids)) {
+            Log::record("cannot find any goods_commonid from goods table.",Log::DEBUG);
+            return;
+        }
+
+        foreach($commonids as $val)
+        {
+            $cid = $val['goods_commonid'];
+            $goods  = $this->check_goods_common($cid);
+            $images = $this->check_images($cid);
+
+            if($goods == false || $images == false) {
+                $this->goods_common->where(array('goods_commonid' => $cid))->delete();
+                $this->goods->where(array('goods_commonid' => $cid))->delete();
+                $this->goods_images->where(array('goods_commonid' => $cid))->delete();
+
+                Log::record("delete goods when goods_commonid = {$cid}",Log::DEBUG);
+            }
+        }
+    }
 }

+ 125 - 125
crontab/crawl/page_request.php

@@ -1,125 +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;
-    }
-}
+<?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;
+    }
+}

+ 267 - 267
crontab/crawl/pretreat_tmdata.php

@@ -1,268 +1,268 @@
-<?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;
-    private $cls_tree;
-
-    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');
-        $this->cls_tree = new class_tree();
-    }
-
-    public function proc()
-    {
-        $this->tm_spec->where(array('num_iid > 0'))->delete(); //->where(array('imported' => 0))
-        $results = $this->tm_goods->field('body,title,num_iid')->limit(false)->select();
-        foreach ($results as $result) {
-            $num_iid = $result['num_iid'];
-            $body = $result['body'];
-            $response = json_decode($body, true);
-            $item = $response['item_seller_get_response']['item'];
-
-            $cid = $item['cid'];
-            if(is_excids($cid)) continue;
-
-            $this->parse_tm_product($item);
-
-            //下载图片,并确认图片数量,用于验证后面商品是否成功导入
-            $picnum = 0;
-            $this->parse_tm_pic($item,$picnum);
-            $this->tm_goods->where(array('num_iid' => $num_iid))->update(array('picnum' => $picnum));
-        }
-    }
-
-    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)
-    {
-        static $pngext = array('png');
-
-        $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");
-        }
-
-        if(file_exists($path))
-        {
-            $fh = fopen($path, "rb");
-            $head = fread($fh, 8);
-            fclose($fh);
-
-            if(empty($head)) {
-                unlink($path);
-                Log::record("{$path} file is empty.",Log::ERR);
-                return false;
-            }
-
-            if(!in_array($info['extension'],$pngext))
-            {
-                $arr = unpack("C4", $head);
-                if($arr[1] == 137 &&  $arr[2] == 80 && $arr[3] == 78 && $arr[4] == 71) {
-                    Log::record("{$path} is a png file",Log::ERR);
-                }
-            }
-
-            return true;
-        } else {
-            return false;
-        }
-    }
-
-    private function parse_tm_pic($item,&$npics)
-    {
-        $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);
-        }
-
-        $prop_imgs = $item['prop_imgs']['prop_img'];
-        if(!empty($prop_imgs))
-        {
-            foreach($prop_imgs as $img) {
-                $url = $img['url'];
-                array_push($pics,$url);
-            }
-        }
-
-        $arpic = array();
-        foreach($pics as $pic)
-        {
-            $name = md5($pic);
-            if(array_key_exists($name,$arpic) == false)
-            {
-                if($this->download($pic)) {
-                    $arpic[$name] = 1;
-                } else {
-                    Log::record("download pic {$pic}.",Log::ERR);
-                }
-            } else {
-                //$arpic[$name] += 1;
-            }
-        }
-
-        foreach($arpic as $key => $val) {
-            $npics += $val;
-        }
-    }
-
-    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);
-                }
-            }
-        }
-    }
+<?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;
+    private $cls_tree;
+
+    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');
+        $this->cls_tree = new class_tree();
+    }
+
+    public function proc()
+    {
+        $this->tm_spec->where(array('num_iid > 0'))->delete(); //->where(array('imported' => 0))
+        $results = $this->tm_goods->field('body,title,num_iid')->limit(false)->select();
+        foreach ($results as $result) {
+            $num_iid = $result['num_iid'];
+            $body = $result['body'];
+            $response = json_decode($body, true);
+            $item = $response['item_seller_get_response']['item'];
+
+            $cid = $item['cid'];
+            if(is_excids($cid)) continue;
+
+            $this->parse_tm_product($item);
+
+            //下载图片,并确认图片数量,用于验证后面商品是否成功导入
+            $picnum = 0;
+            $this->parse_tm_pic($item,$picnum);
+            $this->tm_goods->where(array('num_iid' => $num_iid))->update(array('picnum' => $picnum));
+        }
+    }
+
+    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)
+    {
+        static $pngext = array('png');
+
+        $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");
+        }
+
+        if(file_exists($path))
+        {
+            $fh = fopen($path, "rb");
+            $head = fread($fh, 8);
+            fclose($fh);
+
+            if(empty($head)) {
+                unlink($path);
+                Log::record("{$path} file is empty.",Log::ERR);
+                return false;
+            }
+
+            if(!in_array($info['extension'],$pngext))
+            {
+                $arr = unpack("C4", $head);
+                if($arr[1] == 137 &&  $arr[2] == 80 && $arr[3] == 78 && $arr[4] == 71) {
+                    Log::record("{$path} is a png file",Log::ERR);
+                }
+            }
+
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    private function parse_tm_pic($item,&$npics)
+    {
+        $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);
+        }
+
+        $prop_imgs = $item['prop_imgs']['prop_img'];
+        if(!empty($prop_imgs))
+        {
+            foreach($prop_imgs as $img) {
+                $url = $img['url'];
+                array_push($pics,$url);
+            }
+        }
+
+        $arpic = array();
+        foreach($pics as $pic)
+        {
+            $name = md5($pic);
+            if(array_key_exists($name,$arpic) == false)
+            {
+                if($this->download($pic)) {
+                    $arpic[$name] = 1;
+                } else {
+                    Log::record("download pic {$pic}.",Log::ERR);
+                }
+            } else {
+                //$arpic[$name] += 1;
+            }
+        }
+
+        foreach($arpic as $key => $val) {
+            $npics += $val;
+        }
+    }
+
+    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);
+                }
+            }
+        }
+    }
 }

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 671 - 671
crontab/crawl/product_importer.php


+ 45 - 45
crontab/crawl/product_item.php

@@ -1,45 +1,45 @@
-<?php
-
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 15/11/3
- * Time: 下午8:29
- */
-
-//server
-
-class product_item
-{
-    private $mod_spec_ex;
-
-    public function __construct()
-    {
-        $this->mod_spec_ex = Model("spec_ex");
-    }
-
-    public function proc_item()
-    {
-    }
-
-    protected function  xxx()
-    {
-
-    }
-}
-
-class B extends product_item
-{
-
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-}
-
-//client
-
-$x = new product_item;
-$x->proc_item();
-
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/3
+ * Time: 下午8:29
+ */
+
+//server
+
+class product_item
+{
+    private $mod_spec_ex;
+
+    public function __construct()
+    {
+        $this->mod_spec_ex = Model("spec_ex");
+    }
+
+    public function proc_item()
+    {
+    }
+
+    protected function  xxx()
+    {
+
+    }
+}
+
+class B extends product_item
+{
+
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+}
+
+//client
+
+$x = new product_item;
+$x->proc_item();
+

+ 85 - 85
crontab/crawl/skumatcher.php

@@ -1,85 +1,85 @@
-<?php
-
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/1/9
- * Time: 下午1:35
- */
-class skumatcher
-{
-    private $input_file;
-    private $good_file;
-    private $err_file;
-    private $mod_goods_common;
-    private $mod_goods;
-
-    public function __construct($input)
-    {
-        if(file_exists($input) == false) {
-            throw new Exception("no such file {$input}.");
-        }
-
-        $this->input_file = new SplFileObject($input);
-        $this->input_file->setFlags(SplFileObject::READ_CSV | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE);
-        $this->good_file = new SplFileObject("./good.csv","a");
-        $this->err_file = new SplFileObject("./err.csv","a");
-
-        $this->mod_goods_common = Model('goods_common');
-        $this->mod_goods = Model('goods');
-    }
-
-    public function proc()
-    {
-        foreach($this->input_file as $line)
-        {
-            $this->parase_one($line[0]);
-        }
-    }
-
-    private function match_item($name)
-    {
-        $items = $this->mod_goods_common->field('goods_commonid,goods_name')->where(array('goods_name' => $name))->select();
-        if(empty($items)) {
-            $con['goods_name'] = array('like',"%{$name}%");
-            $items = $this->mod_goods_common->field('goods_commonid,goods_name')->where($con)->select();
-        }
-        if(empty($items)) {
-            $len = mb_strlen($name);
-            $name_x = mb_substr($name,0,$len / 2);
-            $con['goods_name'] = array('like',"%{$name_x}%");
-            $items = $this->mod_goods_common->field('goods_commonid,goods_name')->where($con)->select();
-        }
-
-        return $items;
-    }
-
-    private function parase_one($name)
-    {
-        $items = $this->match_item($name);
-
-        if(empty($items)) {
-            $fields = array($name);
-            $this->err_file->fputcsv($fields,',');
-            return;
-        }
-        $goods_commonid = $items[0]['goods_commonid'];
-        $goods = $this->mod_goods->field('*')->where(array('goods_commonid' => $goods_commonid))->limit(false)->select();
-        if(empty(goods)) {
-            $fields = array($name);
-            $this->err_file->fputcsv($fields,',');
-            return;
-        }
-
-        foreach($goods as $val)
-        {
-            $fields = array($val['goods_name'],$val['goods_serial_tm'],$val['num_iid']);
-            $this->good_file->fputcsv($fields,',');
-        }
-    }
-}
-
-
-$matcher =  new skumatcher('/Users/stanley-king/Desktop/name.csv');
-$matcher->proc();
-
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/1/9
+ * Time: 下午1:35
+ */
+class skumatcher
+{
+    private $input_file;
+    private $good_file;
+    private $err_file;
+    private $mod_goods_common;
+    private $mod_goods;
+
+    public function __construct($input)
+    {
+        if(file_exists($input) == false) {
+            throw new Exception("no such file {$input}.");
+        }
+
+        $this->input_file = new SplFileObject($input);
+        $this->input_file->setFlags(SplFileObject::READ_CSV | SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY | SplFileObject::DROP_NEW_LINE);
+        $this->good_file = new SplFileObject("./good.csv","a");
+        $this->err_file = new SplFileObject("./err.csv","a");
+
+        $this->mod_goods_common = Model('goods_common');
+        $this->mod_goods = Model('goods');
+    }
+
+    public function proc()
+    {
+        foreach($this->input_file as $line)
+        {
+            $this->parase_one($line[0]);
+        }
+    }
+
+    private function match_item($name)
+    {
+        $items = $this->mod_goods_common->field('goods_commonid,goods_name')->where(array('goods_name' => $name))->select();
+        if(empty($items)) {
+            $con['goods_name'] = array('like',"%{$name}%");
+            $items = $this->mod_goods_common->field('goods_commonid,goods_name')->where($con)->select();
+        }
+        if(empty($items)) {
+            $len = mb_strlen($name);
+            $name_x = mb_substr($name,0,$len / 2);
+            $con['goods_name'] = array('like',"%{$name_x}%");
+            $items = $this->mod_goods_common->field('goods_commonid,goods_name')->where($con)->select();
+        }
+
+        return $items;
+    }
+
+    private function parase_one($name)
+    {
+        $items = $this->match_item($name);
+
+        if(empty($items)) {
+            $fields = array($name);
+            $this->err_file->fputcsv($fields,',');
+            return;
+        }
+        $goods_commonid = $items[0]['goods_commonid'];
+        $goods = $this->mod_goods->field('*')->where(array('goods_commonid' => $goods_commonid))->limit(false)->select();
+        if(empty(goods)) {
+            $fields = array($name);
+            $this->err_file->fputcsv($fields,',');
+            return;
+        }
+
+        foreach($goods as $val)
+        {
+            $fields = array($val['goods_name'],$val['goods_serial_tm'],$val['num_iid']);
+            $this->good_file->fputcsv($fields,',');
+        }
+    }
+}
+
+
+$matcher =  new skumatcher('/Users/stanley-king/Desktop/name.csv');
+$matcher->proc();
+

+ 275 - 275
crontab/crawl/spec_attr.php

@@ -1,276 +1,276 @@
-<?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;
-
-    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'] = fetch_config::store_id;
-                    $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;
-    }
+<?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;
+
+    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'] = fetch_config::store_id;
+                    $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;
+    }
 }

+ 397 - 397
crontab/crawl/spec_attr_parser.php

@@ -1,398 +1,398 @@
-<?php
-
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 15/12/5
- * Time: 下午4:21
- */
-
-class spec_attr_parser
-{
-    private $tm_goods;
-    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->tm_goods = Model('tm_goods');
-
-        $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();
-        $this->update_attrval();
-
-    }
-
-    private function add_spec()
-    {
-        $datas = $this->tm_spec->group('props')->order('props')->limit(false)->select(); //获取所有独立的规格
-        foreach ($datas as $item)
-        {
-            $cid = $item['cid'];
-            if(is_excids($cid)) {
-                Log::record("num_iid = {$item['num_iid']} has been excluded.");
-                continue;
-            }
-
-            $pid = $item['props'];
-            if(empty($pid)) {
-                Log::record("num_iid = {$item['num_iid']} props is null.");
-                continue;
-            }
-
-            $spec_name = $this->get_tm_props_name($cid, $pid);
-            if(empty($spec_name)) {
-                Log::record("num_iid = {$item['num_iid']} spec_nme is empty.");
-                continue;
-            }
-
-            $this->mod_spec->insert(array('sp_id' => $pid, 'sp_name' => $spec_name));
-        }
-    }
-
-    private function add_type()
-    {
-        Log::record(__FILE__ ."   " . __FUNCTION__,Log::DEBUG);
-        //通过分类直接建立类型
-        $items = $this->tm_spec->field('cid')->group('cid')->limit(false)->select();
-        foreach($items as $item)
-        {
-            $cid = $item['cid']; // $cid => $typeid 以分类建立类型
-            if(is_excids($cid)) {
-                Log::record("num_iid = {$item['num_iid']} has been excluded.");
-                continue;
-            }
-
-            $cnmae = $this->get_class_name($cid);
-            if(empty($cnmae)) {
-                Log::record("num_iid = {$item['num_iid']} cannot find cid = {$cid}.");
-                continue;
-            }
-
-            $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 type_spec_exist($type_id,$sp_id)
-    {
-        $items = $this->mod_type_spec->where(array('type_id' => $type_id,'sp_id' => $sp_id))->limit(false)->select();
-        return (!empty($items));
-    }
-
-    private function add_type_spec()
-    {
-        //按照分类建立类型
-        $items = $this->tm_spec->field('cid,props,num_iid')->group('cid,props')->limit(false)->select();
-        foreach($items as $item)
-        {
-            $cid = $item['cid']; // $cid => $typeid 以分类建立类型
-            if(is_excids($cid)) {
-                Log::record("num_iid = {$item['num_iid']} has been excluded.");
-                continue;
-            }
-            $pid = $item['props'];
-
-            if(empty($pid)) {
-                Log::record("num_iid = {$item['num_iid']} pid is empty.");
-                continue;
-            }
-
-            if($this->type_spec_exist($cid,$pid)) continue;
-            $this->mod_type_spec->insert(array("type_id" => $cid,"sp_id" => $pid));
-        }
-    }
-
-    private function get_tmgoods()
-    {
-        $bodys = $this->tm_goods->field('num_iid,body')->where(array('imported' => 0))->limit(false)->order('num_iid')->select();
-        $result = array();
-
-        foreach($bodys as $body)
-        {
-            $item = json_decode($body['body'],true);
-            if(empty($item)) {
-                Log::record("Cannot decode num_iid={$body['num_iid']} goods.");
-                continue;
-            }
-            $product = array();
-            $product['body'] = $item['item_seller_get_response']['item'];
-            $product['num_iid'] = $body['num_iid'];
-
-            $cid = $product['body']['cid'];
-
-            if(is_excids($cid)) continue;
-
-            array_push($result,$product);
-        }
-
-        return $result;
-    }
-
-    private function parse_properties_name($props)
-    {
-        $spec_vals = preg_split("/[;]+/", $props);
-
-        $ret = array();
-        foreach($spec_vals as $sv)
-        {
-            $data = preg_split("/[:]+/", $sv);
-            if(!empty($data)) {
-                $item = array();
-                $item['pid'] = $data[0];
-                $item['vid'] = $data[1];
-                $item['pname'] = $data[2];
-                $item['vname'] = $data[3];
-
-                if(empty($item['pid']) || empty($item['vid']) || empty($item['pname']) || empty($item['vname'])) {
-                    continue;
-                } else {
-                    array_push($ret,$item);
-                }
-            }
-        }
-        return $ret;
-    }
-
-    private function specval_exist($props,$cid)
-    {
-        $pid = $props['pid'];
-        $vid = $props['vid'];
-
-        $results = $this->tm_spvid_tpvid->where(array('tppid' => $pid,'tpvid' => $vid, 'tpcid' => $cid))->select();
-        return (!empty($results));
-    }
-
-    private function add_spval($props,$cid)
-    {
-        foreach($props as $spvals)
-        {
-            if($this->specval_exist($spvals,$cid)) continue;
-
-            $spec_val = array();
-            $spec_val['sp_id'] = $spvals['pid'];
-            $spec_val['sp_value_name'] = $spvals['vname'];
-            $spec_val['store_id'] = fetch_config::store_id;
-            $spec_val['sp_value_color'] = '#ddd9c3';
-            $spec_val['gc_id'] = $cid;
-            $spec_val['sp_value_sort'] = 0;
-
-            $tm_vid = $spvals['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' => $spvals['pid'],'tpvid' => $tm_vid));
-                if(empty($ret)) {
-                    Log::record(__FUNCTION__ . ':' . __LINE__,Log::ERR);
-                }
-            }
-            else
-            {
-                Log::record(__FUNCTION__ . ':' . __LINE__,Log::ERR);
-            }
-        }
-    }
-
-    private function add_spec_val()
-    {
-        $tmgoods = $this->get_tmgoods();
-        foreach ($tmgoods as $goods)
-        {
-            $cid = $goods['body']['cid'];
-            if(is_excids($cid)) {
-                continue;
-            }
-
-            $skus = $goods['body']['skus'];
-            if(empty($skus)) {
-                continue;
-            }
-
-            $skus = $skus['sku'];
-            if(empty($skus)) {
-                continue;
-            }
-
-            foreach($skus as $sku) {
-                $prpos_name = $this->parse_properties_name($sku['properties_name']);
-                $this->add_spval($prpos_name,$cid);
-            }
-        }
-    }
-
-    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 attrval_exist($props,$cid)
-    {
-        $pid = $props['pid'];
-        $vid = $props['vid'];
-
-        $results = $this->tm_tvid_attrvid->field('attr_vid')->where(array('tpid' => $pid,'tvid' => $vid, 'tcid' => $cid))->select();
-
-        if(empty($results)) {
-            return false;
-        } else {
-            return $results[0]['attr_vid'];
-        }
-    }
-
-    private function attr_exist($props,$cid)
-    {
-        $pid = $props['pid'];
-
-        $results = $this->tm_cpid_attrid->field('attr_id')->where(array('pid' => $pid, 'cid' => $cid))->select();
-        if(empty($results)) {
-            return false;
-        } else {
-            return $results[0]['attr_id'];
-        }
-    }
-
-    private function is_private_attr($pid,$cid)
-    {
-        if($pid == 20000) return false;
-        $items = $this->tm_props->field('id')->where(array('pid' => $pid,'cid' => $cid))->select();
-
-        return empty($items);
-    }
-
-
-    //需要从天猫的数据表里面排除掉 规格 =》 从而得到属性
-    public function add_attribute()
-    {
-        $tmgoods = $this->get_tmgoods();
-        foreach ($tmgoods as $goods)
-        {
-            $cid = $goods['body']['cid'];
-            if(is_excids($cid)) continue;
-
-            $props = $this->parse_properties_name($goods['body']['props_name']);
-            $expids = $this->get_specids($cid);
-
-            foreach($props as $attr)
-            {
-                $pid = $attr['pid'];
-                if(in_array($pid,$expids)) continue;
-                if($this->is_private_attr($pid,$cid)) continue;
-
-                $attrid = $this->attr_exist($attr,$cid);
-                if($attrid == false) {
-                    $row = array("attr_name" => $attr['pname'],"type_id" => $cid,"attr_show" => 1);
-                    $attrid = $this->mod_attribute->table('attribute')->insert($row);
-                    $this->tm_cpid_attrid->insert(array("attr_id" => $attrid, "cid" => $cid, "pid" => $pid));
-                }
-
-                if($this->attrval_exist($attr,$cid)) continue;
-
-                $attr_vid = $this->mod_attribute_value->insert(array("attr_id" => $attrid,"type_id" => $cid, "attr_value_name" => $attr['vname']));
-                if($attr_vid)
-                {
-                    $rid = $this->tm_tvid_attrvid->insert(array('attr_vid' =>$attr_vid,'tcid' => $cid,'tpid' => $pid,'tvid' => $attr['vid']));
-                    if(empty($rid)) {
-                        throw new Exception('insert tm_tvid_attrvid error');
-                    }
-                }
-                else
-                {
-                    throw new Exception('insert attribute_value error');
-                }
-            }
-        }
-    }
-
-
-
-    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 attr_value($type_id,$attr_id)
-    {
-        $items = $this->mod_attribute_value->field('attr_value_id,attr_value_name')->where(array('attr_id' => $attr_id,'type_id' => $type_id))->order('attr_value_sort')->limit(false)->select();
-
-        $ret = array();
-        foreach($items as $item) {
-            array_push($ret,$item['attr_value_name']);
-        }
-        return implode(',',$ret);
-    }
-
-    private function update_attrval()
-    {
-        $items = $this->mod_attribute->table('attribute')->field('attr_id,type_id')->limit(false)->select();
-        foreach($items as $item) {
-            $attr_id = $item['attr_id'];
-            $type_id = $item['type_id'];
-            $attr_value = $this->attr_value($type_id,$attr_id);
-            $this->mod_attribute->table('attribute')->where(array('attr_id' => $attr_id))->update(array('attr_value' => $attr_value));
-        }
-    }
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/12/5
+ * Time: 下午4:21
+ */
+
+class spec_attr_parser
+{
+    private $tm_goods;
+    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->tm_goods = Model('tm_goods');
+
+        $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();
+        $this->update_attrval();
+
+    }
+
+    private function add_spec()
+    {
+        $datas = $this->tm_spec->group('props')->order('props')->limit(false)->select(); //获取所有独立的规格
+        foreach ($datas as $item)
+        {
+            $cid = $item['cid'];
+            if(is_excids($cid)) {
+                Log::record("num_iid = {$item['num_iid']} has been excluded.");
+                continue;
+            }
+
+            $pid = $item['props'];
+            if(empty($pid)) {
+                Log::record("num_iid = {$item['num_iid']} props is null.");
+                continue;
+            }
+
+            $spec_name = $this->get_tm_props_name($cid, $pid);
+            if(empty($spec_name)) {
+                Log::record("num_iid = {$item['num_iid']} spec_nme is empty.");
+                continue;
+            }
+
+            $this->mod_spec->insert(array('sp_id' => $pid, 'sp_name' => $spec_name));
+        }
+    }
+
+    private function add_type()
+    {
+        Log::record(__FILE__ ."   " . __FUNCTION__,Log::DEBUG);
+        //通过分类直接建立类型
+        $items = $this->tm_spec->field('cid')->group('cid')->limit(false)->select();
+        foreach($items as $item)
+        {
+            $cid = $item['cid']; // $cid => $typeid 以分类建立类型
+            if(is_excids($cid)) {
+                Log::record("num_iid = {$item['num_iid']} has been excluded.");
+                continue;
+            }
+
+            $cnmae = $this->get_class_name($cid);
+            if(empty($cnmae)) {
+                Log::record("num_iid = {$item['num_iid']} cannot find cid = {$cid}.");
+                continue;
+            }
+
+            $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 type_spec_exist($type_id,$sp_id)
+    {
+        $items = $this->mod_type_spec->where(array('type_id' => $type_id,'sp_id' => $sp_id))->limit(false)->select();
+        return (!empty($items));
+    }
+
+    private function add_type_spec()
+    {
+        //按照分类建立类型
+        $items = $this->tm_spec->field('cid,props,num_iid')->group('cid,props')->limit(false)->select();
+        foreach($items as $item)
+        {
+            $cid = $item['cid']; // $cid => $typeid 以分类建立类型
+            if(is_excids($cid)) {
+                Log::record("num_iid = {$item['num_iid']} has been excluded.");
+                continue;
+            }
+            $pid = $item['props'];
+
+            if(empty($pid)) {
+                Log::record("num_iid = {$item['num_iid']} pid is empty.");
+                continue;
+            }
+
+            if($this->type_spec_exist($cid,$pid)) continue;
+            $this->mod_type_spec->insert(array("type_id" => $cid,"sp_id" => $pid));
+        }
+    }
+
+    private function get_tmgoods()
+    {
+        $bodys = $this->tm_goods->field('num_iid,body')->where(array('imported' => 0))->limit(false)->order('num_iid')->select();
+        $result = array();
+
+        foreach($bodys as $body)
+        {
+            $item = json_decode($body['body'],true);
+            if(empty($item)) {
+                Log::record("Cannot decode num_iid={$body['num_iid']} goods.");
+                continue;
+            }
+            $product = array();
+            $product['body'] = $item['item_seller_get_response']['item'];
+            $product['num_iid'] = $body['num_iid'];
+
+            $cid = $product['body']['cid'];
+
+            if(is_excids($cid)) continue;
+
+            array_push($result,$product);
+        }
+
+        return $result;
+    }
+
+    private function parse_properties_name($props)
+    {
+        $spec_vals = preg_split("/[;]+/", $props);
+
+        $ret = array();
+        foreach($spec_vals as $sv)
+        {
+            $data = preg_split("/[:]+/", $sv);
+            if(!empty($data)) {
+                $item = array();
+                $item['pid'] = $data[0];
+                $item['vid'] = $data[1];
+                $item['pname'] = $data[2];
+                $item['vname'] = $data[3];
+
+                if(empty($item['pid']) || empty($item['vid']) || empty($item['pname']) || empty($item['vname'])) {
+                    continue;
+                } else {
+                    array_push($ret,$item);
+                }
+            }
+        }
+        return $ret;
+    }
+
+    private function specval_exist($props,$cid)
+    {
+        $pid = $props['pid'];
+        $vid = $props['vid'];
+
+        $results = $this->tm_spvid_tpvid->where(array('tppid' => $pid,'tpvid' => $vid, 'tpcid' => $cid))->select();
+        return (!empty($results));
+    }
+
+    private function add_spval($props,$cid)
+    {
+        foreach($props as $spvals)
+        {
+            if($this->specval_exist($spvals,$cid)) continue;
+
+            $spec_val = array();
+            $spec_val['sp_id'] = $spvals['pid'];
+            $spec_val['sp_value_name'] = $spvals['vname'];
+            $spec_val['store_id'] = fetch_config::store_id;
+            $spec_val['sp_value_color'] = '#ddd9c3';
+            $spec_val['gc_id'] = $cid;
+            $spec_val['sp_value_sort'] = 0;
+
+            $tm_vid = $spvals['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' => $spvals['pid'],'tpvid' => $tm_vid));
+                if(empty($ret)) {
+                    Log::record(__FUNCTION__ . ':' . __LINE__,Log::ERR);
+                }
+            }
+            else
+            {
+                Log::record(__FUNCTION__ . ':' . __LINE__,Log::ERR);
+            }
+        }
+    }
+
+    private function add_spec_val()
+    {
+        $tmgoods = $this->get_tmgoods();
+        foreach ($tmgoods as $goods)
+        {
+            $cid = $goods['body']['cid'];
+            if(is_excids($cid)) {
+                continue;
+            }
+
+            $skus = $goods['body']['skus'];
+            if(empty($skus)) {
+                continue;
+            }
+
+            $skus = $skus['sku'];
+            if(empty($skus)) {
+                continue;
+            }
+
+            foreach($skus as $sku) {
+                $prpos_name = $this->parse_properties_name($sku['properties_name']);
+                $this->add_spval($prpos_name,$cid);
+            }
+        }
+    }
+
+    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 attrval_exist($props,$cid)
+    {
+        $pid = $props['pid'];
+        $vid = $props['vid'];
+
+        $results = $this->tm_tvid_attrvid->field('attr_vid')->where(array('tpid' => $pid,'tvid' => $vid, 'tcid' => $cid))->select();
+
+        if(empty($results)) {
+            return false;
+        } else {
+            return $results[0]['attr_vid'];
+        }
+    }
+
+    private function attr_exist($props,$cid)
+    {
+        $pid = $props['pid'];
+
+        $results = $this->tm_cpid_attrid->field('attr_id')->where(array('pid' => $pid, 'cid' => $cid))->select();
+        if(empty($results)) {
+            return false;
+        } else {
+            return $results[0]['attr_id'];
+        }
+    }
+
+    private function is_private_attr($pid,$cid)
+    {
+        if($pid == 20000) return false;
+        $items = $this->tm_props->field('id')->where(array('pid' => $pid,'cid' => $cid))->select();
+
+        return empty($items);
+    }
+
+
+    //需要从天猫的数据表里面排除掉 规格 =》 从而得到属性
+    public function add_attribute()
+    {
+        $tmgoods = $this->get_tmgoods();
+        foreach ($tmgoods as $goods)
+        {
+            $cid = $goods['body']['cid'];
+            if(is_excids($cid)) continue;
+
+            $props = $this->parse_properties_name($goods['body']['props_name']);
+            $expids = $this->get_specids($cid);
+
+            foreach($props as $attr)
+            {
+                $pid = $attr['pid'];
+                if(in_array($pid,$expids)) continue;
+                if($this->is_private_attr($pid,$cid)) continue;
+
+                $attrid = $this->attr_exist($attr,$cid);
+                if($attrid == false) {
+                    $row = array("attr_name" => $attr['pname'],"type_id" => $cid,"attr_show" => 1);
+                    $attrid = $this->mod_attribute->table('attribute')->insert($row);
+                    $this->tm_cpid_attrid->insert(array("attr_id" => $attrid, "cid" => $cid, "pid" => $pid));
+                }
+
+                if($this->attrval_exist($attr,$cid)) continue;
+
+                $attr_vid = $this->mod_attribute_value->insert(array("attr_id" => $attrid,"type_id" => $cid, "attr_value_name" => $attr['vname']));
+                if($attr_vid)
+                {
+                    $rid = $this->tm_tvid_attrvid->insert(array('attr_vid' =>$attr_vid,'tcid' => $cid,'tpid' => $pid,'tvid' => $attr['vid']));
+                    if(empty($rid)) {
+                        throw new Exception('insert tm_tvid_attrvid error');
+                    }
+                }
+                else
+                {
+                    throw new Exception('insert attribute_value error');
+                }
+            }
+        }
+    }
+
+
+
+    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 attr_value($type_id,$attr_id)
+    {
+        $items = $this->mod_attribute_value->field('attr_value_id,attr_value_name')->where(array('attr_id' => $attr_id,'type_id' => $type_id))->order('attr_value_sort')->limit(false)->select();
+
+        $ret = array();
+        foreach($items as $item) {
+            array_push($ret,$item['attr_value_name']);
+        }
+        return implode(',',$ret);
+    }
+
+    private function update_attrval()
+    {
+        $items = $this->mod_attribute->table('attribute')->field('attr_id,type_id')->limit(false)->select();
+        foreach($items as $item) {
+            $attr_id = $item['attr_id'];
+            $type_id = $item['type_id'];
+            $attr_value = $this->attr_value($type_id,$attr_id);
+            $this->mod_attribute->table('attribute')->where(array('attr_id' => $attr_id))->update(array('attr_value' => $attr_value));
+        }
+    }
 }

+ 84 - 84
crontab/crawl/tm_pagereq.php

@@ -1,85 +1,85 @@
-<?php
-
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 15/12/4
- * Time: 上午11:07
- */
-class tm_pagereq
-{
-    private $appkey;
-    private $secretKey;
-    private $sessionKey;
-
-    private $total_items;
-    private $num_iids;
-    private $leftcount;
-
-    public function __construct($appKey,$sercetCode,$sessionKey)
-    {
-        $this->appkey = $appKey;
-        $this->secretKey = $sercetCode;
-        $this->sessionKey = $sessionKey;
-
-        $this->total_items = 0;
-        $this->leftcount = -1;
-        $this->num_iids = array();
-    }
-
-    public function proc()
-    {
-        $page_no = 1;
-        do
-        {
-            if($this->get_onsale($page_no) == false) {
-                Log::record("error request.",Log::ERR);
-                return NULL;
-            }
-            $page_no++;
-        } while($this->leftcount > 0);
-
-        return $this->num_iids;
-    }
-
-    public function get_onsale($page_no)
-    {
-        $page_size = 200;
-
-        $c = new TopClient;
-        $c->appkey = $this->appkey;
-        $c->secretKey = $this->secretKey;
-        $req = new ItemsOnsaleGetRequest;
-
-        $req->setFields('approve_status,num_iid');
-        $req->setPageSize($page_size);
-        $req->setPageNo($page_no);
-
-        $resp = $c->execute($req,$body,$this->sessionKey);
-
-        if(!empty($resp))
-        {
-            $this->total_items = $resp->total_results;
-            Log::record("total={$this->total_items}\r\n",Log::DEBUG);
-            $items = $resp->items->item;
-            if($items == NULL) {
-                Log::record("total={$this->total_items}\r\n",Log::DEBUG);
-                echo "total={$this->total_items}\r\n";
-                flush();
-                return NULL;
-            }
-
-            if($this->leftcount < 0) {
-                $this->leftcount = $this->total_items;
-            }
-            $this->leftcount -= count($items);
-
-            foreach($items as $item) {
-                array_push($this->num_iids,$item);
-            }
-            return true;
-        } else {
-            return NULL;
-        }
-    }
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/12/4
+ * Time: 上午11:07
+ */
+class tm_pagereq
+{
+    private $appkey;
+    private $secretKey;
+    private $sessionKey;
+
+    private $total_items;
+    private $num_iids;
+    private $leftcount;
+
+    public function __construct($appKey,$sercetCode,$sessionKey)
+    {
+        $this->appkey = $appKey;
+        $this->secretKey = $sercetCode;
+        $this->sessionKey = $sessionKey;
+
+        $this->total_items = 0;
+        $this->leftcount = -1;
+        $this->num_iids = array();
+    }
+
+    public function proc()
+    {
+        $page_no = 1;
+        do
+        {
+            if($this->get_onsale($page_no) == false) {
+                Log::record("error request.",Log::ERR);
+                return NULL;
+            }
+            $page_no++;
+        } while($this->leftcount > 0);
+
+        return $this->num_iids;
+    }
+
+    public function get_onsale($page_no)
+    {
+        $page_size = 200;
+
+        $c = new TopClient;
+        $c->appkey = $this->appkey;
+        $c->secretKey = $this->secretKey;
+        $req = new ItemsOnsaleGetRequest;
+
+        $req->setFields('approve_status,num_iid');
+        $req->setPageSize($page_size);
+        $req->setPageNo($page_no);
+
+        $resp = $c->execute($req,$body,$this->sessionKey);
+
+        if(!empty($resp))
+        {
+            $this->total_items = $resp->total_results;
+            Log::record("total={$this->total_items}\r\n",Log::DEBUG);
+            $items = $resp->items->item;
+            if($items == NULL) {
+                Log::record("total={$this->total_items}\r\n",Log::DEBUG);
+                echo "total={$this->total_items}\r\n";
+                flush();
+                return NULL;
+            }
+
+            if($this->leftcount < 0) {
+                $this->leftcount = $this->total_items;
+            }
+            $this->leftcount -= count($items);
+
+            foreach($items as $item) {
+                array_push($this->num_iids,$item);
+            }
+            return true;
+        } else {
+            return NULL;
+        }
+    }
 }

+ 150 - 150
crontab/crawl/tmrequest.php

@@ -1,151 +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_one($shopid)
-    {
-        $items = $this->tm_shop->where(array('shop_id' => $shopid))->field('shop_id,shop_name,appKey,sercetCode,sessionKey')->limit(false)->select();
-        $this->request($items);
-
-    }
-
-    public function proc()
-    {
-        $items = $this->tm_shop->field('shop_id,shop_name,appKey,sercetCode,sessionKey')->limit(false)->select();
-        $this->request($items);
-    }
-
-    //添加基础数据。
-    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()
-    {
-        $req = new tm_pagereq($this->appkey,$this->secretKey,$this->sessionKey);
-        return $req->proc();
-    }
-
-    /**
-     * @param $items
-     */
-    private function request($items)
-    {
-        foreach ($items as $item)
-        {
-            Log::record("Inof: shop id =" . $item["shop_id"] . " name=" . $item["shop_name"] . " appKey=" . $item['appKey'] . " sercetCode=" . $item['sercetCode'] . " sessionKey=" . $item['sessionKey'],Log::DEBUG);
-
-            $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)) {
-                Log::record("get product info from taobao err where " . "shop id =" . $item["shop_id"] . " name=" . $item["shop_name"],Log::ERR);
-            }
-            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);
-                        }
-                    }
-                }
-            }
-        }
-    }
+<?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_one($shopid)
+    {
+        $items = $this->tm_shop->where(array('shop_id' => $shopid))->field('shop_id,shop_name,appKey,sercetCode,sessionKey')->limit(false)->select();
+        $this->request($items);
+
+    }
+
+    public function proc()
+    {
+        $items = $this->tm_shop->field('shop_id,shop_name,appKey,sercetCode,sessionKey')->limit(false)->select();
+        $this->request($items);
+    }
+
+    //添加基础数据。
+    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()
+    {
+        $req = new tm_pagereq($this->appkey,$this->secretKey,$this->sessionKey);
+        return $req->proc();
+    }
+
+    /**
+     * @param $items
+     */
+    private function request($items)
+    {
+        foreach ($items as $item)
+        {
+            Log::record("Inof: shop id =" . $item["shop_id"] . " name=" . $item["shop_name"] . " appKey=" . $item['appKey'] . " sercetCode=" . $item['sercetCode'] . " sessionKey=" . $item['sessionKey'],Log::DEBUG);
+
+            $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)) {
+                Log::record("get product info from taobao err where " . "shop id =" . $item["shop_id"] . " name=" . $item["shop_name"],Log::ERR);
+            }
+            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);
+                        }
+                    }
+                }
+            }
+        }
+    }
 }

+ 281 - 281
crontab/crawl/transport_data.php

@@ -1,282 +1,282 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 15/11/2
- * Time: 下午2:59
- */
-
-class ModelOperator
-{
-    private $mod_goods_tmp;
-    private $mod_spec_ex;
-    private $mod_spec;
-    private $mod_spec_value;
-    private $mod_good_class;
-    private $mod_item_props;
-    private $mod_item_prop_values;
-    private $mod_type;
-    private $mod_type_spec;
-    private $mod_spvid_tvid; //spec value id => tmall props vid
-
-    private $mod_attribute;
-    private $mod_attr_tcpid;
-    private $mod_attribute_value;
-
-    public function __construct()
-    {
-        $this->mod_goods_tmp = Model('goods_tmp');
-        $this->mod_spec_ex = Model('spec_ex');
-        $this->mod_spec = Model('spec');
-        $this->mod_good_class = Model('goods_class');
-        $this->mod_item_props = Model('item_props');
-        $this->mod_item_prop_values = Model('item_prop_values');
-        $this->mod_spec_value = Model('spec_value');
-
-        $this->mod_type = Model('type');
-        $this->mod_type_spec = Model('type_spec');
-        $this->mod_spvid_tvid = Model('spvid_tvid');
-
-        $this->mod_attribute = Model('attribute');
-        $this->mod_attr_tcpid = Model('attr_tcpid');
-        $this->mod_attribute_value = Model('attribute_value');
-    }
-
-    public function __call($method,$args)
-    {
-        //$num_iid = $args[0];
-        $body = &$args[1];
-        $response = json_decode($body, true);
-
-        $methods = array('spec');
-        if(in_array(strtolower($method),$methods) == false) {
-            return;
-        }
-        if($method == 'spec')
-        {
-            $item = &$response['item_get_response']['item'];
-            if($item['approve_status'] != 'onsale') {
-                return;
-            }
-
-            $cid = $item['cid'];
-            $num_iid = $item['num_iid'];
-            $title = $item['title'];
-
-            $skus = &$item['skus'];
-            foreach($skus as $skuex)
-            {
-                foreach($skuex as $sku) {
-                    $val = array();
-                    $val['cid'] = $cid;
-                    $val['num_iid'] = $num_iid;
-                    $val['sp_name'] = $sku['properties_name'];
-                    $val['sku_id'] = $sku['sku_id'];
-                    $val['outer_id'] = $sku['outer_id'];
-                    $props = $this->parse_props($sku['properties']);
-                    $val['props'] = empty($props) ? "" : $props[0];
-                    $val['props_val'] = $sku['properties_name'];
-                    $val['title'] = $title;
-                    $val['body'] = $body;
-
-                    $this->mod_spec_ex->insert($val);
-                }
-            }
-            //把数据添加到商品临时表里面
-            $this->mod_goods_tmp->insert(array("num_iid" => $num_iid,'body' => $body,'cid' => $cid,'product_id' =>$item['product_id'],'title' => $title));
-        }
-    }
-
-    function parse_props($props)
-    {
-        $data = preg_split("/[:]+/", $props);
-        $ret = array();
-
-        $count = count($data);
-        for ($i = 0; $i < $count; $i += 2) {
-            array_push($ret, $data[$i]);
-        }
-        return $ret;
-    }
-
-    //根据天猫的商品规格,对应生成规格,并做好分类,类型,规格的映射关系
-    public function genspec()
-    {
-        $datas = $this->mod_spec_ex->group('props')->order('props')->limit(false)->select(); //获取所有独立的规格
-
-        $pids = array();
-        foreach($datas as $item) {
-            $cid = $item['cid'];
-            $pid = $item['props'];
-            $spec_name = $this->get_spec_name($cid, $pid);
-
-            //向数据库中添加spec
-            $val = array('sp_id' => $pid, 'sp_name' => $spec_name);
-            $this->mod_spec->insert($val);
-            array_push($pids,$pid);
-        }
-
-        $this->add_spec_val(); //添加规格值,由于规格值是按照分类走的
-        $this->add_type($pids); //建立类型,以及 规格与类型 的关系
-    }
-
-    private function add_type($pids)
-    {
-        //通过分类直接建立类型
-        $items = $this->mod_spec_ex->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));
-        }
-
-        foreach ($pids as $pid)
-        {
-            //按照分类建立类型
-            $specexs = $this->mod_spec_ex->group('cid')->where(array('props' => $pid))->limit(false)->select();
-            foreach($specexs as $specex) {
-                $cid = $specex['cid']; // $cid => $typeid 以分类建立类型
-                $this->mod_type_spec->insert(array("type_id" => $cid,"sp_id" => $pid));
-            }
-        }
-    }
-
-    private function add_spec_val()
-    {
-        $specex = $this->mod_spec_ex->field('cid,props')->group('cid,props')->limit(false)->select();
-        foreach ($specex as $sp) {
-            $cid = $sp["cid"];
-            $pid = $sp["props"];
-            if($cid == 50013794 && $pid ==1627207) {
-                $x = 100;
-            }
-            $items = $this->get_prop_values($cid,$pid);
-            foreach($items as $item) {
-                $spec_val = array();
-                $spec_val['sp_id'] = $pid;
-                //$spec_val['sp_value_id'] = $item['vid']; //此处不能赋值,因为sp_value_id 是自索引的
-                $spec_val['sp_value_name'] = $item['name'];
-                $spec_val['store_id'] = fetch_config::store_id;
-                $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) {
-                    $this->mod_spvid_tvid->insert(array('spvid' => $specval_id,'tpvid' => $tm_vid));
-                }
-            }
-        }
-    }
-
-    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_spec_name($cid,$pid)
-    {
-        $item = $this->mod_item_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->mod_item_prop_values->where(array('cid' => $cid,'pid' => $pid))->limit(false)->select();
-        return $items;
-    }
-
-    private function get_expids()
-    {
-        $items = $this->mod_spec->field('sp_id')->group('sp_id')->limit(false)->select();
-
-        $expids = array();
-        foreach($items as $item) {
-            array_push($expids,$item['sp_id']);
-        }
-        return $expids;
-    }
-
-    private function get_cids()
-    {
-        $items = $this->mod_spec_ex->group('cid')->order('cid')->limit(false)->select();
-
-        $cids = array();
-        foreach ($items as $item) {
-            array_push($cids,$item['cid']);
-        }
-
-        return $cids;
-    }
-
-    private function get_attrid($cid,$pid)
-    {
-        $item = $this->mod_attr_tcpid->where(array("cid" => $cid,"pid" => $pid))->select();
-        return $item[0]['attr_id'];
-    }
-
-    //需要从天猫的数据表里面排除掉 规格 =》 从而得到属性
-    public function add_attribute()
-    {
-        $expids = $this->get_expids();
-        $cids = $this->get_cids();
-
-        foreach($cids as $cid)
-        {
-            $items =$this->mod_item_props->where(array('cid' => $cid))->select();
-
-            $pids = array();
-            foreach($items as $item) {
-                $pid = $item['pid'];
-                if(in_array($pid,$expids)) continue;
-
-                array_push($pids,$pid);
-
-                $name = $item['name'];
-                $multi = strtolower($item['multi']) == 'true' ? true : false;
-                $attr_multi = $multi ? "TRUE" : "FALSE";
-
-                $attrid = $this->mod_attribute->table('attribute')->insert(array( "attr_name" => $name,"type_id" => $cid,"attr_multi" => $attr_multi,"attr_show" => 1));
-
-
-                if($attrid) { // 建立shopnc attribute id 与 天猫数据 pid + cid 的对应关系
-                    $this->mod_attr_tcpid->insert(array("attr_id" => $attrid, "cid" => $cid, "pid" => $pid));
-                } else {
-                    // add log...
-                }
-            }
-
-            foreach($pids as $pid)
-            {
-                $tm_valus = $this->mod_item_prop_values->where(array('pid' => $pid,'cid'=>$cid))->select();
-
-                foreach($tm_valus as $val)
-                {
-                    $type_id = $cid;
-                    $attrid = $this->get_attrid($cid,$pid);
-                    $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) {
-                        $this->mod_spvid_tvid->insert(array('spvid' =>$attr_vid,"tpvid" => $vid));
-                    } else {
-                        throw(new Exception("cannot add attribute value."));
-                    }
-                }
-            }
-        }
-    }
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 15/11/2
+ * Time: 下午2:59
+ */
+
+class ModelOperator
+{
+    private $mod_goods_tmp;
+    private $mod_spec_ex;
+    private $mod_spec;
+    private $mod_spec_value;
+    private $mod_good_class;
+    private $mod_item_props;
+    private $mod_item_prop_values;
+    private $mod_type;
+    private $mod_type_spec;
+    private $mod_spvid_tvid; //spec value id => tmall props vid
+
+    private $mod_attribute;
+    private $mod_attr_tcpid;
+    private $mod_attribute_value;
+
+    public function __construct()
+    {
+        $this->mod_goods_tmp = Model('goods_tmp');
+        $this->mod_spec_ex = Model('spec_ex');
+        $this->mod_spec = Model('spec');
+        $this->mod_good_class = Model('goods_class');
+        $this->mod_item_props = Model('item_props');
+        $this->mod_item_prop_values = Model('item_prop_values');
+        $this->mod_spec_value = Model('spec_value');
+
+        $this->mod_type = Model('type');
+        $this->mod_type_spec = Model('type_spec');
+        $this->mod_spvid_tvid = Model('spvid_tvid');
+
+        $this->mod_attribute = Model('attribute');
+        $this->mod_attr_tcpid = Model('attr_tcpid');
+        $this->mod_attribute_value = Model('attribute_value');
+    }
+
+    public function __call($method,$args)
+    {
+        //$num_iid = $args[0];
+        $body = &$args[1];
+        $response = json_decode($body, true);
+
+        $methods = array('spec');
+        if(in_array(strtolower($method),$methods) == false) {
+            return;
+        }
+        if($method == 'spec')
+        {
+            $item = &$response['item_get_response']['item'];
+            if($item['approve_status'] != 'onsale') {
+                return;
+            }
+
+            $cid = $item['cid'];
+            $num_iid = $item['num_iid'];
+            $title = $item['title'];
+
+            $skus = &$item['skus'];
+            foreach($skus as $skuex)
+            {
+                foreach($skuex as $sku) {
+                    $val = array();
+                    $val['cid'] = $cid;
+                    $val['num_iid'] = $num_iid;
+                    $val['sp_name'] = $sku['properties_name'];
+                    $val['sku_id'] = $sku['sku_id'];
+                    $val['outer_id'] = $sku['outer_id'];
+                    $props = $this->parse_props($sku['properties']);
+                    $val['props'] = empty($props) ? "" : $props[0];
+                    $val['props_val'] = $sku['properties_name'];
+                    $val['title'] = $title;
+                    $val['body'] = $body;
+
+                    $this->mod_spec_ex->insert($val);
+                }
+            }
+            //把数据添加到商品临时表里面
+            $this->mod_goods_tmp->insert(array("num_iid" => $num_iid,'body' => $body,'cid' => $cid,'product_id' =>$item['product_id'],'title' => $title));
+        }
+    }
+
+    function parse_props($props)
+    {
+        $data = preg_split("/[:]+/", $props);
+        $ret = array();
+
+        $count = count($data);
+        for ($i = 0; $i < $count; $i += 2) {
+            array_push($ret, $data[$i]);
+        }
+        return $ret;
+    }
+
+    //根据天猫的商品规格,对应生成规格,并做好分类,类型,规格的映射关系
+    public function genspec()
+    {
+        $datas = $this->mod_spec_ex->group('props')->order('props')->limit(false)->select(); //获取所有独立的规格
+
+        $pids = array();
+        foreach($datas as $item) {
+            $cid = $item['cid'];
+            $pid = $item['props'];
+            $spec_name = $this->get_spec_name($cid, $pid);
+
+            //向数据库中添加spec
+            $val = array('sp_id' => $pid, 'sp_name' => $spec_name);
+            $this->mod_spec->insert($val);
+            array_push($pids,$pid);
+        }
+
+        $this->add_spec_val(); //添加规格值,由于规格值是按照分类走的
+        $this->add_type($pids); //建立类型,以及 规格与类型 的关系
+    }
+
+    private function add_type($pids)
+    {
+        //通过分类直接建立类型
+        $items = $this->mod_spec_ex->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));
+        }
+
+        foreach ($pids as $pid)
+        {
+            //按照分类建立类型
+            $specexs = $this->mod_spec_ex->group('cid')->where(array('props' => $pid))->limit(false)->select();
+            foreach($specexs as $specex) {
+                $cid = $specex['cid']; // $cid => $typeid 以分类建立类型
+                $this->mod_type_spec->insert(array("type_id" => $cid,"sp_id" => $pid));
+            }
+        }
+    }
+
+    private function add_spec_val()
+    {
+        $specex = $this->mod_spec_ex->field('cid,props')->group('cid,props')->limit(false)->select();
+        foreach ($specex as $sp) {
+            $cid = $sp["cid"];
+            $pid = $sp["props"];
+            if($cid == 50013794 && $pid ==1627207) {
+                $x = 100;
+            }
+            $items = $this->get_prop_values($cid,$pid);
+            foreach($items as $item) {
+                $spec_val = array();
+                $spec_val['sp_id'] = $pid;
+                //$spec_val['sp_value_id'] = $item['vid']; //此处不能赋值,因为sp_value_id 是自索引的
+                $spec_val['sp_value_name'] = $item['name'];
+                $spec_val['store_id'] = fetch_config::store_id;
+                $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) {
+                    $this->mod_spvid_tvid->insert(array('spvid' => $specval_id,'tpvid' => $tm_vid));
+                }
+            }
+        }
+    }
+
+    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_spec_name($cid,$pid)
+    {
+        $item = $this->mod_item_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->mod_item_prop_values->where(array('cid' => $cid,'pid' => $pid))->limit(false)->select();
+        return $items;
+    }
+
+    private function get_expids()
+    {
+        $items = $this->mod_spec->field('sp_id')->group('sp_id')->limit(false)->select();
+
+        $expids = array();
+        foreach($items as $item) {
+            array_push($expids,$item['sp_id']);
+        }
+        return $expids;
+    }
+
+    private function get_cids()
+    {
+        $items = $this->mod_spec_ex->group('cid')->order('cid')->limit(false)->select();
+
+        $cids = array();
+        foreach ($items as $item) {
+            array_push($cids,$item['cid']);
+        }
+
+        return $cids;
+    }
+
+    private function get_attrid($cid,$pid)
+    {
+        $item = $this->mod_attr_tcpid->where(array("cid" => $cid,"pid" => $pid))->select();
+        return $item[0]['attr_id'];
+    }
+
+    //需要从天猫的数据表里面排除掉 规格 =》 从而得到属性
+    public function add_attribute()
+    {
+        $expids = $this->get_expids();
+        $cids = $this->get_cids();
+
+        foreach($cids as $cid)
+        {
+            $items =$this->mod_item_props->where(array('cid' => $cid))->select();
+
+            $pids = array();
+            foreach($items as $item) {
+                $pid = $item['pid'];
+                if(in_array($pid,$expids)) continue;
+
+                array_push($pids,$pid);
+
+                $name = $item['name'];
+                $multi = strtolower($item['multi']) == 'true' ? true : false;
+                $attr_multi = $multi ? "TRUE" : "FALSE";
+
+                $attrid = $this->mod_attribute->table('attribute')->insert(array( "attr_name" => $name,"type_id" => $cid,"attr_multi" => $attr_multi,"attr_show" => 1));
+
+
+                if($attrid) { // 建立shopnc attribute id 与 天猫数据 pid + cid 的对应关系
+                    $this->mod_attr_tcpid->insert(array("attr_id" => $attrid, "cid" => $cid, "pid" => $pid));
+                } else {
+                    // add log...
+                }
+            }
+
+            foreach($pids as $pid)
+            {
+                $tm_valus = $this->mod_item_prop_values->where(array('pid' => $pid,'cid'=>$cid))->select();
+
+                foreach($tm_valus as $val)
+                {
+                    $type_id = $cid;
+                    $attrid = $this->get_attrid($cid,$pid);
+                    $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) {
+                        $this->mod_spvid_tvid->insert(array('spvid' =>$attr_vid,"tpvid" => $vid));
+                    } else {
+                        throw(new Exception("cannot add attribute value."));
+                    }
+                }
+            }
+        }
+    }
 }

+ 100 - 100
crontab/crawl/upload_control.php

@@ -1,100 +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';
-
-    private function fill_files($filename)
-    {
-        if(file_exists(fetch_config::tmp_file)) {
-              unlink(fetch_config::tmp_file);
-        }
-        copy($filename,fetch_config::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'] = fetch_config::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;
-    }
-}
+<?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';
+
+    private function fill_files($filename)
+    {
+        if(file_exists(fetch_config::tmp_file)) {
+              unlink(fetch_config::tmp_file);
+        }
+        copy($filename,fetch_config::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'] = fetch_config::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;
+    }
+}

+ 462 - 462
crontab/crawl/upload_file.php

@@ -1,463 +1,463 @@
-
-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;
-    }
+
+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;
+    }
 }

+ 54 - 54
data/api/smsapi/yuntx/SendSMS.php

@@ -1,54 +1,54 @@
-<?php
-/*
- *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
- *
- *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
- *  that can be found in the LICENSE file in the root of the web site.
- *
- *   http://www.yuntongxun.com
- *
- *  An additional intellectual property rights grant can be found
- *  in the file PATENTS.  All contributing project authors may
- *  be found in the AUTHORS file in the root of the source tree.
- */
-
-/**
-  * 发送模板短信
-  * @param to 手机号码集合,用英文逗号分开
-  * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
-  * @param $tempId 模板Id
-  */       
-function sendSMS($to,$datas,$tempId)
-{
-    //主帐号
-    $accountSid = '8a48b5514ff923b4014ffe4f7d570d2c';
-
-    //主帐号Token
-    $accountToken = '28953ff4d46c492f90329cda3ce473ad';
-
-    //应用Id
-    $appId = '8a48b5515018a0f4015059a74f0f7565';
-
-    //请求地址,格式如下,不需要写https://
-    $serverIP = 'app.cloopen.com';
-
-    //请求端口 
-    $serverPort = '8883';
-
-    //REST版本号
-    $softVersion = '2013-12-26';
-    // 初始化REST SDK
-     //global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
-     $rest = new REST($serverIP,$serverPort,$softVersion);
-     $rest->setAccount($accountSid,$accountToken);
-     $rest->setAppId($appId);
-    
-     // 发送模板短信
-     $result = $rest->sendTemplateSMS($to,$datas,$tempId);
-     if($result == NULL ) {
-         return -1;
-     }
-
-     return intval($result->statusCode);
-}
-?>
+<?php
+/*
+ *  Copyright (c) 2014 The CCP project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a Beijing Speedtong Information Technology Co.,Ltd license
+ *  that can be found in the LICENSE file in the root of the web site.
+ *
+ *   http://www.yuntongxun.com
+ *
+ *  An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+/**
+  * 发送模板短信
+  * @param to 手机号码集合,用英文逗号分开
+  * @param datas 内容数据 格式为数组 例如:array('Marry','Alon'),如不需替换请填 null
+  * @param $tempId 模板Id
+  */       
+function sendSMS($to,$datas,$tempId)
+{
+    //主帐号
+    $accountSid = '8a48b5514ff923b4014ffe4f7d570d2c';
+
+    //主帐号Token
+    $accountToken = '28953ff4d46c492f90329cda3ce473ad';
+
+    //应用Id
+    $appId = '8a48b5515018a0f4015059a74f0f7565';
+
+    //请求地址,格式如下,不需要写https://
+    $serverIP = 'app.cloopen.com';
+
+    //请求端口 
+    $serverPort = '8883';
+
+    //REST版本号
+    $softVersion = '2013-12-26';
+    // 初始化REST SDK
+     //global $accountSid,$accountToken,$appId,$serverIP,$serverPort,$softVersion;
+     $rest = new REST($serverIP,$serverPort,$softVersion);
+     $rest->setAccount($accountSid,$accountToken);
+     $rest->setAppId($appId);
+    
+     // 发送模板短信
+     $result = $rest->sendTemplateSMS($to,$datas,$tempId);
+     if($result == NULL ) {
+         return -1;
+     }
+
+     return intval($result->statusCode);
+}
+?>

+ 33 - 33
data/api/taobao/test.php

@@ -1,34 +1,34 @@
-<?php
-
-	include "TopSdk.php";
-	date_default_timezone_set('Asia/Shanghai');
-
-const appkey = '12619941';
-const secretKey = '9b13aef649d3320dc4cc1f7d353753c4';
-	$sessionKey = '61006189f905270ab4529ae83e119789649cff4050a1d87820445294';
-
-//	$c = new TopClient;
-//	$c->appkey = '12619941';
-//	$c->secretKey = '9b13aef649d3320dc4cc1f7d353753c4';
-//	$req = new ItempropvaluesGetRequest;
-//	$req->setFields("cid,pid,prop_name,vid,name,name_alias,status,sort_order");
-//	$req->setCid(50010790);
-//	$req->setPvs("1627207:3232484");
-//	$resp = $c->execute($req,$sessionKey);
-//
-//	echo $resp;
-
-$c = new TopClient;
-$c->appkey = appkey;
-$c->secretKey = secret;
-$req = new ItemSellerGetRequest;
-$req->setFields("desc");
-$req->setNumIid(41993809338);
-$resp = $c->execute($req, $sessionKey);
-
-//	$httpdns = new HttpdnsGetRequest;
-//	$client = new ClusterTopClient("appkey","appscret");
-//	$client->gatewayUrl = "http://gw.api.taobao.com/router/rest";
-//	var_dump($client->execute($httpdns));
-
+<?php
+
+	include "TopSdk.php";
+	date_default_timezone_set('Asia/Shanghai');
+
+const appkey = '12619941';
+const secretKey = '9b13aef649d3320dc4cc1f7d353753c4';
+	$sessionKey = '61006189f905270ab4529ae83e119789649cff4050a1d87820445294';
+
+//	$c = new TopClient;
+//	$c->appkey = '12619941';
+//	$c->secretKey = '9b13aef649d3320dc4cc1f7d353753c4';
+//	$req = new ItempropvaluesGetRequest;
+//	$req->setFields("cid,pid,prop_name,vid,name,name_alias,status,sort_order");
+//	$req->setCid(50010790);
+//	$req->setPvs("1627207:3232484");
+//	$resp = $c->execute($req,$sessionKey);
+//
+//	echo $resp;
+
+$c = new TopClient;
+$c->appkey = appkey;
+$c->secretKey = secret;
+$req = new ItemSellerGetRequest;
+$req->setFields("desc");
+$req->setNumIid(41993809338);
+$resp = $c->execute($req, $sessionKey);
+
+//	$httpdns = new HttpdnsGetRequest;
+//	$client = new ClusterTopClient("appkey","appscret");
+//	$client->gatewayUrl = "http://gw.api.taobao.com/router/rest";
+//	var_dump($client->execute($httpdns));
+
 ?>

+ 43 - 43
data/api/taobao/top/ApplicationVar.php

@@ -1,44 +1,44 @@
-<?php
-
-class ApplicationVar
-{
-	var $save_file;
-	var $application  = null;
- 	var $app_data    = '';
- 	var $__writed    = false;
-
-	function __construct()
- 	{
-    $this->save_file = __DIR__.'/httpdns.conf' ;
- 		$this->application = array();
- 	}
-
- 	public function setValue($var_name,$var_value)
-  {
-   		if (!is_string($var_name) || empty($var_name))
-    		return false;
-   
-   		$this->application[$var_name] = $var_value;
-  }
-
-  public function write(){
-      $this->app_data = @serialize($this->application);    
-      $this->__writeToFile();
-  }
-
- 	public function getValue()
- 	{
-     	if (!is_file($this->save_file))
-        	 $this->__writeToFile();
-     	return @unserialize(@file_get_contents($this->save_file));
- 	}
-
- 	function __writeToFile()
- 	{
-  		$fp = @fopen($this->save_file,"w");
-  		@fwrite($fp,$this->app_data);
-  		@fclose($fp);
- 	}
-}
-
+<?php
+
+class ApplicationVar
+{
+	var $save_file;
+	var $application  = null;
+ 	var $app_data    = '';
+ 	var $__writed    = false;
+
+	function __construct()
+ 	{
+    $this->save_file = __DIR__.'/httpdns.conf' ;
+ 		$this->application = array();
+ 	}
+
+ 	public function setValue($var_name,$var_value)
+  {
+   		if (!is_string($var_name) || empty($var_name))
+    		return false;
+   
+   		$this->application[$var_name] = $var_value;
+  }
+
+  public function write(){
+      $this->app_data = @serialize($this->application);    
+      $this->__writeToFile();
+  }
+
+ 	public function getValue()
+ 	{
+     	if (!is_file($this->save_file))
+        	 $this->__writeToFile();
+     	return @unserialize(@file_get_contents($this->save_file));
+ 	}
+
+ 	function __writeToFile()
+ 	{
+  		$fp = @fopen($this->save_file,"w");
+  		@fwrite($fp,$this->app_data);
+  		@fclose($fp);
+ 	}
+}
+
 ?>

+ 186 - 186
data/api/taobao/top/ClusterTopClient.php

@@ -1,187 +1,187 @@
-<?php
-class ClusterTopClient extends TopClient {
-
-	private static $dnsconfig;
-	private static $syncDate = 0;
-	private static $applicationVar ;
-	private static $cfgDuration = 10;
-
-	public function __construct($appkey = "",$secretKey = ""){
-		ClusterTopClient::$applicationVar = new ApplicationVar;
-		$this->appkey = $appkey;
-		$this->secretKey = $secretKey ;
-		$saveConfig = ClusterTopClient::$applicationVar->getValue();
-
-		if($saveConfig){
-			$tmpConfig = $saveConfig['dnsconfig'];
-			ClusterTopClient::$dnsconfig = $this->object_to_array($tmpConfig);
-			unset($tmpConfig);
-
-			ClusterTopClient::$syncDate = $saveConfig['syncDate'];
-			if(!ClusterTopClient::$syncDate)
-				ClusterTopClient::$syncDate = 0;
-		}
-	}
-
-	public function __destruct(){
-		if(ClusterTopClient::$dnsconfig && ClusterTopClient::$syncDate){
-			ClusterTopClient::$applicationVar->setValue("dnsconfig",ClusterTopClient::$dnsconfig);
-			ClusterTopClient::$applicationVar->setValue("syncDate",ClusterTopClient::$syncDate);
-			ClusterTopClient::$applicationVar->write();
-		}
-	}
-
-	public function execute($request = null, $session = null,$bestUrl = null){
-		$currentDate = date('U');
-		$syncDuration = $this->getDnsConfigSyncDuration();
-		$bestUrl = $this->getBestVipUrl($this->gatewayUrl,$request->getApiMethodName());
-		if($currentDate - ClusterTopClient::$syncDate > $syncDuration * 60){
-			$httpdns = new HttpdnsGetRequest;
-			ClusterTopClient::$dnsconfig = json_decode(parent::execute($httpdns,null,$bestUrl)->result);
-			$syncDate = date('U');
-			ClusterTopClient::$syncDate = $syncDate ;
-		}
-		return parent::execute($request,$session,$bestUrl);
-	}
-
-	private function getDnsConfigSyncDuration(){
-		if(ClusterTopClient::$cfgDuration){
-			return ClusterTopClient::$cfgDuration;
-		}
-		if(!ClusterTopClient::$dnsconfig){
-			return ClusterTopClient::$cfgDuration;
-		}
-		$config = json_encode(ClusterTopClient::$dnsconfig);
-		if(!$config){
-			return ClusterTopClient::$cfgDuration;
-		}
-		$config = ClusterTopClient::$dnsconfig['config'];
-		$duration = $config['interval'];
-		ClusterTopClient::$cfgDuration = $duration;
-
-		return ClusterTopClient::$cfgDuration;
-	}
-
-	private function getBestVipUrl($url,$apiname = null,$session = null){
-		$currentEnv = $this->getEnvByApiName($apiname,$session);
-		$vip = $this->getVipByEnv($url,$currentEnv);
-		if($vip)
-			return $vip;
-		return $url;
-	}
-
-	private function getVipByEnv($comUrl,$currentEnv){
-		$urlSchema = parse_url($comUrl);
-		if(!$urlSchema)
-			return null;
-		if(!ClusterTopClient::$dnsconfig['env'])
-			return null;
-		
-		if(!array_key_exists($currentEnv,ClusterTopClient::$dnsconfig['env']))
-			return null;
-
-		$hostList = ClusterTopClient::$dnsconfig['env'][$currentEnv];
-		if(!$hostList)
-			return null ;
-
-		$vipList = null;
-		foreach ($hostList as $key => $value) {
-			if(strcmp($key,$urlSchema['host']) == 0 && strcmp($value['proto'],$urlSchema['scheme']) == 0){
-				$vipList = $value;
-				break;
-			}
-		}
-		$vip = $this->getRandomWeightElement($vipList['vip']);
-		
-		if($vip){
-			return $urlSchema['scheme']."://".$vip.$urlSchema['path'];
-		}
-		return null;
-	}
-
-	private function getEnvByApiName($apiName,$session=""){
-		$apiCfgArray = ClusterTopClient::$dnsconfig['api'];
-		if($apiCfgArray){	
-			if(array_key_exists($apiName,$apiCfgArray)){
-				$apiCfg = $apiCfgArray[$apiName];
-				$userFlag = $apiCfg['user'];
-				$flag = $this->getUserFlag($session);
-				if($userFlag && $this->getUserFlag($session)){
-					return $this->getEnvBySessionFlag($userFlag,$flag);
-				}else{
-					return $this->getRandomWeightElement($apiCfg['rule']);
-				}
-			}
-		}
-		return $this->getDeafultEnv();
-	}
-
-	private function getUserFlag($session){
-		if($session && strlen($session) > 5){
-			if($session[0] == '6' || $session[0] == '7'){
-				return $session[strlen($session) -1];
-			}else if($session[0] == '5' || $session[0] == '8'){
-				return $session[5];
-			}
-		}
-		return null;
-	}
-
-	private function getEnvBySessionFlag($targetConfig,$flag){
-		if($flag)
-			return null;
-		$userArry = $this->dnsconfig['user'];
-		$cfgArry = $userConf[$targetConfig];
-		var_dump($cfgArry);
-	}
-
-	private function getRandomWeightElement($elements){
-		$totalWeight = 0;
-		if($elements){
-			foreach ($elements as $ele) {
-				$weight = $this->getElementWeight($ele);
-				$r = $this->randomFloat() * ($weight + $totalWeight);
-				if($r >= $totalWeight){
-					$selected = $ele;
-				}
-				$totalWeight += $weight;
-			}
-			if($selected){
-				return $this->getElementValue($selected);
-			}
-		}
-		return null;
-
-	}
-
-	private function getElementWeight($ele){
-		$params = explode('|', $ele);
-		return floatval($params[1]);
-	}
-	private function getElementValue($ele){
-		$params = explode('|', $ele);
-		return $params[0];		
-	}
-
-	private function getDeafultEnv(){
-		return ClusterTopClient::$dnsconfig['config']['def_env'];
-	}
-
-	private static function startsWith($haystack, $needle) {
-    	return $needle === "" || strpos($haystack, $needle) === 0;
-	}
-
-	private function object_to_array($obj) 
-	{ 
-    	$_arr= is_object($obj) ? get_object_vars($obj) : $obj; 
-    	foreach($_arr as $key=> $val) 
-    	{ 
-        	$val= (is_array($val) || is_object($val))? $this->object_to_array($val) : $val; 
-        	$arr[$key] = $val; 
-    	} 
-    	return$arr; 
-	}
-
-	private function randomFloat($min = 0, $max = 1) { return $min + mt_rand() / mt_getrandmax() * ($max - $min); }
-}
+<?php
+class ClusterTopClient extends TopClient {
+
+	private static $dnsconfig;
+	private static $syncDate = 0;
+	private static $applicationVar ;
+	private static $cfgDuration = 10;
+
+	public function __construct($appkey = "",$secretKey = ""){
+		ClusterTopClient::$applicationVar = new ApplicationVar;
+		$this->appkey = $appkey;
+		$this->secretKey = $secretKey ;
+		$saveConfig = ClusterTopClient::$applicationVar->getValue();
+
+		if($saveConfig){
+			$tmpConfig = $saveConfig['dnsconfig'];
+			ClusterTopClient::$dnsconfig = $this->object_to_array($tmpConfig);
+			unset($tmpConfig);
+
+			ClusterTopClient::$syncDate = $saveConfig['syncDate'];
+			if(!ClusterTopClient::$syncDate)
+				ClusterTopClient::$syncDate = 0;
+		}
+	}
+
+	public function __destruct(){
+		if(ClusterTopClient::$dnsconfig && ClusterTopClient::$syncDate){
+			ClusterTopClient::$applicationVar->setValue("dnsconfig",ClusterTopClient::$dnsconfig);
+			ClusterTopClient::$applicationVar->setValue("syncDate",ClusterTopClient::$syncDate);
+			ClusterTopClient::$applicationVar->write();
+		}
+	}
+
+	public function execute($request = null, $session = null,$bestUrl = null){
+		$currentDate = date('U');
+		$syncDuration = $this->getDnsConfigSyncDuration();
+		$bestUrl = $this->getBestVipUrl($this->gatewayUrl,$request->getApiMethodName());
+		if($currentDate - ClusterTopClient::$syncDate > $syncDuration * 60){
+			$httpdns = new HttpdnsGetRequest;
+			ClusterTopClient::$dnsconfig = json_decode(parent::execute($httpdns,null,$bestUrl)->result);
+			$syncDate = date('U');
+			ClusterTopClient::$syncDate = $syncDate ;
+		}
+		return parent::execute($request,$session,$bestUrl);
+	}
+
+	private function getDnsConfigSyncDuration(){
+		if(ClusterTopClient::$cfgDuration){
+			return ClusterTopClient::$cfgDuration;
+		}
+		if(!ClusterTopClient::$dnsconfig){
+			return ClusterTopClient::$cfgDuration;
+		}
+		$config = json_encode(ClusterTopClient::$dnsconfig);
+		if(!$config){
+			return ClusterTopClient::$cfgDuration;
+		}
+		$config = ClusterTopClient::$dnsconfig['config'];
+		$duration = $config['interval'];
+		ClusterTopClient::$cfgDuration = $duration;
+
+		return ClusterTopClient::$cfgDuration;
+	}
+
+	private function getBestVipUrl($url,$apiname = null,$session = null){
+		$currentEnv = $this->getEnvByApiName($apiname,$session);
+		$vip = $this->getVipByEnv($url,$currentEnv);
+		if($vip)
+			return $vip;
+		return $url;
+	}
+
+	private function getVipByEnv($comUrl,$currentEnv){
+		$urlSchema = parse_url($comUrl);
+		if(!$urlSchema)
+			return null;
+		if(!ClusterTopClient::$dnsconfig['env'])
+			return null;
+		
+		if(!array_key_exists($currentEnv,ClusterTopClient::$dnsconfig['env']))
+			return null;
+
+		$hostList = ClusterTopClient::$dnsconfig['env'][$currentEnv];
+		if(!$hostList)
+			return null ;
+
+		$vipList = null;
+		foreach ($hostList as $key => $value) {
+			if(strcmp($key,$urlSchema['host']) == 0 && strcmp($value['proto'],$urlSchema['scheme']) == 0){
+				$vipList = $value;
+				break;
+			}
+		}
+		$vip = $this->getRandomWeightElement($vipList['vip']);
+		
+		if($vip){
+			return $urlSchema['scheme']."://".$vip.$urlSchema['path'];
+		}
+		return null;
+	}
+
+	private function getEnvByApiName($apiName,$session=""){
+		$apiCfgArray = ClusterTopClient::$dnsconfig['api'];
+		if($apiCfgArray){	
+			if(array_key_exists($apiName,$apiCfgArray)){
+				$apiCfg = $apiCfgArray[$apiName];
+				$userFlag = $apiCfg['user'];
+				$flag = $this->getUserFlag($session);
+				if($userFlag && $this->getUserFlag($session)){
+					return $this->getEnvBySessionFlag($userFlag,$flag);
+				}else{
+					return $this->getRandomWeightElement($apiCfg['rule']);
+				}
+			}
+		}
+		return $this->getDeafultEnv();
+	}
+
+	private function getUserFlag($session){
+		if($session && strlen($session) > 5){
+			if($session[0] == '6' || $session[0] == '7'){
+				return $session[strlen($session) -1];
+			}else if($session[0] == '5' || $session[0] == '8'){
+				return $session[5];
+			}
+		}
+		return null;
+	}
+
+	private function getEnvBySessionFlag($targetConfig,$flag){
+		if($flag)
+			return null;
+		$userArry = $this->dnsconfig['user'];
+		$cfgArry = $userConf[$targetConfig];
+		var_dump($cfgArry);
+	}
+
+	private function getRandomWeightElement($elements){
+		$totalWeight = 0;
+		if($elements){
+			foreach ($elements as $ele) {
+				$weight = $this->getElementWeight($ele);
+				$r = $this->randomFloat() * ($weight + $totalWeight);
+				if($r >= $totalWeight){
+					$selected = $ele;
+				}
+				$totalWeight += $weight;
+			}
+			if($selected){
+				return $this->getElementValue($selected);
+			}
+		}
+		return null;
+
+	}
+
+	private function getElementWeight($ele){
+		$params = explode('|', $ele);
+		return floatval($params[1]);
+	}
+	private function getElementValue($ele){
+		$params = explode('|', $ele);
+		return $params[0];		
+	}
+
+	private function getDeafultEnv(){
+		return ClusterTopClient::$dnsconfig['config']['def_env'];
+	}
+
+	private static function startsWith($haystack, $needle) {
+    	return $needle === "" || strpos($haystack, $needle) === 0;
+	}
+
+	private function object_to_array($obj) 
+	{ 
+    	$_arr= is_object($obj) ? get_object_vars($obj) : $obj; 
+    	foreach($_arr as $key=> $val) 
+    	{ 
+        	$val= (is_array($val) || is_object($val))? $this->object_to_array($val) : $val; 
+        	$arr[$key] = $val; 
+    	} 
+    	return$arr; 
+	}
+
+	private function randomFloat($min = 0, $max = 1) { return $min + mt_rand() / mt_getrandmax() * ($max - $min); }
+}
 ?>

+ 23 - 23
data/api/taobao/top/HttpdnsGetRequest.php

@@ -1,23 +1,23 @@
-<?php
-
-class HttpdnsGetRequest
-{
-	private $apiParas = array();
-	
-	public function getApiMethodName()
-	{
-		return "taobao.httpdns.get";
-	}
-	
-	public function getApiParas()
-	{
-		return $this->apiParas;
-	}
-	
-	public function check(){}
-	
-	public function putOtherTextParam($key, $value) {
-		$this->apiParas[$key] = $value;
-		$this->$key = $value;
-	}
-}
+<?php
+
+class HttpdnsGetRequest
+{
+	private $apiParas = array();
+	
+	public function getApiMethodName()
+	{
+		return "taobao.httpdns.get";
+	}
+	
+	public function getApiParas()
+	{
+		return $this->apiParas;
+	}
+	
+	public function check(){}
+	
+	public function putOtherTextParam($key, $value) {
+		$this->apiParas[$key] = $value;
+		$this->$key = $value;
+	}
+}

+ 213 - 213
data/api/taobao/top/SpiUtils.php

@@ -1,214 +1,214 @@
-<?php
-class SpiUtils{
-	private static $top_sign_list = "HTTP_TOP_SIGN_LIST";
-	private static $timestamp = "timestamp";
-	private static $header_real_ip = array("X_Real_IP", "X_Forwarded_For", "Proxy_Client_IP",
-											"WL_Proxy_Client_IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR");
-	/**
-	 * 校验SPI请求签名,适用于所有GET请求,及不包含文件参数的POST请求。
-	 * 
-	 * @param request 请求对象
-	 * @param secret app对应的secret
-	 * @return true:校验通过;false:校验不通过
-	 */
-	public static function checkSign4FormRequest($secret){
-		return self::checkSign(null,null,$secret);
-	}
-
-	/**
-	 * 校验SPI请求签名,适用于请求体是xml/json等可用文本表示的POST请求。
-	 * 
-	 * @param request 请求对象
-	 * @param body 请求体的文本内容
-	 * @param secret app对应的secret
-	 * @return true:校验通过;false:校验不通过
-	 */
-	public static function checkSign4TextRequest($body,$secret){
-		return self::checkSign(null,$body,$secret);
-	}
-	
-	/**
-	 * 校验SPI请求签名,适用于带文件上传的POST请求。
-	 * 
-	 * @param request 请求对象
-	 * @param form 除了文件参数以外的所有普通文本参数的map集合
-	 * @param secret app对应的secret
-	 * @return true:校验通过;false:校验不通过
-	 */
-	public static function checkSign4FileRequest($form, $secret){
-		return self::checkSign($form, null, $secret);
-	}
-
-	private static function checkSign($form, $body, $secret) {
-		$params = array();
-		// 1. 获取header参数
-		$headerMap = self::getHeaderMap();
-		foreach ($headerMap as $k => $v){
-			$params[$k] = $v ;
-		}
-
-		// 2. 获取url参数
-		$queryMap = self::getQueryMap();
-		foreach ($queryMap as $k => $v){
-			$params[$k] = $v ;
-		}
-
-		// 3. 获取form参数
-		if ($form == null && $body == null) {
-			$formMap = self::getFormMap();
-			foreach ($formMap as $k => $v){
-				$params[$k] = $v ;
-			}
-		} else if ($form != null) {
-			foreach ($form as $k => $v){
-				$params[$k] = $v ;
-			}
-		}
-
-		if($body == null){
-			$body = file_get_contents('php://input');
-		}
-
-		$remoteSign = $queryMap["sign"];
-		$localSign = self::sign($params, $body, $secret);
-		if (strcmp($remoteSign, $localSign) == 0) {
-			return true;
-		} else {
-			$paramStr = self::getParamStrFromMap($params);
-			self::logCommunicationError($remoteSign,$localSign,$paramStr,$body);
-			return false;
-		}
-	}
-
-	private static function getHeaderMap() {
-		$headerMap = array();
-		$signList = $_SERVER['HTTP_TOP_SIGN_LIST']; // 只获取参与签名的头部字段
-		$signList = trim($signList);
-		if (strlen($signList) > 0){
-			$params = split(",", $signList);
-			foreach ($_SERVER as $k => $v){
-				if (substr($k, 0, 5) == 'HTTP_'){
-					foreach($params as $kk){
-						$upperkey = strtoupper($kk);
-						if(self::endWith($k,$upperkey)){
-							$headerMap[$kk] = $v;
-						}
-					}
-				}
-			}
-		}
-		return $headerMap;
-	}
-
-	private static function getQueryMap(){
-		$queryStr = $_SERVER["QUERY_STRING"];
-		$resultArray = array();
-		foreach (explode('&', $queryStr) as $pair) {
-		    list($key, $value) = explode('=', $pair);
-		    if (strpos($key, '.') !== false) {
-		        list($subKey, $subVal) = explode('.', $key);
-
-		        if (preg_match('/(?P<name>\w+)\[(?P<index>\w+)\]/', $subKey, $matches)) {
-		            $resultArray[$matches['name']][$matches['index']][$subVal] = $value;
-		        } else {
-		            $resultArray[$subKey][$subVal] = urldecode($value);
-		        }
-		    } else {
-		        $resultArray[$key] = urldecode($value);
-		    }
-		}
-		return $resultArray;
-	}
-
-	private static function checkRemoteIp(){
-		$remoteIp = $_SERVER["REMOTE_ADDR"];
-		foreach ($header_real_ip as $k){
-			$realIp = $_SERVER[$k];
-			$realIp = trim($realIp);
-			if(strlen($realIp) > 0 && strcasecmp("unknown",$realIp)){
-				$remoteIp = $realIp;
-				break;
-			}
-		}
-		return self::startsWith($remoteIp,"140.205.144.") || $this->startsWith($remoteIp,"40.205.145.");
-	}
-
-	private static function getFormMap(){
-		$resultArray = array();
-		foreach($_POST as $key=>$v) { 
-			$resultArray[$k] = $v ;
-		}
-		return $resultArray ;	
-	}
-
-	private static function startsWith($haystack, $needle) {
-    	return $needle === "" || strpos($haystack, $needle) === 0;
-	}
-
-	private static function endWith($haystack, $needle) {   
-	    $length = strlen($needle);  
-	    if($length == 0)
-	    {    
-	        return true;  
-	    }  
-	    return (substr($haystack, -$length) === $needle);
- 	}
-
-	private static function checkTimestamp(){
-		$ts = $_POST['timestamp'];
-		if($ts){
-			$clientTimestamp = strtotime($ts);
-			$current = $_SERVER['REQUEST_TIME'];
-			return ($current - $clientTimestamp) <= 5*60*1000;
-		}else{
-			return false;
-		}
-	}
-
-	private static function getParamStrFromMap($params){
-		ksort($params);
-		$stringToBeSigned = "";
-		foreach ($params as $k => $v)
-		{
-			if(strcmp("sign", $k) != 0)
-			{
-				$stringToBeSigned .= "$k$v";
-			}
-		}
-		unset($k, $v);
-		return $stringToBeSigned;
-	}
-
-	private static function sign($params,$body,$secret){
-		ksort($params);
-
-		$stringToBeSigned = $secret;
-		$stringToBeSigned .= self::getParamStrFromMap($params);
-
-		if($body)
-			$stringToBeSigned .= $body;
-		$stringToBeSigned .= $secret;
-		return strtoupper(md5($stringToBeSigned));
-	}
-
-	protected static function logCommunicationError($remoteSign, $localSign, $paramStr, $body)
-	{
-		$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
-		$logger = new TopLogger;
-		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_". date("Y-m-d") . ".log";
-		$logger->conf["separator"] = "^_^";
-		$logData = array(
-		"checkTopSign error" ,
-		"remoteSign=".$remoteSign ,
-		"localSign=".$localSign ,
-		"paramStr=".$paramStr ,
-		"body=".$body
-		);
-		$logger->log($logData);
-	}
-	private static function clear_blank($str, $glue='')
-	{
-		$replace = array(" ", "\r", "\n", "\t"); return str_replace($replace, $glue, $str);
-	}
-}
+<?php
+class SpiUtils{
+	private static $top_sign_list = "HTTP_TOP_SIGN_LIST";
+	private static $timestamp = "timestamp";
+	private static $header_real_ip = array("X_Real_IP", "X_Forwarded_For", "Proxy_Client_IP",
+											"WL_Proxy_Client_IP", "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR");
+	/**
+	 * 校验SPI请求签名,适用于所有GET请求,及不包含文件参数的POST请求。
+	 * 
+	 * @param request 请求对象
+	 * @param secret app对应的secret
+	 * @return true:校验通过;false:校验不通过
+	 */
+	public static function checkSign4FormRequest($secret){
+		return self::checkSign(null,null,$secret);
+	}
+
+	/**
+	 * 校验SPI请求签名,适用于请求体是xml/json等可用文本表示的POST请求。
+	 * 
+	 * @param request 请求对象
+	 * @param body 请求体的文本内容
+	 * @param secret app对应的secret
+	 * @return true:校验通过;false:校验不通过
+	 */
+	public static function checkSign4TextRequest($body,$secret){
+		return self::checkSign(null,$body,$secret);
+	}
+	
+	/**
+	 * 校验SPI请求签名,适用于带文件上传的POST请求。
+	 * 
+	 * @param request 请求对象
+	 * @param form 除了文件参数以外的所有普通文本参数的map集合
+	 * @param secret app对应的secret
+	 * @return true:校验通过;false:校验不通过
+	 */
+	public static function checkSign4FileRequest($form, $secret){
+		return self::checkSign($form, null, $secret);
+	}
+
+	private static function checkSign($form, $body, $secret) {
+		$params = array();
+		// 1. 获取header参数
+		$headerMap = self::getHeaderMap();
+		foreach ($headerMap as $k => $v){
+			$params[$k] = $v ;
+		}
+
+		// 2. 获取url参数
+		$queryMap = self::getQueryMap();
+		foreach ($queryMap as $k => $v){
+			$params[$k] = $v ;
+		}
+
+		// 3. 获取form参数
+		if ($form == null && $body == null) {
+			$formMap = self::getFormMap();
+			foreach ($formMap as $k => $v){
+				$params[$k] = $v ;
+			}
+		} else if ($form != null) {
+			foreach ($form as $k => $v){
+				$params[$k] = $v ;
+			}
+		}
+
+		if($body == null){
+			$body = file_get_contents('php://input');
+		}
+
+		$remoteSign = $queryMap["sign"];
+		$localSign = self::sign($params, $body, $secret);
+		if (strcmp($remoteSign, $localSign) == 0) {
+			return true;
+		} else {
+			$paramStr = self::getParamStrFromMap($params);
+			self::logCommunicationError($remoteSign,$localSign,$paramStr,$body);
+			return false;
+		}
+	}
+
+	private static function getHeaderMap() {
+		$headerMap = array();
+		$signList = $_SERVER['HTTP_TOP_SIGN_LIST']; // 只获取参与签名的头部字段
+		$signList = trim($signList);
+		if (strlen($signList) > 0){
+			$params = split(",", $signList);
+			foreach ($_SERVER as $k => $v){
+				if (substr($k, 0, 5) == 'HTTP_'){
+					foreach($params as $kk){
+						$upperkey = strtoupper($kk);
+						if(self::endWith($k,$upperkey)){
+							$headerMap[$kk] = $v;
+						}
+					}
+				}
+			}
+		}
+		return $headerMap;
+	}
+
+	private static function getQueryMap(){
+		$queryStr = $_SERVER["QUERY_STRING"];
+		$resultArray = array();
+		foreach (explode('&', $queryStr) as $pair) {
+		    list($key, $value) = explode('=', $pair);
+		    if (strpos($key, '.') !== false) {
+		        list($subKey, $subVal) = explode('.', $key);
+
+		        if (preg_match('/(?P<name>\w+)\[(?P<index>\w+)\]/', $subKey, $matches)) {
+		            $resultArray[$matches['name']][$matches['index']][$subVal] = $value;
+		        } else {
+		            $resultArray[$subKey][$subVal] = urldecode($value);
+		        }
+		    } else {
+		        $resultArray[$key] = urldecode($value);
+		    }
+		}
+		return $resultArray;
+	}
+
+	private static function checkRemoteIp(){
+		$remoteIp = $_SERVER["REMOTE_ADDR"];
+		foreach ($header_real_ip as $k){
+			$realIp = $_SERVER[$k];
+			$realIp = trim($realIp);
+			if(strlen($realIp) > 0 && strcasecmp("unknown",$realIp)){
+				$remoteIp = $realIp;
+				break;
+			}
+		}
+		return self::startsWith($remoteIp,"140.205.144.") || $this->startsWith($remoteIp,"40.205.145.");
+	}
+
+	private static function getFormMap(){
+		$resultArray = array();
+		foreach($_POST as $key=>$v) { 
+			$resultArray[$k] = $v ;
+		}
+		return $resultArray ;	
+	}
+
+	private static function startsWith($haystack, $needle) {
+    	return $needle === "" || strpos($haystack, $needle) === 0;
+	}
+
+	private static function endWith($haystack, $needle) {   
+	    $length = strlen($needle);  
+	    if($length == 0)
+	    {    
+	        return true;  
+	    }  
+	    return (substr($haystack, -$length) === $needle);
+ 	}
+
+	private static function checkTimestamp(){
+		$ts = $_POST['timestamp'];
+		if($ts){
+			$clientTimestamp = strtotime($ts);
+			$current = $_SERVER['REQUEST_TIME'];
+			return ($current - $clientTimestamp) <= 5*60*1000;
+		}else{
+			return false;
+		}
+	}
+
+	private static function getParamStrFromMap($params){
+		ksort($params);
+		$stringToBeSigned = "";
+		foreach ($params as $k => $v)
+		{
+			if(strcmp("sign", $k) != 0)
+			{
+				$stringToBeSigned .= "$k$v";
+			}
+		}
+		unset($k, $v);
+		return $stringToBeSigned;
+	}
+
+	private static function sign($params,$body,$secret){
+		ksort($params);
+
+		$stringToBeSigned = $secret;
+		$stringToBeSigned .= self::getParamStrFromMap($params);
+
+		if($body)
+			$stringToBeSigned .= $body;
+		$stringToBeSigned .= $secret;
+		return strtoupper(md5($stringToBeSigned));
+	}
+
+	protected static function logCommunicationError($remoteSign, $localSign, $paramStr, $body)
+	{
+		$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
+		$logger = new TopLogger;
+		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_". date("Y-m-d") . ".log";
+		$logger->conf["separator"] = "^_^";
+		$logData = array(
+		"checkTopSign error" ,
+		"remoteSign=".$remoteSign ,
+		"localSign=".$localSign ,
+		"paramStr=".$paramStr ,
+		"body=".$body
+		);
+		$logger->log($logData);
+	}
+	private static function clear_blank($str, $glue='')
+	{
+		$replace = array(" ", "\r", "\n", "\t"); return str_replace($replace, $glue, $str);
+	}
+}
 ?>

+ 42 - 42
data/api/taobao/top/TopLogger.php

@@ -1,43 +1,43 @@
-<?php
-class TopLogger
-{
-	public $conf = array(
-		"separator" => "\t",
-		"log_file" => ""
-	);
-
-	private $fileHandle;
-
-	protected function getFileHandle()
-	{
-		if (null === $this->fileHandle)
-		{
-			if (empty($this->conf["log_file"]))
-			{
-				trigger_error("no log file spcified.");
-			}
-			$logDir = dirname($this->conf["log_file"]);
-			if (!is_dir($logDir))
-			{
-				mkdir($logDir, 0777, true);
-			}
-			$this->fileHandle = fopen($this->conf["log_file"], "a");
-		}
-		return $this->fileHandle;
-	}
-
-	public function log($logData)
-	{
-		if ("" == $logData || array() == $logData)
-		{
-			return false;
-		}
-		if (is_array($logData))
-		{
-			$logData = implode($this->conf["separator"], $logData);
-		}
-		$logData = $logData. "\n";
-		fwrite($this->getFileHandle(), $logData);
-	}
-}
+<?php
+class TopLogger
+{
+	public $conf = array(
+		"separator" => "\t",
+		"log_file" => ""
+	);
+
+	private $fileHandle;
+
+	protected function getFileHandle()
+	{
+		if (null === $this->fileHandle)
+		{
+			if (empty($this->conf["log_file"]))
+			{
+				trigger_error("no log file spcified.");
+			}
+			$logDir = dirname($this->conf["log_file"]);
+			if (!is_dir($logDir))
+			{
+				mkdir($logDir, 0777, true);
+			}
+			$this->fileHandle = fopen($this->conf["log_file"], "a");
+		}
+		return $this->fileHandle;
+	}
+
+	public function log($logData)
+	{
+		if ("" == $logData || array() == $logData)
+		{
+			return false;
+		}
+		if (is_array($logData))
+		{
+			$logData = implode($this->conf["separator"], $logData);
+		}
+		$logData = $logData. "\n";
+		fwrite($this->getFileHandle(), $logData);
+	}
+}
 ?>

+ 0 - 0
data/api/taobao/top/httpdns.conf


+ 26 - 26
data/api/wxpay/cert/apiclient_cert.pem

@@ -1,26 +1,26 @@
------BEGIN CERTIFICATE-----
-MIIEazCCA9SgAwIBAgIDCCtbMA0GCSqGSIb3DQEBBQUAMIGKMQswCQYDVQQGEwJD
-TjESMBAGA1UECBMJR3Vhbmdkb25nMREwDwYDVQQHEwhTaGVuemhlbjEQMA4GA1UE
-ChMHVGVuY2VudDEMMAoGA1UECxMDV1hHMRMwEQYDVQQDEwpNbXBheW1jaENBMR8w
-HQYJKoZIhvcNAQkBFhBtbXBheW1jaEB0ZW5jZW50MB4XDTE1MTAyMjAyNDAwMloX
-DTI1MTAxOTAyNDAwMlowgZsxCzAJBgNVBAYTAkNOMRIwEAYDVQQIEwlHdWFuZ2Rv
-bmcxETAPBgNVBAcTCFNoZW56aGVuMRAwDgYDVQQKEwdUZW5jZW50MQ4wDAYDVQQL
-EwVNTVBheTEwMC4GA1UEAxQn5LiK5rW35Li95Lq65Li95aaG5YyW5aaG5ZOB5pyJ
-6ZmQ5YWs5Y+4MREwDwYDVQQEEwgxMDczMzMwNzCCASIwDQYJKoZIhvcNAQEBBQAD
-ggEPADCCAQoCggEBAMojCgVtpAqLxraCsT5sGanh1ARVpYwFsHYUxBuNAPXXMMxm
-aLm1lD9H/Bmyf0n9j/I2XZDlUQgVxvd6oAqkjngZASFtMgLf9tdCEy31du7ytPTO
-FNnieFG0PQWLCkqGd7xaeWbOEmvXGAFVVbPeX04e3HWjjpBhebw5vNu7Xq39PFvz
-HsPPDq8ASqUMnkrwriKTERaKzUM15wdOevnWRZAujuO2jk5SIOlk4VNna3MCx4Ix
-1Qfsrlqs0PKK07pKmT6jtPYPEJtxgzFv64hpq8c2CnJd2borhPLuGFBMmb5IgFLo
-8RLCR8HdiEWbc/QQh7VkIbfUxhhN3c6d1Ngy5VsCAwEAAaOCAUYwggFCMAkGA1Ud
-EwQCMAAwLAYJYIZIAYb4QgENBB8WHSJDRVMtQ0EgR2VuZXJhdGUgQ2VydGlmaWNh
-dGUiMB0GA1UdDgQWBBQoErMZ2YzhvCMqCJ0kdw8TG06suzCBvwYDVR0jBIG3MIG0
-gBQ+BSb2ImK0FVuIzWR+sNRip+WGdKGBkKSBjTCBijELMAkGA1UEBhMCQ04xEjAQ
-BgNVBAgTCUd1YW5nZG9uZzERMA8GA1UEBxMIU2hlbnpoZW4xEDAOBgNVBAoTB1Rl
-bmNlbnQxDDAKBgNVBAsTA1dYRzETMBEGA1UEAxMKTW1wYXltY2hDQTEfMB0GCSqG
-SIb3DQEJARYQbW1wYXltY2hAdGVuY2VudIIJALtUlyu8AOhXMA4GA1UdDwEB/wQE
-AwIGwDAWBgNVHSUBAf8EDDAKBggrBgEFBQcDAjANBgkqhkiG9w0BAQUFAAOBgQCX
-FhFBqz0q60cVyS4rMwGi6HZFx3gXbr18l2D5XArHZz/CLNtbxJ1aAh2F3/rJIMyA
-g6X5B1o728ywGpFYGAVn8BN/ez4Mf0RFlszz971xgc2GuLQ3UOQnFHbgLH9++zrB
-i8qoLFskBrjZzD5avH6M54dBjmdq76gg2SF8rgF55Q==
------END CERTIFICATE-----
+-----BEGIN CERTIFICATE-----
+MIIEazCCA9SgAwIBAgIDCCtbMA0GCSqGSIb3DQEBBQUAMIGKMQswCQYDVQQGEwJD
+TjESMBAGA1UECBMJR3Vhbmdkb25nMREwDwYDVQQHEwhTaGVuemhlbjEQMA4GA1UE
+ChMHVGVuY2VudDEMMAoGA1UECxMDV1hHMRMwEQYDVQQDEwpNbXBheW1jaENBMR8w
+HQYJKoZIhvcNAQkBFhBtbXBheW1jaEB0ZW5jZW50MB4XDTE1MTAyMjAyNDAwMloX
+DTI1MTAxOTAyNDAwMlowgZsxCzAJBgNVBAYTAkNOMRIwEAYDVQQIEwlHdWFuZ2Rv
+bmcxETAPBgNVBAcTCFNoZW56aGVuMRAwDgYDVQQKEwdUZW5jZW50MQ4wDAYDVQQL
+EwVNTVBheTEwMC4GA1UEAxQn5LiK5rW35Li95Lq65Li95aaG5YyW5aaG5ZOB5pyJ
+6ZmQ5YWs5Y+4MREwDwYDVQQEEwgxMDczMzMwNzCCASIwDQYJKoZIhvcNAQEBBQAD
+ggEPADCCAQoCggEBAMojCgVtpAqLxraCsT5sGanh1ARVpYwFsHYUxBuNAPXXMMxm
+aLm1lD9H/Bmyf0n9j/I2XZDlUQgVxvd6oAqkjngZASFtMgLf9tdCEy31du7ytPTO
+FNnieFG0PQWLCkqGd7xaeWbOEmvXGAFVVbPeX04e3HWjjpBhebw5vNu7Xq39PFvz
+HsPPDq8ASqUMnkrwriKTERaKzUM15wdOevnWRZAujuO2jk5SIOlk4VNna3MCx4Ix
+1Qfsrlqs0PKK07pKmT6jtPYPEJtxgzFv64hpq8c2CnJd2borhPLuGFBMmb5IgFLo
+8RLCR8HdiEWbc/QQh7VkIbfUxhhN3c6d1Ngy5VsCAwEAAaOCAUYwggFCMAkGA1Ud
+EwQCMAAwLAYJYIZIAYb4QgENBB8WHSJDRVMtQ0EgR2VuZXJhdGUgQ2VydGlmaWNh
+dGUiMB0GA1UdDgQWBBQoErMZ2YzhvCMqCJ0kdw8TG06suzCBvwYDVR0jBIG3MIG0
+gBQ+BSb2ImK0FVuIzWR+sNRip+WGdKGBkKSBjTCBijELMAkGA1UEBhMCQ04xEjAQ
+BgNVBAgTCUd1YW5nZG9uZzERMA8GA1UEBxMIU2hlbnpoZW4xEDAOBgNVBAoTB1Rl
+bmNlbnQxDDAKBgNVBAsTA1dYRzETMBEGA1UEAxMKTW1wYXltY2hDQTEfMB0GCSqG
+SIb3DQEJARYQbW1wYXltY2hAdGVuY2VudIIJALtUlyu8AOhXMA4GA1UdDwEB/wQE
+AwIGwDAWBgNVHSUBAf8EDDAKBggrBgEFBQcDAjANBgkqhkiG9w0BAQUFAAOBgQCX
+FhFBqz0q60cVyS4rMwGi6HZFx3gXbr18l2D5XArHZz/CLNtbxJ1aAh2F3/rJIMyA
+g6X5B1o728ywGpFYGAVn8BN/ez4Mf0RFlszz971xgc2GuLQ3UOQnFHbgLH9++zrB
+i8qoLFskBrjZzD5avH6M54dBjmdq76gg2SF8rgF55Q==
+-----END CERTIFICATE-----

+ 28 - 28
data/api/wxpay/cert/apiclient_key.pem

@@ -1,28 +1,28 @@
------BEGIN PRIVATE KEY-----
-MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDKIwoFbaQKi8a2
-grE+bBmp4dQEVaWMBbB2FMQbjQD11zDMZmi5tZQ/R/wZsn9J/Y/yNl2Q5VEIFcb3
-eqAKpI54GQEhbTIC3/bXQhMt9Xbu8rT0zhTZ4nhRtD0FiwpKhne8WnlmzhJr1xgB
-VVWz3l9OHtx1o46QYXm8Obzbu16t/Txb8x7Dzw6vAEqlDJ5K8K4ikxEWis1DNecH
-Tnr51kWQLo7jto5OUiDpZOFTZ2tzAseCMdUH7K5arNDyitO6Spk+o7T2DxCbcYMx
-b+uIaavHNgpyXdm6K4Ty7hhQTJm+SIBS6PESwkfB3YhFm3P0EIe1ZCG31MYYTd3O
-ndTYMuVbAgMBAAECggEBAIezYD3mrlL6JWxPbuhGMDBxUCGc0eefxihvpnwMfFGO
-ps8CDVpnQV/+Vot13qhwlpt3zfbBTFYOMKXh5+FdOdv8hVrIcOOnMZKvZCrdeHvP
-6pXSaAMiW74WL0UyY7VGcsm7P3c57voAy7fRbxiyt+69HynGpKXfGpe3d0dYkaZh
-gYq9gubr7LOsSyoSrkmQ/6ECo9xqcxiPLAjTb9CFbcjtG25QAZRz8jrZxlRSBogc
-1e2lYb9vWZ3DLBY8kJcm6KeYz3XaLILfGbIqqphNImiUIeIm7hFCjWo3DbDKBqtI
-tJ+UFGyG3WTJPYR++dqKYN7gAA5xk2Np79E4cdBr8UkCgYEA+8q0vpXYNtiaCStv
-dxSNEpoAeMGcWqZKkB8xdsDlcaB5LiLL/pEH08PqNcaD/562fOcb8PXK/5UP5j9J
-jguFYZPZrZSAdljv+Zd9uY2Ix8i6JcAkfZBdfjRIVXqmGq7CEilMRusXOcvsaaei
-PjyQ/VZuQEQ2wt1a2UE/jgSkAV0CgYEAzYPiRodbJtsrstMcPwy7cxIvr48n+ReG
-3dtkJReBedhh6IoP3XGg0dQhLejC+8Y4gg3WdFfyuH0BD6zGbPE6LwMQ4Z7XJv5U
-/LbtImvag99xy6DK7Y0PcNGaCYUDKQxx5agz47bxdDfrvdCfD4DQWLa2EZeLFHcH
-sJnRiWRHfhcCgYAgE6HVCcfirNNqyaLIm9ChBwd6WsftcHPdSmwFwes4/4WQkBRG
-2PkTTEkhEqosPW7oGJUhrF5xEu9UmMlpFCSo2qoHh/yZlxjzRg5ZPiOnt/Wm64R6
-jpKqikSQxzA0BAFrSOGTw01RKp5yk02C+jpKW+FtxILpbkOtm7daA1NVbQKBgBW4
-EFu/xkRO+UlGwj9viwfYLi3xhRnwAJLFssmwuEA2O/KlVJPkhEhokLEXXjPZePNV
-nwpgmQgiPdB4Q+gTfkClpE0Tyk0Wp8ilVF5E46z4GkCY15lPRQh5PjwvUGwwIoFQ
-y1sPZGkR19oRiB3NUTdu58LoLwyUn71sJBbPADc1AoGBANX5A77leIKR5wD3RWR3
-W+GMuzmWgvyFHju2zG2nvnd3CIIHnZSlTvCd2H0imjmOPvLofUFnGDTgZWhsqNuk
-9FZ3qFdTgRg3XCWRHT3X5C93iNM7TTHxtDbc7jAdjS6rEDyZD0MD/En5PYxAfFln
-Q3JJqM0w2XNdnYnGL2P2a19l
------END PRIVATE KEY-----
+-----BEGIN PRIVATE KEY-----
+MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDKIwoFbaQKi8a2
+grE+bBmp4dQEVaWMBbB2FMQbjQD11zDMZmi5tZQ/R/wZsn9J/Y/yNl2Q5VEIFcb3
+eqAKpI54GQEhbTIC3/bXQhMt9Xbu8rT0zhTZ4nhRtD0FiwpKhne8WnlmzhJr1xgB
+VVWz3l9OHtx1o46QYXm8Obzbu16t/Txb8x7Dzw6vAEqlDJ5K8K4ikxEWis1DNecH
+Tnr51kWQLo7jto5OUiDpZOFTZ2tzAseCMdUH7K5arNDyitO6Spk+o7T2DxCbcYMx
+b+uIaavHNgpyXdm6K4Ty7hhQTJm+SIBS6PESwkfB3YhFm3P0EIe1ZCG31MYYTd3O
+ndTYMuVbAgMBAAECggEBAIezYD3mrlL6JWxPbuhGMDBxUCGc0eefxihvpnwMfFGO
+ps8CDVpnQV/+Vot13qhwlpt3zfbBTFYOMKXh5+FdOdv8hVrIcOOnMZKvZCrdeHvP
+6pXSaAMiW74WL0UyY7VGcsm7P3c57voAy7fRbxiyt+69HynGpKXfGpe3d0dYkaZh
+gYq9gubr7LOsSyoSrkmQ/6ECo9xqcxiPLAjTb9CFbcjtG25QAZRz8jrZxlRSBogc
+1e2lYb9vWZ3DLBY8kJcm6KeYz3XaLILfGbIqqphNImiUIeIm7hFCjWo3DbDKBqtI
+tJ+UFGyG3WTJPYR++dqKYN7gAA5xk2Np79E4cdBr8UkCgYEA+8q0vpXYNtiaCStv
+dxSNEpoAeMGcWqZKkB8xdsDlcaB5LiLL/pEH08PqNcaD/562fOcb8PXK/5UP5j9J
+jguFYZPZrZSAdljv+Zd9uY2Ix8i6JcAkfZBdfjRIVXqmGq7CEilMRusXOcvsaaei
+PjyQ/VZuQEQ2wt1a2UE/jgSkAV0CgYEAzYPiRodbJtsrstMcPwy7cxIvr48n+ReG
+3dtkJReBedhh6IoP3XGg0dQhLejC+8Y4gg3WdFfyuH0BD6zGbPE6LwMQ4Z7XJv5U
+/LbtImvag99xy6DK7Y0PcNGaCYUDKQxx5agz47bxdDfrvdCfD4DQWLa2EZeLFHcH
+sJnRiWRHfhcCgYAgE6HVCcfirNNqyaLIm9ChBwd6WsftcHPdSmwFwes4/4WQkBRG
+2PkTTEkhEqosPW7oGJUhrF5xEu9UmMlpFCSo2qoHh/yZlxjzRg5ZPiOnt/Wm64R6
+jpKqikSQxzA0BAFrSOGTw01RKp5yk02C+jpKW+FtxILpbkOtm7daA1NVbQKBgBW4
+EFu/xkRO+UlGwj9viwfYLi3xhRnwAJLFssmwuEA2O/KlVJPkhEhokLEXXjPZePNV
+nwpgmQgiPdB4Q+gTfkClpE0Tyk0Wp8ilVF5E46z4GkCY15lPRQh5PjwvUGwwIoFQ
+y1sPZGkR19oRiB3NUTdu58LoLwyUn71sJBbPADc1AoGBANX5A77leIKR5wD3RWR3
+W+GMuzmWgvyFHju2zG2nvnd3CIIHnZSlTvCd2H0imjmOPvLofUFnGDTgZWhsqNuk
+9FZ3qFdTgRg3XCWRHT3X5C93iNM7TTHxtDbc7jAdjS6rEDyZD0MD/En5PYxAfFln
+Q3JJqM0w2XNdnYnGL2P2a19l
+-----END PRIVATE KEY-----

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

@@ -11,7 +11,7 @@ const boss_host    = 'http://172.40.2.14';
 const jeff_office = 'http://192.168.1.128';
 const liax_office = 'http://192.168.1.136';
 
-$SRV_HOST = test_srv_host;
+$SRV_HOST = jeff_office;
 
 $config['base_site_url']        = $SRV_HOST;
 $config['shop_site_url'] 		= $SRV_HOST.'/shop';

+ 0 - 0
data/logic/buy.logic.php


+ 0 - 0
data/logic/buy_1.logic.php


+ 138 - 138
data/logic/delivery.logic.php

@@ -1,139 +1,139 @@
-<?php
-/**
- * 物流推送
- *
- *
- *
- *
- * by Jeff Wan
- */
-
-defined('InShopNC') or exit('Access Invalid!');
-
-require_once (BASE_CORE_PATH . '/framework/function/http.php');
-
-class deliveryLogic
-{
-    private static $appURL = 'http://223.4.48.187:30004/lrlzApiRest/router/rest';
-    //'http://oms.shtest.lrlz.com:49521/lrlzApiRest/router/rest';
-
-    private static $appkey = '2015panda';
-    private static $appPassWord = 'nEs5vu86JSjh89WPW4de2d3e87rwli3e8rw';
-
-    private function _getSign($data){
-        return md5(self::$appkey . self::$appPassWord . json_encode($data));
-    }
-
-    public function putOrder($pay_sn, $trade_no)
-    {
-        Log::record(__FUNCTION__,Log::DEBUG);
-
-        $order_list = Model('order')->getNormalOrderList(array('pay_sn'=> $pay_sn), $this->page, '*', 'order_id desc', '', array('order_address', 'order_goods'));
-        $delivery_order_list = array();
-        foreach ($order_list as $order_info)
-        {
-            Log::record(" 1 ",Log::DEBUG);
-
-            if ($order_info['order_state'] === '20')
-            {
-                Log::record(" 2 ",Log::DEBUG);
-                $delivery_order = array();
-                $delivery_order['tid'] = $order_info['order_sn'];
-                $delivery_order['total_fee'] = $order_info['order_amount'];
-                $delivery_order['discount_fee'] = '';
-                $delivery_order['post_fee'] = $order_info['shipping_fee'];
-                $delivery_order['created'] = date('Y-m-d H:i:s', $order_info['add_time']);
-                $delivery_order['pay_time'] = date('Y-m-d H:i:s',$order_info['payment_time']);
-                $delivery_order['buyer_message'] = '';
-                $delivery_order['express_code'] = '';
-                $delivery_order['pay_account_type'] = $order_info['payment_code'] == 'wxpay' ? '微信支付': '支付宝';
-                $delivery_order['pay_account_id'] = '';
-                $delivery_order['pay_account_no'] = $trade_no;
-                $delivery_order['buyer_nick'] = $order_info['buyer_name'] === 'anonymous' ? 'anonymous'.'_'. $order_info['buyer_id'] : $order_info['buyer_name'];
-                $delivery_order['buyer_email'] = $order_info['buyer_email'];
-                $delivery_order['trade_memo'] = '';
-                $delivery_order['receiver_name'] = $order_info['reciver_name'];
-                $delivery_area =  explode("\t", $order_info['reciver_info']['area']);
-
-                $delivery_order['receiver_state'] = $delivery_area[0];
-                $delivery_order['receiver_city'] = $delivery_area[1];
-                $delivery_order['receiver_district'] = $delivery_area[2];
-
-                Log::record("{$delivery_order['receiver_state']} {$delivery_order['receiver_city']} {$delivery_order['receiver_district']}");
-
-                $delivery_order['receiver_address'] = $order_info['reciver_info']['street'];
-                $delivery_order['receiver_zip'] = '000000';
-                $delivery_order['receiver_mobile'] = $order_info['reciver_info']['mob_phone'];
-                $delivery_order['receiver_phone'] = $order_info['reciver_info']['tel_phone'];
-                $delivery_order['order_size'] = count($order_info['extend_order_goods']);
-                $delivery_order['orderList'] = array();
-
-                foreach($order_info['extend_order_goods'] as $key => $goods)
-                {
-                    $delivery_goods = array();
-                    $delivery_goods['oid'] =  $order_info['order_sn'] . $key;
-                    $delivery_goods['tid'] =  $order_info['order_sn'];
-                    $delivery_goods['title'] =  $goods['goods_name'];
-                    $delivery_goods['price'] =  $goods['goods_price'];
-                    $delivery_goods['num'] =  $goods['goods_num'];
-                    $goods_serial = Model('goods')->getGoodsInfo(array('goods_id'=>$goods['goods_id']));
-                    $delivery_goods['outer_sku_id'] = $goods_serial['goods_serial'];
-                    $delivery_goods['outer_sku_properties_name'] = $goods['goods_name'];
-                    $delivery_goods['buyer_nick'] = $order_info['buyer_name'] === 'anonymous' ? 'anonymous'.'_'. $order_info['buyer_id'] : $order_info['buyer_name'];
-                    array_push($delivery_order['orderList'] , $delivery_goods);
-                }
-                array_push($delivery_order_list, $delivery_order);
-            }
-        }
-        $data = array('type' => 'PUT_TRADE', 'data' => $delivery_order_list);
-        $sign = $this->_getSign($data);
-        $headers = array('v_appkey: '.self::$appkey, 'v_sign: '.$sign, 'Content-Type: application/json');
-        $result = http_post_data(self::$appURL,json_encode($data),$headers);
-        Log::record("post data={$result}",Log::DEBUG);
-        return $result;
-    }
-
-    private function _http_json_post($url, $params = array(), $headers = array())
-    {
-        if (!function_exists('curl_init')) {
-            return NULL;
-        }
-
-        $ci = curl_init();
-        curl_setopt($ci, CURLOPT_URL, $url);
-        if ($headers) {
-            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
-        }
-        curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
-        curl_setopt($ci, CURLOPT_POST, 1);
-        curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
-
-        $response = curl_exec($ci);
-
-        if($response){
-            curl_close($ci);
-            return $response;
-        } else {
-            $error = curl_errno($ci);
-            curl_close($ci);
-            return array('curl error code: '.$error);
-        }
-    }
-
-    public function handleCallback($param){
-        $model_order = Model('order');
-        $condition = array('order_sn' => $param['order_sn']);
-        $order_info = $model_order->getOrderInfo($condition,array('order_common','order_goods'));
-        $model_express = Model('express');
-        $express_info = $model_express->getExpressInfoByOMS($param['oms_code']);
-        $data['reciver_name'] = $order_info['reciver_name'];
-        $data['reciver_info'] = $order_info['reciver_info'];
-        $data['deliver_explain'] = $order_info['deliver_explain'];
-        $data['daddress_id'] = intval($order_info['daddress_id']);
-        $data['shipping_express_id'] =intval($express_info['express_id']);
-        $data['shipping_code']  = $param['shipping_code'];
-        $logic_order = Logic('order');
-        $result = $logic_order->changeOrderSend($order_info, 'seller', $order_info['buyer_name'], $data);
-        return $result;
-    }
+<?php
+/**
+ * 物流推送
+ *
+ *
+ *
+ *
+ * by Jeff Wan
+ */
+
+defined('InShopNC') or exit('Access Invalid!');
+
+require_once (BASE_CORE_PATH . '/framework/function/http.php');
+
+class deliveryLogic
+{
+    private static $appURL = 'http://223.4.48.187:30004/lrlzApiRest/router/rest';
+    //'http://oms.shtest.lrlz.com:49521/lrlzApiRest/router/rest';
+
+    private static $appkey = '2015panda';
+    private static $appPassWord = 'nEs5vu86JSjh89WPW4de2d3e87rwli3e8rw';
+
+    private function _getSign($data){
+        return md5(self::$appkey . self::$appPassWord . json_encode($data));
+    }
+
+    public function putOrder($pay_sn, $trade_no)
+    {
+        Log::record(__FUNCTION__,Log::DEBUG);
+
+        $order_list = Model('order')->getNormalOrderList(array('pay_sn'=> $pay_sn), $this->page, '*', 'order_id desc', '', array('order_address', 'order_goods'));
+        $delivery_order_list = array();
+        foreach ($order_list as $order_info)
+        {
+            Log::record(" 1 ",Log::DEBUG);
+
+            if ($order_info['order_state'] === '20')
+            {
+                Log::record(" 2 ",Log::DEBUG);
+                $delivery_order = array();
+                $delivery_order['tid'] = $order_info['order_sn'];
+                $delivery_order['total_fee'] = $order_info['order_amount'];
+                $delivery_order['discount_fee'] = '';
+                $delivery_order['post_fee'] = $order_info['shipping_fee'];
+                $delivery_order['created'] = date('Y-m-d H:i:s', $order_info['add_time']);
+                $delivery_order['pay_time'] = date('Y-m-d H:i:s',$order_info['payment_time']);
+                $delivery_order['buyer_message'] = '';
+                $delivery_order['express_code'] = '';
+                $delivery_order['pay_account_type'] = $order_info['payment_code'] == 'wxpay' ? '微信支付': '支付宝';
+                $delivery_order['pay_account_id'] = '';
+                $delivery_order['pay_account_no'] = $trade_no;
+                $delivery_order['buyer_nick'] = $order_info['buyer_name'] === 'anonymous' ? 'anonymous'.'_'. $order_info['buyer_id'] : $order_info['buyer_name'];
+                $delivery_order['buyer_email'] = $order_info['buyer_email'];
+                $delivery_order['trade_memo'] = '';
+                $delivery_order['receiver_name'] = $order_info['reciver_name'];
+                $delivery_area =  explode("\t", $order_info['reciver_info']['area']);
+
+                $delivery_order['receiver_state'] = $delivery_area[0];
+                $delivery_order['receiver_city'] = $delivery_area[1];
+                $delivery_order['receiver_district'] = $delivery_area[2];
+
+                Log::record("{$delivery_order['receiver_state']} {$delivery_order['receiver_city']} {$delivery_order['receiver_district']}");
+
+                $delivery_order['receiver_address'] = $order_info['reciver_info']['street'];
+                $delivery_order['receiver_zip'] = '000000';
+                $delivery_order['receiver_mobile'] = $order_info['reciver_info']['mob_phone'];
+                $delivery_order['receiver_phone'] = $order_info['reciver_info']['tel_phone'];
+                $delivery_order['order_size'] = count($order_info['extend_order_goods']);
+                $delivery_order['orderList'] = array();
+
+                foreach($order_info['extend_order_goods'] as $key => $goods)
+                {
+                    $delivery_goods = array();
+                    $delivery_goods['oid'] =  $order_info['order_sn'] . $key;
+                    $delivery_goods['tid'] =  $order_info['order_sn'];
+                    $delivery_goods['title'] =  $goods['goods_name'];
+                    $delivery_goods['price'] =  $goods['goods_price'];
+                    $delivery_goods['num'] =  $goods['goods_num'];
+                    $goods_serial = Model('goods')->getGoodsInfo(array('goods_id'=>$goods['goods_id']));
+                    $delivery_goods['outer_sku_id'] = $goods_serial['goods_serial'];
+                    $delivery_goods['outer_sku_properties_name'] = $goods['goods_name'];
+                    $delivery_goods['buyer_nick'] = $order_info['buyer_name'] === 'anonymous' ? 'anonymous'.'_'. $order_info['buyer_id'] : $order_info['buyer_name'];
+                    array_push($delivery_order['orderList'] , $delivery_goods);
+                }
+                array_push($delivery_order_list, $delivery_order);
+            }
+        }
+        $data = array('type' => 'PUT_TRADE', 'data' => $delivery_order_list);
+        $sign = $this->_getSign($data);
+        $headers = array('v_appkey: '.self::$appkey, 'v_sign: '.$sign, 'Content-Type: application/json');
+        $result = http_post_data(self::$appURL,json_encode($data),$headers);
+        Log::record("post data={$result}",Log::DEBUG);
+        return $result;
+    }
+
+    private function _http_json_post($url, $params = array(), $headers = array())
+    {
+        if (!function_exists('curl_init')) {
+            return NULL;
+        }
+
+        $ci = curl_init();
+        curl_setopt($ci, CURLOPT_URL, $url);
+        if ($headers) {
+            curl_setopt($ci, CURLOPT_HTTPHEADER, $headers);
+        }
+        curl_setopt($ci, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ci, CURLOPT_POST, 1);
+        curl_setopt($ci, CURLOPT_POSTFIELDS, $params);
+
+        $response = curl_exec($ci);
+
+        if($response){
+            curl_close($ci);
+            return $response;
+        } else {
+            $error = curl_errno($ci);
+            curl_close($ci);
+            return array('curl error code: '.$error);
+        }
+    }
+
+    public function handleCallback($param){
+        $model_order = Model('order');
+        $condition = array('order_sn' => $param['order_sn']);
+        $order_info = $model_order->getOrderInfo($condition,array('order_common','order_goods'));
+        $model_express = Model('express');
+        $express_info = $model_express->getExpressInfoByOMS($param['oms_code']);
+        $data['reciver_name'] = $order_info['reciver_name'];
+        $data['reciver_info'] = $order_info['reciver_info'];
+        $data['deliver_explain'] = $order_info['deliver_explain'];
+        $data['daddress_id'] = intval($order_info['daddress_id']);
+        $data['shipping_express_id'] =intval($express_info['express_id']);
+        $data['shipping_code']  = $param['shipping_code'];
+        $logic_order = Logic('order');
+        $result = $logic_order->changeOrderSend($order_info, 'seller', $order_info['buyer_name'], $data);
+        return $result;
+    }
 }

+ 31 - 31
data/model/bonus_type.model.php

@@ -1,31 +1,31 @@
-<?php
-/**
- * 红包类型模型
- *
-
- */
-
-defined('InShopNC') or exit('Access Invalid!');
-
-class bonus_typeModel extends Model {
-    public function __construct()
-    {
-        parent::__construct('bonus_type');
-    }
-
-    public function getAll(){
-        return $this->select();
-    }
-
-    public function get($id){
-        return $this->where(array('type_id' => $id))->select();
-    }
-
-    public function save($data, &$id){
-        if($id > 0){
-            $this->where(array('type_id' => $id))->update($data);
-        }else{
-            $id = $this->insert($data);
-        }
-    }
-}
+<?php
+/**
+ * 红包类型模型
+ *
+
+ */
+
+defined('InShopNC') or exit('Access Invalid!');
+
+class bonus_typeModel extends Model {
+    public function __construct()
+    {
+        parent::__construct('bonus_type');
+    }
+
+    public function getAll(){
+        return $this->select();
+    }
+
+    public function get($id){
+        return $this->where(array('type_id' => $id))->select();
+    }
+
+    public function save($data, &$id){
+        if($id > 0){
+            $this->where(array('type_id' => $id))->update($data);
+        }else{
+            $id = $this->insert($data);
+        }
+    }
+}

+ 0 - 0
data/model/db.model.php


+ 0 - 0
data/model/express.model.php


+ 0 - 0
data/model/goods_attr_index.model.php


+ 0 - 0
data/model/goods_class.model.php


+ 0 - 0
data/model/goods_gift.model.php


+ 0 - 0
data/model/goods_info_by_url.model.php


+ 0 - 0
data/model/groupbuy.model.php


+ 0 - 0
data/model/invoice.model.php


+ 0 - 0
data/model/live_groupbuy.model.php


+ 0 - 0
data/model/order.model.php


+ 0 - 0
data/model/p_xianshi_goods.model.php


+ 0 - 0
data/model/search.model.php


+ 0 - 0
data/model/store_class.model.php


+ 0 - 0
data/model/store_msg_read.model.php


+ 0 - 0
data/model/type.model.php


+ 55 - 55
data/model/user_bonus.model.php

@@ -1,56 +1,56 @@
-<?php
-/**
- * ����
- *
-
- */
-defined('InShopNC') or exit('Access Invalid!');
-class user_bonusModel extends Model
-{
-    public function __construct() {
-        parent::__construct('user_bonus');
-    }
-
-    public function loadFile($content) {
-        $lines = explode("\n", $content);
-        foreach($lines as $line){
-            $bonus = explode(',', trim($line));
-            $this->createBonus($bonus);
-        }
-    }
-
-    public function getBonus($user_id, $user_mobile){
-        $bonus = $this->where(array('user_mobile' => $user_mobile))->select();
-        if(intval($bonus[0]['user_id']) === 0){
-            $update_data = array(
-                'user_id' => $user_id,
-                'get_time' => time()
-            );
-            $this->where(array('user_mobile' => $user_mobile))->update($update_data);
-        }
-        $bonus_data = array(
-            'bonus_sn' => $bonus[0]['bonus_sn'],
-            'bonus_value' => $bonus[0]['bonus_value']
-        );
-        return $bonus_data;
-    }
-
-    private function createBonus($bonus){
-        $bouns_sn = $this->generateSn();
-        $bonus_value = array(
-            'bonus_sn' => $bouns_sn,
-            'bonus_type_id' => 1,
-            'user_mobile' => $bonus[0],
-            'bonus_value' => $bonus[1]
-        );
-        $this->insert($bonus_value);
-    }
-
-    private function generateSn(){
-        $max_sn_rec = $this->field('MAX(bonus_sn) as max_sn')->select();
-        $max_sn = $max_sn_rec[0]['max_sn']? floor($max_sn_rec[0]['max_sn'] / 10000): 100000;
-
-        $bonus_sn = ($max_sn + 1) . str_pad(mt_rand(0, 9999), 4, '0', STR_PAD_LEFT);
-        return $bonus_sn;
-    }
+<?php
+/**
+ * ����
+ *
+
+ */
+defined('InShopNC') or exit('Access Invalid!');
+class user_bonusModel extends Model
+{
+    public function __construct() {
+        parent::__construct('user_bonus');
+    }
+
+    public function loadFile($content) {
+        $lines = explode("\n", $content);
+        foreach($lines as $line){
+            $bonus = explode(',', trim($line));
+            $this->createBonus($bonus);
+        }
+    }
+
+    public function getBonus($user_id, $user_mobile){
+        $bonus = $this->where(array('user_mobile' => $user_mobile))->select();
+        if(intval($bonus[0]['user_id']) === 0){
+            $update_data = array(
+                'user_id' => $user_id,
+                'get_time' => time()
+            );
+            $this->where(array('user_mobile' => $user_mobile))->update($update_data);
+        }
+        $bonus_data = array(
+            'bonus_sn' => $bonus[0]['bonus_sn'],
+            'bonus_value' => $bonus[0]['bonus_value']
+        );
+        return $bonus_data;
+    }
+
+    private function createBonus($bonus){
+        $bouns_sn = $this->generateSn();
+        $bonus_value = array(
+            'bonus_sn' => $bouns_sn,
+            'bonus_type_id' => 1,
+            'user_mobile' => $bonus[0],
+            'bonus_value' => $bonus[1]
+        );
+        $this->insert($bonus_value);
+    }
+
+    private function generateSn(){
+        $max_sn_rec = $this->field('MAX(bonus_sn) as max_sn')->select();
+        $max_sn = $max_sn_rec[0]['max_sn']? floor($max_sn_rec[0]['max_sn'] / 10000): 100000;
+
+        $bonus_sn = ($max_sn + 1) . str_pad(mt_rand(0, 9999), 4, '0', STR_PAD_LEFT);
+        return $bonus_sn;
+    }
 }

+ 0 - 0
data/model/web_config.model.php


+ 0 - 0
data/resource/web_config/web_index.js


+ 43 - 43
debug_run.php

@@ -1,43 +1,43 @@
-<?php
-
-printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
-
-$reqs = array();
-//$reqs['index'] = 'http://localhost:8080/';
-//$reqs['index'] ='http://localhost:8080/mobile/index.php?act=index&op=index';
-//$reqs['login_register'] ='http://localhost:8080/mobile/index.php?act=login&op=register&username=stanley&password=55668899&password_confirm=55668899';
-
-//$reqs['login_genanonymous'] ='http://localhost:.
-//mobile/index.php?act=login&op=genuser&info=helloworld&type=1&client=android';
-//$reqs['login_genwx'] ='http://localhost:8080/mobile/index.php?act=login&op=genuser&type=2&openid=123456789000&client=android';
-
-//$reqs['login_anonymous_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&openid=561f708422817&type=1&client=android';
-//$reqs['login_wx_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&openid=123456789000&type=2&client=android';
-//$reqs['login_mobile_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&mobile=18022196345&password=55668899&type=0&client=android';
-
-
-//$reqs['login_wx_getinfo'] ='http://localhost:8080/mobile/index.php?act=login&op=getinfo&token=08a6a71c051bc5be33f85141f3ca6b52';
-
-//$reqs['login_wx_getcode'] ='http://localhost:8080/mobile/index.php?act=login&op=getcode&token=fe22e0bc1c2e776b3dc22374fc96b0af&mobile=13911129867';
-//$reqs['login_wx_checkcode'] ='http://localhost:8080/mobile/index.php?act=login&op=checkcode&token=08a6a71c051bc5be33f85141f3ca6b52&code=0369';
-
-//$reqs['login_wx_bind'] ='http://localhost:8080/mobile/index.php?act=login&op=bind&token=fe22e0bc1c2e776b3dc22374fc96b0af&code=2578&password=55668899&type=mobile';
-
-$reqs['login_wx_bind'] = 'http://localhost/mobile/index.php?act=goods&op=goods_list&page=10&curpage=1';
-
-
-foreach ($reqs as $key => $uri)
-{    
-    define('StartTime', microtime(true));
-    define('TIMESTAMP', time());
-    
-    $lreq = new local_request($uri);    
-    init_localreq($lreq); 
-   
-    $file = $lreq->script_file(); 
-    if(is_file($file)) {
-        include $file;
-    } else {
-        echo 'no such file';
-    }
-}
+<?php
+
+printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
+
+$reqs = array();
+//$reqs['index'] = 'http://localhost:8080/';
+//$reqs['index'] ='http://localhost:8080/mobile/index.php?act=index&op=index';
+//$reqs['login_register'] ='http://localhost:8080/mobile/index.php?act=login&op=register&username=stanley&password=55668899&password_confirm=55668899';
+
+//$reqs['login_genanonymous'] ='http://localhost:.
+//mobile/index.php?act=login&op=genuser&info=helloworld&type=1&client=android';
+//$reqs['login_genwx'] ='http://localhost:8080/mobile/index.php?act=login&op=genuser&type=2&openid=123456789000&client=android';
+
+//$reqs['login_anonymous_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&openid=561f708422817&type=1&client=android';
+//$reqs['login_wx_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&openid=123456789000&type=2&client=android';
+//$reqs['login_mobile_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&mobile=18022196345&password=55668899&type=0&client=android';
+
+
+//$reqs['login_wx_getinfo'] ='http://localhost:8080/mobile/index.php?act=login&op=getinfo&token=08a6a71c051bc5be33f85141f3ca6b52';
+
+//$reqs['login_wx_getcode'] ='http://localhost:8080/mobile/index.php?act=login&op=getcode&token=fe22e0bc1c2e776b3dc22374fc96b0af&mobile=13911129867';
+//$reqs['login_wx_checkcode'] ='http://localhost:8080/mobile/index.php?act=login&op=checkcode&token=08a6a71c051bc5be33f85141f3ca6b52&code=0369';
+
+//$reqs['login_wx_bind'] ='http://localhost:8080/mobile/index.php?act=login&op=bind&token=fe22e0bc1c2e776b3dc22374fc96b0af&code=2578&password=55668899&type=mobile';
+
+$reqs['login_wx_bind'] = 'http://localhost/mobile/index.php?act=goods&op=goods_list&page=10&curpage=1';
+
+
+foreach ($reqs as $key => $uri)
+{    
+    define('StartTime', microtime(true));
+    define('TIMESTAMP', time());
+    
+    $lreq = new local_request($uri);    
+    init_localreq($lreq); 
+   
+    $file = $lreq->script_file(); 
+    if(is_file($file)) {
+        include $file;
+    } else {
+        echo 'no such file';
+    }
+}

+ 58 - 58
fcgi_run.php

@@ -1,59 +1,59 @@
-<?php
-
-define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
-define('MOBILE_SERVER',true);
-
-require_once (BASE_ROOT_PATH . '/fooder.php');
-
-function pays_execute($file)
-{
-    static $exfiles = array('wxnotify.php','alipay_notify_url.php','dispatch_notify.php');
-    $name = basename($file);
-
-    return in_array($name,$exfiles);
-}
-
-
-function run_fcgi()
-{
-    require_once(BASE_ROOT_PATH.'/mobile/index.php');
-    Base::mobile_init();
-
-    while(($ret = fcgi_accept()) >= 0)
-    {
-        ob_start();
-
-        define('StartTime',microtime(true));
-        define('TIMESTAMP',time());
-
-        try
-        {
-            init_request();
-            Log::record(request_helper::req_uri(),Log::DEBUG);
-
-            $file = request_helper::script_file();
-            if(file_exists($file))
-            {
-                if(pays_execute($file)) {
-                    echo("Content-Type: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8; charset=UTF-8\r\n\r\n");
-                    include $file;
-                } else {
-                    echo("Content-Type: text/html; charset=UTF-8\r\n\r\n");
-                    Base::mobile_control();
-                }
-            }
-        } catch (Exception $ex) {
-            joutput_error($ex->getCode(),$ex->getMessage().'@@@@@'.$ex->getTraceAsString());
-        }
-
-        $contents = ob_get_clean();
-        fcgi_echo($contents);
-        Log::record($contents,Log::DEBUG);
-        fcgi_finish();
-    }
-
-    fcgi_fini();
-}
-
-run_fcgi();
+<?php
+
+define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
+define('MOBILE_SERVER',true);
+
+require_once (BASE_ROOT_PATH . '/fooder.php');
+
+function pays_execute($file)
+{
+    static $exfiles = array('wxnotify.php','alipay_notify_url.php','dispatch_notify.php');
+    $name = basename($file);
+
+    return in_array($name,$exfiles);
+}
+
+
+function run_fcgi()
+{
+    require_once(BASE_ROOT_PATH.'/mobile/index.php');
+    Base::mobile_init();
+
+    while(($ret = fcgi_accept()) >= 0)
+    {
+        ob_start();
+
+        define('StartTime',microtime(true));
+        define('TIMESTAMP',time());
+
+        try
+        {
+            init_request();
+            Log::record(request_helper::req_uri(),Log::DEBUG);
+
+            $file = request_helper::script_file();
+            if(file_exists($file))
+            {
+                if(pays_execute($file)) {
+                    echo("Content-Type: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8; charset=UTF-8\r\n\r\n");
+                    include $file;
+                } else {
+                    echo("Content-Type: text/html; charset=UTF-8\r\n\r\n");
+                    Base::mobile_control();
+                }
+            }
+        } catch (Exception $ex) {
+            joutput_error($ex->getCode(),$ex->getMessage().'@@@@@'.$ex->getTraceAsString());
+        }
+
+        $contents = ob_get_clean();
+        fcgi_echo($contents);
+        Log::record($contents,Log::DEBUG);
+        fcgi_finish();
+    }
+
+    fcgi_fini();
+}
+
+run_fcgi();
 ?>

+ 34 - 34
fooder.php

@@ -1,35 +1,35 @@
-<?php
-
-date_default_timezone_set('UTC');
-
-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');
-define('BASE_UTIL_PATH',BASE_ROOT_PATH.'/util');
-
-require_once(BASE_MOBILE_PATH . '/util/errcode.php');
-require_once(BASE_ROOT_PATH . '/request_helper.php');
-require_once(BASE_ROOT_PATH . '/global.php');
-
-require_once(BASE_DATA_PATH . '/config/config.ini.php');
-require_once(BASE_CORE_PATH .'/33hao.php');
-require_once(BASE_MOBILE_PATH . '/config/config.ini.php');
-require_once(BASE_MOBILE_PATH.'/framework/function/function.php');
-
-require_once(BASE_CORE_PATH.'/framework/libraries/queue.php');
-require_once(BASE_CORE_PATH.'/framework/libraries/tpl.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/libraries/cache.php');
-require_once(BASE_CORE_PATH.'/framework/libraries/queue.php');
-require_once(BASE_CORE_PATH.'/framework/libraries/language.php');
-require_once(BASE_CORE_PATH.'/framework/libraries/model.php');
-require_once(BASE_CORE_PATH.'/framework/libraries/log.php');
-require_once(BASE_CORE_PATH.'/framework/db/mysqli.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');
-require_once (BASE_MOBILE_PATH . '/control/log.php');
+<?php
+
+date_default_timezone_set('UTC');
+
+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');
+define('BASE_UTIL_PATH',BASE_ROOT_PATH.'/util');
+
+require_once(BASE_MOBILE_PATH . '/util/errcode.php');
+require_once(BASE_ROOT_PATH . '/request_helper.php');
+require_once(BASE_ROOT_PATH . '/global.php');
+
+require_once(BASE_DATA_PATH . '/config/config.ini.php');
+require_once(BASE_CORE_PATH .'/33hao.php');
+require_once(BASE_MOBILE_PATH . '/config/config.ini.php');
+require_once(BASE_MOBILE_PATH.'/framework/function/function.php');
+
+require_once(BASE_CORE_PATH.'/framework/libraries/queue.php');
+require_once(BASE_CORE_PATH.'/framework/libraries/tpl.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/libraries/cache.php');
+require_once(BASE_CORE_PATH.'/framework/libraries/queue.php');
+require_once(BASE_CORE_PATH.'/framework/libraries/language.php');
+require_once(BASE_CORE_PATH.'/framework/libraries/model.php');
+require_once(BASE_CORE_PATH.'/framework/libraries/log.php');
+require_once(BASE_CORE_PATH.'/framework/db/mysqli.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');
+require_once (BASE_MOBILE_PATH . '/control/log.php');
 ?>

+ 18 - 18
gcidfiller.php

@@ -1,19 +1,19 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/1/11
- * Time: 下午12:43
- */
-
-
-define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
-require_once (BASE_ROOT_PATH . '/fooder.php');
-require_once (BASE_UTIL_PATH . '/gcid_fill.php');
-
-define('StartTime', microtime(true));
-define('TIMESTAMP', time());
-Base::run_test();
-
-$filler = new gcid_fill();
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 16/1/11
+ * Time: 下午12:43
+ */
+
+
+define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
+require_once (BASE_ROOT_PATH . '/fooder.php');
+require_once (BASE_UTIL_PATH . '/gcid_fill.php');
+
+define('StartTime', microtime(true));
+define('TIMESTAMP', time());
+Base::run_test();
+
+$filler = new gcid_fill();
 $filler->proc();

+ 0 - 0
index.php


Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác