DeliveryServiceRepository.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\delivery;
  12. use app\common\dao\delivery\DeliveryServiceDao;
  13. use app\common\repositories\BaseRepository;
  14. use FormBuilder\Factory\Elm;
  15. use think\facade\Route;
  16. /**
  17. * 配送员
  18. */
  19. class DeliveryServiceRepository extends BaseRepository
  20. {
  21. public function __construct(DeliveryServiceDao $dao)
  22. {
  23. $this->dao = $dao;
  24. }
  25. /**
  26. * 添加 / 编辑 表单
  27. * @param int|null $id
  28. * @return void
  29. * @author Qinii
  30. */
  31. public function form(?int $id)
  32. {
  33. $formData = [];
  34. if ($id) {
  35. $formData = $this->dao->get($id)->toArray();
  36. }
  37. $form = Elm::createForm($id ? Route::buildUrl('merchantDeliveryServiceUpdate', ['id' => $id])->build() : Route::buildUrl('merchantDeliveryServiceCreate')->build());
  38. $form->setRule([
  39. Elm::frameImage('avatar', '头像:', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=avatar&type=1')
  40. ->icon('el-icon-camera')->modal(['modal' => false])->width('1000px')->height('600px')->props(['footer' => false])->required(),
  41. Elm::input('name', '姓名:', $formData['name'] ?? '')->placeholder('请输入姓名')->required(),
  42. Elm::input('phone', '手机号:', $formData['phone'] ?? '')->placeholder('请输入手机号')->required(),
  43. Elm::switches('status', '是否开启:', 1)->inactiveValue(0)
  44. ->activeValue(1)->inactiveText('关')->activeText('开'),
  45. ]);
  46. return $form->setTitle($id ? '编辑' : '添加')->formData($formData);
  47. }
  48. /**
  49. * 根据条件获取列表数据
  50. *
  51. * 本函数用于根据给定的条件数组$where,从数据库中检索满足条件的数据列表。
  52. * 它支持分页查询,每页的数据数量由$limit参数指定,查询的页码由$page参数指定。
  53. *
  54. * @param array $where 查询条件数组,包含要匹配的数据库字段及其值。
  55. * @param int $page 查询的页码,用于实现分页查询。
  56. * @param int $limit 每页显示的数据条数。
  57. * @return array 返回一个包含两个元素的数组,第一个元素是数据总数$count,第二个元素是当前页的数据列表$list。
  58. */
  59. public function getList(array $where, int $page, int $limit)
  60. {
  61. // 根据条件构建查询
  62. $query = $this->dao->getSearch($where)->order('service_id desc,create_time aesc');
  63. // 计算满足条件的数据总数
  64. $count = $query->count();
  65. // 执行分页查询,并获取当前页的数据列表
  66. $list = $query->page($page, $limit)->select();
  67. // 将数据总数和数据列表一起返回
  68. return compact('count', 'list');
  69. }
  70. /**
  71. * 根据条件获取搜索选项
  72. *
  73. * 本函数通过调用DAO层的getSearch方法,根据传入的$where条件查询相关数据,
  74. * 并返回查询结果中特定列的值。这些特定列包括:name(名称)、phone(电话)、service_id(服务ID)。
  75. * 主要用于在前端展示搜索选项或过滤条件,例如用户服务列表。
  76. *
  77. * @param string|array $where 查询条件,可以是字符串或数组形式的SQL WHERE子句。
  78. * @return array 返回一个包含name、phone和服务ID的列数组。
  79. */
  80. public function getOptions($where)
  81. {
  82. // 调用DAO层的getSearch方法查询数据,并指定返回的列
  83. return $this->dao->getSearch($where)->column('name,phone,service_id');
  84. }
  85. }