Product.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * User: charlie
  4. * 商品/服务
  5. */
  6. class Product extends MongoAr
  7. {
  8. public $_id;
  9. public $name;//服务的名字
  10. public $status=0;//产品状态 0=>暂停使用 1=>正常使用 -1=>已删除
  11. public $order=0;//产品权重
  12. public $type;//服务的适用类型
  13. public $is_extra=0;
  14. public $desc;//图文介绍 json格式 [{ // 图文详情"type": 1, // 1: 图片url, 2: 纯文本 "content": "http://a.big.jpg"}, {"type": 1,"content": "http://b.big.jpg"}, {"type": 2,"content": "描述文案..."}, // ... ]
  15. public $pics=array();//七牛的地址 array('url'=>'http://xxx.qiniudn.com/1414476356856.jpg','height'=>1180,'width'=>2340)
  16. public $price=0;//商品的单价 单位:元
  17. public $extra=array();//array('types'=>array(array('type'=>'一室一卫','price'=>180),array('type'=>'二室一卫','price'=>280)))
  18. public static $status_option = array(
  19. 0 => array('name' => '暂停使用'),
  20. 1 => array('name' => '正常使用'),
  21. -1 => array('name' => '已删除')
  22. );
  23. public function __construct($scenario='insert'){
  24. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  25. parent::__construct($scenario);
  26. }
  27. public static function model($className=__CLASS__)
  28. {
  29. return parent::model($className);
  30. }
  31. public static function get($_id) {
  32. if(CommonFn::isMongoId($_id)){
  33. $criteria = new EMongoCriteria();
  34. $criteria->_id('==', $_id);
  35. $model = self::model()->find($criteria);
  36. return $model;
  37. }else{
  38. return false;
  39. }
  40. }
  41. public function getCollectionName()
  42. {
  43. return 'products';
  44. }
  45. public function parseRow($row,$output=array()){
  46. $newRow = array();
  47. $newRow['id'] = (string)$row['_id'];
  48. $newRow['price'] = CommonFn::get_val_if_isset($row,'price',0);
  49. $newRow['name'] = CommonFn::get_val_if_isset($row,'name','');
  50. $newRow['desc'] = CommonFn::get_val_if_isset($row,'desc','');
  51. $newRow['status'] = CommonFn::get_val_if_isset($row,'status',1);
  52. $newRow['is_extra'] = CommonFn::get_val_if_isset($row,'is_extra',0);
  53. $newRow['order'] = CommonFn::get_val_if_isset($row,'order',1);
  54. $newRow['type'] = CommonFn::get_val_if_isset($row,'type',1);
  55. $newRow['type_str'] = Yii::app()->params['o2o_service'][$newRow['type']]['name'];
  56. $newRow['extra'] = CommonFn::get_val_if_isset($row,'extra',array());
  57. $newRow['action_user'] = CommonFn::get_val_if_isset($row,'action_user',"");
  58. $newRow['action_time'] = CommonFn::get_val_if_isset($row,'action_time',"");
  59. $newRow['action_log'] = CommonFn::get_val_if_isset($row,'action_log',"");
  60. $newRow['pics'] = CommonFn::get_val_if_isset($row,'pics',array());
  61. if(empty($newRow['pics'])){
  62. $newRow['pics'] = CommonFn::$empty;
  63. }
  64. if(APPLICATION=='api'){
  65. //unset($newRow['status']);
  66. unset($newRow['action_user']);
  67. unset($newRow['action_time']);
  68. unset($newRow['action_log']);
  69. }
  70. return $this->output($newRow,$output);
  71. }
  72. }