ShopOrder.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\common\model;
  3. use app\common\model\ShopOrderGoodsModel as OrderGoods;
  4. use app\common\model\ShopOrderShippingModel as OrderShipping;
  5. use app\common\model\TimeModel;
  6. class ShopOrder extends TimeModel
  7. {
  8. protected $name = "shop_order";
  9. protected $deleteTime = false;
  10. public function user ()
  11. {
  12. return $this->belongsTo('user', 'user_id', 'id');
  13. }
  14. public function goods ()
  15. {
  16. return $this->hasMany('shopOrderGoods', 'order_id', 'order_id')
  17. ->withAttr('goods_img',function($value){
  18. return getPreviewUrl($value);
  19. });
  20. }
  21. public function shipping ()
  22. {
  23. return $this->hasOne('shopOrderShipping', 'order_id', 'order_id');
  24. }
  25. /**
  26. * @return \think\model\relation\HasMany
  27. * 关联订单商品
  28. */
  29. public function withOrderGoods ()
  30. {
  31. return self::hasMany(OrderGoods::class, 'order_id', 'order_id')
  32. ->field('goods_name,goods_id,goods_img,num,price,total_fee,spec_text,goods_spec_id')
  33. ->withAttr('goods_img', function($value){
  34. return getPreviewUrl($value);
  35. });
  36. }
  37. /**
  38. * @return \think\model\relation\HasOne
  39. * 关联订单配送
  40. */
  41. public function withOrderShipping ()
  42. {
  43. return self::hasOne(OrderShipping::class, 'order_id', 'order_id')->field('sp_name,sp_mobile,sp_province,sp_city,sp_county,sp_remark,sp_mergename');
  44. }
  45. }