Order.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\admin\model\cms;
  3. use think\Model;
  4. class Order extends Model
  5. {
  6. // 表名
  7. protected $name = 'cms_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'paytime_text',
  16. 'status_text'
  17. ];
  18. public function getStatusList()
  19. {
  20. return ['created' => __('Created'), 'paid' => __('Paid'), 'expired' => __('Expired')];
  21. }
  22. public function getPaytimeTextAttr($value, $data)
  23. {
  24. $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
  25. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  26. }
  27. public function getStatusTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  30. $list = $this->getStatusList();
  31. return isset($list[$value]) ? $list[$value] : '';
  32. }
  33. protected function setPaytimeAttr($value)
  34. {
  35. return $value && !is_numeric($value) ? strtotime($value) : $value;
  36. }
  37. public function user()
  38. {
  39. return $this->belongsTo("\app\common\model\User", 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  40. }
  41. public function archives()
  42. {
  43. return $this->belongsTo("Archives", 'archives_id', 'id', [], 'LEFT')->setEagerlyType(0);
  44. }
  45. }