You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Order.php 3.1 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /**
  68. * 关联用户
  69. */
  70. public function user(){
  71. return $this->hasOne('user', 'id', 'user_id');
  72. }
  73. /**
  74. * 关联订单扩展
  75. */
  76. public function extend(){
  77. return $this->belongsTo('orderExtend', 'id', 'order_id');
  78. }
  79. /**
  80. * 关联订单商品
  81. */
  82. public function product(){
  83. return $this->hasMany('orderProduct', 'order_id', 'id');
  84. }
  85. /**
  86. * 关联评价信息
  87. */
  88. public function evaluate()
  89. {
  90. return $this->hasMany('evaluate', 'order_id', 'id');
  91. }
  92. /**
  93. * 关联退货信息
  94. */
  95. public function refund()
  96. {
  97. return $this->hasOne('orderRefund', 'order_id', 'id');
  98. }
  99. public function refundProduct()
  100. {
  101. return $this->hasMany('orderRefundProduct', 'order_id', 'id');
  102. }
  103. }