// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   OrderAction.java

package com.keyshop.shop.order.controller;

import beartool.MD5;
import com.keyshop.pub.controller.PubAction;
import com.keyshop.pub.controller.PubForm;
import com.keyshop.pub.util.*;
import com.keyshop.shop.order.bo.OrderBO;
import com.keyshop.shop.order.model.*;
import com.keyshop.shop.order.util.*;
import com.keyshop.shop.product.model.Product;
import com.keyshop.shop.system.manager.SystemManager;
import com.keyshop.shop.system.model.*;
import com.keyshop.shop.system.util.SystemConst;
import com.keyshop.shop.user.model.User;
import com.keyshop.shop.user.util.UserConst;
import com.keyshop.shop.user.util.UserHelper;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;

// Referenced classes of package com.keyshop.shop.order.controller:
//            OrderForm

public class OrderAction extends PubAction
{

    public boolean isRedirect;

    public OrderAction()
    {
        isRedirect = false;
    }

    public String getSelectSQL()
    {
        String sql = " from Order as order1 where 1=1";
        OrderForm form = (OrderForm)thisform;
        String init = httpRequest.getParameter("init");
        if("true".equals(init))
        {
            form.clear();
            form.setChange("true");
        }
        String change = form.getChange();
        if("true".equals(change))
        {
            String dateType = "2";
           
            if(!StringUtil.isEmpty(startDate))
                sql = sql + " and order1.orderDate >='" + FormatHelper.parseTimestamp(startDate, true) + "'";
            if(!StringUtil.isEmpty(endDate))
                sql = sql + " and order1.orderDate <='" + FormatHelper.parseTimestamp(endDate, false) + "'";
        } else
        {
            OrderForm oform = (OrderForm)thisform;
            Order order = (Order)oform.getBean();
            if(!StringUtil.isEmpty(oform.getStartDate()))
                sql = sql + " and order1.orderDate >='" + FormatHelper.parseTimestamp(oform.getStartDate(), true) + "'";
            if(!StringUtil.isEmpty(oform.getEndDate()))
                sql = sql + " and order1.orderDate <='" + FormatHelper.parseTimestamp(oform.getEndDate(), false) + "'";
         
        }
        
        System.out.println("sql = " + sql);
        return sql;
    }

    public void initClassName()
    {
        boClass = "com.keyshop.shop.order.bo.OrderBO";
        beanClass = "com.keyshop.shop.order.model.Order";
        formBeanClass = "com.keyshop.shop.order.controller.OrderForm";
    }

    public ActionForward performUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        OrderForm oform = (OrderForm)form;
        String id = request.getParameter("bean.id");
        String status = request.getParameter("bean.status");
        try
        {
            OrderBO bo = new OrderBO();
            Order order = (Order)bo.get(id);
            if(order == null)
            {
                if(order.getStatus().equals(status))
                    request.setAttribute("status_error", "true");
            } else
            {
                request.setAttribute("no_order_error", "true");
            }
            order.setStatus(status);
            if(OrderHelper.GET_FIT_STATUS.equals(status))
                UserHelper.addUserOrderIntegral(order.getId());
            String opertor = "";
            if(request.getSession() != null)
            {
                Manager manager = (Manager)request.getSession().getAttribute(SystemConst.MANAGER);
                opertor = manager.getId();
            }
            OrderHelper.addTrace(order, opertor, order.getId(), opertor, status);
            bo.updateBean(order);
            oform.setBean(order);
           
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return mapping.findForward("view");
    }

