소스 검색

更新

guide_order
huangjiajun 5 달 전
부모
커밋
56e7d2d316
24개의 변경된 파일1442개의 추가작업 그리고 26개의 파일을 삭제
  1. +26
    -0
      app/db/db_coupon_base.go
  2. +18
    -0
      app/db/db_newcomers_qualification_record.go
  3. +21
    -0
      app/db/db_placard_record.go
  4. +1
    -1
      app/db/dbs_map.go
  5. +17
    -0
      app/db/dbs_order_relate.go
  6. +17
    -0
      app/db/model/comm_coupon.go
  7. +21
    -0
      app/db/model/newcomers_qualification_record.go
  8. +10
    -0
      app/db/model/ord_item_info.go
  9. +13
    -0
      app/db/model/placard_record.go
  10. +21
    -0
      app/db/model/third_newcomers_qualification_record.go
  11. +1
    -1
      app/lib/push/admin_mob_push.go
  12. +30
    -0
      app/md/coupon.go
  13. +4
    -0
      app/md/provider.go
  14. +106
    -0
      app/svc/svc_coupon_api.go
  15. +19
    -7
      app/svc/svc_order_track_parse_pid.go
  16. +812
    -0
      app/svc/svc_order_track_save_create.go
  17. +1
    -1
      app/svc/svc_order_track_save_update.go
  18. +58
    -0
      app/svc/svc_placard_record.go
  19. +33
    -0
      app/svc/svc_privilege_card.go
  20. +8
    -4
      consume/init.go
  21. +20
    -0
      consume/md/consume_key.go
  22. +90
    -0
      consume/zhios_order_track_create_for_jd_consume.go
  23. +90
    -0
      consume/zhios_order_track_update_for_jd_consume.go
  24. +5
    -12
      go.mod

+ 26
- 0
app/db/db_coupon_base.go 파일 보기

@@ -0,0 +1,26 @@
package db

import (
"applet/app/db/model"
"applet/app/utils/logx"
"xorm.io/xorm"
)

//查询记录
func CommCouponBaseList(Db *xorm.Engine) (*model.CommCoupon, error) {
var CommCouponBaseList model.CommCoupon
if has, err := Db.Get(&CommCouponBaseList); err != nil || !has {
return nil, logx.Error(err)
}
return &CommCouponBaseList, nil
}

//添加
func CommCouponBaseInsert(Db *xorm.Engine, m *model.CommCoupon) (int64, error) {
return Db.InsertOne(m)
}

//编辑
func CommCouponBaseUpdate(Db *xorm.Engine, m *model.CommCoupon) (int64, error) {
return Db.ID(m.Id).AllCols().Update(m)
}

+ 18
- 0
app/db/db_newcomers_qualification_record.go 파일 보기

@@ -0,0 +1,18 @@
package db

import (
"applet/app/db/model"

"xorm.io/xorm"
)

//FreeQualificationRecordInsertOne 新人免单记录
func FreeQualificationRecordInsertOne(Db *xorm.Engine, m *model.NewcomersQualificationRecord) (int64, error) {
return Db.InsertOne(m)
}
func SecondFreeQualificationRecordInsertOne(Db *xorm.Engine, m *model.SecondNewcomersQualificationRecord) (int64, error) {
return Db.InsertOne(m)
}
func ThirdFreeQualificationRecordInsertOne(Db *xorm.Engine, m *model.ThirdNewcomersQualificationRecord) (int64, error) {
return Db.InsertOne(m)
}

+ 21
- 0
app/db/db_placard_record.go 파일 보기

@@ -0,0 +1,21 @@
package db

import (
"applet/app/db/model"
"applet/app/utils/logx"
"xorm.io/xorm"
)

func PlacardRecordCreate(Db *xorm.Engine, args *model.PlacardRecord) (int64, error) {
return Db.InsertOne(args)
}
func PlacardRecordList(eg *xorm.Engine) (*[]model.PlacardRecord, error) {
var ord []model.PlacardRecord
if err := eg.Where("1=1").Desc("time").Limit(10, 0).Find(&ord); err != nil {
return nil, logx.Error(err)
}
if len(ord) == 0 {
return nil, nil
}
return &ord, nil
}

+ 1
- 1
app/db/dbs_map.go 파일 보기

