|
@@ -0,0 +1,55 @@
|
|
|
+package order
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "errors"
|
|
|
+ "fmt"
|
|
|
+ "github.com/gogf/gf/v2/errors/gerror"
|
|
|
+ "github.com/gogf/gf/v2/frame/g"
|
|
|
+ "github.com/gogf/gf/v2/util/gconv"
|
|
|
+ "jyOrderManager/internal/jyutil"
|
|
|
+ "jyOrderManager/internal/logic/product"
|
|
|
+ "jyOrderManager/internal/model"
|
|
|
+)
|
|
|
+
|
|
|
+func ServiceOpen(ctx context.Context, param model.OrderOpenServiceParams) error {
|
|
|
+ //查询订单
|
|
|
+ orderData, _ := g.DB().GetOne(ctx, fmt.Sprintf("select * from dataexport_order where order_code ='%s'", param.OrderCode))
|
|
|
+ if orderData.IsEmpty() {
|
|
|
+ return errors.New("为查询到订单信息")
|
|
|
+ }
|
|
|
+
|
|
|
+ if gconv.String(orderData.Map()["user_phone"]) != param.Phone {
|
|
|
+ g.DB().Update(ctx, "dataexport_order", map[string]interface{}{
|
|
|
+ "user_phone": param.Phone,
|
|
|
+ }, map[string]interface{}{
|
|
|
+ "order_code": param.OrderCode,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ productDetail, err := g.DB().Ctx(ctx).Query(ctx, fmt.Sprintf(`SELECT * FROM jy_order_detail WHERE order_code ='%s'`, param.OrderCode))
|
|
|
+ if err != nil || productDetail.IsEmpty() {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ // 产品服务开通
|
|
|
+ for _, m := range productDetail.List() {
|
|
|
+ if !jyutil.IsServiceOpen(m) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ //参数注入
|
|
|
+ m["phone"] = param.Phone
|
|
|
+ m["order_code"] = param.OrderCode
|
|
|
+ productCode := gconv.String(m["product_code"])
|
|
|
+ pFunc, err := product.JyProFunc.GetProductInitFuncByCode(productCode)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ pObj, err := pFunc(m)
|
|
|
+ if err != nil {
|
|
|
+ return gerror.Wrap(err, fmt.Sprintf("获取%s商品异常", productCode))
|
|
|
+ }
|
|
|
+ if err := pObj.OpenService(ctx); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|