Ads.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Created by Administrator on 2015/4/15.
  3. * 广告管理
  4. */
  5. var mongoose = require('mongoose');
  6. var shortid = require('shortid');
  7. var Schema = mongoose.Schema;
  8. var AdsItems = require('./AdsItems');
  9. var AdsSchema = new Schema({
  10. _id: {
  11. type: String,
  12. unique: true,
  13. 'default': shortid.generate
  14. },
  15. name: String,
  16. type: { type: String, default: "0" }, // 展示形式 0文字 1图片 2友情链接
  17. state : { type: String, default: "1" }, // 广告状态,是否显示
  18. date: { type: Date, default: Date.now },
  19. items: [{ type: String , ref: 'AdsItems' }] // 广告列表id
  20. });
  21. AdsSchema.statics = {
  22. getOneAds : function(res,targetId,callBack){
  23. if(shortid.isValid(targetId)){
  24. Ads.findOne({'_id' : targetId}).populate('items').exec(function(err,doc){
  25. if(err){
  26. res.end(err);
  27. }
  28. callBack(doc);
  29. })
  30. }else{
  31. res.end('非法参数!');
  32. }
  33. }
  34. };
  35. var Ads = mongoose.model("Ads",AdsSchema);
  36. module.exports = Ads;