java批量生成订单号_【笔记6-支付及订单模块】从0开始 独立完成企业级Java电商网站开发(服务端)...
支付模塊
實際開發(fā)工作中經(jīng)常會遇見如下場景,一個支付模塊,一個訂單模塊,有一定依賴,一個同事負(fù)責(zé)支付模塊,另一個同事負(fù)責(zé)訂單模塊,但是開發(fā)支付模塊的時候要依賴訂單模塊的相關(guān)類 ,方法,或者工具類,這些還沒開發(fā)出來,看不到一個完整的訂單業(yè)務(wù)邏輯,可能只拿到了訂單的Order類,但是呢不能影響我們后端的并行開發(fā),就像前端和后端之間的并行開發(fā),后端之間也有并行開發(fā),后端的項目有時候是非常大的,這個時候該怎么辦,本章支付模塊和下節(jié)訂單模塊就要模擬這種場景,提高自己的勝任跨業(yè)務(wù)開發(fā)的抽象開發(fā)能力,這種能力再開發(fā)大型項目的時候非常重要,而且是衡量一個優(yōu)秀開發(fā)者非常重要的標(biāo)準(zhǔn),比如在面試的時候經(jīng)常會問到這樣問題來此判斷這個面試者是否有開發(fā)大型項目的經(jīng)驗或者潛力,與此同時,還有一個重要目的,為了考慮后面的進階課程,會把項目演進到拆分微服務(wù)和進行dubbo服務(wù)化的時候,我們只能拿到一個接口和一個類,什么都看不到,具體的實現(xiàn)都在遠(yuǎn)程的rpc服務(wù)端,這種場景的開發(fā)正是需要跨業(yè)務(wù)的一定抽象開發(fā)能力
數(shù)據(jù)庫表設(shè)計
支付信息表
CREATE TABLE‘ mmall_ pay_ info’ ( 'id' int(11) NOT NULL AUTO_ INCREMENT, 'user_ id' int(11) DEFAULT NULL COMMENT . 用戶id', 'order_ no' bigint(20) DEFAULT NULL COMMENT '訂單號' 'pay_ platform' int(10) DEFAULT NULL COMMENT ' 支付平臺:1-支付寶,2-微信', 'platform_ number' varchar (200) DEFAULT NULL COMMENT ' 支付寶支付流水號' , 'platform_ _status' varchar(20) DEFAULT NULL COMMENT ' 支付寶支付狀態(tài)' , 'create_ time' datetime DEFAULT NULL COMMENT ' 創(chuàng)建時間, 'update_ time' datetime DEFAULT NULL COMMENT ' 更新時間', PRIMARY KEY ( id') ) ENGINE= InnoDB AUTO_ INCREMENT=53 DEFAULT CHARSET=utf8功能
- 支付寶對接
- 支付回調(diào)
- 查詢支付狀態(tài)
支付寶對接對接流程
1、首先得有一個支付寶賬號,(注冊螞蟻金服開發(fā)平臺賬號)
2、創(chuàng)建應(yīng)用,因為我們是自己開發(fā)或者公司開發(fā),所以要創(chuàng)建自研型應(yīng)用(自研型應(yīng)用分為網(wǎng)頁移動應(yīng)用,AR,生活號,小程序),創(chuàng)建應(yīng)用得過程中:
a) 需要一個用戶名和一個logo(應(yīng)用圖標(biāo),因為我是自己學(xué)習(xí),可以在線網(wǎng)站免費設(shè)計一個),填寫完畢之后確認(rèn)創(chuàng)建,之后就可以在應(yīng)用列表中看到創(chuàng)建得應(yīng)用,一般情況下會進入下一個頁面填寫應(yīng)用的更多詳細(xì)信息
b) 進入下面頁面
c) 關(guān)于應(yīng)用網(wǎng)關(guān)和授權(quán)回調(diào)地址,單純的支付接口是不需要配置這兩個信息的,簡單來說就是:應(yīng)用網(wǎng)關(guān)是用于接收口碑或是生活號的信息的,授權(quán)回調(diào)地址是第三方授權(quán)或是用戶信息授權(quán)使用的,如果用不到是可以不配置的!
d) 下面就靜等審核(說是一個工作日)
涉及知識點
- 熟悉支付寶對接核心文檔,調(diào)通支付寶支付功能官方Demo
- 解析支付寶SDK對接源碼
- RSA1和RSA2驗證簽名及加解密
- 避免支付寶重復(fù)通知和數(shù)據(jù)校驗
- natapp外網(wǎng)穿透和tomcat remote debug
- 生成二維碼,并持久化到圖片服務(wù)器
接口設(shè)計
【前臺】
1.支付
/order/pay.do
http://localhost:8080/order/pay.do?orderNo=1485158676346
requestorderNoresponsesuccess
{"status": 0,"data": {"orderNo": "1485158676346","qrPath": "http://img.happymmall.com/qr-1492329044075.png"} }2.查詢訂單支付狀態(tài)
/order/queryorderpay_status.do
http://localhost:8080/order/queryorderpay_status.do?orderNo=1485158676346
requestorderNoresponsesuccess
{"status": 0,"data": true }3.支付寶回調(diào)
參考支付寶回調(diào)文檔:https://support.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.mFogPC&treeId=193&articleId=103296&docType=1
/order/alipay_callback.do
requestHttpServletRequestresponsesuccess
success訂單模塊
數(shù)據(jù)庫表設(shè)計
訂單表
CREATE TABLE mmall_ order’( 'id' int(11) NOT NULL AUTO_ INCREMENT COMMENT '訂單id', 'order_ no' bigint(20) DEFAULT NULL COMMENT '訂單號', 'user_ id' int(11) DEFAULT NULL COMMENT '用戶id' , 'shipping_ id' int(11) DEFAULT NULL, 'payment' decimal(20,2) DEFAULT NULL COMMENT ' 實際付款金額,單位是元,保留兩位小數(shù)', 'payment_ type' int(4) DEFAULT NULL COMMENT ' 支付類型,1-在線支付' , 'postage' int(10) DEFAULT NULL COMMENT ' 運費,單位是元', 'status' int(10) DEFAULT NULL COMMENT '訂單狀態(tài):0-已取消-10- 未付款,20-已付款, 40-已發(fā)貨,50- 交易成功,60- 交易關(guān)閉", 'payment_time' datetime DEFAULT NULL COMMENT ' 支付時間', 'send_ time' datetime DEFAULT NULL COMMENT ' 發(fā)貨時間, 'end. time' datetime DEFAULT NULL COMHENT ‘交易 完成時間', 'close_ time' datetine DEFAULT NULL COMMENT ‘交 易關(guān)閉時間', 'create_ _time' datetime DEFAULT NULL COMMENT ' 創(chuàng)建時間", 'update_ time' datetime DEFAULT NULL COMMENT ' 更新時間' , PRIHARY KEY ( id'), UNIQUE KEY“ order_ _no_ index" (order_ no') USING BTREE ) ENGINE-InnoDB AUTO INCREMENT-103 DEFAULT CHARSET=utf8訂單明細(xì)表
CREATE TABLE: mmall_ order_ item’( 'id' int(11) NOT NULL AUTO_ ,INCREMENT COMMENT '訂單子表id' , 'user_ id' int(11) DEFAULT NULL, 'order_ no' bigint(20) DEFAULT NULL, 'product_ id' int(11) DEFAULT NULL COMNENT .商晶id', 'product_ name' varchar(100) DEFAULT NULL COMMENT ' 商品名稱', 'product_ image' varchar(500) DEFAULT NULL COMNENT ' 商品圖片地址, 'current _unit_ price' decimal(20,2) DEFAULT NULL COMNENT '生成訂單時的商品單價,單位是元,保留兩位小數(shù)' , . 'quantity' int(10) DEFAULT NULL COMMENT 商品數(shù)量 'total_ price' decimal(20,2) DEFAULT NULL COMMENT "商品總價,單位是元,保留兩位小數(shù)' , 'create_ time' datetime DEFAULT NULL, 'update_ time' datetime DEFAULT NULL, PRIMARY KEY ( id'), KEY 'order_ no_ index' ('order. no' ) USING BTREE, KEY 'order_ no_user_ id_ index' ('user_ _id' ,'order_ no') USING BTREE ) ENGINE: =InnoDB AUTO_ INCREMENT-113 DEFAULT CHARSET=utf8功能
前臺功能
創(chuàng)建訂單商品信息訂單列表訂單詳情取消訂單
后臺功能
訂單列表訂單搜索訂單詳情訂單發(fā)貨
涉及知識點
- 避免業(yè)務(wù)邏輯中橫向越權(quán)和縱向越權(quán)等安全漏洞
- 設(shè)計實用、安全、擴展性強大的常量、枚舉類
- 訂單號生成規(guī)則、訂單嚴(yán)謹(jǐn)性判斷
- POJO和VO之間的實際操練
- mybatis批量插入
接口設(shè)計
【前臺】
1.創(chuàng)建訂單
/order/create.do
引用已存在的收貨地址idhttp://localhost:8080/order/create.do?shippingId=5
requestshippingIdresponsesuccess
{"status": 0,"data": {"orderNo": 1485158223095,"payment": 2999.11,"paymentType": 1,"postage": 0,"status": 10,"paymentTime": null,"sendTime": null,"endTime": null,"closeTime": null,"createTime": 1485158223095,"orderItemVoList": [{"orderNo": 1485158223095,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": null}],"shippingId": 5,"shippingVo": null} }2.獲取訂單的商品信息
/order/getordercart_product.do
http://localhost:8080/order/getordercart_product.do
request無responsesuccess
{"status": 0,"data": {"orderItemVoList": [{"orderNo": null,"productId": 1,"productName": "iphone7","productImage": "mmall/aa.jpg","currentUnitPrice": 7999,"quantity": 10,"totalPrice": 79990,"createTime": ""}],"imageHost": "http://img.happymmall.com/","productTotalPrice": 79990} }3.訂單List
http://localhost:8080/order/list.do?pageSize=3
/order/list.do
requestpageSize(default=10) pageNum(default=1)responsesuccess
{"status": 0,"data": {"pageNum": 1,"pageSize": 3,"size": 3,"orderBy": null,"startRow": 1,"endRow": 3,"total": 16,"pages": 6,"list": [{"orderNo": 1485158676346,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:36","orderItemVoList": [{"orderNo": 1485158676346,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:36"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"receiverName": "geely","shippingVo": null},{"orderNo": 1485158675516,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:35","orderItemVoList": [{"orderNo": 1485158675516,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:35"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"receiverName": "geely","shippingVo": null},{"orderNo": 1485158675316,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:35","orderItemVoList": [{"orderNo": 1485158675316,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:35"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"receiverName": "geely","shippingVo": null}],"firstPage": 1,"prePage": 0,"nextPage": 2,"lastPage": 6,"isFirstPage": true,"isLastPage": false,"hasPreviousPage": false,"hasNextPage": true,"navigatePages": 8,"navigatepageNums": [1,2,3,4,5,6]} }4.訂單詳情detail
http://localhost:8080/order/detail.do?orderNo=1480515829406
/order/detail.do
requestorderNoresponsesuccess
{"status": 0,"data": {"orderNo": 1480515829406,"payment": 30000.00,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "","sendTime": "","endTime": "","closeTime": "","createTime": "2016-11-30 22:23:49","orderItemVoList": [{"orderNo": 1480515829406,"productId": 1,"productName": "iphone7","productImage": "mainimage.jpg","currentUnitPrice": 10000.00,"quantity": 1,"totalPrice": 10000.00,"createTime": "2016-11-30 22:23:49"},{"orderNo": 1480515829406,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 20000.00,"quantity": 1,"totalPrice": 20000.00,"createTime": "2016-11-30 22:23:49"}],"imageHost": "http://img.happymmall.com/","shippingId": 3,"receiverName": "geely","shippingVo": {"receiverName": "geely","receiverPhone": "0100","receiverMobile": "186","receiverProvince": "北京","receiverCity": "北京","receiverDistrict": "昌平區(qū)","receiverAddress": "矩陣小區(qū)","receiverZip": "100000"}} }5.取消訂單
http://localhost:8080/order/cancel.do?orderNo=1480515829406
/order/cancel.do
requestorderNoresponsesuccess
{"status": 0 }【后臺】
1.訂單List
http://localhost:8080/manage/order/list.do?pageSize=3
/manage/order/list.do
requestpageSize(default=10) pageNum(default=1)responsesuccess
{"status": 0,"data": {"pageNum": 1,"pageSize": 3,"size": 3,"orderBy": null,"startRow": 1,"endRow": 3,"total": 16,"pages": 6,"list": [{"orderNo": 1485158676346,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:36","orderItemVoList": [{"orderNo": 1485158676346,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:36"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"shippingVo": null},{"orderNo": 1485158675516,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:35","orderItemVoList": [{"orderNo": 1485158675516,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:35"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"receiverName": "geely","shippingVo": null},{"orderNo": 1485158675316,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:35","orderItemVoList": [{"orderNo": 1485158675316,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:35"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"receiverName": "geely","shippingVo": null}],"firstPage": 1,"prePage": 0,"nextPage": 2,"lastPage": 6,"isFirstPage": true,"isLastPage": false,"hasPreviousPage": false,"hasNextPage": true,"navigatePages": 8,"navigatepageNums": [1,2,3,4,5,6]} }2.按訂單號查詢
http://localhost:8080/manage/order/search.do?orderNo=1480515829406
/manage/order/search.do
requestorderNoresponsesuccess
{"status": 0,"data": {"pageNum": 1,"pageSize": 3,"size": 3,"orderBy": null,"startRow": 1,"endRow": 3,"total": 16,"pages": 6,"list": [{"orderNo": 1485158676346,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:36","orderItemVoList": [{"orderNo": 1485158676346,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:36"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"shippingVo": null},{"orderNo": 1485158675516,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:35","orderItemVoList": [{"orderNo": 1485158675516,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:35"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"receiverName": "geely","shippingVo": null},{"orderNo": 1485158675316,"payment": 2999.11,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "2017-02-11 12:27:18","sendTime": "2017-02-11 12:27:18","endTime": "2017-02-11 12:27:18","closeTime": "2017-02-11 12:27:18","createTime": "2017-01-23 16:04:35","orderItemVoList": [{"orderNo": 1485158675316,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 2999.11,"quantity": 1,"totalPrice": 2999.11,"createTime": "2017-01-23 16:04:35"}],"imageHost": "http://img.happymmall.com/","shippingId": 5,"receiverName": "geely","shippingVo": null}],"firstPage": 1,"prePage": 0,"nextPage": 2,"lastPage": 6,"isFirstPage": true,"isLastPage": false,"hasPreviousPage": false,"hasNextPage": true,"navigatePages": 8,"navigatepageNums": [1,2,3,4,5,6]} }3.訂單詳情
http://localhost:8080/manage/order/detail.do?orderNo=1480515829406
/manage/order/detail.do
requestorderNoresponsesuccess
{"status": 0,"data": {"orderNo": 1480515829406,"payment": 30000.00,"paymentType": 1,"paymentTypeDesc": "在線支付","postage": 0,"status": 10,"statusDesc": "未支付","paymentTime": "","sendTime": "","endTime": "","closeTime": "","createTime": "2016-11-30 22:23:49","orderItemVoList": [{"orderNo": 1480515829406,"productId": 1,"productName": "iphone7","productImage": "mainimage.jpg","currentUnitPrice": 10000.00,"quantity": 1,"totalPrice": 10000.00,"createTime": "2016-11-30 22:23:49"},{"orderNo": 1480515829406,"productId": 2,"productName": "oppo R8","productImage": "mainimage.jpg","currentUnitPrice": 20000.00,"quantity": 1,"totalPrice": 20000.00,"createTime": "2016-11-30 22:23:49"}],"imageHost": "http://img.happymmall.com/","shippingId": 3,"receiverName": "geely","shippingVo": {"receiverName": "geely","receiverPhone": "0100","receiverMobile": "186","receiverProvince": "北京","receiverCity": "北京","receiverDistrict": "昌平區(qū)","receiverAddress": "矩陣小區(qū)","receiverZip": "100000"}} }4.訂單發(fā)貨
http://localhost:8080/manage/order/send_goods.do?orderNo=1480515829406
/manage/order/send_goods.do
requestorderNoresponsesuccess
{"status": 0,"data": "發(fā)貨成功" }總結(jié)
以上是生活随笔為你收集整理的java批量生成订单号_【笔记6-支付及订单模块】从0开始 独立完成企业级Java电商网站开发(服务端)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring 事务隔离级别和传播行为_S
- 下一篇: python如何打开txt文件、并算词频