xingzai 1 жил өмнө
parent
commit
2aac97e007

+ 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
 }

+ 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), //用户虚拟资产表(所购买的单篇报告,活动等)
 	)
 }

+ 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
+}

+ 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())

+ 59 - 8
services/order.go

@@ -1,6 +1,7 @@
 package services
 
 import (
+	"encoding/json"
 	"errors"
 	"fmt"
 	"hongze/hongze_mfyx/models"
@@ -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
+}