StoreModel.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 StoreModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'user';
  22. protected $appends = ['mobile_text'];
  23. // 封面图
  24. public function getAvatarAttribute($value)
  25. {
  26. $value = $value ? get_image_url($value) : '';
  27. return $value;
  28. }
  29. public function setAvatarAttribute($value)
  30. {
  31. return $value ? get_image_path($value) : '';
  32. }
  33. // 营业执照
  34. public function getBusinessLicenseAttribute($value)
  35. {
  36. $value = $value ? get_image_url($value) : '';
  37. return $value;
  38. }
  39. /**
  40. * @return array
  41. */
  42. public function getmobileTextAttribute()
  43. {
  44. return $this->mobile? format_mobile($this->mobile):'';
  45. }
  46. /**
  47. * 用户
  48. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  49. */
  50. public function member()
  51. {
  52. return $this->hasOne(MemberModel::class, 'id', 'user_id')
  53. ->select(['id', 'realname', 'nickname', 'mobile','parents', 'status']);
  54. }
  55. /**
  56. * 商家商品
  57. */
  58. public function goods()
  59. {
  60. return $this->hasMany(GoodsModel::class, 'store_id', 'id')
  61. ->with(['category'])
  62. ->where(['status'=>1,'mark'=>1])
  63. ->select(['id','goods_name','category_id','store_id','price','thumb','sales','sku_type','unit','status'])
  64. ->orderBy('sort','desc')
  65. ->orderBy('id','desc');
  66. }
  67. public function getInfoByUserId($userId)
  68. {
  69. return $this->where(['user_id' => $userId, 'mark' => 1])->first();
  70. }
  71. }