Prizerecord.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\admin\model\trade;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Prizerecord extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $name = 'prize_record';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'create_time';
  14. protected $updateTime = 'update_time';
  15. protected $deleteTime = 'delete_time';
  16. // 追加属性
  17. protected $append = [
  18. 'status_text',
  19. 'exchange_time_text',
  20. 'create_time_text',
  21. 'update_time_text',
  22. 'delete_time_text'
  23. ];
  24. public function getStatusList()
  25. {
  26. return ['bag' => __('Status bag'), 'exchange' => __('Status exchange'), 'delivery' => __('Status delivery'), 'received' => __('Status received')];
  27. }
  28. public function getStatusTextAttr($value, $data)
  29. {
  30. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  31. $list = $this->getStatusList();
  32. return isset($list[$value]) ? $list[$value] : '';
  33. }
  34. public function getExchangeTimeTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : (isset($data['exchange_time']) ? $data['exchange_time'] : '');
  37. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  38. }
  39. public function getCreateTimeTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  42. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  43. }
  44. public function getUpdateTimeTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  47. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  48. }
  49. public function getDeleteTimeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['delete_time']) ? $data['delete_time'] : '');
  52. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  53. }
  54. public function getGoodsImageAttr($value)
  55. {
  56. return cdnurl($value, true);
  57. }
  58. protected function setExchangeTimeAttr($value)
  59. {
  60. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  61. }
  62. protected function setCreateTimeAttr($value)
  63. {
  64. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  65. }
  66. protected function setUpdateTimeAttr($value)
  67. {
  68. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  69. }
  70. protected function setDeleteTimeAttr($value)
  71. {
  72. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  73. }
  74. }