| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\common\repositories\delivery;
- use app\common\dao\delivery\DeliveryServiceDao;
- use app\common\repositories\BaseRepository;
- use FormBuilder\Factory\Elm;
- use think\facade\Route;
- /**
- * 配送员
- */
- class DeliveryServiceRepository extends BaseRepository
- {
- public function __construct(DeliveryServiceDao $dao)
- {
- $this->dao = $dao;
- }
- /**
- * 添加 / 编辑 表单
- * @param int|null $id
- * @return void
- * @author Qinii
- */
- public function form(?int $id)
- {
- $formData = [];
- if ($id) {
- $formData = $this->dao->get($id)->toArray();
- }
- $form = Elm::createForm($id ? Route::buildUrl('merchantDeliveryServiceUpdate', ['id' => $id])->build() : Route::buildUrl('merchantDeliveryServiceCreate')->build());
- $form->setRule([
- Elm::frameImage('avatar', '头像:', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=avatar&type=1')
- ->icon('el-icon-camera')->modal(['modal' => false])->width('1000px')->height('600px')->props(['footer' => false])->required(),
- Elm::input('name', '姓名:', $formData['name'] ?? '')->placeholder('请输入姓名')->required(),
- Elm::input('phone', '手机号:', $formData['phone'] ?? '')->placeholder('请输入手机号')->required(),
- Elm::switches('status', '是否开启:', 1)->inactiveValue(0)
- ->activeValue(1)->inactiveText('关')->activeText('开'),
- ]);
- return $form->setTitle($id ? '编辑' : '添加')->formData($formData);
- }
- /**
- * 根据条件获取列表数据
- *
- * 本函数用于根据给定的条件数组$where,从数据库中检索满足条件的数据列表。
- * 它支持分页查询,每页的数据数量由$limit参数指定,查询的页码由$page参数指定。
- *
- * @param array $where 查询条件数组,包含要匹配的数据库字段及其值。
- * @param int $page 查询的页码,用于实现分页查询。
- * @param int $limit 每页显示的数据条数。
- * @return array 返回一个包含两个元素的数组,第一个元素是数据总数$count,第二个元素是当前页的数据列表$list。
- */
- public function getList(array $where, int $page, int $limit)
- {
- // 根据条件构建查询
- $query = $this->dao->getSearch($where)->order('service_id desc,create_time aesc');
- // 计算满足条件的数据总数
- $count = $query->count();
- // 执行分页查询,并获取当前页的数据列表
- $list = $query->page($page, $limit)->select();
- // 将数据总数和数据列表一起返回
- return compact('count', 'list');
- }
- /**
- * 根据条件获取搜索选项
- *
- * 本函数通过调用DAO层的getSearch方法,根据传入的$where条件查询相关数据,
- * 并返回查询结果中特定列的值。这些特定列包括:name(名称)、phone(电话)、service_id(服务ID)。
- * 主要用于在前端展示搜索选项或过滤条件,例如用户服务列表。
- *
- * @param string|array $where 查询条件,可以是字符串或数组形式的SQL WHERE子句。
- * @return array 返回一个包含name、phone和服务ID的列数组。
- */
- public function getOptions($where)
- {
- // 调用DAO层的getSearch方法查询数据,并指定返回的列
- return $this->dao->getSearch($where)->column('name,phone,service_id');
- }
- }
|