refund.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package service
  2. import (
  3. "encoding/json"
  4. "database/sql"
  5. "time"
  6. . "bp.jydev.jianyu360.cn/BaseService/orderCenter/entity"
  7. "bp.jydev.jianyu360.cn/BaseService/orderCenter/rpc/ordercenter"
  8. )
  9. func RefundAdd(this *ordercenter.RefundAddReq) *ordercenter.OrderAddUpdateResp {
  10. flag := false
  11. nowTime := time.Now().Format("2006-01-02 15:04:05")
  12. flag = Mysql.ExecTx("", func(tx *sql.Tx) bool {
  13. refundId := Mysql.InsertBySqlByTx(tx, `insert into `+OrderRefund+`(appid,order_code,refund_time,refund_money,refund_reason,operate_person,refund_channel) values (?,?,?,?,?,?,?)`,
  14. this.Appid, this.OrderCode, nowTime, this.Refund.RefundMoney, this.Refund.RefundReason, this.Refund.OperatePerson, this.Refund.RefundChannel)
  15. ok := Mysql.UpdateByTx(tx, Order, map[string]interface{}{"appid": this.Appid, "order_code": this.OrderCode}, map[string]interface{}{"refund_status": this.RefundStatus})
  16. return refundId > 0 && ok
  17. })
  18. status := 0
  19. if flag {
  20. status = 1
  21. }
  22. return &ordercenter.OrderAddUpdateResp{
  23. ErrorCode: 1,
  24. Data: &ordercenter.DataStatus{Status: int64(status)},
  25. }
  26. }
  27. func RefundInfo(this *ordercenter.OrderInfoReq) *ordercenter.RefundInfoResp {
  28. refundList := []*ordercenter.Refund{}
  29. refund := Mysql.Find(OrderRefund, map[string]interface{}{"appid": this.Appid, "user_id": this.OrderCode}, "", "", 0, 0)
  30. if refund != nil && len(*refund) > 0 {
  31. for _, v := range *refund {
  32. refundData := &ordercenter.Refund{}
  33. refundByte, _ := json.Marshal(v)
  34. json.Unmarshal(refundByte, refundData)
  35. refundList = append(refundList, refundData)
  36. }
  37. }
  38. return &ordercenter.RefundInfoResp{
  39. ErrorCode: 1,
  40. Data: refundList,
  41. }
  42. }