コード例 #1
0
ファイル: BonusRecordMgr.cs プロジェクト: lxh2014/gigade-net
 /// <summary>
 /// 向 bonus_record 裱中添加 數據
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public string InsertBonusRecord(BonusRecord br)
 {
     try
     {
         return _bonusRecordDao.InsertBonusRecord(br);
     }
     catch (Exception ex)
     {
         throw new Exception("BonusRecordMgr-->InsertBonusRecord(BonusRecord br)-->" + ex.Message, ex);
     }
 }
コード例 #2
0
ファイル: BonusRecordDao.cs プロジェクト: lxh2014/gigade-net
 /// <summary>
 /// 向 bonus_record 裱中添加 數據  add by zhuoqin0830w 2015/08/24
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public string InsertBonusRecord(BonusRecord br)
 {
     StringBuilder strSql = new StringBuilder();
     try
     {
         //獲取使用者電腦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_record(record_id,order_id,master_id,type_id,record_use,record_note,record_writer,record_createdate,record_updatedate,record_ipfrom)");
         strSql.AppendFormat(@" VALUES({0},", br.record_id);
         strSql.Append(@"'{0}',");
         strSql.AppendFormat(@"'{0}','{1}','{2}','{3}','{4}',", br.master_id, br.type_id, br.record_use, br.record_note, br.record_writer);
         strSql.AppendFormat(@"'{0}','{1}','{2}');", br.record_createdate, br.record_updatedate, ip);
         return strSql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("BonusRecordDao-->InsertBonusRecord(BonusRecord br)-->" + strSql.ToString() + ex.Message, ex);
     }
 }
コード例 #3
0
ファイル: BonusMasterDao.cs プロジェクト: lxh2014/gigade-net
 //bonus_record記錄
 public string InsertBonusRecord(BonusRecord query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat("insert into bonus_record(record_id,master_id,type_id,order_id,");
         sql.AppendFormat("record_use,record_note,record_writer,record_createdate,record_updatedate,record_ipfrom) values( ");
         sql.AppendFormat("'{0}','{1}','{2}','{3}',",query.record_id,query.master_id,query.type_id,query.order_id);
         sql.AppendFormat("'{0}','{1}','{2}','{3}','{4}','{5}');", query.record_use, query.record_note, query.record_writer, CommonFunction.GetPHPTime(), CommonFunction.GetPHPTime(), query.record_ipfrom);
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("BonusMasterDao-->InsertBonusRecord-->" + sql.ToString() + ex.Message, ex);
     }
 }
