⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auctionorderdb.java~6~

📁 源码/软件简介: 云网论坛1.1RC国际版是采用JSP开发的集论坛、CMS(网站内容管理系统)、博客、聊天室、商城、交友、语音灌水等于一体的门户式社区。拥有CWBBS ( Cloud Web BBS
💻 JAVA~6~
📖 第 1 页 / 共 2 页
字号:
package com.redmoon.forum.plugin.auction;

import java.sql.*;
import java.util.*;

import javax.servlet.http.*;

import cn.js.fan.base.*;
import cn.js.fan.db.*;
import cn.js.fan.util.*;
import cn.js.fan.web.*;
import com.redmoon.forum.plugin.*;
import com.redmoon.forum.message.MessageDb;
import cn.js.fan.mail.SendMail;
import com.redmoon.forum.person.UserDb;
import com.redmoon.forum.SequenceMgr;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class AuctionOrderDb extends ObjectDb {
    public static final int SCORE_NONE = -100;

    public AuctionOrderDb() {
        super();
    }

    private int buyerScore = SCORE_NONE;

    public static final int STATE_NONE = 0;
    public static final int STATE_PAY = 1;      // 已付款
    public static final int STATE_DELIVERY = 2; // 已交货
    public static final int STATE_COMPLETE = 3; // 订单已付款交货

    public static int JUDGE_GOOD = 10;   // 好评
    public static int JUDGE_COMMON = 0;  // 中评
    public static int JUDGE_BAD = -10;   // 差评

    static {
        AuctionConfig ac = new AuctionConfig();
        JUDGE_GOOD = Integer.parseInt(ac.getProperty("judge.good"));
        JUDGE_COMMON = Integer.parseInt(ac.getProperty("judge.common"));
        JUDGE_BAD = Integer.parseInt(ac.getProperty("judge.bad"));
    }

    public AuctionOrderDb(int id) {
        this.id = id;
        init();
        load();
    }

    public String getJudgeDesc(HttpServletRequest request, int judge) {
        String str = "";
        if (judge==JUDGE_GOOD)
           str = AuctionSkin.LoadString(request, "judge_good");
        else if (judge==JUDGE_COMMON)
           str = AuctionSkin.LoadString(request, "judge_common");
        else if (judge==JUDGE_BAD)
           str = AuctionSkin.LoadString(request, "judge_bad");
        return str;
    }


    public static String getStateDesc(HttpServletRequest request, int state) {
        String str = "";
        if (state==STATE_NONE)
            str = AuctionSkin.LoadString(request, "order_state_none");
        if (state==STATE_PAY)
            str = AuctionSkin.LoadString(request, "order_state_pay");
        else if (state==STATE_DELIVERY)
            str = AuctionSkin.LoadString(request, "order_state_delivery");
        else if (state==STATE_COMPLETE)
            str = AuctionSkin.LoadString(request, "order_state_complete");
        return str;
    }

    public boolean del() throws ErrMsgException {
        int rowcount = 0;
        Conn conn = null;
        try {
            conn = new Conn(connname);
            PreparedStatement ps = conn.prepareStatement(this.QUERY_DEL);
            ps.setInt(1, id);
            rowcount = conn.executePreUpdate();
        } catch (SQLException e) {
            logger.error(e.getMessage());
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        if (rowcount > 0) {
            AuctionOrderCache cc = new AuctionOrderCache(this);
            primaryKey.setValue(new Integer(id));
            cc.refreshDel(primaryKey);
        }
        return rowcount>0? true:false;
    }

    public ObjectDb getObjectRaw(PrimaryKey pk) {
        return new AuctionOrderDb(pk.getIntValue());
    }

    public boolean create() throws ErrMsgException, ResKeyException {
        int rowcount = 0;
        Conn conn = null;
        id = (int)SequenceMgr.nextID(SequenceMgr.AuctionOrderId);
        try {
            conn = new Conn(connname);
            PreparedStatement ps = conn.prepareStatement(this.QUERY_CREATE);
            ps.setLong(1, auctionId);
            ps.setInt(2, auctionSellType);
            ps.setString(3, seller);
            ps.setString(4, buyer);
            ps.setDouble(5, price);
            ps.setString(6, moneyCode);
            ps.setDouble(7, totalPrice);
            ps.setInt(8, amount);
            ps.setInt(9, sellerScore);
            ps.setInt(10, buyerScore);
            ps.setInt(11, state);
            ps.setInt(12, id);
            if (payTime==null)
                ps.setString(13, null);
            else
                ps.setString(13, DateUtil.toLongString(payTime));
            if (deliverTime==null)
                ps.setString(14, null);
            else
                ps.setString(14, DateUtil.toLongString(deliverTime));
            ps.setString(15, commodityName);
            ps.setString(16, "" + System.currentTimeMillis());
            rowcount = conn.executePreUpdate();

            if (rowcount>0) {
                if (auctionSellType==AuctionDb.SELL_TYPE_AUCTION) {
                    AuctionDb ad = new AuctionDb();
                    ad = ad.getAuctionDb(auctionId);
                    ad.setOrderId(id);
                    // logger.info("msgRootId=" + ad.getMsgRootId());
                    // logger.info("orderId=" + ad.getOrderId());
                    ad.save();
                }
            }
        } catch (SQLException e) {
            logger.error("create:" + e.getMessage());
            throw new ResKeyException(new SkinUtil(), SkinUtil.ERR_DB);
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        if (rowcount>0) {
            AuctionConfig ac = new AuctionConfig();
            // 发短消息
            String subject = ac.getOrderNoticeSubject();
            String body = ac.getOrderNoticeBody();
            body = body.replaceFirst("\\$buyer", buyer);
            body = body.replaceFirst("\\$seller", seller);
            body = body.replaceAll("\\$orderId", "" + id);
            String rootPath = Global.getRootPath();
            rootPath = rootPath.replaceFirst("http", "hhttttpp");
            body = body.replaceAll("\\$rootPath", rootPath);

            String ubbBody = ac.getUbbBody();
            ubbBody = ubbBody.replaceFirst("\\$buyer", buyer);
            ubbBody = ubbBody.replaceFirst("\\$seller", seller);
            ubbBody = ubbBody.replaceAll("\\$orderId", "" + id);
            ubbBody = ubbBody.replaceAll("\\$rootPath", rootPath);

            MessageDb msd = new MessageDb();
            msd.title = subject;
            msd.content = ubbBody;
            msd.sender = msd.USER_SYSTEM;
            msd.type = msd.TYPE_SYSTEM;
            msd.ip = "0.0.0.0";
            // 至卖家
            msd.receiver = seller;
            msd.create();
            // 至买家
            msd.receiver = buyer;
            msd.create();

            // 发邮件
            String from = StrUtil.GBToUnicode(ac.getEmailAlias());
	    from += "<" + ac.getEmail() + ">";

            // 至卖家
            SendMail sm = new SendMail();
            UserDb user = new UserDb();
            user = user.getUser(seller);
            sm.send(Global.smtpServer, Global.smtpPort, Global.smtpUser, Global.smtpPwd, user.getEmail(), from, subject, body);
            // 至买家
            user = user.getUser(buyer);
            sm.send(Global.smtpServer, Global.smtpPort, Global.smtpUser, Global.smtpPwd, user.getEmail(), from, subject, body);
        }
        return rowcount>0? true:false;
    }

    public boolean save() {
        int rowcount = 0;
        Conn conn = null;
        try {
            conn = new Conn(connname);
            PreparedStatement ps = conn.prepareStatement(this.QUERY_SAVE);
            ps.setLong(1, auctionId);
            ps.setInt(2, auctionSellType);
            ps.setString(3, seller);
            ps.setString(4, buyer);
            ps.setDouble(5, price);
            ps.setString(6, moneyCode);
            ps.setDouble(7, totalPrice);
            ps.setInt(8, amount);
            ps.setInt(9, sellerScore);
            ps.setInt(10, buyerScore);
            ps.setInt(11, state);
            if (payTime==null)
                ps.setString(12, null);
            else
                ps.setString(12, DateUtil.toLongString(payTime));
            if (deliverTime==null)
                ps.setString(13, null);
            else
                ps.setString(13, DateUtil.toLongString(deliverTime));
            ps.setString(14, commodityName);
            ps.setInt(15, id);
            rowcount = conn.executePreUpdate();
            if (rowcount>0) {
                AuctionOrderCache uc = new AuctionOrderCache(this);
                primaryKey.setValue(new Integer(id));
                uc.refreshSave(primaryKey);
            }
        } catch (SQLException e) {
            logger.error("save:" + e.getMessage());
        } finally {
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return rowcount>0? true:false;
    }

    public void load() {
        ResultSet rs = null;
        Conn conn = new Conn(connname);
        try {
            PreparedStatement ps = conn.prepareStatement(this.QUERY_LOAD);
            ps.setInt(1, id);
            primaryKey.setValue(new Integer(id));
            rs = conn.executePreQuery();
            if (rs.next()) {
                auctionId = rs.getInt(1);
                auctionSellType = rs.getInt(2);
                seller = rs.getString(3);
                buyer = rs.getString(4);
                price = rs.getDouble(5);
                moneyCode = rs.getString(6);
                totalPrice = rs.getDouble(7);
                amount = rs.getInt(8);
                sellerScore = rs.getInt(9);
                buyerScore = rs.getInt(10);
                state = rs.getInt(11);
                orderDate = DateUtil.parse(rs.getString(12));
                String str = rs.getString(13);
                if (str!=null) {
                    payTime = DateUtil.parse(str);
                }
                str = rs.getString(14);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -