// +---------------------------------------------------------------------- namespace app\common\repositories\user; use app\common\dao\user\UserLabelDao; use app\common\repositories\BaseRepository; use app\common\repositories\store\CityAreaRepository; use FormBuilder\Exception\FormBuilderException; use app\controller\admin\store\StoreBrand; use FormBuilder\Factory\Elm; use FormBuilder\Form; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; use think\facade\Route; /** * Class UserLabelRepository * @package app\common\repositories\user * @author xaboy * @day 2020-05-07 * @mixin UserLabelDao */ class UserLabelRepository extends BaseRepository { /** * @var UserLabelDao */ protected $dao; /** * UserGroupRepository constructor. * @param UserLabelDao $dao */ public function __construct(UserLabelDao $dao) { $this->dao = $dao; } /** * @param array $where * @param $page * @param $limit * @return array * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author xaboy * @day 2020-05-07 */ public function getList(array $where, $page, $limit) { $query = $this->dao->search($where); $count = $query->count($this->dao->getPk()); $list = $query->order('label_id DESC')->page($page, $limit)->select(); return compact('count', 'list'); } /** * @param null $id * @param array $formData * @return Form * @throws FormBuilderException * @author xaboy * @day 2020-05-07 */ public function form($id = null, array $formData = []) { $isCreate = is_null($id); $action = Route::buildUrl($isCreate ? 'systemUserLabelCreate' : 'systemUserLabelUpdate', $isCreate ? [] : compact('id'))->build(); return Elm::createForm($action, [ Elm::input('label_name', '用户标签名称')->required() ])->setTitle($isCreate ? '添加用户标签' : '编辑用户标签')->formData($formData); } public function form2($id = null, array $formData = []) { $isCreate = is_null($id); $action = Route::buildUrl($isCreate ? 'systemUserLabelCreate' : 'systemUserLabelUpdate', $isCreate ? [] : compact('id'))->build(); $StoreBrand = new CityAreaRepository(); $where['parent_id'] = 0; $area =$StoreBrand->getList($where); return Elm::createForm($action, [ Elm::input('name', '角色名称')->required(), Elm::input('ratio', '分润比例')->required(), Elm::select('area_id', '区域')->options($area), Elm::switches('status', '是否开启区域限制', 1)->activeValue(1) ->inactiveValue(0)->inactiveText('关')->activeText('开'), Elm::radio('type', '角色代理类型', 1)->options([ ['value' => 1, 'label' => '全部'], ['value' => 2, 'label' => '社区'], ['value' => 3, 'label' => '品牌'], ['value' => 4, 'label' => '行业'], ]), Elm::input('max_role_num', '角色最高设置人数')->required(), Elm::input('brand_id', '品牌')->required(), Elm::input('trade_id', '行业')->required(), ])->setTitle($isCreate ? '添加合作人' : '编辑合作人')->formData($formData); } /** * @param $id * @return Form * @throws FormBuilderException * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author xaboy * @day 2020-05-07 */ public function updateForm($id) { return $this->form($id, $this->dao->get($id)->toArray()); } }