ExpressDao.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\shipping;
  12. use app\dao\BaseDao;
  13. use app\model\other\Express;
  14. /**
  15. * 物流信息
  16. * Class ExpressDao
  17. * @package app\dao\other
  18. */
  19. class ExpressDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return Express::class;
  28. }
  29. /**
  30. * 获取物流列表
  31. * @param array $where
  32. * @param int $page
  33. * @param int $limit
  34. * @return array
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function getExpressList(array $where, string $field, int $page, int $limit)
  40. {
  41. return $this->search($where)->field($field)->order('sort DESC,is_show DESC,id ASC')
  42. ->when($page > 0 && $limit > 0, function ($query) use ($page, $limit) {
  43. $query->page($page, $limit);
  44. })->select()->toArray();
  45. }
  46. /**
  47. * 指定的条件获取物流信息以数组返回
  48. * @param array $where
  49. * @param string $field
  50. * @param string $key
  51. * @return array
  52. */
  53. public function getExpress(array $where, string $field, string $key)
  54. {
  55. return $this->search($where)->order('id DESC')->column($field, $key);
  56. }
  57. /**
  58. * 通过code获取一条信息
  59. * @param string $code
  60. * @param string $field
  61. * @return array|\think\Model|null
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. */
  66. public function getExpressByCode(string $code, string $field = '*')
  67. {
  68. return $this->getModel()->field($field)->where('code', $code)->find();
  69. }
  70. }