|
@@ -2,6 +2,7 @@ package mysql
|
|
|
|
|
|
import (
|
|
|
orm "duoduo/database"
|
|
|
+ "errors"
|
|
|
"github.com/shopspring/decimal"
|
|
|
)
|
|
|
|
|
@@ -23,6 +24,27 @@ type Order struct {
|
|
|
Amount1 decimal.Decimal `gorm:"column:amount_1" json:"amount1"`
|
|
|
Amount2 decimal.Decimal `gorm:"column:amount_2" json:"amount2"`
|
|
|
OrderAmount decimal.Decimal `gorm:"column:order_amount" json:"orderAmount"`
|
|
|
+ OpenId string `gorm:"column:open_id" json:"openId"`
|
|
|
+ OpenId1 string `gorm:"column:open_id_1" json:"openId1"`
|
|
|
+ OpenId2 string `gorm:"column:open_id_2" json:"openId2"`
|
|
|
+}
|
|
|
+
|
|
|
+type OrderAmount struct {
|
|
|
+ TotalAmount decimal.Decimal `gorm:"column:total_amount" json:"totalAmount"`
|
|
|
+ TotalAmountOne decimal.Decimal `gorm:"column:total_amount_one" json:"totalAmountOne"`
|
|
|
+ TotalAmountTwo decimal.Decimal `gorm:"column:total_amount_two" json:"totalAmountTwo"`
|
|
|
+ TodayAmount decimal.Decimal `gorm:"column:today_amount" json:"todayAmount"`
|
|
|
+ TodayAmountOne decimal.Decimal `gorm:"column:today_amount_one" json:"todayAmountOne"`
|
|
|
+ TodayAmountTwo decimal.Decimal `gorm:"column:today_amount_two" json:"todayAmountTwo"`
|
|
|
+ YesterdayAmount decimal.Decimal `gorm:"column:yesterday_amount" json:"yesterdayAmount"`
|
|
|
+ YesterdayAmountOne decimal.Decimal `gorm:"column:yesterday_amount_one" json:"yesterdayAmountOne"`
|
|
|
+ YesterdayAmountTwo decimal.Decimal `gorm:"column:yesterday_amount_two" json:"yesterdayAmountTwo"`
|
|
|
+ LatelyAmount decimal.Decimal `gorm:"column:lately_amount" json:"latelyAmount"`
|
|
|
+ LatelyAmountOne decimal.Decimal `gorm:"column:lately_amount_one" json:"latelyAmountOne"`
|
|
|
+ LatelyAmountTwo decimal.Decimal `gorm:"column:lately_amount_two" json:"latelyAmountTwo"`
|
|
|
+ AvailableAmount decimal.Decimal `gorm:"column:available_amount" json:"availableAmount"`
|
|
|
+ AvailableAmountOne decimal.Decimal `gorm:"column:available_amount_one" json:"availableAmountOne"`
|
|
|
+ AvailableAmountTwo decimal.Decimal `gorm:"column:available_amount_two" json:"availableAmountTwo"`
|
|
|
}
|
|
|
|
|
|
// TableName sets the insert table name for this struct type
|
|
@@ -93,6 +115,108 @@ func (o *Order) GetAmount() (Wallet, error) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+func (o *Order) GetAmountOpenId() (OrderAmount, error) {
|
|
|
+ var wallet OrderAmount
|
|
|
+
|
|
|
+ //历史总收益: 0,1,2,3,5 求和
|
|
|
+ //今日预估收益:0,1,2,3 求和
|
|
|
+ //昨日预估收益:0,1,2,3 求和
|
|
|
+ //近30日预估收益:0,1,2,3,5 求和
|
|
|
+ //可体现金额:5求和-已体现金额
|
|
|
+ //已体现金额:提现记录求和
|
|
|
+ //历史总收益
|
|
|
+ err := orm.Eloquent.Select("SUM(amount) as total_amount").Where("order_status in (0,1,2,3,5) and open_id = ? ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_1) as total_amount_one").Where("order_status in (0,1,2,3,5) and open_id_1 = ? ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_2) as total_amount_two").Where("order_status in (0,1,2,3,5) and open_id_2 = ? ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+ //今日收益
|
|
|
+ err = orm.Eloquent.Select("SUM(amount) as today_amount").Where("order_status in (0,1,2,3) and open_id = ? and DATE(order_group_success_time) = curdate() ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_1) as today_amount_one").Where("order_status in (0,1,2,3) and open_id_1 = ? and DATE(order_group_success_time) = curdate() ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_2) as today_amount_two").Where("order_status in (0,1,2,3) and open_id_2 = ? and DATE(order_group_success_time) = curdate() ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+ //昨日收益
|
|
|
+ err = orm.Eloquent.Select("SUM(amount) as yesterday_amount").Where("order_status in (0,1,2,3) and open_id = ? and DATE(order_group_success_time) = date_sub(curdate(),interval 1 day) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_1) as yesterday_amount_one").Where("order_status in (0,1,2,3) and open_id_1 = ? and DATE(order_group_success_time) = date_sub(curdate(),interval 1 day) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_2) as yesterday_amount_two").Where("order_status in (0,1,2,3) and open_id_2 = ? and DATE(order_group_success_time) = date_sub(curdate(),interval 1 day) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+ //近30日收益
|
|
|
+ err = orm.Eloquent.Select("SUM(amount) as lately_amount").Where("order_status in (0,1,2,3) and open_id = ? and DATE(order_group_success_time) >= date_sub(curdate(),interval 30 day) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_1) as lately_amount_one").Where("order_status in (0,1,2,3) and open_id_1 = ? and DATE(order_group_success_time) >= date_sub(curdate(),interval 30 day) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_2) as lately_amount_two").Where("order_status in (0,1,2,3) and open_id_2 = ? and DATE(order_group_success_time) >= date_sub(curdate(),interval 30 day) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ //上个月结算收益
|
|
|
+ err = orm.Eloquent.Select("SUM(amount) as available_amount").Where("order_status = 5 and open_id = ? and DATE(order_group_success_time) >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now()) day),interval 0 month) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_1) as available_amount_one").Where("order_status = 5 and open_id_1 = ? and DATE(order_group_success_time) >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now()) day),interval 0 month) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = orm.Eloquent.Select("SUM(amount_2) as available_amount_two").Where("order_status = 5 and open_id_2 = ? and DATE(order_group_success_time) >= date_sub(date_sub(date_format(now(),'%y-%m-%d'),interval extract(day from now()) day),interval 0 month) ", o.OpenId).Table(o.TableName()).First(&wallet).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return wallet, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return wallet, nil
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
// 更新
|
|
|
func (o *Order) Update(orderId string) (update Order, err error) {
|
|
|
if err = orm.Eloquent.Table(o.TableName()).Where("order_id = ?", orderId).First(&update).Error; err != nil {
|
|
@@ -101,7 +225,7 @@ func (o *Order) Update(orderId string) (update Order, err error) {
|
|
|
|
|
|
//参数1:是要修改的数据
|
|
|
//参数2:是修改的数据
|
|
|
- if err = orm.Eloquent.Table(o.TableName()).Model(&update).Updates(&o).Error; err != nil {
|
|
|
+ if err = orm.Eloquent.Table(o.TableName()).Where("order_id = ?", orderId).Model(&update).Updates(&o).Error; err != nil {
|
|
|
return
|
|
|
}
|
|
|
return
|
|
@@ -122,3 +246,29 @@ func (o *Order) GetOrderList(pageSize int, pageIndex int) ([]Order, int, error)
|
|
|
table.Count(&count)
|
|
|
return doc, count, nil
|
|
|
}
|
|
|
+
|
|
|
+//list 接口使用
|
|
|
+func (o *Order) GetOrderOpenIdList(pageSize int, pageIndex int, status int) ([]Order, int, error) {
|
|
|
+ var doc []Order
|
|
|
+
|
|
|
+ table := orm.Eloquent.Table(o.TableName())
|
|
|
+
|
|
|
+ if status == 0 {
|
|
|
+ table = table.Where("open_id = ? ", o.OpenId)
|
|
|
+ } else if status == 1 {
|
|
|
+ table = table.Where("open_id_1 = ? ", o.OpenId)
|
|
|
+ } else if status == 2 {
|
|
|
+ table = table.Where("open_id_2 = ? ", o.OpenId)
|
|
|
+ } else {
|
|
|
+ return nil, 0, errors.New("status err")
|
|
|
+ }
|
|
|
+
|
|
|
+ //table = table.Where("open_id = ? ", o.OpenId)
|
|
|
+
|
|
|
+ var count int
|
|
|
+ if err := table.Select("order_id,promotion_amount,p_id,order_status,order_status_desc,goods_name,goods_thumbnail_url,order_group_success_time,amount,amount_1,amount_2,order_sn,DATE_FORMAT(order_create_time,'%Y-%m-%d %H:%i:%s') as order_create_time,order_amount").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
|
|
|
+}
|