CommonController.php 3.4 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use think\Db;
class CommonController extends HomeBaseController
{
    //七牛云域名
    const domain = 'http://jinglong.springchunjia.cn/';
    //分页数量
    const limit = 10;
    //查找单条数据
    public static function findData($table,$where,$field){
        $res = Db::name($table)
            ->where($where)
            ->field($field)
            ->find();
        return $res;
    }

    //查找多条数据(无排序,无分页,无条件)
    public static function selectNoPositionData($table,$field){
        $res = Db::name($table)
            ->field($field)
            ->select()
            ->toArray();
        return $res;
    }

    //查找多条数据(有限制条数)
    public static function selectLimitData($table,$field,$limit){
        $res = Db::name($table)
            ->field($field)
            ->limit($limit)
            ->select()
            ->toArray();
        return $res;
    }

    //查找多条数据(无排序,无分页)
    public static function selectData($table,$where,$field){
        $res = Db::name($table)
            ->where($where)
            ->field($field)
            ->select()
            ->toArray();
        return $res;
    }

    //查找多条数据(有排序,无分页)
    public static function selectOrderData($table,$where,$field,$order){
        $res = Db::name($table)
            ->where($where)
            ->field($field)
            ->order($order)
            ->select()
            ->toArray();
        return $res;
    }

    //查询产品系列分类(首页)
    public static function getSeriesType($field,$flag){
        $parent_res = self::selectData('type',['pid'=>0],$field);
        $res = self::selectData('type',['pid'=>['<>',0]],$field);
        foreach($parent_res as &$value){
            $k=0;
            $children_name = [];
            foreach ($res as $value1){
                $k+=0;
                if($value['id'] == $value1['pid']){
                    $children_name[$k] = $value1[$flag];
                    $k++;
                }
            }
            $value['children_name'] = implode(',',$children_name);
            unset($value['pid']);
        }
        return $parent_res;
    }

    //查询产品系列分类(正题页)
    public static function findSeriesType($field){
        $parent_res = self::selectData('type',['pid'=>0],$field);
        $res = self::selectData('type',['pid'=>['<>',0]],$field);
        foreach($parent_res as &$value){
            $k=0;
            foreach ($res as $value1){
                $k+=0;
                if($value['id'] == $value1['pid']){
                    $value['children'][$k] = $value1;
                    $k++;
                }
            }
        }
        return $parent_res;
    }
}