Skip to content

Commit

Permalink
feat 购物流程添加支付模拟
Browse files Browse the repository at this point in the history
  • Loading branch information
tumobi committed Aug 1, 2017
1 parent 0597c41 commit 6b63861
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 12 deletions.
18 changes: 8 additions & 10 deletions database/nideshop.sql → nideshop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ CREATE TABLE `nideshop_address` (

LOCK TABLES `nideshop_address` WRITE;
/*!40000 ALTER TABLE `nideshop_address` DISABLE KEYS */;
INSERT INTO `nideshop_address` VALUES (3,'明天',1,1,20,233,2413,'民族大道1号','13800008888',1),(11,'哈哈',11,0,3,38,423,'大街天桥下','13800000000',1);
INSERT INTO `nideshop_address` VALUES (3,'小明',1,1,20,233,2414,'民族大道1号','13800008888',1);
/*!40000 ALTER TABLE `nideshop_address` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down Expand Up @@ -221,7 +221,7 @@ CREATE TABLE `nideshop_cart` (
`list_pic_url` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `session_id` (`session_id`)
) ENGINE=MyISAM AUTO_INCREMENT=84 DEFAULT CHARSET=utf8;
) ENGINE=MyISAM AUTO_INCREMENT=87 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -230,7 +230,7 @@ CREATE TABLE `nideshop_cart` (

LOCK TABLES `nideshop_cart` WRITE;
/*!40000 ALTER TABLE `nideshop_cart` DISABLE KEYS */;
INSERT INTO `nideshop_cart` VALUES (77,1,'1',1130037,'1130037',189,'帆布丝羽绒多用坐垫',39.00,39.00,2,'','',1,'http://yanxuan.nosdn.127.net/19ecd7c6f6f31219cf75117238d95139.png'),(78,1,'1',1116011,'1116011',167,'蔓越莓曲奇 200克',36.00,36.00,2,'','',1,'http://yanxuan.nosdn.127.net/767b370d07f3973500db54900bcbd2a7.png'),(83,11,'1',1092024,'1092024',112,'双宫茧纱布亲肤手工蚕丝被',1599.00,1599.00,1,'','',1,'http://yanxuan.nosdn.127.net/f245a86dcb9f455217241e437b203926.png');
INSERT INTO `nideshop_cart` VALUES (83,11,'1',1092024,'1092024',112,'双宫茧纱布亲肤手工蚕丝被',1599.00,1599.00,1,'','',1,'http://yanxuan.nosdn.127.net/f245a86dcb9f455217241e437b203926.png');
/*!40000 ALTER TABLE `nideshop_cart` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down Expand Up @@ -468,7 +468,7 @@ CREATE TABLE `nideshop_footprint` (
`goods_id` int(11) NOT NULL DEFAULT '0',
`add_time` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=74 DEFAULT CHARSET=utf8mb4;
) ENGINE=InnoDB AUTO_INCREMENT=78 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -477,7 +477,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);
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);
/*!40000 ALTER TABLE `nideshop_footprint` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down Expand Up @@ -728,7 +728,7 @@ CREATE TABLE `nideshop_order` (
KEY `pay_status` (`pay_status`),
KEY `shipping_id` (`shipping_id`),
KEY `pay_id` (`pay_id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -737,7 +737,6 @@ CREATE TABLE `nideshop_order` (

LOCK TABLES `nideshop_order` WRITE;
/*!40000 ALTER TABLE `nideshop_order` DISABLE KEYS */;
INSERT INTO `nideshop_order` VALUES (1,'20170505233345921032',1,0,0,0,'明天',0,20,233,2413,'民族大道1号','13800008888','',0,'',0,'',0.00,118.00,0,0.00,118.00,118.00,1496417625,0,0,0,0,0,0.00,'true'),(2,'20170505233635958710',1,0,0,0,'明天',0,20,233,2413,'民族大道1号','13800008888','',0,'',0,'',0.00,1036.00,0,0.00,1036.00,1036.00,1496417795,0,0,0,0,0,0.00,'true'),(3,'20170505233918640351',1,0,0,0,'明天',0,20,233,2413,'民族大道1号','13800008888','',0,'',0,'',0.00,1036.00,0,0.00,1036.00,1036.00,1496417958,0,0,0,0,0,0.00,'true'),(4,'20170600232741309218',11,0,0,0,'哈哈',0,3,38,423,'大街天桥下','13800000000','',0,'',0,'',0.00,358.00,0,0.00,358.00,358.00,1500823661,0,0,0,0,0,0.00,'true'),(5,'20170603000253711666',11,0,0,0,'哈哈',0,3,38,423,'大街天桥下','13800000000','',0,'',0,'',0.00,118.00,0,0.00,118.00,118.00,1500998573,0,0,0,0,0,0.00,'true');
/*!40000 ALTER TABLE `nideshop_order` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down Expand Up @@ -765,7 +764,7 @@ CREATE TABLE `nideshop_order_goods` (
PRIMARY KEY (`id`),
KEY `order_id` (`order_id`),
KEY `goods_id` (`goods_id`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand All @@ -774,7 +773,6 @@ CREATE TABLE `nideshop_order_goods` (

LOCK TABLES `nideshop_order_goods` WRITE;
/*!40000 ALTER TABLE `nideshop_order_goods` DISABLE KEYS */;
INSERT INTO `nideshop_order_goods` VALUES (1,1,1015007,'典雅美式全棉刺绣抱枕','',21,2,59.00,59.00,'',0,'','http://yanxuan.nosdn.127.net/a2045004de8a6225289376ad54317fc8.png'),(2,2,1015007,'典雅美式全棉刺绣抱枕','1015007',21,2,59.00,59.00,'',0,'','http://yanxuan.nosdn.127.net/a2045004de8a6225289376ad54317fc8.png'),(3,2,1152161,'竹语丝麻印花四件套','1152161',239,2,459.00,459.00,'',0,'','http://yanxuan.nosdn.127.net/977401e75113f7c8334c4fb5b4bf6215.png'),(4,3,1015007,'典雅美式全棉刺绣抱枕','1015007',21,2,59.00,59.00,'',0,'','http://yanxuan.nosdn.127.net/a2045004de8a6225289376ad54317fc8.png'),(5,3,1152161,'竹语丝麻印花四件套','1152161',239,2,459.00,459.00,'',0,'','http://yanxuan.nosdn.127.net/977401e75113f7c8334c4fb5b4bf6215.png'),(6,4,1115028,'日式色织水洗棉条纹四件套','1115028',161,1,299.00,299.00,'',0,'','http://yanxuan.nosdn.127.net/3d0045e8f43439c7004fae052b2162ed.png'),(7,4,1015007,'典雅美式全棉刺绣抱枕','1015007',21,1,59.00,59.00,'',0,'','http://yanxuan.nosdn.127.net/a2045004de8a6225289376ad54317fc8.png'),(8,5,1009012,'可水洗舒柔丝羽绒枕','1009012',14,2,59.00,59.00,'',0,'','http://yanxuan.nosdn.127.net/a196b367f23ccfd8205b6da647c62b84.png');
/*!40000 ALTER TABLE `nideshop_order_goods` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down Expand Up @@ -1079,4 +1077,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2017-07-30 16:54:48
-- Dump completed on 2017-08-01 23:57:46
4 changes: 2 additions & 2 deletions src/api/controller/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class extends Base {

//开启事务,插入订单信息和订单商品
let orderId = await this.model('order').add(orderInfo);

orderInfo.id = orderId;
if (!orderId) {
return this.fail('订单提交失败');
}
Expand All @@ -185,7 +185,7 @@ export default class extends Base {

await this.model('cart').clearBuyGoods();

return this.success('订单提交成功');
return this.success({orderInfo: orderInfo});
}

}
74 changes: 74 additions & 0 deletions src/api/controller/pay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

import Base from './base.js';
const rp = require("request-promise");
const request = require("request");

export default class extends Base {

// 支付类型 1 微信支付 2支付宝
// TODO 支付功能由于没有公司账号和微信支付账号,所以没有经过测试,如您可以提供相关账号测试,可联系 [email protected]

/**
* 获取支付信息(订单信息和支持的支付方式信息)
* @return {Promise} []
*/
async indexAction() {
//auto render template file index_index.html
return this.display();
}

/**
* 获取支付的请求参数
* @returns {Promise<PreventPromise|void|Promise>}
*/
async payPrepayAction() {

const orderId = this.get('orderId');
const payType = this.get('payType');

const orderInfo = await this.model('order').where({id: orderId}).find();
if (think.isEmpty(orderInfo)) {
return this.fail(400, '订单已取消');
}
console.log(orderInfo)
if (parseInt(orderInfo.pay_status) !== 0) {
return this.fail(400, '订单已支付,请不要重复操作');
}

//微信支付统一调用接口,body参数请查看微信支付文档:https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=9_1
let options = {
method: 'POST',
url: 'https://api.mch.weixin.qq.com/pay/unifiedorder',
body: {
appid: 'payload',
mch_id: '',
sub_appid: '',
sub_mch_id: '',
device_info: '',
nonce_str: think.uuid(32),
sign: '',
sign_type: 'MD5',
body: '',
out_trade_no: '',
total_fee: orderInfo.actual_price * 100,
spbill_create_ip: '',
notify_url: '',
trade_type: 'JSAPI',
openid: '',
sub_openid: '',
},
};
//let payParam = await rp(options);

//统一返回成功,方便测试
return this.success({
'timeStamp': getTime(),
'nonceStr': think.uuid(16),
'package': 'prepay_id=wx201410272009395522657a690389285100',
'signType': 'MD5',
'paySign': 'jdsdlsdsd',
});
}

}
15 changes: 15 additions & 0 deletions src/api/logic/pay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
/**
* logic
* @param {} []
* @return {} []
*/
export default class extends think.logic.base {
/**
* index action logic
* @return {} []
*/
indexAction(){

}
}

0 comments on commit 6b63861

Please sign in to comment.