repair_user_picture.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package frontm
  2. import ("github.com/astaxie/beego/orm"
  3. "wuyebaoxiuapi/models")
  4. type RepairUserPicture struct {
  5. Id int
  6. UserId int
  7. PictureId int
  8. RepairId int
  9. Types int
  10. }
  11. func NewRepairUserPicture()(*RepairUserPicture) {
  12. return new(RepairUserPicture)
  13. }
  14. func (a *RepairUserPicture) TableName() string {
  15. return models.TableName("repair_user_picture")
  16. }
  17. func (a *RepairUserPicture)Add()(int64, error) {
  18. return orm.NewOrm().Insert(a)
  19. }
  20. func (a *RepairUserPicture)DeleteByPictureId(pictureId int) (int64, error) {
  21. query := orm.NewOrm().QueryTable(models.TableName("repair_user_picture"))
  22. return query.Filter("picture_id", pictureId).Delete()
  23. }
  24. type OutPicture struct {
  25. Path string
  26. }
  27. // 查找维修图片
  28. func (a *RepairUserPicture)FindPictureByUserIdAndReparId(userid int,repairId int)([]string) {
  29. o := orm.NewOrm()
  30. outPictures := make([]*OutPicture,0)
  31. var err error
  32. where := " pr.user_id = ? and pr.repair_id = ? and pr.types = 1 "
  33. _,err = o.Raw("SELECT pp.path as path" +
  34. " FROM pp_repair_user_picture pr left join pp_picture pp on pr.picture_id = pp.id WHERE"+where,userid,repairId).QueryRows(&outPictures)
  35. if err != nil {
  36. return nil
  37. }
  38. images := make([]string,0)
  39. for _, v := range outPictures {
  40. images = append(images,v.Path)
  41. }
  42. return images
  43. }
  44. func init() {
  45. orm.RegisterModel(new(RepairUserPicture))
  46. }