|
|
@@ -0,0 +1,470 @@ |
|
|
|
package db |
|
|
|
|
|
|
|
import ( |
|
|
|
"applet/app/db/model" |
|
|
|
"applet/app/utils" |
|
|
|
"applet/app/utils/logx" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"time" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
// 这里不做具体的搜索, 因为搜索条件过多可能对导致效率较低, 所以这里只把所有数据搜索出来 |
|
|
|
func OrderList(Db *xorm.Engine, uid string) *[]model.OrdList { |
|
|
|
var o []model.OrdList |
|
|
|
if err := Db.Where("`benefit_list` LIKE ?", "%|"+uid+":%"). |
|
|
|
Desc("update_at").Desc("create_at").Find(&o); err != nil || len(o) == 0 { |
|
|
|
logx.Error(err) |
|
|
|
return nil |
|
|
|
} |
|
|
|
return &o |
|
|
|
} |
|
|
|
|
|
|
|
// 批量订单id查找订单 |
|
|
|
func OrderListByOids(Db *xorm.Engine, oids []int64) (*[]model.OrdList, error) { |
|
|
|
var o []model.OrdList |
|
|
|
if err := Db.In("ord_id", oids).Desc("create_at").Find(&o); err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
func OrderListByOid(Db *xorm.Engine, oids string) (*model.OrdList, error) { |
|
|
|
var o model.OrdList |
|
|
|
get, err := Db.Where("pvd_oid=?", oids).Get(&o) |
|
|
|
if err != nil || get == false { |
|
|
|
return nil, errors.New("没订单") |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// 按传入的oid顺序排序 |
|
|
|
func OrderListByOidsAndOrderByOids(Db *xorm.Engine, oids []int64) (*[]model.OrdList, error) { |
|
|
|
var o []model.OrdList |
|
|
|
orderStr := "FIND_IN_SET(ord_id, '%s')" |
|
|
|
oidsStr := "" |
|
|
|
for _, item := range oids { |
|
|
|
oidsStr = oidsStr + "," + utils.AnyToString(item) |
|
|
|
} |
|
|
|
orderStr = fmt.Sprintf(orderStr, oidsStr) |
|
|
|
fmt.Println(orderStr) |
|
|
|
if err := Db.In("ord_id", oids).OrderBy(orderStr).Find(&o); err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByUID is 查询订单 by uid |
|
|
|
func OrderListByUID(Db *xorm.Engine, uid interface{}) (*[]model.OrdList, error) { |
|
|
|
var o []model.OrdList |
|
|
|
if err := Db.Where("uid = ?", uid).Find(&o); err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByUIDByPaidPrice is 查询订单 by uid 和付款金额大于 x元的 |
|
|
|
func OrderListByUIDByPaidPrice(Db *xorm.Engine, uid interface{}, pay interface{}, state []string) (*[]model.OrdList, error) { |
|
|
|
var o []model.OrdList |
|
|
|
if err := Db.Where("uid = ? AND paid_price > ?", uid, pay).In("state", state).Find(&o); err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByUIDByState is 查询uid 和 指定状态的订单 |
|
|
|
func OrderListByUIDByState(Db *xorm.Engine, uid interface{}, state []string) (*[]model.OrdList, error) { |
|
|
|
var o []model.OrdList |
|
|
|
if err := Db.Where("uid = ?", uid).In("state", state).Find(&o); err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByUIDByOrderType is 查询订单 by uid by |
|
|
|
func OrderListByUIDByOrderType(Db *xorm.Engine, uid, buyType interface{}) (*[]model.OrdList, error) { |
|
|
|
var o []model.OrdList |
|
|
|
if err := Db.Where("uid = ? AND order_type = ?", uid, buyType).Find(&o); err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListCountByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单数 |
|
|
|
func OrderListCountByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (int64, error) { |
|
|
|
|
|
|
|
str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) AND create_at > %s AND create_at < %s", |
|
|
|
utils.AnyToString(uid), buyType, state, stime, etime) |
|
|
|
fmt.Println("============test订单数=================") |
|
|
|
fmt.Println(str) |
|
|
|
total, err := Db.Where("uid = ? AND order_type = ? AND ( state in (?) or settle_at>0) AND create_at > ? AND create_at < ?", uid, buyType, state, stime, etime).Count(&model.OrdList{}) |
|
|
|
fmt.Println(err) |
|
|
|
fmt.Println(total) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, logx.Error(err) |
|
|
|
} |
|
|
|
return total, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListPaidPriceByUIDByOrderTypeByTime is 查询订单 by uid by time ,获取规定时间内的订单类型的订单消费金额 |
|
|
|
func OrderListPaidPriceByUIDByOrderTypeByTime(Db *xorm.Engine, uid, buyType, state, stime, etime interface{}) (float64, error) { |
|
|
|
|
|
|
|
str := fmt.Sprintf("uid = %s AND order_type = %s AND ( state in (%s) or settle_at>0) AND create_at > %s AND create_at < %s", |
|
|
|
utils.AnyToString(uid), buyType, state, stime, etime) |
|
|
|
fmt.Println("============test订单数=================") |
|
|
|
fmt.Println(str) |
|
|
|
total, err := Db.Where("uid = ? AND order_type = ? AND ( state in (?) or settle_at>0) AND create_at > ? AND create_at < ?", uid, buyType, state, stime, etime).Sum(&model.OrdList{}, "paid_price") |
|
|
|
fmt.Println(err) |
|
|
|
fmt.Println(total) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, logx.Error(err) |
|
|
|
} |
|
|
|
return total, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListCountByUIDByTime is 查询订单 by uid by time ,获取规定时间内的UID订单数 |
|
|
|
func OrderListCountByUIDByTime(Db *xorm.Engine, uid, stime, etime interface{}) (*[]model.OrdList, error) { |
|
|
|
var o []model.OrdList |
|
|
|
err := Db.Where("uid = ? AND create_at > ? AND create_at < ?", |
|
|
|
uid, stime, etime).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByUIDByOrderTypeDesc is 查询订单 by uid by type |
|
|
|
func OrderListByUIDByOrderTypeDesc(Db *xorm.Engine, uid, buyType interface{}) (*[]model.OrdList, error) { |
|
|
|
var o []model.OrdList |
|
|
|
if err := Db.Where("uid = ? AND order_type = ?", uid, buyType).Desc("create_at").Find(&o); err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByOID is 查询订单 by oid |
|
|
|
func OrderListByOID(Db *xorm.Engine, uid interface{}) (*model.OrdList, error) { |
|
|
|
var o model.OrdList |
|
|
|
if has, err := Db.Where("ord_id = ?", uid).Get(&o); err != nil || !has { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByOIDANDNOTBIND is 查询订单 by oid 并且没绑定 |
|
|
|
func OrderListByOIDANDNOTBIND(Db *xorm.Engine, oid interface{}) (*model.OrdList, error) { |
|
|
|
var o model.OrdList |
|
|
|
if has, err := Db.Where("ord_id = ? and uid=0", oid).Get(&o); err != nil || !has { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByPvdOidAndUid is 查询订单 by pvd_oid and uid=0 |
|
|
|
func OrderListByPvdOidAndUid(Db *xorm.Engine, oid string) (*model.OrdList, error) { |
|
|
|
var o model.OrdList |
|
|
|
if has, err := Db.Where("(pvd_oid = ? or parent_ord_id = ?) and uid=0", oid, oid).Get(&o); err != nil || !has { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
func OrderListByUpdateOrd(Db *xorm.Engine, ord *model.OrdList) (bool, error) { |
|
|
|
if row, err := Db.Where("pvd_oid = ? ", ord.PvdOid).AllCols().Update(ord); row == 0 || err != nil { |
|
|
|
return false, logx.Warn(err) |
|
|
|
} |
|
|
|
return true, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByStateOr is 获取满足几种状态中的订单 |
|
|
|
func OrderListByStateOr(Db *xorm.Engine, uid string, states ...int) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("`benefit_list` LIKE ? AND (state = ? OR state = ? OR state = ?)", "%|"+uid+":%", states[0], states[1], states[2]).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByTimeByStateOr is 获取某段时间内满足几种状态中的订单 |
|
|
|
func OrderListByTimeByStateOr(Db *xorm.Engine, uid, startTime, endTime string, states ...int) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("`benefit_list` LIKE ? AND (state = ? OR state = ? OR state = ?) AND create_at > ? AND create_at < ?", "%|"+uid+":%", states[0], states[1], states[2], startTime, endTime).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByTimeByState is 根据时间段和状态获取订单 |
|
|
|
func OrderListByTimeByState(Db *xorm.Engine, uid, state, startTime, endTime interface{}) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("`benefit_list` LIKE ? AND state = ? AND create_at > ? AND create_at < ?", "%|"+utils.AnyToString(uid)+":%", state, startTime, endTime).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
func OrderListByIdsByState(ids []int64, state int) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.In("`ord_id`", ids).Where("state=3").Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
func OrderListByIds(eg *xorm.Engine, ids []interface{}) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := eg.In("`ord_id`", ids).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
//OrderListByPvdByTimeByState is 根据时间段、提供商和状态获取订单 |
|
|
|
func OrderListByPvdByTimeByState(Db *xorm.Engine, provider, uid, startTime, endTime, state string) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("pvd = ? AND `benefit_list` LIKE ? AND state = ? AND create_at > ? AND create_at < ?", provider, "%|"+uid+":%", state, startTime, endTime).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// 根据 uid 去 ord_list_relate 查询 ord_id, 拿 ord_id 查询 ord_list |
|
|
|
func OrderListRelateByUid(Db *xorm.Engine, uid string) ([]*model.OrdListRelate, error) { |
|
|
|
var o []*model.OrdListRelate |
|
|
|
err := Db.Where("uid = ?", uid).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// 根据 oid 去 ord_list_relate |
|
|
|
func OrderListRelateByOid(Db *xorm.Engine, oid, uid string) ([]*model.OrdListRelate, error) { |
|
|
|
var o []*model.OrdListRelate |
|
|
|
err := Db.Where("oid = ? AND uid = ?", oid, uid).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
func OrderListRelateByOidFirst(Db *xorm.Engine, oid string) (*model.OrdListRelate, error) { |
|
|
|
var o model.OrdListRelate |
|
|
|
has, err := Db.Where("oid = ? AND level = ?", oid, 0).Get(&o) |
|
|
|
if has == false || err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return &o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// 根据 oid 和 pvd 去 ord_list_relate |
|
|
|
func OrderListRelateByOidAndPvd(Db *xorm.Engine, oid, pvd string) ([]*model.OrdListRelate, error) { |
|
|
|
var o []*model.OrdListRelate |
|
|
|
err := Db.Where("oid = ? AND pvd = ?", oid, pvd).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// 根据 ord_id 去 ord_list 查询 |
|
|
|
func OrderListByOrdId(Db *xorm.Engine, ordId []int64, provider, startTime, endTime, state string) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.In("ord_id", ordId).Where("pvd = ? AND create_at > ? AND create_at < ? AND settle_at != ?", provider, startTime, endTime, 0).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// 判断是否自购 and 预估 |
|
|
|
func OrderListRelateByUidAndOver(Db *xorm.Engine, ordId []int64, provider, startTime, endTime string, states ...int) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.In("ord_id", ordId).Where("pvd = ? AND (state = ? OR state = ? OR state = ? OR state = ?) AND create_at > ? AND create_at < ? AND settle_at = ?", provider, states[0], states[1], states[2], states[3], startTime, endTime, 0).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByOrderTypeByStateOr is 获取满足几种状态中和订单类型的订单 |
|
|
|
func OrderListByOrderTypeByStateOr(Db *xorm.Engine, provider, t, uid, startTime, endTime string, states ...int) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("pvd = ? AND order_type = ? AND `benefit_list` LIKE ? AND (state = ? OR state = ? OR state = ?) AND create_at > ? AND create_at < ?", |
|
|
|
provider, t, "%|"+uid+":%", states[0], states[1], states[2], startTime, endTime).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByPVDByStateOr is 获取某渠道满足几种状态中的订单的 |
|
|
|
func OrderListByPVDByStateOr(Db *xorm.Engine, provider, uid, startTime, endTime string, states ...int) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
//err := Db.Where("pvd = ? AND `benefit_list` LIKE ? AND (state = ? OR state = ? OR state = ?) AND create_at > ? AND create_at < ?", |
|
|
|
// provider, "%|"+uid+":%", states[0], states[1], states[2],states[3], startTime, endTime).Find(&o) |
|
|
|
|
|
|
|
err := Db.Where("pvd = ? AND uid = ? AND (state = ? OR state = ? OR state = ? OR state = ? ) AND create_at > ? AND create_at < ?", |
|
|
|
provider, uid, states[0], states[1], states[2], states[3], startTime, endTime).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByPVDByUIDByStateOr is 获取某uid某渠道满足几种状态中的订单的 |
|
|
|
func OrderListByPVDByUIDByStateOr(Db *xorm.Engine, provider, uid, startTime, endTime string, states ...int) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
//err := Db.Where("pvd = ? AND uid =? AND `benefit_list` LIKE ? AND (state = ? OR state = ? OR state = ?) AND create_at > ? AND create_at < ?", |
|
|
|
// provider, uid, "%|"+uid+":%", states[0], states[1], states[2], startTime, endTime).Find(&o) |
|
|
|
|
|
|
|
err := Db.Where("pvd = ? AND uid =? AND (state = ? OR state = ? OR state = ? OR state = ?) AND create_at > ? AND create_at < ?", |
|
|
|
provider, uid, states[0], states[1], states[2], states[3], startTime, endTime).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListInByPVDByStateOr is 获取某渠道满足几种状态中的订单的 |
|
|
|
func OrderListInByPVDByStateOr(Db *xorm.Engine, provider, startTime, endTime string, uids []string, states ...int) ([]*model.OrdList, error) { |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("pvd = ? AND (state = ? OR state = ? OR state = ?) AND create_at > ? AND create_at < ?", |
|
|
|
provider, states[0], states[1], states[2], startTime, endTime).In("benefit_list", uids).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, logx.Error(err) |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListByPvdAndNoSettledWithPage is 查询指定平台未结算订单 |
|
|
|
func OrderListByPvdAndNoSettledWithPage(Db *xorm.Engine, page int, pvdList ...string) ([]*model.OrdList, error) { |
|
|
|
perPage := 500 |
|
|
|
startPlace := (page - 1) * perPage |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("settle_at=? and uid>0", 0).In("pvd", pvdList).In("state", 0, 1, 2, 3).Limit(perPage, startPlace).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
func OrderListByPvdAndNoSettledWithLimitStateAndPage(Db *xorm.Engine, page, limitState int, pvdList ...string) ([]*model.OrdList, error) { |
|
|
|
perPage := 100 |
|
|
|
startPlace := (page - 1) * perPage |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("second_price_type=0 and price_type=0 and settle_at=? and benefit_all>0 and uid>0 and state>=? and state !=4 and state !=5", 0, limitState).In("pvd", pvdList).Limit(perPage, startPlace).OrderBy("state desc,create_at asc,ord_id asc").Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
func FreeOrderListByPvdAndNoSettledWithLimitStateAndPage(Db *xorm.Engine, page, limitState int, pvdList ...string) ([]*model.OrdList, error) { |
|
|
|
perPage := 100 |
|
|
|
startPlace := (page - 1) * perPage |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("price_type>0 and settle_at=? and benefit_all>0 and uid>0 and state>=? and state !=4 and state !=5", 0, limitState).In("pvd", pvdList).Limit(perPage, startPlace).OrderBy("state desc,create_at asc,ord_id asc").Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
func SecondFreeOrderListByPvdAndNoSettledWithLimitStateAndPage(Db *xorm.Engine, page, limitState int) ([]*model.OrdList, error) { |
|
|
|
perPage := 100 |
|
|
|
startPlace := (page - 1) * perPage |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("second_price_type>0 and settle_at=? and benefit_all>0 and uid>0 and state>=? and state !=4 and state !=5", 0, limitState).Limit(perPage, startPlace).OrderBy("state desc,create_at asc,ord_id asc").Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
func OrderListByStateWithReturnMoneySettleAt(Db *xorm.Engine, page int, state ...string) ([]*model.OrdList, error) { |
|
|
|
perPage := 500 |
|
|
|
startPlace := (page - 1) * perPage |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("return_money_settle_at=? and uid>0 ", 0).In("state", state).Limit(perPage, startPlace).OrderBy("state desc").Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
func OrderListByStateWithMonthCommissionSettleAt(Db *xorm.Engine, page int, state ...string) ([]*model.OrdList, error) { |
|
|
|
perPage := 100 |
|
|
|
startPlace := (page - 1) * perPage |
|
|
|
timeArr := utils.GetTimeRange("last_month") |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("settle_at=? and uid>0 and create_at<?", 0, timeArr["end"]).In("state", state).Limit(perPage, startPlace).OrderBy("state desc").Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListNormalByPvdWithPage is 查询指定平台未关闭订单 |
|
|
|
func OrderListNormalByPvdAndUidWithPage(Db *xorm.Engine, uid interface{}, page int, perPage int, createTime int64, pvdList ...string) ([]*model.OrdList, error) { |
|
|
|
startPlace := (page - 1) * perPage |
|
|
|
var o []*model.OrdList |
|
|
|
err := Db.Where("uid=? AND create_at>=?", uid, createTime).In("pvd", pvdList).In("state", 0, 1, 2, 3, 5).Limit(perPage, startPlace).Find(&o) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
return o, nil |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListCountByPvdByUidByTimeByValid is 计算某平台某时间段和除了某状态的订单数量 |
|
|
|
func OrderListCountByPvdByUidByTimeByValid(Db *xorm.Engine, provider, startTime, endTime, uid string, state int) (int64, error) { |
|
|
|
return Db.Where("pvd = ? AND uid = ? AND state != ? AND create_at > ? AND create_at < ?", provider, uid, state, startTime, endTime).Count(&model.OrdList{}) |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListCountByPriceType is 计算免单价格类型下的购买 |
|
|
|
func OrderListCountByPriceType(Db *xorm.Engine, uid string, priceType, day int) (int64, error) { |
|
|
|
sess := Db.Where(" uid = ? AND state != 4 AND price_type= ?", uid, priceType) |
|
|
|
if day > 0 { |
|
|
|
sess = sess.And("create_at>=?", time.Now().Unix()-int64(day*86400)) |
|
|
|
} |
|
|
|
return sess.Count(&model.OrdList{}) |
|
|
|
} |
|
|
|
|
|
|
|
// OrderListCountByItemId is 计算免单单个商品购买的次数 |
|
|
|
func OrderListCountByItemId(Db *xorm.Engine, uid string, itemId string, day int) (int64, error) { |
|
|
|
sess := Db.Where(" uid = ? AND state != 4 AND item_id = ?", uid, itemId) |
|
|
|
if day > 0 { |
|
|
|
sess = sess.And("create_at>=?", time.Now().Unix()-int64(day*86400)) |
|
|
|
} |
|
|
|
return sess.Count(&model.OrdList{}) |
|
|
|
} |
|
|
|
|
|
|
|
func OrderUpdateWithSession(session *xorm.Session, ordId int64, order *model.OrdList, forceCols ...string) (int64, error) { |
|
|
|
var ( |
|
|
|
affected int64 |
|
|
|
err error |
|
|
|
) |
|
|
|
affected, err = session.Where("ord_id=?", ordId).Cols("is_refund,state,settle_at").Update(order) |
|
|
|
if err != nil { |
|
|
|
return 0, logx.Warn(err) |
|
|
|
} |
|
|
|
return affected, nil |
|
|
|
} |
|
|
|
|
|
|
|
// |
|
|
|
func OrdUpdateOne(Db *xorm.Engine, order *model.OrdList) (int64, error) { |
|
|
|
affect, err := Db.ID(order.OrdId).Cols("is_refund,state,settle_at,is_send_msg,platform_data").Update(order) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return affect, nil |
|
|
|
} |
|
|
|
func OrdUpdateOneAll(Db *xorm.Engine, order *model.OrdList) (int64, error) { |
|
|
|
affect, err := Db.ID(order.OrdId).AllCols().Update(order) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return affect, nil |
|
|
|
} |