Order.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\admin\model\unishop;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Order extends Model
  6. {
  7. use SoftDelete;
  8. //数据库
  9. protected $connection = 'database';
  10. // 表名
  11. protected $name = 'unishop_order';
  12. // 自动写入时间戳字段
  13. protected $autoWriteTimestamp = 'int';
  14. // 定义时间戳字段名
  15. protected $createTime = 'createtime';
  16. protected $updateTime = 'updatetime';
  17. protected $deleteTime = 'deletetime';
  18. // 订单状态
  19. const STATUS_NORMAL = 1; // 正常
  20. const STATUS_CANCEL = 0; // 用户取消订单
  21. const STATUS_REFUND = -1; // 申请售后
  22. // 追加属性
  23. protected $append = [
  24. 'pay_type_text',
  25. 'status_text'
  26. ];
  27. public function getPayTypeList()
  28. {
  29. return ['1' => __('Online'), '2' => __('Offline'), '3' => __('wxPay'), '4' => __('aliPay')];
  30. }
  31. public function getStatusList()
  32. {
  33. return [/*'-1' => __('Refund'),*/ '0' => __('Cancel'), '1' => __('Normal')];
  34. }
  35. public function getRefundStatusList()
  36. {
  37. return ['0' => __('None'), '1' => __('Apply'),'2' => __('Pass and left User delivery') , '3' => __('Pass'), '4' => __('Refuse')];
  38. }
  39. public function getPayTypeTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
  42. $list = $this->getPayTypeList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getStatusTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  48. $list = $this->getStatusList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. protected function setHavePaidAttr($value)
  52. {
  53. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  54. }
  55. protected function setHaveDeliveredAttr($value)
  56. {
  57. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  58. }
  59. protected function setHaveCommentedAttr($value)
  60. {
  61. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  62. }
  63. protected function setHaveReceivedAttr($value)
  64. {
  65. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  66. }
  67. protected function setBooktimeAttr($value)
  68. {
  69. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  70. }
  71. /**
  72. * 关联用户
  73. */
  74. public function user(){
  75. return $this->hasOne('user', 'id', 'user_id');
  76. }
  77. /**
  78. * 关联订单扩展
  79. */
  80. public function extend(){
  81. return $this->belongsTo('orderExtend', 'id', 'order_id');
  82. }
  83. /**
  84. * 关联订单商品
  85. */
  86. public function product(){
  87. return $this->hasMany('orderProduct', 'order_id', 'id');
  88. }
  89. /**
  90. * 关联评价信息
  91. */
  92. public function evaluate()
  93. {
  94. return $this->hasMany('evaluate', 'order_id', 'id');
  95. }
  96. /**
  97. * 关联退货信息
  98. */
  99. public function refund()
  100. {
  101. return $this->hasOne('orderRefund', 'order_id', 'id');
  102. }
  103. public function refundProduct()
  104. {
  105. return $this->hasMany('orderRefundProduct', 'order_id', 'id');
  106. }
  107. }