Explorar el Código

update

guide_order
dengbiao hace 7 meses
padre
commit
5a357a16f2
Se han modificado 32 ficheros con 1413 adiciones y 10 borrados
  1. +3
    -3
      app/db/db_user.go
  2. +1
    -1
      app/db/db_user_withdrawapply.go
  3. +1
    -1
      app/db/dbs_map.go
  4. +1
    -0
      app/db/model/fin_withdraw_apply.go
  5. +40
    -0
      app/flexible_employment/db/db_flexible_employment_basic.go
  6. +44
    -0
      app/flexible_employment/db/db_flexible_employment_ord.go
  7. +40
    -0
      app/flexible_employment/db/db_flexible_employment_pupiao_basic.go
  8. +44
    -0
      app/flexible_employment/db/db_flexible_employment_pupiao_ord.go
  9. +13
    -0
      app/flexible_employment/db/model/flexible_employment_basic.go
  10. +18
    -0
      app/flexible_employment/db/model/flexible_employment_ord.go
  11. +14
    -0
      app/flexible_employment/db/model/flexible_employment_pupiao_basic.go
  12. +21
    -0
      app/flexible_employment/db/model/flexible_employment_pupiao_ord.go
  13. +13
    -0
      app/flexible_employment/db/model/flexible_employment_pupiao_user_info.go
  14. +17
    -0
      app/flexible_employment/db/model/flexible_employment_user_info.go
  15. +35
    -0
      app/flexible_employment/enum/enum_api.go
  16. +22
    -0
      app/flexible_employment/enum/enum_pupiao_api.go
  17. +9
    -0
      app/flexible_employment/md/md_api.go
  18. +58
    -0
      app/flexible_employment/md/md_call_back.go
  19. +77
    -0
      app/flexible_employment/md/mq.go
  20. +105
    -0
      app/flexible_employment/svc/svc_fin_withdraw_apply.go
  21. +99
    -0
      app/flexible_employment/utils/aes/utils.go
  22. +26
    -0
      app/flexible_employment/utils/algorithm.go
  23. +60
    -0
      app/flexible_employment/utils/rpc_client.go
  24. +10
    -0
      app/flexible_employment/utils/string.go
  25. +155
    -0
      app/lib/flexible_employment/gongmao.go
  26. +117
    -0
      app/lib/flexible_employment/pupiao.go
  27. +3
    -0
      app/utils/convert.go
  28. +5
    -3
      consume/init.go
  29. +20
    -0
      consume/md/consume_key.go
  30. +165
    -0
      consume/withdraw_consume_gongmao.go
  31. +176
    -0
      consume/withdraw_consume_pupiao.go
  32. +1
    -2
      go.mod

+ 3
- 3
app/db/db_user.go Ver fichero

