OrderProduct.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\common\model\order;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 订单商品模型
  6. */
  7. class OrderProduct extends BaseModel
  8. {
  9. protected $name = 'order_product';
  10. protected $pk = 'order_product_id';
  11. /**
  12. * 订单商品列表
  13. * @return \think\model\relation\BelongsTo
  14. */
  15. public function image()
  16. {
  17. return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id');
  18. }
  19. /**
  20. * 关联商品表
  21. * @return \think\model\relation\BelongsTo
  22. */
  23. public function product()
  24. {
  25. return $this->belongsTo('app\\common\\model\\product\\Product');
  26. }
  27. /**
  28. * 关联商品sku表
  29. * @return \think\model\relation\BelongsTo
  30. */
  31. public function sku()
  32. {
  33. return $this->belongsTo('app\\common\\model\\product\\ProductSku', 'spec_sku_id', 'spec_sku_id');
  34. }
  35. /**
  36. * 关联订单主表
  37. * @return \think\model\relation\BelongsTo
  38. */
  39. public function orderM()
  40. {
  41. return $this->belongsTo('Order','order_id','order_id');
  42. }
  43. /**
  44. * 售后单记录表
  45. * @return \think\model\relation\HasOne
  46. */
  47. public function refund()
  48. {
  49. return $this->hasOne('app\\common\\model\\order\\OrderRefund');
  50. }
  51. /**
  52. * 售后单最新记录表
  53. * @return \think\model\relation\HasMany
  54. */
  55. public function lastRefund()
  56. {
  57. return $this->hasMany('app\\common\\model\\order\\OrderRefund')->order('order_refund_id', 'desc');
  58. }
  59. /**
  60. * 关联分销商
  61. * @return \think\model\relation\BelongsTo
  62. */
  63. public function agent()
  64. {
  65. return $this->belongsTo('app\\common\\model\\agent\\Apply', 'agent_user_id', 'user_id');
  66. }
  67. /**
  68. * 订单商品详情
  69. * @param $where
  70. * @return array|\think\Model|null
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\DbException
  73. * @throws \think\db\exception\ModelNotFoundException
  74. */
  75. public static function detail($where)
  76. {
  77. return (new static())->with(['image', 'refund', 'orderM', 'last_refund'])->find($where);
  78. }
  79. }