Store.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model;
  13. use cores\BaseModel;
  14. use think\model\relation\HasOne;
  15. /**
  16. * 商家记录表模型
  17. * Class Store
  18. * @package app\common\model
  19. */
  20. class Store extends BaseModel
  21. {
  22. // 定义表名
  23. protected $name = 'store';
  24. // 定义主键
  25. protected $pk = 'store_id';
  26. /**
  27. * 关联logo图片
  28. * @return HasOne
  29. */
  30. public function logoImage(): HasOne
  31. {
  32. return $this->hasOne('UploadFile', 'file_id', 'logo_image_id');
  33. }
  34. /**
  35. * 详情信息
  36. * @param int $storeId
  37. * @return static|array|null
  38. */
  39. public static function detail(int $storeId)
  40. {
  41. try {
  42. return self::withoutGlobalScope()
  43. ->with(['logoImage'])
  44. ->where('store_id', '=', $storeId)
  45. ->find();
  46. } catch (\Exception $e) {
  47. return null;
  48. }
  49. }
  50. /**
  51. * 获取列表数据
  52. * @param bool $isRecycle 是否在回收站
  53. * @return \think\Paginator
  54. * @throws \think\db\exception\DbException
  55. */
  56. public function getList(bool $isRecycle = false): \think\Paginator
  57. {
  58. return $this->where('is_recycle', '=', (int)$isRecycle)
  59. ->where('is_delete', '=', 0)
  60. ->order(['create_time' => 'desc', $this->getPk()])
  61. ->paginate(15);
  62. }
  63. }