StoreModel.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // 封面图
  23. public function getLogoAttribute($value)
  24. {
  25. $value = $value ? get_image_url($value) : '';
  26. return $value;
  27. }
  28. public function setLogoAttribute($value)
  29. {
  30. return $value ? get_image_path($value) : '';
  31. }
  32. // 营业执照
  33. public function getBusinessLicenseAttribute($value)
  34. {
  35. $value = $value ? get_image_url($value) : '';
  36. return $value;
  37. }
  38. // 其他证件
  39. public function getOtherPhotoAttribute($value)
  40. {
  41. $value = $value ? get_image_url($value) : '';
  42. return $value;
  43. }
  44. public function user()
  45. {
  46. return $this->hasOne(UserModel::class, 'id', 'user_id')
  47. ->select(['id', 'realname', 'nickname', 'status']);
  48. }
  49. public function member()
  50. {
  51. return $this->hasOne(MemberModel::class, 'id', 'user_id')
  52. ->select(['id', 'realname', 'nickname', 'mobile', 'parents', 'status']);
  53. }
  54. /**
  55. * 商家商品
  56. */
  57. public function goods()
  58. {
  59. return $this->hasMany(GoodsModel::class, 'store_id', 'id')
  60. ->with(['category'])
  61. ->where(['status' => 1, 'mark' => 1])
  62. ->select(['id', 'goods_name', 'category_id', 'store_id', 'price', 'thumb', 'sales', 'sku_type', 'unit', 'status'])
  63. ->orderBy('sort', 'desc')
  64. ->orderBy('id', 'desc');
  65. }
  66. /**
  67. * 关联商家分类
  68. */
  69. public function category()
  70. {
  71. return $this->hasOne(StoreCategoryModel::class, 'id', 'category_id')
  72. ->select(['id', 'name', 'status']);
  73. }
  74. public function getInfoByUserId($userId)
  75. {
  76. return $this->where(['user_id' => $userId, 'mark' => 1])->first();
  77. }
  78. }