public IHttpActionResult Set(Evalution evalution) { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); if (user == "C") { return(Ok(new { result = "廠商無法評價" })); } evalution.del_flag = "N"; evalution.postday = DateTime.Now; ModelState.Clear(); Validate(evalution); db.Evalution.Add(evalution); db.SaveChanges(); return(Ok(new { result = "評價完成" })); }
public IHttpActionResult GetNotice() { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); var unread = db.Notice.Where(x => x.toseq == userseq).ToList(); unread = unread.Where(x => x.state == Convert.ToBoolean(Noticestate.未讀)).ToList(); List <Notice> notices = db.Notice.Where(x => x.toseq == userseq).OrderBy(x => x.state).ThenByDescending(x => x.postday).Take(10).ToList(); var result = new { unread = unread.Count(), notices = notices.Select( x => new { x.noticeseq, x.fromseq, x.toseq, state = Enum.Parse(typeof(Noticestate), x.state.GetHashCode().ToString()).ToString(), x.text, type = Enum.Parse(typeof(Noticetype), x.type.ToString()).ToString(), time = Convert.ToDateTime(x.postday).ToString("yyyy-MM-dd HH:mm") }) }; return(Ok(result)); }
public IHttpActionResult GetOne() { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); Member member = db.Member.Find(userseq); if (member == null) { return(Ok(new { result = "查無資料" })); } MemberGetone memberGetone = new MemberGetone(); memberGetone.memberseq = member.memberseq; memberGetone.membername = member.membername; memberGetone.phone = member.phone; memberGetone.email = member.email; memberGetone.avatar = member.avatar; return(Ok(memberGetone)); }
public IHttpActionResult PostAnswer(QuestionAnswer questionAnswer) { string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); if (user == "M") { return(Ok(new { result = "會員無法回答" })); } questionAnswer.companyseq = userseq; questionAnswer.del_flag = "N"; questionAnswer.postday = DateTime.Now; db.QuestionAnswer.Add(questionAnswer); db.SaveChanges(); //var questisonAnswer_ = db.QuestionAnswer.Where(x => x.Question.queseq == questionAnswer.queseq).FirstOrDefault(); var question = db.Question.Where(x => x.queseq == questionAnswer.queseq).ToList(); QuestionAnswer questionAnswer_ = db.QuestionAnswer.Find(questionAnswer.ansseq); //signalr即時通知 Utility.signalR_notice(questionAnswer_.companyseq, questionAnswer_.Question.memberseq, questionAnswer_.ansseq, "", Noticetype.答通知); var context = GlobalHost.ConnectionManager.GetHubContext <DefaultHub>(); var connectid = db.Signalr.Where(x => x.whoseq == questionAnswer_.Question.memberseq).Select(x => x.connectid).ToList();//需要通知的會員signalr connectid var unread = db.Notice.Where(x => x.toseq == questionAnswer_.Question.memberseq).ToList(); unread = unread.Where(x => x.state == Convert.ToBoolean(Noticestate.未讀)).ToList(); List <Notice> notices = db.Notice.Where(x => x.toseq == questionAnswer_.Question.memberseq).OrderBy(x => x.state).ThenByDescending(x => x.postday).Take(10).ToList(); var result = new { unread = unread.Count(), notices = notices.Select( x => new { x.noticeseq, x.fromseq, x.toseq, state = Enum.Parse(typeof(Noticestate), x.state.GetHashCode().ToString()).ToString(), x.text, type = Enum.Parse(typeof(Noticetype), x.type.ToString()).ToString(), time = Convert.ToDateTime(x.postday).ToString("yyyy-MM-dd HH:mm") }) }; foreach (var c in connectid) { context.Clients.Client(c).Get(result); } return(Ok(new { result = "回覆成功" })); }
public IHttpActionResult Uploadimg() { string error_message = "Uploadimg錯誤,請至伺服器log查詢錯誤訊息"; //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string filename = null; //string parameter = HttpContext.Current.Request.Form["parameter"]; //company_Avatar //company_Banner try { //處理圖片 HttpPostedFile postedFile = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null; if (postedFile != null) { if (postedFile.ContentLength >= 2097152) { error_message = "Uploadimg錯誤,請至伺服器log查詢錯誤訊息"; throw new Exception("圖片大小不可超過 2 MB"); } string extension = postedFile.FileName.Split('.')[postedFile.FileName.Split('.').Length - 1]; if (String.Compare(extension, "jpg", true) == 0 || String.Compare(extension, "png", true) == 0) { filename = Utility.SaveUpImage(postedFile, "", userseq); } else { error_message = "圖片格式錯誤"; throw new Exception("圖片格式錯誤"); } } return(Ok(new { result = filename })); } catch (Exception ex) { Utility.log("Uploadimg", ex.ToString()); return(Ok(new { result = error_message })); } }
public IHttpActionResult Patchcompany(CompanyPatch companyPatch) { //CompanyPatch companyPatch string error_message = "patch錯誤,請至伺服器log查詢錯誤訊息"; //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); if (ModelState.IsValid) { using (var transaction1 = db.Database.BeginTransaction()) { try { Company company = db.Company.Find(userseq); company.introduce = companyPatch.introduce; company.morning = Convert.ToBoolean(companyPatch.morning); company.afternoon = Convert.ToBoolean(companyPatch.afternoon); company.night = Convert.ToBoolean(companyPatch.night); company.midnight = Convert.ToBoolean(companyPatch.midnight); company.bannerimg = companyPatch.bannerimg; db.Entry(company).State = EntityState.Modified; db.SaveChanges(); transaction1.Commit(); } catch (Exception ex)//失敗 { transaction1.Rollback(); Utility.log("Patchcompany", ex.ToString()); return(Ok(new { result = error_message//修改失敗 })); } return(Ok(new { result = "修改成功" })); } } else { return(Ok(new { result = ModelState })); } }
public IHttpActionResult Cancelorder(OrderCancel orderCancel) { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); //C 廠商 M會員 Order order = db.Order.Find(orderCancel.orderseq); TimeSpan s = new TimeSpan(order.orderdates.Value.Ticks - DateTime.Now.Ticks); if (s.Days <= 7)//訂單-今日 日期大於七天 不可消單 { return(Ok(new { result = "七天內無法取消訂單" })); } if (order.state == (int)Orderstate.已取消) { return(Ok(new { result = "已取消" })); } orderCancel.del_flag = "N"; db.OrderCancel.Add(orderCancel); order.state = (int)Orderstate.已取消; order.updateday = DateTime.Now; //取消訂單時間 order.updateseq = userseq; //取消訂單人 db.Entry(order).State = EntityState.Modified; db.SaveChanges(); return(Ok(new { result = "取消成功" })); }
public IHttpActionResult Sendid(Signalr signalr) { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); signalr.whoseq = userseq; signalr.postday = DateTime.Now; db.Signalr.Add(signalr); db.SaveChanges(); return(Ok(new { result = "連線加入成功" })); }
public IHttpActionResult GetQuestionDetail(string queseq) { string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); //會員 可合併 好像做同一件事 if (user == "M") { var question = db.Question.Find(queseq); return(Ok(new { question.queseq, name = GetMemberName(question.memberseq), question = question.message, question_date = question.postday.Value.ToString("yyyy-MM-dd HH:mm:ss"), answer = question.QuestionAnswer.Select(y => y.message).FirstOrDefault() is null ? "" : question.QuestionAnswer.Select(y => y.message).FirstOrDefault(), answer_date = question.QuestionAnswer.Select(y => y.postday).FirstOrDefault() is null ? "" : question.QuestionAnswer.Select(y => y.postday).FirstOrDefault().Value.ToString("yyyy-MM-dd HH:mm:ss") }));
public IHttpActionResult Resetpwd(Company company_) { if (string.IsNullOrWhiteSpace(company_.pwd)) { return(Ok(new { result = "密碼不能為空或空白" })); } string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); Company company = db.Company.Find(userseq); company.pwd = Utility.GenerateHashWithSalt(company_.pwd, company.pwdsalt); db.Entry(company).State = EntityState.Modified; db.SaveChanges(); return(Ok(new { result = "修改成功" })); }
public IHttpActionResult GetIdentity() { string error_message = "GetIdentity,請至伺服器log查詢錯誤訊息"; //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); GetIdentityModel getIdentityModel = new GetIdentityModel(); try { string temp = userseq.Substring(0, 1); if (temp == "C") { getIdentityModel.identity = "廠商"; getIdentityModel.avatar = db.Company.Find(userseq).avatar; } else { getIdentityModel.identity = "會員"; getIdentityModel.avatar = db.Member.Find(userseq).avatar; } return(Ok(new { result = getIdentityModel })); } catch (Exception ex) { Utility.log("GetIdentity", ex.ToString()); return(Ok(new { result = error_message })); } }
public IHttpActionResult Readall() { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); var notices = db.Notice.Where(x => x.toseq == userseq).ToList(); notices = notices.Where(x => x.state == Convert.ToBoolean(Noticestate.未讀)).ToList(); foreach (var n in notices) { n.state = Convert.ToBoolean(Noticestate.已讀); db.Entry(n).State = EntityState.Modified; } db.SaveChanges(); return(Ok(new { result = "已讀" })); }
public IHttpActionResult GetQuestion(string state = null, int page = 1, int paged = 6) { string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); //會員 if (user == "M") { var questions = db.Question.Where(x => x.memberseq == userseq); if (state == ((int)Qastate.未回覆).ToString()) { questions = questions.Where(x => !x.QuestionAnswer.Any()); } else if (state == ((int)Qastate.已回覆).ToString()) { questions = questions.Where(x => x.QuestionAnswer.Any()); } questions = questions.OrderByDescending(x => x.postday); //分頁 Pagination pagination = new Pagination(); var questions_ = questions.Skip((page - 1) * paged).Take(paged).ToList(); pagination.total = questions.Count(); pagination.count = questions_.Count; pagination.per_page = paged; pagination.current_page = page; pagination.total_page = Convert.ToInt16(Math.Ceiling(Convert.ToDouble(pagination.total) / Convert.ToDouble(pagination.per_page))); return(Ok(new { question = questions_.Select(x => new { x.queseq, membername = GetMemberName(x.memberseq), x.roomseq, roomname = GetRoomName(x.roomseq), x.companyseq, state = x.QuestionAnswer.Any() == true ? Qastate.已回覆.ToString() : Qastate.未回覆.ToString(), x.message, postday = x.postday.Value.ToString("yyyy-MM-dd HH:mm:ss") }), meta = pagination })); } //廠商 else { var questions = db.Question.Where(x => x.companyseq == userseq); if (state == ((int)Qastate.未回覆).ToString()) { questions = questions.Where(x => !x.QuestionAnswer.Any()); } else if (state == ((int)Qastate.已回覆).ToString()) { questions = questions.Where(x => x.QuestionAnswer.Any()); } questions = questions.OrderByDescending(x => x.postday); //分頁 Pagination pagination = new Pagination(); var questions_ = questions.Skip((page - 1) * paged).Take(paged).ToList(); pagination.total = questions.Count(); pagination.count = questions_.Count; pagination.per_page = paged; pagination.current_page = page; pagination.total_page = Convert.ToInt16(Math.Ceiling(Convert.ToDouble(pagination.total) / Convert.ToDouble(pagination.per_page))); return(Ok(new { question = questions_.Select(x => new { x.queseq, membername = GetMemberName(x.memberseq), x.roomseq, roomname = GetRoomName(x.roomseq), x.companyseq, state = x.QuestionAnswer.Any() == true ? Qastate.已回覆.ToString() : Qastate.未回覆.ToString(), x.message, postday = x.postday.Value.ToString("yyyy-MM-dd HH:mm:ss") }), meta = pagination })); } }
public IHttpActionResult Get(string id) { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string user = userseq.Substring(0, 1); Order order = db.Order.Find(id); //Evalution evalution = db.Evalution.Where(x => x.orderseq == id).FirstOrDefault(); Company company = db.Company.Find(order.companyseq); Member member = db.Member.Find(order.memberseq); if (user == "C") { return(Ok(new { company = new { company.companyname, company.companybrand, member.avatar, company.bannerimg, order.roomname, order.orderseq, order.amt, member.membername, }, evalution = new { star = order.Evalution.Select(x => x.star).FirstOrDefault(), memo = order.Evalution.Select(x => x.memo).FirstOrDefault() }, })); } else { return(Ok(new { company = new { company.companyname, company.companybrand, company.avatar, company.bannerimg, order.roomname, order.orderseq, order.amt }, evalution = new { star = order.Evalution.Select(x => x.star).FirstOrDefault() == null ? 5 : order.Evalution.Select(x => x.star).FirstOrDefault(), memo = order.Evalution.Select(x => x.memo).FirstOrDefault() }, state = new { btn_Evalution_readonly = order.Evalution.Count == 0 ? false : true } })); } }
public IHttpActionResult Getorder(string id) { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string temp = userseq.Substring(0, 1); Order order = db.Order.Find(id); if (order == null) { return(Ok(new { result = "查無資料" })); } bool 取消訂單鈕 = false; TimeSpan s = new TimeSpan(order.orderdates.Value.Ticks - DateTime.Now.Ticks); if (order.state == 1 && s.Days > 7)//如果 狀態不是進行中 就不能消單 //訂單-今日 日期大於七天 可消單 { 取消訂單鈕 = true; } s = new TimeSpan(order.orderdatee.Value.Ticks - order.orderdates.Value.Ticks); int 寄宿總價 = 0; //寄宿總價 寄宿總價 += (order.roomprice.Value + order.roomamount_amt.Value * (order.petamount.Value - 1)) * (s.Days + 1); //每間金額 * 天數 var result = new { order = new { order.orderseq, //state = Enum.Parse(typeof(Orderstate), order.state.Value.ToString()).ToString(), order.roomname, order.companyname, order.country, order.area, order.address, orderdates = Convert.ToDateTime(order.orderdates).ToString("yyyy-MM-dd"), orderdatee = Convert.ToDateTime(order.orderdatee).ToString("yyyy-MM-dd"), roomamt = 寄宿總價, order.state, setdate = Convert.ToDateTime(order.postday).ToString("yyyy-MM-dd HH:mm"), canceldate = Convert.ToDateTime(order.updateday).ToString("yyyy-MM-dd HH:mm"), }, detail = new { order.name, order.tel, order.petamount, order.pettype, order.petsize, order.memo, medicine = new { order.medicine_infeed, order.medicine_infeed_amt, order.medicine_paste, order.medicine_paste_amt, order.medicine_pill, order.medicine_pill_amt, }, plus = new { order.bath, order.bath_amt, order.nails, order.nails_amt, order.hair, order.hair_amt }, orderprice = order.amt,//訂購總額 btn_cancel = 取消訂單鈕 }, cancel = new { reason = order.OrderCancel.Select(x => x.reason).FirstOrDefault(), memo = order.OrderCancel.Select(x => x.memo).FirstOrDefault() } }; return(Ok(result)); }
public IHttpActionResult Getorder(int state = 99, int page = 1, int paged = 6, string orderseq = null, DateTime?datetimes = null, DateTime?datetimee = null, string roomname = null) { Pagination pagination = new Pagination(); //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); string temp = userseq.Substring(0, 1); //廠商 if (temp == "C") { var linq = db.Order.Where(x => x.companyseq == userseq && (state == 99 ? x.state != 0 : x.state == state)); var linq_ = linq; //搜尋 if (orderseq != null) { linq_ = linq_.Where(x => x.orderseq == orderseq); } if (datetimes.HasValue && datetimee.HasValue) { linq_ = linq_.Where(x => x.orderdates <= datetimee.Value && datetimes.Value <= x.orderdatee); } if (roomname != null) { linq_ = linq_.Where(x => x.orderseq.Contains(roomname) || x.roomname.Contains(roomname)); } if (state == 2) { linq_ = linq_.OrderByDescending(x => x.updateday).Skip((page - 1) * paged).Take(paged); } else { linq_ = linq_.OrderByDescending(x => x.postday).Skip((page - 1) * paged).Take(paged); } List <Order> order = linq_.ToList(); if (order == null) { return(Ok(new { result = "查無資料" })); } //switch (field) //{ // case "seq": // if (orderby == "ASC") // order = order.OrderBy(x => x.orderseq).ToList(); // else if (orderby == "DESC") // order = order.OrderByDescending(x => x.orderseq).ToList(); // break; // case "date": // if (orderby == "ASC") // order = order.OrderBy(x => x.orderdates).ToList(); // else if (orderby == "DESC") // order = order.OrderByDescending(x => x.orderdates).ToList(); // break; // case "room": // if (orderby == "ASC") // order = order.OrderBy(x => x.roomname).ToList(); // else if (orderby == "DESC") // order = order.OrderByDescending(x => x.roomname).ToList(); // break; // default: // break; //} pagination.total = linq_.Count(); pagination.count = order.Count; pagination.per_page = paged; pagination.current_page = page; pagination.total_page = Convert.ToInt16(Math.Ceiling(Convert.ToDouble(pagination.total) / Convert.ToDouble(pagination.per_page))); var result = new { order = order.Select(x => new { x.companyseq, x.roomseq, x.orderseq, orderdates = Convert.ToDateTime(x.orderdates).ToString("yyyy-MM-dd"), orderdatee = Convert.ToDateTime(x.orderdatee).ToString("yyyy-MM-dd"), x.roomname, setdate = Convert.ToDateTime(x.postday).ToString("yyyy-MM-dd HH:mm"), canceldate = Convert.ToDateTime(x.updateday).ToString("yyyy-MM-dd HH:mm"), x.state, btn_Evalution = x.Evalution.Count != 0 && x.state == (int)Orderstate.已完成 ? true : false }), meta = pagination }; return(Ok(result)); } //會員 else { var linq = db.Order.Where(x => x.memberseq == userseq && (state == 99 ? x.state != 0 : x.state == state)); var linq_ = linq; //搜尋 if (orderseq != null) { linq_ = linq_.Where(x => x.orderseq == orderseq); } if (datetimes.HasValue && datetimee.HasValue) { linq_ = linq_.Where(x => x.orderdates > datetimes.Value && x.orderdatee < datetimee.Value); } if (roomname != null) { linq_ = linq_.Where(x => x.orderseq.Contains(roomname) || x.roomname.Contains(roomname)); } if (state == 2) { linq_ = linq_.OrderByDescending(x => x.updateday).Skip((page - 1) * paged).Take(paged); } else { linq_ = linq_.OrderByDescending(x => x.postday).Skip((page - 1) * paged).Take(paged); } var order = linq_.ToList(); if (order == null) { return(Ok(new { result = "查無資料" })); } pagination.total = linq.Count(); pagination.count = order.Count; pagination.per_page = paged; pagination.current_page = page; pagination.total_page = Convert.ToInt16(Math.Ceiling(Convert.ToDouble(pagination.total) / Convert.ToDouble(pagination.per_page))); var result = new { order = order.Select(x => new { x.companyseq, x.roomseq, x.orderseq, orderdates = Convert.ToDateTime(x.orderdates).ToString("yyyy-MM-dd"), orderdatee = Convert.ToDateTime(x.orderdatee).ToString("yyyy-MM-dd"), x.roomname, setdate = Convert.ToDateTime(x.postday).ToString("yyyy-MM-dd HH:mm"), canceldate = Convert.ToDateTime(x.updateday).ToString("yyyy-MM-dd HH:mm"), x.state, btn_Evalution = x.state == (int)Orderstate.已完成 ? true : false, btn_Evalution_readonly = x.Evalution.Count == 0 && x.state == (int)Orderstate.已完成 ? true : false }), meta = pagination }; return(Ok(result)); } }
public IHttpActionResult SpgatewayPayBill(Order order) { string error_message = "下單錯誤,請至伺服器log查詢錯誤訊息"; string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); //後端 判斷日期有沒有被下訂 List <Order> orders = db.Order.Where(x => x.state == (int)Orderstate.已付款 && x.roomseq == order.roomseq).ToList(); //已下的訂單 List <string> date = new List <string>(); //排除的日期 foreach (Order o in orders) { date.AddRange(Utility.Data(o.orderdates.Value, o.orderdatee.Value)); } if (date.Contains(order.orderdates.Value.ToString("yyyy-MM-dd")) || date.Contains(order.orderdatee.Value.ToString("yyyy-MM-dd"))) { error_message = "日期已被下訂"; return(Ok(new { result = error_message })); } Room room = db.Room.Find(order.roomseq); Company company = db.Company.Find(room.companyseq); order.companyseq = room.companyseq; order.companyname = company.companybrand; order.roomname = room.roomname; order.memberseq = userseq; //登入者 流水號 order.country = company.country; order.area = company.area; order.address = company.address; //order.name 前端傳進 //order.tel 前端傳進 //order.pettype //order.petsize //數量前端傳 金額room表拿 //order.petamount order.roomprice = room.roomprice; order.roomamount_amt = room.roomamount_amt; //是否有勾 前端傳 重新回room表拿金額 order.medicine_infeed_amt = room.medicine_infeed_amt; order.medicine_paste_amt = room.medicine_paste_amt; order.medicine_pill_amt = room.medicine_pill_amt; order.bath_amt = room.bath_amt; order.hair_amt = room.hair_amt; order.nails_amt = room.nails_amt; order.state = 0; //未付款 //orderdatee orderdates #region 金額 // 處理金額 TimeSpan s = new TimeSpan(order.orderdatee.Value.Ticks - order.orderdates.Value.Ticks); int amt = 0; amt += (room.roomprice.Value + room.roomamount_amt.Value * (order.petamount.Value - 1)) * (s.Days + 1); //每間金額 * 天數 //隻 * 每隻金額 if (order.medicine_infeed.Value) //判斷藥 { amt = amt + room.medicine_infeed_amt.Value * (order.petamount.Value); } if (order.medicine_paste.Value) { amt = amt + room.medicine_paste_amt.Value * (order.petamount.Value); } if (order.medicine_pill.Value) { amt = amt + room.medicine_pill_amt.Value * (order.petamount.Value); } if (order.bath.Value) //判斷加購 { amt = amt + room.bath_amt.Value * (order.petamount.Value); } if (order.hair.Value) { amt = amt + room.hair_amt.Value * (order.petamount.Value); } if (order.nails.Value) { amt = amt + room.nails_amt.Value * (order.petamount.Value); } //amt += room.roomprice.Value * (s.Days+1); //amt += order.petamount.Value * room.roomamount_amt.Value; //隻 * 每隻金額 #endregion order.amt = amt; order.postday = DateTime.Now; order.del_flag = "N"; db.Order.Add(order); ModelState.Clear(); Validate(order); if (!ModelState.IsValid) { Utility.log("下單 pay/Getinfo", ModelState.ToString()); return(Ok(new { result = error_message })); } db.SaveChanges(); string version = "1.5"; // 目前時間轉換 +08:00, 防止傳入時間或Server時間時區不同造成錯誤 DateTimeOffset taipeiStandardTimeOffset = DateTimeOffset.Now.ToOffset(new TimeSpan(8, 0, 0)); TradeInfo tradeInfo = new TradeInfo() { // * 商店代號 MerchantID = _bankInfoModel.MerchantID, // * 回傳格式 RespondType = "String", // * TimeStamp TimeStamp = taipeiStandardTimeOffset.ToUnixTimeSeconds().ToString(), // * 串接程式版本 Version = version, // * 商店訂單編號 //MerchantOrderNo = $"T{DateTime.Now.ToString("yyyyMMddHHmm")}", MerchantOrderNo = order.orderseq, // * 訂單金額 Amt = order.amt.Value, // * 商品資訊 ItemDesc = "pertrip交易訂單" + order.orderseq, // 繳費有效期限(適用於非即時交易) ExpireDate = null, // 支付完成 返回商店網址 ReturnURL = _bankInfoModel.ReturnURL, // 支付通知網址 NotifyURL = _bankInfoModel.NotifyURL, // 商店取號網址 CustomerURL = _bankInfoModel.CustomerURL, // 支付取消 返回商店網址 ClientBackURL = null, // * 付款人電子信箱 Email = string.Empty, // 付款人電子信箱 是否開放修改(1=可修改 0=不可修改) EmailModify = 0, // 商店備註 OrderComment = null, // 信用卡 一次付清啟用(1=啟用、0或者未有此參數=不啟用) CREDIT = null, // WEBATM啟用(1=啟用、0或者未有此參數,即代表不開啟) WEBATM = null, // ATM 轉帳啟用(1=啟用、0或者未有此參數,即代表不開啟) VACC = null, // 超商代碼繳費啟用(1=啟用、0或者未有此參數,即代表不開啟)(當該筆訂單金額小於 30 元或超過 2 萬元時,即使此參數設定為啟用,MPG 付款頁面仍不會顯示此支付方式選項。) CVS = null, // 超商條碼繳費啟用(1=啟用、0或者未有此參數,即代表不開啟)(當該筆訂單金額小於 20 元或超過 4 萬元時,即使此參數設定為啟用,MPG 付款頁面仍不會顯示此支付方式選項。) BARCODE = null }; //暫定都信用卡 tradeInfo.CREDIT = 1; //if (string.Equals(payType, "CREDIT")) //{ // tradeInfo.CREDIT = 1; //} //else if (string.Equals(payType, "WEBATM")) //{ // tradeInfo.WEBATM = 1; //} //else if (string.Equals(payType, "VACC")) //{ // // 設定繳費截止日期 // tradeInfo.ExpireDate = taipeiStandardTimeOffset.AddDays(1).ToString("yyyyMMdd"); // tradeInfo.VACC = 1; //} //else if (string.Equals(payType, "CVS")) //{ // // 設定繳費截止日期 // tradeInfo.ExpireDate = taipeiStandardTimeOffset.AddDays(1).ToString("yyyyMMdd"); // tradeInfo.CVS = 1; //} //else if (string.Equals(payType, "BARCODE")) //{ // // 設定繳費截止日期 // tradeInfo.ExpireDate = taipeiStandardTimeOffset.AddDays(1).ToString("yyyyMMdd"); // tradeInfo.BARCODE = 1; //} Atom <string> result = new Atom <string>() { IsSuccess = true }; var inputModel = new SpgatewayInputModel { MerchantID = _bankInfoModel.MerchantID, Version = version }; // 將model 轉換為List<KeyValuePair<string, string>>, null值不轉 List <KeyValuePair <string, string> > tradeData = LambdaUtil.ModelToKeyValuePairList <TradeInfo>(tradeInfo); // 將List<KeyValuePair<string, string>> 轉換為 key1=Value1&key2=Value2&key3=Value3... var tradeQueryPara = string.Join("&", tradeData.Select(x => $"{x.Key}={x.Value}")); // AES 加密 inputModel.TradeInfo = CryptoUtil.EncryptAESHex(tradeQueryPara, _bankInfoModel.HashKey, _bankInfoModel.HashIV); // SHA256 加密 inputModel.TradeSha = CryptoUtil.EncryptSHA256($"HashKey={_bankInfoModel.HashKey}&{inputModel.TradeInfo}&HashIV={_bankInfoModel.HashIV}"); // 將model 轉換為List<KeyValuePair<string, string>>, null值不轉 List <KeyValuePair <string, string> > postData = LambdaUtil.ModelToKeyValuePairList <SpgatewayInputModel>(inputModel); return(Ok(postData)); }
public IHttpActionResult GetOne()//改token不是id { //拿已登入的流水 string token = Request.Headers.Authorization.Parameter; JwtAuthUtil jwtAuthUtil = new JwtAuthUtil(); string userseq = jwtAuthUtil.Getuserseq(token); Company company = db.Company.Find(userseq); if (company == null) { return(Ok(new { result = "查無資料" })); } CompanyGetone companyGetone = new CompanyGetone(); companyGetone.companyseq = company.companyseq; companyGetone.companyname = company.companyname; companyGetone.companybrand = company.companybrand; companyGetone.phone = company.phone; companyGetone.email = company.email; companyGetone.country = company.country; companyGetone.area = company.area; companyGetone.address = company.address; companyGetone.pblicense = company.pblicense; if (company.effectivedate.HasValue) { companyGetone.effectivedate = Convert.ToDateTime(company.effectivedate.Value).ToString("yyyy-MM-dd"); } companyGetone.introduce = company.introduce is null ? "" : company.introduce; companyGetone.morning = Convert.ToBoolean(company.morning); companyGetone.afternoon = Convert.ToBoolean(company.afternoon); companyGetone.night = Convert.ToBoolean(company.night); companyGetone.midnight = Convert.ToBoolean(company.midnight); companyGetone.avatar = company.avatar is null ? "" : company.avatar;; companyGetone.bannerimg = company.bannerimg is null ? "" : company.bannerimg;; //#region 讀取圖片banner //if (!Directory.Exists(HttpContext.Current.Server.MapPath("/") + @"/Images/company_Banner/" + company.companyseq)) //{ // //新增資料夾 // Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/") + @"/Images/company_Banner/" + company.companyseq); //} //DirectoryInfo di = new DirectoryInfo(HttpContext.Current.Server.MapPath("/") + @"/Images/company_Banner/" + company.companyseq); //FileInfo[] fi = di.GetFiles(); //DataTable dt = new DataTable(); //DataColumn dcFilename = new DataColumn("strFilename", Type.GetType("System.String")); //dt.Columns.Add(dcFilename); //Object[] data = new object[1]; //foreach (FileInfo file in fi) //{ // data[0] = file.Name; // dt.Rows.Add(data); //} //#endregion ////banner 圖片 //if (dt.Rows.Count > 0) // companyGetone.imgurl = "http://pettrip.rocket-coding.com/Images/company_Banner/" + company.companyseq + "/" + dt.Rows[0]["strFilename"]; //#region 讀取圖片廠商大頭 //if (!Directory.Exists(HttpContext.Current.Server.MapPath("/") + @"/Images/company_Avatar/" + company.companyseq)) //{ // //新增資料夾 // Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/") + @"/Images/company_Avatar/" + company.companyseq); //} //di = new DirectoryInfo(HttpContext.Current.Server.MapPath("/") + @"/Images/company_Avatar/" + company.companyseq); //fi = di.GetFiles(); //dt = new DataTable(); //dcFilename = new DataColumn("strFilename", Type.GetType("System.String")); //dt.Columns.Add(dcFilename); //data = new object[1]; //foreach (FileInfo file in fi) //{ // data[0] = file.Name; // dt.Rows.Add(data); //} //#endregion //if (dt.Rows.Count > 0) // companyGetone.avatar = "http://pettrip.rocket-coding.com/Images/company_Avatar/" + company.companyseq + "/" + dt.Rows[0]["strFilename"]; return(Ok(companyGetone)); }