Comment.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 $technicians = array();//多个保洁师
  16. public $technician_name = '';
  17. public $reply = ''; // 客服回复
  18. public function __construct($scenario='insert'){
  19. $this->setMongoDBComponent(Yii::app()->getComponent('mongodb_o2o'));
  20. parent::__construct($scenario);
  21. }
  22. public static $status_option = array(
  23. 1 => array('name' => '正常'),
  24. 0 => array('name' => '删除')
  25. /*-1 => array('name' => '垃圾')*/
  26. );
  27. public static function model($className=__CLASS__)
  28. {
  29. return parent::model($className);
  30. }
  31. public function getCollectionName()
  32. {
  33. return 'comment';
  34. }
  35. public static function get($_id) {
  36. if(CommonFn::isMongoId($_id)){
  37. $criteria = new EMongoCriteria();
  38. $criteria->_id('==', $_id);
  39. $model = self::model()->find($criteria);
  40. return $model;
  41. }else{
  42. return false;
  43. }
  44. }
  45. /**
  46. * 根据OrderId获取评价
  47. */
  48. public static function getByOrder($order) {
  49. if (CommonFn::isMongoId($order)) {
  50. $criteria = new EMongoCriteria();
  51. $criteria->order('==', $order);
  52. $model = self::model()->find($criteria);
  53. return $model;
  54. } else {
  55. return false;
  56. }
  57. }
  58. public function parseRow($row,$output=array()){
  59. $newRow = array();
  60. $newRow['id'] = (string)$row['_id'];
  61. $newRow['content'] = CommonFn::get_val_if_isset($row,'content','');
  62. $newRow['score'] = CommonFn::get_val_if_isset($row,'score',5);
  63. $newRow['order'] = (string)CommonFn::get_val_if_isset($row,'order','');
  64. $newRow['time'] = CommonFn::get_val_if_isset($row,'time',0);
  65. $newRow['time_str'] = date('Y-m-d H:i:s',$newRow['time']);
  66. $newRow['time_str_short'] = date('m-d H:i', $newRow['time']);
  67. $newRow['type'] = CommonFn::get_val_if_isset($row,'type',1);
  68. $newRow['weight'] = CommonFn::get_val_if_isset($row,'weight',0);
  69. $newRow['status'] = CommonFn::get_val_if_isset($row,'status',0);
  70. $newRow['pics'] = CommonFn::get_val_if_isset($row,'pics',array());
  71. if(empty($newRow['pics'])){
  72. $newRow['pics'] = CommonFn::$empty;
  73. }
  74. $user = array();
  75. $t_user = new ZUser();
  76. if(isset($row['user'])){
  77. $_user = $t_user->get($row['user']);
  78. $user = RUser::model()->parseRow($_user->attributes,array('user_name','user_type','can_be_message','can_access','level','id','avatar','is_fake_user'));
  79. }
  80. $newRow['user'] = $user;
  81. $newRow['technicians'] = CommonFn::get_val_if_isset($row, 'technicians');
  82. //$newRow['technician_name'] = '';
  83. $newRow['tech_info'] = [];
  84. if ($newRow['technicians']) {
  85. foreach($newRow['technicians'] as $technicians) {
  86. $tech_info = TechInfo::get($technicians);
  87. if ($tech_info) {
  88. $newRow['tech_info'][] = TechInfo::model()->parseRow($tech_info, array('id', 'name', 'mobile', 'weixin_userid'));
  89. $newRow['technician_name'][] = $tech_info->name;
  90. }
  91. }
  92. }
  93. $newRow['reply'] = CommonFn::get_val_if_isset($row, 'reply', '');
  94. $newRow['action_user'] = CommonFn::get_val_if_isset($row,'action_user',"");
  95. $newRow['action_time'] = CommonFn::get_val_if_isset($row,'action_time',"");
  96. $newRow['action_log'] = CommonFn::get_val_if_isset($row,'action_log',"");
  97. if(APPLICATION=='api'){
  98. unset($newRow['action_user']);
  99. unset($newRow['action_time']);
  100. unset($newRow['action_log']);
  101. }
  102. return $this->output($newRow,$output);
  103. }
  104. }