MoneyRecord.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class MoneyRecord extends Model
  5. {
  6. // 表名
  7. protected $name = 'money_record';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'create_time_text',
  18. 'update_time_text',
  19. 'delete_time_text'
  20. ];
  21. public function getTypeList()
  22. {
  23. return ['box_exchange' => __('Type box_exchange'), 'refund' => __('Type refund'), 'withdrawal' => __('Type withdrawal'), 'to_coin' => __('Type to_coin'), 'withdrawal_fail' => __('Type withdrawal_fail'), 'withdrawals' => __('Type withdrawals')];
  24. }
  25. public function getTypeTextAttr($value, $data)
  26. {
  27. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  28. $list = $this->getTypeList();
  29. return isset($list[$value]) ? $list[$value] : '';
  30. }
  31. public function getCreateTimeTextAttr($value, $data)
  32. {
  33. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  34. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  35. }
  36. public function getUpdateTimeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  39. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40. }
  41. public function getDeleteTimeTextAttr($value, $data)
  42. {
  43. $value = $value ? $value : (isset($data['delete_time']) ? $data['delete_time'] : '');
  44. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  45. }
  46. protected function setCreateTimeAttr($value)
  47. {
  48. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  49. }
  50. protected function setUpdateTimeAttr($value)
  51. {
  52. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  53. }
  54. protected function setDeleteTimeAttr($value)
  55. {
  56. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  57. }
  58. }