StoreModel.php 2.7 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 StoreModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'stores';
  22. protected $appends = ['mobile_text'];
  23. // 封面图
  24. public function getLogoAttribute($value)
  25. {
  26. $value = $value ? get_image_url($value) : '';
  27. return $value;
  28. }
  29. public function setLogoAttribute($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. public function getDriverLicenseAttribute($value)
  41. {
  42. $value = $value ? get_image_url($value) : '';
  43. return $value;
  44. }
  45. // 手机号
  46. public function getMobileTextAttribute()
  47. {
  48. $value = $this->mobile ? format_mobile($this->mobile) : '';
  49. return $value;
  50. }
  51. public function user()
  52. {
  53. return $this->hasOne(UserModel::class, 'id', 'user_id')
  54. ->select(['id', 'realname', 'nickname', 'status']);
  55. }
  56. public function member()
  57. {
  58. return $this->hasOne(MemberModel::class, 'id', 'user_id')
  59. ->select(['id', 'realname', 'nickname', 'mobile', 'parents', 'status']);
  60. }
  61. /**
  62. * 商家商品
  63. */
  64. public function goods()
  65. {
  66. return $this->hasMany(GoodsModel::class, 'store_id', 'id')
  67. ->with(['category'])
  68. ->where(['status' => 1, 'mark' => 1])
  69. ->select(['id', 'goods_name', 'category_id', 'store_id', 'price', 'thumb', 'sales', 'sku_type', 'unit', 'status'])
  70. ->orderBy('sort', 'desc')
  71. ->orderBy('id', 'desc');
  72. }
  73. /**
  74. * 关联商家分类
  75. */
  76. public function category()
  77. {
  78. return $this->hasOne(StoreCategoryModel::class, 'id', 'category_id')
  79. ->select(['id', 'name', 'status']);
  80. }
  81. public function getInfoByUserId($userId)
  82. {
  83. return $this->where(['user_id' => $userId, 'mark' => 1])->first();
  84. }
  85. }