123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- namespace app\model;
- use think\Model;
- class Category extends Model
- {
- protected $connection = 'mysql';
- protected $pk = 'id';
- protected $name = 'category';
- public static function getsonid($id)
- {
- //加空判定
- if (empty($id)) {
- return '';
- }
- $data = self::where(['weid' => weid(), 'pid' => $id])
- ->select()->toArray();
- $returndata = $id;
- if (!empty($data)) {
- foreach ($data as $vo) {
- $returndata = $returndata . "," . $vo['id'];
- }
- }
- return explode(',', $returndata);
- }
- public static function getidssonid($ids)
- {
- if (!empty($ids)) {
- $returndata = '';
- $idsarray = explode(',', $ids);
- foreach ($idsarray as $vo) {
- $sonid = '';
- $sonid = self::getsonid($vo);
- if (empty($returndata)) {
- if (!empty($sonid)) {
- $returndata = implode(',', $sonid);
- }
- } else {
- if (!empty($sonid)) {
- $returndata = $returndata . "," . implode(',', $sonid);
- }
- }
- }
- }
- return $returndata;
- }
- public static function getlist($params = ['status' => ''])
- {
- $where['weid'] = weid();
- $where['pid'] = (int) $params['pid'];
- if (!empty($params['ptype'])) {
- $where['ptype'] = $params['ptype'];
- }
- if ($params['status'] !== '') {
- $where['status'] = $params['status'];
- }
- $data = Category::where($where)
- ->order('sort asc')
- ->select()
- ->toArray();
- return $data;
- }
- public static function getmultiple($ids)
- {
- if (!empty($ids)) {
- $data = self::where(['weid' => weid()])->where('id', 'in', $ids)
- ->select()->toArray();
- if (!empty($data)) {
- foreach ($data as $vo) {
- if (empty($returndata)) {
- $returndata = $vo['title'];
- } else {
- $returndata = $returndata . "," . $vo['title'];
- }
- }
- }
- return $returndata;
- }
- }
- public static function getTreeparray()
- {
- $return = [];
- $data = self::where(['weid' => weid()])
- ->order('sort asc')
- ->select()
- ->toArray();
- $returndata = Tree::title($data, 0);
- if (!empty($returndata)) {
- foreach ($returndata as $vo) {
- $return[$vo['id']] = $vo['title'];
- }
- }
- return $return;
- }
- public static function getparray()
- {
- $data = self::where(['weid' => weid(), 'pid' => 0])
- ->order('sort asc')
- ->select()
- ->toArray();
- $returndata[0] = "顶级分类";
- if (!empty($data)) {
- foreach ($data as $vo) {
- $returndata[$vo['id']] = $vo['title'];
- }
- }
- return $returndata;
- }
- public static function getTitle($id)
- {
- $data = [];
- $data = Category::find($id);
- if (!empty($data)) {
- $data = $data->toArray();
- $returndata = $data['title'];
- if ($data['pid'] > 0) {
- //$returndata = Category::getTitle($data['pid']) . " / " . $returndata;
- }
- }
- return $returndata;
- }
- public static function getImage($id)
- {
- $data = [];
- $data = Category::find($id);
- if (!empty($data)) {
- $data = $data->toArray();
- return toimg($data['image']);
- }
- }
- function getdatalist()
- {
- $ptypeArray = $this->where(['weid' => weid()])
- ->orderBy('sort asc')
- ->select()
- ->toArray();
- $arr = Tree::title($ptypeArray, 0);
- return $arr;
- }
- public static function getcatapiall($pid = 0, $ptype = '')
- {
- $where['weid'] = weid();
- $where['pid'] = $pid;
- $where['status'] = 1;
- if (!empty($ptype)) {
- $where['ptype'] = $ptype;
- }
- $data = self::where($where)
- ->order('sort asc')
- ->select()
- ->toArray();
- if (!empty($data)) {
- foreach ($data as &$vo) {
- if ($son = self::getcatapiall($vo['id'])) {
- $vo['son'] = $son;
- } else {
- $vo['son'] = [];
- }
- $vo['icon'] = toimg($vo['image']);
- }
- }
- return $data;
- }
- public static function getpcarray($ptype = '')
- {
- $where['weid'] = weid();
- $where['status'] = 1;
- if (!empty($ptype)) {
- $where['ptype'] = $ptype;
- }
- $list = self::field('id,title,pid')->where($where)
- ->order('sort asc')
- ->select()
- ->toArray();
- $array = [];
- foreach ($list as $k => $v) {
- $array[$k]['val'] = $v['id'];
- $array[$k]['key'] = $v['title'];
- $array[$k]['pid'] = $v['pid'];
- }
- return $array;
- }
- public static function gettoparray($ptype = '')
- {
- $where['pid'] = 0;
- $where['weid'] = weid();
- $where['status'] = 1;
- if (!empty($ptype)) {
- $where['ptype'] = $ptype;
- }
- $list = self::field('id,title,pid')
- ->where($where)
- ->order('sort asc')
- ->select()
- ->toArray();
- $array = [];
- foreach ($list as $k => $v) {
- $array[$k]['val'] = $v['id'];
- $array[$k]['key'] = $v['title'];
- $array[$k]['pid'] = $v['pid'];
- }
- return $array;
- }
- }
|