Takecash.php 2.0 KB

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