belongsTo('user', 'user_id', 'id'); } public function goods () { return $this->hasMany('shopOrderGoods', 'order_id', 'order_id') ->withAttr('goods_img',function($value){ return getPreviewUrl($value); }); } public function shipping () { return $this->hasOne('shopOrderShipping', 'order_id', 'order_id'); } /** * @return \think\model\relation\HasMany * 关联订单商品 */ public function withOrderGoods () { return self::hasMany(OrderGoods::class, 'order_id', 'order_id') ->field('goods_name,goods_id,goods_img,num,price,total_fee,spec_text,goods_spec_id') ->withAttr('goods_img', function($value){ return getPreviewUrl($value); }); } /** * @return \think\model\relation\HasOne * 关联订单配送 */ public function withOrderShipping () { return self::hasOne(OrderShipping::class, 'order_id', 'order_id')->field('sp_name,sp_mobile,sp_province,sp_city,sp_county,sp_remark,sp_mergename'); } }