Order.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\admin\model\order;
  3. use think\Model;
  4. class Order extends Model
  5. {
  6. // 表名
  7. protected $name = 'order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'is_deleted_text',
  18. 'paytime_text',
  19. 'type_text',
  20. 'pay_type_text'
  21. ];
  22. public function getStatusList()
  23. {
  24. return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1')];
  25. }
  26. public function getIsDeletedList()
  27. {
  28. return ['0' => __('Is_deleted 0'), '1' => __('Is_deleted 1')];
  29. }
  30. public function getTypeList()
  31. {
  32. return ['0' => __('Type 0'), '1' => __('Type 1')];
  33. }
  34. public function getPayTypeList()
  35. {
  36. return ['0' => __('Pay_type 0'), '1' => __('Pay_type 1')];
  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 getIsDeletedTextAttr($value, $data)
  45. {
  46. $value = $value ? $value : (isset($data['is_deleted']) ? $data['is_deleted'] : '');
  47. $list = $this->getIsDeletedList();
  48. return isset($list[$value]) ? $list[$value] : '';
  49. }
  50. public function getPaytimeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
  53. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  54. }
  55. public function getTypeTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  58. $list = $this->getTypeList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function getPayTypeTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
  64. $list = $this->getPayTypeList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. protected function setPaytimeAttr($value)
  68. {
  69. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  70. }
  71. }