Preorder.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Preorder extends Model
  5. {
  6. // 表名
  7. protected $name = 'pre_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'pre_time_text',
  17. 'order_time_text',
  18. 'cancel_time_text',
  19. 'pre_order_status_text'
  20. ];
  21. public function getPreOrderStatusList()
  22. {
  23. return ['0' => __('Pre_order_status 0'), '1' => __('Pre_order_status 1'), '2' => __('Pre_order_status 2')];
  24. }
  25. public function getPreTimeTextAttr($value, $data)
  26. {
  27. $value = $value ? $value : (isset($data['pre_time']) ? $data['pre_time'] : '');
  28. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  29. }
  30. public function getOrderTimeTextAttr($value, $data)
  31. {
  32. $value = $value ? $value : (isset($data['order_time']) ? $data['order_time'] : '');
  33. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  34. }
  35. public function getCancelTimeTextAttr($value, $data)
  36. {
  37. $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
  38. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  39. }
  40. public function getPreOrderStatusTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['pre_order_status']) ? $data['pre_order_status'] : '');
  43. $list = $this->getPreOrderStatusList();
  44. return isset($list[$value]) ? $list[$value] : '';
  45. }
  46. protected function setPreTimeAttr($value)
  47. {
  48. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  49. }
  50. protected function setOrderTimeAttr($value)
  51. {
  52. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  53. }
  54. protected function setCancelTimeAttr($value)
  55. {
  56. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  57. }
  58. public function company()
  59. {
  60. return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
  61. }
  62. public function user()
  63. {
  64. return $this->belongsTo('User', 'id', 'id', [], 'LEFT')->setEagerlyType(0);
  65. }
  66. public function servicetype()
  67. {
  68. return $this->belongsTo('Servicetype', 'servicetype_id', 'id', [], 'LEFT')->setEagerlyType(0);
  69. }
  70. public function order()
  71. {
  72. return $this->belongsTo('Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
  73. }
  74. }