DeliveryServiceDao.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\store;
  12. use app\dao\BaseDao;
  13. use app\model\store\DeliveryService;
  14. /**
  15. * 配送dao
  16. * Class DeliveryServiceDao
  17. * @package app\dao\store
  18. */
  19. class DeliveryServiceDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return DeliveryService::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 getServiceList(array $where, int $page = 0, int $limit = 0)
  40. {
  41. $realName = $where['keyword'] ?? '';
  42. $fieldKey = $where['field_key'] ?? '';
  43. $fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
  44. return $this->search($where)->with('user')->when($page && $limit, function ($query) use ($page, $limit) {
  45. $query->page($page, $limit);
  46. })->when($realName && $fieldKey && in_array($fieldKey, ['id', 'phone']), function ($query) use ($where, $realName, $fieldKey) {
  47. $query->whereLike($fieldKey, '%' . $where['keyword'] . '%');
  48. })->when($realName && !$fieldKey, function ($query) use ($where) {
  49. $query->whereLike('uid|id|nickname|phone', '%' . $where['keyword'] . '%');
  50. })->when(isset($where['noId']), function ($query) use ($where) {
  51. $query->where('id', '<>', $where['noId']);
  52. })->order('id DESC')->field('id,uid,avatar,nickname as wx_name,status,add_time,phone')->select()->toArray();
  53. }
  54. /**
  55. * 获取配送员select
  56. * @param array $where
  57. * @return array
  58. */
  59. public function getSelectList(array $where)
  60. {
  61. return $this->search($where)->field('uid,nickname')->select()->toArray();
  62. }
  63. }