personService.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package user
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "fmt"
  6. "github.com/gogf/gf/v2/frame/g"
  7. "github.com/gogf/gf/v2/util/gconv"
  8. "jyOrderManager/internal/jyutil"
  9. "jyOrderManager/internal/logic/product"
  10. "jyOrderManager/internal/model"
  11. )
  12. func OrderUserChangePhone(ctx context.Context, param model.UserServiceParams) (interface{}, error) {
  13. buySubject, _ := g.DB().GetCount(ctx, fmt.Sprintf(`SELECT * FROM dataexport_order WHERE order_code = '%s' and buy_subject =1`, param.OrderCode))
  14. if buySubject == 0 {
  15. return nil, nil
  16. }
  17. userData, _ := jyutil.MG.DB().FindOne("user", map[string]interface{}{
  18. "$or": []map[string]interface{}{
  19. {"s_phone": param.Phone},
  20. {"s_m_phone": param.Phone},
  21. },
  22. })
  23. if userData == nil || len(*userData) == 0 {
  24. return nil, nil
  25. }
  26. order, _ := g.DB().Query(ctx, fmt.Sprintf(`SELECT * FROM jy_order_detail WHERE order_code = '%s' and status =1 `, param.OrderCode))
  27. if order.IsEmpty() {
  28. return nil, nil
  29. }
  30. for _, tParam := range order.List() {
  31. //参数注入
  32. tParam["phone"] = param.Phone //开通手机号
  33. tParam["order_code"] = param.OrderCode //订单号
  34. tParam["reqSubject"] = 1 //购买主体
  35. productCode := gconv.String(tParam["product_code"])
  36. pFunc, pErr := product.JyProFunc.GetProductInitFuncByCode(productCode)
  37. if pErr != nil {
  38. return nil, pErr
  39. }
  40. pObj, pErr := pFunc(tParam)
  41. if pErr != nil {
  42. return nil, pErr
  43. }
  44. var (
  45. actCode = gconv.String(tParam["activityCode"]) //活动code
  46. checkCode = common.If(actCode != "", 2, 1).(int) //1:普通商品 2:活动商品
  47. )
  48. if err := pObj.Check(ctx, checkCode); err != nil {
  49. return nil, err
  50. }
  51. }
  52. return nil, nil
  53. }