Coupon.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * User: charlie
  4. * 代金券
  5. */
  6. class Coupon extends MongoAr
  7. {
  8. public $_id;
  9. public $value;//代金券面额
  10. public $name;//代金券别名
  11. public $pic=array();//代金券的图片
  12. public $min_price;//满XX元才可以使用
  13. public $status=0;//代金券状态 0=>暂停使用 1=>正常使用 -1=>已删除
  14. public $memo;//备注
  15. public $alias_name;//别名
  16. public $type;//代金券的适用类型 array(1=>array("name"=>"宠物洗澡"),2=>array("name"=>"宠物剪毛"),3=>array("name"=>"宠物美容"))
  17. public $workday_limit=0; // 工作日非工作日限制 0: 无限制; 1: 仅限工作日使用; 2: 仅限周末使用
  18. public $time_limit_start; // 时间限制 0-24的数字
  19. public $time_limit_end; // 时间限制 0-24的数字
  20. public $time; // 代金券创建的时间
  21. public static $status_option = array(
  22. 0 => array('name' => '暂停使用'),
  23. 1 => array('name' => '正常使用'),
  24. -1 => array('name' => '已删除')
  25. );
  26. public static $workday_limit_option = array(
  27. 0 => array('name' => '无限制'),
  28. 1 => array('name' => '仅限工作日'),
  29. 2 => array('name' => '仅限周末'),
  30. );
  31. public function __construct($scenario='insert'){
  32. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  33. parent::__construct($scenario);
  34. }
  35. public static function model($className=__CLASS__)
  36. {
  37. return parent::model($className);
  38. }
  39. public function getCollectionName()
  40. {
  41. return 'coupons';
  42. }
  43. public static function get($_id) {
  44. if(CommonFn::isMongoId($_id)){
  45. $criteria = new EMongoCriteria();
  46. $criteria->_id('==', $_id);
  47. $model = self::model()->find($criteria);
  48. return $model;
  49. }else{
  50. return false;
  51. }
  52. }
  53. public function parseRow($row,$output=array()){
  54. $newRow = array();
  55. $newRow['id'] = (string)$row['_id'];
  56. $newRow['value'] = CommonFn::get_val_if_isset($row,'value',10);
  57. $newRow['name'] = CommonFn::get_val_if_isset($row,'name','');
  58. $newRow['alias_name'] = CommonFn::get_val_if_isset($row,'alias_name','');
  59. $newRow['memo'] = CommonFn::get_val_if_isset($row,'memo','');
  60. $newRow['min_price'] = CommonFn::get_val_if_isset($row,'min_price',100);
  61. $newRow['status'] = CommonFn::get_val_if_isset($row,'status',1);
  62. $newRow['type'] = CommonFn::get_val_if_isset($row,'type',0);
  63. if($newRow['type'] == 0){
  64. $newRow['type_str'] = '全部';
  65. }else{
  66. $newRow['type_str'] = Yii::app()->params['o2o_service'][$newRow['type']]['name'];
  67. }
  68. $newRow['workday_limit'] = CommonFn::get_val_if_isset($row, 'workday_limit', 0);
  69. $newRow['workday_limit_str'] = self::$workday_limit_option[$newRow['workday_limit']]['name'];
  70. $newRow['time_limit_start'] = CommonFn::get_val_if_isset($row, 'time_limit_start', '');
  71. $newRow['time_limit_end'] = CommonFn::get_val_if_isset($row, 'time_limit_end', '');
  72. $newRow['time_limit_str'] = '';
  73. if($newRow['workday_limit']==1){
  74. $newRow['time_limit_str'] = '工作日';
  75. }elseif($newRow['workday_limit'] == 2){
  76. $newRow['time_limit_str'] = '周末';
  77. }
  78. if($newRow['time_limit_start'] && $newRow['time_limit_end']){
  79. $newRow['time_limit_str'] = $newRow['time_limit_str'].' '.$newRow['time_limit_start'].'点-'.$newRow['time_limit_end'].'点';
  80. }
  81. $newRow['action_user'] = CommonFn::get_val_if_isset($row,'action_user',"");
  82. $newRow['action_time'] = CommonFn::get_val_if_isset($row,'action_time',"");
  83. $newRow['action_log'] = CommonFn::get_val_if_isset($row,'action_log',"");
  84. if(APPLICATION=='api'){
  85. //unset($newRow['status']);
  86. unset($newRow['action_user']);
  87. unset($newRow['action_time']);
  88. unset($newRow['action_log']);
  89. unset($newRow['memo']);
  90. }
  91. return $this->output($newRow,$output);
  92. }
  93. }