| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Models;
- /**
- * 商品管理-模型
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Models
- */
- class GoodsModel extends BaseModel
- {
- // 设置数据表
- protected $table = 'goods';
- // 封面图
- public function getThumbAttribute($value)
- {
- $thumb = $value? get_image_url($value) : get_image_url('/images/goods/goods.jpeg');
- return $thumb;
- }
- public function setThumbAttribute($value)
- {
- return $value? get_image_path($value) : '';
- }
- public function getInfo($id)
- {
- $info = parent::getInfo($id); // TODO: Change the autogenerated stub
- if($info){
- $info['shipper_area'][] = isset($info['shipper_province_id'])? $info['shipper_province_id'] : 0;
- $info['shipper_area'][] = isset($info['shipper_city_id'])? $info['shipper_city_id'] : 0;
- $info['shipper_area'][] = isset($info['shipper_district_id'])? $info['shipper_district_id'] : 0;
- $info['receiver_area'][] = isset($info['receiver_province_id'])? $info['receiver_province_id'] : 0;
- $info['receiver_area'][] = isset($info['receiver_city_id'])? $info['receiver_city_id'] : 0;
- $info['receiver_area'][] = isset($info['receiver_district_id'])? $info['receiver_district_id'] : 0;
- }
- return $info;
- }
- /**
- * 订单信息
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function order()
- {
- return $this->hasOne(OrderModel::class, 'goods_id','id')
- ->where(['mark'=>1])
- ->whereIn('status',[2,3]);
- }
- /**
- * 寄货城市
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function shipperCity()
- {
- return $this->hasOne(CityModel::class, 'citycode','shipper_city_id');
- }
- /**
- * 寄货县/区
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function shipperDistrict()
- {
- return $this->hasOne(CityModel::class, 'citycode','shipper_district_id');
- }
- /**
- * 收货城市
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function receiverCity()
- {
- return $this->hasOne(CityModel::class, 'citycode','receiver_city_id');
- }
- /**
- * 收货县/区
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function receiverDistrict()
- {
- return $this->hasOne(CityModel::class, 'citycode','receiver_district_id');
- }
- }
|