|
@@ -0,0 +1,65 @@
|
|
|
+package mysql
|
|
|
+
|
|
|
+import (
|
|
|
+ orm "duoduo/database"
|
|
|
+ "duoduo/tools"
|
|
|
+ "github.com/shopspring/decimal"
|
|
|
+)
|
|
|
+
|
|
|
+type Wallet struct {
|
|
|
+ AvailableAmount decimal.Decimal `gorm:"column:available_amount" json:"availableAmount"` //可提现金额
|
|
|
+ CreateTime string `gorm:"column:create_time" json:"createTime"` //创建时间
|
|
|
+ LatelyAmount decimal.Decimal `gorm:"column:lately_amount" json:"latelyAmount"` //近30日金额
|
|
|
+ OpenID string `gorm:"column:open_id" json:"openId"` //openId
|
|
|
+ TodayAmount decimal.Decimal `gorm:"column:today_amount" json:"todayAmount"` //今日金额
|
|
|
+ TotalAmount decimal.Decimal `gorm:"column:total_amount" json:"totalAmount"` //历史总金额
|
|
|
+ UpdateTime string `gorm:"column:update_time" json:"updateTime"` //更新时间
|
|
|
+ WithdrawalAmount decimal.Decimal `gorm:"column:withdrawal_amount" json:"withdrawalAmount"` //已经体现总金额
|
|
|
+ YesterdayAmount decimal.Decimal `gorm:"column:yesterday_amount" json:"yesterdayAmount"` //昨日收益
|
|
|
+ Pid string `gorm:"column:pid" json:"pid"`
|
|
|
+}
|
|
|
+
|
|
|
+// TableName sets the insert table name for this struct type
|
|
|
+func (w *Wallet) TableName() string {
|
|
|
+ return "wallet"
|
|
|
+}
|
|
|
+
|
|
|
+func (w *Wallet) Create() (Wallet, error) {
|
|
|
+ var doc Wallet
|
|
|
+ result := orm.Eloquent.Table(w.TableName()).Create(&w)
|
|
|
+ if result.Error != nil {
|
|
|
+ err := result.Error
|
|
|
+ return doc, err
|
|
|
+ }
|
|
|
+ doc = *w
|
|
|
+ return doc, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (w *Wallet) Update() (update Wallet, err error) {
|
|
|
+
|
|
|
+ if err := orm.Eloquent.Table(w.TableName()).Model(&update).Where("open_id = ? ", w.OpenID).Updates(
|
|
|
+ map[string]interface{}{
|
|
|
+ "pid": w.Pid,
|
|
|
+ "update_time": tools.GetCurrntTimeStr()}).Error; err != nil {
|
|
|
+ return update, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return update, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (w *Wallet) UpdateAll() (update Wallet, err error) {
|
|
|
+
|
|
|
+ if err := orm.Eloquent.Table(w.TableName()).Model(&update).Where("open_id = ? ", w.OpenID).Updates(
|
|
|
+ map[string]interface{}{
|
|
|
+ "total_amount": w.TotalAmount,
|
|
|
+ "available_amount": w.AvailableAmount,
|
|
|
+ "today_amount": w.TodayAmount,
|
|
|
+ "yesterday_amount": w.YesterdayAmount,
|
|
|
+ "lately_amount": w.LatelyAmount,
|
|
|
+ "withdrawal_amount": w.WithdrawalAmount,
|
|
|
+ "update_time": tools.GetCurrntTimeStr()}).Error; err != nil {
|
|
|
+ return update, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return update, nil
|
|
|
+}
|