Activeorder.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Activeorder extends Model
  5. {
  6. // 表名
  7. protected $name = 'active_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'paytype_text',
  17. 'status_text',
  18. 'refundstatus_text',
  19. 'refundtime_text'
  20. ];
  21. public function getPaytypeList()
  22. {
  23. return ['0' => __('Paytype 0'), '1' => __('Paytype 1')];
  24. }
  25. public function getStatusList()
  26. {
  27. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
  28. }
  29. public function getRefundstatusList()
  30. {
  31. return ['0' => __('Refundstatus 0'), '1' => __('Refundstatus 1'), '2' => __('Refundstatus 2')];
  32. }
  33. public function getPaytypeTextAttr($value, $data)
  34. {
  35. $value = $value ? $value : (isset($data['paytype']) ? $data['paytype'] : '');
  36. $list = $this->getPaytypeList();
  37. return isset($list[$value]) ? $list[$value] : '';
  38. }
  39. public function getStatusTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  42. $list = $this->getStatusList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getRefundstatusTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['refundstatus']) ? $data['refundstatus'] : '');
  48. $list = $this->getRefundstatusList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getRefundtimeTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['refundtime']) ? $data['refundtime'] : '');
  54. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  55. }
  56. protected function setRefundtimeAttr($value)
  57. {
  58. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  59. }
  60. public function active()
  61. {
  62. return $this->belongsTo('Active', 'active_id', 'id', [], 'LEFT')->setEagerlyType(0);
  63. }
  64. public function user()
  65. {
  66. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  67. }
  68. }