You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.5 KiB

  1. <?php
  2. namespace addons\unishop\model;
  3. use addons\unishop\extend\Hashids;
  4. use think\Model;
  5. use traits\model\SoftDelete;
  6. class Evaluate extends Model
  7. {
  8. use SoftDelete;
  9. // 表名
  10. protected $name = 'unishop_evaluate';
  11. // 开启自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'int';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = 'updatetime';
  16. protected $deleteTime = 'deletetime';
  17. /**
  18. * 加密商品id
  19. * @param $value
  20. * @return string
  21. */
  22. public function getProductIdAttr($value)
  23. {
  24. return Hashids::encodeHex($value);
  25. }
  26. // 是否置顶
  27. const TOP_OFF = 0;
  28. // 是否匿名
  29. const ANONYMOUS_YES = 1; // 是
  30. const ANONYMOUS_NO = 0; // 否
  31. public function getCreatetimeTextAttr($value, $data)
  32. {
  33. return date('Y-m-d H:i:s', $data['createtime']);
  34. }
  35. public function getUsernameAttr($value, $data) {
  36. if ($data['anonymous'] == self::ANONYMOUS_YES) {
  37. return __('Anonymous');
  38. } else {
  39. return $data['username'] ? $data['username'] : __('Tourist');
  40. }
  41. }
  42. public function getAvatarAttr($value, $data){
  43. if ($data['anonymous'] == self::ANONYMOUS_YES) {
  44. $data['avatar'] = Config::getByName('avatar')['value'];
  45. } else {
  46. $data['avatar'] = $data['avatar'] ? $data['avatar'] : Config::getByName('avatar')['value'];
  47. }
  48. return Config::getImagesFullUrl($data['avatar']);
  49. }
  50. }