From cd7e397ff5fd9e6f8d3f5ab3d195950c8bca54a7 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Fri, 24 Apr 2020 15:04:42 +0800 Subject: [PATCH] order --- controllers/client/good.go | 50 ++++++++++++++++++++++++++++++++--------- models/customer_order.go | 10 +++++---- models/customer_order_option.go | 21 ++++++++--------- models/customer_order_sub.go | 2 +- 4 files changed, 57 insertions(+), 26 deletions(-) diff --git a/controllers/client/good.go b/controllers/client/good.go index d6507aa..fb2b14f 100644 --- a/controllers/client/good.go +++ b/controllers/client/good.go @@ -7,6 +7,7 @@ import ( "hudongzhuanjia/models" pay_service "hudongzhuanjia/services/pay" "hudongzhuanjia/utils/code" + "strings" "time" ) @@ -46,28 +47,38 @@ func (t *GoodCtl) ListGood() { goods, err := models.GetGoodsByActivityId(activityId, areaId) t.CheckErr(err) - // - //for index := range goods { - // goods[index].GoodType = option.PostFeeType - // goods[index].Postage = option.PostFee - //} + + for index := range goods { + goods[index].GoodType = option.PostFeeType + goods[index].Postage = option.PostFee + } t.JSON(goods) return } func (t *GoodCtl) ListOrder() { activityId := t.MustGetInt64("activity_id") - status := t.MustGetInt("status") + status := t.MustGet("status") areaId := t.MustGetInt64("area_id") uid := t.MustGetUID() + statusList := strings.Split(status, ",") + activity := new(models.Activity) exist, err := models.GetById(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") + option := new(models.CustomerOrderOption) + exist, err = option.GetByActivityId(activityId) + t.CheckErr(err) + if !exist { + t.JSON([]interface{}{}) + return + } + orders, err := models.GetCustomerOrdersByActivityId(uid, activity.Id, activity.RehearsalId, - areaId, status, t.Page, t.PageSize) + areaId, statusList, t.Page, t.PageSize) t.CheckErr(err) outTradeNos := make([]string, 0) for _, order := range orders { @@ -76,6 +87,7 @@ func (t *GoodCtl) ListOrder() { subs, err := models.GetCustomerOrderSubByOutTradeNos(outTradeNos) t.CheckErr(err) for index, order := range orders { + order.ServicePhone = option.MainServicePhone for _, sub := range subs { if order.OutTradeNo == sub["out_trade_no"] { orders[index].SubOrders = append(orders[index].SubOrders, sub) @@ -182,7 +194,7 @@ func (t *GoodCtl) Order() { t.CheckErr(err) } - order := &models.CustomerOrder{ + order := models.CustomerOrder{ IsDelete: false, CreatedAt: time.Now(), UpdatedAt: time.Now(), @@ -209,14 +221,14 @@ func (t *GoodCtl) Order() { //ExpressName: "", //ExpressNo: "", //CancelTime: time.Time{}, - AutoReceiveTime: time.Now().AddDate(0, 0, 15), + //AutoReceiveTime: time.Now().AddDate(0, 0, 15), //OrderTime: time.Now(), //Good: nil, //User: nil, //OrderEntryPersonName: "", //SubOrders: nil, } - _, err = session.InsertOne(order) + _, err = session.InsertOne(&order) if err != nil { session.Rollback() t.CheckErr(err) @@ -259,13 +271,14 @@ func (t *GoodCtl) RefundOrder() { } else if order.Status == 3 { _, err = order.UpdateStatusBy(outTradeNo, 3, 7) } else { - t.ERROR("订单完成状态不能申请退款", code.MSG_CUSTOMER_ORDER_ERROR) + t.ERROR("订单非已支付或者已发货状态不能申请退款", code.MSG_CUSTOMER_ORDER_ERROR) return } t.CheckErr(err) t.SUCCESS("成功申请退款") } +// 取消订单 func (t *GoodCtl) CancelOrder() { outTradeNo := t.MustGet("out_trade_no") @@ -280,3 +293,18 @@ func (t *GoodCtl) CancelOrder() { t.CheckErr(err) t.SUCCESS("成功取消订单") } + +func (t *GoodCtl) VerifyOrder() { + outTradeNo := t.MustGet("out_trade_no") + + order := new(models.CustomerOrder) + exist, err := order.GetByOutTradeNO(outTradeNo) + t.CheckErr(err) + t.Assert(exist, code.MSG_CUSTOMER_ORDER_NOT_EXIST, "用户订单不存在") + if order.Status != 3 && order.Status != 1 { + t.ERROR("非已支付或已发货状态不能确认", code.MSG_CUSTOMER_ORDER_ERROR) + } + _, err = order.UpdateStatusBy(outTradeNo, 3, 4) + t.CheckErr(err) + t.SUCCESS("成功确认已收货") +} diff --git a/models/customer_order.go b/models/customer_order.go index 409a267..f9a0eb4 100644 --- a/models/customer_order.go +++ b/models/customer_order.go @@ -45,6 +45,7 @@ type CustomerOrder struct { Good *CustomerGoods `json:"good,omitempty" xorm:"-"` User *User `json:"user,omitempty" xorm:"-"` OrderEntryPersonName string `json:"order_entry_person_name,omitempty" xorm:"-"` + ServicePhone string `json:"service_phone" xorm:"-"` // 无关变量 SubOrders []map[string]string `json:"sub_orders,omitempty" xorm:"-"` @@ -72,16 +73,17 @@ func (t *CustomerOrder) Count(activityId, rehearsalId int64, limitTime time.Time limitTime, activityId, rehearsalId).Count(t) } -func GetCustomerOrdersByActivityId(userId, activityId, rehearsalId, areaId int64, status, page, pageSize int) ([]*CustomerOrder, error) { +func GetCustomerOrdersByActivityId(userId, activityId, rehearsalId, areaId int64, status []string, page, pageSize int) ([]*CustomerOrder, error) { orders := make([]*CustomerOrder, 0) err := core.GetXormAuto().Where("is_delete=0 and buyer_id=? and activity_id=? and "+ - "rehearsal_id=? and area_id=? and status=?", userId, activityId, rehearsalId, areaId, status). - Asc("created_at").Limit(pageSize, page*pageSize).Find(&orders) + "rehearsal_id=? and area_id=?", userId, activityId, rehearsalId, areaId).In("status", status). + Desc("created_at").Limit(pageSize, page*pageSize).Find(&orders) return orders, err } func (t *CustomerOrder) UpdateStatusBy(outTradeNo string, originStatus, status int) (int64, error) { t.Status = status + t.CancelTime = time.Now() return core.GetXormAuto().Where("is_delete=0 and status=? and out_trade_no=?", - originStatus, outTradeNo).Cols("status").Update(t) + originStatus, outTradeNo).Cols("status, cancel_time").Update(t) } diff --git a/models/customer_order_option.go b/models/customer_order_option.go index 23c38c8..430abb2 100644 --- a/models/customer_order_option.go +++ b/models/customer_order_option.go @@ -9,16 +9,17 @@ import ( const CustomerOrderOptionTableName = TableNamePrefix + "customer_order_option" type CustomerOrderOption struct { - Id int64 `json:"id" xorm:"not null pk INT(11)"` - ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` - SettingBox string `json:"setting_box" xorm:"not null comment('json格式 选中的表单项') TEXT"` - SelfBox string `json:"self_box" xorm:"not null comment('json格式 邀请函选中的表单项') TEXT"` - Status int `json:"status" xorm:"not null default 0 comment('订单活动的开启1|关闭0') TINYINT(1)"` - PostFeeType int `json:"post_fee_type" xorm:"not null default 0 comment('直播订单运费设置0包邮1货到付款2收费') TINYINT(1)"` - PostFee float64 `json:"post_fee" xorm:"not null default 0.00 comment('直播订单运费') DECIMAL(18)"` - IsDelete int `json:"-" xorm:"not null default 0 comment('删除') TINYINT(1)"` - CreatedAt time.Time `json:"-" xorm:"created"` - UpdatedAt time.Time `json:"-" xorm:"updated"` + Id int64 `json:"id" xorm:"not null pk INT(11)"` + ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('互动id') INT(11)"` + SettingBox string `json:"setting_box" xorm:"not null comment('json格式 选中的表单项') TEXT"` + SelfBox string `json:"self_box" xorm:"not null comment('json格式 邀请函选中的表单项') TEXT"` + Status int `json:"status" xorm:"not null default 0 comment('订单活动的开启1|关闭0') TINYINT(1)"` + PostFeeType int `json:"post_fee_type" xorm:"not null default 0 comment('直播订单运费设置0包邮1货到付款2收费') TINYINT(1)"` + PostFee float64 `json:"post_fee" xorm:"not null default 0.00 comment('直播订单运费') DECIMAL(18)"` + MainServicePhone string `json:"main_service_phone" xorm:"not null default '' comment('客服电话') VARCHAR(128)"` + IsDelete int `json:"-" xorm:"not null default 0 comment('删除') TINYINT(1)"` + CreatedAt time.Time `json:"-" xorm:"created"` + UpdatedAt time.Time `json:"-" xorm:"updated"` } func (t *CustomerOrderOption) TableName() string { diff --git a/models/customer_order_sub.go b/models/customer_order_sub.go index 5bcebbd..db6cbf7 100644 --- a/models/customer_order_sub.go +++ b/models/customer_order_sub.go @@ -37,6 +37,6 @@ func GetCustomerOrderSubByOutTradeNos(outTradeNos []string) (subs []map[string]s Select("s.out_trade_no, s.goods_id, s.goods_num, s.good_name, s.good_price, g.goods_pic_url").Join("left", new(CustomerGoods).Alias("g"), "g.id=s.goods_id"). Where("s.is_delete=0").In("s.out_trade_no", outTradeNos). - Asc("s.created_at").Find(&subs) + Desc("s.created_at").Find(&subs) return }