1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package service
- import (
- "time"
- "youngee_b_api/app/dao"
- "youngee_b_api/app/entity"
- "youngee_b_api/app/vo"
- )
- type TeamBuyingService struct{}
- func (p TeamBuyingService) GetTeamBuyingsByStoreId(param vo.GetAllTeamBuyingParam) (vo.ResultVO, error) {
- if param.Page == 0 {
- param.Page = 1
- }
- if param.PageSize == 0 {
- param.PageSize = 10
- }
- var result vo.ResultVO
- var teamBuyings []entity.TeamBuying
- var err error
- var total int64
- storeId := param.StoreId
- teamBuyings, total, err = (&dao.TeamBuyingDao{}).GetTeamBuyingsByStoreIdAndTeamBuyingTitle(storeId, param.TeamBuyingTitle, param.Page, param.PageSize)
- if err != nil {
- // 数据库查询error
- return result, err
- }
- var reTeamBuyings []vo.ReTeamBuying
- for _, teamBuying := range teamBuyings {
- photoUrl, e := dao.ProductPhotoDAO{}.GetMainPhotoByTeamBuyingID(teamBuying.TeamBuyingID)
- if e != nil {
- photoUrl = ""
- }
- reTeamBuying := vo.ReTeamBuying{
- TeamBuyingID: teamBuying.TeamBuyingID,
- TeamBuyingName: teamBuying.TeamBuyingName,
- TeamBuyingPrice: teamBuying.TeamBuyingPrice,
- TeamBuyingCategory: teamBuying.TeamBuyingCategory,
- TeamBuyingDetail: teamBuying.TeamBuyingDetail,
- CreatedAt: teamBuying.CreatedAt.Format("2006-01-02 15:04:05"),
- PhotoUrl: photoUrl,
- }
- reTeamBuyings = append(reTeamBuyings, reTeamBuying)
- }
- result = vo.ResultVO{
- Page: param.Page,
- PageSize: param.PageSize,
- Total: total,
- Data: reTeamBuyings,
- }
- return result, nil
- }
- func (p TeamBuyingService) CreateTeamBuying(param *vo.TeamBuyingCreateParam) (int64, error) {
- newTeamBuying := entity.TeamBuying{
- TeamBuyingName: param.TeamBuyingName,
- TeamBuyingCategory: param.TeamBuyingCategory,
- TeamBuyingPrice: param.TeamBuyingPrice,
- PublicCommission: param.PublicCommission,
- TeamBuyingDetail: param.TeamBuyingDetail,
- TeamBuyingLink: param.TeamBuyingLink,
- StoreID: param.StoreId,
- CreatedAt: time.Now(),
- EnterpriseID: param.EnterpriseId,
- SubAccountID: param.SubAccountId,
- OperateType: 1,
- }
- teamBuyingId, err := dao.TeamBuyingDao{}.CreateTeamBuying(newTeamBuying)
- if err != nil {
- return 0, err
- }
- if param.TeamBuyingPhotos != nil {
- teamBuyingPhotos := []entity.ProductPhoto{}
- for _, photo := range param.TeamBuyingPhotos {
- teamBuyingPhoto := entity.ProductPhoto{
- PhotoUrl: photo.PhotoUrl,
- PhotoUid: photo.PhotoUid,
- Symbol: photo.Symbol,
- TeamBuyingID: teamBuyingId,
- ProductPhotoType: 3,
- CreatedAt: time.Now(),
- }
- teamBuyingPhotos = append(teamBuyingPhotos, teamBuyingPhoto)
- }
- err = dao.ProductPhotoDAO{}.CreateProductPhoto(teamBuyingPhotos)
- if err != nil {
- return 0, err
- }
- }
- return teamBuyingId, nil
- }
|