Evaluate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }