コード例 #1
0
        //確認退款單---執行之前的歸檔邏輯但是除去更新庫存的操作
        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;
        }
コード例 #2
0
        /// <summary>
        /// hg_batch_deduct_refund表,hg_batch_accumulate_refund表結構一模一樣
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public string hg_batch_deduct_refund(HgBatchAccumulateRefund query)
        {
            StringBuilder sql = new StringBuilder();
            //要改**////////////////
            try
            {
                sql.AppendFormat("insert into hg_batch_deduct_refund(order_id,head,card_no,card_checksum,enc_idno,");
                sql.AppendFormat("checksum,merchant_pos,terminal_pos,refund_point,category_id, ");
                sql.AppendFormat("order_note,wallet,batch_error_code,batch_status,");
                sql.AppendFormat("created_time,modified_time,billing_checked,transaction_time,batch_import_time)");
                sql.AppendFormat("values('{0}','{1}','{2}','{3}','{4}',", query.order_id, query.head, query.card_no, query.card_checksum, query.enc_idno);
                sql.AppendFormat("'{0}','{1}','{2}','{3}','{4}',", query.checksum, query.merchant_pos, query.terminal_pos, query.refund_point, query.category_id);
                sql.AppendFormat("'{0}','{1}','{2}','{3}',", "吉甲地台灣好市集訂單編號" + query.order_id + "返還" + query.refund_point + "點", query.wallet, query.batch_error_code, query.batch_status);
                sql.AppendFormat("'{0}','{1}',{2},'{3}','{4}');", CommonFunction.DateTimeToString(DateTime.Now), CommonFunction.DateTimeToString(DateTime.Now), query.billing_checked, CommonFunction.DateTimeToString(DateTime.Now), CommonFunction.DateTimeToString(DateTime.Now));
            }
            catch (Exception ex)
            {
                throw new Exception("OrderReturnStatusDao-->hg_batch_deduct_refund-->" + sql.ToString() + ex.Message, ex);
            }

            return sql.ToString();
        }