コード例 #4
0
ファイル: BonusMasterDao.cs プロジェクト: lxh2014/gigade-net
 /// <summary>
 /// 根據 User_id 和 時間 的倒序查詢出相應的列表 抵用券
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public List<BonusMaster> GetWelfareByEndTime(BonusRecord br)
 {
     StringBuilder strSql = new StringBuilder();
     try
     {
         strSql.AppendFormat(@"SELECT master_id,user_id,type_id,master_total,master_balance,master_note,master_writer,master_start,master_end FROM bonus_master WHERE user_id = {0} AND bonus_type = 2 AND master_start <= {1} AND master_end >= {1} ORDER BY master_end ASC;", br.user_id, Common.CommonFunction.GetPHPTime());
         return _access.getDataTableForObj<BonusMaster>(strSql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("BonusMasterDao-->GetWelfareByEndTime(BonusRecord br)-->" + strSql.ToString() + ex.Message, ex);
     }
 }
コード例 #5
0
ファイル: BonusMasterDao.cs プロジェクト: lxh2014/gigade-net
 /// <summary>
 /// 得到 bonus_master 裱中 抵用券 總和
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public int GetSumWelfare(BonusRecord br)
 {
     StringBuilder strSql = new StringBuilder();
     try
     {
         strSql.AppendFormat(@"SELECT SUM(master_balance) FROM bonus_master WHERE user_id = {0} AND bonus_type = 2 AND master_start <= {1} AND master_end >= {1};", br.user_id, Common.CommonFunction.GetPHPTime());
         //判斷查詢出來的sum值是否為空  如果為空則表示沒有可用 抵用券 則賦值為0反之則使用該用戶的抵用券  edit by zhuoqin0830w 2015/09/01
         if (string.IsNullOrEmpty(_access.getDataTable(strSql.ToString()).Rows[0][0].ToString()))
         {
             return 0;
         }
         else
         {
             return Convert.ToInt32(_access.getDataTable(strSql.ToString()).Rows[0][0]);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("BonusMasterDao-->GetSumWelfare(BonusRecord br)-->" + strSql.ToString() + ex.Message, ex);
     }
 }
コード例 #6
0
ファイル: BonusMasterDao.cs プロジェクト: lxh2014/gigade-net
        public bool InsertIntoBonusRecord(BonusRecord bonusRecord)
        {
            StringBuilder sbSql = new StringBuilder();
            try
            {
                sbSql.AppendFormat(@"insert into bonus_record (record_id,master_id,type_id,");
                sbSql.AppendFormat(@"order_id,record_use,record_note,record_writer,");
                sbSql.AppendFormat(@"record_createdate,record_updatedate,record_ipfrom)");
                sbSql.AppendFormat(@" values({0},{1},{2},{3},", bonusRecord.record_id, bonusRecord.master_id, bonusRecord.type_id, bonusRecord.order_id);
                sbSql.AppendFormat(@"{0},'{1}','{2}',", bonusRecord.record_use, bonusRecord.record_note, bonusRecord.record_writer);
                sbSql.AppendFormat(@"{0},{1},'{2}')", CommonFunction.GetPHPTime(DateTime.Now.ToString()), CommonFunction.GetPHPTime(DateTime.Now.ToString()), bonusRecord.record_ipfrom);

                return _access.execCommand(sbSql.ToString()) > 0;
            }
            catch (Exception ex)
            {

                throw new Exception("BonusMasterDao-->InsertIntoBonusRecord-->" + sbSql.ToString() + ex.Message, ex);
            }
        }
コード例 #7
0
        public string Deduct_User_Bonus(int deduct_bonus, string order_id, string user_id)
        {
            BonusMasterQuery b = new BonusMasterQuery();
            BonusRecord br = new BonusRecord();
            Serial s = new Serial();
            _serial = new SerialDao(connString);
            _bonus = new BonusMasterDao(connString);
            List<BonusMaster> store = new List<BonusMaster>();
            List<BonusMaster> store2 = new List<BonusMaster>();
            System.Net.IPAddress[] ips = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList;
            if (ips.Count() > 0)
            {
                b.master_ipfrom = ips[0].ToString();
            }
            StringBuilder sql = new StringBuilder();
            StringBuilder sqlstr = new StringBuilder();
            try
            {
                int bonus_num = deduct_bonus;
                //是否發放購物金 
                b.master_note = order_id;
                b.master_total = uint.Parse(deduct_bonus.ToString());
                b.bonus_type = 1;
                store = _bonus.GetBonus(b);
                if (store.Count == 1)
                {
                    bool user = false;
                    foreach (var item in store)
                    {
                        if (item.master_total == item.master_balance)
                        {//判斷發放的購物金是否使用 
                            user = true;
                            bonus_num = 0;
                        }
                        else
                        {
                            bonus_num = bonus_num - item.master_balance;
                        }
                        b.master_id = item.master_id;
                        b.masterid = item.master_id.ToString() + ",";
                    }
                    s = _serial.GetSerialById(28);
                    uint a = 1;
                    #region 發放購物金扣除
                    if (deduct_bonus - bonus_num > 0)
                    {


                        //先清除bonus_master表裏面的發放的購物金
                        b.master_balance = deduct_bonus - bonus_num;
                        b.master_writer = "訂單取消";
                        sqlstr.Append(_bonus.UpBonusMaster(b));
                        //并記錄到購物金記錄表中
                        sqlstr.Append(_serial.Update(28));
                        br.record_id = uint.Parse(s.Serial_Value.ToString()) + a;
                        a++;
                        br.master_id = b.master_id;
                        br.type_id = 32;
                        br.order_id = uint.Parse(b.master_note);
                        br.record_use = uint.Parse(b.master_balance.ToString());
                        br.record_note = order_id;
                        br.record_writer = "訂單整筆取消";
                        br.record_ipfrom = b.master_ipfrom;
                        sqlstr.Append(_bonus.InsertBonusRecord(br));
                    }
                    if (!user)
                    {//發放購物金被使用 
                        b.user_id = uint.Parse(user_id.ToString());
                        b.masterid = b.masterid.TrimEnd(',');
                        uint order = uint.Parse(b.master_note.ToString());
                        b.master_note = null;
                        b.master_total = 0;
                        b.usebonus = "K";
                        //該用戶剩餘可用購物金 
                        store2 = _bonus.GetBonus(b);

                        foreach (var item in store2)
                        {
                            if (bonus_num > item.master_balance)
                            {
                                b.master_balance = item.master_balance;
                                bonus_num = bonus_num - item.master_balance;
                            }
                            else
                            {
                                b.master_balance = bonus_num;
                                bonus_num = 0;
                            }
                            //變更bonus_master表裏面的發放的購物金
                            b.master_id = item.master_id;
                            sqlstr.Append(_bonus.UpBonusMaster(b));
                            //記錄到購物金記錄表中 
                            sqlstr.Append(_serial.Update(28));
                            br.record_id = uint.Parse(s.Serial_Value.ToString()) + a;
                            a++;
                            br.master_id = b.master_id;
                            br.type_id = 32;
                            br.order_id = order;
                            br.record_use = uint.Parse(b.master_balance.ToString());
                            br.record_note = order_id;
                            br.record_writer = "訂單取消被使用,額外扣除購物金";
                            br.record_ipfrom = b.master_ipfrom;
                            sqlstr.Append(_bonus.InsertBonusRecord(br));

                            if (bonus_num == 0)
                            {
                                break;
                            }
                        }
                    }
                    if (bonus_num > 0)
                    {//該用戶剩餘的購物金不夠扣剩下記錄到表中
                        sqlstr.AppendFormat(@"insert into users_deduct_bonus (deduct_bonus,user_id,createdate,order_id)");
                        sqlstr.AppendFormat(@" values('{0}','{1}','{2}','{3}');", bonus_num, user_id, CommonFunction.GetPHPTime(DateTime.Now.ToString()), order_id);
                    }
                    #endregion
                }
                return sqlstr.ToString();
            }
            catch (Exception ex)
            {
                throw new Exception("OrderReturnlMasterDao-->Deduct_User_Bonus-->" + ex.Message, ex);
            }
        }
コード例 #8
0
 // 記錄
 public string InsertBonusRecord(BonusRecord brModel)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat(@"insert into bonus_record (record_id,master_id,type_id,");
         sql.AppendFormat(@"order_id,record_use,record_note,record_writer");
         sql.AppendFormat(@"record_createdate,record_updatedate,record_ipfrom)");
         sql.AppendFormat(@" values({0},{1},{2},{3},", brModel.record_id, brModel.master_id, 32, brModel.order_id);
         sql.AppendFormat(@"{0},{1},{2},", brModel.record_use, "訂單取消", "");
         sql.AppendFormat(@"{0},{1},{2});", CommonFunction.GetPHPTime(DateTime.Now.ToString()), CommonFunction.GetPHPTime(DateTime.Now.ToString()), brModel.record_ipfrom);
         return sql.ToString();
     }
     catch (Exception ex)
     {
         throw new Exception("OrderReturnStatusDao.InsertBonusRecord-->" + ex.Message + sql.ToString(), ex);
     }
 }
