Order.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Exception;
  5. use think\Model;
  6. use Yansongda\Pay\Exceptions\GatewayException;
  7. use addons\epay\library\Service;
  8. use app\common\model\OrderAction;
  9. use app\common\model\TemplateMsg;
  10. use traits\model\SoftDelete;
  11. use app\common\Enum\OrderEnum;
  12. use app\common\Traits\OrderStatusTrait;
  13. /**
  14. * 订单模型
  15. * @property mixed $address 订单地址信息(动态属性)
  16. */
  17. class Order extends Model
  18. {
  19. use SoftDelete;
  20. use OrderStatusTrait;
  21. // 表名
  22. protected $name = 'shop_order';
  23. // 开启自动写入时间戳字段
  24. protected $autoWriteTimestamp = 'int';
  25. // 定义时间戳字段名
  26. protected $createTime = 'createtime';
  27. protected $updateTime = 'updatetime';
  28. protected $deleteTime = 'deletetime';
  29. // 追加属性
  30. // protected $append = [
  31. // 'order_status_text',
  32. // ];
  33. protected static $tagCount = 0;
  34. // public function getOrderStatusTextAttr($value, $data)
  35. // {
  36. // return OrderEnum::getOrderStatusText($data['order_status']);
  37. // }
  38. public function user()
  39. {
  40. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  41. }
  42. public function address()
  43. {
  44. return $this->belongsTo('Address', 'address_id', 'id', [], 'LEFT')->setEagerlyType(0);
  45. }
  46. public function orderGoods()
  47. {
  48. return $this->hasMany('OrderGoods', 'order_sn', 'order_sn');
  49. }
  50. public function orderElectronics()
  51. {
  52. return $this->hasMany('OrderElectronics', 'order_sn', 'order_sn');
  53. }
  54. public function orderAction()
  55. {
  56. return $this->hasMany('OrderAction', 'order_sn', 'order_sn');
  57. }
  58. public function orderAddress()
  59. {
  60. return $this->hasOne('OrderAddress', 'order_id', 'id');
  61. }
  62. public function orderProfile()
  63. {
  64. return $this->hasOne('OrderProfile', 'order_id', 'id');
  65. }
  66. }