OrderGoods.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/5/8
  6. * Time: 下午5:06
  7. */
  8. namespace app\backend\modules\order\models;
  9. use app\backend\modules\goods\models\Goods;
  10. use app\common\models\Member;
  11. use Yunshop\GoodsSource\common\models\GoodsSet;
  12. class OrderGoods extends \app\common\models\OrderGoods
  13. {
  14. static protected $needLog = true;
  15. protected $with = ['goods'];
  16. protected $appends = [
  17. 'goods_thumb', 'after_sales'
  18. ];
  19. public function getGoodsThumbAttribute()
  20. {
  21. return yz_tomedia($this->goods->thumb);
  22. }
  23. public function scopeOrderDetailGoods($query)
  24. {
  25. $orderDetailGoods = $query->select([
  26. 'id', 'order_id', 'goods_id', 'refund_id','is_refund','goods_price', 'total', 'goods_option_title', 'price', 'goods_market_price',
  27. 'goods_cost_price', 'thumb', 'title', 'goods_sn','payment_amount','deduction_amount','vip_price'
  28. ]);
  29. // $orderDetailGoods = $query->select('*');
  30. $orderDetailGoods->with([
  31. 'goods'=>function ($query) {
  32. return $query->select(['id','title','status','type','thumb','sku','market_price','price','cost_price','weight','product_sn','goods_sn']);
  33. },
  34. 'orderGoodsDeductions',
  35. 'orderGoodsDiscounts'
  36. ]);
  37. return $orderDetailGoods;
  38. }
  39. public function goods()
  40. {
  41. return $this->hasOne(Goods::class, 'id', 'goods_id')->withTrashed();
  42. }
  43. /**
  44. * 关联模型 1对1:购买者
  45. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  46. */
  47. public function belongsToMember()
  48. {
  49. return $this->belongsTo(Member::class, 'uid', 'uid');
  50. }
  51. public function goodsSource()
  52. {
  53. return $this->hasOne(GoodsSet::class, 'goods_id', 'goods_id');
  54. }
  55. }