Browse Source

Merge branch 'mfyx_2.0' of http://8.136.199.33:3000/cxzhang/hongze_mfyx into debug

xingzai 1 year ago
parent
commit
8b6156610f

+ 1 - 1
controllers/activity.go

@@ -568,7 +568,7 @@ func (this *ActivityCoAntroller) Detail() {
 			} else {
 				resp.GoodsList = services.GetGoodsInfoByActivity(activityInfo) //单场活动信息
 				fmt.Println("activityId", activityId)
-				_, resp.PayTimeCountdown = services.GetHaverEquallyOrderByUser10MinByActivty(uid, activityId) //截止支付时间倒计时
+				resp.OrderCode, resp.PayTimeCountdown = services.GetHaverEquallyOrderByUser10MinByActivty(uid, activityId) //截止支付时间倒计时
 			}
 			for _, v := range resp.GoodsList {
 				resp.PopupPriceMsg += v.PopupPriceMsg //价格弹窗信息

+ 46 - 0
controllers/order.go

@@ -369,3 +369,49 @@ func (this *OrderController) OrderDetail() {
 	br.Success = true
 	br.Msg = "获取成功"
 }
+
+// @Title 通过活动创建订单
+// @Description 通过活动创建订单接口
+// @Param	request	body models.ActivitySingnupRep true "type json string"
+// @Success Ret=200 {object} models.SignupStatus
+// @router /cancel [post]
+func (this *OrderController) Cancel() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	var req order.CygxOrderCancelReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	orderCode := req.OrderCode
+	orderDetail, err := order.GetCygxOrderDetailByOrderCode(orderCode)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+
+	err = order.CancelCygxOrder(orderDetail)
+	if err != nil {
+		br.Msg = "取消订单失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 2 - 2
controllers/wechat.go

@@ -457,12 +457,12 @@ func (this *WechatCommonController) WxpayNotify() {
 	item.CreateTime = time.Now()
 	//item.Body = jsonCompany
 	item.Result = string(body)
-	go models.AddCygxShanghaiCompanyLog(item)
+	//go models.AddCygxShanghaiCompanyLog(item)
 	itemNotify := services.WxDecodeNotify(body)
 	if itemNotify.OutTradeNo != "" {
 		go services.HandleOrderHandle(itemNotify)
 	}
-	//br.Data = itemNotify
+	br.Data = itemNotify
 	br.Ret = 200
 	br.Success = true
 }

+ 1 - 0
models/activity.go

@@ -261,6 +261,7 @@ type CygxActivityResp struct {
 	IsCompanyApply     bool                   `description:"机构是否申请过试用"`
 	IsNeedBusinessCard bool                   `description:"是否需要上传名片"`
 	PayTimeCountdown   int                    `description:"支付时间倒计时"`
+	OrderCode          string                 `comment:"订单编号"`
 	GoodsList          []*order.CygxGoodsResp `description:"商品信息"`
 }
 

+ 7 - 5
models/db.go

@@ -190,10 +190,12 @@ func init() {
 // initOrder 买方研选订单模块
 func initOrder() {
 	orm.RegisterModel(
-		new(order.CygxUserBusinessCard), //用户上传名片
-		new(order.CygxOrder),            //订单表
-		new(order.CygxOrderAction),      //订单操表
-		new(order.CygxOrderUserCard),    //用户持卡表
-		new(order.CygxOrderUserCardLog), //用户持卡日志表
+		new(order.CygxUserBusinessCard),  //用户上传名片
+		new(order.CygxOrder),             //订单表
+		new(order.CygxOrderAction),       //订单操表
+		new(order.CygxOrderUserCard),     //用户持卡表
+		new(order.CygxOrderUserCardLog),  //用户持卡日志表
+		new(order.CygxOrderPayment),      //支付记录表
+		new(order.CygxOrderVirtualAsset), //用户虚拟资产表(所购买的单篇报告,活动等)
 	)
 }

+ 58 - 0
models/order/order.go

@@ -29,6 +29,10 @@ type CygxOrderAddReq struct {
 	SourceId int `description:"资源ID"`
 }
 
+type CygxOrderCancelReq struct {
+	OrderCode string `comment:"订单编号"`
+}
+
 type CygxOrder struct {
 	OrderId          int       `orm:"column(order_id);pk";comment:"订单id"`
 	OrderCode        string    `comment:"订单编号"`
@@ -153,6 +157,9 @@ func AddCygxOrder(item *CygxOrder) (err error) {
 			o.Rollback()
 		}
 	}()
+
+	item.OrderStatus = 1 // 初始状态待支付
+
 	itemOrderAction := new(CygxOrderAction)
 
 	itemOrderAction.Action = "创建订单"
@@ -182,6 +189,57 @@ func AddCygxOrder(item *CygxOrder) (err error) {
 	return
 }
 
+// 添加
+func CancelCygxOrder(item *CygxOrder) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	itemOrderAction := new(CygxOrderAction)
+	itemOrderAction.Action = "取消订单"
+	itemOrderAction.OrderStatus = 0
+	itemOrderAction.OrderStatusText = "已取消"
+	itemOrderAction.OrderCode = item.OrderCode
+	itemOrderAction.UserId = item.UserId
+	itemOrderAction.Mobile = item.Mobile
+	itemOrderAction.Email = item.Email
+	itemOrderAction.CompanyId = item.CompanyId
+	itemOrderAction.CompanyName = item.CompanyName
+	itemOrderAction.RealName = item.RealName
+	itemOrderAction.SellerName = item.SellerName
+	itemOrderAction.CreateTime = time.Now()
+	itemOrderAction.ModifyTime = time.Now()
+	itemOrderAction.RegisterPlatform = item.RegisterPlatform
+
+	_, err = o.Insert(itemOrderAction) // 写入订单操作信息
+	if err != nil {
+		return
+	}
+
+	updateParams := make(map[string]interface{})
+	updateParams["OrderStatus"] = 0
+	updateParams["ModifyTime"] = item.ModifyTime
+	ptrStructOrTableName := "cygx_order"
+	whereParam := map[string]interface{}{"order_code": item.OrderCode}
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	if err != nil {
+		return
+	}
+	return
+}
+
 // 根据订单编号修改
 func UpdateCygxOrder(item *CygxOrder, oldOrderCode string) (err error) {
 	o := orm.NewOrm()

+ 25 - 0
models/order/order_payment.go

@@ -0,0 +1,25 @@
+package order
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxOrderPayment struct {
+	OrderPaymentID int       `orm:"column(order_payment_id);pk";comment:"订单支付ID"`
+	OrderCode      string    `comment:"订单编号"`
+	OutTradeCode   string    `comment:"外部交易号退款使用"`
+	PayBody        string    `comment:"订单支付简介"`
+	PayDetail      string    `comment:"订单支付详情"`
+	PayMoney       float64   `comment:"支付金额"`
+	PayStatus      string    `comment:"支付状态"`
+	CreateTime     time.Time `comment:"创建时间"`
+	PaymentType    int       `comment:"支付类型。取值范围:1微信支付,2支付宝支付。"`
+}
+
+// 添加
+func AddCygxOrderPayment(item *CygxOrderPayment) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item) //回调支付信息
+	return
+}

+ 97 - 0
models/order/order_virtual_asset.go

@@ -0,0 +1,97 @@
+package order
+
+//用户虚拟资产表
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_mfyx/utils"
+	"time"
+)
+
+type CygxOrderVirtualAsset struct {
+	OrderVirtualAssetsId int       `orm:"column(order_virtual_assets_id);pk";comment:"订单支付ID"`
+	OrderCode            string    `comment:"订单编号"`
+	UserId               int       `comment:"用户ID"`
+	Mobile               string    `comment:"手机号"`
+	Email                string    `comment:"邮箱"`
+	CompanyId            int       `comment:"公司ID"`
+	CompanyName          string    `comment:"公司名称"`
+	RealName             string    `comment:"用户实际名称"`
+	SellerName           string    `comment:"所属销售"`
+	CreateTime           time.Time `comment:"创建时间"`
+	ModifyTime           time.Time `comment:"修改时间"`
+	SourceId             int       `comment:"来源ID"`
+	Source               string    `comment:"来源\n报告 :article\n活动 :activity"`
+}
+
+// 添加
+func AddCygxOrderVirtualAsset(item *CygxOrderVirtualAsset, itemOrder *CygxOrder) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+
+	itemOrderAction := new(CygxOrderAction)
+
+	itemOrderAction.Action = "微信小程序已支付"
+	itemOrderAction.OrderStatus = 2
+	itemOrderAction.OrderStatusText = "已支付"
+	itemOrderAction.OrderCode = item.OrderCode
+	itemOrderAction.UserId = item.UserId
+	itemOrderAction.Mobile = item.Mobile
+	itemOrderAction.Email = item.Email
+	itemOrderAction.CompanyId = item.CompanyId
+	itemOrderAction.CompanyName = item.CompanyName
+	itemOrderAction.RealName = item.RealName
+	itemOrderAction.SellerName = item.SellerName
+	itemOrderAction.CreateTime = time.Now()
+	itemOrderAction.ModifyTime = time.Now()
+	itemOrderAction.RegisterPlatform = utils.REGISTER_PLATFORM
+
+	updateParams := make(map[string]interface{})
+	updateParams["PayTime"] = itemOrder.PayTime
+	updateParams["PayMoney"] = itemOrder.PayMoney
+	updateParams["OrderStatus"] = itemOrder.OrderStatus
+	updateParams["OutTradeCode"] = itemOrder.OutTradeCode
+	updateParams["ModifyTime"] = item.ModifyTime
+	updateParams["PaymentType"] = 1
+	ptrStructOrTableName := "cygx_order"
+	whereParam := map[string]interface{}{"order_code": itemOrder.OrderCode}
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams) // 修改订单状态
+	if err != nil {
+		return
+	}
+
+	_, err = o.Insert(itemOrderAction) // 写入订单操作信息
+	if err != nil {
+		return
+	}
+
+	_, err = o.Insert(item) //写入用户用户虚拟资产表
+	if err != nil {
+		return
+	}
+
+	return
+}
+
+// 获取数量
+func GetCygxOrderVirtualAssetdCount(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS  count  FROM cygx_order_virtual_asset WHERE   1= 1  ` + condition
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -322,6 +322,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"] = append(beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"],
+        beego.ControllerComments{
+            Method: "Cancel",
+            Router: `/cancel`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"] = append(beego.GlobalControllerRouter["hongze/hongze_mfyx/controllers:OrderController"],
         beego.ControllerComments{
             Method: "OrderDetail",

+ 16 - 0
services/activity.go

@@ -196,6 +196,7 @@ func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.Ac
 	var companyDetailStatus string
 	var userTypeStr string
 	userId := user.UserId
+	activityId := activityInfo.ActivityId
 	activityPointsByUserAllMap := GetActivityPointsByUserAllMap() // 获取对用户进行研选扣点的活动
 	//勾选【研选扣点】且扣点对象为参会人的活动,需要有买方研选的正式权限
 	if strings.Contains(activityInfo.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) && activityPointsByUserAllMap[activityInfo.ActivityId] {
@@ -208,6 +209,21 @@ func GetActivityDetailUserPower(user *models.WxUserItem, activityInfo *models.Ac
 		return
 	}
 
+	if (!activityInfo.IsResearchPoints && activityInfo.IsLimitPeople == 0) || activityInfo.YidongActivityId != "" { //易董的活动 或者(不扣点且不限制人数)走月卡日卡逻辑
+		//用户是否持有有效卡片
+		userCardTotal := GetCygxOrderUserCardTotal(user.Mobile)
+		if userCardTotal == 1 {
+			havePower = true
+			return
+		}
+	} else {
+		activtyPayTotal := GetCygxOrderVirtualAssetdCountTotal(user.Mobile, activityId)
+		if activtyPayTotal == 1 {
+			havePower = true
+			return
+		}
+	}
+
 	userType, permissionStr, permissionStrZhengShi, e := GetUserTypeZhengShi(user.CompanyId)
 	if e != nil {
 		err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())

+ 61 - 10
services/order.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"encoding/json"
 	"errors"
 	"fmt"
 	"hongze/hongze_mfyx/models"
@@ -78,7 +79,7 @@ func GetHaverEquallyOrderByUser10Min(userId, goodsId int) (orderCode string) {
 	var condition string
 	var pars []interface{}
 	endTime := time.Now().Add(-10 * time.Minute)
-	condition = ` AND  user_id = ? AND  goods_id = ? AND create_time > ?  ORDER BY order_id DESC  `
+	condition = ` AND order_status = 1 AND  user_id = ? AND  goods_id = ? AND create_time > ?  ORDER BY order_id DESC  `
 	pars = append(pars, userId, goodsId, endTime)
 	orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
 	if e != nil && e.Error() != utils.ErrNoRow() {
@@ -107,7 +108,7 @@ func GetHaverEquallyOrderByUser10MinByActivty(userId, sourceId int) (orderCode s
 	var condition string
 	var pars []interface{}
 	endTime := time.Now().Add(-10 * time.Minute)
-	condition = ` AND source = 'activity' AND  user_id = ? AND  source_id = ? AND create_time > ?  ORDER BY order_id DESC  `
+	condition = `  AND order_status = 1  AND source = 'activity' AND  user_id = ? AND  source_id = ? AND create_time > ?  ORDER BY order_id DESC  `
 	pars = append(pars, userId, sourceId, endTime)
 	orderList, e := order.GetCygxOrderList(condition, pars, 0, 1)
 	if e != nil && e.Error() != utils.ErrNoRow() {
@@ -142,21 +143,30 @@ func HandleOrderHandle(itemCallback *WechatPayCallback) {
 		err = errors.New("GetCygxOrderDetailByOrderCode, Err: " + e.Error())
 		return
 	}
+
+	go AddCygxOrderPayment(itemCallback) // 记录支付交易信息
+
+	if itemCallback.TradeState != "SUCCESS" { // 回调显示支付不成功,模版消息推送
+		if e != nil {
+			err = errors.New("支付失败,  OrderCode: " + outTradeNo)
+			return
+		}
+	}
 	//修改过状态的不再二次处理
 	if orderDetail.OrderStatus == 2 {
 		return
 	}
+	go AddCygxOrderPayment(itemCallback) // 记录支付交易信息
+
 	itemOrder := new(order.CygxOrder)
 	itemOrder.OrderCode = itemCallback.OutTradeNo
 	itemOrder.PayTime = itemCallback.SuccessTime
-	//fmt.Println(itemCallback.Amount.PayerTotal / 100)
 	itemOrder.PayMoney = float64(float64(itemCallback.Amount.PayerTotal) / 100) // 金额分转换处理
 	itemOrder.OrderStatus = 2
 	itemOrder.OutTradeCode = itemCallback.TransactionID
-	fmt.Println("itemOrder.PayMoney", itemOrder.PayMoney)
-	//文章处理逻辑
-	if orderDetail.Source == utils.CYGX_OBJ_ARTICLE {
 
+	//文章处理逻辑  	OrderType        int       `comment:"订单类型,1:畅读卡订单,2:单场付费订单"`
+	if orderDetail.OrderType == 1 {
 		itemUserCard := new(order.CygxOrderUserCard)
 		itemUserCard.OrderCode = orderDetail.OrderCode
 		itemUserCard.UserId = orderDetail.UserId
@@ -185,12 +195,53 @@ func HandleOrderHandle(itemCallback *WechatPayCallback) {
 			err = errors.New("AddCygxOrderUserCard, Err: " + e.Error())
 			return
 		}
-	} else if orderDetail.Source == utils.CYGX_OBJ_ACTIVITY {
-
+	} else if orderDetail.OrderType == 2 {
+		//如果是活动,把单场付费信息的活动写入 用户虚拟资产表
+		itemOrderVirtualAsset := new(order.CygxOrderVirtualAsset)
+		itemOrderVirtualAsset.OrderCode = orderDetail.OrderCode
+		itemOrderVirtualAsset.UserId = orderDetail.UserId
+		itemOrderVirtualAsset.Mobile = orderDetail.Mobile
+		itemOrderVirtualAsset.Email = orderDetail.Email
+		itemOrderVirtualAsset.CompanyId = orderDetail.CompanyId
+		itemOrderVirtualAsset.CompanyName = orderDetail.CompanyName
+		itemOrderVirtualAsset.RealName = orderDetail.RealName
+		itemOrderVirtualAsset.SellerName = orderDetail.SellerName
+		itemOrderVirtualAsset.Source = orderDetail.Source
+		itemOrderVirtualAsset.SourceId = orderDetail.SourceId
+		itemOrderVirtualAsset.CreateTime = time.Now()
+		itemOrderVirtualAsset.ModifyTime = time.Now()
+		e = order.AddCygxOrderVirtualAsset(itemOrderVirtualAsset, itemOrder)
+		if e != nil {
+			err = errors.New("AddCygxOrderVirtualAsset, Err: " + e.Error())
+			return
+		}
 	}
 	fmt.Println(orderDetail.Source)
-	//var condition string
-	//var pars []interface{}
+	return
+}
 
+func AddCygxOrderPayment(itemCallback *WechatPayCallback) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("处理订单回调信息失败 HandleOrderHandle, err:", err.Error()), 2)
+		}
+	}()
+	itemPay := new(order.CygxOrderPayment)
+	itemPay.OrderCode = itemCallback.OutTradeNo
+	itemPay.OutTradeCode = itemCallback.TransactionID
+	itemPay.PayBody = itemCallback.TradeStateDesc
+	jsonData, _ := json.Marshal(itemCallback)
+	itemPay.PayDetail = string(jsonData)
+	itemPay.PayMoney = float64(float64(itemCallback.Amount.PayerTotal) / 100) // 金额分转换处理
+	itemPay.PayStatus = itemCallback.TradeState
+	itemPay.CreateTime = time.Now()
+	itemPay.PaymentType = 1
+	e := order.AddCygxOrderPayment(itemPay)
+	if e != nil {
+		err = errors.New("AddCygxOrderPayment, Err: " + e.Error())
+		return
+	}
 	return
 }

+ 23 - 1
services/user_yanxuan_permission.go

@@ -79,7 +79,7 @@ func GetCygxOrderUserCardTotal(mobile string) (total int) {
 	defer func() {
 		if err != nil {
 			fmt.Println(err)
-			go utils.SendAlarmMsg(fmt.Sprint("判断用户是否开通了个人研选权限失败 GetCygxOrderUserCardTotal mobile", mobile, ",err:", err.Error()), 2)
+			go utils.SendAlarmMsg(fmt.Sprint("判断用户是否持有阅读卡失败 GetCygxOrderUserCardTotal mobile", mobile, ",err:", err.Error()), 2)
 		}
 	}()
 	var condition string
@@ -94,3 +94,25 @@ func GetCygxOrderUserCardTotal(mobile string) (total int) {
 	}
 	return
 }
+
+// 判断用户是购买了单场付费活动
+func GetCygxOrderVirtualAssetdCountTotal(mobile string, activityId int) (total int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("判断用户是购买了单场付费活动失败 GetCygxOrderUserCardTotal mobile", mobile, "activityId:", activityId, ",err:", err.Error()), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition += ` AND mobile  =   ?  AND source  = 'activity'  AND  source_id =  ? `
+	pars = append(pars, mobile, activityId)
+
+	total, e := order.GetCygxOrderVirtualAssetdCount(condition, pars)
+	if e != nil {
+		err = errors.New("GetCygxOrderVirtualAssetdCount, Err: " + e.Error())
+		return
+	}
+	return
+}