@@ -91,7 +91,7 @@ func GetAllDatabaseDev() *[]model.DbMapping {
fmt.Println("cfg.Local is: ", cfg.Local)
if cfg.Local { // 本地调试 加快速度
fmt.Println("notice:LOCAL TEST, only masterId:** 99813608 ** available!")
err = Db.Where("deleted_at != ? AND db_master_id=?", 1, 89608884).Find(&m)
err = Db.Where("deleted_at != ? AND db_master_id=?", 1, 22255132).Find(&m)
} else {
err = Db.Where("deleted_at != ? AND is_dev = '1' ", 1).Find(&m)
}


+ 17
- 0
app/db/dbs_order_relate.go 파일 보기

@@ -0,0 +1,17 @@
package db

import (
"xorm.io/xorm"

"applet/app/db/model"
"applet/app/utils/logx"
)

func DbsOrderItemInfoInsert(eg *xorm.Engine, m *model.OrdItemInfo) bool {
_, err := eg.InsertOne(m)
if err != nil {
logx.Warn(err)
return false
}
return true
}

+ 17
- 0
app/db/model/comm_coupon.go 파일 보기

@@ -0,0 +1,17 @@
package model

import (
"time"
)

type CommCoupon struct {
Id int `json:"id" xorm:"not null pk autoincr comment('主键id') INT(11)"`
IsUse int `json:"is_use" xorm:"not null comment('是否开启(否:0;是:1)') TINYINT(1)"`
ExchangeRatio string `json:"exchange_ratio" xorm:"not null default 0.00 comment('兑换比例(与金额)') DECIMAL(5,2)"`
BonusType string `json:"bonus_type" xorm:"not null default '' comment('渠道(json([]string))') VARCHAR(255)"`
BuyType int `json:"buy_type" xorm:"not null default 0 comment('购买类型(1固定+自定义,2固定金额,3自定义金额)') TINYINT(1)"`
FixedAmountValue string `json:"fixed_amount_value" xorm:"not null comment('固定金额设置内容(json)') TEXT"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
RefundTime int `json:"refund_time" xorm:"default 0 comment('回退时间点 单位:分钟') INT(11)"`
}

+ 21
- 0
app/db/model/newcomers_qualification_record.go 파일 보기

@@ -0,0 +1,21 @@
package model

import (
"time"
)

type NewcomersQualificationRecord struct {
Id int `json:"id" xorm:"not null pk autoincr INT(10)"`
Uid int `json:"uid" xorm:"not null default 0 INT(11)"`
Source int `json:"source" xorm:"not null default 0 comment('1为注册获得
2为分享获得
3为消费扣除
4为后台修改
来源标识') TINYINT(4)"`
SourceText string `json:"source_text" xorm:"not null default '' comment('来源') VARCHAR(255)"`
ChangeNum int `json:"change_num" xorm:"not null default 0 comment('变更值') INT(11)"`
AfterChangeNum int `json:"after_change_num" xorm:"not null default 0 comment('变更后值') INT(11)"`
OrderId int64 `json:"order_id" xorm:"not null default 0 comment('新人免单订单ID(与order_list主键对应)') BIGINT(20)"`
CreatedAt time.Time `json:"created_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
}

+ 10
- 0
app/db/model/ord_item_info.go 파일 보기

@@ -0,0 +1,10 @@
package model

type OrdItemInfo struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
ItemId string `json:"item_id" xorm:"not null default '' comment('商品id') index VARCHAR(100)"`
Pvd string `json:"pvd" xorm:"not null default '' comment('供应商') VARCHAR(32)"`
Thumbnail string `json:"thumbnail" xorm:"not null default '' comment('缩略图URL') VARCHAR(2000)"`
ItemTitle string `json:"item_title" xorm:"not null default '' comment('标题') VARCHAR(256)"`
ItemLink string `json:"item_link" xorm:"not null default '' comment('商品链接') VARCHAR(2000)"`
}

+ 13
- 0
app/db/model/placard_record.go 파일 보기

@@ -0,0 +1,13 @@
package model

type PlacardRecord struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"default 0 comment('用户') INT(11)"`
Phone string `json:"phone" xorm:"default '' comment('手机号') VARCHAR(100)"`
Content string `json:"content" xorm:"default '' comment('内容') VARCHAR(255)"`
Time int `json:"time" xorm:"default 0 INT(11)"`
IsXuni int `json:"is_xuni" xorm:"default 0 comment('是否虚拟信息') INT(1)"`
Price string `json:"price" xorm:"default 0.00 comment('金额') DECIMAL(10,2)"`
Type string `json:"type" xorm:"default '' comment('公告类型') VARCHAR(50)"`
Data string `json:"data" xorm:"comment('预留') TEXT"`
}

+ 21
- 0
app/db/model/third_newcomers_qualification_record.go 파일 보기

@@ -0,0 +1,21 @@
package model

import (
"time"
)

type ThirdNewcomersQualificationRecord struct {
Id int `json:"id" xorm:"not null pk autoincr INT(10)"`
Uid int `json:"uid" xorm:"not null default 0 INT(11)"`
Source int `json:"source" xorm:"not null default 0 comment('1为注册获得
2为分享获得
3为消费扣除
4为后台修改
来源标识') TINYINT(4)"`
SourceText string `json:"source_text" xorm:"not null default '' comment('来源') VARCHAR(255)"`
ChangeNum int `json:"change_num" xorm:"not null default 0 comment('变更值') INT(11)"`
AfterChangeNum int `json:"after_change_num" xorm:"not null default 0 comment('变更后值') INT(11)"`
OrderId int64 `json:"order_id" xorm:"not null default 0 comment('新人免单订单ID(与order_list主键对应)') BIGINT(20)"`
CreatedAt time.Time `json:"created_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
}

+ 1
- 1
app/lib/push/admin_mob_push.go 파일 보기

@@ -46,7 +46,7 @@ func CommAddPush(eg *xorm.Engine, args md.PushParams) {
if args.DomainWapBase == "" {
args.DomainWapBase = "http://h5." + args.MasterId + ".izhyin.com"
if cfg.Prd {
args.DomainWapBase = "http://h5." + args.MasterId + ".zhiyingos.com"
args.DomainWapBase = "http://" + args.MasterId + ".izhim.net"
}
}
if args.PushType != "" {


+ 30
- 0
app/md/coupon.go 파일 보기

@@ -0,0 +1,30 @@
package md

type CouponCheck struct {
CouponAmount string `json:"coupon_amount"`
Uid string `json:"uid"`
PvdType string `json:"pvd_type"`
Pvd string `json:"pvd"`
Gid string `json:"gid"`
CreateAt string `json:"create_at"`
CheckAmount string `json:"check_amount"`
IsMustReduce string `json:"is_must_reduce"`
IsChangeState string `json:"is_change_state"`
GoodsTitle string `json:"goods_title"`
Oid string `json:"oid"`
}

type CouponCheckRequest struct {
CouponAmount string `json:"coupon_amount"`
Uid string `json:"uid"`
PvdType string `json:"pvd_type"`
Type string `json:"type"`
Pvd string `json:"pvd"`
Gid string `json:"gid"`
CheckAmount string `json:"check_amount"`
IsMustReduce string `json:"is_must_reduce"`
CreateAt string `json:"create_at"`
IsChangeState string `json:"is_change_state"`
GoodsTitle string `json:"goods_title"`
Oid string `json:"oid"`
}

+ 4
- 0
app/md/provider.go 파일 보기

@@ -24,6 +24,8 @@ const (
PVD_TBBYSETTLE = "tb_by_settle"
PVD_JD = "jd"
PVD_JDOwn = "jd_own"
PVD_JDUNIONOWN = "jd_union_own"
PVD_JDUNIONOWNUPDATE = "jd_union_own_update"
PVD_SN = "suning"
PVD_VIP = "vip"
PVD_PDD = "pdd"
@@ -118,6 +120,8 @@ var PVD_LIST = map[string]string{
PVD_VIP: "唯品会",
PVD_PDD: "拼多多",
PVD_JDBYCREATETIME: "京东",
PVD_JDUNIONOWN: "京东",
PVD_JDUNIONOWNUPDATE: "京东",
PVD_JDOwn: "京东",
PVD_JDFAILBYCREATETIME: "京东",
PVD_PDDBYCREATETIME: "拼多多",


+ 106
- 0
app/svc/svc_coupon_api.go 파일 보기

@@ -0,0 +1,106 @@
package svc

import (
"applet/app/cfg"
"applet/app/db"
"applet/app/md"
"applet/app/utils/cache"
"applet/app/utils/logx"
"crypto/tls"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"time"
"xorm.io/xorm"
)

//检测优惠券扣钱
func ApiToReduceCoupon(masterId string, req *md.CouponCheck) int {
logx.Info(req)

//检测优惠券功能是否开启
bools := CouponOpen(db.DBs[masterId])
if bools == false {
return 1
}
// 加锁 防止并发提取
mutexKey := fmt.Sprintf("%s:ReduceCoupon:%s", masterId, req.Uid)
withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1, "NX")
if err != nil {
return 2
}
if withdrawAvailable != "OK" {
return 2
}
var host string
host = cfg.AppComm.URL + "/api/v1/inComm/Coupon/reduce"
tr := &http.Transport{
MaxIdleConnsPerHost: 200,
MaxIdleConns: 200,
MaxConnsPerHost: 200,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{
Timeout: 5 * time.Second,
Transport: tr,
}
byte1, _ := json.Marshal(req)
req1, _ := http.NewRequest("POST", host, strings.NewReader(string(byte1)))
req1.Header.Set("master_id", masterId)
req1.Header.Set("Content-Type", "application/json")
resp, err := (client).Do(req1)
logx.Info(req)

logx.Info(resp)
if err != nil || resp == nil {
if resp != nil {
_, _ = io.Copy(ioutil.Discard, resp.Body)
}
return 0
}
defer resp.Body.Close()
respByte, _ := ioutil.ReadAll(resp.Body)
logx.Info(string(respByte))
if len(respByte) == 0 {
return 0
}
var serverResp map[string]interface{}
err = json.Unmarshal(respByte, &serverResp)
logx.Info(serverResp)
if err != nil || serverResp == nil {
return 0
}
if serverResp["data"] == nil {
if serverResp["msg"] != "" {
return 0
}
return 0
}
if serverResp["data"] == "success" {
return 1
}
return 0
}

func CouponOpen(eg *xorm.Engine) bool {
//查出基本配置
baseList, err := db.CommCouponBaseList(eg)
if err != nil || baseList == nil {
return false
}
if baseList.Id == 0 {
return false
}
//判断有没有开启
if baseList.IsUse == 0 {
return false
}
//判断有没有这个渠道
if baseList.BonusType == "" {
return false
}
return true
}

+ 19
- 7
app/svc/svc_order_track_parse_pid.go 파일 보기

@@ -231,7 +231,7 @@ func parsePids(eg *xorm.Engine, masterId, pvd string, pids []string) map[int]*md
}
}

case md.PVD_JD, md.PVD_PDD:
case md.PVD_JD, md.PVD_PDD, md.PVD_JDOwn:
var (
jdPddSelfUid []int
jdPddShareUid []int
@@ -241,18 +241,30 @@ func parsePids(eg *xorm.Engine, masterId, pvd string, pids []string) map[int]*md
var user1 = map[int]*md.UserPid{}
for _, v := range pids {
s := strings.Split(v, "_")
if len(s) < 6 {
id := 0
orderType := md.OrderTypeSelf
types := "self"
isContinue := 1
if len(s) == 2 && (pvd == md.PVD_JD || pvd == md.PVD_JDOwn) {
id = utils.StrToInt(s[1])
types = s[0]
isContinue = 0
}
if len(s) >= 6 {
id = utils.StrToInt(s[5])
types = s[4]
isContinue = 0
}
if isContinue == 1 {
continue
}
id := utils.StrToInt(s[5])
orderType := md.OrderTypeSelf
if s[4] == "share" {
if types == "share" {
orderType = md.OrderTypeShare
jdPddShareUid = append(jdPddShareUid, id)
} else if s[4] == "free" {
} else if types == "free" {
orderType = md.OrderTypeFree
jdPddFreeUid = append(jdPddFreeUid, id)
} else if s[4] == "cloud" {
} else if types == "cloud" {
orderType = 10
jdPddCloudUid = append(jdPddCloudUid, id)
} else {


+ 812
- 0
app/svc/svc_order_track_save_create.go 파일 보기

@@ -0,0 +1,812 @@
package svc

import (
"applet/app/cfg"
"applet/app/utils/cache"
"applet/app/utils/logx"
md3 "code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git/svc"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/o2o"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan"
"fmt"
"github.com/tidwall/gjson"
"strings"
"time"

"xorm.io/xorm"

"applet/app/db"
"applet/app/db/model"
"applet/app/lib/plan"
"applet/app/md"
"applet/app/utils"
)

// 订单入库, TODO 1. 入库, 判断订单是否已经在库, 并到各个会员里面进行订单判断分润状态, 2.算利并进行分配, 所有订单都要进行拆单, 包括从智盟获取的订单
func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts map[string]*plan.PlanOpt, dbName string) error {
var (
allOrdIds []string
pids []string //
)
littlePocket := db.SysCfgFindWithDb(eg, dbName, "little_pocket_basic_data")
returnMoneyType := "0"
if littlePocket != nil && gjson.Get(littlePocket["little_pocket_basic_data"], "return_money_type").String() == "1" {
returnMoneyType = "1"
}
var ch *rabbit.Channel
var err error
//if cfg.Prd {
ch, err = rabbit.Cfg.Pool.GetChannel()
if err == nil {
defer ch.Release()
}
//}
ords := map[string]md.OrderInfo{}
for _, v := range *ordData {
// 如果订单存在则更改订单状态, 其它不需要操作, 结算由另外一个任务进行结算
ords[v.PvdOid] = v
// 计算推广位
if v.Pid != "" {
pids = append(pids, v.Pid)
}
allOrdIds = append(allOrdIds, v.PvdOid)
}
fmt.Println(pids)
if strings.Contains(pvd, "meituan") {
pvd = "meituan"
}
if pvd == "hw_movie" {
pvd = "cinema"
}
if pvd == md.PVD_PDDBYCREATETIME || pvd == md.PVD_PDDBYAGOTIME || pvd == md.PVD_PDDBYSTATUS || pvd == md.PVD_PDDBYSTATUSSUCCESS || pvd == md.PVD_PDDBYSTATUSFAIL { //判断下拼多多
pvd = md.PVD_PDD
}

if pvd == md.PVD_JDUNIONOWN || pvd == md.PVD_JDUNIONOWNUPDATE || pvd == md.PVD_JDBYCREATETIME || pvd == md.PVD_JDBYSUCCESS || pvd == md.PVD_JDFAILBYCREATETIME || pvd == md.PVD_JDBYSTATUS { //判断下京东
pvd = md.PVD_JD
}
if utils.InArr(pvd, []string{"csjp_create", "own_csjp", "own_csjp_activity"}) {
pvd = "csjp"
}
if utils.InArr(pvd, []string{"own_csjp_live"}) {
pvd = "csjp_live"
}
if utils.InArr(pvd, []string{md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) {
pvd = md.PVD_TB
}
if pvd == md.PVD_DIDI_ENERGY { //
pvd = "oil"
}
if pvd == md.PVD_TO_KFC { //判断下
pvd = md.PVD_KFC
}
if pvd == md.PVD_TIKTOKOWNLIVE { //判断下
pvd = md.PVD_TIKTOKLIVE
}
if utils.InArr(pvd, []string{md.PVD_TIKTOKOwn, md.PVD_TIKTOKOwnCreate, md.PVD_TIKTOKOwnActivity, md.PVD_TIKTOKOwnMix}) { //判断下
pvd = md.PVD_TIKTOK
}
if utils.InArr(pvd, []string{md.PVD_KuaishouOwn, md.PVD_KuaishouOwnCreate}) { //判断下
pvd = md.PVD_KUAISHOU
}
var syncTime int64 = 0
use, _ := db.SysUnionByPVDByUse(eg, dbName, pvd)
if use != nil && use.SyncTime.IsZero() == false {
syncTime = use.SyncTime.Unix()
}
// 用推广位计算出查询对应人员的等级
userInfo := parsePids(eg, dbName, pvd, pids)

pidToUser := map[string]*md.UserPid{}
for _, vv := range userInfo {
if pvd == md.PVD_TB {
prefix := "self_"
if vv.OrderType == md.OrderTypeShare {
prefix = "share_"
}
if vv.OrderType == md.OrderTypeFree {
prefix = "free_"
}
if vv.OrderType == 15 {
prefix = "relationfree_"
}
if vv.OrderType == md.OrderTypeTljFree {
prefix = "tljfree_"
}
if vv.OrderType == 16 {
prefix = "ttljfree_"
}
if vv.OrderType == 10 {
prefix = "cloud_"
}
if vv.OrderType == md.OrderTypeTljRelationFree {
prefix = "tljrelationfree_"
}
if vv.OrderType == md.OrderTypeActSelf {
prefix = "actself_"
}
if vv.OrderType == md.OrderTypeWechatActShare {
prefix = "wechatactshare_"
}
if vv.OrderType == md.OrderTypeWechatActSelf {
prefix = "wechatactself_"
}
if vv.OrderType == md.OrderTypeWechatActSelfNew {
prefix = "wechatactselfnew_"
}
pidToUser[prefix+vv.Pid] = vv
} else {
if len(vv.Pids) > 0 {
for _, v1 := range vv.Pids {
pidToUser[v1] = vv
}
} else {
pidToUser[vv.Pid] = vv
}
}
}
now := int(time.Now().Unix())
existOrds, _ := db.DbsOrderFindByIdsNew(eg, pvd, allOrdIds)
// 更新订单
if existOrds != nil {
for _, v := range *existOrds {
// 去除已存在订单
delete(ords, v.PvdOid)
}
}
//判断饿了么的
if pvd == md.PVD_TB {
eleExistOrds, _ := db.DbsOrderFindByIdsNew(eg, "ele", allOrdIds)
// 更新订单
if eleExistOrds != nil {
for _, v := range *eleExistOrds {
// 去除已存在订单
delete(ords, v.PvdOid)
}
}
}
if len(ords) == 0 {
return nil
}
var commissionReqList = make([]md.CommissionFirstParam, 0)
var returnMoneyReqList = make([]map[string]string, 0)
for k, v := range ords {
if v.StartTime < syncTime && syncTime > 0 { //根据后台的时间配置来
continue
}
var oneOrd = v
var user *md.UserPid
if utils.InArr(pvd, []string{md.PVD_TB, "ele", md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) {
//如果是淘宝要处理下类型拿用户
for k1 := range pidToUser {
pidTmp := strings.Split(v.Pid, "_")
if len(pidTmp) == 2 {
if strings.Contains(k1, pidTmp[1]) && pidTmp[1] != "" {
v.Pid = k1
}
}
}
}
if v.Pid != "" {
if pidToUser[v.Pid] != nil {
user = pidToUser[v.Pid]
}
}
if v.Pid == "" && (v.Pvd == md.PVD_TB || v.Pvd == "ele") {
v.Pid = "self"
}
newPvd := pvd
//判断是饿了么的
if v.Pvd == "ele" {
newPvd = "ele"
}
//判断是否美团
if strings.Contains(pvd, "meituan_") {
newPvd = "meituan"
}
if pvd == "hw_movie" {
newPvd = "cinema"
}
if pvd == md.PVD_PDDBYCREATETIME || pvd == md.PVD_PDDBYAGOTIME || pvd == md.PVD_PDDBYSTATUS || pvd == md.PVD_PDDBYSTATUSSUCCESS || pvd == md.PVD_PDDBYSTATUSFAIL { //判断下拼多多
newPvd = md.PVD_PDD
}
if pvd == md.PVD_JDUNIONOWN || pvd == md.PVD_JDUNIONOWNUPDATE || pvd == md.PVD_JDBYCREATETIME || pvd == md.PVD_JDBYSUCCESS || pvd == md.PVD_JDFAILBYCREATETIME || pvd == md.PVD_JDBYSTATUS { //判断下京东
newPvd = md.PVD_JD
}
if utils.InArr(pvd, []string{"csjp_create", "own_csjp", "own_csjp_activity"}) {
newPvd = "csjp"
}
if utils.InArr(pvd, []string{"own_csjp_live"}) {
newPvd = "csjp_live"
}
if utils.InArr(pvd, []string{md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) {
newPvd = md.PVD_TB
}
if pvd == md.PVD_TO_KFC { //判断下
newPvd = md.PVD_KFC
}
if utils.InArr(pvd, []string{md.PVD_TIKTOKOwn, md.PVD_TIKTOKOwnCreate, md.PVD_TIKTOKOwnActivity, md.PVD_TIKTOKOwnMix}) { //判断下
newPvd = md.PVD_TIKTOK
}
if utils.InArr(pvd, []string{md.PVD_KuaishouOwn, md.PVD_KuaishouOwnCreate}) { //判断下
newPvd = md.PVD_KUAISHOU
}
if pvd == md.PVD_TIKTOKOWNLIVE { //判断下
newPvd = md.PVD_TIKTOKLIVE
}
if pvd == md.PVD_DIDI_ENERGY { //判断下
newPvd = "oil"
}
if v.Pvd == md.PVD_JDOwn {
newPvd = md.PVD_JDOwn
pvd = md.PVD_JD
}
optPvd := newPvd
if newPvd == "oil" {
optPvd = "oilstation"
}
if utils.InArr(pvd, []string{md.PVD_KuaishouOwn, md.PVD_KuaishouOwnCreate}) {
if v.Pvd == "Live" {
optPvd = md.PVD_KUAISHOULIVE
}
}
if !strings.Contains(v.Pid, "moreFree") && !strings.Contains(v.Pid, "shareSeFree") && !strings.Contains(v.Pid, "seFree") && !strings.Contains(v.Pid, "cloud") && !strings.Contains(v.Pid, "share") && !strings.Contains(v.Pid, "self") && !strings.Contains(v.Pid, "free") && !strings.Contains(v.Pid, "actself") && !strings.Contains(v.Pid, "wechatactself") && !strings.Contains(v.Pid, "wechatactselfnew") && !strings.Contains(v.Pid, "wechatactshare") {
continue
}
var oid int64
if user != nil { //用户不为空才判断
oid = utils.StrToInt64(utils.OrderUUID(user.Uid))
}
if v.OrderType == 15 {
v.OrderType = 2
}
if v.OrderType == 16 {
v.OrderType = 6
}
oneOrd.Oid = oid
ords[k] = oneOrd
ownbuyReturnType := 0 //自购返利 0返利 1不返利
//免单逻辑处理
if v.OrderType == 13 || v.OrderType == md.OrderTypeFree || v.OrderType == md.OrderTypeTljFree || v.OrderType == md.OrderTypeTljRelationFree {
if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单
continue
}
v.OptPvd = newPvd
v.OrderType = 0
}
//TODO 多方案
if v.OrderType == 11 || v.OrderType == 12 { //多方案
if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单
continue
}
freeOrder := orderSecondFreeCheck(eg, &v, oid, user.Uid, 0)
if freeOrder != nil {
optPvd = "seFree_" + utils.IntToStr(freeOrder.PriceType)
}
}

var uid = 0

if user != nil {
user.OwnbuyReturnType = ownbuyReturnType //是否有自购奖励
uid = user.Uid
isShare := 0
if v.OrderType == md.OrderTypeShare || v.OrderType == md.OrderTypeWechatActShare {
isShare = 1
}
//调用公共的分佣
pvdOid := v.PvdOid
//if v.ParentOrdId > 0 {
// pvdOid = utils.Int64ToStr(v.ParentOrdId)
//}
TikTokTeamCommission := v.TikTokTeamCommission
if utils.StrToFloat64(v.TikTokTeamRealCommission) > 0 {
TikTokTeamCommission = v.TikTokTeamRealCommission
}
req := md.CommissionFirstParam{
CommissionParam: md.CommissionParam{
Commission: utils.Float64ToStr(v.Commission),
PaidPrice: utils.Float64ToStr(v.PaidPrice),
OldPrice: utils.Float64ToStr(v.PaidPrice),
TikTokTeamCommission: TikTokTeamCommission,
IsTikTokTeamOrder: utils.IntToStr(v.IsTikTokTeamOrder),
},
Uid: utils.IntToStr(uid),
IsShare: isShare,
Provider: optPvd,
IsAllLevelReturn: 1,
OwnbuyReturnType: ownbuyReturnType,
Oid: pvdOid,
}
if utils.InArr(optPvd, []string{md.PVD_TB, md.PVD_TM, md.PVD_PDD, md.PVD_SN, md.PVD_KL, md.PVD_JD, md.PVD_JDOwn, md.PVD_VIP}) == false {
req.CommissionParam.GoodsPrice = utils.Float64ToStr(v.PaidPrice)
}
commissionReqList = append(commissionReqList, req)
returnMoneyReq := map[string]string{
"commission": utils.Float64ToStr(v.Commission),
"goods_price": utils.Float64ToStr(v.PaidPrice),
"uid": utils.IntToStr(uid),
"provider": optPvd,
"is_share": utils.IntToStr(isShare),
"is_return_all": "1",
"key_value": pvdOid,
}
returnMoneyReqList = append(returnMoneyReqList, returnMoneyReq)
}
}
commissionListArr, returnListArr := GetMoreRebateResult(eg, dbName, returnMoneyType, commissionReqList, returnMoneyReqList)
// 如果不存在的订单, 则进行计算更新
for _, v := range ords {
utils.FilePutContents("order", v.PvdOid)
if v.StartTime < syncTime && syncTime > 0 { //根据后台的时间配置来
continue
}
var user *md.UserPid
if pvd == md.PVD_TB12 || pvd == md.PVD_TB13 || pvd == md.PVD_TB14 || pvd == md.PVD_TB3 || pvd == md.PVD_TB || pvd == "ele" || pvd == md.PVD_TBBYCREATETIME || pvd == md.PVD_TBBYPAY || pvd == md.PVD_TBBYSETTLE {
//如果是淘宝要处理下类型拿用户
for k1 := range pidToUser {
pidTmp := strings.Split(v.Pid, "_")
if len(pidTmp) == 2 {
if strings.Contains(k1, pidTmp[1]) && pidTmp[1] != "" {
v.Pid = k1
}
}
}
}
if v.Pid != "" {
if pidToUser[v.Pid] != nil {
user = pidToUser[v.Pid]
}
}
fmt.Println("================", v.PvdOid, v.Pid, utils.SerializeStr(user))

if v.Pid == "" && (v.Pvd == md.PVD_TB || v.Pvd == "ele") {
v.Pid = "self"
}
v.Pid = strings.ReplaceAll(v.Pid, "relationfree_", "free_")

allCommission := v.Commission
newPvd := pvd
//判断是饿了么的
if v.Pvd == "ele" {
newPvd = "ele"
}
//判断是否美团
if strings.Contains(pvd, "meituan_") {
newPvd = "meituan"
}
if pvd == "hw_movie" {
newPvd = "cinema"
}
if pvd == md.PVD_PDDBYCREATETIME || pvd == md.PVD_PDDBYAGOTIME || pvd == md.PVD_PDDBYSTATUS || pvd == md.PVD_PDDBYSTATUSSUCCESS || pvd == md.PVD_PDDBYSTATUSFAIL { //判断下拼多多
newPvd = md.PVD_PDD
}
if utils.InArr(pvd, []string{"csjp_create", "own_csjp", "own_csjp_activity"}) {
newPvd = "csjp"
}
if utils.InArr(pvd, []string{"own_csjp_live"}) {
newPvd = "csjp_live"
}
if pvd == md.PVD_JDUNIONOWN || pvd == md.PVD_JDUNIONOWNUPDATE || pvd == md.PVD_JDBYCREATETIME || pvd == md.PVD_JDBYSUCCESS || pvd == md.PVD_JDFAILBYCREATETIME || pvd == md.PVD_JDBYSTATUS { //判断下京东
newPvd = md.PVD_JD
}
if utils.InArr(pvd, []string{md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) {
newPvd = md.PVD_TB
}
if pvd == md.PVD_TO_KFC { //判断下
newPvd = md.PVD_KFC
}
if utils.InArr(pvd, []string{md.PVD_TIKTOKOwn, md.PVD_TIKTOKOwnCreate, md.PVD_TIKTOKOwnActivity, md.PVD_TIKTOKOwnMix}) { //判断下
newPvd = md.PVD_TIKTOK
}
if pvd == md.PVD_TIKTOKOWNLIVE { //判断下
newPvd = md.PVD_TIKTOKLIVE
}
if pvd == md.PVD_DIDI_ENERGY { //判断下
newPvd = "oil"
}
if v.Pvd == md.PVD_JDOwn {
newPvd = md.PVD_JDOwn
pvd = md.PVD_JD
}
optPvd := newPvd
opt := opts[newPvd]
if v.Pvd == md.PVD_JDOwn && (opt == nil || (opt != nil && opt.PlanCommissionId == 0)) {
opt = opts[md.PVD_JD]
}
//判断是否加油
if newPvd == "oil" {
var ok = true
optPvd = "oilstation"
opt, ok = opts["oilstation"]
if ok == false {
continue
}
} else if opt == nil {
continue
}
if (pvd == "tikTok" || pvd == "csjp") && v.IsTikTokTeamOrder == 1 && opts["tikTokTeam"] != nil && opts["tikTokTeam"].PlanCommissionId > 0 {
opt = opts["tikTokTeam"]
}
if pvd == "kuaishou" && v.IsTikTokTeamOrder == 1 && opts["kuaishouTeam"] != nil && opts["kuaishouTeam"].PlanCommissionId > 0 {
opt = opts["kuaishouTeam"]
}
priceType := 0
secondPriceType := 0
if !strings.Contains(v.Pid, "moreFree") && !strings.Contains(v.Pid, "shareSeFree") && !strings.Contains(v.Pid, "seFree") && !strings.Contains(v.Pid, "cloud") && !strings.Contains(v.Pid, "share") && !strings.Contains(v.Pid, "self") && !strings.Contains(v.Pid, "free") && !strings.Contains(v.Pid, "actself") && !strings.Contains(v.Pid, "wechatactself") && !strings.Contains(v.Pid, "wechatactselfnew") && !strings.Contains(v.Pid, "wechatactshare") {
continue
}
var oid = v.Oid
if user != nil && oid == 0 { //用户不为空才判断
oid = utils.StrToInt64(utils.OrderUUID(user.Uid))
}
ownbuyReturnType := 0 //自购返利 0返利 1不返利
//免单逻辑处理
if v.OrderType == 15 {
v.OrderType = md.OrderTypeFree
}
freeOrderType := v.OrderType
if v.OrderType == 15 || v.OrderType == md.OrderTypeFree || v.OrderType == md.OrderTypeTljFree || v.OrderType == md.OrderTypeTljRelationFree {
if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单
continue
}
v.OptPvd = newPvd
v.OrderType = 0
}
if v.OrderType == 13 {
if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单
continue
}
v.OptPvd = newPvd
v.OrderType = 0
}
if v.OrderType == 11 || v.OrderType == 12 {
if user == nil || user.Uid == 0 { //判断免单的如果没有用户不跟这个订单
continue
}
//TODO
freeOrder := orderSecondFreeCheck(eg, &v, oid, user.Uid, 1)
if freeOrder != nil {
secondPriceType = freeOrder.PriceType
// 切换免单活动的分佣方案, 如1元购等
optPvd = "seFree_" + utils.IntToStr(freeOrder.PriceType)
opt = opts[optPvd]
}
}
var lvUser *comm_plan.LvUser
var pvdFee float64
var sysFee float64
var subsidyFee float64
var subsidyRate float64
var uid = 0
var profit float64 = 0
var returnProfit float64 = 0
var selfRate float64 = 0
var returnMoneyOne map[string]interface{}
if user != nil {
user.OwnbuyReturnType = ownbuyReturnType //是否有自购奖励
uid = user.Uid
userLv := user.Lv
pvdOid := v.PvdOid
fmt.Println(optPvd)
if returnMoneyType == "0" {
commissionList := commissionListArr[pvdOid]
if commissionList != nil {
pvdFee = commissionList.PvdFee
sysFee = commissionList.SysFee
subsidyFee = commissionList.SubsidyFee
lvUser = commissionList.LvUser
profit = commissionList.Profit
}

} else {
returnMoneyList := returnListArr[pvdOid]
var ok = true
returnMoneyOne, ok = returnMoneyList.(map[string]interface{})
if returnMoneyOne != nil && ok {
returnProfit = utils.AnyToFloat64(returnMoneyOne["self_commission"])
if v.OrderType == 1 {
returnProfit = utils.AnyToFloat64(returnMoneyOne["share_commission"])
}
}
}
fmt.Println(returnProfit)

//判断下这个等级有么有设置
if opt.UserRate != nil {
for k, item := range opt.UserRate {
if k == 0 {
selfRate = item.SelfRate
subsidyRate = item.SubsidyShareRate
if v.OrderType == 0 {
subsidyRate = item.SubsidySelfRate
}
}
if k == userLv {
selfRate = item.SelfRate
selfRate = item.SelfRate
subsidyRate = item.SubsidyShareRate
if v.OrderType == 0 {
subsidyRate = item.SubsidySelfRate
}
}
}
}
}

if v.OrderType == 15 || v.OrderType == 11 || v.OrderType == md.OrderTypeFree || v.OrderType == md.OrderTypeWechatActSelf || v.OrderType == md.OrderTypeWechatActSelfNew || v.OrderType == md.OrderTypeActSelf {
v.OrderType = md.OrderTypeSelf
}
if v.OrderType == 12 {
v.OrderType = md.OrderTypeShare
}
if v.OrderType == md.OrderTypeTljFree || v.OrderType == md.OrderTypeTljRelationFree {
v.OrderType = 3 //淘礼金免单
}
if v.OrderType == md.OrderTypeWechatActShare {
v.OrderType = md.OrderTypeShare
}
//如果没有商品id的用订单好代替
if v.ItemId == "" || v.ItemId == "0" {
v.ItemId = v.PvdOid
}
orderFormType := 0
if newPvd == md.PVD_JDOwn {
newPvd = md.PVD_JD
orderFormType = 1
}
// 插入新订单
newOrd := &model.OrdList{
OrderFormType: orderFormType,
OrdId: oid,
Uid: uid,
PvdOid: v.PvdOid,
ParentOrdId: v.ParentOrdId,
Pvd: newPvd,
ItemId: v.ItemId,
ItemNum: v.ItemNum,
ItemPrice: v.ItemPrice,
PaidPrice: v.PaidPrice,
OrderType: v.OrderType,
PriceType: priceType,
SecondPriceType: secondPriceType,
SubsidyFee: subsidyFee,
SubsidyRate: subsidyRate,
UserCommission: profit,
UserReturnMoney: returnProfit,
UserCommissionRate: selfRate,
PvdCommission: pvdFee,
PvdCommissionRate: opt.PvdRate,
SysCommission: sysFee,
SysCommissionRate: opt.SysRate,
PlanCommissionId: opt.PlanCommissionId,
Reason: v.Reason,
State: v.State,
CreateAt: int(v.StartTime),
UpdateAt: now,
ConfirmAt: 0,
PvdSettleAt: 0,
SettleAt: 0,
BenefitList: SerializeLvUser(CalcLvUserFee(lvUser)),
BenefitAll: allCommission,
Data: "",
UpdateFrom: 0,
PvdPid: v.Pid,
OrderCompare: v.IsCompare,
CostPrice: v.CostPrice,
IsTikTokTeamOrder: v.IsTikTokTeamOrder,
TikTokTeamCommission: v.TikTokTeamCommission,
TikTokTeamRealCommission: v.TikTokTeamRealCommission,
}
if v.State == md.OrderStateSucc && v.ConfirmAt == 0 {
newOrd.ConfirmAt = now
}
if utils.InArr(utils.IntToStr(v.State), []string{"1", "2"}) && v.ConfirmAt > 0 {
newOrd.ConfirmAt = int(v.ConfirmAt)
}
// 供应商结算时间
if v.State == md.OrderStatePvdSettle {
newOrd.PvdSettleAt = now
if v.EndTime > 0 {
newOrd.PvdSettleAt = int(v.EndTime)
}
}
db.DbsOrderInsert(eg, newOrd)
// 塞入订单商品对应图片
thumbnail := v.Thumbnail
if len(v.Thumbnail) > 3 && v.Thumbnail[0:2] == "//" {
thumbnail = "http:" + v.Thumbnail
}

db.DbsOrderItemInfoInsert(eg, &model.OrdItemInfo{
ItemId: v.ItemId,
Pvd: newPvd,
Thumbnail: thumbnail,
ItemTitle: v.ItemTitle,
ItemLink: v.ItemLink,
})
mode := ""
if opt != nil {
mode = opt.Mode
}
// TODO 塞入对应订单关系
if lvUser != nil && returnMoneyType == "0" {
//if optPvd == md.PVD_FREE && freeNewType == "1" {
// lvUser.AdditionalSubsidy = v.Commission
//}
OrderRelateInsert(eg, oid, newPvd, newOrd.CreateAt, lvUser, newOrd, dbName, false, mode, "1")
} else if returnMoneyOne != nil && returnMoneyType == "1" {
OrderReturnMoneyRelateInsert(eg, oid, newPvd, newOrd.CreateAt, returnMoneyOne, newOrd, dbName, false)
}
AcquisitionHookFirstOrder(eg, dbName, newOrd)
if uid > 0 {
//商家分佣
args := map[string]string{
"commission": utils.Float64ToStr(utils.FloatFormat(allCommission, 6)), // 总佣金
"bili": utils.Float64ToStrByPrec(opt.MerchantRate, 4), // 抽成 除以100之后的
"uid": utils.IntToStr(uid), // 用户id
"oid": utils.Int64ToStr(oid), // 订单号
"pvd": newPvd, // 渠道
}
o2o.AddStoreCommission(eg, args)
//写入区域代理订单
var req = &md.InsertRegionalAgentOrdBelongData{
Uid: uid,
Pvd: md.PVD_GUIDE,
CommPvd: md.PVD_COMMON,
Commission: utils.Float64ToStr(utils.FloatFormat(allCommission, 6)),
OrderId: oid,
RegionRate: opt.RegionRate,
GlobalRate: opt.GlobalRate,
RegionSubRate: opt.RegionSubRate,

Status: "0",
}
//if opt.Mode == "lv_ds_check" && lvUser != nil {
// req.Commission = utils.Float64ToStrByPrec(lvUser.MinProfit, 8)
//}
go SaveOrderByCommApi(eg, dbName, req)
commCheckCoupon(eg, uid, v.ItemId, 0, 1, newOrd.Pvd, utils.Int64ToStr(v.Oid)) //导购的判断

if v.State != 4 {
//加油扣除优惠券额度 查询优惠券使用记录
if v.Pvd == md.PVD_OILSTATION {
profits := v.CostPrice - v.PaidPrice
profits = utils.FloatFormat(profits, 2)
if profits > 0 {
bools := ReduceCoupon(eg, dbName, utils.Float64ToStr(profits), uid, v.ItemId, md.PVD_OILSTATION, "OIL", newOrd.CreateAt, v.ItemTitle, utils.Int64ToStr(v.Oid))
//加入公告栏明细
if bools == 1 {
AddPlacardRecord(eg, uid, "", "", md.PVD_OILSTATION, utils.Float64ToStr(profits), "")
}
}
} else {
commCheckCoupon(eg, uid, v.ItemId, 0, 1, newOrd.Pvd, utils.Int64ToStr(v.Oid)) //导购的判断
}
//定制 抽奖加入付款订单
req := md3.DayLuckDrawOrderJackpotReq{
Uid: utils.IntToStr(uid),
Oid: utils.Int64ToStr(newOrd.OrdId),
Pvd: newOrd.Pvd,
Amount: utils.Float64ToStrByPrec(newOrd.PaidPrice, 7),
Commission: utils.Float64ToStrByPrec(newOrd.BenefitAll, 7),
}
svc.AddOrderJackpot(eg, req)
if cfg.Prd {
CheckValid(eg, dbName, uid, 1, ch)
}
}

}
if freeOrderType == 13 || freeOrderType == md.OrderTypeFree || freeOrderType == md.OrderTypeTljFree || freeOrderType == md.OrderTypeTljRelationFree {
mutexKey := fmt.Sprintf("%s:all_order_to_store:%s:pvd:%s", dbName, v.PvdOid, v.Pvd)
available, err := cache.Do("SET", mutexKey, 1, "EX", 5, "NX")
if err != nil {
continue
}
if available != "OK" {
continue
}
arg := md.ZhiosOrderFree{
ItemId: newOrd.ItemId,
OptPvd: newPvd,
OrderType: utils.IntToStr(freeOrderType),
Pid: v.Pid,
Uid: utils.IntToStr(newOrd.Uid),
Mid: dbName,
Oid: utils.Int64ToStr(newOrd.OrdId),
}
if cfg.Prd {
ch.Publish(md.OrderFree, utils.SerializeStr(arg), md.OrderFreeRoutKeyForOrder)

} else {
ch.Publish(md.OrderFree, utils.SerializeStr(arg), md.OrderFreeRoutKeyForOrderdev)
}
}
}
return nil
}
func CheckValid(eg *xorm.Engine, dbName string, uid, isOrder int, ch *rabbit.Channel) {
if ch == nil {
return
}
vdata := db.SysCfgGetWithDb(eg, dbName, "valid_member_condition")
if (strings.Contains(vdata, "orderPay") == false || strings.Contains(vdata, "goodsCommission") == false) && isOrder == 1 {
return
}
user, _ := db.UserProfileFindByID(eg, uid)
if user == nil {
return
}
if user.IsVerify == 1 {
return
}
arg := md.ZhiosAcquisition{
Uid: utils.IntToStr(uid),
Mid: dbName,
}
if cfg.Prd {
ch.Publish(md.UserValid, utils.SerializeStr(arg), md.AcquisitionRoutKeyForUserValid)
} else {
ch.Publish(md.UserValid, utils.SerializeStr(arg), md.AcquisitionRoutKeyForUserValidDev)
}

}

func orderSecondFreeCheck(eg *xorm.Engine, v *md.OrderInfo, oid int64, uid int, isNeedReduct int) *model.SecondNewcomersFreeProduct {
m, err := db.SecondFreeProductByID(eg, v.ItemId, v.Pvd)
if err != nil || m == nil {

logx.Warn(err)
return nil
}
if strings.Contains(v.Pid, "seFree_") {
mt, err := db.SecondFreePriceTypeByID(eg, m.PriceType)
if err != nil || mt == nil {

logx.Warn(err)
return nil
}
// 查找用户剩余的免单资格数
profile, err := db.UserProfileFindByID(eg, uid)
if err != nil || profile == nil {
logx.Warn(err)
return m
}
//判断要不要扣免单券
if isNeedReduct == 1 {
if mt.NeedUseQuan == 1 {
// 更新剩余次数
if mt.NeedQuan > profile.SecondFreeRemainTime {
return m
}
profile.SecondFreeRemainTime = profile.SecondFreeRemainTime - mt.NeedQuan
_, err = db.UserProfileUpdate(eg, profile.Uid, profile, "second_free_remain_time")
if err != nil {
logx.Warn(err)
return m
}
// 插入日志记录
go db.SecondFreeQualificationRecordInsertOne(eg, &model.SecondNewcomersQualificationRecord{
Uid: profile.Uid,
Source: 3,
SourceText: "消费扣除",
OrderId: oid,
ChangeNum: -mt.NeedQuan,
AfterChangeNum: profile.SecondFreeRemainTime,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
})
}
m.Stock--
if m.Stock < 0 {
m.Stock = 0
}
m.Sale++
eg.Where("id=?", m.Id).Cols("stock,sale").Update(m)
}
return m
}
return m
}

+ 1
- 1
app/svc/svc_order_track_save_update.go 파일 보기

@@ -59,7 +59,7 @@ func OrderSaveUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts
if pvd == md.PVD_PDDBYCREATETIME || pvd == md.PVD_PDDBYAGOTIME || pvd == md.PVD_PDDBYSTATUS || pvd == md.PVD_PDDBYSTATUSSUCCESS || pvd == md.PVD_PDDBYSTATUSFAIL { //判断下拼多多
pvd = md.PVD_PDD
}
if pvd == md.PVD_JDBYCREATETIME || pvd == md.PVD_JDBYSUCCESS || pvd == md.PVD_JDFAILBYCREATETIME || pvd == md.PVD_JDBYSTATUS { //判断下京东
if pvd == md.PVD_JDUNIONOWN || pvd == md.PVD_JDUNIONOWNUPDATE || pvd == md.PVD_JDBYCREATETIME || pvd == md.PVD_JDBYSUCCESS || pvd == md.PVD_JDFAILBYCREATETIME || pvd == md.PVD_JDBYSTATUS { //判断下京东
pvd = md.PVD_JD
}
if utils.InArr(pvd, []string{"csjp_create", "own_csjp", "own_csjp_activity"}) {


+ 58
- 0
app/svc/svc_placard_record.go 파일 보기

@@ -0,0 +1,58 @@
package svc

import (
"applet/app/db"
"applet/app/db/model"
"applet/app/md"
"applet/app/utils"
"time"
"xorm.io/xorm"
)

func AddPlacardRecord(Db *xorm.Engine, uid int, name, str, types, coupon, typeId string) {
if uid == 0 {
return
}
if Db == nil {
return
}
//加入公告优惠记录
user, _ := db.UserFindByID(Db, uid)
nickname := ""
if user != nil {
nickname = user.Nickname
}
hideNickname := utils.HideTrueName(nickname)
if types == md.PVD_CARD {
str = "购买" + name
if typeId == "recharge" {
str = "充值" + name
}
str = "用户" + hideNickname + ",[时间]" + str + "节省了" + coupon + "元"
}
if types == md.PVD_OILSTATION {
str = "用户" + hideNickname + ",[时间]加油节省了" + coupon + "元"
}
var args = map[string]string{
"uid": utils.IntToStr(uid),
"phone": nickname,
"content": str,
"price": coupon,
"type": types,
}
InsertPlacardRecord(Db, args)
}
func InsertPlacardRecord(eg *xorm.Engine, args map[string]string) {

var arg = &model.PlacardRecord{
Uid: utils.StrToInt(args["uid"]),
Phone: args["phone"],
Content: args["content"],
Time: int(time.Now().Unix()),
IsXuni: 0,
Price: args["price"],
Type: args["type"],
Data: args["data"],
}
db.PlacardRecordCreate(eg, arg)
}

+ 33
- 0
app/svc/svc_privilege_card.go 파일 보기

@@ -0,0 +1,33 @@
package svc

import (
"applet/app/md"
"applet/app/utils"
"errors"
"time"
"xorm.io/xorm"
)

var PrivilegeOpenCardSessFailErr = errors.New("privilege open card order session fail")

func ReduceCoupon(Db *xorm.Engine, masterId, profit string, uid int, goodsId, pvd, pvdType string, createAt int, goodsTitle, oid string) int {
var tmp = &md.CouponCheck{
CouponAmount: profit,
Uid: utils.IntToStr(uid),
PvdType: pvdType,
Pvd: pvd,
Gid: goodsId,
CheckAmount: "1",
IsMustReduce: "1",
IsChangeState: "1",
GoodsTitle: goodsTitle,
Oid: oid,
}
if createAt > 0 {
tmp.CreateAt = time.Unix(int64(createAt), 0).Format("2006-01-02 15:04:05")
}
bools := ApiToReduceCoupon(masterId, tmp)

return bools

}

+ 8
- 4
consume/init.go 파일 보기

@@ -17,10 +17,14 @@ func Init() {

// 增加消费任务队列
func initConsumes() {
jobs[consumeMd.ZhiosOrderTrackUpdateForTbConsumeFunName] = ZhiosOrderTrackUpdateForTbConsume //淘宝-更新订单
jobs[consumeMd.ZhiosOrderTrackCreateForTbConsumeFunName] = ZhiosOrderTrackCreateForTbConsume //淘宝-创建订单
jobs[consumeMd.ZhiosOrderTrackRefundForTbAllConsumeFunName] = ZhiosOrderTrackRefundForTbAllConsume //淘宝-全部退款
jobs[consumeMd.ZhiosOrderTrackRefundForTbPartConsumeFunName] = ZhiosOrderTrackRefundForTbPartConsume //淘宝-部分退款
//jobs[consumeMd.ZhiosOrderTrackUpdateForTbConsumeFunName] = ZhiosOrderTrackUpdateForTbConsume //淘宝-更新订单
//jobs[consumeMd.ZhiosOrderTrackCreateForTbConsumeFunName] = ZhiosOrderTrackCreateForTbConsume //淘宝-创建订单
//jobs[consumeMd.ZhiosOrderTrackRefundForTbAllConsumeFunName] = ZhiosOrderTrackRefundForTbAllConsume //淘宝-全部退款
//jobs[consumeMd.ZhiosOrderTrackRefundForTbPartConsumeFunName] = ZhiosOrderTrackRefundForTbPartConsume //淘宝-部分退款

jobs[consumeMd.ZhiosOrderTrackCreateForJdConsumeFunName] = ZhiosOrderTrackCreateForJdConsume //京东-创建订单
jobs[consumeMd.ZhiosOrderTrackUpdateForJdConsumeFunName] = ZhiosOrderTrackUpdateForJdConsume //京东-更新订单

}

func Run() {


+ 20
- 0
consume/md/consume_key.go 파일 보기

@@ -20,6 +20,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "ZhiosOrderTrackUpdateForTbConsume",
},
{
ExchangeName: "zhios.order_track_update.exchange",
Name: "order_track_update_for_jd",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "jd",
BindKey: "",
ConsumeFunName: "ZhiosOrderTrackUpdateForJdConsume",
},
{
ExchangeName: "zhios.order_track_create.exchange",
Name: "order_track_create_for_tb",
@@ -29,6 +38,15 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "ZhiosOrderTrackCreateForTbConsume",
},
{
ExchangeName: "zhios.order_track_create.exchange",
Name: "order_track_create_for_jd",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "jd",
BindKey: "",
ConsumeFunName: "ZhiosOrderTrackCreateForJdConsume",
},
{
ExchangeName: "zhios.order_track_refund.exchange",
Name: "order_track_refund_for_tb_all",
@@ -52,6 +70,8 @@ var RabbitMqQueueKeyList = []*MqQueue{
const (
ZhiosOrderTrackUpdateForTbConsumeFunName = "ZhiosOrderTrackUpdateForTbConsume"
ZhiosOrderTrackCreateForTbConsumeFunName = "ZhiosOrderTrackCreateForTbConsume"
ZhiosOrderTrackCreateForJdConsumeFunName = "ZhiosOrderTrackCreateForJdConsume"
ZhiosOrderTrackUpdateForJdConsumeFunName = "ZhiosOrderTrackUpdateForJdConsume"
ZhiosOrderTrackRefundForTbAllConsumeFunName = "ZhiosOrderTrackRefundForTbAllConsume"
ZhiosOrderTrackRefundForTbPartConsumeFunName = "ZhiosOrderTrackRefundForTbPartConsume"
)

+ 90
- 0
consume/zhios_order_track_create_for_jd_consume.go 파일 보기

@@ -0,0 +1,90 @@
package consume

import (
"applet/app/cfg"
"applet/app/db"
md2 "applet/app/md"
svc2 "applet/app/svc"
"applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"time"
)

func ZhiosOrderTrackCreateForJdConsume(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>ZhiosOrderTrackCreateForJdConsume>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(1)
delivery := ch.Consume(queue.Name, false)

one_circles.Init(cfg.RedisAddr)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
err = handleZhiosOrderTrackCreateForJdConsume(res.Body)
fmt.Println("err ::: ", err)
if err != nil {
fmt.Println("ZhiosOrderTrackCreateForJdConsume_ERR:::::", err.Error())
_ = res.Reject(true) //TODO::拒绝 Ack
//_ = res.Reject(false)
var msg interface{}
json.Unmarshal(res.Body, &msg)
if err.Error() == "Connection timed out" {
//TODO::重新推回队列末尾,避免造成队列堵塞
ch.Publish(queue.ExchangeName, msg, queue.RoutKey)
} else {
//TODO::推入新的队列中备份
utils.FilePutContents("ZhiosOrderTrackCreateForJdConsume_ERR", utils.SerializeStr(err.Error()))
ch.Publish("zhios.order_track_create_exception.exchange", map[string]interface{}{
"msg": msg,
"err": err.Error(),
}, "jd")
}
} else {
err = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosOrderTrackCreateForJdConsume(msgData []byte) error {
//1、解析mq中queue的数据结构体
var msg md2.ZhiosOrderTrackCreateRoutKeyForTb
err := json.Unmarshal(msgData, &msg)
if err != nil {
return err
}
time.Sleep(time.Microsecond * 100) // 等待100毫秒
fmt.Println("order_track_create_for_Jd_message:::::::::::>>>>>>>>>")
fmt.Println(msg)
if db.DBs[msg.DbName] == nil {
return nil
}
engine := db.DBs[msg.DbName]
err = svc2.OrderSaveCreate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName)
if err != nil {
fmt.Println("order_track_create_for_Jd_ERR:::::::::::>>>>>>>>>", err.Error())
return err
}
return nil
}

+ 90
- 0
consume/zhios_order_track_update_for_jd_consume.go 파일 보기

@@ -0,0 +1,90 @@
package consume

import (
"applet/app/cfg"
"applet/app/db"
md2 "applet/app/md"
svc2 "applet/app/svc"
"applet/app/utils"
"applet/app/utils/logx"
"applet/consume/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles"
"encoding/json"
"errors"
"fmt"
"github.com/streadway/amqp"
"time"
)

func ZhiosOrderTrackUpdateForJdConsume(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>ZhiosOrderTrackUpdateForJdConsume>>>>>>>>>>>>")
ch, err := rabbit.Cfg.Pool.GetChannel()
if err != nil {
logx.Error(err)
return
}
defer ch.Release()
//1、将自己绑定到交换机上
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey)
//2、取出数据进行消费
ch.Qos(1)
delivery := ch.Consume(queue.Name, false)

one_circles.Init(cfg.RedisAddr)

var res amqp.Delivery
var ok bool
for {
res, ok = <-delivery
if ok == true {
err = handleZhiosOrderTrackUpdateForJdConsume(res.Body)
fmt.Println("err ::: ", err)
if err != nil {
fmt.Println("ZhiosOrderTrackUpdateForJdConsume_ERR:::::", err.Error())
_ = res.Reject(true) //TODO::拒绝 Ack
//_ = res.Reject(false)
var msg interface{}
json.Unmarshal(res.Body, &msg)
if err.Error() == "Connection timed out" {
//TODO::重新推回队列末尾,避免造成队列堵塞
ch.Publish(queue.ExchangeName, msg, queue.RoutKey)
} else {
//TODO::推入新的队列中备份
utils.FilePutContents("ZhiosOrderTrackUpdateForJdConsume_ERR", utils.SerializeStr(err.Error()))
ch.Publish("zhios.order_track_Update_exception.exchange", map[string]interface{}{
"msg": msg,
"err": err.Error(),
}, "jd")
}
} else {
err = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleZhiosOrderTrackUpdateForJdConsume(msgData []byte) error {
//1、解析mq中queue的数据结构体
var msg md2.ZhiosOrderTrackUpdateRoutKeyForTb
err := json.Unmarshal(msgData, &msg)
if err != nil {
return err
}
time.Sleep(time.Microsecond * 100) // 等待100毫秒
fmt.Println("order_track_Update_for_Jd_message:::::::::::>>>>>>>>>")
fmt.Println(msg)
if db.DBs[msg.DbName] == nil {
return nil
}
engine := db.DBs[msg.DbName]
err = svc2.OrderSaveUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName)
if err != nil {
fmt.Println("order_track_Update_for_Jd_ERR:::::::::::>>>>>>>>>", err.Error())
return err
}
return nil
}

+ 5
- 12
go.mod 파일 보기

@@ -3,18 +3,17 @@ module applet
go 1.18

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git v1.1.2-0.20240222023917-c31b53f7e8cb
code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git v1.1.2
code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git v1.2.1
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.0
code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git v1.0.5
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.4
code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git v1.0.9
code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240428041015-bcc1e79f0d28
code.fnuoos.com/go_rely_warehouse/zyos_go_pay.git v1.6.2-0.20231116085701-9ba6e19f877b
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240126015516-38ca248db2fd
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/boombuler/barcode v1.0.1
github.com/cc14514/go-geoip2 v0.0.0-20190105051856-0a1854480a11
github.com/cc14514/go-geoip2-db v0.0.0-20190106063142-7b6408a9812a
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/forgoer/openssl v1.2.1
@@ -25,8 +24,8 @@ require (
github.com/go-playground/validator/v10 v10.19.0
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.6.0
github.com/gocolly/colly v1.2.0
github.com/gomodule/redigo v2.0.0+incompatible
github.com/iGoogle-ink/gopay v1.5.36
github.com/jinzhu/copier v0.3.5
github.com/json-iterator/go v1.1.12
github.com/makiuchi-d/gozxing v0.1.1
@@ -47,9 +46,6 @@ require (
)

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_day_luck_draw.git v1.2.1 // indirect
code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git v1.0.5 // indirect
code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git v1.0.9 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/goquery v1.9.2 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
@@ -70,7 +66,6 @@ require (
github.com/go-openapi/swag v0.19.15 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gocolly/colly v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
@@ -90,7 +85,6 @@ require (
github.com/olivere/elastic/v7 v7.0.32 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/temoto/robotstxt v1.1.2 // indirect
@@ -102,7 +96,6 @@ require (
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
@@ -111,7 +104,7 @@ require (
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
)

불러오는 중...
취소
저장