ProductOrder.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class ProductOrder extends Model
  5. {
  6. // 表名
  7. protected $table = 'product_order';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'create_time';
  12. protected $updateTime = 'update_time';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'create_time_text',
  17. 'update_time_text'
  18. ];
  19. const Ordered = 0;
  20. const Paid = 1;
  21. const Transferred = 2;
  22. const Shipped = 3;
  23. const Cancelled = 4;
  24. const Closure = 5;
  25. const Popular = 0;
  26. const Transfer = 1;
  27. const Giveaway = 2;
  28. /*
  29. * 订单状态 '已下单', 1=>'已付款', 2=>'已转让', 3=>'提货', 4=>'已取消', 5=>'完成'];
  30. */
  31. public $order_status = [
  32. '-1' => '全部',
  33. self::Ordered => '已下单',
  34. self::Paid => '已付款',
  35. self::Transferred => '已转让',
  36. self::Shipped => '提货',
  37. self::Cancelled => '已取消',
  38. self::Closure => '关闭',
  39. ];
  40. public static function getStatusList()
  41. {
  42. return [self::Ordered => __('已下单'), self::Paid => __('已付款'), self::Transferred => __('已转让'),
  43. self::Shipped => __('提货'), self::Cancelled => __('已取消'), self::Closure => __('关闭')];
  44. }
  45. //产品
  46. public function products()
  47. {
  48. return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->setEagerlyType(0);
  49. }
  50. //用户 user_id
  51. public function users()
  52. {
  53. return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
  54. }
  55. //区域
  56. public function areas()
  57. {
  58. return $this->hasOne('ProductArea', 'id', 'area_id', [], 'LEFT')->setEagerlyType(0);
  59. }
  60. //提货地址
  61. public function address()
  62. {
  63. return $this->hasOne('UserArea', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
  64. }
  65. public function getCreateTimeTextAttr($value, $data)
  66. {
  67. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  68. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  69. }
  70. public function getUpdateTimeTextAttr($value, $data)
  71. {
  72. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  73. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  74. }
  75. protected function setCreateTimeAttr($value)
  76. {
  77. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  78. }
  79. protected function setUpdateTimeAttr($value)
  80. {
  81. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  82. }
  83. }