Browse Source

feat 添加订单物流

tumobi 7 years ago
parent
commit
500282b31e

+ 106 - 49
nideshop.sql

@@ -1,13 +1,13 @@
--- MySQL dump 10.13  Distrib 5.7.12, for Win64 (x86_64)
+-- MySQL dump 10.13  Distrib 5.7.17, for Win64 (x86_64)
 --
--- Host: 127.0.0.1    Database: nideshop
+-- Host: 39.108.108.55    Database: nideshop
 -- ------------------------------------------------------
--- Server version	5.5.40
+-- Server version	5.7.20
 
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
-/*!40101 SET NAMES utf8mb4 */;
+/*!40101 SET NAMES utf8 */;
 /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
 /*!40103 SET TIME_ZONE='+00:00' */;
 /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
@@ -21,7 +21,7 @@
 
 DROP TABLE IF EXISTS `nideshop_ad`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_ad` (
   `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
   `ad_position_id` smallint(5) unsigned NOT NULL DEFAULT '0',
@@ -54,7 +54,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_ad_position`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_ad_position` (
   `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
   `name` varchar(60) NOT NULL DEFAULT '',
@@ -81,7 +81,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_address`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_address` (
   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `name` varchar(50) NOT NULL DEFAULT '',
@@ -114,7 +114,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_admin`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_admin` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `username` varchar(10) NOT NULL DEFAULT '''''',
@@ -146,7 +146,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_attribute`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_attribute` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `attribute_category_id` int(11) unsigned NOT NULL DEFAULT '0',
@@ -175,7 +175,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_attribute_category`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_attribute_category` (
   `id` int(11) unsigned NOT NULL,
   `name` varchar(60) NOT NULL DEFAULT '',
@@ -200,7 +200,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_brand`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_brand` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `name` varchar(255) NOT NULL DEFAULT '',
@@ -235,7 +235,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_cart`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_cart` (
   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `user_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
@@ -272,7 +272,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_category`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_category` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `name` varchar(90) NOT NULL DEFAULT '',
@@ -310,7 +310,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_channel`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_channel` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `name` varchar(45) NOT NULL DEFAULT '',
@@ -337,7 +337,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_collect`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_collect` (
   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `user_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
@@ -368,7 +368,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_comment`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_comment` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `type_id` tinyint(3) unsigned NOT NULL DEFAULT '0',
@@ -399,7 +399,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_comment_picture`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_comment_picture` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `comment_id` int(11) unsigned NOT NULL DEFAULT '0',
@@ -425,7 +425,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_coupon`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_coupon` (
   `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
   `name` varchar(60) NOT NULL DEFAULT '',
@@ -458,7 +458,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_feedback`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_feedback` (
   `msg_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `parent_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
@@ -494,14 +494,14 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_footprint`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_footprint` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `user_id` int(11) NOT NULL DEFAULT '0',
   `goods_id` int(11) NOT NULL DEFAULT '0',
   `add_time` int(11) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=89 DEFAULT CHARSET=utf8mb4;
+) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8mb4;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -510,7 +510,7 @@ CREATE TABLE `nideshop_footprint` (
 
 LOCK TABLES `nideshop_footprint` WRITE;
 /*!40000 ALTER TABLE `nideshop_footprint` DISABLE KEYS */;
-INSERT INTO `nideshop_footprint` VALUES (10,1,1152161,1497674756),(20,1,1152161,1497685361),(22,1,1152161,1497685374),(24,1,1152161,1497685394),(25,1,1156006,1497685418),(26,1,1113019,1497685452),(27,1,1156006,1497685528),(28,1,1113019,1497685650),(29,1,1114011,1497685671),(30,1,1156006,1497685798),(31,1,1181000,1497685812),(32,1,1152161,1497685817),(33,1,1057036,1497685824),(34,1,1023003,1497685828),(35,1,1085019,1497685833),(36,1,1181000,1497685840),(37,1,1085019,1497685952),(38,1,1181000,1500086354),(39,1,1130037,1500428563),(40,1,1030003,1500428699),(41,1,1030003,1500428701),(42,1,1147046,1500561687),(43,1,1143016,1500727170),(44,1,1116011,1500727970),(45,1,1116011,1500811201),(46,1,1006013,1500811213),(47,11,1116011,1500822628),(48,11,1127047,1500822635),(49,11,1006013,1500822646),(50,11,1009012,1500822666),(51,11,1011004,1500822814),(52,11,1011004,1500822831),(53,11,1115028,1500823219),(54,11,1015007,1500823260),(55,11,1006013,1500910756),(56,11,1009012,1500910795),(57,11,1006013,1500911162),(58,11,1009012,1500987803),(59,11,1009012,1500987827),(60,11,1009012,1500987975),(61,11,1143020,1500993469),(62,11,1020000,1500994081),(63,11,1020000,1500997775),(64,11,1006013,1500998521),(65,11,1006013,1500998612),(66,11,1092024,1501082801),(67,11,1006013,1501341315),(68,1,1006013,1501380499),(69,1,1006013,1501381026),(70,1,1006013,1501381307),(71,1,1116011,1501404539),(72,1,1006013,1501404548),(73,1,1006013,1501404833),(74,1,1116011,1501407318),(75,1,1116011,1501408596),(76,1,1015007,1501602678),(77,1,1011004,1501602769),(78,1,1116011,1505404383),(79,1,1015007,1505404405),(80,1,1030002,1505404415),(81,1,1038004,1505404424),(82,1,1045000,1505404433),(83,1,1085019,1505404449),(84,1,1092026,1505404804),(85,1,1116005,1505404812),(86,1,1039056,1505404825),(87,1,1152031,1505404834),(88,1,1130056,1505404865);
+INSERT INTO `nideshop_footprint` VALUES (10,1,1152161,1497674756),(20,1,1152161,1497685361),(22,1,1152161,1497685374),(24,1,1152161,1497685394),(25,1,1156006,1497685418),(26,1,1113019,1497685452),(27,1,1156006,1497685528),(28,1,1113019,1497685650),(29,1,1114011,1497685671),(30,1,1156006,1497685798),(31,1,1181000,1497685812),(32,1,1152161,1497685817),(33,1,1057036,1497685824),(34,1,1023003,1497685828),(35,1,1085019,1497685833),(36,1,1181000,1497685840),(37,1,1085019,1497685952),(38,1,1181000,1500086354),(39,1,1130037,1500428563),(40,1,1030003,1500428699),(41,1,1030003,1500428701),(42,1,1147046,1500561687),(43,1,1143016,1500727170),(44,1,1116011,1500727970),(45,1,1116011,1500811201),(46,1,1006013,1500811213),(47,11,1116011,1500822628),(48,11,1127047,1500822635),(49,11,1006013,1500822646),(50,11,1009012,1500822666),(51,11,1011004,1500822814),(52,11,1011004,1500822831),(53,11,1115028,1500823219),(54,11,1015007,1500823260),(55,11,1006013,1500910756),(56,11,1009012,1500910795),(57,11,1006013,1500911162),(58,11,1009012,1500987803),(59,11,1009012,1500987827),(60,11,1009012,1500987975),(61,11,1143020,1500993469),(62,11,1020000,1500994081),(63,11,1020000,1500997775),(64,11,1006013,1500998521),(65,11,1006013,1500998612),(66,11,1092024,1501082801),(67,11,1006013,1501341315),(68,1,1006013,1501380499),(69,1,1006013,1501381026),(70,1,1006013,1501381307),(71,1,1116011,1501404539),(72,1,1006013,1501404548),(73,1,1006013,1501404833),(74,1,1116011,1501407318),(75,1,1116011,1501408596),(76,1,1015007,1501602678),(77,1,1011004,1501602769),(78,1,1116011,1505404383),(79,1,1015007,1505404405),(80,1,1030002,1505404415),(81,1,1038004,1505404424),(82,1,1045000,1505404433),(83,1,1085019,1505404449),(84,1,1092026,1505404804),(85,1,1116005,1505404812),(86,1,1039056,1505404825),(87,1,1152031,1505404834),(88,1,1130056,1505404865),(89,13,1116011,1518156484),(90,13,1006013,1518156493),(91,13,1006013,1518157620);
 /*!40000 ALTER TABLE `nideshop_footprint` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -520,7 +520,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_goods`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_goods` (
   `id` int(11) unsigned NOT NULL,
   `category_id` int(11) unsigned NOT NULL DEFAULT '0',
@@ -578,7 +578,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_goods_attribute`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_goods_attribute` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `goods_id` int(11) unsigned NOT NULL DEFAULT '0',
@@ -606,7 +606,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_goods_gallery`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_goods_gallery` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `goods_id` int(11) unsigned NOT NULL DEFAULT '0',
@@ -634,7 +634,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_goods_issue`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_goods_issue` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `goods_id` text,
@@ -660,7 +660,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_goods_specification`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_goods_specification` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `goods_id` int(11) unsigned NOT NULL DEFAULT '0',
@@ -689,7 +689,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_keywords`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_keywords` (
   `keyword` varchar(90) NOT NULL DEFAULT '',
   `is_hot` tinyint(1) unsigned NOT NULL DEFAULT '0',
@@ -719,7 +719,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_order`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_order` (
   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `order_sn` varchar(20) NOT NULL DEFAULT '',
@@ -735,11 +735,9 @@ CREATE TABLE `nideshop_order` (
   `address` varchar(255) NOT NULL DEFAULT '',
   `mobile` varchar(60) NOT NULL DEFAULT '',
   `postscript` varchar(255) NOT NULL DEFAULT '',
-  `shipping_id` tinyint(3) NOT NULL DEFAULT '0',
-  `shipping_name` varchar(120) NOT NULL DEFAULT '',
-  `pay_id` tinyint(3) NOT NULL DEFAULT '0',
-  `pay_name` varchar(120) NOT NULL DEFAULT '',
   `shipping_fee` decimal(10,2) NOT NULL DEFAULT '0.00',
+  `pay_name` varchar(120) NOT NULL DEFAULT '',
+  `pay_id` tinyint(3) NOT NULL DEFAULT '0',
   `actual_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '实际需要支付的金额',
   `integral` int(10) unsigned NOT NULL DEFAULT '0',
   `integral_money` decimal(10,2) NOT NULL DEFAULT '0.00',
@@ -751,7 +749,7 @@ CREATE TABLE `nideshop_order` (
   `freight_price` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配送费用',
   `coupon_id` mediumint(8) unsigned NOT NULL DEFAULT '0' COMMENT '使用的优惠券id',
   `parent_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
-  `coupon_price` decimal(10,2) NOT NULL,
+  `coupon_price` decimal(10,2) NOT NULL DEFAULT '0.00',
   `callback_status` enum('true','false') DEFAULT 'true',
   PRIMARY KEY (`id`),
   UNIQUE KEY `order_sn` (`order_sn`),
@@ -759,7 +757,6 @@ CREATE TABLE `nideshop_order` (
   KEY `order_status` (`order_status`),
   KEY `shipping_status` (`shipping_status`),
   KEY `pay_status` (`pay_status`),
-  KEY `shipping_id` (`shipping_id`),
   KEY `pay_id` (`pay_id`)
 ) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4;
 /*!40101 SET character_set_client = @saved_cs_client */;
@@ -774,12 +771,46 @@ LOCK TABLES `nideshop_order` WRITE;
 UNLOCK TABLES;
 
 --
+-- Table structure for table `nideshop_order_express`
+--
+
+DROP TABLE IF EXISTS `nideshop_order_express`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `nideshop_order_express` (
+  `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+  `order_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
+  `shipper_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
+  `shipper_name` varchar(120) NOT NULL DEFAULT '' COMMENT '物流公司名称',
+  `shipper_code` varchar(60) NOT NULL DEFAULT '' COMMENT '物流公司代码',
+  `logistic_code` varchar(20) NOT NULL DEFAULT '' COMMENT '快递单号',
+  `traces` varchar(2000) NOT NULL DEFAULT '' COMMENT '物流跟踪信息',
+  `is_finish` tinyint(1) NOT NULL DEFAULT '0',
+  `request_count` int(11) DEFAULT '0' COMMENT '总查询次数',
+  `request_time` int(11) DEFAULT '0' COMMENT '最近一次向第三方查询物流信息时间',
+  `add_time` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
+  `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
+  PRIMARY KEY (`id`),
+  KEY `order_id` (`order_id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COMMENT='订单物流信息表,发货时生成';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `nideshop_order_express`
+--
+
+LOCK TABLES `nideshop_order_express` WRITE;
+/*!40000 ALTER TABLE `nideshop_order_express` DISABLE KEYS */;
+/*!40000 ALTER TABLE `nideshop_order_express` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
 -- Table structure for table `nideshop_order_goods`
 --
 
 DROP TABLE IF EXISTS `nideshop_order_goods`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_order_goods` (
   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `order_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
@@ -815,7 +846,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_product`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_product` (
   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `goods_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
@@ -843,7 +874,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_region`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_region` (
   `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
   `parent_id` smallint(5) unsigned NOT NULL DEFAULT '0',
@@ -873,7 +904,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_related_goods`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_related_goods` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `goods_id` int(11) unsigned NOT NULL DEFAULT '0',
@@ -897,7 +928,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_search_history`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_search_history` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `keyword` char(50) NOT NULL,
@@ -919,12 +950,39 @@ INSERT INTO `nideshop_search_history` VALUES (23,'母亲节','',1500564813,'1'),
 UNLOCK TABLES;
 
 --
+-- Table structure for table `nideshop_shipper`
+--
+
+DROP TABLE IF EXISTS `nideshop_shipper`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `nideshop_shipper` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `name` varchar(20) NOT NULL DEFAULT '' COMMENT '快递公司名称',
+  `code` varchar(10) NOT NULL DEFAULT '' COMMENT '快递公司代码',
+  `sort_order` int(11) NOT NULL DEFAULT '10' COMMENT '排序',
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `nideshop_shipper_id_uindex` (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COMMENT='快递公司';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `nideshop_shipper`
+--
+
+LOCK TABLES `nideshop_shipper` WRITE;
+/*!40000 ALTER TABLE `nideshop_shipper` DISABLE KEYS */;
+INSERT INTO `nideshop_shipper` VALUES (1,'顺丰速运','SF',1),(2,'百世快递','HTKY',2),(3,'中通快递','ZTO',3),(4,'申通快递','STO',4),(5,'圆通速递','YTO',5),(6,'韵达速递','YD',6),(7,'邮政快递包裹','YZPY',7),(8,'EMS','EMS',8),(9,'天天快递','HHTT',9),(10,'京东物流','JD',10),(11,'全峰快递','QFKD',11),(12,'国通快递','GTO',12),(13,'优速快递','UC',13);
+/*!40000 ALTER TABLE `nideshop_shipper` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
 -- Table structure for table `nideshop_specification`
 --
 
 DROP TABLE IF EXISTS `nideshop_specification`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_specification` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `name` varchar(60) NOT NULL DEFAULT '',
@@ -949,7 +1007,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_topic`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_topic` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `title` varchar(255) NOT NULL DEFAULT '''''',
@@ -985,7 +1043,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_topic_category`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_topic_category` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `title` varchar(255) NOT NULL DEFAULT '',
@@ -1010,7 +1068,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_user`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_user` (
   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `username` varchar(60) NOT NULL DEFAULT '',
@@ -1028,7 +1086,7 @@ CREATE TABLE `nideshop_user` (
   `weixin_openid` varchar(50) NOT NULL DEFAULT '',
   PRIMARY KEY (`id`),
   UNIQUE KEY `user_name` (`username`)
-) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4;
+) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
 --
@@ -1037,7 +1095,6 @@ CREATE TABLE `nideshop_user` (
 
 LOCK TABLES `nideshop_user` WRITE;
 /*!40000 ALTER TABLE `nideshop_user` DISABLE KEYS */;
-INSERT INTO `nideshop_user` VALUES (1,'nideshop','oILjs0JEDIZzaWVc_sJW2k3fhp1k',1,0,1501342787,1501342840,'192.168.31.233',0,'你的商城','','192.168.31.233','https://yanxuan.nosdn.127.net/80841d741d7fa3073e0ae27bf487339f.jpg?imageView&quality=90&thumbnail=64x64','oILjs0JESDXXWVc_sJW2k3fhp1k');
 /*!40000 ALTER TABLE `nideshop_user` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -1047,7 +1104,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_user_coupon`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_user_coupon` (
   `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
   `coupon_id` tinyint(3) unsigned NOT NULL DEFAULT '0',
@@ -1076,7 +1133,7 @@ UNLOCK TABLES;
 
 DROP TABLE IF EXISTS `nideshop_user_level`;
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
-/*!40101 SET character_set_client = utf8mb4 */;
+/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE `nideshop_user_level` (
   `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
   `name` varchar(30) NOT NULL DEFAULT '',
@@ -1112,4 +1169,4 @@ UNLOCK TABLES;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
 
--- Dump completed on 2017-09-15 22:17:52
+-- Dump completed on 2018-02-09 20:26:21

+ 26 - 10
src/api/controller/order.js

@@ -7,11 +7,11 @@ module.exports = class extends Base {
    * @return {Promise} []
    */
   async listAction() {
-    const orderList = await this.model('order').where({user_id: think.userId}).page(1, 10).countSelect();
+    const orderList = await this.model('order').where({ user_id: think.userId }).page(1, 10).countSelect();
     const newOrderList = [];
     for (const item of orderList.data) {
       // 订单的商品
-      item.goodsList = await this.model('order_goods').where({order_id: item.id}).select();
+      item.goodsList = await this.model('order_goods').where({ order_id: item.id }).select();
       item.goodsCount = 0;
       item.goodsList.forEach(v => {
         item.goodsCount += v.number;
@@ -32,18 +32,21 @@ module.exports = class extends Base {
 
   async detailAction() {
     const orderId = this.get('orderId');
-    const orderInfo = await this.model('order').where({user_id: think.userId, id: orderId}).find();
+    const orderInfo = await this.model('order').where({ user_id: 1, id: orderId }).find();
 
     if (think.isEmpty(orderInfo)) {
       return this.fail('订单不存在');
     }
 
-    orderInfo.province_name = await this.model('region').where({id: orderInfo.province}).getField('name', true);
-    orderInfo.city_name = await this.model('region').where({id: orderInfo.city}).getField('name', true);
-    orderInfo.district_name = await this.model('region').where({id: orderInfo.district}).getField('name', true);
+    orderInfo.province_name = await this.model('region').where({ id: orderInfo.province }).getField('name', true);
+    orderInfo.city_name = await this.model('region').where({ id: orderInfo.city }).getField('name', true);
+    orderInfo.district_name = await this.model('region').where({ id: orderInfo.district }).getField('name', true);
     orderInfo.full_region = orderInfo.province_name + orderInfo.city_name + orderInfo.district_name;
 
-    const orderGoods = await this.model('order_goods').where({order_id: orderId}).select();
+    const latestExpressInfo = await this.model('order_express').getLatestOrderExpress(orderId);
+    orderInfo.express = latestExpressInfo;
+
+    const orderGoods = await this.model('order_goods').where({ order_id: orderId }).select();
 
     // 订单状态的处理
     orderInfo.order_status_text = await this.model('order').getOrderStatusText(orderId);
@@ -75,14 +78,14 @@ module.exports = class extends Base {
   async submitAction() {
     // 获取收货地址信息和计算运费
     const addressId = this.post('addressId');
-    const checkedAddress = await this.model('address').where({id: addressId}).find();
+    const checkedAddress = await this.model('address').where({ id: addressId }).find();
     if (think.isEmpty(checkedAddress)) {
       return this.fail('请选择收货地址');
     }
     const freightPrice = 0.00;
 
     // 获取要购买的商品
-    const checkedGoodsList = await this.model('cart').where({user_id: think.userId, session_id: 1, checked: 1}).select();
+    const checkedGoodsList = await this.model('cart').where({ user_id: think.userId, session_id: 1, checked: 1 }).select();
     if (think.isEmpty(checkedGoodsList)) {
       return this.fail('请选择商品');
     }
@@ -159,6 +162,19 @@ module.exports = class extends Base {
     await this.model('order_goods').addMany(orderGoodsData);
     await this.model('cart').clearBuyGoods();
 
-    return this.success({orderInfo: orderInfo});
+    return this.success({ orderInfo: orderInfo });
+  }
+
+  /**
+   * 查询物流信息
+   * @returns {Promise.<void>}
+   */
+  async expressAction() {
+    const orderId = this.get('orderId');
+    if (think.isEmpty(orderId)) {
+      return this.fail('订单不存在');
+    }
+    const latestExpressInfo = await this.model('order_express').getLatestOrderExpress(orderId);
+    return this.success(latestExpressInfo);
   }
 };

+ 60 - 0
src/api/model/order_express.js

@@ -0,0 +1,60 @@
+module.exports = class extends think.Model {
+  get tableName() {
+    return this.tablePrefix + 'order_express';
+  }
+
+  /**
+   * 获取最新的订单物流信息
+   * @param orderId
+   * @returns {Promise.<*>}
+   */
+  async getLatestOrderExpress(orderId) {
+    const returnExpressInfo = {
+      shipper_code: '',
+      shipper_name: '',
+      logistic_code: '',
+      is_finish: 0,
+      request_time: 0,
+      traces: []
+    };
+    const orderExpress = await this.where({ order_id: orderId }).find();
+    if (think.isEmpty(orderExpress)) {
+      return returnExpressInfo;
+    }
+    if (think.isEmpty(orderExpress.shipper_code) || think.isEmpty(orderExpress.logistic_code)) {
+      return returnExpressInfo;
+    }
+
+    returnExpressInfo.shipper_code = orderExpress.shipper_code;
+    returnExpressInfo.shipper_name = orderExpress.shipper_name;
+    returnExpressInfo.logistic_code = orderExpress.logistic_code;
+    returnExpressInfo.is_finish = orderExpress.is_finish;
+    returnExpressInfo.request_time = think.datetime(orderExpress.request_time * 1000);
+    returnExpressInfo.traces = think.isEmpty(orderExpress.traces) ? [] : JSON.parse(orderExpress.traces);
+
+    // 如果物流配送已完成,直接返回
+    if (orderExpress.is_finish) {
+      return returnExpressInfo;
+    }
+
+    // 查询最新物流信息
+    const ExpressSerivce = think.service('express', 'api');
+    const latestExpressInfo = await ExpressSerivce.queryExpress(orderExpress.shipper_code, orderExpress.logistic_code);
+    const nowTime = Number.parseInt(Date.now() / 1000);
+    const updateData = {
+      request_time: nowTime,
+      update_time: nowTime,
+      request_count: ['EXP', 'request_count+1']
+    };
+    if (latestExpressInfo.success) {
+      returnExpressInfo.traces = latestExpressInfo.traces;
+      returnExpressInfo.is_finish = latestExpressInfo.isFinish;
+      // 查询成功则更新订单物流信息
+      updateData.traces = JSON.stringify(latestExpressInfo.traces);
+      returnExpressInfo.request_time = think.datetime(nowTime * 1000);
+      updateData.is_finish = latestExpressInfo.isFinish;
+    }
+    await this.where({ id: orderExpress.id }).update(updateData);
+    return returnExpressInfo;
+  }
+};

+ 19 - 0
src/api/model/shipper.js

@@ -0,0 +1,19 @@
+module.exports = class extends think.Model {
+  /**
+   * 根据快递公司编码获取名称
+   * @param shipperCode
+   * @returns {Promise.<*>}
+   */
+  async getShipperNameByCode(shipperCode) {
+    return this.where({ code: shipperCode }).getField('name', true);
+  }
+
+  /**
+   * 根据 id 获取快递公司信息
+   * @param shipperId
+   * @returns {Promise.<*>}
+   */
+  async getShipperById(shipperId) {
+    return this.where({ id: shipperId }).find();
+  }
+};

+ 107 - 0
src/api/service/express.js

@@ -0,0 +1,107 @@
+const rp = require('request-promise');
+const _ = require('lodash');
+
+module.exports = class extends think.Service {
+  async queryExpress(shipperCode, logisticCode, orderCode = '') {
+    let expressInfo = {
+      success: false,
+      shipperCode: shipperCode,
+      shipperName: '',
+      logisticCode: logisticCode,
+      isFinish: 0,
+      traces: []
+    };
+    const fromData = this.generateFromData(shipperCode, logisticCode, orderCode);
+    if (think.isEmpty(fromData)) {
+      return expressInfo;
+    }
+
+    const sendOptions = {
+      method: 'POST',
+      url: think.config('express.request_url'),
+      headers: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      form: fromData
+    };
+
+    try {
+      const requestResult = await rp(sendOptions);
+      if (think.isEmpty(requestResult)) {
+        return expressInfo;
+      }
+      expressInfo = this.parseExpressResult(requestResult);
+      expressInfo.shipperCode = shipperCode;
+      expressInfo.logisticCode = logisticCode;
+      return expressInfo;
+    } catch (err) {
+      return expressInfo;
+    }
+  }
+
+  parseExpressResult(requestResult) {
+    const expressInfo = {
+      success: false,
+      shipperCode: '',
+      shipperName: '',
+      logisticCode: '',
+      isFinish: 0,
+      traces: []
+    };
+
+    if (think.isEmpty(requestResult)) {
+      return expressInfo;
+    }
+
+    try {
+      if (_.isString(requestResult)) {
+        requestResult = JSON.parse(requestResult);
+      }
+    } catch (err) {
+      return expressInfo;
+    }
+
+    if (think.isEmpty(requestResult.Success)) {
+      return expressInfo;
+    }
+
+    // 判断是否已签收
+    if (Number.parseInt(requestResult.State) === 3) {
+      expressInfo.isFinish = 1;
+    }
+    expressInfo.success = true;
+    if (!think.isEmpty(requestResult.Traces) && Array.isArray(requestResult.Traces)) {
+      expressInfo.traces = _.map(requestResult.Traces, item => {
+        return { datetime: item.AcceptTime, content: item.AcceptStation };
+      });
+      _.reverse(expressInfo.traces);
+    }
+    return expressInfo;
+  }
+
+  generateFromData(shipperCode, logisticCode, orderCode) {
+    const requestData = this.generateRequestData(shipperCode, logisticCode, orderCode);
+    const fromData = {
+      RequestData: encodeURI(requestData),
+      EBusinessID: think.config('express.appid'),
+      RequestType: '1002',
+      DataSign: this.generateDataSign(requestData),
+      DataType: '2'
+    };
+    return fromData;
+  }
+
+  generateRequestData(shipperCode, logisticCode, orderCode = '') {
+    // 参数验证
+    const requestData = {
+      OrderCode: orderCode,
+      ShipperCode: shipperCode,
+      LogisticCode: logisticCode
+    };
+    return JSON.stringify(requestData);
+  }
+
+  generateDataSign(requestData) {
+    return encodeURI(Buffer.from(think.md5(requestData + think.config('express.appkey'))).toString('base64'));
+  }
+};

+ 6 - 0
src/common/config/config.js

@@ -7,5 +7,11 @@ module.exports = {
     mch_id: '', // 商户帐号ID
     partner_key: '', // 微信支付密钥
     notify_url: '' // 微信异步通知,例:https://www.nideshop.com/api/pay/notify
+  },
+  express: {
+    // 快递物流信息查询使用的是快递鸟接口,申请地址:http://www.kdniao.com/
+    appid: '', // 对应快递鸟用户后台 用户ID
+    appkey: '', // 对应快递鸟用户后台 API key
+    request_url: 'http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx'
   }
 };