| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace app\common\model\order;
- use app\common\model\BaseModel;
- /**
- * 订单商品模型
- */
- class OrderProduct extends BaseModel
- {
- protected $name = 'order_product';
- protected $pk = 'order_product_id';
- /**
- * 订单商品列表
- * @return \think\model\relation\BelongsTo
- */
- public function image()
- {
- return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id');
- }
- /**
- * 关联商品表
- * @return \think\model\relation\BelongsTo
- */
- public function product()
- {
- return $this->belongsTo('app\\common\\model\\product\\Product');
- }
- /**
- * 关联商品sku表
- * @return \think\model\relation\BelongsTo
- */
- public function sku()
- {
- return $this->belongsTo('app\\common\\model\\product\\ProductSku', 'spec_sku_id', 'spec_sku_id');
- }
- /**
- * 关联订单主表
- * @return \think\model\relation\BelongsTo
- */
- public function orderM()
- {
- return $this->belongsTo('Order','order_id','order_id');
- }
- /**
- * 售后单记录表
- * @return \think\model\relation\HasOne
- */
- public function refund()
- {
- return $this->hasOne('app\\common\\model\\order\\OrderRefund');
- }
- /**
- * 售后单最新记录表
- * @return \think\model\relation\HasMany
- */
- public function lastRefund()
- {
- return $this->hasMany('app\\common\\model\\order\\OrderRefund')->order('order_refund_id', 'desc');
- }
- /**
- * 关联分销商
- * @return \think\model\relation\BelongsTo
- */
- public function agent()
- {
- return $this->belongsTo('app\\common\\model\\agent\\Apply', 'agent_user_id', 'user_id');
- }
- /**
- * 订单商品详情
- * @param $where
- * @return array|\think\Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function detail($where)
- {
- return (new static())->with(['image', 'refund', 'orderM', 'last_refund'])->find($where);
- }
- }
|