Express.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  15. * 物流公司模型
  16. * Class Express
  17. * @package app\common\model
  18. */
  19. class Express extends BaseModel
  20. {
  21. // 定义表名
  22. protected $name = 'express';
  23. // 定义主键
  24. protected $pk = 'express_id';
  25. /**
  26. * 获取全部记录
  27. * @param array $param
  28. * @return \think\Collection
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function getAll(array $param = []): \think\Collection
  34. {
  35. // 检索查询条件
  36. $filter = $this->getFilter($param);
  37. // 查询列表数据
  38. return $this->where($filter)->order(['sort', $this->getPk()])->select();
  39. }
  40. /**
  41. * 获取列表
  42. * @param array $param
  43. * @return \think\Paginator
  44. * @throws \think\db\exception\DbException
  45. */
  46. public function getList(array $param = []): \think\Paginator
  47. {
  48. // 检索查询调价你
  49. $filter = $this->getFilter($param);
  50. // 查询列表数据
  51. return $this->where($filter)->order(['sort', 'express_id'])->paginate(15);
  52. }
  53. /**
  54. * 检索查询条件
  55. * @param array $param
  56. * @return array
  57. */
  58. private function getFilter(array $param = []): array
  59. {
  60. // 默认查询条件
  61. $params = $this->setQueryDefaultValue($param, ['search' => '']);
  62. // 检索查询条件
  63. $filter = [];
  64. !empty($params['search']) && $filter[] = ['express_name', 'like', "%{$params['search']}%"];
  65. return $filter;
  66. }
  67. /**
  68. * 物流公司详情
  69. * @param int $expressId
  70. * @return static|array|null
  71. */
  72. public static function detail(int $expressId)
  73. {
  74. return self::get($expressId);
  75. }
  76. }