GoodsModel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 商品管理-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class GoodsModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'goods';
  22. // 封面图
  23. public function getThumbAttribute($value)
  24. {
  25. $thumb = $value? get_image_url($value) : get_image_url('/images/goods/goods.jpeg');
  26. return $thumb;
  27. }
  28. public function setThumbAttribute($value)
  29. {
  30. return $value? get_image_path($value) : '';
  31. }
  32. public function getInfo($id)
  33. {
  34. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  35. if($info){
  36. $info['shipper_area'][] = isset($info['shipper_province_id'])? $info['shipper_province_id'] : 0;
  37. $info['shipper_area'][] = isset($info['shipper_city_id'])? $info['shipper_city_id'] : 0;
  38. $info['shipper_area'][] = isset($info['shipper_district_id'])? $info['shipper_district_id'] : 0;
  39. $info['receiver_area'][] = isset($info['receiver_province_id'])? $info['receiver_province_id'] : 0;
  40. $info['receiver_area'][] = isset($info['receiver_city_id'])? $info['receiver_city_id'] : 0;
  41. $info['receiver_area'][] = isset($info['receiver_district_id'])? $info['receiver_district_id'] : 0;
  42. }
  43. return $info;
  44. }
  45. /**
  46. * 订单信息
  47. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  48. */
  49. public function order()
  50. {
  51. return $this->hasOne(OrderModel::class, 'goods_id','id')
  52. ->where(['mark'=>1])
  53. ->whereIn('status',[2,3]);
  54. }
  55. /**
  56. * 寄货城市
  57. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  58. */
  59. public function shipperCity()
  60. {
  61. return $this->hasOne(CityModel::class, 'citycode','shipper_city_id');
  62. }
  63. /**
  64. * 寄货县/区
  65. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  66. */
  67. public function shipperDistrict()
  68. {
  69. return $this->hasOne(CityModel::class, 'citycode','shipper_district_id');
  70. }
  71. /**
  72. * 收货城市
  73. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  74. */
  75. public function receiverCity()
  76. {
  77. return $this->hasOne(CityModel::class, 'citycode','receiver_city_id');
  78. }
  79. /**
  80. * 收货县/区
  81. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  82. */
  83. public function receiverDistrict()
  84. {
  85. return $this->hasOne(CityModel::class, 'citycode','receiver_district_id');
  86. }
  87. }