coupon-admin/app/model/Category.php

82 lines
2.0 KiB
PHP
Raw Normal View History

2021-11-18 09:57:04 +00:00
<?php
namespace app\model;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 商家分类
* Class Disease
* @package app\model
*/
class Category extends Base
{
/**
2021-11-29 09:32:48 +00:00
* 根据父级ID 获取列表
2021-11-18 09:57:04 +00:00
*
2021-11-29 09:32:48 +00:00
* @param int $pid
* @param string[] $fields
2021-11-18 09:57:04 +00:00
* @return Disease[]|array|Collection
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getListByPid(int $pid = 0, array $fields = ['pid', 'name', 'id'])
{
return self::where('pid', $pid)->order('id', 'desc')->field($fields)->select();
}
2021-11-29 09:32:48 +00:00
/**
* 获取上下级
* */
public static function getByGroup()
{
$top = self::column(['pid', 'name', 'id'], "id");
foreach ($top as $key => $value) {
if (isset($top[$value["pid"]])) {
$top[$value["pid"]]['children'][] = $value;
unset($top[$key]);
}
}
return $top;
}
2021-11-18 09:57:04 +00:00
/**
2021-11-23 09:13:55 +00:00
* 获取全部列表
2021-11-18 09:57:04 +00:00
*
2021-11-30 10:52:02 +00:00
* @return Collection
2021-11-18 09:57:04 +00:00
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function getList()
{
2021-11-29 09:32:48 +00:00
return self::field('id,pid,name,commision')->order('id', 'desc')->select();
2021-11-18 09:57:04 +00:00
}
/**
* 病种 xmSelect json数据
*
2021-11-29 09:32:48 +00:00
* @param int $pid
* @param array $selected
* @param array $disabled
2021-11-30 10:52:02 +00:00
* @return array|Collection
2021-11-18 09:57:04 +00:00
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public static function diseaseXmJson(int $pid = 0, array $selected = [], array $disabled = [])
{
$list = self::getListByPid($pid);
foreach ($list as $k => $m) {
$list[$k]['selected'] = in_array($m['id'], $selected);
$list[$k]['disabled'] = in_array($m['id'], $disabled);
}
return $list;
}
}