public DataTable CheckOrderId(OrderReturnStatusQuery query)
 {
     try
     {
         return _orderReturnStatus.CheckOrderId(query);
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusMgr-->CheckOrderId-->" + ex.Message, ex);
     }
 }
 public DataTable CheckTransport(OrderReturnStatusQuery query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         query.Replace4MySQL();
         sql.AppendFormat("select orc.orc_deliver_code from order_return_content orc   where orc.orc_order_id='{0}' and return_id='{1}' ; ", query.orc_order_id,query.return_id);
         DataTable _dt = _access.getDataTable(sql.ToString());
         return _dt;
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusDao-->CheckTransport-->" + ex.Message + sql.ToString(), ex);
     }
 }
        public DataTable CheckOrderId(OrderReturnStatusQuery query)
        {
            StringBuilder sql = new StringBuilder();
            try
            {
                query.Replace4MySQL();
                sql.AppendFormat("select ors.ors_status from order_return_status ors   where ors.ors_order_id='{0}'  and return_id='{1}' order by ors_status desc; ", query.ors_order_id, query.return_id);
                DataTable _dt = _access.getDataTable(sql.ToString());
                return _dt;

            }
            catch (Exception ex)
            {
                throw new Exception("OrderReturnStatusDao-->CheckOrderId-->" + ex.Message + sql.ToString(), ex);
            }

        }
        //確認退款單---執行之前的歸檔邏輯但是除去更新庫存的操作
        public bool CouldReturnMoney(OrderReturnStatusQuery query)
        {
            StringBuilder sql = new StringBuilder();
            ArrayList arrList = new ArrayList();
            try
            {
                arrList.Add(CouldReturn(query));
                arrList.Add(UpOrderReturnMaster(query));
                HgBatchAccumulateRefund hgBatch = new HgBatchAccumulateRefund();
               HGLogin hgLogin = GetHGLoginData((uint)query.ors_order_id);
                OrderMaster om = _ordermasterdao.GetOrderMasterByOrderId4Change(Convert.ToInt32(query.ors_order_id));
                DataTable _returnDt = GetReturnId(query);
                DataTable odli = _orderDetailDao.OrderDetailTable(Convert.ToUInt32(query.return_id),0);
                OrderReturnMasterQuery omQuery = new OrderReturnMasterQuery();
                SerialDao serialDao = new SerialDao(connStr);
                MySqlCommand mySqlCmd = new MySqlCommand();
                MySqlConnection mySqlConn = new MySqlConnection(connStr);
                if (odli != null)
                {
                    #region hg個字段賦值
                    if (hgLogin != null)
                    {
                        #region hg_batch_accumulate_refund
                        hgBatch.order_id = (uint)query.ors_order_id;
                        hgBatch.head = "B";
                        hgBatch.card_no = ""; 
                        hgBatch.card_checksum = ""; 
                        hgBatch.category_id = "N0699999";
                        hgBatch.wallet = "991991"; 
                        hgBatch.enc_idno = hgLogin.enc_idno;
                        hgBatch.checksum = hgLogin.chk_sum;
                        hgBatch.transaction_time = hgLogin.transaction_time;
                        hgBatch.merchant_pos = hgLogin.merchant_pos;
                        hgBatch.terminal_pos = hgLogin.terminal_pos;
                        hgBatch.refund_point = om.Deduct_Happygo;
                        //hgBatch.order_note = "吉甲地台灣好市集訂單編號" + hgBatch.order_id + "返還" + hgBatch.refund_point + "點";
                        //吉甲地台灣好市集訂單編號131210039累點取消4點
                        hgBatch.batch_status = 0;
                        hgBatch.billing_checked = 0;
                       // hgBatch.batch_import_time = Convert.ToInt32(CommonFunction.GetPHPTime());
                        #endregion
                    }

                    #endregion
                    int paymoney = 0;
                    int returnmoney = 0;
                    int deductbonus = 0;
                    int deductcash = 0;
                    int accumulated_bonus = 0;
                    int accumulated_happygo = 0;
                    int deduct_happygo = 0;
                    int deduct_happygo_money = 0;
                    #region 退款金額 = 商品購買金額 - 購物金
                    foreach (DataRow od in odli.Rows)
                    {
                        // 退款金額 = 商品購買金額 - 購物金
                        paymoney += (Convert.ToInt32(od["single_money"]) * Convert.ToInt32(od["buy_num"]));
                        deductbonus += Convert.ToInt32(od["deduct_bonus"]);
                        deductcash += Convert.ToInt32(od["deduct_welfare"]);
                        accumulated_bonus += Convert.ToInt32(od["accumulated_bonus"]);
                        accumulated_happygo += Convert.ToInt32(od["accumulated_happygo"]);
                        deduct_happygo += Convert.ToInt32(od["deduct_happygo"]);
                        deduct_happygo_money += Convert.ToInt32(od["deduct_happygo_money"]);
                    }
                    returnmoney += paymoney - (deductbonus + deductcash + deduct_happygo_money);//計算應退還的money
                    #endregion
                    #region 判斷是否有付款
                    if (om.Money_Collect_Date > 0 && om.Order_Amount > 0 && returnmoney > 0)
                    {
                        #region 新增退款單
                        string serial_sql = serialDao.Update(46);//46 退款單流水號
                        DataTable _moneyDt = GetMoneyIDBySerial(serial_sql);
                        uint moneyId = Convert.ToUInt32(_moneyDt.Rows[0][0]);
                        OrderMoneyReturn omr = new OrderMoneyReturn();
                        omQuery.order_id = Convert.ToUInt32(query.ors_order_id);
                        omr.money_type = om.Order_Payment;
                        omr.money_total = Convert.ToUInt32(returnmoney);
                        omr.money_status = 0;
                        omr.money_source = "return_id:" + query.return_id;
                        omr.money_id = moneyId;
                        omQuery.return_ipfrom = "";
                        omQuery.bank_name = query.bank_name;
                        omr.bank_branch = query.bank_branch;
                        omr.bank_account = query.bank_account;
                        omr.account_name = query.account_name;
                        omr.bank_note = query.bank_note;
                        string insertSql = _orderMoneyReturnDao.InsertSql(omQuery, omr);

                        arrList.Add(insertSql);
                        #endregion
                        //取回給予的購物金與happygo點數
                        if (accumulated_bonus > 0)
                        {
                            Deduct_User_Bonus(accumulated_bonus, om);
                        }
                        //扣除給予會員的hg點數
                        if (accumulated_happygo > 0)
                        {
                         
                            //插入hg_batch_accumulate_refund
                           
                             arrList.Add(hg_batch_accumulate_refund(hgBatch));
                          
                        }
                    }
                    #endregion
                    #region 黑貓例外處理
                    //黑貓例外處理
                    if (om.Money_Collect_Date == 0 && om.Order_Payment == 8)
                    {
                        //扣除給予會員的購物金
                        if (accumulated_bonus > 0)
                        {
                            Deduct_User_Bonus(accumulated_bonus, om);
                        }
                        //扣除給予會員的hg點數
                        if (accumulated_happygo > 0)
                        {
                            //插入hg_batch_accumulate_refund
                            
                            arrList.Add(hg_batch_accumulate_refund(hgBatch));
                            
                        }
                    }
                    #endregion
                    //寫入付款單退款金額
                    arrList.Add(_ordermasterdao.UpdateMoneyReturn(returnmoney, om.Order_Id));
                    //退回購買扣抵的hp點數
                    #region 判斷退回購買扣抵的hp點數  判斷是否要退回購物金
                    if (deduct_happygo > 0)
                    {
                        //插入hg_deduct_refund
                        arrList.Add(hg_batch_deduct_refund(hgBatch));
                    }
                    if (deductbonus > 0)
                    {
                        Deduct_Refund(om, deductbonus, 0, 0, omQuery);
                    }
                    if (deductcash > 0)
                    {
                        Deduct_Refund(om, 0, deductcash, 0, omQuery);
                    }
                    #endregion
                    DataTable _dt = GetTotalCount(om.Order_Id, 1);
                    if (Convert.ToInt32(_dt.Rows[0][0]) == 0)
                    {
                        if (om.Priority == 1)
                        {
                            arrList.Add(UpdatePriority(om.Order_Id));
                            arrList.Add(UpdateFirstTime(om.user_id));
                        }
                    }
                    DataTable _dt2 = GetTotalCount(om.Order_Id, 2);
                    #region  更改推薦
                    if (Convert.ToInt32(_dt2.Rows[0][0]) == 0)
                    {
                        List<UserRecommend> usRecommandLi = _userRecommendDao.QueryByOrderId(om.Order_Id);
                        string idStr = string.Empty;
                        if (usRecommandLi.Count != 0)
                        {
                            foreach (var record in usRecommandLi)
                            {
                                idStr += "," + record.id;
                            }
                             idStr=  idStr.TrimStart(',');
                            arrList.Add(_userRecommendDao.UpdateIsCommend(idStr));
                        }
                    }
                    #endregion
                    if (_mySqlDao.ExcuteSqlsThrowException(arrList))
                    {
                        return true;
                    }
                    else {
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("OrderReturnStatusDao-->CouldReturnMoney-->" + ex.Message, ex);
            }
            return true;
        }
        //更新庫存的操作
        public bool PlaceOnFile(OrderReturnStatusQuery query)
        {
            //選中要退的商品進行入庫,未選中的則不入庫,將未選中的記錄到order_return_status里
            try
            {
                bool b = true;
                ArrayList arrList = new ArrayList();
              
                if (query.ors_status == 3)
                {
                    List<OrderReturnStatusQuery> ORStore = new List<OrderReturnStatusQuery>();

                    if (query.data != "")
                    {
                        string[] dataSplit = query.data.Split(';');
                        for (int i = 0; i < dataSplit.Length; i++)
                        {
                            if (dataSplit[i] != "")
                            {
                                string[] newData = dataSplit[i].Split('*');
                                query.item_id = Convert.ToUInt32(newData[0]);
                                query.itemStr += query.item_id + ",";
                                query.buy_num = Convert.ToUInt32(newData[1]);
                                DataTable odli = _orderDetailDao.OrderDetailTable(Convert.ToUInt32(query.return_id), query.item_id);
                                if (Convert.ToInt32(odli.Rows[0]["item_mode"]) == 1)//组合商品
                                {
                                    List<OrderDetail> childDetail = Get_Combined_Product(Convert.ToUInt32(query.ors_order_id), Convert.ToUInt32(odli.Rows[0]["Parent_Id"]), Convert.ToUInt32(odli.Rows[0]["pack_id"]));
                                    foreach (var child in childDetail)
                                    {
                                        arrList.Add(_itemDao.UpdateItemStock(child.Item_Id, child.Buy_Num * child.parent_num));//更新庫存
                                    }
                                }
                                else
                                {
                                    arrList.Add(_itemDao.UpdateItemStock(query.item_id, query.buy_num));//更新庫存
                                }
                            }
                        }
                    }
                        int totalCount = 0;
                        query.IsPage = false;
                        query.itemStr = query.itemStr.TrimEnd(',');
                       // query.nonSelected = true;
                        ORStore = CouldGridList(query, out totalCount);
                        query.itemStr = string.Empty;
                        foreach (var item in ORStore)
                        {
                            query.itemStr += item.item_id + ",";
                        }
                        if (query.itemStr != "")
                        {
                            query.ors_remark = "未入庫的商品細項編號為:" + query.itemStr.TrimEnd(',');
                        }
                    arrList.Add(CouldReturn(query));
                }
                if (_mySqlDao.ExcuteSqlsThrowException(arrList))
                {
                    b = true;
                }
                else
                {
                    b = false;
                }
                return b;
            }
            catch (Exception ex)
            {
                throw new Exception("OrderReturnStatusDao-->PlaceOnFile-->" + ex.Message, ex);
            }

        }
        public List<OrderReturnStatusQuery> CouldGridList(OrderReturnStatusQuery query, out int totalCount)
        {
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlFrom = new StringBuilder();
            StringBuilder sqlWhere = new StringBuilder();
            StringBuilder sqlCount = new StringBuilder();
            try
            {
                totalCount = 0;
                sql.Append("select orm.order_id,od.item_id,od.product_name,para.parameterName as 'product_mode',od.product_spec_name,od.buy_num,od.single_money ,om.order_payment,orm.bank_name,orm.bank_branch,orm.bank_account,orm.account_name,orm.bank_note  ");
                sqlFrom.Append(" from order_return_master  orm  LEFT JOIN order_return_detail ord on orm.return_id=ord.return_id ");
                sqlFrom.Append("LEFT JOIN order_detail  od on ord.detail_id=od.detail_id ");
                sqlFrom.Append(" LEFT JOIN (select parameterCode,parameterName,remark from t_parametersrc where parametertype='product_mode') para on od.product_mode=para.parameterCode  ");
                sqlFrom.Append(" LEFT JOIN order_master om on om.order_id = orm.order_id ");
                sqlWhere.AppendFormat(" where orm.return_id='{0}'  ", query.return_id);
                if (query.itemStr!="")
                {
                    sqlWhere.AppendFormat(" and od.item_id not in({0}) ",query.itemStr);
                }
                if (query.IsPage)
                {
                    DataTable _dt = _access.getDataTable("select count(orm.order_id) as 'totalCount'  " + sqlFrom.ToString() + sqlWhere.ToString());
                    if (_dt != null)
                    {
                        totalCount = Convert.ToInt32(_dt.Rows[0][0]);
                    }
                }
                sqlWhere.AppendFormat(" limit {0},{1}; ", query.Start, query.Limit);
                sql.Append(sqlFrom.ToString() + sqlWhere.ToString());
                return _access.getDataTableForObj<OrderReturnStatusQuery>(sql.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("OrderReturnStatusDao-->CouldGridList-->" + sql.ToString() + ex.Message, ex);
            }

        }
 public string CouldReturn(OrderReturnStatusQuery query)
 {
     string json = string.Empty;
    // List<OrderReturnStatusQuery> store = new List<OrderReturnStatusQuery>();
     ArrayList arrList = new ArrayList();
     try
     {
         //int totalCount = 0;
         //query.IsPage = false;
         //store= _orderReturnStatus.CouldGridList(query, out   totalCount);
       
        //   int modeCount = 0;
         //foreach (var item in store)
         //{
         //    if (item.product_mode =="自出")
         //    {
         //        modeCount++;
         //    }
         //}
         //if (modeCount ==store.Count)
         //{
         //    //全是自出
         //    query.ors_status = 4;
         //    arrList.Add(_orderReturnStatus.CouldReturn(query));
         //}
             //不全是自出
         arrList.Add(_orderReturnStatus.UpdateORM(query));
         arrList.Add(_orderReturnStatus.CouldReturn(query));
         if (_mysql.ExcuteSqlsThrowException(arrList))
         {
             json = "{success:true}";
         }
         else
         {
             json = "{success:false}";
         }
         return json;
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusMgr-->CouldReturn-->" + ex.Message, ex);
     }
 }
 public HttpResponseBase CouldGridList()
 {
     string json = string.Empty;
     try
     {
         _orderReturnStatus = new OrderReturnStatusMgr(mySqlConnectionString);
         OrderReturnStatusQuery query = new OrderReturnStatusQuery();
         List<OrderReturnStatusQuery> store = new List<OrderReturnStatusQuery>();
         query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
         query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25");
         if (!string.IsNullOrEmpty(Request.Params["return_id"]))
         {
             query.return_id = Convert.ToUInt32(Request.Params["return_id"]);
             query.ors_order_id = _orderReturnStatus.GetOrderIdByReturnId(query.return_id);
         }
  
         int totalCount = 0;
         store = _orderReturnStatus.CouldGridList(query, out totalCount);
         json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, Formatting.Indented) + "}";//返回json數據
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:true,totalCount:0,data:[]}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
        public HttpResponseBase CheckOrderId()
        {
            string json = string.Empty;
            OrderReturnStatusQuery query = new OrderReturnStatusQuery();
            DataTable _dt = new DataTable();
            DataTable _tranDt = new DataTable();
            List<OrderReturnStatusQuery> store = new List<OrderReturnStatusQuery>();
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["return_id"]))
                {
                    query.return_id =   Convert.ToUInt32(Request.Params["return_id"]);
                    //如果ors_order_id為0則證明return_id不存在
                    _orderReturnStatus = new OrderReturnStatusMgr(mySqlConnectionString);
                    query.ors_order_id = _orderReturnStatus.GetOrderIdByReturnId(query.return_id);
                    query.orc_order_id = query.ors_order_id;

                    //add 歸檔取消退貨的商品 直接告知不再繼續往下
                    if (query.ors_order_id == 0)
                    {
                        json = "{success:true,status:'-1'}";
                    }
                    else
                    {
                        _dt = _orderReturnStatus.CheckOrderId(query);
                        _tranDt = _orderReturnStatus.CheckTransport(query);
                        int totalCount = 0;
                        query.IsPage = false;

                        store = _orderReturnStatus.CouldGridList(query, out totalCount);
                        if (_dt != null && _dt.Rows.Count > 0)
                        {
                            if (Convert.ToInt32(_dt.Rows[0][0]) == 2 || Convert.ToInt32(_dt.Rows[0][0]) == 3 || Convert.ToInt32(_dt.Rows[0][0]) == 4)
                            {
                                json = "{success:true,status:'" + Convert.ToInt32(_dt.Rows[0]["ors_status"]) + "',order_payment:'" + store[0].order_payment + "',bank_name:'" + store[0].bank_name + "',bank_branch:'" + store[0].bank_branch + "',bank_account:'" + store[0].bank_account + "',account_name:'" + store[0].account_name + "',bank_note:'" + store[0].bank_note + "' }";
                            }
                            else if (_tranDt == null || _tranDt.Rows[0][0].ToString() == "")
                            {
                                json = "{success:true,status:'0.5'}";
                            }
                            else
                            {
                                if (Convert.ToInt32(_dt.Rows[0]["ors_status"]) == 2)//此時需要點擊確認入庫
                                {

                                    json = "{success:true,status:'" + Convert.ToInt32(_dt.Rows[0]["ors_status"]) + "'}";
                                }
                                else
                                {
                                    json = "{success:true,status:'" + Convert.ToInt32(_dt.Rows[0]["ors_status"]) + "'}";
                                }
                            }
                        }
                        else
                        {
                            OrderMaster om = _orderReturnStatus.GetOrderInfo(Convert.ToUInt32(query.return_id));
                            string delivery_name = "***";
                            string delivery_mobile = "***";
                            string delivery_address = "***";
                            if (!string.IsNullOrEmpty(om.Delivery_Name))
                            {
                                delivery_name = om.Delivery_Name.Substring(0, 1) + "**";
                            }
                            if (!string.IsNullOrEmpty(om.Delivery_Mobile))
                            {
                                if (!CommonFunction.isMobile(om.Delivery_Mobile))
                                {
                                    if (om.Delivery_Mobile.ToString().Length == 48)
                                    {
                                        om.Delivery_Mobile = EncryptComputer.EncryptDecryptTextByApi(om.Delivery_Mobile, false);
                                        if (!CommonFunction.isMobile(om.Delivery_Mobile))
                                        {
                                            //異常記錄
                                            Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                            logMessage.Content = string.Format("表名:{0},訂單編號:{1},行動電話:{2},Message:{3}", "order_master", query.orc_order_id, om.Delivery_Mobile, "訂購人行動電話解密后不滿足正則表達式");
                                            logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                            log.Error(logMessage);
                                        }
                                    }
                                    else
                                    {
                                        //異常記錄
                                        Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                        logMessage.Content = string.Format("表名:{0},訂單編號:{1},行動電話:{2},Message:{3}", "order_master", query.orc_order_id, om.Delivery_Mobile, "訂購人行動電話錯誤");
                                        logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                        log.Error(logMessage);
                                    }
                                }
                                if (om.Delivery_Mobile.ToString().Length > 3)
                                {
                                    om.Delivery_Mobile = om.Delivery_Mobile.Substring(0, 3) + "***";
                                }
                                else
                                {
                                    om.Delivery_Mobile = om.Delivery_Mobile + "***";
                                }
                            }
                            if (!string.IsNullOrEmpty(om.Delivery_Address))
                            {
                                if (om.Delivery_Address.Length > 3)
                                {
                                    delivery_address = om.Delivery_Address.Substring(0, 3) + "**";
                                }
                                else
                                {
                                    delivery_address = om.Delivery_Address + "***";
                                }
                            }
                            json = "{success:true,name:'" + delivery_name + "',mobile:'" + delivery_mobile + "',address:'" + delivery_address + "',zipcode:'" + om.Delivery_Zip + "',status:'0',bank_note:'" + store[0].bank_note + "'}";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
 public string InsertOrderReturnContent(OrderReturnStatusQuery query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("insert into order_return_content(orc_order_id,orc_deliver_code,orc_deliver_date,orc_deliver_time,orc_name,orc_mobile,orc_zipcode,orc_address,orc_remark,orc_type,orc_service_remark,return_id,orc_send) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');", query.orc_order_id, query.orc_deliver_code, CommonFunction.DateTimeToString(query.orc_deliver_date), query.orc_deliver_time, query.orc_name, query.orc_mobile, query.orc_zipcode, query.orc_address, query.orc_remark, query.orc_type, query.orc_service_remark, query.return_id, query.orc_send);
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusDao-->InsertOrderReturnContent-->" + ex.Message + sql.ToString(), ex);
     }
 }
 public string InsertTransport(OrderReturnStatusQuery query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("set sql_safe_updates = 0;update order_return_content set orc_deliver_date='{0}' ,orc_deliver_time='{1}',orc_deliver_code='{2}' where orc_order_id='{3}' and return_id='{4}' ;set sql_safe_updates=1;", CommonFunction.DateTimeToString(query.orc_deliver_date), query.orc_deliver_time, query.orc_deliver_code, query.orc_order_id,query.return_id);
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusDao.InsertTransport-->" + ex.Message + sql.ToString(), ex);
     }
 }
      public string SaveOrderReturn(OrderReturnStatusQuery query)
      {
          string json = string.Empty;
          try
          {
              ArrayList arrList = new ArrayList();
              bool zichu = false;
              query.ors_createdate = DateTime.Now;
              if (query.orc_name.IndexOf("*")>0)
              {
                  OrderMaster om = _orderReturnStatus.GetOrderInfo(Convert.ToUInt32(query.orc_order_id));
                  query.orc_name = om.Delivery_Name;
                  query.orc_mobile = om.Delivery_Mobile;
                  query.orc_address = om.Delivery_Address;
              }
              arrList.Add(_orderReturnStatus.InsertOrderReturnContent(query));
              arrList.Add(_orderReturnStatus.InsertOrderReturnStatus(query));
              arrList.Add(_orderReturnStatus.UpdateORM(query));
              //產看要退的商品是不是都是自出
              List<OrderReturnStatusQuery> store = new List<OrderReturnStatusQuery>();
              int totalCount = 0;
              query.IsPage = false;
              store = _orderReturnStatus.CouldGridList(query, out   totalCount);
              int modeCount = 0;
              foreach (var item in store)
              {
                  if (item.product_mode == "自出")
                  {
                      modeCount++;
                  }
              }
              if (modeCount == store.Count)
              {
                  //全是自出
                  zichu = true;
                  query.ors_status = 3;
                  arrList.Add(_orderReturnStatus.CouldReturn(query));
              }
              else
              {
                  if (query.orc_send == 0)//未發貨,寄倉/調度則在客戶信息填完之後,就確認入庫
                  {
                      query.ors_status = 2;
                      arrList.Add(_orderReturnStatus.CouldReturn(query));
                  }
              }

              if (_orderReturnStatus.ExecSqls(arrList))
              {
                  if (zichu)
                  {
                      json = "{success:true,isZIChu:'1',}";
                  }
                  else
                  {
                      json = "{success:true}";
                  }
              }
              else
              {
                  json = "{success:false}";
              }
              return json;
          }
          catch (Exception ex)
          {
              throw new Exception("OrderReturnStatusMgr-->SaveOrderReturn-->" + ex.Message, ex);
          }
      }
 //確認入庫,更新庫存
 public string PlaceOnFile(OrderReturnStatusQuery query)
 {
     string json = string.Empty;
     try
     {
         if (_orderReturnStatus.PlaceOnFile(query))
         {
             json = "{success:true}";
         }
         else
         {
             json = "{success:false}";
         }
         return json;
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusDao-->PlaceOnFile-->" + ex.Message, ex);
     }
 }
 public string CouldReturnMoney(OrderReturnStatusQuery query)
 {
     string json = string.Empty;
     try
     {
         if (_orderReturnStatus.CouldReturnMoney(query))
         {
             json = "{success:true}";
         }
         else
         {
             json = "{success:false}";
         }
         return json;
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusMgr-->CouldReturnMoney-->" + ex.Message, ex);
     }
 }
      public string InsertTransport(OrderReturnStatusQuery query)
      {
          string json = string.Empty;
          try
          {
              ArrayList arrList = new ArrayList();
              arrList.Add(_orderReturnStatus.InsertTransport(query));
              arrList.Add(_orderReturnStatus.UpdateORS(query));//由於邏輯變更,此處為想order_return_status表裏插入數據
              if (_mysql.ExcuteSqlsThrowException(arrList))
              {
                  json = "{success:'true',msg:'1'}";
              }
              else
              {
                  json = "{success:'false'}";
              }
              return json;
          }
          catch (Exception ex)
          {
              throw new Exception("OrderReturnStatusMgr-->InsertTransport-->" + ex.Message, ex);
 
          }
      }
        public DataTable GetReturnId(OrderReturnStatusQuery query)
        {
            StringBuilder sql = new StringBuilder();
            try
            {
                sql.AppendFormat("select return_id from order_return_master where order_id='{0}';", query.ors_order_id);
                return _access.getDataTable(sql.ToString());
            }
            catch (Exception ex)
            {
                throw new Exception("OrderReturnStatusDao-->GetReturnId-->" + ex.Message + sql.ToString(), ex);
            }

        }
 public string UpdateORM(OrderReturnStatusQuery query)
 {
     StringBuilder sql = new StringBuilder();
     StringBuilder sql1 = new StringBuilder();
     try
     {
         sql.AppendFormat("update order_return_master  set ");
         if (query.invoice_deal == 0 && query.ormpackage != 0)
         {
             sql1.AppendFormat("   package='{0}' ", query.ormpackage);
         }
         else   if (query.invoice_deal != 0 && query.ormpackage == 0)
         {
             sql1.AppendFormat(" invoice_deal='{0}'  ", query.invoice_deal);
         }
         if (query.bank_note != "")
         {
             if (sql1.Length > 1)
             {
                 sql1.Append(",");
             }
             sql1.AppendFormat(" bank_note='{0}'  ", query.bank_note);
         }
         sql1.AppendFormat(" where return_id='{0}'; ", query.return_id);
         sql.Append(sql1.ToString());
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusDao-->UpdateORM-->" + sql.ToString() + ex.Message, ex);
     }
 }
 public string CouldReturn(OrderReturnStatusQuery query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("insert into order_return_status(ors_order_id,ors_status,ors_remark,ors_createdate,ors_createuser,return_id) values('{0}','{1}','{2}','{3}','{4}','{5}');", query.ors_order_id, query.ors_status, query.ors_remark, CommonFunction.DateTimeToString(DateTime.Now), query.ors_createuser, query.return_id);
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusDao-->CouldReturn-->" + sql.ToString() + ex.Message, ex);
     }
 }
 public HttpResponseBase SaveOrderStatus()
 {
     OrderReturnStatusQuery query = new OrderReturnStatusQuery();
     string json = string.Empty;
     try
     {
         _orderReturnStatus = new OrderReturnStatusMgr(mySqlConnectionString);
         if (!string.IsNullOrEmpty(Request.Params["orc_name"]))
         {
             query.orc_name = (Request.Params["orc_name"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["return_id"]))
         {
             query.return_id = Convert.ToUInt32(Request.Params["return_id"]);
             query.orc_order_id = _orderReturnStatus.GetOrderIdByReturnId(query.return_id);
             query.ors_order_id = query.orc_order_id;
         }
         if (!string.IsNullOrEmpty(Request.Params["orc_mobile"]))
         {
             query.orc_mobile = Request.Params["orc_mobile"];
             //變更電話需加密 後期解除注視
             //if (!CommonFunction.isMobile(Request.Params["orc_mobile"]))
             //{
             //    //異常記錄
             //    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
             //    logMessage.Content = string.Format("表名:{0},退貨編號:{1},行動電話:{2},Message:{3}", "order_return_content", query.return_id, Request.Params["orc_mobile"], "退貨狀態查詢行動電話不滿足正則表達式");
             //    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
             //    log.Error(logMessage);
             //}
             //else { 
             //    //加密電話
             //    query.orc_mobile = EncryptComputer.EncryptDecryptTextByApi(Request.Params["orc_mobile"]);
             //}
         }
         if (!string.IsNullOrEmpty(Request.Params["orc_zipcode"]))
         {
             query.orc_zipcode = (Request.Params["orc_zipcode"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["orc_address"]))
         {
             query.orc_address = (Request.Params["orc_address"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["orc_type"]))
         {
             query.orc_type =Convert.ToInt32(Request.Params["orc_type"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["orc_service_remark"]))
         {
             query.orc_service_remark =  (Request.Params["orc_service_remark"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["orc_remark"]))
         {
             query.orc_remark = (Request.Params["orc_remark"]);
             query.ors_remark = (Request.Params["orc_remark"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["invoice_deal"]))
         {
             query.invoice_deal =Convert.ToInt32(Request.Params["invoice_deal"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["orc_send"]))
         {
             query.orc_send = Convert.ToInt32(Request.Params["orc_send"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["bank_note"]))
         {//退款諮詢添加到此
             query.bank_note = Request.Params["bank_note"];
         }
         
         query.ors_createuser = (Session["caller"] as Caller).user_id;
      
         json = _orderReturnStatus.SaveOrderReturn(query);
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:false}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
 public string UpOrderReturnMaster(OrderReturnStatusQuery query)
 {
     StringBuilder sql = new StringBuilder();
     StringBuilder sql1 = new StringBuilder();
     try
     {
         sql.AppendFormat("set sql_safe_updates = 0;update order_return_master set return_status=1,bank_name='{0}', bank_branch='{1}',bank_account='{2}',account_name='{3}' ", query.bank_name, query.bank_branch, query.bank_account, query.account_name);
         if (!String.IsNullOrEmpty(query.bank_note))
         {//add 如果退款備註不為空則更新
             sql1.AppendFormat(",bank_note='{0}' ", query.bank_note);
         }
         sql.Append(sql1.ToString());
         sql.AppendFormat(" where return_id='{0}';set sql_safe_updates = 1;", query.return_id);
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusDao-->UpOrderReturnMaster-->"+sql.ToString()+ex.Message,ex);
     }
 }
 //確認退款單
 public HttpResponseBase CouldReturnMoney()
 {
     string json = string.Empty;
     try
     {
         _orderReturnStatus = new OrderReturnStatusMgr(mySqlConnectionString);
         OrderReturnStatusQuery query = new OrderReturnStatusQuery();
         if (!string.IsNullOrEmpty(Request.Params["return_id"]))
         {
             query.return_id = Convert.ToUInt32(Request.Params["return_id"]);
             query.ors_order_id = _orderReturnStatus.GetOrderIdByReturnId(query.return_id);
         }
         if (!string.IsNullOrEmpty(Request.Params["bank_name"]))
         {
             query.bank_name =(Request.Params["bank_name"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["bank_branch"]))
         {
             query.bank_branch = (Request.Params["bank_branch"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["bank_account"]))
         {
             query.bank_account = (Request.Params["bank_account"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["account_name"]))
         {
             query.account_name = (Request.Params["account_name"]);
         }
         if (!string.IsNullOrEmpty(Request.Params["bank_note"]))
         {
             query.bank_note = (Request.Params["bank_note"]);
         }
         query.ors_status = 4;
         query.ors_createuser = (Session["caller"] as Caller).user_id;
         json = _orderReturnStatus.CouldReturnMoney(query);
     }
     catch (Exception ex)
     {
         Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
         logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
         logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
         log.Error(logMessage);
         json = "{success:false}";
     }
     this.Response.Clear();
     this.Response.Write(json);
     this.Response.End();
     return this.Response;
 }
      public List<OrderReturnStatusQuery> CouldGridList(OrderReturnStatusQuery query, out int totalCount)
      {
          try
          {
             return _orderReturnStatus.CouldGridList(query, out totalCount);
          }
          catch (Exception ex)
          {
              throw new Exception("OrderReturnStatusMgr-->CouldGridList-->" + ex.Message, ex);
          }

      }