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 $config = [];
  34. protected static $tagCount = 0;
  35. protected static function init()
  36. {
  37. $config = get_addon_config('shop');
  38. self::$config = $config;
  39. }
  40. // public function getOrderStatusTextAttr($value, $data)
  41. // {
  42. // return OrderEnum::getOrderStatusText($data['order_status']);
  43. // }
  44. public function user()
  45. {
  46. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  47. }
  48. public function address()
  49. {
  50. return $this->belongsTo('Address', 'address_id', 'id', [], 'LEFT')->setEagerlyType(0);
  51. }
  52. public function orderGoods()
  53. {
  54. return $this->hasMany('OrderGoods', 'order_sn', 'order_sn');
  55. }
  56. public function orderElectronics()
  57. {
  58. return $this->hasMany('OrderElectronics', 'order_sn', 'order_sn');
  59. }
  60. public function orderAction()
  61. {
  62. return $this->hasMany('OrderAction', 'order_sn', 'order_sn');
  63. }
  64. public function orderAddress()
  65. {
  66. return $this->hasOne('OrderAddress', 'order_id', 'id');
  67. }
  68. }