コード例 #9
0
 public void Deduct_User_Bonus(int accumulated_bonus, OrderMaster om)
 {
     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;
         int userbonus = GetUserBonus(om.User_Id, 1);
         if (userbonus >= accumulated_bonus)
         {
             string ip = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList.FirstOrDefault().ToString();
             mySqlCmd.CommandText = CheckBonusTypeExist(32);//32代表 退貨產生的購物金
             //判斷type_id是否存在
             if (mySqlCmd.ExecuteScalar().ToString() == null)
             {
                 mySqlCmd.Transaction.Rollback();
             }
             int bonusnum = accumulated_bonus;
             // 會員目前可用購物金
             if (bonusnum < 0)
             {
                 bonusnum = bonusnum * -1;
             }
             if (bonusnum > userbonus)
             {
                 mySqlCmd.Transaction.Rollback();
             }
             // 找出目前可用購物金,以到期日排序
             List<BonusMaster> bmList = QueryBonusById(om.User_Id);
             foreach (var item in bmList)
             {
                 if (bonusnum > 0)
                 {
                     // 記錄點數數量
                     int tempNum = bonusnum > item.master_balance ? item.master_balance : bonusnum;
                     // 取得下一個流水號
                     mySqlCmd.CommandText = serialDao.Update(28);//28 // 購物金使用記錄流水號
                     BonusRecord brModel = new BonusRecord();
                     brModel.record_id = Convert.ToUInt32(mySqlCmd.ExecuteScalar());
                     brModel.master_id = item.master_id;
                     brModel.type_id = 32;
                     brModel.order_id = om.Order_Id;
                     brModel.record_ipfrom = ip;
                     brModel.record_use = uint.Parse(tempNum.ToString());
                     // 更新購物金結餘
                     mySqlCmd.CommandText += UpdateBonusMaster(tempNum, item.master_id);
                     bonusnum -= tempNum;
                 }
                 else
                 {
                     break;
                 }
             }
         }
         else
         {
             sql.AppendFormat(" insert into  users_deduct_bonus (deduct_bonus,user_id,createdate,order_id) values ('{0}','{1}','{2}','{3}');",
               accumulated_bonus, om.User_Id, CommonFunction.GetPHPTime(DateTime.Now.ToString()), om.Order_Id);
             mySqlCmd.CommandText += sql;
            
         }
         mySqlCmd.ExecuteNonQuery();
         mySqlCmd.Transaction.Commit();
     }
     catch (Exception ex)
     {
         mySqlCmd.Transaction.Rollback();
         throw new Exception("OrderReturnStatusDao-->Deduct_User_Bonus-->" + ex.Message, ex);
     }
     finally
     {
         if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
         {
             mySqlConn.Close();
         }
     }
 }
