1. 請問java的商城訂單模塊,如何解決用戶惡意創建訂單,但是不支付的問題 求詳細解決方案。
其實這種問題應該是從產品的角度來解決的。而不是讓一個程序員去想如何限制用戶的行為。作為產品應該相處解決方案,然後程序員去實現。不過目前看來你這可能是個練手的項目,我跟你說下我之前項目的一些解決方案。
首先就是對用戶頻繁下單的限制,這里你可以在redis里寫入一個和用戶id相關的key。設置20秒左右的失效時間,這樣如果是正常用戶的話在這個時間里一般會避免這種情況的發生。然後從訂單的角度來說,這樣一個用戶就算下了大量的訂單也不會太多,然後寫個定時任務,對下單超過30分鍾還沒支付的訂單進行處理,比如給他的訂單狀態設置成已刪除這種。
當然我們做的商城屬於一個項目內置的,買周邊和虛擬物品的,所以訪問量不大。太大的量的話最好還是先讓產品來想如何限制。
2. java題:編寫類似淘寶一個簡單的處理訂單發貨和進貨的程序,要求實現簡單的進貨和發貨以及統計貨物量的功能
import java.util.ArrayList;
public class Du {
public static void main(String[] args) throws Exception {
Seller seller = new Seller("My Store");
seller.addGoods("T-shirt", 200);
seller.addGoods("Pill", 100);
seller.addGoods("T-shirt", 100);
seller.addGoods("T-shirt", 50);
seller.addGoods("Pill", 50);
seller.addGoods("Hat", 100);
seller.printGoods();
Seller sell2 = new Seller("The Other Store");
sell2.addGoods("T-shirt", 200);
sell2.addGoods("Hat", 100);
sell2.sellGoods("T-shirt", 50);
sell2.addGoods("Hat", 100);
sell2.printGoods();
}
}
class Seller {
private String sellerName;
private int TotalTypeOfGoods;
private ArrayList<String> goodsNameList = new ArrayList<String>();
private ArrayList<Integer> goodsQuantityList = new ArrayList<Integer>();
public Seller(String sellerName) {
this.sellerName = sellerName;
}
public void addGoods(String goodName, int goodNum) {
int index = goodsNameList.indexOf(goodName);
if (index == -1) {
goodsNameList.add(goodName);
goodsQuantityList.add(new Integer(goodNum));
} else {
goodsQuantityList.set(index, goodsQuantityList.get(index)
.intValue()
+ goodNum);
}
TotalTypeOfGoods = goodsNameList.size();
}
public void sellGoods(String goodName, int goodNum) throws Exception {
if (TotalTypeOfGoods == 0) {
throw new Exception("No goods provided by the shop. Closed!");
}
int index = goodsNameList.indexOf(goodName);
if (index != -1) {
int qty = goodsQuantityList.get(index);
if (goodNum > qty) {
throw new Exception("Insufficient goods in the shop. Sorry!");
}
goodsQuantityList.set(index, qty - goodNum);
}else{
throw new Exception("Our shop doesn't sell " + goodName);
}
}
public void printGoods() {
System.out.print("Seller :" + this.sellerName + "\t");
System.out.println("Totoal Types of Goods is :" + this.TotalTypeOfGoods);
for(int i = 0; i < goodsNameList.size(); i++){
System.out.print("Goods Name: " + goodsNameList.get(i));
System.out.println("Remains: " + goodsQuantityList.get(i));
}
System.out.println();
}
}
-----------------testing
Seller :My Store Totoal Types of Goods is :3
Goods Name: T-shirtRemains: 350
Goods Name: PillRemains: 150
Goods Name: HatRemains: 100
Seller :The Other Store Totoal Types of Goods is :2
Goods Name: T-shirtRemains: 150
Goods Name: HatRemains: 200
3. java一個訂單介面,調用訂單介面要創建10000份訂單,用多線程怎麼實現,求助大神!!!!!
{
//重寫run方法,run方法的方法體就是現場執行體
publicvoidrun()
{
System.out.println("創建訂單");
}
}
publicclassTest{
publicstaticvoidmain(String[]args)
{
newMyThread().start();//開啟一個線程
newMyThread().start();//開啟一個線程
}
}
4. java 如何實現一個用戶 一個訂單
package cn.test.logan.day04;
import java.util.ArrayList;
/**
* 訂單類
* 包含:訂單ID、訂單所屬用戶、訂單所包含的商品、訂單總金額、訂單應付金額
* 500-1000 -------> 8.5折
* 1000-1500 -------> 8折
* 1500-2000 -------> 7折
* 2000以上 -------> 6.5折
* 如果是會員,那麼可以基於以上折扣繼續折扣
* 一般會員:9.5折
* 中級會員:9折
* 高級會員:8折
* @author QIN
*
*/
public class Order {undefined
// 訂單ID
public String ordId;
// 訂單所屬用戶
public User user;
// 訂單所包含的商品(多個商品,使用ArrayList)
public ArrayList pds;
// 訂單總金額
public float ordAllAmt;
// 訂單應付金額
public float payAmt;
// 計算總金額的方法
public void setAllAmt() {undefined
float sum = 0;
for(int i=0;i
sum +=this.pds.get(i).price * this.pds.get(i).number;
}
this.ordAllAmt = sum;
}
// 計算實付金額
public void setPayAmt() {undefined
float tmp = this.ordAllAmt;
// 根據總金額進行折扣
if(this.ordAllAmt >= 500 && this.ordAllAmt < 1000) {undefined
tmp = this.ordAllAmt * 0.85f;
}
if(this.ordAllAmt >= 1000 && this.ordAllAmt < 1500) {undefined
tmp = this.ordAllAmt * 0.8f;
}
if(this.ordAllAmt >= 1500 && this.ordAllAmt < 2000) {undefined
tmp = this.ordAllAmt * 0.7f;
}
if(this.ordAllAmt >= 2000) {undefined
tmp = this.ordAllAmt * 0.65f;
}
// 根據會員等級折扣
if(user.CustLevel.equals("一般會員")) {undefined
tmp = tmp * 0.95f;
}
if(user.CustLevel.equals("中級會員")) {undefined
tmp = tmp * 0.9f;
}
if(user.CustLevel.equals("高級會員")) {undefined
tmp = tmp * 0.8f;
}
//計算結果賦值給對象上的payAmt變數
this.payAmt = tmp;
}
}
參考資料來源:網路貼吧CSDN博主「公子京」
5. java web 開發 購物網站 怎麼做訂單結算部分
我寫過兩次訂單結算,不過都是asp.net下的,但是應該差不多吧.訂單結算是最後的步驟,提交訂單之後需要做結算,實際上就是收錢嘛.
傳統來講此時需要一個支付介面,比如說支付寶財付通快錢 網銀在線之類的,他們提供介面,我們按照他們說明文檔來實現就好.重要的是交易記錄哦!!提交訂單後需要交易日誌(不能從字面意義上來理解"交易",實際上跟別人討價還價也是交易的一種不是嘛.)轉到介面前需要日誌,介面返回信息需要日誌(表結構差不多啦)這些日誌,方便以後退款或者查看狀態使用;
不傳統來講除支付介面外,要考慮購物網站個人錢包支付或者線下匯款之類的 建議使用策略模式
額 不知道說啥了.縷一縷在紙上構思下就差不多 但一定要考慮好安全性
6. java實現實時訂單推送需要用到什麼技術
1:支付技術,訂單需要支付
2:流程,訂單系統肯定從下單到支付再到送貨等一系列需要走流程
3:定位技術,訂單需要地理定位,幫助送貨員准確送貨到買家
4:消息技術,在訂單走到任何環節都需要消息及時反饋
5:搜索技術,買家會在系統搜索滿意的物品