MoneyOut.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class MoneyOut extends Model
  5. {
  6. // 表名
  7. protected $name = 'money_out';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'create_time';
  12. protected $updateTime = 'update_time';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'create_time_text',
  17. 'update_time_text'
  18. ];
  19. //状态
  20. const Default = 0;
  21. const Pending = 100;
  22. const Success = 200;
  23. const Fail = 400;
  24. const Cancel = 500;
  25. /*
  26. * 订单状态
  27. */
  28. public function getStatusNames($type = -1){
  29. $status_names = [
  30. '-1' => __('全部状态'),
  31. self::Default => __('默认'),
  32. self::Pending => __('待处理'),
  33. self::Success => __('完成'),
  34. self::Fail => __('失败'),
  35. self::Cancel => __('取消'),
  36. ];
  37. if($type == -1){
  38. return $status_names;
  39. }
  40. if(isset($status_names[$type])){
  41. return $status_names[$type];
  42. }
  43. return __('未定义');
  44. }
  45. //操作列表
  46. public function getTypeList()
  47. {
  48. return [1 => __('Usdt'), 2 => __('Bank')];
  49. }
  50. public function users()
  51. {
  52. return $this->hasOne('Users','id','user_id',[],'LEFT')->setEagerlyType(0);
  53. }
  54. public function admins()
  55. {
  56. return $this->hasOne('\app\admin\model\Admin','id','admin_id',[],'LEFT')->setEagerlyType(0);
  57. }
  58. public function getCreateTimeTextAttr($value, $data)
  59. {
  60. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  61. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  62. }
  63. public function getUpdateTimeTextAttr($value, $data)
  64. {
  65. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  66. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  67. }
  68. protected function setCreateTimeAttr($value)
  69. {
  70. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  71. }
  72. protected function setUpdateTimeAttr($value)
  73. {
  74. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  75. }
  76. }