| 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 StoreModel extends BaseModel
- {
- // 设置数据表
- protected $table = 'stores';
- protected $appends = ['mobile_text'];
- // 封面图
- public function getLogoAttribute($value)
- {
- $value = $value ? get_image_url($value) : '';
- return $value;
- }
- public function setLogoAttribute($value)
- {
- return $value ? get_image_path($value) : '';
- }
- // 营业执照/行驶证
- public function getBusinessLicenseAttribute($value)
- {
- $value = $value ? get_image_url($value) : '';
- return $value;
- }
- // 驾照
- public function getDriverLicenseAttribute($value)
- {
- $value = $value ? get_image_url($value) : '';
- return $value;
- }
- // 手机号
- public function getMobileTextAttribute()
- {
- $value = $this->mobile ? format_mobile($this->mobile) : '';
- return $value;
- }
- public function user()
- {
- return $this->hasOne(UserModel::class, 'id', 'user_id')
- ->select(['id', 'realname', 'nickname', 'status']);
- }
- public function member()
- {
- return $this->hasOne(MemberModel::class, 'id', 'user_id')
- ->select(['id', 'realname', 'nickname', 'mobile', 'parents', 'status']);
- }
- /**
- * 商家商品
- */
- public function goods()
- {
- return $this->hasMany(GoodsModel::class, 'store_id', 'id')
- ->with(['category'])
- ->where(['status' => 1, 'mark' => 1])
- ->select(['id', 'goods_name', 'category_id', 'store_id', 'price', 'thumb', 'sales', 'sku_type', 'unit', 'status'])
- ->orderBy('sort', 'desc')
- ->orderBy('id', 'desc');
- }
- /**
- * 关联商家分类
- */
- public function category()
- {
- return $this->hasOne(StoreCategoryModel::class, 'id', 'category_id')
- ->select(['id', 'name', 'status']);
- }
- public function getInfoByUserId($userId)
- {
- return $this->where(['user_id' => $userId, 'mark' => 1])->first();
- }
- }
|