コード例 #10
0
ファイル: OrderMasterMgr.cs プロジェクト: lxh2014/gigade-net
 public void AddBonusRecord(OrderModifyModel model)
 {
     // 會員目前可用購物金
     int userBonus = bonusMasterDao.GetUserBonus(model.user_id);
     if (model.bonus_num < 0)
     {
         model.bonus_num = model.bonus_num * -1;
     }
     if (model.bonus_num > userBonus)
     {
         return;
     }
     List<BonusMasterQuery> bonusQuery = bonusMasterDao.GetBonusMasterListByUser(model.user_id);
     foreach (BonusMasterQuery bonus in bonusQuery)
     {
         if (model.bonus_num > 0)
         {
             BonusRecord bonusRecord = new BonusRecord();
             int decuteBonusNum = bonus.master_balance > model.bonus_num ? model.bonus_num : bonus.master_balance;
             Serial ser = _serialDao.GetSerialById(28);
             ser.Serial_Value = ser.Serial_Value + 1;
             _serialDao.Update(ser);
             bonusRecord.record_id = Convert.ToUInt32(ser.Serial_Value);
             bonusRecord.master_id = bonus.master_id;
             bonusRecord.type_id = bonus.type_id;
             bonusRecord.order_id = Convert.ToUInt32(model.order_id);
             bonusRecord.record_use = Convert.ToUInt32(decuteBonusNum);
             bonusRecord.record_note = model.record_note;
             bonusRecord.record_writer = model.record_writer;
             bonusRecord.record_ipfrom = model.ip_from;
             bonusMasterDao.InsertIntoBonusRecord(bonusRecord);
             bonus.master_balance = bonus.master_balance - decuteBonusNum;//減去扣除的購物金
             bonusMasterDao.UpdateBonusMasterMasterBalance(bonus);
             model.bonus_num -= decuteBonusNum;//更新
         }
         else
         {
             return;
         }
     }
 }
コード例 #11
0
ファイル: OrderController.cs プロジェクト: lxh2014/gigade-net
        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;
        }
コード例 #12
0
ファイル: BonusMasterMgr.cs プロジェクト: lxh2014/gigade-net
 public ArrayList regainBonus(BonusMasterQuery bm, BonusRecord br)
 {
     ArrayList arrList = new ArrayList();
     try
     {
         arrList.Add(_IBonusMasterDao.UpdateBonusMaster(bm));
         arrList.Add(_IBonusMasterDao.InsertBonusRecord(br));
         return arrList;
     }
     catch (Exception ex)
     {
         throw new Exception("BonusMasterMgr-->regainBonus-->" + ex.Message, ex);
     }
 }
コード例 #13
0
ファイル: BonusMasterMgr.cs プロジェクト: lxh2014/gigade-net
 /// <summary>
 /// 根據 User_id 和 時間 的倒序查詢出相應的列表 抵用券
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public List<BonusMaster> GetWelfareByEndTime(BonusRecord br)
 {
     try
     {
         return _IBonusMasterDao.GetWelfareByEndTime(br);
     }
     catch (Exception ex)
     {
         throw new Exception("BonusMasterDao-->GetWelfareByEndTime(BonusRecord br)-->"+ex.Message, ex);
     }
 }
コード例 #14
0
ファイル: BonusMasterMgr.cs プロジェクト: lxh2014/gigade-net
 /// <summary>
 /// 得到 bonus_master 裱中 抵用卷 總和
 /// </summary>
 /// <param name="br"></param>
 /// <returns></returns>
 public int GetSumWelfare(BonusRecord br)
 {
     try
     {
         return _IBonusMasterDao.GetSumWelfare(br);
     }
     catch (Exception ex)
     {
         throw new Exception("BonusMasterMgr-->GetSumWelfare(BonusRecord br)-->"  + ex.Message, ex);
     }
 }