Orders.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Orders extends Model
  5. {
  6. // 表名
  7. protected $name = 'orders';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'order_type_text',
  17. 'order_status_text',
  18. 'auto_cancel_time_text'
  19. ];
  20. public function getOrderTypeList()
  21. {
  22. return ['0' => __('Order_type 0'), '1' => __('Order_type 1')];
  23. }
  24. public function getOrderStatusList()
  25. {
  26. return ['0' => __('Order_status 0'), '10' => __('Order_status 10'), '20' => __('Order_status 20'), '30' => __('Order_status 30'), '40' => __('Order_status 40'), '50' => __('Order_status 50')];
  27. }
  28. public function getOrderTypeTextAttr($value, $data)
  29. {
  30. $value = $value ? $value : (isset($data['order_type']) ? $data['order_type'] : '');
  31. $list = $this->getOrderTypeList();
  32. return isset($list[$value]) ? $list[$value] : '';
  33. }
  34. public function getOrderStatusTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
  37. $list = $this->getOrderStatusList();
  38. return isset($list[$value]) ? $list[$value] : '';
  39. }
  40. public function getAutoCancelTimeTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['auto_cancel_time']) ? $data['auto_cancel_time'] : '');
  43. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  44. }
  45. protected function setAutoCancelTimeAttr($value)
  46. {
  47. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  48. }
  49. public function orderGoods(): \think\model\relation\HasMany
  50. {
  51. return $this->hasMany('app\common\model\order\Goods', 'order_no', 'order_no');
  52. }
  53. public function orderPayment(): \think\model\relation\HasMany
  54. {
  55. return $this->hasMany('app\common\model\order\Payment', 'order_no', 'order_no');
  56. }
  57. public function Demand()
  58. {
  59. return $this->belongsTo('Demands', 'parent_order_no', 'parent_order_no');
  60. }
  61. public function orderShip(): \think\model\relation\HasOne
  62. {
  63. return $this->hasOne('app\common\model\order\Ships', 'order_no', 'order_no');
  64. }
  65. }