public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset     = "utf-8";

            string Action = context.Request["Action"].ToString();

            string result = "{\"result\":\"failed\"}";
            string openid = "";

            if (!string.IsNullOrEmpty(Action))
            {
                switch (Action)
                {
                case "order":
                    var    orderdata  = context.Request["orderdata"].ToString();
                    string _statusid  = "1";
                    string _statusStr = "NotPaid";
                    AllTrustUs.SquirrelPocket.Entity.Order _o = JsonUtility.Deserialize <AllTrustUs.SquirrelPocket.Entity.Order>(orderdata);
                    if (Convert.ToDecimal(_o.actualprice) == 0)
                    {
                        _statusid  = "2";
                        _statusStr = "PaidSuccessed";
                    }

                    string insjson = @"insert into t_order(openid,outtradeno,fruittype,unitprice,startdate,enddate,days,
                            count,deliveryaddr,user,mp,totalprice,status,createdate,statusid,deliverystatus,otheraddr,GiftCardCode,deduction,actualprice,agencylevel,discount) values({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21});select @@IDENTITY;";
                    insjson = string.Format(insjson,
                                            UtilityFn.formatstring(_o.openid),
                                            UtilityFn.formatstring(UtilityFn.GenerateOutTradeNo()),
                                            UtilityFn.formatstring(_o.fruittype),
                                            UtilityFn.formatstring(_o.unitprice),
                                            UtilityFn.formatstring(_o.startdate),
                                            UtilityFn.formatstring(_o.enddate),
                                            UtilityFn.formatstring(_o.days),
                                            UtilityFn.formatstring(_o.count),
                                            UtilityFn.formatstring(_o.deliveryaddr),
                                            UtilityFn.formatstring(_o.user),
                                            UtilityFn.formatstring(_o.mp),
                                            UtilityFn.formatstring(_o.totalprice),
                                            UtilityFn.formatstring(_statusStr),
                                            UtilityFn.formatstring(DateTime.Now.ToString("yyyy/MM/dd HH:mm")),
                                            UtilityFn.formatstring(_statusid),
                                            UtilityFn.formatstring("未配送"),
                                            UtilityFn.formatstring(_o.otheraddr),
                                            UtilityFn.formatstring(_o.GiftCardCode),
                                            UtilityFn.formatstring(_o.deduction),
                                            UtilityFn.formatstring(_o.actualprice),
                                            UtilityFn.formatstring(_o.agencylevel),
                                            UtilityFn.formatstring(_o.discount)
                                            );
                    DataTable order = MySqlHelp.ExecuteDataTable(insjson);

                    if (order.Rows.Count > 0 && int.Parse(order.Rows[0][0].ToString()) > 0)
                    {
                        var orderid = order.Rows[0][0].ToString();
                        if (!string.IsNullOrEmpty(_o.GiftCardCode))
                        {
                            var updatecard = "update giftcard set isused='1',usedorderid='" + orderid + "',useddate='" + DateTime.Now.ToString("yyyy-MM-dd") + "' where giftcardcode='" + _o.GiftCardCode.Replace("-", "") + "'";
                            MySqlHelp.ExecuteNonQuery(updatecard);
                        }

                        foreach (AllTrustUs.SquirrelPocket.Entity.OrderFruit of in _o.fruits)
                        {
                            string insof = @"insert into t_orderfruts(orderid,fruitid,name,unit,unitprice,count,price,fruitNum,cost) 
                                    values({0},{1},{2},{3},{4},{5},{6},{7},{8});";
                            insof = string.Format(insof,
                                                  UtilityFn.formatstring(orderid),
                                                  UtilityFn.formatstring(of.FruitID),
                                                  UtilityFn.formatstring(of.Name),
                                                  UtilityFn.formatstring(string.IsNullOrEmpty(of.unit) ? "个" : of.unit),
                                                  UtilityFn.formatstring(of.unitprice),
                                                  UtilityFn.formatstring(string.IsNullOrEmpty(of.count) ? "1" : of.count),
                                                  UtilityFn.formatstring(of.price),
                                                  UtilityFn.formatstring(of.fruitNum),
                                                  UtilityFn.formatstring(of.cost)
                                                  );

                            MySqlHelp.ExecuteNonQuery(insof);
                        }

                        foreach (Entity.Delivery de in _o.deliverys)
                        {
                            string insdeli = @"insert into t_delivery(orderid,date,count,status) 
                                    values({0},{1},{2},{3});select @@IDENTITY;";
                            insdeli = string.Format(insdeli,
                                                    UtilityFn.formatstring(orderid),
                                                    UtilityFn.formatstring(de.Date),
                                                    UtilityFn.formatstring(de.Count),
                                                    UtilityFn.formatstring("未配送"));
                            DataTable deliDT = MySqlHelp.ExecuteDataTable(insdeli);
                            if (deliDT.Rows.Count > 0 && int.Parse(deliDT.Rows[0][0].ToString()) > 0)
                            {
                                var deliID = deliDT.Rows[0][0].ToString();
                                foreach (Entity.Deliveryfruits def in de.Deliveryfruits)
                                {
                                    string insdelif = @"insert into t_deliveryfruits(deliveryid,fruitid,name) 
                                    values({0},{1},{2});";
                                    insdelif = string.Format(insdelif,
                                                             UtilityFn.formatstring(deliID),
                                                             UtilityFn.formatstring(def.FruitID),
                                                             UtilityFn.formatstring(def.Name));
                                    MySqlHelp.ExecuteNonQuery(insdelif);
                                }
                            }
                        }
                        EmailHelper eh = new EmailHelper();
                        eh.SendMail("Squirel New Order Create", UtilityFn.JsonToHTMLTable(_o.ToJSONString()));

                        result = "{\"result\":\"successed\",\"orderid\":\"" + orderid + "\"}";
                    }
                    break;

                case "getorder":
                    openid = context.Request["openid"].ToString();
                    var status = context.Request["status"].ToString();
                    List <Entity.Order> _Orders = new List <Entity.Order>();
                    string    getsql            = "select * from t_order where openid=" + UtilityFn.formatstring(openid) + " and status=" + UtilityFn.formatstring(status) + " and status<>'deleted' order by statusid asc, createdate desc";
                    DataTable odDT = MySqlHelp.ExecuteDataTable(getsql);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.Order orderentity = new Entity.Order();

                        orderentity.openid       = odDT.Rows[i]["openid"].ToString();
                        orderentity.fruittype    = odDT.Rows[i]["fruittype"].ToString();
                        orderentity.startdate    = odDT.Rows[i]["startdate"].ToString();
                        orderentity.enddate      = odDT.Rows[i]["enddate"].ToString();
                        orderentity.days         = odDT.Rows[i]["days"].ToString();
                        orderentity.count        = odDT.Rows[i]["count"].ToString();
                        orderentity.deliveryaddr = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.user         = odDT.Rows[i]["user"].ToString();
                        orderentity.mp           = odDT.Rows[i]["mp"].ToString();
                        orderentity.totalprice   = odDT.Rows[i]["totalprice"].ToString();
                        orderentity.outtradeno   = odDT.Rows[i]["outtradeno"].ToString();
                        orderentity.status       = odDT.Rows[i]["status"].ToString();
                        orderentity.orderid      = odDT.Rows[i]["orderid"].ToString();
                        orderentity.createdate   = odDT.Rows[i]["createdate"].ToString();
                        orderentity.unitprice    = odDT.Rows[i]["unitprice"].ToString();
                        orderentity.otheraddr    = odDT.Rows[i]["otheraddr"].ToString();
                        orderentity.deduction    = odDT.Rows[i]["deduction"].ToString();
                        orderentity.actualprice  = odDT.Rows[i]["actualprice"].ToString();

                        string    getfruitssql = "select * from t_orderfruts where orderid=" + UtilityFn.formatstring(orderentity.orderid);
                        DataTable frDT         = MySqlHelp.ExecuteDataTable(getfruitssql);
                        orderentity.fruits = new List <Entity.OrderFruit>();
                        for (int j = 0; j < frDT.Rows.Count; j++)
                        {
                            Entity.OrderFruit ordereFruitntity = new Entity.OrderFruit();
                            ordereFruitntity.FruitID = frDT.Rows[j]["fruitid"].ToString();
                            ordereFruitntity.Name    = frDT.Rows[j]["name"].ToString();
                            orderentity.fruits.Add(ordereFruitntity);
                        }

                        _Orders.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_Orders) + "}";



                    break;

                case "cancelorder":
                    string cancelorderid = context.Request["orderid"].ToString();
                    MySqlHelp.ExecuteNonQuery("update t_order set status='Canceled',statusid='5' where orderid=" + UtilityFn.formatstring(cancelorderid));
                    result = "{\"result\":\"successed\"}";
                    break;

                case "deleteorder":
                    string deleteorderorderid = context.Request["orderid"].ToString();
                    MySqlHelp.ExecuteNonQuery("update t_order set status='Deleted',statusid='4' where orderid=" + UtilityFn.formatstring(deleteorderorderid));
                    result = "{\"result\":\"successed\"}";
                    break;

                case "saveuserinfo":
                    string userdata = context.Request["userdata"].ToString();
                    openid = context.Request["openid"].ToString();

                    Dictionary <string, object> Dic = JsonUtility.ToDictionary(userdata);
                    var nickname = Dic["nickname"].ToString();
                    var country  = Dic["country"].ToString();
                    var province = Dic["province"].ToString();
                    var city     = Dic["city"].ToString();
                    var sex      = "";
                    if (!string.IsNullOrEmpty(Dic["sex"].ToString()))
                    {
                        if (Dic["sex"].ToString().Contains("男"))
                        {
                            sex = "1";
                        }
                        else
                        {
                            sex = "2";
                        }
                    }
                    else
                    {
                        sex = "1";
                    }

                    var mp = Dic["mp"].ToString();

                    ((WeXUser)context.Session["CurrentWeXUser"]).MP       = mp;
                    ((WeXUser)context.Session["CurrentWeXUser"]).city     = city;
                    ((WeXUser)context.Session["CurrentWeXUser"]).country  = country;
                    ((WeXUser)context.Session["CurrentWeXUser"]).nickname = nickname;
                    ((WeXUser)context.Session["CurrentWeXUser"]).sex      = sex;
                    ((WeXUser)context.Session["CurrentWeXUser"]).province = province;
                    MySqlHelp.ExecuteNonQuery("update t_user set mp=" + UtilityFn.formatstring(mp)
                                              + ",nickname=" + UtilityFn.formatstring(nickname)
                                              + ",country=" + UtilityFn.formatstring(country)
                                              + ",province=" + UtilityFn.formatstring(province)
                                              + ",city=" + UtilityFn.formatstring(city)
                                              + ",sex=" + UtilityFn.formatstring(sex)
                                              + " where openid=" + UtilityFn.formatstring(openid));

                    //((WeXUser)context.Session["CurrentWeXUser"]).MP = mp;

                    result = "{\"result\":\"successed\"}";

                    break;

                case "getDeliveryDetail":
                    var Deliveryorderid         = context.Request["orderid"].ToString();
                    List <Entity.Delivery> deli = new List <Entity.Delivery>();
                    string    Deligetsql        = "select * from t_delivery where orderid=" + UtilityFn.formatstring(Deliveryorderid);
                    DataTable DeliDT            = MySqlHelp.ExecuteDataTable(Deligetsql);

                    for (int i = 0; i < DeliDT.Rows.Count; i++)
                    {
                        Entity.Delivery ent = new Entity.Delivery();
                        ent.ID             = DeliDT.Rows[i]["ID"].ToString();
                        ent.OrderID        = Deliveryorderid;
                        ent.Date           = DeliDT.Rows[i]["Date"].ToString();
                        ent.Count          = DeliDT.Rows[i]["Count"].ToString();
                        ent.deliverystatus = DeliDT.Rows[i]["status"].ToString();
                        deli.Add(ent);
                    }

                    result = "{\"result\":\"successed\",\"deliverys\":" + JsonUtility.ToJSONString(deli) + "}";
                    break;

                case "orderRefund":
                    string    orderRefundorderid = context.Request["orderid"].ToString();
                    DataTable orderDT            = MySqlHelp.ExecuteDataTable(string.Format("select * from t_order where orderid={0}", orderRefundorderid));
                    var       outtradeno         = orderDT.Rows[0]["outtradeno"].ToString();
                    var       transaction_id     = orderDT.Rows[0]["transaction_id"].ToString();
                    var       totalprice         = orderDT.Rows[0]["totalprice"].ToString();
                    var       actualprice        = orderDT.Rows[0]["actualprice"].ToString();
                    try
                    {
                        string Refundresult = Refund.Run(transaction_id, outtradeno, (int.Parse(actualprice) * 100).ToString(), (int.Parse(actualprice) * 100).ToString());

                        Dictionary <string, object> di = JsonUtility.ToDictionary(Refundresult);
                        EmailHelper eh = new EmailHelper();
                        if (di["result_code"].ToString().ToUpper() == "FAIL")
                        {
                            result = "{\"result\":\"failed\"}";
                            eh.SendMail("Squirel Refunded Order failed[" + orderRefundorderid + "]", UtilityFn.JsonToHTMLTable(Refundresult));
                        }
                        else
                        {
                            result = "{\"result\":\"successed\"}";
                            MySqlHelp.ExecuteNonQuery(string.Format("update t_order set status='Refunded',statusid='100' where  orderid={0}", orderRefundorderid));
                            eh.SendMail("Squirel Refunded Order Successed[" + orderRefundorderid + "]", UtilityFn.JsonToHTMLTable(Refundresult));
                        }
                        Log.Info(this.GetType().ToString(), Refundresult);

                        //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result + "</span>");
                    }
                    catch (WxPayException ex)
                    {
                        result = "{\"result\":\"failed\"}";
                        //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
                    }
                    catch (Exception ex)
                    {
                        result = "{\"result\":\"failed\"}";
                        //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex.ToString() + "</span>");
                    }


                    break;

                case "getgiftcode":
                    string    giftcode   = context.Request["giftcode"].ToString().Replace("-", "");
                    DataTable giftcodeDT = MySqlHelp.ExecuteDataTable(string.Format("select * from giftcard where isused='0' and giftcardcode='{0}'", giftcode));
                    if (giftcodeDT.Rows.Count > 0)
                    {
                        Giftcard gc = new Giftcard();
                        gc.id           = Convert.ToInt32(giftcodeDT.Rows[0]["id"]);
                        gc.giftcardcode = giftcodeDT.Rows[0]["giftcardcode"].ToString();
                        gc.amount       = giftcodeDT.Rows[0]["amount"].ToString();
                        gc.generatedate = giftcodeDT.Rows[0]["generatedate"].ToString();
                        gc.isused       = giftcodeDT.Rows[0]["isused"].ToString();
                        gc.usedorderid  = giftcodeDT.Rows[0]["usedorderid"].ToString();
                        gc.useddate     = giftcodeDT.Rows[0]["useddate"].ToString();
                        gc.forcompany   = giftcodeDT.Rows[0]["forcompany"].ToString();
                        gc.expireddate  = giftcodeDT.Rows[0]["expireddate"].ToString();

                        result = "{\"result\":\"successed\",\"giftcard\":" + JsonUtility.ToJSONString(gc) + "}";
                    }
                    else
                    {
                        result = "{\"result\":\"failed\"}";
                    }
                    break;

                default:
                    break;
                }
            }
            context.Response.Write(result);
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset     = "utf-8";

            string Action     = context.Request["Action"].ToString();
            var    conditions = context.Request["conditions"];
            var    deliveryid = context.Request["deliveryid"];
            var    orderid    = context.Request["orderid"];
            string result     = string.Empty;
            var    querySQL   = string.Empty;
            List <Entity.DeliveryReport> _DeliveryReport = new List <Entity.DeliveryReport>();
            DataTable odDT = new DataTable();

            if (!string.IsNullOrEmpty(Action))
            {
                switch (Action.ToLower())
                {
                case "getdeliverys":
                    querySQL = @"select 
tor.outtradeno as 'orderid',
td.id as 'deliveryid',
td.status as 'deliverystatus',
tor.openid,
tu.nickname,
tor.fruittype,
tor.count,
tor.deliveryaddr,
tor.user,
tor.mp,
td.date,
GROUP_CONCAT(tdf.name) as 'fruits'
from t_order tor
inner join t_delivery td
on tor.orderid=td.orderid and tor.status='PaidSuccessed'
inner join t_deliveryfruits tdf
on tdf.deliveryid=td.id
inner join t_user tu
on tu.openid=tor.openid
group by 
tor.outtradeno,
tor.openid,
tu.nickname,
tor.fruittype,
tor.count,
tor.deliveryaddr,
tor.user,
tor.mp,
td.date
order by td.date
";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.orderid        = odDT.Rows[i]["orderid"].ToString();
                        orderentity.openid         = odDT.Rows[i]["openid"].ToString();
                        orderentity.nickname       = odDT.Rows[i]["nickname"].ToString();
                        orderentity.fruittype      = odDT.Rows[i]["fruittype"].ToString();
                        orderentity.count          = odDT.Rows[i]["count"].ToString();
                        orderentity.deliveryaddr   = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.user           = odDT.Rows[i]["user"].ToString();
                        orderentity.date           = odDT.Rows[i]["date"].ToString();
                        orderentity.mp             = odDT.Rows[i]["mp"].ToString();
                        orderentity.fruits         = odDT.Rows[i]["fruits"].ToString();
                        orderentity.deliveryid     = odDT.Rows[i]["deliveryid"].ToString();
                        orderentity.deliverystatus = odDT.Rows[i]["deliverystatus"].ToString();
                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";

                    break;

                case "getgiftboxdelivery":

                    querySQL = @"select 
tor.outtradeno as 'orderid',
tor.openid,
tu.nickname,
tor.fruittype,
tor.startdate,
tor.count,
tor.deliveryaddr,
tor.user,
tor.mp,
tor.deliverystatus,
GROUP_CONCAT(CONCAT(tof.name,tof.fruitNum * tof.count ,tof.unit,' (',CAST(tof.count AS char),'份)' ) )as 'fruits',
tor.GiftCardCode,
tor.ExpressNumber
from t_order tor
inner join t_orderfruts tof
on tof.orderid=tor.orderid and  tor.status in('PaidSuccessed','Completed') and fruittype like '%礼盒%' 
inner join t_user tu
on tu.openid=tor.openid
group by
tor.outtradeno
order by startdate
";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.orderid   = odDT.Rows[i]["orderid"].ToString();
                        orderentity.openid    = odDT.Rows[i]["openid"].ToString();
                        orderentity.nickname  = odDT.Rows[i]["nickname"].ToString();
                        orderentity.fruittype = odDT.Rows[i]["fruittype"].ToString();
                        orderentity.date      = odDT.Rows[i]["startdate"].ToString();

                        orderentity.count          = odDT.Rows[i]["count"].ToString();
                        orderentity.deliveryaddr   = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.user           = odDT.Rows[i]["user"].ToString();
                        orderentity.mp             = odDT.Rows[i]["mp"].ToString();
                        orderentity.fruits         = odDT.Rows[i]["fruits"].ToString();
                        orderentity.deliverystatus = odDT.Rows[i]["deliverystatus"].ToString();
                        orderentity.ExpressNumber  = odDT.Rows[i]["ExpressNumber"].ToString();
                        orderentity.GiftCardCode   = odDT.Rows[i]["GiftCardCode"].ToString();
                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";
                    break;

                case "getcommunitydelivery":
                    querySQL = @"select 
tor.outtradeno as 'orderid',
tor.openid,
tu.nickname,
tor.fruittype,
tor.startdate,
tor.count,
tor.deliveryaddr,
tor.user,
tor.mp,
tor.deliverystatus,
GROUP_CONCAT(CONCAT(tof.name,tof.fruitNum * tof.count ,tof.unit ) ) as 'fruits',
tor.GiftCardCode,
tor.ExpressNumber,
tor.actualprice,
tor.status,
tor.agencylevel,
tor.discount,
tor.rebate
from t_order tor
inner join t_orderfruts tof
on tof.orderid=tor.orderid and  tor.status in('PaidSuccessed','Completed','NotPaid') and fruittype like '%社区%'
inner join t_user tu
on tu.openid=tor.openid
group by
tor.outtradeno
order by startdate
";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.orderid   = odDT.Rows[i]["orderid"].ToString();
                        orderentity.openid    = odDT.Rows[i]["openid"].ToString();
                        orderentity.nickname  = odDT.Rows[i]["nickname"].ToString();
                        orderentity.fruittype = odDT.Rows[i]["fruittype"].ToString();
                        orderentity.date      = odDT.Rows[i]["startdate"].ToString();

                        orderentity.count          = odDT.Rows[i]["count"].ToString();
                        orderentity.deliveryaddr   = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.user           = odDT.Rows[i]["user"].ToString();
                        orderentity.mp             = odDT.Rows[i]["mp"].ToString();
                        orderentity.fruits         = odDT.Rows[i]["fruits"].ToString();
                        orderentity.deliverystatus = odDT.Rows[i]["deliverystatus"].ToString();
                        orderentity.ExpressNumber  = odDT.Rows[i]["ExpressNumber"].ToString();
                        orderentity.GiftCardCode   = odDT.Rows[i]["GiftCardCode"].ToString();
                        orderentity.actualprice    = odDT.Rows[i]["actualprice"].ToString();
                        orderentity.status         = odDT.Rows[i]["status"].ToString();
                        orderentity.agencylevel    = odDT.Rows[i]["agencylevel"].ToString();
                        orderentity.discount       = odDT.Rows[i]["discount"].ToString();
                        orderentity.rebate         = odDT.Rows[i]["rebate"].ToString();
                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";
                    break;

                case "getfruitsestimate":
                    querySQL = @"
select * from
(
select 
td.date,
tdf.name as fruits,
sum(tor.count*150) as count,
'g' as unit
 from t_order tor
inner join t_delivery td
on tor.orderid=td.orderid and tor.status='PaidSuccessed' and tor.fruittype<>'精品礼盒DIY'
inner join t_deliveryfruits tdf
on td.id=tdf.deliveryid
group by
td.date,
tdf.name 
union
select 
tor.startdate as 'date',
tof.name as fruits,
sum(tof.fruitNum * tof.count* tor.count) as 'count',
tof.unit
from t_order tor
inner join t_orderfruts tof
on tof.orderid=tor.orderid and  tor.status='PaidSuccessed' and fruittype='精品礼盒DIY'
inner join t_user tu
on tu.openid=tor.openid
group by
tor.startdate,
tof.name,
tof.unit
)T
order by date";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.date   = odDT.Rows[i]["date"].ToString();
                        orderentity.fruits = odDT.Rows[i]["fruits"].ToString();
                        orderentity.count  = odDT.Rows[i]["count"].ToString();
                        orderentity.unit   = odDT.Rows[i]["unit"].ToString();
                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";
                    break;

                case "getcommunityfruitsestimate":
                    querySQL = @"select * from
(
select 
tor.status,
tor.deliveryaddr,
tor.startdate as 'date',
tof.name as fruits,
sum(tof.fruitNum * tof.count* tor.count) as 'count',
tof.unit
from t_order tor
inner join t_orderfruts tof
on tof.orderid=tor.orderid and fruittype like '%社区%'
inner join t_user tu
on tu.openid=tor.openid
group by
tor.status,
tor.startdate,
tof.name,
tof.unit,
deliveryaddr
)T
order by date";
                    odDT     = MySqlHelp.ExecuteDataTable(querySQL);
                    for (int i = 0; i < odDT.Rows.Count; i++)
                    {
                        Entity.DeliveryReport orderentity = new Entity.DeliveryReport();
                        orderentity.date         = odDT.Rows[i]["date"].ToString();
                        orderentity.fruits       = odDT.Rows[i]["fruits"].ToString();
                        orderentity.count        = odDT.Rows[i]["count"].ToString();
                        orderentity.unit         = odDT.Rows[i]["unit"].ToString();
                        orderentity.deliveryaddr = odDT.Rows[i]["deliveryaddr"].ToString();
                        orderentity.status       = odDT.Rows[i]["status"].ToString();

                        _DeliveryReport.Add(orderentity);
                    }
                    result = "{\"result\":\"successed\",\"orders\":" + JsonUtility.ToJSONString(_DeliveryReport) + "}";
                    break;

                case "singledelivery":

                    DataTable checkdt = MySqlHelp.ExecuteDataTable(string.Format(@"update t_delivery set status='已配送' 
where id={0};
select 1 from t_order tor
inner join t_delivery td
on td.orderid=tor.orderid
where td.status='未配送' and tor.outtradeno='{1}'", deliveryid, orderid));
                    if (checkdt.Rows.Count <= 0)
                    {
                        MySqlHelp.ExecuteNonQuery("update t_order set status='Completed',statusid='3' where outtradeno=" + UtilityFn.formatstring(orderid));
                    }
                    result = "{\"result\":\"successed\"}";
                    break;

                case "bodelivery":
                    MySqlHelp.ExecuteNonQuery("update t_order set deliverystatus='已配送',status='Completed',statusid='3' where outtradeno=" + UtilityFn.formatstring(deliveryid));
                    result = "{\"result\":\"successed\"}";
                    break;

                case "changeexpressnumber":
                    var ExpressNumber = context.Request["ExpressNumber"];
                    MySqlHelp.ExecuteNonQuery("update t_order set ExpressNumber=" + UtilityFn.formatstring(ExpressNumber) + " where outtradeno=" + UtilityFn.formatstring(orderid));
                    result = "{\"result\":\"successed\"}";

                    break;

                default:
                    break;
                }
            }
            context.Response.Write(result);
        }
示例#3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string code = context.Request.QueryString["code"];

            context.Response.AddHeader("Access-Control-Allow-Origin", "*");

            //context.Response.Write("AuthorizationCheckByCodeHandler:" + code);
            string RedirectPage = "";
            string returnresult = "{\"result:\":\"{0}\",\"RedirectPage\":\"{1}\"}";

            try
            {
                //构造获取openid及access_token的url
                WxPayData data = new WxPayData();
                data.SetValue("appid", WxPayConfig.APPID);
                data.SetValue("secret", WxPayConfig.APPSECRET);
                data.SetValue("code", code);
                data.SetValue("grant_type", "authorization_code");
                string url = "https://api.weixin.qq.com/sns/oauth2/access_token?" + data.ToUrl();
                Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode url : " + url);
                //请求url以获取数据
                string result = HttpService.Get(url);

                Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode response : " + result);

                //保存access_token,用于收货地址获取
                JsonData jd = JsonMapper.ToObject(result);
                Log.Debug(this.GetType().ToString(), "GetOpenidAndAccessTokenFromCode Result : " + result);
                var access_token = (string)jd["access_token"];
                //Response.Write(result);

                //获取用户openid
                var       openid       = (string)jd["openid"];
                WxPayData dataUserInfo = new WxPayData();
                dataUserInfo.SetValue("access_token", access_token);
                dataUserInfo.SetValue("openid", openid);

                DataTable checkuserDT = MySqlHelp.ExecuteDataTable(@"select tu.*
,
CASE
WHEN  la.agencylevel is null THEN 'L0'
ELSE la.agencylevel
END as 'agencylevel',
CASE
WHEN  la.agencylevel is null THEN '1'
ELSE la.discount
END as 'discount'
from t_user tu
left join t_agencylevel la
on tu.id=la.userid and la.enabled='1'
where tu.openid=" + UtilityFn.formatstring(openid));

                //数据库里是否有用户信息
                if (checkuserDT.Rows.Count > 0)
                {
                    if (FormatWeXUser(checkuserDT, context))
                    {
                        var ActionPage = context.Request.QueryString["ActionPage"];
                        if (!string.IsNullOrEmpty(ActionPage))
                        {
                            //Response.Redirect(ActionPage, false);
                            RedirectPage = ActionPage;
                        }
                        else
                        {
                            //Response.Redirect("home.aspx", false);
                            RedirectPage = "home.aspx";
                        }
                    }
                    else
                    {
                        //Response.Redirect("/Order/MyInfoPage.aspx", false);
                        RedirectPage = "/Order/MyInfoPage.aspx";
                    }
                    //Log.Info("Get User End", "=========" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));

                    //Response.Redirect("home.aspx", false);
                }
                else
                {
                    //Response.Redirect("login.aspx", false);
                    RedirectPage = "login.aspx";
                }


                //Response.Write(result);

                //Log.Debug(this.GetType().ToString(), "Get openid : " + openid);
                //Log.Debug(this.GetType().ToString(), "Get access_token : " + access_token);

                context.Response.Write("{\"result:\":\"success\",\"RedirectPage\":\"" + RedirectPage + "\"}");
            }
            catch (Exception ex)
            {
                Log.Error(this.GetType().ToString(), ex.ToString());
                //throw new WxPayException(ex.ToString());
                context.Response.Write("{\"result:\":\"failed\",\"RedirectPage\":\"\"}");
            }
        }