Comment.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. class Comment extends MongoAr
  3. {
  4. public $_id; //评价的object id
  5. public $content;//内容
  6. public $score;//评分
  7. public $order;//订单object id
  8. public $time;//评价发表时间
  9. public $user;//作者object id
  10. public $pics;
  11. public $status =1;//状态 1正常 0删除 -1垃圾
  12. public $type;//
  13. public $weight = 0;//评价权重
  14. public $technician = 0;
  15. public $technician_name = '';
  16. public $reply = ''; // 客服回复
  17. public function __construct($scenario='insert'){
  18. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  19. parent::__construct($scenario);
  20. }
  21. public static $status_option = array(
  22. 1 => array('name' => '正常'),
  23. 0 => array('name' => '删除')
  24. /*-1 => array('name' => '垃圾')*/
  25. );
  26. public static function model($className=__CLASS__)
  27. {
  28. return parent::model($className);
  29. }
  30. public function getCollectionName()
  31. {
  32. return 'comment';
  33. }
  34. public static function get($_id) {
  35. if(CommonFn::isMongoId($_id)){
  36. $criteria = new EMongoCriteria();
  37. $criteria->_id('==', $_id);
  38. $model = self::model()->find($criteria);
  39. return $model;
  40. }else{
  41. return false;
  42. }
  43. }
  44. /**
  45. * 根据OrderId获取评价
  46. */
  47. public static function getByOrder($order) {
  48. if (CommonFn::isMongoId($order)) {
  49. $criteria = new EMongoCriteria();
  50. $criteria->order('==', $order);
  51. $model = self::model()->find($criteria);
  52. return $model;
  53. } else {
  54. return false;
  55. }
  56. }
  57. public function parseRow($row,$output=array()){
  58. $newRow = array();
  59. $newRow['id'] = (string)$row['_id'];
  60. $newRow['content'] = CommonFn::get_val_if_isset($row,'content','');
  61. $newRow['score'] = CommonFn::get_val_if_isset($row,'score',5);
  62. $newRow['order'] = (string)CommonFn::get_val_if_isset($row,'order','');
  63. $newRow['time'] = CommonFn::get_val_if_isset($row,'time',0);
  64. $newRow['time_str'] = date('Y-m-d H:i:s',$newRow['time']);
  65. $newRow['time_str_short'] = date('m-d H:i', $newRow['time']);
  66. $newRow['type'] = CommonFn::get_val_if_isset($row,'type',1);
  67. $newRow['weight'] = CommonFn::get_val_if_isset($row,'weight',0);
  68. $newRow['status'] = CommonFn::get_val_if_isset($row,'status',0);
  69. $newRow['pics'] = CommonFn::get_val_if_isset($row,'pics',array());
  70. if(empty($newRow['pics'])){
  71. $newRow['pics'] = CommonFn::$empty;
  72. }
  73. $user = array();
  74. $t_user = new ZUser();
  75. if(isset($row['user'])){
  76. $_user = $t_user->get($row['user']);
  77. $user = RUser::model()->parseRow($_user->attributes,array('user_name','user_type','can_be_message','can_access','level','id','avatar','is_fake_user'));
  78. }
  79. $newRow['user'] = $user;
  80. $newRow['technician'] = intval(CommonFn::get_val_if_isset($row, 'technician', 0));
  81. $newRow['technician_name'] = '';
  82. $newRow['tech_info'] = [];
  83. if ($newRow['technician']) {
  84. $tech_info = TechInfo::get($newRow['technician']);
  85. if ($tech_info) {
  86. $newRow['tech_info'] = TechInfo::model()->parseRow($tech_info,array('id','name','mobile','weixin_userid'));
  87. $newRow['technician_name'] = $tech_info->name;
  88. }
  89. }
  90. $newRow['reply'] = CommonFn::get_val_if_isset($row, 'reply', '');
  91. $newRow['action_user'] = CommonFn::get_val_if_isset($row,'action_user',"");
  92. $newRow['action_time'] = CommonFn::get_val_if_isset($row,'action_time',"");
  93. $newRow['action_log'] = CommonFn::get_val_if_isset($row,'action_log',"");
  94. if(APPLICATION=='api'){
  95. unset($newRow['action_user']);
  96. unset($newRow['action_time']);
  97. unset($newRow['action_log']);
  98. }
  99. return $this->output($newRow,$output);
  100. }
  101. }