Order.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class Order extends Model
  5. {
  6. // 表名
  7. protected $name = '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. //订单状态: 0未支付 1完成 2冻结 3取消
  20. const STATUSUNPAID = 0;
  21. const STATUSFINISH = 1;
  22. const STATUSFREEZE = 2;
  23. const STATUSCANCEL = 3;
  24. /*
  25. * 订单状态
  26. * 0未支付 1完成 2冻结 3取消
  27. */
  28. public function getStatusNames($type = -1){
  29. $status_names = [
  30. '-1' => __('全部状态'),
  31. self::STATUSUNPAID => __('待支付'),
  32. self::STATUSFINISH => __('完成'),
  33. self::STATUSFREEZE => __('冻结'),
  34. self::STATUSCANCEL => __('取消'),
  35. ];
  36. if($type == -1){
  37. return $status_names;
  38. }
  39. if(isset($status_names[$type])){
  40. return $status_names[$type];
  41. }
  42. return __('未定义');
  43. }
  44. //users
  45. public function users()
  46. {
  47. return $this->hasOne('Users','id','user_id',[],'LEFT')->setEagerlyType(0);
  48. }
  49. //操作列表
  50. public function getstatusList()
  51. {
  52. return [self::STATUSFINISH => __('Finish'), 2 => __('Freeze'), 3 => __('Cancel')];
  53. }
  54. public function getCreateTimeTextAttr($value, $data)
  55. {
  56. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  57. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  58. }
  59. public function getUpdateTimeTextAttr($value, $data)
  60. {
  61. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  62. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  63. }
  64. protected function setCreateTimeAttr($value)
  65. {
  66. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  67. }
  68. protected function setUpdateTimeAttr($value)
  69. {
  70. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  71. }
  72. }