Order.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace addons\ddrive\model;
  3. use think\Model;
  4. class Order extends Model
  5. {
  6. // 表名
  7. protected $name = 'ddrive_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'status_text',
  17. 'comment_text',
  18. ];
  19. public function getStatusList()
  20. {
  21. return ['-2' => __('Status -2'),'-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1'), '4' => __('Status 4'), '2' => __('Status 2'), '3' => __('Status 3'), '99' => __('Status 99'), '5' => __('Status 5'), '-2' => __('Status -2')];
  22. }
  23. public function getCommentList()
  24. {
  25. return ['0' => __('Comment 0'), '1' => __('Comment 1')];
  26. }
  27. public function getTypeList()
  28. {
  29. return ['1' => __('Type 1'), '2' => __('Type 2')];
  30. }
  31. public function getStatusTextAttr($value, $data)
  32. {
  33. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  34. $list = $this->getStatusList();
  35. return isset($list[$value]) ? $list[$value] : '';
  36. }
  37. public function getCommentTextAttr($value, $data)
  38. {
  39. $value = $value ? $value : (isset($data['comment']) ? $data['comment'] : '');
  40. $list = $this->getCommentList();
  41. return isset($list[$value]) ? $list[$value] : '';
  42. }
  43. public function getTypeTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['Type']) ? $data['Type'] : '');
  46. $list = $this->getTypeList();
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. public function user()
  50. {
  51. return $this->belongsTo('\\app\\admin\\model\\User', 'user_id', 'id', [], 'LEFT')->field('avatar,mobile,group_id,id,username,nickname,email,prevtime,logintime,jointime')->setEagerlyType(0);
  52. }
  53. public function driver()
  54. {
  55. return $this->belongsTo('\\app\\admin\\model\\User', 'driver_id', 'id', [], 'LEFT')->field('avatar,mobile,group_id,id,username,nickname,email,prevtime,logintime,jointime')->setEagerlyType(0);
  56. }
  57. }