CommonController.php
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?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;
}
}