diff --git a/app/db/db_order.go b/app/db/db_order.go new file mode 100644 index 0000000..615df66 --- /dev/null +++ b/app/db/db_order.go @@ -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=?", 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 +} diff --git a/app/db/db_user_real_name_auth.go b/app/db/db_user_real_name_auth.go new file mode 100644 index 0000000..7430f75 --- /dev/null +++ b/app/db/db_user_real_name_auth.go @@ -0,0 +1,59 @@ +package db + +import ( + "applet/app/db/model" + "applet/app/utils/logx" + "xorm.io/xorm" +) + +func GetRealNameAuth(Db *xorm.Engine, uid int) (*model.UserRealNameAuth, error) { + var m model.UserRealNameAuth + if has, err := Db.Where("uid = ? AND is_pay = ?", uid, 1).Get(&m); err != nil || !has { + return nil, logx.Warn(err) + } + return &m, nil +} +func GetRealNameAuthByUid(Db *xorm.Engine, uid int) (*model.UserRealNameAuth, error) { + var m model.UserRealNameAuth + if has, err := Db.Where("uid = ? ", uid).Get(&m); err != nil || !has { + return nil, logx.Warn(err) + } + return &m, nil +} +func GetRealNameAuthByUidWithState(Db *xorm.Engine, uid, state int) (*model.UserRealNameAuth, error) { + var m model.UserRealNameAuth + if has, err := Db.Where("uid = ? and state=?", uid, state).Get(&m); err != nil || !has { + return nil, logx.Warn(err) + } + return &m, nil +} +func GetRealNameAuthByOid(Db *xorm.Engine, oid string) (*model.UserRealNameAuth, error) { + var m model.UserRealNameAuth + if has, err := Db.Where("oid = ? ", oid).Get(&m); err != nil || !has { + return nil, logx.Warn(err) + } + return &m, nil +} +func GetRealNameAuthCount(Db *xorm.Engine, uid int, realName, certifyId string) (int64, error) { + var m model.UserRealNameAuth + has, err := Db.Where("uid <> ? AND(real_name = ? or card_no = ?)", uid, realName, certifyId).Count(&m) + if has == 0 || err != nil { + return 0, err + } + return has, nil +} + +func RealNameAuthInsert(Db *xorm.Engine, m *model.UserRealNameAuth) (int64, error) { + affected, err := Db.InsertOne(m) + if err != nil { + return 0, err + } + return affected, nil +} +func RealNameAuthUpdate(Db *xorm.Engine, m *model.UserRealNameAuth) (int64, error) { + affected, err := Db.Where("id=?", m.Id).Update(m) + if err != nil { + return 0, err + } + return affected, nil +} diff --git a/app/db/db_user_withdrawapply.go b/app/db/db_user_withdrawapply.go new file mode 100644 index 0000000..17676cb --- /dev/null +++ b/app/db/db_user_withdrawapply.go @@ -0,0 +1,91 @@ +package db + +import ( + "applet/app/db/model" + "applet/app/utils/logx" + + "xorm.io/xorm" +) + +//SessionUserWithDrawApplyInsertOne 事务插入一条提现记录单 +func SessionUserWithDrawApplyInsertOne(Db *xorm.Session, m *model.FinWithdrawApply) (int64, error) { + affected, err := Db.InsertOne(m) + if err != nil { + + return 0, err + } + return affected, nil +} + +//UserWithDrawApplyInsertOne 插入一条提现记录单 +func UserWithDrawApplyInsertOne(Db *xorm.Engine, m *model.FinWithdrawApply) (int64, error) { + affected, err := Db.InsertOne(m) + if err != nil { + return 0, err + } + return affected, nil +} + +//UserWithDrawApplyInsertOne 插入一条提现记录单 +func UserWithDrawApplyWithSessionInsertOne(session *xorm.Session, m *model.FinWithdrawApply) (int64, error) { + affected, err := session.InsertOne(m) + if err != nil { + return 0, err + } + return affected, nil +} + +//UserWithDrawApplyDeletedOne is 删除指定id的数据 +func UserWithDrawApplyDeletedOne(Db *xorm.Engine, id interface{}) (int64, error) { + m := new(model.FinWithdrawApply) + affected, err := Db.ID(id).Delete(m) + if err != nil { + return 0, err + } + return affected, nil +} + +// UserWithDrawApplyByUID is 获取支出记录 +func UserWithDrawApplyByUID(Db *xorm.Engine, uid interface{}, time string, limit, start int) ([]*model.FinWithdrawApply, error) { + var m []*model.FinWithdrawApply + if err := Db.Where("uid = ? AND create_at like ?", uid, time+"%").Desc("create_at").Limit(limit, start).Find(&m); err != nil { + return nil, logx.Warn(err) + } + return m, nil +} + +// UserWithDrawApplyByUIDByTime is 获取某时间段所有的提现申请单号 审核失败的不要 +func UserWithDrawApplyByUIDByTime(Db *xorm.Engine, uid interface{}, stime, etime string) ([]*model.FinWithdrawApply, error) { + var m []*model.FinWithdrawApply + if err := Db.Where("uid = ? AND state!=3 AND create_at > ? AND create_at < ?", uid, stime, etime).Find(&m); err != nil { + return nil, logx.Warn(err) + } + return m, nil +} + +func UserWithDrawApplyByUIDById(Db *xorm.Engine, id int64) (*model.FinWithdrawApply, error) { + var m model.FinWithdrawApply + has, err := Db.Where("id = ?", id).Get(&m) + if err != nil { + return nil, logx.Warn(err) + } + if !has { + return nil, logx.Error("Not found") + } + return &m, nil +} + +//UserWithDrawApplySumByState is 统计某种状态的提现订单的金额 +func UserWithDrawApplySumByState(Db *xorm.Engine, uid interface{}, state ...interface{}) (float64, error) { + m := new(model.FinWithdrawApply) + total, err := Db.Where("uid = ?", uid).In("state", state...).Sum(m, "amount") + if err != nil { + return 0, logx.Warn(err) + } + return total, nil +} + +// UserWithDrawApplyDeleteByUserDelete is 用户删除时的删除 +func UserWithDrawApplyDeleteByUserDelete(Db *xorm.Engine, uid interface{}) (int64, error) { + return Db.Where("uid = ?", uid).Delete(model.FinWithdrawApply{}) +} diff --git a/app/db/model/user_real_name_auth.go b/app/db/model/user_real_name_auth.go new file mode 100644 index 0000000..0909e96 --- /dev/null +++ b/app/db/model/user_real_name_auth.go @@ -0,0 +1,23 @@ +package model + +import ( + "time" +) + +type UserRealNameAuth struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Uid int `json:"uid" xorm:"comment('用户id') index INT(11)"` + RealName string `json:"real_name" xorm:"comment('真实姓名') VARCHAR(255)"` + CardNo string `json:"card_no" xorm:"comment('身份证号') VARCHAR(255)"` + FrontImg string `json:"front_img" xorm:"comment('身份证正面(国徽面)') VARCHAR(255)"` + BackImg string `json:"back_img" xorm:"comment('身份证反面(人像面)') VARCHAR(255)"` + State int `json:"state" xorm:"comment('0未审核 1通过 2拒绝') TINYINT(1)"` + AuditType int `json:"audit_type" xorm:"comment('审核类型:1自动 2手动') TINYINT(1)"` + IsPay int `json:"is_pay" xorm:"not null default 0 comment('是否支付,0:否 ,1:是') TINYINT(1)"` + CreateTime time.Time `json:"create_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` + UpdateTime time.Time `json:"update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"` + Oid string `json:"oid" xorm:"default '' comment('订单号') VARCHAR(50)"` + Msg string `json:"msg" xorm:"default '' comment('调用支付宝实名接口数据') VARCHAR(255)"` + CertifyId string `json:"certify_id" xorm:"default '' comment('支付宝的实名认证id') VARCHAR(255)"` + Amount float64 `json:"amount" xorm:"default '0.00' comment('付款金额') DOUBLE(11,2)"` +} diff --git a/consume/init.go b/consume/init.go index 85e2ef7..f44df3c 100644 --- a/consume/init.go +++ b/consume/init.go @@ -17,6 +17,8 @@ func Init() { // 增加消费任务队列 func initConsumes() { + jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser + //jobs[consumeMd.ZhiosAcquisitionConditionDevFunName] = ZhiosAcquisitionCondition jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index b17d2ee..e2147ad 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -227,6 +227,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", ConsumeFunName: "zhiosWithdrawReward", }, + { + ExchangeName: "zhios.user_valid.exchange", + Name: "zhios_user_valid", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "user_valid", + BindKey: "", + ConsumeFunName: "ZhiosValidUser", + }, } const ( @@ -253,5 +262,6 @@ const ( ZhiosTikTokAllUpdateFunName = "ZhiosTikTokAllUpdate" CloudIssuanceAsyncMLoginFunName = "CloudIssuanceAsyncMLoginConsume" ZhiosAcquisitionConditionFunName = "ZhiosAcquisitionCondition" + ZhiosValidUserFunName = "ZhiosValidUser" ZhiosAcquisitionConditionDevFunName = "ZhiosAcquisitionConditionDev" ) diff --git a/consume/zhios_valid_user.go b/consume/zhios_valid_user.go new file mode 100644 index 0000000..c6f6e31 --- /dev/null +++ b/consume/zhios_valid_user.go @@ -0,0 +1,181 @@ +package consume + +import ( + "applet/app/db" + "applet/app/utils" + "applet/app/utils/logx" + "applet/consume/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" + "xorm.io/xorm" +) + +func ZhiosValidUser(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>") + 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(300) + delivery := ch.Consume(queue.Name, false) + + var res amqp.Delivery + var ok bool + for { + res, ok = <-delivery + if ok == true { + //fmt.Println(string(res.Body)) + fmt.Println(">>>>>>>>>>>>>>>>ZhiosAcquisitionCondition<<<<<<<<<<<<<<<<<<<<<<<<<") + err = handleValidUser(res.Body) + //_ = res.Reject(false) + fmt.Println(err) + _ = res.Ack(true) + } else { + panic(errors.New("error getting message")) + } + } + fmt.Println("get msg done") +} +func handleValidUser(msg []byte) error { + //1、解析canal采集至mq中queue的数据结构体 + var canalMsg *md.ZhiosAcquisition + fmt.Println(string(msg)) + var tmpString string + err := json.Unmarshal(msg, &tmpString) + if err != nil { + fmt.Println(err.Error()) + return err + } + fmt.Println(tmpString) + err = json.Unmarshal([]byte(tmpString), &canalMsg) + if err != nil { + return err + } + mid := canalMsg.Mid + eg := db.DBs[mid] + if eg == nil { + return nil + } + if canalMsg.Uid == "" { + return nil + } + RoutineUpdateUserComm(eg, mid, canalMsg.Uid) + return nil +} +func RoutineUpdateUserComm(eg *xorm.Engine, dbName, uid string) { + if utils.StrToInt(uid) == 0 { + return + } + user, _ := db.UserFindByID(eg, uid) + if user == nil { + return + } + userProfile, _ := db.UserProfileFindByID(eg, uid) + if userProfile == nil { + return + } + if userProfile.IsVerify == 1 { + return + } + validConditionMap := map[string]interface{}{} + checkMap := map[string]interface{}{} + todone := 0 + //有效会员 校验 + vdata := db.SysCfgGetWithDb(eg, dbName, "valid_member_condition") + if err := json.Unmarshal([]byte(vdata), &validConditionMap); err != nil { + return + logx.Warn(err) + } + for k, v := range validConditionMap { + if v != "" && utils.AnyToFloat64(v) > 0 { + todone++ + checkMap[k] = v + } + } + + for k, v := range checkMap { + switch k { + case "realCheck": + // 检查实名认证 + one, _ := db.GetRealNameAuthByUidWithState(eg, user.Uid, 1) + if one != nil && one.Uid == user.Uid { + todone-- + } + case "bindPhone": + // 检查绑定手机号 + if user.Phone != "" { + todone-- + } + case "goodsCommission": + sqlTpl := `SELECT cast(SUM(LEFT(olr.amount,LENGTH(olr.amount)-2)) as decimal(50,4)) AS amount +FROM ord_list_relate olr + LEFT JOIN ord_list ol ON olr.oid = ol.ord_id + LEFT JOIN privilege_card_ord pco ON olr.oid =pco.ord_id + LEFT JOIN duoyou_ord_list dol ON olr.oid =dol.oid + LEFT JOIN recharge_order ro ON olr.oid =ro.oid + LEFT JOIN playlet_sale_order pso ON olr.oid =pso.custom_oid +WHERE olr.uid = ? AND (ol.state<>4 or pco.state=1 or dol.id>0 or ro.status<>'已退款' or pso.status<>'订单退款'); +` + todayResult, err := db.QueryNativeString(eg, sqlTpl, uid) + today := "0" + if err == nil { + today = todayResult[0]["amount"] + } + // 累计佣金 + if utils.StrToFloat64(today) >= utils.AnyToFloat64(v) { + todone-- + } + case "orderPay": + // 付款订单满足v元 + ms, err := db.OrderListByUIDByPaidPrice(eg, user.Uid, v, []string{"0", "1", "2", "3", "5"}) + if err != nil { + logx.Warn(err) + } + mss := *ms + if len(mss) > 0 { + todone-- + } + case "receive": + // 已收货 + ms, err := db.OrderListByUIDByState(eg, user.Uid, []string{"1", "2", "3", "5"}) + if err != nil { + logx.Warn(err) + } + mss := *ms + if len(mss) > 0 { + todone-- + } + case "tbAuth": + // 是否淘宝授权 + if userProfile.AccTaobaoAuthTime != 0 { + todone-- + } + case "withdraw": + // 提现 + sum, err := db.UserWithDrawApplySumByState(eg, user.Uid, "1", "2") + if err != nil { + logx.Warn(err) + } + if sum > 0 { + todone-- + } + } + } + // 满足条件则将改用户打为有效用户 + if todone == 0 { + userProfile.IsVerify = 1 + } + _, err := db.UserProfileUpdate(eg, userProfile.Uid, userProfile) + if err != nil { + logx.Warn(err) + } + return +}