| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package shanghu
- import (
- orm "duoduo/database"
- "github.com/shopspring/decimal"
- "time"
- )
- type ClientActivePayTrans struct {
- ID int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
- RequestID string `gorm:"column:request_id;type:varchar(255)" json:"request_id"`
- OutTradeNo string `gorm:"column:out_trade_no;type:varchar(255)" json:"out_trade_no"`
- ActiveConfigID int64 `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"`
- ClientOpenID string `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`
- Status int `gorm:"column:status;type:int(11)" json:"status"`
- ThirdTradeNo string `gorm:"column:third_trade_no;type:varchar(255)" json:"third_trade_no"`
- AccountStatus int `gorm:"column:account_status;type:int(11)" json:"account_status"`
- PayTime time.Time `gorm:"column:pay_time;type:datetime(3);default:null" json:"pay_time"`
- InvitationCode string `gorm:"column:invitation_code;type:varchar(25)" json:"invitation_code"`
- Amount decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"`
- AccountErrLog string `gorm:"column:account_err_log;type:varchar(255)" json:"account_err_log"`
- GroupBuyID int64 `gorm:"column:group_buy_id;type:bigint(20)" json:"group_buy_id"`
- SeckillID int64 `gorm:"column:seckill_id;type:bigint(20)" json:"seckill_id"`
- CreateBy int64 `gorm:"column:create_by;type:bigint(20)" json:"create_by"`
- UpdateBy int64 `gorm:"column:update_by;type:bigint(20)" json:"update_by"`
- CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`
- UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`
- DeletedAt time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"`
- MerchantAmount decimal.Decimal `gorm:"column:merchant_amount;type:decimal(10,2)" json:"merchant_amount"`
- ClientAmount decimal.Decimal `gorm:"column:client_amount;type:decimal(10,2)" json:"client_amount"`
- MerchantOpenID string `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"`
- }
- const (
- ClientActivePayTransAccountStatusDef = 0
- ClientActivePayTransAccountStatusUnSettle = 1
- ClientActivePayTransAccountStatusSettleFail = 2
- ClientActivePayTransAccountStatusSettlePending = 3
- ClientActivePayTransAccountStatusSettleSuccess = 99
- )
- const (
- ClientActivePayTransStatusDef = 0
- ClientActivePayTransStatusUnPay = 1
- ClientActivePayTransStatusPaySuccess = 2
- ClientActivePayTransStatusPayCancel = 3
- ClientActivePayTransStatusRefund = 4
- )
- const (
- YuanShiMa = "yuanshima"
- )
- func (m *ClientActivePayTrans) TableName() string {
- return "client_active_pay_trans"
- }
- func (m *ClientActivePayTrans) GetRequestNum() int {
- var count int
- tableCount := orm.ShMysql.Table(m.TableName()).Where("request_id = ? ", m.RequestID)
- tableCount.Count(&count)
- return count
- }
- func (m *ClientActivePayTrans) Create() (ClientActivePayTrans, error) {
- var doc ClientActivePayTrans
- var err error
- doc = *m
- err = orm.ShMysql.Table(m.TableName()).Create(&doc).Error
- if err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (m *ClientActivePayTrans) GetPayTransByTradeNo() (ClientActivePayTrans, error) {
- var doc ClientActivePayTrans
- table := orm.ShMysql.Table(m.TableName())
- table = table.Where("out_trade_no = ? ", m.OutTradeNo)
- if err := table.Select("*").First(&doc).Error; err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (m *ClientActivePayTrans) UpdatePayTransByTradeNo() error {
- if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("out_trade_no = ? ", m.OutTradeNo).Updates(
- map[string]interface{}{
- "third_trade_no": m.ThirdTradeNo,
- "pay_time": m.PayTime,
- "status": m.Status,
- "account_status": m.AccountStatus,
- "updated_at": time.Now()}).Error; err != nil {
- return err
- }
- return nil
- }
- func (m *ClientActivePayTrans) GetPendingCancelByMerchant() (ClientActivePayTrans, error) {
- var doc ClientActivePayTrans
- table := orm.ShMysql.Table(m.TableName())
- table = table.Where("status = 2 and account_status = 1 and merchant_open_id = ?", m.MerchantOpenID)
- if err := table.Select("sum(merchant_amount) as merchant_amount").First(&doc).Error; err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (m *ClientActivePayTrans) GetPendingCancelByClient() (ClientActivePayTrans, error) {
- var doc ClientActivePayTrans
- table := orm.ShMysql.Table(m.TableName())
- table = table.Where("status = 2 and account_status = 1 and client_open_id = ?", m.ClientOpenID)
- if err := table.Select("sum(client_amount) as client_amount").First(&doc).Error; err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (m *ClientActivePayTrans) GetActivePayTransList(pageSize int, pageIndex int, openId string) ([]ClientActivePayTrans, int, error) {
- var doc []ClientActivePayTrans
- table := orm.ShMysql.Table(m.TableName())
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- table = table.Where("client_open_id = ? and status = 2 and account_status in (1,2)", openId)
- var count int
- if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
- return nil, 0, err
- }
- table.Count(&count)
- return doc, count, nil
- }
- func (m *ClientActivePayTrans) GetPayTransByThirdTradeNo() (ClientActivePayTrans, error) {
- var doc ClientActivePayTrans
- table := orm.ShMysql.Table(m.TableName())
- table = table.Where("third_trade_no = ? ", m.ThirdTradeNo)
- if err := table.Select("*").First(&doc).Error; err != nil {
- return doc, err
- }
- return doc, nil
- }
- func (m *ClientActivePayTrans) TXSettle(payInfo ClientActivePayTrans) error {
- var err error
- tx := orm.ShMysql.Begin()
- defer func() {
- if err != nil {
- tx.Rollback()
- } else {
- tx.Commit()
- }
- }()
-
-
- return nil
- }
|