Userwithdraw.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Userwithdraw extends Model
  5. {
  6. // 表名
  7. protected $table = 'user_withdraw';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'status_text',
  18. 'audittime_text'
  19. ];
  20. public function getTypeList()
  21. {
  22. return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
  23. }
  24. public function getStatusList()
  25. {
  26. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
  27. }
  28. public function getFromList()
  29. {
  30. return ['1' => __('from 1'), '2' => __('from 2')];
  31. }
  32. public function getTypeTextAttr($value, $data)
  33. {
  34. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  35. $list = $this->getTypeList();
  36. return isset($list[$value]) ? $list[$value] : '';
  37. }
  38. public function getStatusTextAttr($value, $data)
  39. {
  40. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  41. $list = $this->getStatusList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getFromTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['from']) ? $data['from'] : '');
  47. $list = $this->getFromList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. public function getAudittimeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['audittime']) ? $data['audittime'] : '');
  53. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  54. }
  55. protected function setAudittimeAttr($value)
  56. {
  57. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  58. }
  59. public function user()
  60. {
  61. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  62. }
  63. }