    public ActionForward performSave(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        verifycode = getVerifycode(request);

        OrderForm orderForm = (OrderForm)form;
        Order order = (Order)orderForm.getBean();
        User user = (User)session.getValue("User");
        CartManager cartManager = null;
        if(user != null)
            cartManager = user.getCartManager();
        order.getOrderAddress().setOrder(order);
        if(cartManager != null && cartManager.getProducts() != null && cartManager.getProducts().size() > 0)
        {
            ShipType shiptype = OrderHelper.getShipType(order.getShipType());
            double totalCost = cartManager.getTotalAmount(user);
            if(user != null && !UserConst.ADVANCEUSERTYPE.equals(user.getUsertype()))
            {
                if("rate".equals(shiptype.getChargeType()))
                    totalCost *= 1.0D + (double)shiptype.getAmount() / 100D;
                else
                    totalCost += shiptype.getAmount();
                totalCost = FormatHelper.getDouble(totalCost, 2);
            }
            order.setTotalCost(totalCost);
            for(int i = 0; i < cartManager.getProducts().size(); i++)
            {
                com.keyshop.shop.order.model.CartManager.CartManagerProduct product = (com.keyshop.shop.order.model.CartManager.CartManagerProduct)cartManager.getProducts().get(i);
                OrderDetail orderDetail = new OrderDetail();
                orderDetail.setListPrice(product.getProduct().getListPrice());
                orderDetail.setUnitPrice(product.getProduct().getUnitPrice());
                orderDetail.setOmorder(order);
                orderDetail.setProductId(product.getId());
                orderDetail.setQuantity(product.getNumber());
                orderDetail.setTotalPrice((double)product.getNumber() * orderDetail.getUnitPrice());
                orderDetail.setProductName(product.getProduct().getName());
                orderDetail.setOrderDate(DateUtil.getSysDateString());
                orderDetail.setUnitType(product.getProduct().getUnit());
                order.getChildList().add(orderDetail);
            }

            try
            {
                OrderBO orderbo = new OrderBO();
                order.setCreator(user.getId());
                order.setStatus(OrderHelper.NO_DEAL_STATUS);
                order.getOrderAddress().setOrder(order);
                if(orderForm.isEquals())
                    syncOrderAddress(order.getOrderAddress(), order.getOrderConsigneeAddress());
                order.getOrderConsigneeAddress().setOrder(order);
                OrderHelper.addTrace(order, user.getId(), order.getId(), "", OrderHelper.NO_DEAL_STATUS);
                String serialNo = OrderHelper.createOrderNo();
                order.setSerialNo(serialNo);
                if(order.getChildList().size() > 0)
                    order.setProductNumber(order.getChildList().size());
                orderbo.addBean(order);
                order = (Order)orderbo.get(order.getId());
                orderForm.setBean(order);
                sendOrderMail(order, "user");
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        } else
        {
            request.setAttribute("sub_error", "true");
            return mapping.findForward("error");
        }
        user.setCartManager(new CartManager());
        try
        {
            PayConfig capInfoConfig = SystemManager.getCapInfoConfig(request);
            if(capInfoConfig != null)
            {
                order = (Order)orderForm.getBean();
                String vmid = capInfoConfig.getUsername();
                String orderId = DateUtil.getNoSpSysDateString() + "-" + vmid + "-" + order.getSerialNo();
                String v_rcvname = vmid;
                String v_rcvaddr = order.getOrderConsigneeAddress().getAddress();
                String v_rcvtel = order.getOrderConsigneeAddress().getTelephone();
                String v_rcvpost = order.getOrderConsigneeAddress().getZipCode();
                String v_amount = (int)order.getTotalCost() + ".00";
                String orderDate = DateUtil.getNoSpSysDateString();
                String v_orderstatus = "1";
                String v_ordername = order.getOrderAddress().getName();
                String v_moneytype = "0";
                String returnUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/" + "shop/order/capInfoListen.do";
                StringBuffer sb = new StringBuffer();
                sb.append(v_moneytype);
                sb.append(orderDate);
                sb.append(v_amount);
                sb.append(v_rcvname);
                sb.append(orderId);
                sb.append(vmid);
                sb.append(returnUrl);
                String key = capInfoConfig.getPassword();
                String md5info = PayUtil.getDigestString(sb.toString(), key);
                CapInfoPayInfo info = new CapInfoPayInfo();
                info.setVmid(vmid);
                info.setOrderId(orderId);
                info.setV_rcvname(v_rcvname);
                info.setV_rcvaddr(v_rcvaddr);
                info.setV_rcvtel(v_rcvtel);
                info.setV_rcvpost(v_rcvpost);
                info.setV_amount(v_amount);
                info.setOrderDate(orderDate);
                info.setV_orderstatus(v_orderstatus);
                info.setV_ordername(v_ordername);
                info.setV_moneytype(v_moneytype);
                info.setReturnUrl(returnUrl);
                info.setV_md5info(md5info);
                request.setAttribute("capInfo", info);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        try
        {
            PayConfig chinabankInfoConfig = SystemManager.getChinabankInfoConfig(request);
            if(chinabankInfoConfig != null)
            {
                order = (Order)orderForm.getBean();
                String v_mid = chinabankInfoConfig.getUsername();
                String v_oid = DateUtil.getNoSpSysDateString() + "-" + v_mid + "-" + order.getSerialNo();
                String v_rcvname = v_mid;
                String v_rcvaddr = order.getOrderConsigneeAddress().getAddress();
                String v_rcvtel = order.getOrderConsigneeAddress().getTelephone();
                String v_rcvpost = order.getOrderConsigneeAddress().getZipCode();
                String v_amount = (int)order.getTotalCost() + ".00";
                String orderDate = DateUtil.getNoSpSysDateString();
                String v_ordername = order.getOrderAddress().getName();
                String v_moneytype = "0";
                String returnUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/";
                StringBuffer sb = new StringBuffer();
                sb.append(v_amount);
                sb.append(v_moneytype);
                sb.append(v_oid);
                sb.append(v_mid);
                sb.append(returnUrl);
                String key = chinabankInfoConfig.getPassword();
                sb.append(key);
                MD5 md5 = new MD5();
                String v_md5info = md5.getMD5ofStr(sb.toString());
                ChinabankInfoPayInfo info = new ChinabankInfoPayInfo();
                info.setV_mid(v_mid);
                info.setV_rcvname(v_rcvname);
                info.setV_oid(v_oid);
                info.setV_rcvaddr(v_rcvaddr);
                info.setV_rcvtel(v_rcvtel);
                info.setV_rcvpost(v_rcvpost);
                info.setV_amount(v_amount);
                info.setV_ordername(v_ordername);
                info.setV_moneytype(v_moneytype);
                info.setV_url(returnUrl);
                info.setV_md5info(v_md5info);
                request.setAttribute("chinabankInfo", info);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        try
        {
            PayConfig cnCardConfig = SystemManager.getCnCardConfig(request);
            if(cnCardConfig != null)
            {
                order = (Order)orderForm.getBean();
                String c_mid = cnCardConfig.getUsername();
                String c_order = order.getSerialNo();
                String c_name = order.getOrderAddress().getName();
                String c_address = order.getOrderAddress().getAddress();
                String c_tel = order.getOrderAddress().getTelephone();
                String c_post = order.getOrderAddress().getZipCode();
                String c_email = order.getOrderAddress().getEmailAddress();
                String c_orderamount = (new StringBuffer(String.valueOf(order.getTotalCost()))).toString();
                String c_ymd = DateUtil.getNoSpSysDateString();
                String c_moneytype = "0";
                String c_retflag = "0";
                String c_paygate = "";
                String c_returl = "";
                String c_memo1 = "";
                String c_memo2 = "";
                String notifytype = "0";
                String c_language = "0";
                String c_pass = cnCardConfig.getPassword();
                CnCardMD5 md5 = new CnCardMD5();
                String srcStr = c_mid + c_order + c_orderamount + c_ymd + c_moneytype + c_retflag + c_returl + c_paygate + c_memo1 + c_memo2 + notifytype + c_language + c_pass;
                String c_signstr = md5.getMD5ofStr(srcStr);
                CnCardPayInfo info = new CnCardPayInfo();
                info.setC_mid(c_mid);
                info.setC_order(c_order);
                info.setC_name(c_name);
                info.setC_address(c_address);
                info.setC_tel(c_tel);
                info.setC_post(c_post);
                info.setC_email(c_email);
                info.setC_orderamount(c_orderamount);
                info.setC_ymd(c_ymd);
                info.setC_moneytype(c_moneytype);
                info.setC_retflag(c_retflag);
                info.setC_paygate(c_paygate);
                info.setC_returl(c_returl);
                info.setC_memo1(c_memo1);
                info.setC_memo2(c_memo2);
                info.setNotifytype(notifytype);
                info.setC_language(c_language);
                info.setC_signstr(c_signstr);
                request.setAttribute("cncardpayinfo", info);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        try
        {
            PayConfig alipayInfoConfig = SystemManager.getAlipayInfoConfig(request);
            if(alipayInfoConfig != null)
            {
                order = (Order)orderForm.getBean();
                String cmd = "0001";
                String body = order.getOrderString();
                String subject = body;
                String seller = alipayInfoConfig.getUsername();
                String order_no = order.getSerialNo();
                String price = (int)order.getTotalCost() + ".00";
                String ordinary_fee = "0.00";
                String express_fee = "0.00";
                StringBuffer sb = new StringBuffer();
                sb.append("cmd" + cmd);
                sb.append("subject" + subject);
                sb.append("body" + body);
                sb.append("order_no" + order_no);
                sb.append("price" + price);
                sb.append("ordinary_fee" + ordinary_fee);
                sb.append("express_fee" + express_fee);
                sb.append("seller" + seller);
                sb.append("partner2088002065646805");
                String key = alipayInfoConfig.getPassword();
                sb.append(key);
                String ac = Md5Encrypt.md5(sb.toString());
                AlipayInfoPayInfo info = new AlipayInfoPayInfo();
                info.setCmd(cmd);
                info.setSubject(subject);
                info.setBody(body);
                info.setOrder_no(order_no);
                info.setPrice(price);
                info.setOrdinary_fee(ordinary_fee);
                info.setExpress_fee(express_fee);
                info.setSeller(seller);
                info.setAc(ac);
                request.setAttribute("alipayInfo", info);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return mapping.findForward("success");
    }

    public ActionForward performFgsave(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        performSave(mapping, form, request, response);
        return mapping.findForward("success");
    }

    public ActionForward performList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        PubForm pForm = (PubForm)form;
        Pager page = new Pager(pForm.getCurrentPageNo());
        request.setAttribute("pager", page);
        List list = new ArrayList();
        try
        {
            OrderBO bo = new OrderBO();
            list = bo.list(page, getSelectSQL());
        }
        catch(Exception exception) { }
        request.setAttribute("searchresult", list);
        return mapping.findForward("list");
    }

    public ActionForward performFgview(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        super.performView(mapping, form, request, response);
        OrderForm tform = (OrderForm)form;
        Order order = (Order)tform.getBean();
        if(order == null || !StringUtil.isEmpty(order.getId()))
            request.setAttribute("no_order", "true");
        return mapping.findForward("fgview");
    }

    public ActionForward performSendremessage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        OrderForm pForm = (OrderForm)form;
        Order order = (Order)pForm.getBean();
        String orderId = order.getId();
        if(!StringUtil.isEmpty(order.getId()))
            try
            {
                OrderBO bo = new OrderBO();
                Order prorder = (Order)bo.get(orderId);
                prorder.setRemessage(order.getRemessage());
                bo.updateBean(prorder);
                if(prorder.getOrderAddress() != null && !StringUtil.isEmpty(prorder.getOrderAddress().getEmailAddress()))
                    sendSendRemessageMail(prorder);
                pForm.setBean(prorder);
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        return mapping.findForward("view");
    }

    private void sendSendRemessageMail(Order order)
    {
        if(order == null || order.getOrderAddress() == null)
            return;
        HashMap replaceTbl = new HashMap();
        String USERNAME = " ";
        String REMESSAGE = " ";
        String PRODUCTINFO = " ";
        String PAYTYPE = " ";
        String SHIPTYPE = " ";
        String TOTALCOST = " ";
        String ORDERID = " ";
        String ORDERADDRESSADDRESS = " ";
        String ORDERADDRESSNAME = " ";
        String ORDERADDRESSZIPCODE = " ";
        String ORDERCONADDRESSADDRESS = " ";
        String ORDERCONADDRESSNAME = " ";
        String ORDERCONADDRESSZIPCODE = " ";
        String SHIPAMOUNT = " ";
        String CONTACT = "";
        String ORDERCONADDRESSCONTACT = "";
        int QUANTITY = 0;
        if(!StringUtil.isEmpty(order.getOrderAddress().getName()))
        {
            USERNAME = order.getCreator();
            if(!StringUtil.isEmpty(order.getCreator()))
                USERNAME = order.getOrderAddress().getName();
        }
        if(order.getChildList() != null && order.getChildList().size() > 0)
        {
            for(Iterator it = order.getChildList().iterator(); it.hasNext();)
            {
                PRODUCTINFO = PRODUCTINFO + "<tr bgcolor='#FFECF5'>";
                PRODUCTINFO = PRODUCTINFO + "<td><strong>商品单价/名称:</strong></td>";
                PRODUCTINFO = PRODUCTINFO + "<td>";
                OrderDetail detail = (OrderDetail)it.next();
                PRODUCTINFO = PRODUCTINFO + "<font color='#FF0000'>￥" + detail.getUnitPrice() + "元</font>&nbsp;&nbsp;";
                PRODUCTINFO = PRODUCTINFO + "<font color='black'>" + detail.getProductName() + "</font>&nbsp;&nbsp;";
                PRODUCTINFO = PRODUCTINFO + "<font color='black'>" + detail.getQuantity() + "册</font>&nbsp;&nbsp;";
                PRODUCTINFO = PRODUCTINFO + "</td>";
                PRODUCTINFO = PRODUCTINFO + "</tr>";
                QUANTITY += detail.getQuantity();
            }

        }
        if(!StringUtil.isEmpty(order.getPayType()))
        {
            PayType pt = OrderHelper.getPayType(order.getPayType());
            PAYTYPE = pt.getName();
        }
        if(!StringUtil.isEmpty(order.getShipType()))
        {
            ShipType sp = OrderHelper.getShipType(order.getShipType());
            SHIPTYPE = sp.getName();
            SHIPAMOUNT = (new StringBuffer(String.valueOf(sp.getAmount()))).toString();
        }
        TOTALCOST = (new StringBuffer(String.valueOf(order.getTotalCost()))).toString();
        ORDERID = (new StringBuffer(String.valueOf(order.getSerialNo()))).toString();
        if(order.getOrderAddress() != null)
        {
            ORDERADDRESSADDRESS = order.getOrderAddress().getAddress();
            ORDERADDRESSNAME = order.getOrderAddress().getName();
            ORDERADDRESSZIPCODE = order.getOrderAddress().getZipCode();
            CONTACT = order.getOrderAddress().getAreaNo();
            if(StringUtil.isEmpty(CONTACT))
                CONTACT = CONTACT + order.getOrderAddress().getTelephone();
            else
                CONTACT = CONTACT + "-" + order.getOrderAddress().getTelephone();
            if(StringUtil.isEmpty(CONTACT))
                CONTACT = order.getOrderAddress().getMobileTelephone();
        }
        if(order.getOrderConsigneeAddress() != null)
        {
            ORDERCONADDRESSADDRESS = order.getOrderConsigneeAddress().getAddress();
            ORDERCONADDRESSNAME = order.getOrderConsigneeAddress().getName();
            ORDERCONADDRESSZIPCODE = order.getOrderConsigneeAddress().getZipCode();
            ORDERCONADDRESSCONTACT = order.getOrderConsigneeAddress().getAreaNo();
            if(StringUtil.isEmpty(ORDERCONADDRESSCONTACT))
                ORDERCONADDRESSCONTACT = order.getOrderAddress().getTelephone();
            else
                ORDERCONADDRESSCONTACT = "-" + order.getOrderAddress().getTelephone();
            if(StringUtil.isEmpty(ORDERCONADDRESSCONTACT))
                CONTACT = order.getOrderConsigneeAddress().getMobileTelephone();
        } else
        {
            ORDERCONADDRESSADDRESS = order.getOrderAddress().getAddress();
            ORDERCONADDRESSNAME = order.getOrderAddress().getName();
            ORDERCONADDRESSZIPCODE = order.getOrderAddress().getZipCode();
        }
        if(StringUtil.isEmpty(TOTALCOST))
            TOTALCOST = "&nbsp;";
        replaceTbl.put("$$TOTALCOST$$$", TOTALCOST);
        if(StringUtil.isEmpty(ORDERID))
            ORDERID = "&nbsp;";
        replaceTbl.put("$$ORDERID$$$", ORDERID);
        if(StringUtil.isEmpty(ORDERADDRESSADDRESS))
            ORDERADDRESSADDRESS = "&nbsp;";
        replaceTbl.put("$$ORDERADDRESSADDRESS$$$", ORDERADDRESSADDRESS);
        if(StringUtil.isEmpty(ORDERADDRESSNAME))
            ORDERADDRESSNAME = "&nbsp;";
        replaceTbl.put("$$ORDERADDRESSNAME$$$", ORDERADDRESSNAME);
        if(StringUtil.isEmpty(ORDERADDRESSZIPCODE))
            ORDERADDRESSZIPCODE = "&nbsp;";
        replaceTbl.put("$$ORDERADDRESSZIPCODE$$$", ORDERADDRESSZIPCODE);
        if(StringUtil.isEmpty(ORDERCONADDRESSADDRESS))
            ORDERCONADDRESSADDRESS = "&nbsp;";
        replaceTbl.put("$$ORDERCONADDRESSADDRESS$$$", ORDERCONADDRESSADDRESS);
       
        replaceTbl.put("$$QUANTITY$$$", (new StringBuffer(String.valueOf(QUANTITY))).toString());
        if(StringUtil.isEmpty(ORDERCONADDRESSCONTACT))
            ORDERCONADDRESSCONTACT = "&nbsp;";
        replaceTbl.put("$$ORDERCONADDRESSCONTACT$$$", (new StringBuffer(String.valueOf(ORDERCONADDRESSCONTACT))).toString());
        replaceTbl.put("$$SYSADDRESS$$", viewConfig.getSys_address());
        replaceTbl.put("$$SYSNAME$$", viewConfig.getSys_name());
        replaceTbl.put("$$SYSEMAIL$$", viewConfig.getSys_email());
        replaceTbl.put("$$SYSLOCALNAME$$", viewConfig.getSys_localname());
        replaceTbl.put("$$SYSLOCALIP$$", viewConfig.getSys_localip());
        replaceTbl.put("$$LINKINFO$$", viewConfig.getLink_info());
        replaceTbl.put("$$LOGIMAGE$$", viewConfig.getLog_image());
        replaceTbl.put("$$SYSMSN$$", viewConfig.getSys_msn());
        replaceTbl.put("$$SYSTEL$$", viewConfig.getSys_tel());
        replaceTbl.put("$$SYSQQ$$", viewConfig.getSys_qq());
        replaceTbl.put("$$VERSIONINFO$$", viewConfig.getVersion_info());
        String modelStr = "";
        MailConfig mailconfig = SystemManager.getMailConfig(httpRequest);
        if(mailconfig != null)
        {
            modelStr = mailconfig.getUser_order_remail();
            try
            {
                String mailContent = FileIO.repalceStr(modelStr, replaceTbl);
                String subject = mailconfig.getUser_order_remail_subject();
                String serverAddress = mailconfig.getSmtp_host();
                String userName = mailconfig.getSmtp_user();
                String pwd = mailconfig.getSmtp_password();
                String receiver = "";
                receiver = order.getOrderAddress().getEmailAddress();
                String from = mailconfig.getMail_from();
                MailHelper.sendMail(serverAddress, userName, pwd, from, receiver, subject, mailContent);
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        }
    }

    public ActionForward performCancel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
return null;
    }

    public ActionForward performFglist(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
       return null;
    }

    public ActionForward performView(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
      return null;
    }

    public ActionForward performAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
return null;
    }

    private void syncOrderAddress(Order order, User user)
    {
        OrderAddress ad = order.getOrderAddress();
        ad.setAddress(user.getContact_address());
        ad.setEmailAddress(user.getEmail());
        ad.setMobileTelephone(user.getMobile());
        ad.setTelephone(user.getPhone());
        ad.setName(user.getUserName());
        ad.setSex(user.isSex());
        ad.setZipCode(user.getZipcode());
    }

    private void syncOrderAddress(OrderAddress orderAddress, OrderConsigneeAddress orderCoAddress)
    {
        orderCoAddress.setAddress(orderAddress.getAddress());
        orderCoAddress.setEmailAddress(orderAddress.getEmailAddress());
        orderCoAddress.setMobileTelephone(orderAddress.getMobileTelephone());
        orderCoAddress.setTelephone(orderAddress.getTelephone());
        orderCoAddress.setName(orderAddress.getName());
        orderCoAddress.setSex(orderAddress.isSex());
        orderCoAddress.setZipCode(orderAddress.getZipCode());
    }

    public String getDigestString(String text, String key)
        throws IOException
    {
        Md5 md5 = new Md5("");
        md5.hmac_Md5(text, key);
        byte b[] = md5.getDigest();
        return Md5.stringify(b);
    }

    private void sendOrderMail(Order order, String type)
    {
        if(order == null || order.getOrderAddress() == null)
            return;
        HashMap replaceTbl = new HashMap();
        String USERNAME = " ";
        String PRODUCTINFO = " ";
        String PAYTYPE = " ";
        String SHIPTYPE = " ";
        String TOTALCOST = " ";
        String ORDERID = " ";
        String ORDERADDRESSADDRESS = " ";
        String ORDERADDRESSNAME = " ";
        String ORDERADDRESSZIPCODE = " ";
        String ORDERCONADDRESSADDRESS = " ";
        String ORDERCONADDRESSNAME = " ";
        String ORDERCONADDRESSZIPCODE = " ";
        String SHIPAMOUNT = " ";
        if(!StringUtil.isEmpty(order.getOrderAddress().getName()))
            USERNAME = order.getCreator();
        double ptotalCost = 0.0D;
        if(order.getChildList() != null && order.getChildList().size() > 0)
        {
            for(Iterator it = order.getChildList().iterator(); it.hasNext();)
            {
                OrderDetail detail = (OrderDetail)it.next();
                PRODUCTINFO = PRODUCTINFO + detail.getProductName() + "&nbsp;&nbsp;";
                PRODUCTINFO = PRODUCTINFO + "单价:" + detail.getUnitPrice() + "元&nbsp;&nbsp;";
                PRODUCTINFO = PRODUCTINFO + detail.getQuantity() + "册&nbsp;&nbsp;";
                PRODUCTINFO = PRODUCTINFO + "金额:" + detail.getUnitPrice() * (double)detail.getQuantity() + "元&nbsp;&nbsp;";
                PRODUCTINFO = PRODUCTINFO + "<br/>";
                ptotalCost = detail.getUnitPrice() * (double)detail.getQuantity();
            }

        }
        if(!StringUtil.isEmpty(order.getShipType()))
        {
            ShipType sp = OrderHelper.getShipType(order.getShipType());
            SHIPTYPE = sp.getName();
            if("rate".equals(sp.getChargeType()))
                SHIPAMOUNT = (new StringBuffer(String.valueOf(ptotalCost * (1.0D + (double)sp.getAmount() / 100D)))).toString();
            else
                SHIPAMOUNT = (new StringBuffer(String.valueOf(sp.getAmount()))).toString();
            SHIPAMOUNT = (new StringBuffer(String.valueOf(sp.getAmount()))).toString();
        }
        TOTALCOST = (new StringBuffer(String.valueOf(order.getTotalCost()))).toString();
        ORDERID = (new StringBuffer(String.valueOf(order.getSerialNo()))).toString();

        if(order.getOrderConsigneeAddress() != null)
        {
            ORDERCONADDRESSADDRESS = order.getOrderConsigneeAddress().getAddress();
            ORDERCONADDRESSNAME = order.getOrderConsigneeAddress().getName();
            ORDERCONADDRESSZIPCODE = order.getOrderConsigneeAddress().getZipCode();
        } else
        {
            ORDERCONADDRESSADDRESS = order.getOrderAddress().getAddress();
            ORDERCONADDRESSNAME = order.getOrderAddress().getName();
            ORDERCONADDRESSZIPCODE = order.getOrderAddress().getZipCode();
        }
        replaceTbl.put("$$USERNAME$$$", USERNAME);
        replaceTbl.put("$$PRODUCTINFO$$$", PRODUCTINFO);
        replaceTbl.put("$$PAYTYPE$$$", PAYTYPE);
        replaceTbl.put("$$SHIPTYPE$$$", SHIPTYPE);
        replaceTbl.put("$$TOTALCOST$$$", TOTALCOST);
        replaceTbl.put("$$ORDERID$$$", ORDERID);
        replaceTbl.put("$$ORDERADDRESSADDRESS$$$", ORDERADDRESSADDRESS);
        replaceTbl.put("$$ORDERADDRESSNAME$$$", ORDERADDRESSNAME);
        replaceTbl.put("$$ORDERADDRESSZIPCODE$$$", ORDERADDRESSZIPCODE);
        replaceTbl.put("$$ORDERCONADDRESSADDRESS$$$", ORDERCONADDRESSADDRESS);
        replaceTbl.put("$$ORDERCONADDRESSNAME$$$", ORDERCONADDRESSNAME);
        replaceTbl.put("$$ORDERCONADDRESSZIPCODE$$$", ORDERCONADDRESSZIPCODE);
        replaceTbl.put("$$SHIPAMOUNT$$$", SHIPAMOUNT);
        String modelStr = "";
        MailConfig mailconfig = SystemManager.getMailConfig(httpRequest);
        if(mailconfig != null)
        {
            if("manager".equals(type))
                modelStr = mailconfig.getManager_order_mail();
            else
                modelStr = mailconfig.getUser_order_mail();
            try
            {
                String mailContent = FileIO.repalceStr(modelStr, replaceTbl);
                String subject = "";
                if("manager".equals(type))
                    subject = mailconfig.getManager_order_mail_subject();
                else
                    subject = mailconfig.getUser_order_mail_subject();
                String serverAddress = mailconfig.getSmtp_host();
                String userName = mailconfig.getSmtp_user();
                String pwd = mailconfig.getSmtp_password();
                String receiver = "";
                if("manager".equals(type))
                    receiver = mailconfig.getMail_receiver();
                else
                    receiver = order.getOrderAddress().getEmailAddress();
                String from = mailconfig.getMail_from();
                MailHelper.sendMail(serverAddress, userName, pwd, from, receiver, subject, mailContent);
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
            }
        }
    }
}
