logicalDelOrder.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package order
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/date"
  5. "context"
  6. "fmt"
  7. "github.com/gogf/gf/v2/frame/g"
  8. "io/ioutil"
  9. "jyOrderManager/internal/model"
  10. "k8s.io/apimachinery/pkg/util/json"
  11. "log"
  12. "net/http"
  13. "net/url"
  14. "strconv"
  15. )
  16. // OrderLogicalDelOrder 删除
  17. func OrderLogicalDelOrder(ctx context.Context, param model.OrderCopyLinkParams) (interface{}, error) {
  18. ok := true
  19. _, err := g.DB().Ctx(ctx).Update(ctx, "dataexport_order", map[string]interface{}{"del_status": 1, "del_time": date.NowFormat(date.Date_Full_Layout), "last_update_time": date.NowFormat(date.Date_Full_Layout)}, map[string]interface{}{"id": param.Id})
  20. if err == nil {
  21. orderData, _ := g.DB().Ctx(ctx).GetOne(ctx, fmt.Sprintf("SELECT * FROM dataexport_order WHERE id =%s", param.Id))
  22. if !orderData.IsEmpty() {
  23. userId := common.ObjToString(orderData.Map()["user_id"])
  24. disRelationId := common.ObjToString(orderData.Map()["d_relation_id"])
  25. orderStatus := common.IntAll(orderData.Map()["order_status"])
  26. if orderStatus != 1 {
  27. //调用活动中台,释放优惠券
  28. ok = UpdateCouponState(userId, disRelationId, 0)
  29. }
  30. } else {
  31. ok = false
  32. }
  33. }
  34. return map[string]interface{}{
  35. "status": ok,
  36. }, nil
  37. }
  38. // UpdateCouponState 更新当前卡卷状态model: 1使用、3待使用、0未使用 productType: 商品类型0普通的1线上课程 useProduct:产品名称 discountId:满赠id
  39. func UpdateCouponState(userId, userLotteryId string, model int) (b bool) {
  40. data := url.Values{
  41. "userId": []string{userId},
  42. "appId": []string{"10000"},
  43. "userLotteryId": []string{userLotteryId},
  44. "model": []string{strconv.Itoa(model)},
  45. }
  46. log.Println("参数:", data)
  47. // g.Cfg().MustGet(context.Background(), "couponUpdate").string()
  48. res, err := http.PostForm(g.Cfg().MustGet(context.Background(), "couponUpdate").String(), data)
  49. if err != nil {
  50. log.Println(err.Error())
  51. return false
  52. }
  53. defer res.Body.Close()
  54. bs, _ := ioutil.ReadAll(res.Body)
  55. resMap := map[string]interface{}{}
  56. err = json.Unmarshal(bs, &resMap)
  57. if err != nil {
  58. log.Println("json.unmarshal err", resMap)
  59. } else {
  60. if common.IntAll(resMap["Code"]) == 1 {
  61. b = true
  62. }
  63. }
  64. return b
  65. }