@@ -193,8 +193,8 @@ func UserFindByID(Db *xorm.Engine, id interface{}) (*model.User, error) {
}
return &m, nil
}
func UserFindByIDWithSession(sess *xorm.Session, id interface{}) (*model.User, error) {
var m model.User
func UserFindByIDWithSession(sess *xorm.Session, id interface{}) (*model.UserProfile, error) {
var m model.UserProfile
if has, err := sess.Where("uid = ?", id).
Get(&m); err != nil || has == false {
return nil, logx.Warn(err)
@@ -290,7 +290,7 @@ func UserUpdate(Db *xorm.Engine, uid interface{}, user *model.User, forceColums
return affected, nil
}

func UserUpdateWithSession(Db *xorm.Session, uid interface{}, user *model.User, forceColums ...string) (int64, error) {
func UserUpdateWithSession(Db *xorm.Session, uid interface{}, user *model.UserProfile, forceColums ...string) (int64, error) {
var (
affected int64
err error


+ 1
- 1
app/db/db_user_withdrawapply.go Ver fichero

@@ -63,7 +63,7 @@ func UserWithDrawApplyByUIDByTime(Db *xorm.Engine, uid interface{}, stime, etime
return m, nil
}

func UserWithDrawApplyByUIDById(Db *xorm.Engine, id int64) (*model.FinWithdrawApply, error) {
func UserWithDrawApplyByUIDById(Db *xorm.Engine, id string) (*model.FinWithdrawApply, error) {
var m model.FinWithdrawApply
has, err := Db.Where("id = ?", id).Get(&m)
if err != nil {


+ 1
- 1
app/db/dbs_map.go Ver fichero

@@ -110,7 +110,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, 31585332).Find(&m)
err = Db.Where("deleted_at != ? AND db_master_id=?", 1, 89608884).Find(&m)
} else {
err = Db.Where("deleted_at != ? AND is_dev = '1' ", 1).Find(&m)
}


+ 1
- 0
app/db/model/fin_withdraw_apply.go Ver fichero

@@ -8,6 +8,7 @@ type FinWithdrawApply struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') index INT(10)"`
AdmId int `json:"adm_id" xorm:"not null default 0 comment('审核人ID,0为系统自动') INT(10)"`
FeeType int `json:"fee_type" xorm:"not null default 0 comment('审核人ID,0为系统自动') INT(10)"`
Amount string `json:"amount" xorm:"not null default 0.00 comment('提现金额') DECIMAL(10,2)"`
Memo string `json:"memo" xorm:"not null default '' comment('备注,失败请备注原因') VARCHAR(500)"`
Type int `json:"type" xorm:"not null default 1 comment('提现类型;1:手动;2:自动') TINYINT(1)"`


+ 40
- 0
app/flexible_employment/db/db_flexible_employment_basic.go Ver fichero

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

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

type FlexibleEmploymentBasicDb struct {
Db *xorm.Engine `json:"model"`
}

func (flexibleEmploymentBasicDb *FlexibleEmploymentBasicDb) Set() { // set方法
flexibleEmploymentBasicDb.Db = db.Db
}

func (flexibleEmploymentBasicDb *FlexibleEmploymentBasicDb) Get(masterId string) (m *model.FlexibleEmploymentBasic, err error) {
m = new(model.FlexibleEmploymentBasic)
has, err := flexibleEmploymentBasicDb.Db.Where("master_id = ?", masterId).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (flexibleEmploymentBasicDb *FlexibleEmploymentBasicDb) GetBasicByAppKey(appKey string) (m *model.FlexibleEmploymentBasic, err error) {
m = new(model.FlexibleEmploymentBasic)
has, err := flexibleEmploymentBasicDb.Db.Where("app_key = ?", appKey).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

+ 44
- 0
app/flexible_employment/db/db_flexible_employment_ord.go Ver fichero

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

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

type FlexibleEmploymentOrdDb struct {
Db *xorm.Engine `json:"model"`
}

func (flexibleEmploymentOrdDb *FlexibleEmploymentOrdDb) Set(masterId string) { // set方法
flexibleEmploymentOrdDb.Db = db.DBs[masterId]
}

func (flexibleEmploymentOrdDb *FlexibleEmploymentOrdDb) Get(requestId string) (m *model.FlexibleEmploymentOrd, err error) {
m = new(model.FlexibleEmploymentOrd)
has, err := flexibleEmploymentOrdDb.Db.Where("request_id = ?", requestId).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (flexibleEmploymentOrdDb *FlexibleEmploymentOrdDb) Update(id interface{}, m *model.FlexibleEmploymentOrd, forceColums ...string) (int64, error) {
var (
affected int64
err error
)
if forceColums != nil {
affected, err = flexibleEmploymentOrdDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = flexibleEmploymentOrdDb.Db.Where("id=?", id).Update(m)
}
if err != nil {
return 0, err
}
return affected, nil
}

+ 40
- 0
app/flexible_employment/db/db_flexible_employment_pupiao_basic.go Ver fichero

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

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

type FlexibleEmploymentPuiaoBasicDb struct {
Db *xorm.Engine `json:"model"`
}

func (flexibleEmploymentPupiaoBasicDb *FlexibleEmploymentPuiaoBasicDb) Set() { // set方法
flexibleEmploymentPupiaoBasicDb.Db = db.Db
}

func (flexibleEmploymentPupiaoBasicDb *FlexibleEmploymentPuiaoBasicDb) GetBasic(masterId string) (m *model.FlexibleEmploymentPupiaoBasic, err error) {
m = new(model.FlexibleEmploymentPupiaoBasic)
has, err := flexibleEmploymentPupiaoBasicDb.Db.Where("master_id = ?", masterId).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (flexibleEmploymentPupiaoBasicDb *FlexibleEmploymentPuiaoBasicDb) GetBasicByAppId(appId string) (m *model.FlexibleEmploymentPupiaoBasic, err error) {
m = new(model.FlexibleEmploymentPupiaoBasic)
has, err := flexibleEmploymentPupiaoBasicDb.Db.Where("app_id = ?", appId).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

+ 44
- 0
app/flexible_employment/db/db_flexible_employment_pupiao_ord.go Ver fichero

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

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

type FlexibleEmploymentPupiaoOrdDb struct {
Db *xorm.Engine `json:"model"`
}

func (flexibleEmploymentPupiaoOrdDb *FlexibleEmploymentPupiaoOrdDb) Set(masterId string) { // set方法
flexibleEmploymentPupiaoOrdDb.Db = db.DBs[masterId]
}

func (flexibleEmploymentPupiaoOrdDb *FlexibleEmploymentPupiaoOrdDb) Get(outBatchNo string) (m *model.FlexibleEmploymentPupiaoOrd, err error) {
m = new(model.FlexibleEmploymentPupiaoOrd)
has, err := flexibleEmploymentPupiaoOrdDb.Db.Where("out_batch_no = ?", outBatchNo).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (flexibleEmploymentPupiaoOrdDb *FlexibleEmploymentPupiaoOrdDb) Update(id interface{}, m *model.FlexibleEmploymentPupiaoOrd, forceColums ...string) (int64, error) {
var (
affected int64
err error
)
if forceColums != nil {
affected, err = flexibleEmploymentPupiaoOrdDb.Db.Where("id=?", id).Cols(forceColums...).Update(m)
} else {
affected, err = flexibleEmploymentPupiaoOrdDb.Db.Where("id=?", id).Update(m)
}
if err != nil {
return 0, err
}
return affected, nil
}

+ 13
- 0
app/flexible_employment/db/model/flexible_employment_basic.go Ver fichero

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

type FlexibleEmploymentBasic struct {
Id int `json:"id" xorm:"pk autoincr INT(11)"`
AppKey string `json:"app_key" xorm:"app_key"`
AppSecret string `json:"app_secret" xorm:"app_secret"`
SecretId string `json:"secret_id" xorm:"secret_id"`
CallbackUrl string `json:"callback_url" xorm:"callback_url"`
AgreementContent string `json:"agreement_content" xorm:"agreement_content"`
CompanyName string `json:"company_name" xorm:"company_name"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 18
- 0
app/flexible_employment/db/model/flexible_employment_ord.go Ver fichero

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

type FlexibleEmploymentOrd struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
ServiceId string `json:"service_id" xorm:"not null default '' comment('服务主体id') VARCHAR(255)"`
RequestId string `json:"request_id" xorm:"not null default '' comment('提现记录ID') VARCHAR(255)"`
Mobile string `json:"mobile" xorm:"not null default '' comment('手机号') VARCHAR(255)"`
Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(255)"`
Amount string `json:"amount" xorm:"not null default 0.00 comment('提现金额') DECIMAL(8,2)"`
Identity string `json:"identity" xorm:"not null default 0.00 comment('证件号码') DECIMAL(8,2)"`
BankAccount string `json:"bank_account" xorm:"not null default 0 comment('入款账号 银行卡提现此字段传入员工绑定的银行卡,支付宝提现此字段请传入员工绑定的支付宝账号') TINYINT(1)"`
SettleType string `json:"settle_type" xorm:"not null default '' comment('商户提现账户类型 银行通道:BANK, 微信通道:WECHAT, 支付宝通道:ALIPAY 例如:传BANK会从商户银行账户扣款') CHAR(50)"`
CallbackDataForTradeResult string `json:"callback_data_for_trade_result" xorm:"not null comment('交易结果通知') TEXT"`
State int `json:"state" xorm:"not null default 0 comment('状态(0:待提交易 1:已提交交易 2:交易成功 3:交易失败)') TINYINT(1)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 14
- 0
app/flexible_employment/db/model/flexible_employment_pupiao_basic.go Ver fichero

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

type FlexibleEmploymentPupiaoBasic struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
MasterId int `json:"master_id" xorm:"not null default 0 comment('站长ID') INT(11)"`
AppId string `json:"app_id" xorm:"not null default '' comment('appId') VARCHAR(255)"`
AppSecret string `json:"app_secret" xorm:"not null default '' comment('appSecret') VARCHAR(255)"`
HrCompanyId string `json:"hr_company_id" xorm:"not null default '' comment('hrcompanyId') VARCHAR(255)"`
SettleAccountId string `json:"settle_account_id" xorm:"not null default '' comment('settleAccountId') VARCHAR(255)"`
CallbackUrl string `json:"callback_url" xorm:"not null default '' comment('回调地址') VARCHAR(255)"`
WithdrawalType int `json:"withdrawal_type" xorm:"not null default 1 comment('提现方式(1:支付宝 2:银行卡)') TINYINT(1)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 21
- 0
app/flexible_employment/db/model/flexible_employment_pupiao_ord.go Ver fichero

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

type FlexibleEmploymentPupiaoOrd struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
WithdrawApplyId int64 `json:"withdraw_apply_id" xorm:"not null default 0 comment('提现记录ID') BIGINT(20)"`
OutBatchNo string `json:"out_batch_no" xorm:"not null default '' comment('外部商户批次订单号') VARCHAR(255)"`
PlatformBatchNo string `json:"platform_batch_no" xorm:"not null default '' comment('平台批次订单号') VARCHAR(255)"`
TotalAmount string `json:"total_amount" xorm:"not null default 0.00 comment('总金额') DECIMAL(8,2)"`
ValidTotalFeeAmount string `json:"valid_total_fee_amount" xorm:"not null default 0.00 comment('平台总服务费金额') DECIMAL(8,2)"`
BatchStatus int `json:"batch_status" xorm:"not null default 0 comment('批次状态(0:待创建 1:制单失败 2:待确认支付 3:支付成功 4:支付失败)') TINYINT(1)"`
SettleType string `json:"settle_type" xorm:"not null default '' comment('结算方式(CARD:银行卡,ALIPAY:支付宝,WECHAT:微信)') CHAR(50)"`
PayeeNo string `json:"payee_no" xorm:"not null default '' comment('收款人账户') CHAR(50)"`
PayeePhone string `json:"payee_phone" xorm:"not null default '' comment('收款人手机号') CHAR(50)"`
PayeeName string `json:"payee_name" xorm:"not null default '' comment('收款人姓名') CHAR(50)"`
PayeeIdCard string `json:"payee_id_card" xorm:"not null default '' comment('收款人身份证号') CHAR(50)"`
CallbackDataForReceiveOrder string `json:"callback_data_for_receive_order" xorm:"not null comment('制单回调通知') TEXT"`
CallbackDataForTradeResult string `json:"callback_data_for_trade_result" xorm:"not null comment('交易结果通知') TEXT"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 13
- 0
app/flexible_employment/db/model/flexible_employment_pupiao_user_info.go Ver fichero

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

type FlexibleEmploymentPupiaoUserInfo struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 INT(11)"`
Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(255)"`
Mobile string `json:"mobile" xorm:"not null default '' comment('手机号') VARCHAR(255)"`
Identity string `json:"identity" xorm:"not null default '' comment('证件号码') VARCHAR(255)"`
BankAccountNo string `json:"bank_account_no" xorm:"not null default '' comment('默认银行账号') VARCHAR(255)"`
AlipayAccountNo string `json:"alipay_account_no" xorm:"not null default '' comment('默认支付宝账号') VARCHAR(255)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 17
- 0
app/flexible_employment/db/model/flexible_employment_user_info.go Ver fichero

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

type FlexibleEmploymentUserInfo struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 INT(11)"`
Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(255)"`
Mobile string `json:"mobile" xorm:"not null default '' comment('手机号') VARCHAR(255)"`
Identity string `json:"identity" xorm:"not null default '' comment('证件号码') VARCHAR(255)"`
BankAccountNo string `json:"bank_account_no" xorm:"not null default '' comment('默认银行账号') VARCHAR(255)"`
AlipayAccountNo string `json:"alipay_account_no" xorm:"not null default '' comment('默认支付宝账号') VARCHAR(255)"`
IdentityFrontBase64 string `json:"identity_front_base64" xorm:"not null comment('证件头像面图片base64(图片大小不能超过3M)') TEXT"`
IdentityBackgroundBase64 string `json:"identity_background_base64" xorm:"not null comment('证件国徽面图片base64(图片大小不能超过3M)') TEXT"`
ContractId string `json:"contract_id" xorm:"not null comment('合同id') CHAR(50)"`
State int `json:"state" xorm:"not null default 0 comment('状态(0:未签约(员工未同步) 1:待签约(员工已同步,但未确认签约)2:签约文件生成中(用户已确认签署,合同文件正在生成,此状态可发起提现) 3:签约完成 (用户已签约,签约合同生成完成))') TINYINT(1)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"`
}

+ 35
- 0
app/flexible_employment/enum/enum_api.go Ver fichero

@@ -0,0 +1,35 @@
package enum

type GongMaoMethodName string

const (
MerchantContractGetList = "/api/merchant/contract/getList"
MerchantEmployeeSyncInfo = "/api/merchant/employee/syncInfo"
MerchantEmployeeSignContract = "/api/merchant/employee/signContract"
MerchantQueryBalance = "/api/merchant/queryBalance"
MerchantDoSinglePayment = "/api/merchant/doSinglePayment"
MerchantEmployeeGetContractStatusByContractId = "/api/merchant/employee/getContractStatusByContractId"
MerchantEmployeeDeleteContract = "/api/merchant/employee/deleteContract"
MerchantEmployeeUpdateEmployee = "/api/merchant/employee/updateEmployee"
)

func (gt GongMaoMethodName) String() string {
switch gt {
case MerchantContractGetList:
return "查询电签时需要的合同模板列表"
case MerchantEmployeeSyncInfo:
return "发起签署"
case MerchantEmployeeSignContract:
return "确认签署"
case MerchantEmployeeGetContractStatusByContractId:
return "通过合同id查询电签结果"
case MerchantEmployeeDeleteContract:
return "员工解除签署"
case MerchantDoSinglePayment:
return "提现"
case MerchantEmployeeUpdateEmployee:
return "更新员工默认手机号或者账号"
default:
return "未知"
}
}

+ 22
- 0
app/flexible_employment/enum/enum_pupiao_api.go Ver fichero

@@ -0,0 +1,22 @@
package enum

type PuPiaoMethodName string

const (
OpenApiContractSignApply = "/open/api/contract/signApply"
OpenApiPaymentReceiveOrder = "/open/api/payment/receiveOrder"
OpenApiPaymentConfirmPay = "/open/api/payment/confirmPay"
)

func (gt PuPiaoMethodName) String() string {
switch gt {
case OpenApiContractSignApply:
return "申请签约接口"
case OpenApiPaymentReceiveOrder:
return "发起制单"
case OpenApiPaymentConfirmPay:
return "确认支付"
default:
return "未知"
}
}

+ 9
- 0
app/flexible_employment/md/md_api.go Ver fichero

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

type CurlPuPiaoConfirmPayResponse struct {
IsSuccess string `json:"isSuccess"`
Data interface{} `json:"data"`
Charset string `json:"charset"`
ErrorMsg string `json:"errorMsg"`
ErrorCode string `json:"errorCode"`
}

+ 58
- 0
app/flexible_employment/md/md_call_back.go Ver fichero

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

type CallbackRequestForPuPiao struct {
AppId string `json:"appId"` //appId
PlatformOrderNo string `json:"platformOrderNo"` //平台订单号
NotifyType string `json:"notifyType"` //通知业务类型
NotifyContent string `json:"notifyContent"` //业务参数加密密文 (根据不同通知类型解密后参数不同,具体请参考通知类型参数说明)
Sign string `json:"sign"` //签名字符串
}

type CallbackRequestForPuPiaoByRECEIVEORDER struct {
PlatformBatchNo string `json:"platformBatchNo"` //平台批次订单号
OutBatchNo string `json:"outBatchNo"` //外部商户批次订单号
TotalCount string `json:"totalCount"` //总笔数
TotalAmount string `json:"totalAmount"` //总金额
ValidTotalCount string `json:"validTotalCount"` //有效订单(平台收单成功)-总笔数
ValidTotalAmount string `json:"validTotalAmount"` //有效订单(平台收单成功)-总金额
ValidTotalFeeAmount string `json:"validTotalFeeAmount"` //有效订单(平台收单成功)-平台总服务费金额
BatchStatus string `json:"batchStatus"` //批次状态 RECEIVE_FAIL:收单失败(整批次下全部失败) WAIT_CONFIRM:待确认支付(有效订单笔数大于0时,为此批次状态)
ItemList []struct {
PlatformOrderNo string `json:"platformOrderNo"` //单笔平台订单号
OutTradeNo string `json:"outTradeNo"` //单笔外部商户订单号(批次下唯一不可重复)
SettleType string `json:"settleType"` //结算方式(CARD:银行卡,ALIPAY:支付宝,WECHAT:微信)
PayeeName string `json:"payeeName"` //收款人姓名
PayeeIdCard string `json:"payeeIdCard"` //收款人身份证号
PayeePhone string `json:"payeePhone"` //收款人手机号
PayeeNo string `json:"payeeNo"` //收款人账户
OrderAmount string `json:"orderAmount"` //订单金额(最多保留两位小数)
OrderStatus string `json:"orderStatus"` //单笔订单状态,见以下取值范围 RECEIVE_FAIL:收单失败 WAIT_CONFIRM:待确认支付
PayeeBankName string `json:"payeeBankName"` //收款人银行名称
PayeeBranchNo string `json:"payeeBranchNo"` //收款人分行联行号
OrderMemo string `json:"orderMemo"` //付款备注摘要
FeeAmount string `json:"feeAmount"` //单笔平台服务费金额
ErrorCode string `json:"errorCode"` //单笔异常code
ErrorMsg string `json:"errorMsg"` //单笔异常msg
} `json:"itemList"` //批次明细list
}

type CallbackRequestForPuPiaoByTRADERESULT struct {
PlatformBatchNo string `json:"platformBatchNo"` //平台批次订单号
OutBatchNo string `json:"outBatchNo"` //外部商户批次订单号
PlatformOrderNo string `json:"platformOrderNo"` //单笔平台订单号
OutTradeNo string `json:"outTradeNo"` //单笔外部商户订单号(批次下唯一不可重复)
SettleType string `json:"settleType"` //结算方式(CARD:银行卡,ALIPAY:支付宝,WECHAT:微信)
PayeeName string `json:"payeeName"` //收款人姓名
PayeeIdCard string `json:"payeeIdCard"` //收款人身份证号
PayeePhone string `json:"payeePhone"` //收款人手机号
PayeeNo string `json:"payeeNo"` //收款人账户
OrderAmount string `json:"orderAmount"` //订单金额(最多保留两位小数)
OrderStatus string `json:"orderStatus"` //单笔订单状态,见以下取值范围 RECEIVE_FAIL:收单失败 WAIT_CONFIRM:待确认支付
TradeTime string `json:"tradeTime"` //交易时间(格式 yyyy-MM-dd HH:mm:ss)
PayeeBankName string `json:"payeeBankName"` //收款人银行名称
PayeeBranchNo string `json:"payeeBranchNo"` //收款人分行联行号
OrderMemo string `json:"orderMemo"` //付款备注摘要
FeeAmount string `json:"feeAmount"` //单笔平台服务费金额
ErrorCode string `json:"errorCode"` //单笔异常code
ErrorMsg string `json:"errorMsg"` //单笔异常msg
}

+ 77
- 0
app/flexible_employment/md/mq.go Ver fichero

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

const RobotQrcodeMacLoginQueue = "cloud_issuance_async_mlogin"
const CloudIssuanceMsgCallBackQueue = "cloud_issuance_msg_call_back" //云发单消息回调

type CloudIssuanceAsyncMLogin struct {
UserId string `json:"user_id"` //用户id
MasterId string `json:"master_id"` //站长id
WId string `json:"wId"` //实例id
RobotId int `json:"robot_id"` //机器人id
QrCodeUrl string `json:"qrCodeUrl"`
}

const UserWithdrawApplyExchange = "zhios.app.user.withdraw.apply.exchange"
const ZhiosCapitalPoolOrderTotalExchange = "zhios.capital_pool.order_total.exchange"
const CloudIssuanceMsgCallBackExchange = "zhios.cloud.issuance.msg.callback.exchange"

const DouShenUserRegisterExchange = "zhios.doushen.user.register.exchange"
const FastReturnOrder = "zhios.order.fast.return.exchange"

const (
DouShenUserRegisterRoutKeyForOfficial = "official" // 官方
DouShenUserRegisterRoutKeyForOperationCenter = "operation_center" // 运营中心
DouShenUserRegisterRoutKeyForMyRecommender = "my_recommender" // 我的推荐人
DouShenUserRegisterRoutKeyForMyFans = "my_fans" // 我的粉丝
DouShenUserRegisterRoutKeyForUserRegisterCommUpLv = "user_register_comm_up_lv" // 用户注册自动升级(给推荐人)
FastReturnOrderRoutKeyForOrderPay = "order_pay"
FastReturnOrderRoutKeyForOrderRefund = "order_refund"
FastReturnOrderRoutKeyForOrderSuccess = "order_success"
ZhiosCapitalPoolOrderTotalStr = "order_total"
)

type DouShenUserRegisterMessageStructForOfficial struct {
MasterId string `json:"master_id"`
Phone int64 `json:"phone"`
Uid int64 `json:"uid"`
}
type DouShenUserRegisterMessageStructForMyFans struct {
MasterId string `json:"master_id"`
Phone int64 `json:"phone"`
Uid int64 `json:"uid"`
}
type DouShenUserRegisterMessageStructForMyRecommender struct {
MasterId string `json:"master_id"`
Phone int64 `json:"phone"`
Uid int64 `json:"uid"`
RecommenderUid int64 `json:"recommender_uid"`
RecommenderPhone string `json:"recommender_phone"`
}
type DouShenUserRegisterMessageStructForOperationCenter struct {
MasterId string `json:"master_id"`
Phone int64 `json:"phone"`
Uid int64 `json:"uid"`
OperationCenterUid int64 `json:"operation_center_uid"`
OperationCenterPhone string `json:"operation_center_phone"`
}
type DouShenUserRegisterMessageStructForCommUpLv struct {
MasterId string `json:"master_id"`
Uid int64 `json:"uid"`
}

type ZhiosFatReturnOrderPay struct {
Uid string `json:"uid"`
Mid string `json:"mid"`
Oid string `json:"oid"`
Name string `json:"name"`
Prd string `json:"prd"`
}

type ZhiosCapitalPoolOrderTotal struct {
Uid []string `json:"uid"`
Mid string `json:"mid"`
Runtime int64 `json:"runtime"`
TotalTime int64 `json:"totalTime"`
BonusLevelType int `json:"bonusLevelType"`
Level string `json:"level"`
}

+ 105
- 0
app/flexible_employment/svc/svc_fin_withdraw_apply.go Ver fichero

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

import (
"applet/app/db"
"applet/app/db/model"
model2 "applet/app/flexible_employment/db/model"
"applet/app/svc"
"applet/app/utils"
"errors"
"time"
"xorm.io/xorm"
)

func DealFailResult(sess *xorm.Session, apply *model.FinWithdrawApply, masterId, errMsg string) (err error) {
userProfile, err := db.UserFindByIDWithSession(sess, apply.Uid)
if err != nil {
return err
}

//1、修改提现单为失败
apply.State = 3
apply.Memo = errMsg
updateAck, err := sess.Where("id=?", apply.Id).Cols("state", "memo").Update(apply)
if err != nil {
return err
}
if updateAck <= 0 {
return errors.New("更新提现单失败")
}
updateAck, err = sess.Where("request_id=?", apply.Id).Cols("state", "callback_data_for_trade_result").Update(model2.FlexibleEmploymentOrd{
State: 3,
CallbackDataForTradeResult: errMsg,
})
if err != nil {
return err
}
if updateAck <= 0 {
return errors.New("更新工猫记录失败")
}

//2、判断类型 加回手续费
var finUserFlow model.FinUserFlow
has, err := sess.Where("other_id = ?", apply.Id).Get(&finUserFlow)
if err != nil {
return
}
var sysFee = 0.00
if has && apply.FeeType == 1 {
apply.Amount = utils.Float64ToStr(utils.StrToFloat64(apply.Amount) + utils.StrToFloat64(finUserFlow.SysFee))
sysFee = utils.StrToFloat64(finUserFlow.SysFee)
}

//3、退回余额
cb, err := svc.HandleBalanceDistributedLock(masterId, utils.IntToStr(apply.Uid), "withdraw_consume")
if err != nil {
return
}
if cb != nil {
defer cb()
}
var beforeAmount = userProfile.FinValid
userProfile.FinValid = utils.Float64ToStrPrec4(utils.StrToFloat64(beforeAmount) + utils.StrToFloat64(apply.Amount))
_, err = db.UserUpdateWithSession(sess, userProfile.Uid, userProfile, "fin_valid")
if err != nil {
return err
}

//4、插入流水表
newFinUserFlow := model.FinUserFlow{
Type: 0,
Uid: userProfile.Uid,
Amount: apply.Amount,
BeforeAmount: beforeAmount,
AfterAmount: userProfile.FinValid,
OrdType: "withdraw",
OrdAction: 22,
PaymentType: 1,
SysFee: utils.Float64ToStrPrec4(sysFee),
OrdDetail: "",
OtherId: apply.Id,
OrdTitle: "提现退回",
State: 2,
OrdTime: int(apply.CreateAt.Unix()),
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err = db.InsertCommWithSession(sess, &newFinUserFlow)
if err != nil {
return err
}
return nil
}

func DealSuccessResult(sess *xorm.Session, apply *model.FinWithdrawApply) (err error) {
//1、修改提现单为成功
apply.State = 2
updateAck, err := sess.Where("id=?", apply.Id).Cols("state").Update(apply)
if err != nil {
return err
}
if updateAck <= 0 {
return errors.New("更新提现单失败")
}
return nil
}

+ 99
- 0
app/flexible_employment/utils/aes/utils.go Ver fichero

@@ -0,0 +1,99 @@
package aes

import (
"bytes"
"crypto/aes"
"encoding/base64"
"fmt"
"net/url"
)

// 加密
func AesEncryptByECB(key []byte, plaintext string) (string, error) {
block, err := aes.NewCipher(key)
if err != nil {
return "", err
}

plainBytes := []byte(plaintext)
// PKCS5Padding
pad := block.BlockSize() - len(plainBytes)%block.BlockSize()
plainBytes = append(plainBytes, bytes.Repeat([]byte{byte(pad)}, pad)...)

// ECB模式
encrypted := make([]byte, len(plainBytes))
for bs, be := 0, block.BlockSize(); bs <= len(plainBytes)-block.BlockSize(); bs, be = bs+block.BlockSize(), be+block.BlockSize() {
block.Encrypt(encrypted[bs:be], plainBytes[bs:be])
}

return url.QueryEscape(base64.StdEncoding.EncodeToString(encrypted)), nil
}

// AesDecryptByECB 解密AES ECB加密的字符串
func AesDecryptByECB(key []byte, ciphertext string) (string, error) {

// 先进行URL解码

decodedCiphertext, err := url.QueryUnescape(ciphertext)

if err != nil {

return "", err

}

// Base64解码

encrypted, err := base64.StdEncoding.DecodeString(decodedCiphertext)

if err != nil {

return "", err

}

block, err := aes.NewCipher(key)

if err != nil {

return "", err

}

// ECB模式

decrypted := make([]byte, len(encrypted))

for bs, be := 0, block.BlockSize(); bs < len(encrypted); bs, be = bs+block.BlockSize(), be+block.BlockSize() {

block.Decrypt(decrypted[bs:be], encrypted[bs:be])

}

// 去除PKCS5Padding

decrypted = PKCS5UnPadding(decrypted)

if decrypted == nil {

return "", fmt.Errorf("invalid PKCS5 padding")

}

return string(decrypted), nil

}

// PKCS5UnPadding 去除PKCS5Padding
func PKCS5UnPadding(data []byte) []byte {
length := len(data)

unpadding := int(data[length-1])

if unpadding > length {

return nil

}
return data[:(length - unpadding)]
}

+ 26
- 0
app/flexible_employment/utils/algorithm.go Ver fichero

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

import (
"math/rand"
"time"
)

//RED_PACKET_MIN_MONEY 红包最小金额(单位:分)
const RED_PACKET_MIN_MONEY = 1

//DoubleAverage 二倍均值算法
func DoubleAverage(count, amount int64) int64 {
if count == 1 {
return amount
}
//计算出最大可用金额
max := amount - RED_PACKET_MIN_MONEY*count
//计算出最大可用平均值
avg := max / count
//二倍均值基础上再加上最小金额 防止出现金额为0
avg2 := 2*avg + RED_PACKET_MIN_MONEY
//随机红包金额序列元素,把二倍均值作为随机的最大数
rand.Seed(time.Now().UnixNano())
x := rand.Int63n(avg2) + RED_PACKET_MIN_MONEY
return x
}

+ 60
- 0
app/flexible_employment/utils/rpc_client.go Ver fichero

@@ -0,0 +1,60 @@
package utils

import (
"applet/pkg/pb"
"context"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"strconv"
"time"
)

func GetBusinessIntClient(url, port string) pb.BusinessIntClient {
target := fmt.Sprintf("%s:%s", url, port)
conn, err := grpc.Dial(target, grpc.WithInsecure())
if err != nil {
fmt.Println(err)
return nil
}
return pb.NewBusinessIntClient(conn)
}

func GetBusinessExtClient(url, port string) pb.BusinessExtClient {
target := fmt.Sprintf("%s:%s", url, port)
conn, err := grpc.Dial(target, grpc.WithInsecure())
//defer conn.Close()
if err != nil {
fmt.Println(err)
return nil
}
return pb.NewBusinessExtClient(conn)
}

func GetLogicExtClient(url, port string) pb.LogicExtClient {
target := fmt.Sprintf("%s:%s", url, port)
conn, err := grpc.Dial(target, grpc.WithInsecure())
if err != nil {
fmt.Println(err)
return nil
}
return pb.NewLogicExtClient(conn)
}

func GetCtx(token, userId, deviceId, masterId string) context.Context {
if userId == "" {
userId = "1"
}
if deviceId == "" {
deviceId = "1"
}
if token == "" {
token = "0"
}
return metadata.NewOutgoingContext(context.TODO(), metadata.Pairs(
"user_id", userId,
"device_id", deviceId,
"token", token,
"master_id", masterId,
"request_id", strconv.FormatInt(time.Now().UnixNano(), 10)))
}

+ 10
- 0
app/flexible_employment/utils/string.go Ver fichero

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

func ContainerStr(slice []string, element string) bool {
for _, e := range slice {
if e == element {
return true
}
}
return false
}

+ 155
- 0
app/lib/flexible_employment/gongmao.go Ver fichero

@@ -0,0 +1,155 @@
package flexible_employment

import (
"applet/app/cfg"
"applet/app/utils"
"bytes"
"crypto/md5"
"crypto/tls"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
"time"
)

type GongMao struct {
AppKey string
AppSecret string
Nonce string
Timestamp string
ServiceId string
Sign string
}

const postUrlForPrd = "https://openapi.gongmall.com"
const postUrlForDev = "https://openapi-qa.gongmall.com"

func New(appKey, appSecret, serviceId string) *GongMao {
return &GongMao{
AppKey: appKey,
AppSecret: appSecret,
Nonce: randomString(32),
Timestamp: "", // 生成timestamp(当前毫秒时间戳)
ServiceId: serviceId,
Sign: "",
}
}

// generateSign 生成签名
func (gm *GongMao) generateSign(params map[string]interface{}, appSecret string) string {
var keys []string
for k := range params {
keys = append(keys, k)
}
sort.Strings(keys)
var stringA bytes.Buffer
for _, k := range keys {
if stringA.Len() > 0 {
stringA.WriteString("&")
}
stringA.WriteString(url.QueryEscape(k))
stringA.WriteString("=")
stringA.WriteString(utils.AnyToString(params[k]))
}

stringSignTemp := stringA.String() + "&appSecret=" + appSecret
h := md5.New()
h.Write([]byte(stringSignTemp))
sign := hex.EncodeToString(h.Sum(nil))
return strings.ToUpper(sign)
}

func (gm *GongMao) Curl(uri string, params map[string]interface{}) (result map[string]interface{}, err error) {
// 准备请求参数
gm.Timestamp = strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10)
paramData := make(map[string]interface{})
paramData = gm.mergeMaps(map[string]interface{}{
"appKey": gm.AppKey,
"nonce": gm.Nonce,
"serviceId": gm.ServiceId,
"timestamp": gm.Timestamp,
}, params)

// 生成签名
paramData["sign"] = gm.generateSign(paramData, gm.AppSecret)

// 编码请求参数为URL编码的字符串
form := url.Values{}
for key, value := range paramData {
form.Set(key, utils.AnyToString(value))
}
requestBody := form.Encode()

// 构造请求
var url string
fmt.Println("prd::::::::::", cfg.Prd)
if cfg.Prd {
url = postUrlForPrd + uri
} else {
url = postUrlForDev + uri
}
fmt.Println("url::::::::::", url)

req, err := http.NewRequest("POST", url, bytes.NewBufferString(requestBody))
if err != nil {
return
}

// 设置请求头
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

// 发送请求
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
resp, err := client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()

// 读取响应体
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}

// 打印响应内容
fmt.Printf("Response: %s\n", body)

// 解析JSON响应
err = json.Unmarshal(body, &result)
if err != nil {
return
}
return
}

// 合并map
func (gm *GongMao) mergeMaps(map1, map2 map[string]interface{}) map[string]interface{} {
for key, value := range map2 {
map1[key] = value
}
return map1
}

// 随机生成指定位数的大写字母和数字的组合
func randomString(ln int) string {
letters := []rune("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, ln)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := range b {
b[i] = letters[r.Intn(len(letters))]
}

return string(b)
}

+ 117
- 0
app/lib/flexible_employment/pupiao.go Ver fichero

@@ -0,0 +1,117 @@
package flexible_employment

import (
"applet/app/cfg"
"bytes"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"sort"
"strconv"
"time"
)

type PuPiao struct {
AppId string
Charset string
Version string
Sign string
RequestId string
AppSecret string
}

const urlForPrd = "https://openapi.gongmall.com"
const urlForDev = "http://api.testlg.cn"

func NewPuPiao(appId, appSecret string) *PuPiao {
return &PuPiao{
AppId: appId,
Charset: "UTF-8",
Version: "1.0",
Sign: "",
RequestId: "",
AppSecret: appSecret,
}
}

// generateSign 生成签名
func (gm *PuPiao) generateSign(params map[string]interface{}, appSecret string) string {
var keys []string
for k := range params {
keys = append(keys, k)
}
sort.Strings(keys)
var stringA = map[string]interface{}{}
for _, k := range keys {
stringA[k] = params[k]
}
str, _ := json.Marshal(stringA)
paramJson := string(str)
stringSignTemp := paramJson + appSecret
h := md5.New()
h.Write([]byte(stringSignTemp))
sign := hex.EncodeToString(h.Sum(nil))
return sign
}

func (gm *PuPiao) Curl(uri string, params map[string]interface{}) (result map[string]interface{}, err error) {
// 准备请求参数
gm.RequestId = strconv.FormatInt(time.Now().UnixNano()/int64(time.Microsecond), 10) //请求Id,每次请求唯一
paramData := make(map[string]interface{})
paramData = gm.mergeMaps(map[string]interface{}{
"appId": gm.AppId,
"charset": gm.Charset,
"requestId": gm.RequestId,
"version": gm.Version,
}, params)

// 生成签名
paramData["sign"] = gm.generateSign(paramData, gm.AppSecret)
b, err := json.Marshal(paramData)
if err != nil {
return
}

// 构造请求
var url string
if cfg.Prd {
url = urlForPrd + uri
} else {
url = urlForDev + uri
}
fmt.Println("url::::::::::", url)
postBody, err := gm.httpPostBody(url, b)
if err != nil {
return
}
// 打印响应内容
fmt.Printf("Response: %s\n", postBody)

// 解析JSON响应
err = json.Unmarshal(postBody, &result)
if err != nil {
return
}
return
}

// 合并map
func (gm *PuPiao) mergeMaps(map1, map2 map[string]interface{}) map[string]interface{} {
for key, value := range map2 {
map1[key] = value
}
return map1
}

func (gm *PuPiao) httpPostBody(url string, msg []byte) ([]byte, error) {
resp, err := http.Post(url, "application/json;charset=utf-8", bytes.NewBuffer(msg))
if err != nil {
return []byte(""), err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
return body, err
}

+ 3
- 0
app/utils/convert.go Ver fichero

@@ -278,6 +278,9 @@ func Float64ToStr(f float64) string {
func Float64ToStrPrec1(f float64) string {
return strconv.FormatFloat(f, 'f', 1, 64)
}
func Float64ToStrPrec4(f float64) string {
return strconv.FormatFloat(f, 'f', 4, 64)
}

func Float32ToStr(f float32) string {
return Float64ToStr(float64(f))


+ 5
- 3
consume/init.go Ver fichero

@@ -84,10 +84,12 @@ func initConsumes() {
//jobs[consumeMd.OneCirclesSignInCopyGreenEnergyFunName] = OneCirclesSignInCopyGreenEnergyConsume

//////////////////////////////////////// withdraw /////////////////////////////////////////////////////
//jobs[consumeMd.WithdrawConsumeFunName] = WithdrawConsume
jobs[consumeMd.WithdrawConsumeFunName] = WithdrawConsume
jobs[consumeMd.FlexibleEmploymentWithdrawForGongMaoConsumeFunName] = FlexibleEmploymentWithdrawForGongMaoConsume
//jobs[consumeMd.FlexibleEmploymentWithdrawForPupiaoConsumeFunName] = FlexibleEmploymentWithdrawForPupiaoConsume

jobs[consumeMd.ZhiosMallGreenCoinConsumeFunName] = ZhiosMallGreenCoinConsume //绿色双链积分
jobs[consumeMd.ZhiosOneCirclesCoinConsumeFunName] = ZhiosOneCirclesCoinConsume //一个圈圈虚拟币变化
//jobs[consumeMd.ZhiosMallGreenCoinConsumeFunName] = ZhiosMallGreenCoinConsume //绿色双链积分
//jobs[consumeMd.ZhiosOneCirclesCoinConsumeFunName] = ZhiosOneCirclesCoinConsume //一个圈圈虚拟币变化
}

func Run() {


+ 20
- 0
consume/md/consume_key.go Ver fichero

@@ -443,6 +443,24 @@ var RabbitMqQueueKeyList = []*MqQueue{
BindKey: "",
ConsumeFunName: "WithdrawConsume",
},
{
ExchangeName: "zhios.app.user.withdraw.apply.flexible.employment.exchange",
Name: "zhios_app_user_withdraw_apply_gongmao_queue",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "gongmao",
BindKey: "",
ConsumeFunName: "FlexibleEmploymentWithdrawForGongMaoConsume",
},
{
ExchangeName: "zhios.app.user.withdraw.apply.flexible.employment.exchange",
Name: "zhios_app_user_withdraw_apply_pupiao_queue",
Type: DirectQueueType,
IsPersistent: false,
RoutKey: "pupiao",
BindKey: "",
ConsumeFunName: "FlexibleEmploymentWithdrawForPupiaoConsume",
},
}

const (
@@ -495,4 +513,6 @@ const (
OneCirclesStartLevelDividendFunName = "OneCirclesStartLevelDividendConsume"
OneCirclesSignInCopyGreenEnergyFunName = "OneCirclesSignInCopyGreenEnergyConsume"
WithdrawConsumeFunName = "WithdrawConsume"
FlexibleEmploymentWithdrawForGongMaoConsumeFunName = "FlexibleEmploymentWithdrawForGongMaoConsume"
FlexibleEmploymentWithdrawForPupiaoConsumeFunName = "FlexibleEmploymentWithdrawForPupiaoConsume"
)

+ 165
- 0
consume/withdraw_consume_gongmao.go Ver fichero

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

import (
"applet/app/cfg"
"applet/app/db"
db2 "applet/app/flexible_employment/db"
"applet/app/flexible_employment/enum"
"applet/app/flexible_employment/svc"
"applet/app/lib/flexible_employment"
"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 FlexibleEmploymentWithdrawForGongMaoConsume(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>FlexibleEmploymentWithdrawForGongMaoConsume>>>>>>>>>>>>")
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 = handleFlexibleEmploymentWithdrawForGongMaoConsume(res.Body)
fmt.Println("err ::: ", err)
if err != nil {
fmt.Println("FlexibleEmploymentWithdrawForGongMaoConsume_ERR:::::", err.Error())
_ = res.Reject(true)
//_ = 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("FlexibleEmploymentWithdrawForGongMaoConsume_ERR", utils.SerializeStr(err.Error()))
ch.Publish("zhios.app.user.withdraw.apply.exception.exchange", msg, "gongmao")
}
} else {
err = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleFlexibleEmploymentWithdrawForGongMaoConsume(msgData []byte) error {
var ms string
err := json.Unmarshal(msgData, &ms)
if err != nil {
return err
}
time.Sleep(time.Microsecond * 200) // 等待200毫秒
//1、解析mq中queue的数据结构体
var msg struct {
Uid string `json:"uid"`
Nickname string `json:"nickname"`
MasterId string `json:"master_id"`
AppName string `json:"app_name"`
ApplyOrder string `json:"apply_order"`
ActualAmount string `json:"actual_amount"`
MobCfg interface{} `json:"mob_cfg"`
}
err = json.Unmarshal([]byte(ms), &msg)
if err != nil {
return err
}
fmt.Println("gongmao_message:::::::::::>>>>>>>>>")
fmt.Println(msg)
if db.DBs[msg.MasterId] == nil {
return nil
}
engine := db.DBs[msg.MasterId]

//1、查找对应记录
flexibleEmploymentOrdDb := db2.FlexibleEmploymentOrdDb{}
flexibleEmploymentOrdDb.Set(msg.MasterId)
flexibleEmploymentOrd, err := flexibleEmploymentOrdDb.Get(msg.ApplyOrder)
if err != nil {
return err
}
if flexibleEmploymentOrd == nil {
return errors.New("未查询到对应订单记录")
}

flexibleEmploymentBasicDb := db2.FlexibleEmploymentBasicDb{}
flexibleEmploymentBasicDb.Set()
basic, err := flexibleEmploymentBasicDb.Get(msg.MasterId)
if err != nil {
return err
}
gongMao := flexible_employment.New(basic.AppKey, basic.AppSecret, basic.SecretId)
result, err := gongMao.Curl(enum.MerchantDoSinglePayment, map[string]interface{}{
"requestId": flexibleEmploymentOrd.RequestId,
"mobile": flexibleEmploymentOrd.Mobile,
"name": flexibleEmploymentOrd.Name,
"amount": flexibleEmploymentOrd.Amount,
"identity": flexibleEmploymentOrd.Identity,
"bankAccount": flexibleEmploymentOrd.BankAccount,
"dateTime": time.Now().Format("20060102150405"),
"salaryType": flexibleEmploymentOrd.SettleType,
})
if err != nil {
return err
}
var response struct {
Success bool `json:"success"`
ErrorCode string `json:"errorCode"`
ErrorMsg string `json:"errorMsg"`
Data struct {
RequestId string `json:"requestId"`
AppmentTime string `json:"appmentTime"`
} `json:"data"`
}
if err = json.Unmarshal(utils.Serialize(result), &response); err != nil {
return err
}
if !response.Success {
//TODO::发起提现失败,将处理提现失败状态
finWithdrawApply, err := db.UserWithDrawApplyByUIDById(engine, flexibleEmploymentOrd.RequestId)
if err != nil {
return err
}
session := engine.NewSession()
defer session.Close()
session.Begin()
err = svc.DealFailResult(session, finWithdrawApply, msg.MasterId, response.ErrorMsg)
if err != nil {
_ = session.Rollback()
return err
}
return session.Commit()
}
flexibleEmploymentOrd.State = 1
updateAck, err := flexibleEmploymentOrdDb.Update(flexibleEmploymentOrd.Id, flexibleEmploymentOrd, "state")
if err != nil {
return err
}
if updateAck <= 0 {
return errors.New("更新 flexible_employment_ord 状态失败")
}
return nil
}

+ 176
- 0
consume/withdraw_consume_pupiao.go Ver fichero

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

import (
"applet/app/cfg"
"applet/app/db"
db2 "applet/app/flexible_employment/db"
"applet/app/flexible_employment/enum"
"applet/app/flexible_employment/svc"
"applet/app/flexible_employment/utils/aes"
"applet/app/lib/flexible_employment"
"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 FlexibleEmploymentWithdrawForPupiaoConsume(queue md.MqQueue) {
fmt.Println(">>>>>>>>>>>>FlexibleEmploymentWithdrawForPupiaoConsume>>>>>>>>>>>>")
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 = handleFlexibleEmploymentWithdrawForPupiaoConsume(res.Body)
fmt.Println("err ::: ", err)
if err != nil {
fmt.Println("FlexibleEmploymentWithdrawForPupiaoConsume_ERR:::::", err.Error())
//_ = res.Reject(true)
_ = 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("FlexibleEmploymentWithdrawForPupiaoConsume_ERR", utils.SerializeStr(err.Error()))
ch.Publish("zhios.app.user.withdraw.apply.exception.exchange", msg, "pupiao")
}
} else {
err = res.Ack(true)
}
} else {
panic(errors.New("error getting message"))
}
}
fmt.Println("get msg done")
}

func handleFlexibleEmploymentWithdrawForPupiaoConsume(msgData []byte) error {
time.Sleep(time.Microsecond * 200) // 等待200毫秒
//1、解析mq中queue的数据结构体
var msg struct {
Uid string `json:"uid"`
Nickname string `json:"nickname"`
MasterId string `json:"master_id"`
AppName string `json:"app_name"`
ApplyOrder string `json:"apply_order"`
ActualAmount string `json:"actual_amount"`
Oid string `json:"oid"`
MobCfg string `json:"mob_cfg"`
}
err := json.Unmarshal(msgData, &msg)
if err != nil {
return err
}
fmt.Println("pupiao_message:::::::::::>>>>>>>>>")
fmt.Println(msg)
if db.DBs[msg.MasterId] == nil {
return nil
}
engine := db.DBs[msg.MasterId]

//1、查找对应记录
flexibleEmploymentPupiaoOrdDb := db2.FlexibleEmploymentPupiaoOrdDb{}
flexibleEmploymentPupiaoOrdDb.Set(msg.MasterId)
flexibleEmploymentPupiaoOrd, err := flexibleEmploymentPupiaoOrdDb.Get(msg.Oid)
if err != nil {
return err
}
if flexibleEmploymentPupiaoOrd == nil {
return errors.New("未查询到对应订单记录")
}

flexibleEmploymentPuiaoBasicDb := db2.FlexibleEmploymentPuiaoBasicDb{}
flexibleEmploymentPuiaoBasicDb.Set()
basic, err := flexibleEmploymentPuiaoBasicDb.GetBasic(msg.MasterId)
if err != nil {
return err
}

//2、发起制单
puPiao := flexible_employment.NewPuPiao(basic.AppId, basic.AppSecret)
var userAESData = []map[string]string{
{
"outTradeNo": "o_" + utils.Int64ToStr(flexibleEmploymentPupiaoOrd.WithdrawApplyId),
"settleType": flexibleEmploymentPupiaoOrd.SettleType,
"payeeName": flexibleEmploymentPupiaoOrd.PayeeName,
"payeeIdCard": flexibleEmploymentPupiaoOrd.PayeeIdCard,
"payeePhone": flexibleEmploymentPupiaoOrd.PayeePhone,
"payeeNo": flexibleEmploymentPupiaoOrd.PayeeNo,
"orderAmount": flexibleEmploymentPupiaoOrd.TotalAmount,
},
}
str, _ := json.Marshal(userAESData)
itemAESContent, _ := aes.AesEncryptByECB([]byte(basic.AppSecret), string(str))
result, err := puPiao.Curl(enum.OpenApiPaymentReceiveOrder, map[string]interface{}{
"outBatchNo": flexibleEmploymentPupiaoOrd.OutBatchNo,
"hrcompanyId": basic.HrCompanyId,
"settleAccountId": basic.SettleAccountId,
"totalCount": "1",
"totalAmount": flexibleEmploymentPupiaoOrd.TotalAmount,
"itemAESContent": itemAESContent,
})
if err != nil {
return err
}
var response struct {
IsSuccess string `json:"isSuccess"`
Charset string `json:"charset"`
ErrorCode string `json:"errorCode"`
ErrorMsg string `json:"errorMsg"`
Data struct {
PlatformBatchNo string `json:"platformBatchNo"`
OutBatchNo string `json:"outBatchNo"`
} `json:"data"`
}
if err = json.Unmarshal(utils.Serialize(result), &response); err != nil {
return err
}
if response.IsSuccess == "F" {
flexibleEmploymentPupiaoOrd.BatchStatus = 1
updateAck, err := flexibleEmploymentPupiaoOrdDb.Update(flexibleEmploymentPupiaoOrd.Id, flexibleEmploymentPupiaoOrd, "batch_status")
if err != nil {
return err
}
if updateAck <= 0 {
return errors.New("更新 flexible_employment_pupiao_ord 状态失败")
}
//TODO::制单失败,将处理提现失败状态
finWithdrawApply, err := db.UserWithDrawApplyByUIDById(engine, utils.Int64ToStr(flexibleEmploymentPupiaoOrd.WithdrawApplyId))
if err != nil {
return err
}
session := engine.NewSession()
defer session.Close()
session.Begin()
err = svc.DealFailResult(session, finWithdrawApply, msg.MasterId, response.ErrorMsg)
if err != nil {
_ = session.Rollback()
return err
}
return session.Commit()
}
return nil
}

+ 1
- 2
go.mod Ver fichero

@@ -16,14 +16,12 @@ require (
github.com/cc14514/go-geoip2-db v0.0.0-20190106063142-7b6408a9812a
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
github.com/forgoer/openssl v1.2.1
github.com/gin-contrib/sessions v0.0.3
github.com/gin-gonic/gin v1.8.0
github.com/go-playground/locales v0.14.0
github.com/go-playground/universal-translator v0.18.0
github.com/go-playground/validator/v10 v10.10.0
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.6.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
@@ -57,6 +55,7 @@ require (
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gomodule/redigo v1.9.2 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/sessions v1.2.1 // indirect


Cargando…
Cancelar
Guardar