| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package models
- import (
- "errors"
- "fmt"
- "reflect"
- "strings"
- "github.com/beego/beego/v2/client/orm"
- )
- type CyySaasUser struct {
- Id int `orm:"column(id);auto"`
- Uid int `orm:"column(uid);null" description:"用户uid"`
- Mobile string `orm:"column(mobile);size(11)" description:"手机号"`
- ParentId int `orm:"column(parent_id);null" description:"上级id"`
- CreatedAt int `orm:"column(created_at);null" description:"创建时间"`
- UpdatedAt int `orm:"column(updated_at);null" description:"更新时间"`
- IsDelete int8 `orm:"column(is_delete);null" description:"是否删除"`
- Price float64 `orm:"column(price);null;digits(10);decimals(2)" description:"可提现佣金"`
- TotalPrice float64 `orm:"column(total_price);null;digits(10);decimals(2)" description:"累计佣金"`
- StoreId int `orm:"column(store_id)" description:"商城ID,表示该用户是哪个商城带来的"`
- PlatformOpenId string `orm:"column(platform_open_id);size(255)" description:"平台openid"`
- PlatformOpenIdMerchant string `orm:"column(platform_open_id_merchant);size(255);null" description:"批发端openid"`
- ShareProfit float64 `orm:"column(share_profit);digits(10);decimals(2)" description:"联盟佣金"`
- Name string `orm:"column(name);size(255)" description:"昵称"`
- Gender int8 `orm:"column(gender);null" description:"性别,0: 未设置,1:男,2:女"`
- Avatar string `orm:"column(avatar);size(255)" description:"头像"`
- AccessToken string `orm:"column(access_token);size(255)" description:"token"`
- TotalIntegral int `orm:"column(total_integral);null"`
- Integral float64 `orm:"column(integral);digits(10);decimals(2)" description:"积分"`
- BytedanceOpenId string `orm:"column(bytedance_open_id);size(255)" description:"bytedance open id"`
- WithdrawMethod string `orm:"column(withdraw_method);null" description:"提现方式"`
- IsSalesman int8 `orm:"column(is_salesman)" description:"是否是业务员"`
- AliUserId string `orm:"column(ali_user_id);size(50)" description:"支付宝用户ID 18位"`
- LeaguePrice float64 `orm:"column(league_price);null;digits(10);decimals(2)"`
- SaasIntegral int `orm:"column(saas_integral);null" description:"联盟用户积分"`
- Money float64 `orm:"column(money);null;digits(10);decimals(2)" description:"余额"`
- CircleBg string `orm:"column(circle_bg);size(255);null" description:"朋友圈背景图"`
- AliOpenId string `orm:"column(ali_openId);size(255);null" description:"支付宝openid"`
- CloudInventoryBalance float64 `orm:"column(cloud_inventory_balance);null;digits(10);decimals(2)" description:"可提现云库存余额"`
- CloudInventoryFreezeBalance float64 `orm:"column(cloud_inventory_freeze_balance);null;digits(10);decimals(2)" description:"冻结云库存余额"`
- CloudInventoryTotalBalance float64 `orm:"column(cloud_inventory_total_balance);null;digits(10);decimals(2)" description:"累计云库存余额"`
- PurchaseMoney float64 `orm:"column(purchase_money);null;digits(10);decimals(2)" description:"采购金"`
- IsCloudInventory int8 `orm:"column(is_cloud_inventory);null" description:"是否云库存用户"`
- CloudInventoryLevel int8 `orm:"column(cloud_inventory_level);null" description:"云库存会员等级"`
- CanOpenStore int `orm:"column(can_open_store)" description:"是否有开店权限"`
- AiCloudInventory int8 `orm:"column(ai_cloud_inventory);null" description:"开启AI云库存 0关闭 1开启"`
- AutoExchange int8 `orm:"column(auto_exchange);null" description:"自动兑换采购金"`
- AiShopping int8 `orm:"column(ai_shopping);null" description:"AI带货"`
- PlatformOpenIdNew string `orm:"column(platform_open_id_new);size(255);null" description:"串码联名openid"`
- WechatUnionId string `orm:"column(wechat_union_id);size(255);null"`
- SaasUnionId string `orm:"column(saas_union_id);size(255);null"`
- IsPublicSphere int8 `orm:"column(is_public_sphere);null" description:"是否公域用户"`
- TotalAmount float64 `orm:"column(total_amount);null;digits(10);decimals(6)" description:"可用倍数"`
- WaitAmount float64 `orm:"column(wait_amount);null;digits(10);decimals(6)" description:"待领取红包"`
- LeijiTotalAmount float64 `orm:"column(leiji_total_amount);null;digits(10);decimals(6)" description:"累计倍数"`
- UnionId string `orm:"column(union_id);size(255);null"`
- }
- func (t *CyySaasUser) TableName() string {
- return "cyy_saas_user"
- }
- func init() {
- orm.RegisterModel(new(CyySaasUser))
- }
- // AddCyySaasUser insert a new CyySaasUser into database and returns
- // last inserted Id on success.
- func AddCyySaasUser(m *CyySaasUser) (id int64, err error) {
- o := orm.NewOrm()
- id, err = o.Insert(m)
- return
- }
- // GetCyySaasUserById retrieves CyySaasUser by Id. Returns error if
- // Id doesn't exist
- func GetCyySaasUserById(id int) (v *CyySaasUser, err error) {
- o := orm.NewOrm()
- v = &CyySaasUser{Id: id}
- if err = o.Read(v); err == nil {
- return v, nil
- }
- return nil, err
- }
- // GetAllCyySaasUser retrieves all CyySaasUser matches certain condition. Returns empty list if
- // no records exist
- func GetAllCyySaasUser(query map[string]string, fields []string, sortby []string, order []string,
- offset int64, limit int64) (ml []interface{}, err error) {
- o := orm.NewOrm()
- qs := o.QueryTable(new(CyySaasUser))
- // query k=v
- for k, v := range query {
- // rewrite dot-notation to Object__Attribute
- k = strings.Replace(k, ".", "__", -1)
- if strings.Contains(k, "isnull") {
- qs = qs.Filter(k, (v == "true" || v == "1"))
- } else {
- qs = qs.Filter(k, v)
- }
- }
- // order by:
- var sortFields []string
- if len(sortby) != 0 {
- if len(sortby) == len(order) {
- // 1) for each sort field, there is an associated order
- for i, v := range sortby {
- orderby := ""
- if order[i] == "desc" {
- orderby = "-" + v
- } else if order[i] == "asc" {
- orderby = v
- } else {
- return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
- }
- sortFields = append(sortFields, orderby)
- }
- qs = qs.OrderBy(sortFields...)
- } else if len(sortby) != len(order) && len(order) == 1 {
- // 2) there is exactly one order, all the sorted fields will be sorted by this order
- for _, v := range sortby {
- orderby := ""
- if order[0] == "desc" {
- orderby = "-" + v
- } else if order[0] == "asc" {
- orderby = v
- } else {
- return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
- }
- sortFields = append(sortFields, orderby)
- }
- } else if len(sortby) != len(order) && len(order) != 1 {
- return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
- }
- } else {
- if len(order) != 0 {
- return nil, errors.New("Error: unused 'order' fields")
- }
- }
- var l []CyySaasUser
- qs = qs.OrderBy(sortFields...)
- if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
- if len(fields) == 0 {
- for _, v := range l {
- ml = append(ml, v)
- }
- } else {
- // trim unused fields
- for _, v := range l {
- m := make(map[string]interface{})
- val := reflect.ValueOf(v)
- for _, fname := range fields {
- m[fname] = val.FieldByName(fname).Interface()
- }
- ml = append(ml, m)
- }
- }
- return ml, nil
- }
- return nil, err
- }
- // UpdateCyySaasUser updates CyySaasUser by Id and returns error if
- // the record to be updated doesn't exist
- func UpdateCyySaasUserById(m *CyySaasUser) (err error) {
- o := orm.NewOrm()
- v := CyySaasUser{Id: m.Id}
- // ascertain id exists in the database
- if err = o.Read(&v); err == nil {
- var num int64
- if num, err = o.Update(m); err == nil {
- fmt.Println("Number of records updated in database:", num)
- }
- }
- return
- }
- // DeleteCyySaasUser deletes CyySaasUser by Id and returns error if
- // the record to be deleted doesn't exist
- func DeleteCyySaasUser(id int) (err error) {
- o := orm.NewOrm()
- v := CyySaasUser{Id: id}
- // ascertain id exists in the database
- if err = o.Read(&v); err == nil {
- var num int64
- if num, err = o.Delete(&CyySaasUser{Id: id}); err == nil {
- fmt.Println("Number of records deleted in database:", num)
- }
- }
- return
- }
|