/// <summary> /// 向 bonus_master 裱中 添加 一筆數據 /// </summary> /// <param name="br"></param> /// <returns></returns> public string AddBonusMaster(BonusMaster bm) { StringBuilder strSql = new StringBuilder(); try { StringBuilder master = new StringBuilder(); //獲取使用者電腦IP System.Net.IPAddress[] addlist = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList; string ip = string.Empty; if (addlist.Length > 0) { ip = addlist[0].ToString(); } strSql.Append(@"INSERT INTO bonus_master(master_id,user_id,type_id,master_total,master_balance,master_writer,master_start,master_end,master_createdate,master_updatedate,master_ipfrom,bonus_type) VALUES("); strSql.AppendFormat(@"{0},{1},{2},{3},{4},'{5}',", bm.master_id, bm.user_id, bm.type_id, bm.master_total, bm.master_balance, bm.master_writer); strSql.AppendFormat(@"{0},{1},{2},{3},'{4}',{5});", bm.master_start, bm.master_end, bm.master_createdate, bm.master_updatedate, ip, bm.bonus_type); return strSql.ToString(); } catch (Exception ex) { throw new Exception("BonusMasterDao-->AddBonusMaster(BonusMaster bm)-->" + strSql.ToString() + ex.Message, ex); } }
/// <summary> /// 根據 master_id 修改數據 /// </summary> /// <param name="br"></param> /// <returns></returns> public string UpdateBonusMasterBalance(BonusMaster bm) { StringBuilder strSql = new StringBuilder(); try { strSql.AppendFormat(@"SET sql_safe_updates = 0;UPDATE bonus_master SET master_balance = {0},master_updatedate = {1} where master_id = {2};SET sql_safe_updates = 1;", bm.master_balance, bm.master_updatedate, bm.master_id); return strSql.ToString(); } catch (Exception ex) { throw new Exception("BonusMasterDao-->UpdateBonusMasterBalance(BonusMaster bm)-->" + strSql.ToString() + ex.Message, ex); } }
public void Bonus_Master_Add(BonusMaster bm) { StringBuilder sql = new StringBuilder(); MySqlCommand mySqlCmd = new MySqlCommand(); SerialDao serialDao = new SerialDao(connStr); MySqlConnection mySqlConn = new MySqlConnection(connStr); try { if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Closed) { mySqlConn.Open(); } mySqlCmd.Connection = mySqlConn; mySqlCmd.Transaction = mySqlConn.BeginTransaction(); mySqlCmd.CommandType = System.Data.CommandType.Text; //type_id 4 // 訂單退回購物金 mySqlCmd.CommandText = CheckBonusTypeExist(4);//32代表 退貨產生的購物金 //判斷type_id是否存在 if (mySqlCmd.ExecuteScalar().ToString() == null) { mySqlCmd.Transaction.Rollback(); } // 限制不能為負值 if (bm.master_total < 0) { mySqlCmd.Transaction.Rollback(); } // 判斷日期 if (bm.master_start > bm.master_end) { mySqlCmd.Transaction.Rollback(); } // 取得下一個流水號 string master_sql= serialDao.Update(27);//27 購物金流水號 DataTable _dt = GetMasterID(master_sql); bm.master_id = Convert.ToUInt32(_dt.Rows[0][0]); mySqlCmd.CommandText += InsertBonusMaster(bm); mySqlCmd.ExecuteNonQuery(); mySqlCmd.Transaction.Commit(); } catch (Exception ex) { mySqlCmd.Transaction.Rollback(); throw new Exception("OrderReturnStatusDao-->Bonus_Master_Add-->" + ex.Message, ex); } finally { if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open) { mySqlConn.Close(); } } }
public string InsertBonusMaster(BonusMaster bm) { StringBuilder sql = new StringBuilder(); try { sql.AppendFormat(@"insert into bonus_master (master_id,user_id,type_id,master_total,master_balance,"); sql.AppendFormat(@"master_note,master_writer,master_start,master_end,master_createdate,master_updatedate,master_ipfrom,bonus_type)"); sql.AppendFormat(@" values('{0}','{1}','{2}','{3}','{4}',", bm.master_id, bm.user_id, bm.type_id, bm.master_total, bm.master_balance); sql.AppendFormat(@"'{0}','{1}','{2}','{3}','{4}',", bm.master_note, bm.master_writer, bm.master_start, bm.master_end, bm.master_createdate); sql.AppendFormat(@"'{0}','{1}','{2}')", bm.master_updatedate, bm.master_ipfrom, bm.bonus_type); return sql.ToString(); } catch (Exception ex) { throw new Exception("OrderReturnStatusDao.InsertBonusMaster-->" + ex.Message + sql.ToString(), ex); } }
public void Deduct_Refund(OrderMaster om, int deductbonus, int deductcash, int deducthg, OrderReturnMasterQuery query) { #region 購金 int expireDay = 90; BonusMaster bm = new BonusMaster(); bm.user_id = om.User_Id; bm.type_id = 4; bm.bonus_type = 1; DateTime master_start = DateTime.Now; bm.master_start = Convert.ToUInt32(CommonFunction.GetPHPTime(master_start.ToString("yyyy-MM-dd 00:00:00"))); bm.master_createdate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString())); bm.master_updatedate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString())); bm.master_ipfrom = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault().ToString(); bm.master_note = om.Order_Id.ToString(); bm.master_writer = "system"; if (deductbonus > 0) { List<VipUserGroup> vipuserLi = _vipuserGroupDao.GetVipUserByOrderId(om.User_Id, 0, 1); if (vipuserLi.Count!=0) { VipUserGroup vug = vipuserLi.FirstOrDefault(); expireDay = vug.bonus_expire_day; om.Accumulated_Bonus = om.Accumulated_Bonus * vug.bonus_rate; } #region BonusMaster Model bm.master_total = Convert.ToUInt32(deductbonus); bm.master_balance = Convert.ToInt32(deductbonus); DateTime master_end = master_start.AddDays(Convert.ToDouble(expireDay)); bm.master_end = Convert.ToUInt32(CommonFunction.GetPHPTime(master_end.ToString("yyyy-MM-dd 23:59:59"))); #endregion bm.master_writer = "訂單退貨返還購物金"; Bonus_Master_Add(bm); } #endregion #region 抵用券 if (deductcash > 0) { bm.bonus_type = 2; bm.master_total = Convert.ToUInt32(deductcash); bm.master_balance = Convert.ToInt32(deductcash); DateTime master_end = master_start.AddDays(Convert.ToDouble(expireDay)); bm.master_end = Convert.ToUInt32(CommonFunction.GetPHPTime(master_end.ToString("yyyy-MM-dd 23:59:59"))); bm.master_writer = "訂單退貨返還抵用券"; Bonus_Master_Add(bm); } #endregion #region HG點 if (deducthg > 0) { //hg_deduct_reverse(deducthg, om.Order_Id, query); } #endregion }
public string ChangePayMent(OrderMasterQuery query) { string json = string.Empty; ArrayList arrList = new ArrayList(); OrderMasterStatusQuery omsQuery = new OrderMasterStatusQuery(); OrderShowMasterQuery osmQuery = new OrderShowMasterQuery(); osmQuery = _orderMasterDao.GetData(query.Order_Id); try { if (query.payment == "T_CAT") { query.Order_Payment = 8; query.Order_Date_Pay = (uint)CommonFunction.GetPHPTime(); query.status_description = query.username + "轉黑貓貨到付款"; query.Delivery_Store = (uint)query.delivery; #region modify_order_status arrList.Add(_orderMasterDao.ModifyOrderStatus(query)); omsQuery.serial_id = Convert.ToUInt64(_orderMasterDao.GetNextSerial(new Serial { Serial_id = 29 }).Rows[0][0]); omsQuery.order_id = query.Order_Id; omsQuery.status_description = query.status_description; omsQuery.order_status = 2; omsQuery.status_ipfrom = query.Order_Ipfrom; query.user_id = osmQuery.user_id; arrList.Add(_orderMasterDao.OMSRecord(omsQuery)); DataTable _dt = _orderMasterDao.IsFirstTime(query); if (_dt != null && _dt.Rows.Count > 0) { arrList.Add(_orderMasterDao.UpFirstTime(query)); } #endregion //加30運費 if (osmQuery.order_freight_normal != 0) { query.Order_Freight_Normal = osmQuery.order_freight_normal += 30; query.t_cat_amount += 30; } if (osmQuery.order_freight_low != 0) { query.Order_Freight_Low = osmQuery.order_freight_low += 30; query.t_cat_amount += 30; } if (query.t_cat_amount != 0) { query.Order_Amount = osmQuery.order_amount += query.t_cat_amount; } } if (query.delivery == 12) { if (osmQuery.order_status == 0) { query.Order_Amount = osmQuery.order_amount - (osmQuery.order_freight_normal + osmQuery.order_freight_low); query.Order_Freight_Normal = 0; query.Order_Freight_Low = 0; query.Order_Payment = 9; query.Order_Date_Pay = (uint)CommonFunction.GetPHPTime(); query.status_description = query.username + "轉自取,現金"; #region modify_order_status arrList.Add(_orderMasterDao.ModifyOrderStatus(query)); omsQuery.serial_id = Convert.ToUInt64(_orderMasterDao.GetNextSerial(new Serial { Serial_id = 29 }).Rows[0][0]); omsQuery.order_id = query.Order_Id; omsQuery.status_description = query.status_description; omsQuery.order_status = 2; omsQuery.status_ipfrom = query.Order_Ipfrom; arrList.Add(_orderMasterDao.OMSRecord(omsQuery)); query.user_id = osmQuery.user_id; DataTable _dt = _orderMasterDao.IsFirstTime(query); if (_dt != null && _dt.Rows.Count > 0) { arrList.Add(_orderMasterDao.UpFirstTime(query)); } #endregion int master_total = osmQuery.accumulated_bonus; if (master_total > 0) { BonusMaster bm = new BonusMaster(); bm.master_start = (uint)CommonFunction.GetPHPTime(); bm.master_end = bm.master_start + (86400 * 90); bm.master_note = query.Order_Id.ToString(); bm.master_writer = "Writer : 轉自取發放購物金"; bm.type_id = 30; bm.master_total = (uint)master_total; bm.master_balance = master_total; bm.user_id = osmQuery.user_id; bm.master_createdate = (uint)CommonFunction.GetPHPTime(); bm.master_updatedate = bm.master_createdate; bm.master_ipfrom = query.Order_Ipfrom; _orsDao.Bonus_Master_Add(bm); } } else { DataTable _serDt = _orderMasterDao.GetNextSerial(new Serial { Serial_id = 29 }); omsQuery.serial_id = Convert.ToUInt64(_serDt.Rows[0][0]); omsQuery.order_id = query.Order_Id; omsQuery.status_description = query.username + "轉自取"; omsQuery.order_status = osmQuery.order_status; omsQuery.status_ipfrom = query.Order_Ipfrom; arrList.Add(_orderMasterDao.OMSRecord(omsQuery)); } arrList.Add(_orderMasterDao.UpDeliveryMaster(query.Order_Id, query.Delivery_Store)); } //更新order_master arrList.Add(_orderMasterDao.UpdateOrderMaster(query, osmQuery)); if (_mysqlDao.ExcuteSqlsThrowException(arrList)) { json = "{success:true}"; } else { json = "{success:false}"; } } catch (Exception ex) { throw new Exception("OrderMasterMgr-->ChangePayMent-->" + ex.Message, ex); } return json; }
public HttpResponseBase OrderSave() { int orderType = Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd" ? 2 : 1;//訂單類型,:1為普通訂單輸入,2為內部訂單輸入 string jsonStr = "{success:false,msg:'" + Resources.OrderAdd.ORDER_ADD_FAIL + "'}"; try { Caller _caller = (Session["caller"] as Caller); uint normalFright = 0, lowFright = 0, receipt_to = 0, productTotalPrice = 0, combChannelId = 0, combPayMent = 0, combStoreMode = 0, combOrderStatus = 0, storeType = 0, retrieve_mode = 0; string combOrderDate = "", combLatestDeliverDate = "", txtAdminNote = "", txtCartNote = "", txtTradeNumber = "", txtOrderId = "", txtDeliverNumber = ""; uint.TryParse(Request.Params["retrieve_mode"] ?? "0", out retrieve_mode); uint.TryParse(Request.Params["receipt_to"] ?? "0", out receipt_to); uint.TryParse(Request.Params["normalFright"] ?? "0", out normalFright); uint.TryParse(Request.Params["lowFright"] ?? "0", out lowFright); uint.TryParse(Request.Params["comboPrice"] ?? "0", out productTotalPrice); uint.TryParse(Request.Params["combChannelId"] ?? "0", out combChannelId); uint.TryParse(Request.Params["combPayMent"] ?? "0", out combPayMent);//付款方式 uint.TryParse(Request.Params["combStoreMode"] ?? "0", out combStoreMode); uint.TryParse(Request.Params["combOrderStatus"] ?? "0", out combOrderStatus);//訂單狀態 uint.TryParse(Request.Params["storeType"] ?? "0", out storeType); combOrderDate = Request.Params["combOrderDate"]; //txtOrderDateHour = Request.Params["txtOrderDateHour"]; //txtOrderDateMinute = Request.Params["txtOrderDateMinute"]; combLatestDeliverDate = Request.Params["combLatestDeliverDate"]; txtAdminNote = Request.Params["txtareAdminNote"]; txtCartNote = Request.Params["txtareCartNote"]; txtTradeNumber = Request.Params["txtTradeNumber"]; txtOrderId = Request.Params["txtOrderId"]; txtDeliverNumber = Request.Params["txtDeliverNumber"]; //combOrderDate += " " + txtOrderDateHour + ":" + txtOrderDateMinute; if (!string.IsNullOrEmpty(txtAdminNote)) { txtAdminNote = Resources.OrderAdd.NOTE + ":" + txtAdminNote; } #region 訂購人信息 string b_txtName = "", b_txtMobil = "", b_txtPhoneHead = "", b_txtPhoneContent = "", b_txtAddress = ""; uint b_combZip = 0; b_txtName = Request.Params["b_txtName"]; b_txtMobil = Request.Params["b_txtMobel"]; b_txtPhoneHead = Request.Params["b_txtPhoneHead"]; b_txtPhoneContent = Request.Params["b_txtPhoneContent"]; b_txtAddress = Request.Params["b_txtAddress"]; uint.TryParse(Request.Params["b_combZip"] ?? "0", out b_combZip); #endregion #region 收件人信息 string r_txtCNFullName = "", r_txtActionPhone = "", r_txtContactPhoneHead = "", r_txtContactPhoneContent = "", r_txtContactAddress = ""; uint r_combZip = 0; r_txtCNFullName = Request.Params["r_txtCNFullName"]; r_txtActionPhone = Request.Params["r_txtActionPhone"]; r_txtContactPhoneHead = Request.Params["r_txtContactPhoneHead"]; r_txtContactPhoneContent = Request.Params["r_txtContactPhoneContent"]; r_txtContactAddress = Request.Params["r_txtContactAddress"]; uint.TryParse(Request.Params["r_combZip"] ?? "0", out r_combZip); #endregion string dataStr = Request.Params["gridData"]; OrderAddCustom odc = new OrderAddCustom(); JavaScriptSerializer jss = new JavaScriptSerializer(); List<OrderAddCustom> errorOrder = new List<OrderAddCustom>(); List<CooperatorOrderCustom> coopErrorList = new List<CooperatorOrderCustom>(); //添加總和 抵用金 和 購物金 add by zhuoqin0830w uint productTotal = 0, deduct_bonusTotal = 0, deduct_welfareTotal = 0, acc_bonusTotal = 0; OrderImportMgr orderImportMgr = new OrderImportMgr(connectionString, 0); Resource.CoreMessage = new CoreResource("OrderImport"); List<OrderSlave> slaves = new List<OrderSlave>(); List<ChannelOrder> channelList = new List<ChannelOrder>(); //add by zhuoqin0830w 2015/02/26 公關單與報廢單功能 獲取前臺傳來的單據類型 string billtype = orderType == 1 ? "" : Request.Form["BillType"]; string dep = orderType == 1 ? "" : Request.Form["dep"]; //獲取前臺傳來 的 Cart_Delivery 和 Site_Id add by zhuoqin0830w 2015/07/03 uint Cart_Delivery = uint.Parse(Request.Params["Cart_Delivery"]); uint Site_Id = orderType == 1 ? 0 : uint.Parse(Request.Form["Site_Id"]); switch (storeType) { case 1: #region 合作外站新增訂單 List<CooperatorOrderCustom> odcList1 = jss.Deserialize<List<CooperatorOrderCustom>>(dataStr); IPriceMasterImplMgr _priceMgr = new PriceMasterMgr(connectionString); var parentList1 = from rec in odcList1 where rec.parent_id == "0" && rec.Item_Id == 0 select rec;//rec.price_type!=2:各自定價的價格是從表中讀取的,所以到後臺不需要重新計算價格 var singleList1 = from rec in odcList1 where rec.Item_Id != 0 && rec.parent_id == "0" select rec; foreach (var item in parentList1) { var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum).ToString()); productItemMapMgr = new ProductItemMapMgr(connectionString); ProductItemMap pMap = productItemMapMgr.QueryAll(new ProductItemMap { channel_id = uint.Parse(combChannelId.ToString()), channel_detail_id = item.coop_product_id }).FirstOrDefault(); PriceMaster pMaster = _priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(pMap.product_id.ToString()), //user_id = 0, //user_level = 1, //site_id = 1, price_master_id = pMap.price_master_id, child_id = int.Parse(pMap.product_id.ToString()) }); odcList1.Find(rec => rec.Product_Id == item.Product_Id && rec.group_id == item.group_id).price_master_id = pMaster.price_master_id; ////查找該父商品下的子商品 var childList = from rec in odcList1 where rec.parent_id == item.coop_product_id select rec; foreach (var child in childList) { IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster query = new PriceMaster { user_id = pMaster.user_id, user_level = pMaster.user_level, site_id = pMaster.site_id }; if (item.price_type == 1) { query.product_id = uint.Parse(child.coop_product_id); query.child_id = 0; } else if (item.price_type == 2) { query.product_id = uint.Parse(pMap.product_id.ToString()); query.child_id = int.Parse(child.coop_product_id); } PriceMaster pM = _priceMgr.QueryPriceMaster(query); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).price_master_id = pM.price_master_id; ipList = iPMgr.Query(new ItemPrice { item_id = child.Item_Id, price_master_id = pM.price_master_id }); if ((item.price_type == 1 && pM.same_price == 1) || (item.price_type == 2 && pMaster.same_price == 1)) { odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Item_Money = uint.Parse(pM.price.ToString()); //odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Item_Cost = uint.Parse(pM.cost.ToString()); odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Event_Item_Cost = uint.Parse(pM.event_cost.ToString()); } else { odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Item_Money = ipList[0].item_money; //odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Item_Cost = ipList[0].item_cost; odcList1.Find(rec => rec.coop_product_id == child.coop_product_id && rec.group_id == child.group_id).Event_Item_Cost = ipList[0].event_cost; } } } } //單一商品 #region Channel_Order 資料 ChannelOrder chOrd; foreach (CooperatorOrderCustom coop in odcList1) { ChannelOrder existChl = channelList.Where(m => m.Channel_Detail_Id == coop.coop_product_id).FirstOrDefault(); if (existChl != null) { continue; } chOrd = new ChannelOrder(); chOrd.Channel_Detail_Id = coop.coop_product_id; chOrd.Channel_Id = int.Parse(combChannelId.ToString()); chOrd.Createtime = DateTime.Now; if (!string.IsNullOrEmpty(combOrderDate)) { chOrd.Ordertime = Convert.ToDateTime(combOrderDate); } chOrd.Order_Id = txtTradeNumber; if (!string.IsNullOrEmpty(combLatestDeliverDate)) { chOrd.Latest_Deliver_Date = Convert.ToDateTime(combLatestDeliverDate); } chOrd.Dispatch_Seq = txtDeliverNumber; channelList.Add(chOrd); } #endregion slaves = orderImportMgr.FillSlaveCooperator(odcList1, coopErrorList, combChannelId, combOrderStatus, txtOrderId); foreach (var item in singleList1) { var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum).ToString()); } #endregion break; case 2: //Gigade新增訂單 List<OrderAddCustom> odcList2 = jss.Deserialize<List<OrderAddCustom>>(dataStr); //將前臺傳來的 Site_Id 的值傳入到後臺 并插入數據庫 add by zhuoqin0830w 2015/07/03 odcList2.ForEach(m => { m.Site_Id = Site_Id; }); if (orderType == 1) { #region 重新計算組合商品價格 IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString); var parentList = from rec in odcList2 where rec.parent_id == 0 && rec.Item_Id == 0 && rec.price_type != 2 select rec; //rec.price_type!=2:各自定價的價格是從表中讀取的,所以到後臺不需要重新計算價格 var singleList = from rec in odcList2 where rec.Item_Id != 0 && rec.parent_id == 0 select rec; var priceSelfList = from rec in odcList2 where rec.Item_Id == 0 && rec.parent_id == 0 && rec.price_type == 2 select rec; //單一商品計算價格 foreach (var item in singleList) { //使 總價 減去 抵用金 和 購物金 edit by zhuoqin0830w 2015/05/14 var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum - item.deduct_bonus - item.deduct_welfare).ToString()); // 計算 購物金 和 抵用金 的 總和 add by zhuoqin0830w 2015/05/14 deduct_bonusTotal += uint.Parse(item.deduct_bonus.ToString()); deduct_welfareTotal += uint.Parse(item.deduct_welfare.ToString()); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(item.Product_Id.ToString()), user_id = 0, user_level = 1, site_id = Site_Id, child_id = 0 }); if (pM != null) { odcList2.Find(rec => rec.Product_Id == item.Product_Id).price_master_id = pM.price_master_id; } } //組合商品各自定價計算價格 foreach (var item in priceSelfList) { //使 總價 減去 抵用金 和 購物金 edit by zhuoqin0830w 2015/05/14 var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum - item.deduct_bonus - item.deduct_welfare).ToString()); // 計算 購物金 和 抵用金 的 總和 add by zhuoqin0830w 2015/05/14 deduct_bonusTotal += uint.Parse(item.deduct_bonus.ToString()); deduct_welfareTotal += uint.Parse(item.deduct_welfare.ToString()); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = item.Product_Id, user_id = 0, user_level = 1, site_id = 1, child_id = Convert.ToInt32(item.Product_Id) }); if (pM != null) { odcList2.Find(rec => rec.Product_Id == item.Product_Id && rec.group_id == item.group_id).price_master_id = pM.price_master_id; } //找出當前父商品的子商品 var childList = from rec in odcList2 where rec.parent_id == item.Product_Id && rec.group_id == item.group_id select rec; foreach (var child in childList) { pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = item.Product_Id, user_id = 0, user_level = 1, site_id = 1, child_id = Convert.ToInt32(child.Product_Id) }); if (pM != null) { IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); ItemPrice price = iPMgr.Query(new ItemPrice { item_id = child.Item_Id, price_master_id = pM.price_master_id }).FirstOrDefault(); if (price != null) { odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = price.item_cost; //成本 odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Event_Item_Cost = price.event_cost;//活動成本 odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Money = price.item_money;//售價 } } } } //組合商品按比例拆分計算價格 foreach (var item in parentList) { var TotalPrice = 0.0; var TotalCost = 0.0; //使 總價 減去 抵用金 和 購物金 edit by zhuoqin0830w 2015/05/14 var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum - item.deduct_bonus - item.deduct_welfare).ToString()); // 計算 購物金 和 抵用金 的 總和 add by zhuoqin0830w 2015/05/14 deduct_bonusTotal += uint.Parse(item.deduct_bonus.ToString()); deduct_welfareTotal += uint.Parse(item.deduct_welfare.ToString()); PriceMaster pMaster = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(item.Product_Id.ToString()), user_id = 0, user_level = 1, site_id = Site_Id, child_id = int.Parse(item.Product_Id.ToString()) }); odcList2.Find(rec => rec.Product_Id == item.Product_Id && rec.group_id == item.group_id).price_master_id = pMaster.price_master_id; //找出當前父商品的子商品 var childList = from rec in odcList2 where rec.parent_id == item.Product_Id && rec.group_id == item.group_id select rec; var parentPrice = item.product_cost; var parentCost = pMaster != null ? pMaster.cost : 0; //子商品總價 foreach (var child in childList) { //價格 IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(child.Product_Id.ToString()), user_id = 0, user_level = 1, site_id = Site_Id, child_id = 0 }); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { //必購數量 _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(item.Product_Id.ToString()), Child_Id = child.Product_Id.ToString() //add by wangwei02016w 2014/9/24 }); var s_must_buy = prodComList[0].S_Must_Buy == 0 ? child.s_must_buy : prodComList[0].S_Must_Buy; if (pM.same_price == 1)//同價 { TotalPrice += pM.price * s_must_buy; TotalCost += pM.cost * s_must_buy; } else { ipList = iPMgr.Query(new ItemPrice { item_id = child.Item_Id, price_master_id = pM.price_master_id }); if (ipList.Count != 0) { TotalPrice += ipList[0].item_money * s_must_buy; TotalCost += ipList[0].item_cost * s_must_buy; } } } } //子商品按比例拆分后的價格 foreach (var child in childList) { _prodCombMgr = new ProductComboMgr(connectionString); List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(item.Product_Id.ToString()), Child_Id = child.Product_Id.ToString() //add by wangwei02016w 2014/9/24 }); var s_must_buy = prodComList[0].S_Must_Buy == 0 ? child.s_must_buy : prodComList[0].S_Must_Buy; IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString); PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster { product_id = uint.Parse(child.Product_Id.ToString()), user_id = 0, user_level = 1, site_id = Site_Id, child_id = 0 }); List<ItemPriceCustom> ipList = new List<ItemPriceCustom>(); if (pM != null) { odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).price_master_id = pM.price_master_id; if (pM.same_price == 1) { odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = uint.Parse(pM.cost.ToString()); //成本 odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Event_Item_Cost = uint.Parse(pM.event_cost.ToString());//活動成本 var afterPrice = 0; var afterCost = 0; if (TotalPrice <= 0) { afterPrice = 0; } else { afterPrice = Convert.ToInt16(Math.Round(parentPrice * (Convert.ToDouble(pM.price * s_must_buy) / TotalPrice / s_must_buy))); } if (TotalCost <= 0) { afterCost = 0; } else { afterCost = Convert.ToInt16(Math.Round(parentCost * (Convert.ToDouble(pM.cost * s_must_buy) / TotalCost / s_must_buy))); } //var singleTotal = afterPrice * s_must_buy; var singleTotal = afterPrice; parentPrice -= uint.Parse(singleTotal.ToString()); TotalPrice -= Convert.ToDouble(pM.price) * s_must_buy; odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).product_cost = uint.Parse(afterPrice.ToString()); //var singleCostTotal = afterCost * s_must_buy; var singleCostTotal = afterCost; parentCost -= singleCostTotal; TotalCost -= Convert.ToDouble(pM.cost) * s_must_buy; odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = uint.Parse(afterCost.ToString()); } else { ipList = iPMgr.Query(new ItemPrice { item_id = child.Item_Id, price_master_id = pM.price_master_id }); if (ipList.Count != 0) { odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = ipList[0].item_cost; //成本 odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Event_Item_Cost = ipList[0].event_cost;//活動成本 //var afterPrice = CommonFunction.Math4Cut5Plus(parentPrice * ipList[0].item_money * s_must_buy / TotalPrice / s_must_buy); //beforePrice += afterPrice * s_must_buy; //new logic var afterPrice = 0; var afterCost = 0; if (TotalPrice <= 0) { afterPrice = 0; } else { afterPrice = Convert.ToInt16(Math.Round(parentPrice * (Convert.ToDouble(ipList[0].item_money * s_must_buy) / TotalPrice / s_must_buy))); } if (TotalCost <= 0) { afterCost = 0; } else { afterCost = Convert.ToInt16(Math.Round(parentCost * (Convert.ToDouble(ipList[0].item_cost * s_must_buy) / TotalCost / s_must_buy))); } //var singleTotal = afterPrice * s_must_buy; var singleTotal = afterPrice; parentPrice -= uint.Parse(singleTotal.ToString()); TotalPrice -= Convert.ToDouble(ipList[0].item_money) * s_must_buy; // beforePrice += singleTotal; //var singleCostTotal = afterCost * s_must_buy; var singleCostTotal = afterCost; parentCost -= singleCostTotal; TotalCost -= Convert.ToDouble(ipList[0].item_cost) * s_must_buy; odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).product_cost = uint.Parse(afterPrice.ToString()); odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).Item_Cost = uint.Parse(afterCost.ToString()); odcList2.Find(rec => rec.Product_Id == child.Product_Id && rec.group_id == item.group_id).s_must_buy = s_must_buy; } } } } } #endregion } else { foreach (var item in odcList2.FindAll(m => (m.parent_id == 0 && m.Item_Id == 0) || (m.Item_Id != 0 && m.parent_id == 0))) { //使 總價 減去 抵用金 和 購物金 edit by zhuoqin0830w 2015/05/14 var totalPrice = item.Event_Item_Money == 0 ? item.product_cost : item.Event_Item_Money;//add by zhuoqin0830w 2015/12/02 判斷是否使用活動價 productTotal += uint.Parse((totalPrice * item.buynum - item.deduct_bonus - item.deduct_welfare).ToString()); // 計算 購物金 和 抵用金 的 總和 add by zhuoqin0830w 2015/05/14 deduct_bonusTotal += uint.Parse(item.deduct_bonus.ToString()); deduct_welfareTotal += uint.Parse(item.deduct_welfare.ToString()); acc_bonusTotal += uint.Parse(item.accumulated_bonus.ToString()); } } slaves = orderImportMgr.FillSlave(odcList2, errorOrder, combOrderStatus, txtOrderId); break; default: break; } if (slaves != null && errorOrder.Count() == 0 && coopErrorList.Count() == 0) { channelMgr = new ChannelMgr(connectionString); #region OrderMaster 信息 #region receipt_to 發票開立方式 switch (receipt_to) { case 1: receipt_to = 2; break; case 2: receipt_to = 0; break; case 3: receipt_to = 2; break; } #endregion #region retrieve_mode 取貨方式 channelShipMgr = new ChannelShippingMgr(connectionString); ChannelShipping chip = new ChannelShipping(); chip.channel_id = int.Parse(combChannelId.ToString()); chip.shipping_carrior = int.Parse(combStoreMode.ToString()); retrieve_mode = uint.Parse(channelShipMgr.Query(chip)[0].retrieve_mode.ToString()); #endregion OrderMaster ordermaster = new OrderMaster(); //ordermaster.Order_Id = Convert.ToUInt32(orderImportMgr.NextOrderId()); ordermaster.Channel_Order_Id = txtTradeNumber; ordermaster.Invoice_Status = receipt_to; ordermaster.Order_Freight_Normal = normalFright; ordermaster.Order_Freight_Low = lowFright; ordermaster.Delivery_Store = combStoreMode; ordermaster.Channel = combChannelId; ordermaster.Order_Status = combOrderStatus; //orderType=2為内部订单输入 edit by xiangwang0413w 2014/10/29 ordermaster.User_Id = (orderType == 1) ? (uint)channelMgr.GetUserIdByChannelId((int)combChannelId) : uint.Parse(Request.Params["userId"]);//订单人的user_id ordermaster.Order_Product_Subtotal = productTotal; ordermaster.Order_Amount = productTotal + normalFright + lowFright; ordermaster.Order_Payment = combPayMent; //向 order_master 裱中 添加 從前臺獲取的 Cart_Delivery edit by zhuoqin0830w 2015/07/03 ordermaster.Cart_Id = Cart_Delivery; ordermaster.Note_Admin = string.Format(Resources.OrderAdd.NOTE_CONTENT, _caller.user_username, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), txtAdminNote); ordermaster.Note_Order = txtCartNote; ordermaster.Order_Date_Pay = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()); ordermaster.Order_Createdate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime(combOrderDate)); ordermaster.Import_Time = DateTime.Now; ordermaster.Retrieve_Mode = retrieve_mode; //向 order_master 裱中 添加 抵用金 和 購物金 add by zhuoqin0830w 2015/05/14 ordermaster.Deduct_Welfare = deduct_welfareTotal; ordermaster.Deduct_Bonus = deduct_bonusTotal; //向 order_master 表中 添加 返還購物金 add by zhuoqin0830w 2015/09/01 ordermaster.Accumulated_Bonus = (int)acc_bonusTotal; #endregion #region 出貨時間 if (orderType == 2)//內部訂單輸入 { ordermaster.Holiday_Deliver = Convert.ToInt32(Request.Form["HolidayDeliver"]); ordermaster.Estimated_Arrival_Period = Convert.ToInt32(Request.Form["EstimatedArrivalPeriod"]); } #endregion #region 訂購人信息 ordermaster.Order_Name = b_txtName; ordermaster.Order_Mobile = b_txtMobil; b_txtPhoneHead = !string.IsNullOrEmpty(b_txtPhoneHead) ? b_txtPhoneHead + "-" : b_txtPhoneHead; ordermaster.Order_Phone = b_txtPhoneHead + b_txtPhoneContent; ordermaster.Order_Zip = b_combZip; ordermaster.Order_Address = b_txtAddress; ordermaster.Order_Gender = Request.Params["ServiceSex"] == "1" ? true : false; //add by wwei0216w 2015/1/21 訂購人性別 #endregion #region 收件人信息 ordermaster.Delivery_Name = r_txtCNFullName; ordermaster.Delivery_Mobile = r_txtActionPhone; ordermaster.Delivery_Phone = r_txtContactPhoneHead + "-" + r_txtContactPhoneContent; ordermaster.Delivery_Zip = r_combZip; ordermaster.Delivery_Address = r_txtContactAddress; ordermaster.Delivery_Gender = Request.Params["AddresseeSex"] == "1" ? true : false; //add by wwei0216w 收件人性別 #endregion #region add by zhuoqin0830w 2015/02/26 公關單與報廢單功能 判斷單據類型是否為空值 如果不為空則執行添加功能 OrderMasterPattern op = null; if (!string.IsNullOrEmpty(billtype)) { op = new OrderMasterPattern { Pattern = int.Parse(billtype), Dep = int.Parse(dep) }; } #endregion #region add by zhuoqin0830w 2015/08/24 在內部訂單輸入時 同時將 輸入的 購物金 和 返還購物金 以及 抵用券 添加至 bonus_master 和 bonus_record 表中 BonusMaster bm = null; BonusRecord brBonus = null; BonusRecord brWelfare = null; //判斷返還購物金 是否 大於0 如果大於 0 表示需要在 bonus_master 新增一筆數據 if (acc_bonusTotal > 0) { bm = new BonusMaster { user_id = ordermaster.User_Id, type_id = 30,// 默認為 商品回饋購物金 master_writer = "商品回饋購物金", master_total = acc_bonusTotal, master_balance = (int)acc_bonusTotal, master_start = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), master_end = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.AddDays(90).ToString())),//默認過期時間是當前時間+90天 master_createdate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), master_updatedate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), bonus_type = 1//默認為 購物金 }; } //判斷購物金是否大於 0 如果是 則表示 需要在 bonus_record 增加一筆數據 //並且需要 在 bonus_master 中 按照 過期日期 減去 相應的 參數 if (deduct_bonusTotal > 0) { brBonus = new BonusRecord { user_id = ordermaster.User_Id, record_use = deduct_bonusTotal, record_createdate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), record_updatedate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()) }; //判斷購物金是否小於或等於數據庫中的購物金 _bonusMasterMgr = new BonusMasterMgr(connectionString); int userBonusTotal = _bonusMasterMgr.GetSumBouns(brBonus); if (deduct_bonusTotal > userBonusTotal) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.BONUS_PRICE_NULL + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } //判斷 抵用卷 金額 是否 大於 0 if (deduct_welfareTotal > 0) { brWelfare = new BonusRecord { user_id = ordermaster.User_Id, record_use = deduct_welfareTotal, record_createdate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()), record_updatedate = Convert.ToUInt32(BLL.gigade.Common.CommonFunction.GetPHPTime()) }; //判斷購物金是否小於或等於數據庫中的購物金 _bonusMasterMgr = new BonusMasterMgr(connectionString); int userWelfateTotal = _bonusMasterMgr.GetSumWelfare(brWelfare); if (deduct_welfareTotal > userWelfateTotal) { jsonStr = "{success:false,msg:'" + Resources.OrderAdd.WELFARE_PRICE_NULL + "'}"; this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; } } #endregion #region 保存至數據庫 bool result = orderImportMgr.Save2DB(ordermaster, slaves, channelList, null, op, bm, brBonus, brWelfare); #endregion if (result) { jsonStr = "{success:true,msg:'" + Resources.OrderAdd.ORDER_ADD_SUCCESS + "'}"; } } else { StringBuilder stb = new StringBuilder(); if (storeType == 1) { foreach (CooperatorOrderCustom item in coopErrorList) { stb.Append(item.coop_product_id + "\\n"); } stb.Append("\\n" + Resources.OrderAdd.EMPTY_NULL_FAIL); } else if (storeType == 2) { foreach (OrderAddCustom item in errorOrder) { stb.Append(item.Product_Id + item.Spec_Name_1 + item.Spec_Name_2 + "\\n"); } stb.Append("\\n" + Resources.OrderAdd.EMPTY_NULL_FAIL); } jsonStr = "{success:false,msg:'" + stb.ToString() + "'}"; } } 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); } this.Response.Clear(); this.Response.Write(jsonStr); this.Response.End(); return this.Response; }
/// <summary> /// 根據 master_id 修改數據 /// </summary> /// <param name="br"></param> /// <returns></returns> public string UpdateBonusMasterBalance(BonusMaster bm) { try { return _IBonusMasterDao.UpdateBonusMasterBalance(bm); } catch (Exception ex) { throw new Exception("BonusMasterMgr-->UpdateBonusMasterBalance(BonusMaster bm)-->" + ex.Message, ex); } }
/// <summary> /// 向 bonus_master 裱中 添加 一筆數據 /// </summary> /// <param name="br"></param> /// <returns></returns> public string AddBonusMaster(BonusMaster bm) { try { return _IBonusMasterDao.AddBonusMaster(bm); } catch (Exception ex) { throw new Exception("BonusMasterMgr-->AddBonusMaster(BonusMaster bm)-->" + ex.Message, ex); } }