Explorar o código

自提订单支付处理

abiao %!s(int64=4) %!d(string=hai) anos
pai
achega
1968f9c9d1

+ 41 - 12
go/gopath/src/fohow.com/apps/controllers/pay_controller/pay_exchange_controller.go

@@ -40,11 +40,37 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
 	wxUId := self.GetCurrentWxUserId()
 	uId := self.GetCurrentUserId()
 
-	//地址
-	addressId, _ := self.GetInt64("address_id")
-	address := address_model.GetUserAddressById(addressId)
-	if address == nil || address.WxUserId != wxUId {
-		self.ReturnError(403, apps.AddressNotMatch, "", nil)
+	var concat string
+	var tel string
+	var addr string
+	pick_dept, _ := self.GetInt64("pick_dept")
+	pick_way, _ := self.GetInt64("pick_way")
+	if pick_way == order_model.PICK_EXPRESS {
+		//地址
+		addressId, _ := self.GetInt64("address_id")
+		address := address_model.GetUserAddressById(addressId)
+		//beego.BeeLogger.Warn("address.wxuserId--%d", address.WxUserId)
+		beego.BeeLogger.Warn("wxUId-%d", wxUId)
+
+		if address == nil || address.WxUserId != wxUId {
+			self.ReturnError(403, apps.AddressNotMatch, "", nil)
+		}
+		concat = address.Contact
+		tel = address.Tel
+		addr = fmt.Sprintf("%s%s%s%s", address.Province, address.City, address.District, address.Address)
+
+	} else {
+		//物流方式
+		pick_addr_id, _ := self.GetInt64("pick_addr_id")
+		pick_address := address_model.GetUserPickAddressById(pick_addr_id)
+		pick_dept := user_model.GetDepartRecordById(pick_dept, true)
+		if pick_dept == nil || pick_address == nil || pick_address.WxUserId != wxUId {
+			self.ReturnError(403, apps.AddressNotMatch, "", nil)
+		}
+
+		concat = pick_address.Contact
+		tel = pick_address.Tel
+		addr = pick_dept.PickAddress
 	}
 
 	if source != order_model.SOURCE_XCX && source != order_model.SOURCE_GZH {
@@ -133,9 +159,9 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
 
 		order.Remark = remark
 		order.PayWay = payWay
-		order.Contact = address.Contact
-		order.Tel = address.Tel
-		order.Address = fmt.Sprintf("%s%s%s%s", address.Province, address.City, address.District, address.Address)
+		order.Contact = concat
+		order.Tel = tel
+		order.Address = addr
 		order.BuyPrice = buy_price_total
 		order.TotalPrice = total_price
 		//支付信息判断
@@ -154,7 +180,7 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
 		userLeftBalanceCount := balance_model.GetUserTotalBalance(wxUId)
 		tp := order.TotalPrice
 		freight := sys_config.GetFreight()
-		if tp >= sys_config.GetOrderLimit() {
+		if tp >= sys_config.GetOrderLimit() || pick_way == order_model.PICK_SHOP {
 			freight = int64(0)
 		}
 		tp += freight
@@ -166,6 +192,9 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
 				totalCoupon = tp
 			}
 		}
+		order.Freight = freight
+		order.PickDept = pick_dept
+		order.PickWay = pick_way
 		//先扣减提货券
 		if totalCoupon > 0 {
 			source := balance_model.BALANCE_SOURCE_EXCHANGE_PRODUCT
@@ -200,10 +229,10 @@ func (self *PayController) payExchange(oId, payWay, tradPwd, returnUrl, source,
 			//self.Data["json"] = self.FormatResult([]interface{}{result})
 			self.Data["json"] = result
 		case true: // 微信支付
-			order.Contact = address.Contact
+			order.Contact = concat
+			order.Tel = tel
+			order.Address = addr
 			order.PaiedPrice = tp - totalCoupon
-			order.Tel = address.Tel
-			order.Address = fmt.Sprintf("%s%s%s%s", address.Province, address.City, address.District, address.Address)
 			order.Source = source
 			order.Save()
 			if order.Source == order_model.SOURCE_XCX { //小程序微信支付

+ 6 - 0
go/gopath/src/fohow.com/apps/models/order_model/order.go

@@ -58,6 +58,10 @@ const (
 	SHOP_BENETFIT_BL = float64(0.08)
 
 	ZT_PASSWORD = "pQtIjP"
+
+	//物流类型 0:快递运输, 1:门店自提
+	PICK_EXPRESS = int64(0)
+	PICK_SHOP    = int64(1)
 )
 
 var STATUS_CN_TEXT = map[string]string{
@@ -107,6 +111,8 @@ type Order struct {
 	Freight        int64              `orm:"column(freight);null"                            json:"freight"`              // int(11)
 	Depart         int64              `orm:"column(depart)" json:"-"`                                                     // datetime
 	Pv             int64              `orm:"column(pv)"            json:"pv"`                                             // varchar(255)
+	PickWay        int64              `orm:"column(pick_way)"            json:"pick_way"`                                 // 物流方式
+	PickDept       int64              `orm:"column(pick_dept)"           json:"pick_dept"`                                // 自提部门
 	DispatchTime   time.Time          `orm:"column(dispatch_time);null;type(datetime)"           json:"dispatch_time"`
 	ReceiveTime    time.Time          `orm:"column(receive_time);null;type(datetime)"            json:"receive_time"`
 	PaiedTime      time.Time          `orm:"column(paied_time);null;type(datetime)"              json:"paied_time"` // int(11)

+ 20 - 1
go/gopath/src/fohow.com/apps/models/user_model/three_wx_user.go

@@ -35,7 +35,7 @@ type DepartRecord struct {
 	InnerNo     string    `orm:"inner_no"                                       json:"-"`          // varchar(100)
 	Pick        bool      `orm:"column(pick)"             json:"pick"`                             // int(11)
 	PickTitle   string    `orm:"column(pick_title)"       json:"pick_title"`                       // int(11)
-	PickAddress bool      `orm:"column(pick_address)"         json:"pick_address"`                 // int(11)
+	PickAddress string    `orm:"column(pick_address)"         json:"pick_address"`                 // int(11)
 	CreatedAt   time.Time `orm:"column(created_at);auto_now_add;type(datetime)" json:"-"`          // datetime
 	UpdatedAt   time.Time `orm:"column(updated_at);auto_now;type(datetime)"     json:"-"`          // datetime
 }
@@ -63,6 +63,25 @@ func GetDepartRecords() (list []*DepartRecord) {
 	return list
 }
 
+func GetDepartRecordById(id int64, useCache bool) *DepartRecord {
+	k := fmt.Sprintf("user_model.GetDepartRecordById(%d)", id)
+	if useCache {
+		if usr, ok := cache.Cache.Get(k).(*DepartRecord); ok {
+			return usr
+		}
+	}
+	usr := new(DepartRecord)
+	o := orm.NewOrm()
+	err := o.QueryTable(usr).Filter("id", id).Limit(1).One(usr)
+	if err != nil {
+		beego.Debug("GetDepartRecordById(%d), err=[%s]", id, err)
+		return nil
+	} else {
+		cache.Cache.Put(k, usr, 24*time.Hour)
+		return usr
+	}
+}
+
 func GetPickDepartList(sort string) (items []*DepartRecord) {
 	o := orm.NewOrm()
 	orderBy := fmt.Sprintf("-%s", sort)