init
This commit is contained in:
12
app/common/model/Ad.php
Executable file
12
app/common/model/Ad.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Ad extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
}
|
||||
60
app/common/model/Agents.php
Executable file
60
app/common/model/Agents.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Agents extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getAgentList($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getAgentLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
60
app/common/model/Article.php
Executable file
60
app/common/model/Article.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Article extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getCateArticleList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('article_category c', 'a.cid=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getCateArticleLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('article_category c', 'a.cid=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
196
app/common/model/ArticleCategory.php
Executable file
196
app/common/model/ArticleCategory.php
Executable file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ArticleCategory extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getCategoryLists($where = null, $order = null, $field = null, $limit = 20, $level = 0, array &$alldata = array()) {
|
||||
if ($level > 5) {
|
||||
return;
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
$limit = $limit? : 12;
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
$row['level'] = $level;
|
||||
$alldata[] = $row;
|
||||
$where['pid'] = $row['id'];
|
||||
//self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
!$row['haschild'] ? '' : self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
}
|
||||
}
|
||||
return $alldata;
|
||||
}
|
||||
|
||||
public function getChildIDArray($id) {
|
||||
$list = $this->where(['pid' => $id, 'stat' => 0])->field(['id', 'haschild'])->select();
|
||||
$childIDArray = array((int) $id);
|
||||
if ($list) {
|
||||
foreach ($list as $val) {
|
||||
$childArray = $val['haschild'] ? self::getChildIDArray($val['id']) : array((int) $val['id']);
|
||||
$childIDArray = array_merge($childIDArray, $childArray);
|
||||
}
|
||||
}
|
||||
return $childIDArray;
|
||||
}
|
||||
|
||||
public function getTopParentID($id, $where = null) {
|
||||
$data = $this::get(function($query)use($id, $where) {
|
||||
$query->where(['id' => $id]);
|
||||
if ($where) {
|
||||
$query->where($where);
|
||||
}
|
||||
$query->field(['id', 'pid']);
|
||||
});
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
$topid = self::getTopParentID($data['pid'], $where);
|
||||
} else {
|
||||
$topid = $id;
|
||||
}
|
||||
return $topid;
|
||||
}
|
||||
|
||||
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
|
||||
if (!$id) {
|
||||
return array();
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
$data = $this->field(['id', 'name', 'pid'])->get($id);
|
||||
$catarr[] = $data;
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
self::getBreadCrumb($data['pid'], $where, $catarr);
|
||||
} else {
|
||||
return array_reverse($catarr);
|
||||
}
|
||||
return $catarr;
|
||||
}
|
||||
|
||||
public function getCategoryOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
|
||||
$options = '';
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getCategoryOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
|
||||
$options = '';
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
$where['pid'] = $row['id'];
|
||||
//$options.=self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
$options.=!$row['haschild'] ? '' : self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getCategoryTree($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
$result = array();
|
||||
if ($level > 5) {
|
||||
return $result;
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select(); // 获取
|
||||
if ($list) {
|
||||
foreach ($list as $row) {
|
||||
$row['level'] = $level;
|
||||
$where['pid'] = $row['id'];
|
||||
//$row['child'] = self::getCategoryTree($where, $order, $field, $limit, $level + 1);
|
||||
$row['child'] = !$row['haschild'] ? array() : self::getCategoryTree($where, $order, $field, $limit, $level + 1);
|
||||
$result[] = $row;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
110
app/common/model/ArticleComment.php
Executable file
110
app/common/model/ArticleComment.php
Executable file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ArticleComment extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
|
||||
public function getPageList($where = null, $order = null, $field = null, $limit = null, $selfpaginate = true) {
|
||||
$this->alias('a')->join('article as c', 'a.article_id=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['c.stat' => ['in', '0,1']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
$object = $this->paginate($limit);
|
||||
return $object;
|
||||
|
||||
}
|
||||
|
||||
public function getList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('article as c', 'a.article_id=c.id', 'LEFT');
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['c.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
//$this->fetchsql(true);
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getOneRow($where, $field = null, $order = null, $stat = true) {
|
||||
$object = $this::get(function($query)use($where, $field, $order, $stat) {
|
||||
if ($stat) {
|
||||
$query->where(['stat' => ['eq', '1']]);
|
||||
}
|
||||
$query->where('id', $where);
|
||||
if ($field) {
|
||||
$query->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$query->order($order);
|
||||
}
|
||||
//$query->fetchsql(true);
|
||||
});
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getRow($where = null, $field = null, $order = null, $fetchsql = false) {
|
||||
$object = $this::get(function($query)use($where, $field, $order, $fetchsql) {
|
||||
if (is_numeric($where)) {
|
||||
$query->where(['stat' => ['eq', '1']])->where('id', $where);
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '1']], $where);
|
||||
$query->where($where);
|
||||
}
|
||||
if ($field) {
|
||||
$query->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$query->order($order);
|
||||
}
|
||||
//$fetchsql ? $query->fetchsql(true) : '';
|
||||
});
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function updateRow($data = [], $where = [], $field = null) {
|
||||
$object = $this::update($data, $where, $field);
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function updateRows($data = [], $where = []) {
|
||||
if (!empty($where)) {
|
||||
$result = $this->save($data, function($query)use($where) {
|
||||
$query->where($where);
|
||||
});
|
||||
}
|
||||
return isset($result) ? $result : false;
|
||||
}
|
||||
|
||||
}
|
||||
60
app/common/model/Ask.php
Executable file
60
app/common/model/Ask.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Ask extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getAskList($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getInquiryLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
125
app/common/model/Banner.php
Executable file
125
app/common/model/Banner.php
Executable file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Config;
|
||||
|
||||
class Banner extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getBannerList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('b')->join('banner_type bt', 'b.typeid=bt.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['b.stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getBannerLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('b')->join('banner_type bt', 'b.typeid=bt.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['b.stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
//$this->fetchsql(true);
|
||||
$object = $this->paginate($limit);
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getList($where = null, $order = null, $field = null, $limit = null) {
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
$object = $this->paginate($limit);
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getOneBanner($id, $field = null) {
|
||||
$object = $this::get(function($query)use($id, $field) {
|
||||
$query->where(['id' => $id, 'stat' => 0]);
|
||||
if ($field) {
|
||||
$query->field($field);
|
||||
}
|
||||
});
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getBanner($where = null, $field = null, $order = null) {
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => 0], $where);
|
||||
}
|
||||
$object = $this::get(function($query)use($where, $field, $order) {
|
||||
if ($where) {
|
||||
$query->where($where);
|
||||
}
|
||||
if ($field) {
|
||||
$query->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$query->order($order);
|
||||
}
|
||||
});
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function updateBanner($data = [], $where = [], $field = null) {
|
||||
$object = $this::update($data, $where, $field);
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
112
app/common/model/Blog.php
Executable file
112
app/common/model/Blog.php
Executable file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Blog extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
|
||||
public function getBlogLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
//echo "<pre>++"; print_r($where); die;
|
||||
//$this->alias('a')->join('blog_remark', 'a.b_id=blog_remark.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '1']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
//header("content-type:text/html;charset=utf8;");
|
||||
//print_r($object);
|
||||
//exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getRemarkList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('blog_remark', 'a.id=blog_remark.b_id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['blog_remark.stat' => ['eq', '1']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
|
||||
return $object;
|
||||
|
||||
}
|
||||
|
||||
public function getBlogDetail($id){
|
||||
|
||||
}
|
||||
|
||||
public function getOneRow($where, $field = null, $order = null, $stat = true) {
|
||||
$object = $this::get(function($query)use($where, $field, $order, $stat) {
|
||||
if ($stat) {
|
||||
$query->where(['stat' => ['eq', '1']]);
|
||||
}
|
||||
$query->where('id', $where);
|
||||
if ($field) {
|
||||
$query->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$query->order($order);
|
||||
}
|
||||
//$query->fetchsql(true);
|
||||
});
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getRow($where = null, $field = null, $order = null, $fetchsql = false) {
|
||||
$object = $this::get(function($query)use($where, $field, $order, $fetchsql) {
|
||||
if (is_numeric($where)) {
|
||||
$query->where(['stat' => ['eq', '1']])->where('id', $where);
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '1']], $where);
|
||||
$query->where($where);
|
||||
}
|
||||
if ($field) {
|
||||
$query->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$query->order($order);
|
||||
}
|
||||
//$fetchsql ? $query->fetchsql(true) : '';
|
||||
});
|
||||
return $object;
|
||||
}
|
||||
|
||||
/*public function updateRow($data = [], $where = [], $field = null) {
|
||||
$object = $this::update($data, $where, $field);
|
||||
return $object;
|
||||
}*/
|
||||
|
||||
}
|
||||
110
app/common/model/BlogRemark.php
Executable file
110
app/common/model/BlogRemark.php
Executable file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class BlogRemark extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
|
||||
public function getPageList($where = null, $order = null, $field = null, $limit = null, $selfpaginate = true) {
|
||||
$this->alias('a')->join('blog_remark', 'a.b_id=blog_remark.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['blog_remark.stat' => ['in', '0,1']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
$object = $this->paginate($limit);
|
||||
return $object;
|
||||
|
||||
}
|
||||
|
||||
public function getList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('blog_remark', 'a.b_id=blog_remark.id', 'LEFT');
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
//$this->fetchsql(true);
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getOneRow($where, $field = null, $order = null, $stat = true) {
|
||||
$object = $this::get(function($query)use($where, $field, $order, $stat) {
|
||||
if ($stat) {
|
||||
$query->where(['stat' => ['eq', '1']]);
|
||||
}
|
||||
$query->where('id', $where);
|
||||
if ($field) {
|
||||
$query->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$query->order($order);
|
||||
}
|
||||
//$query->fetchsql(true);
|
||||
});
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getRow($where = null, $field = null, $order = null, $fetchsql = false) {
|
||||
$object = $this::get(function($query)use($where, $field, $order, $fetchsql) {
|
||||
if (is_numeric($where)) {
|
||||
$query->where(['stat' => ['eq', '1']])->where('id', $where);
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '1']], $where);
|
||||
$query->where($where);
|
||||
}
|
||||
if ($field) {
|
||||
$query->field($field);
|
||||
}
|
||||
if ($order) {
|
||||
$query->order($order);
|
||||
}
|
||||
//$fetchsql ? $query->fetchsql(true) : '';
|
||||
});
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function updateRow($data = [], $where = [], $field = null) {
|
||||
$object = $this::update($data, $where, $field);
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function updateRows($data = [], $where = []) {
|
||||
if (!empty($where)) {
|
||||
$result = $this->save($data, function($query)use($where) {
|
||||
$query->where($where);
|
||||
});
|
||||
}
|
||||
return isset($result) ? $result : false;
|
||||
}
|
||||
|
||||
}
|
||||
60
app/common/model/Bulk.php
Executable file
60
app/common/model/Bulk.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Bulk extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getBulkList($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getInquiryLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
60
app/common/model/BulkInquiry.php
Executable file
60
app/common/model/BulkInquiry.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class BulkInquiry extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getBulkInquiryList($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getBulkInquiryLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
33
app/common/model/ClickSum.php
Executable file
33
app/common/model/ClickSum.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ClickSum extends Model {
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getList($where = null, $order = null, $field = null, $limit = null) {
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
|
||||
$result = $this->select();
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
32
app/common/model/Collection.php
Executable file
32
app/common/model/Collection.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Collection extends Model {
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('product b', 'a.coll_id=b.id', 'LEFT');
|
||||
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
|
||||
$result = $this->paginate($limit);
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
17
app/common/model/Country.php
Executable file
17
app/common/model/Country.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ORICO
|
||||
* Date: 2018-12-25
|
||||
* Time: 17:13
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Country extends Model
|
||||
{
|
||||
|
||||
}
|
||||
107
app/common/model/Customer.php
Executable file
107
app/common/model/Customer.php
Executable file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
use think\Session;
|
||||
|
||||
class Customer extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
/**
|
||||
* 更新用户密码
|
||||
*/
|
||||
public function updatePassword($data) {
|
||||
//$salt = getstr_random();
|
||||
$row = array(
|
||||
'id' => $data['id'],
|
||||
'password' => md5($data['password']),
|
||||
'salt' => $data['password'],
|
||||
);
|
||||
$object = $this::update($row);
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录认证
|
||||
* @param string $condition 验证条件如用户名邮箱手机号ID
|
||||
* @param string $password 用户密码
|
||||
* @param integer $type 用户名类型 (1-用户名,2-邮箱,3-手机,4-UID)
|
||||
* @return integer 登录成功-用户ID,登录失败-错误编号
|
||||
*/
|
||||
public function login($condition, $password, $type = 1) {
|
||||
$where = [];
|
||||
switch ($type) {
|
||||
case 1:$where['firstname'] = $condition;
|
||||
break;
|
||||
case 2:$where['email'] = $condition;
|
||||
break;
|
||||
case 3:$where['mobile'] = $condition;
|
||||
break;
|
||||
case 4:$where['id'] = $condition;
|
||||
break;
|
||||
default:
|
||||
return ['status' => false, 'msg' => '参数错误', 'id' => 0]; //参数错误
|
||||
}
|
||||
/* 获取用户数据 */
|
||||
$row = $this->where($where)->field('id,firstname,lastname,password,salt,login,picture,telephone,email,safe,stat')->find();
|
||||
if (empty($row) || (int) $row->stat !== 0) {
|
||||
return ['status' => false, 'msg' => '用户不存在或被禁用', 'id' => 0];
|
||||
}
|
||||
if (!$row->safe) {
|
||||
return ['status' => false, 'msg' => '请联系管理员激活您的账户', 'id' => 0];
|
||||
}
|
||||
/* 验证用户密码 */
|
||||
if (md5($password) !== $row->password) {
|
||||
return ['status' => false, 'msg' => '密码错误', 'id' => 0];
|
||||
}
|
||||
unset($row->password);
|
||||
unset($row->salt);
|
||||
/* 登录用户 */
|
||||
$this->autoLogin($row->toArray());
|
||||
return ['status' => true, 'msg' => '登录成功', 'id' => $row->id]; //登录成功,返回用户ID
|
||||
}
|
||||
|
||||
public function getBasicInfo($id) {
|
||||
return $this->where(['stat' => 0])->field('id, firstname, picture, sex, email, telephone, qq, birthday, password')->find($id);
|
||||
}
|
||||
|
||||
public function getBasicInfoByTelephone($telephone) {
|
||||
return $this->where(['telephone' => $telephone, 'stat' => 0])->field('id, firstname, picture, sex, email, telephone, qq, birthday, password')->find();
|
||||
}
|
||||
|
||||
public function getBasicInfoByEmail($email) {
|
||||
return $this->where(['email' => $email, 'stat' => 0])->field('id, firstname, picture, email, sex, telephone, qq, birthday, password')->find();
|
||||
}
|
||||
|
||||
private function autoLogin($row) {
|
||||
/* 更新登录信息 */
|
||||
$data = [
|
||||
'id' => $row['id'],
|
||||
'login' => \think\Db::raw('`login`+1'),
|
||||
//'last_login_time' => Request::instance()->time(),
|
||||
'ip' => Request::instance()->ip()
|
||||
];
|
||||
$this::update($data);
|
||||
/* 记录登录SESSION和COOKIES */
|
||||
Session::set('customer_auth', $row);
|
||||
Session::set('customer_auth_sign', data_auth_sign($row));
|
||||
unset($row);
|
||||
}
|
||||
|
||||
public function insertRow($data) {
|
||||
$object = $this::create($data);
|
||||
return $object;
|
||||
}
|
||||
|
||||
protected function setIpAttr($value) {
|
||||
if (empty($value)) {
|
||||
return Request::instance()->ip();
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
60
app/common/model/Download.php
Executable file
60
app/common/model/Download.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Download extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getCateDownloadList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('download_category c', 'a.cid=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getCateDownloadLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('download_category c', 'a.cid=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
//$this->fetchsql(true);
|
||||
$object = $this->paginate($limit);
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
196
app/common/model/DownloadCategory.php
Executable file
196
app/common/model/DownloadCategory.php
Executable file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class DownloadCategory extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getCategoryLists($where = null, $order = null, $field = null, $limit = 20, $level = 0, array &$alldata = array()) {
|
||||
if ($level > 5) {
|
||||
return;
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
$limit = $limit? : 12;
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
$row['level'] = $level;
|
||||
$alldata[] = $row;
|
||||
$where['pid'] = $row['id'];
|
||||
//self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
!$row['haschild'] ? '' : self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
}
|
||||
}
|
||||
return $alldata;
|
||||
}
|
||||
|
||||
public function getChildIDArray($id) {
|
||||
$list = $this->where(['pid' => $id, 'stat' => 0])->field(['id', 'haschild'])->select();
|
||||
$childIDArray = array((int) $id);
|
||||
if ($list) {
|
||||
foreach ($list as $val) {
|
||||
$childArray = $val['haschild'] ? self::getChildIDArray($val['id']) : array((int) $val['id']);
|
||||
$childIDArray = array_merge($childIDArray, $childArray);
|
||||
}
|
||||
}
|
||||
return $childIDArray;
|
||||
}
|
||||
|
||||
public function getTopParentID($id, $where = null) {
|
||||
$data = $this::get(function($query)use($id, $where) {
|
||||
$query->where(['id' => $id]);
|
||||
if ($where) {
|
||||
$query->where($where);
|
||||
}
|
||||
$query->field(['id', 'pid']);
|
||||
});
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
$topid = self::getTopParentID($data['pid'], $where);
|
||||
} else {
|
||||
$topid = $id;
|
||||
}
|
||||
return $topid;
|
||||
}
|
||||
|
||||
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
|
||||
if (!$id) {
|
||||
return array();
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
$data = $this->field(['id', 'name', 'pid'])->get($id);
|
||||
$catarr[] = $data;
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
self::getBreadCrumb($data['pid'], $where, $catarr);
|
||||
} else {
|
||||
return array_reverse($catarr);
|
||||
}
|
||||
return $catarr;
|
||||
}
|
||||
|
||||
public function getCategoryOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
|
||||
$options = '';
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getCategoryOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
|
||||
$options = '';
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
$where['pid'] = $row['id'];
|
||||
//$options.=self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
$options.=!$row['haschild'] ? '' : self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getCategoryTree($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
$result = array();
|
||||
if ($level > 5) {
|
||||
return $result;
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select(); // 获取
|
||||
if ($list) {
|
||||
foreach ($list as $row) {
|
||||
$row['level'] = $level;
|
||||
$where['pid'] = $row['id'];
|
||||
//$row['child'] = self::getCategoryTree($where, $order, $field, $limit, $level + 1);
|
||||
$row['child'] = !$row['haschild'] ? array() : self::getCategoryTree($where, $order, $field, $limit, $level + 1);
|
||||
$result[] = $row;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
53
app/common/model/Email.php
Executable file
53
app/common/model/Email.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: kingliang
|
||||
* Date: 2020-10-21
|
||||
* Time: 15:09
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use app\common\traits\IndexModel;
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Email extends Model
|
||||
{
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
protected $insert = ['state' => 0, 'ip', 'createtime'];
|
||||
|
||||
public function insertRow($data) {
|
||||
$object = $this::create($data);
|
||||
return $object;
|
||||
}
|
||||
public function chickEmail($email) {
|
||||
$list = $this->where(['email' => $email, 'state' => 0])->select();
|
||||
if (!$list) {
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 属性修改器 创建时间
|
||||
protected function setCreatetimeAttr($value, $data) {
|
||||
if (empty($value)) {
|
||||
return time();
|
||||
} else {
|
||||
return strtotime($value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setContentAttr($value) {
|
||||
return htmlspecialchars($value);
|
||||
}
|
||||
|
||||
protected function setIpAttr() {
|
||||
return Request::instance()->ip();
|
||||
}
|
||||
}
|
||||
59
app/common/model/Flink.php
Executable file
59
app/common/model/Flink.php
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Flink extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getFlinkList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('f')->join('flink_type ft', 'f.typeid=ft.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['f.stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getFlinkLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('f')->join('flink_type ft', 'f.typeid=ft.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['f.stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
//$this->fetchsql(true);
|
||||
$object = $this->paginate($limit);
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
53
app/common/model/Fq.php
Executable file
53
app/common/model/Fq.php
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Fq extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getList($where = null, $order = null, $field = null, $limit = null) {
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 10;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
60
app/common/model/Inquiry.php
Executable file
60
app/common/model/Inquiry.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Inquiry extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getInquiryList($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getInquiryLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
|
||||
$object = $this->paginate($limit);
|
||||
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
36
app/common/model/Job.php
Executable file
36
app/common/model/Job.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\model;
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
|
||||
class Job extends Model {
|
||||
|
||||
use \app\common\traits\AdminModel;
|
||||
|
||||
|
||||
public function getJobLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
//$this->fetchsql(true);
|
||||
$object = $this->paginate($limit);
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
38
app/common/model/Msgform.php
Executable file
38
app/common/model/Msgform.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Msgform extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
protected $auto = ['content'];
|
||||
protected $insert = ['stat' => 0, 'display' => 0, 'ip', 'createtime'];
|
||||
|
||||
public function insertRow($data) {
|
||||
$object = $this::create($data);
|
||||
return $object;
|
||||
}
|
||||
|
||||
// 属性修改器 创建时间
|
||||
protected function setCreatetimeAttr($value, $data) {
|
||||
if (empty($value)) {
|
||||
return time();
|
||||
} else {
|
||||
return strtotime($value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setContentAttr($value) {
|
||||
return htmlspecialchars($value);
|
||||
}
|
||||
|
||||
protected function setIpAttr() {
|
||||
return Request::instance()->ip();
|
||||
}
|
||||
|
||||
}
|
||||
73
app/common/model/Navigation.php
Executable file
73
app/common/model/Navigation.php
Executable file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Navigation extends Model {
|
||||
|
||||
use \app\common\traits\AdminModel;
|
||||
|
||||
protected $insert = ['createtime'];
|
||||
protected $update = ['updatetime'];
|
||||
|
||||
public function getNavigationList($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['in', '0,1']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getNavigationLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['in', '0,1']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
//$this->fetchsql(true);
|
||||
$object = $this->paginate($limit);
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
// 属性修改器 创建时间
|
||||
protected function setCreatetimeAttr($value, $data) {
|
||||
if (empty($value)) {
|
||||
return time();
|
||||
} else {
|
||||
return strtotime($value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
49
app/common/model/Pinglun.php
Executable file
49
app/common/model/Pinglun.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Pinglun extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
protected $auto = ['content'];
|
||||
protected $insert = ['stat' => 0, 'display' => 0, 'ip'];
|
||||
|
||||
public function insertRow($data) {
|
||||
$object = $this::create($data);
|
||||
return $object;
|
||||
}
|
||||
|
||||
protected function setContentAttr($value) {
|
||||
return htmlspecialchars($value);
|
||||
}
|
||||
|
||||
protected function setIpAttr() {
|
||||
return Request::instance()->ip();
|
||||
}
|
||||
|
||||
public function getCommentList($where = null, $order = null, $field = null, $limit = null) {
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
$object = $this->paginate($limit);
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
155
app/common/model/Product.php
Executable file
155
app/common/model/Product.php
Executable file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
|
||||
class Product extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getCateProductList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['p.stat' => ['eq', '0'],'p.is_show' =>'0'], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getCateProductLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['p.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
$object = $this->paginate($limit);
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function getRelatedProductList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('p')->join('product_related pr', 'p.id=pr.related_product_id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['p.stat' => ['eq', '0'], 'pr.stat' => ['eq', '0'], 'pr.product_id' => '0'], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
public function productImg()
|
||||
{
|
||||
return $this->hasMany('ProductBkImg', 'product_id', 'id');
|
||||
}
|
||||
public function productTwoImg(){
|
||||
return $this->hasMany('ProductTwoImg','product_id','id');
|
||||
}
|
||||
|
||||
public function productCategory()
|
||||
{
|
||||
return $this->belongsTo('ProductCategory', "id", 'cid');
|
||||
}
|
||||
|
||||
/******获取新品数据******/
|
||||
public function getNewProductLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'INNER')->join('product_category t', 'c.pid=t.id', 'INNER');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['p.stat' => ['eq', '0'],'p.isnew' => ['eq', '1'],'p.is_show' => ['eq', '0'],'t.isshow' => ['eq', '1'],'p.country_code' => ['eq', 'US']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
/******获取新品数据******/
|
||||
public function getCnNewProductLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'INNER')->join('product_category t', 'c.pid=t.id', 'INNER');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['p.stat' => ['eq', '0'],'p.isnew' => ['eq', '1'],'p.is_show' => ['eq', '0'],'t.isshow' => ['eq', '1'],'p.country_code' => ['eq', 'ZH']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getNewItemLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('p')->join('product_category c', 'p.cid=c.id', 'INNER')->join('product_category t', 'c.pid=t.id', 'INNER');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['p.stat' => ['eq', '0'],'p.isnew' => ['eq', '1'],'p.is_show' => ['eq', '0'],'t.isshow' => ['eq', '1'],'p.country_code' => ['eq', 'ZH']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
20
app/common/model/ProductBkImg.php
Executable file
20
app/common/model/ProductBkImg.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ORICO
|
||||
* Date: 2018-10-22
|
||||
* Time: 11:42
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
|
||||
class ProductBkImg extends Model {
|
||||
|
||||
use \app\common\traits\AdminModel;
|
||||
|
||||
|
||||
}
|
||||
196
app/common/model/ProductCategory.php
Executable file
196
app/common/model/ProductCategory.php
Executable file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ProductCategory extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getCategoryLists($where = null, $order = null, $field = null, $limit = 20, $level = 0, array &$alldata = array()) {
|
||||
if ($level > 5) {
|
||||
return;
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
$limit = $limit? : 12;
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
$row['level'] = $level;
|
||||
$alldata[] = $row;
|
||||
$where['pid'] = $row['id'];
|
||||
//self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
!$row['haschild'] ? '' : self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
}
|
||||
}
|
||||
return $alldata;
|
||||
}
|
||||
|
||||
public function getChildIDArray($id) {
|
||||
$list = $this->where(['pid' => $id, 'stat' => 0])->field(['id', 'haschild'])->select();
|
||||
$childIDArray = array((int) $id);
|
||||
if ($list) {
|
||||
foreach ($list as $val) {
|
||||
$childArray = $val['haschild'] ? self::getChildIDArray($val['id']) : array((int) $val['id']);
|
||||
$childIDArray = array_merge($childIDArray, $childArray);
|
||||
}
|
||||
}
|
||||
return $childIDArray;
|
||||
}
|
||||
|
||||
public function getTopParentID($id, $where = null) {
|
||||
$data = $this::get(function($query)use($id, $where) {
|
||||
$query->where(['id' => $id]);
|
||||
if ($where) {
|
||||
$query->where($where);
|
||||
}
|
||||
$query->field(['id', 'pid']);
|
||||
});
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
$topid = self::getTopParentID($data['pid'], $where);
|
||||
} else {
|
||||
$topid = $id;
|
||||
}
|
||||
return $topid;
|
||||
}
|
||||
|
||||
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
|
||||
if (!$id) {
|
||||
return array();
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
$data = $this->field(['id', 'name', 'pid'])->get($id);
|
||||
$catarr[] = $data;
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
self::getBreadCrumb($data['pid'], $where, $catarr);
|
||||
} else {
|
||||
return array_reverse($catarr);
|
||||
}
|
||||
return $catarr;
|
||||
}
|
||||
|
||||
public function getCategoryOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
|
||||
$options = '';
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getCategoryOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
|
||||
$options = '';
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
$where['pid'] = $row['id'];
|
||||
//$options.=self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
$options.=!$row['haschild'] ? '' : self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getCategoryTree($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
$result = array();
|
||||
if ($level > 5) {
|
||||
return $result;
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select(); // 获取
|
||||
if ($list) {
|
||||
foreach ($list as $row) {
|
||||
$row['level'] = $level;
|
||||
$where['pid'] = $row['id'];
|
||||
//$row['child'] = self::getCategoryTree($where, $order, $field, $limit, $level + 1);
|
||||
$row['child'] = !$row['haschild'] ? array() : self::getCategoryTree($where, $order, $field, $limit, $level + 1);
|
||||
$result[] = $row;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
12
app/common/model/ProductDl.php
Executable file
12
app/common/model/ProductDl.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ProductDl extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
}
|
||||
12
app/common/model/ProductImage.php
Executable file
12
app/common/model/ProductImage.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ProductImage extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
}
|
||||
8
app/common/model/ProductSeries.php
Executable file
8
app/common/model/ProductSeries.php
Executable file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
|
||||
class ProductSeries extends Model
|
||||
{
|
||||
|
||||
}
|
||||
17
app/common/model/ProductSku.php
Executable file
17
app/common/model/ProductSku.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ORICO
|
||||
* Date: 2019-07-26
|
||||
* Time: 14:24
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ProductSku extends Model
|
||||
{
|
||||
use \app\common\traits\IndexModel;
|
||||
}
|
||||
17
app/common/model/ProductSpecial.php
Executable file
17
app/common/model/ProductSpecial.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ORICO
|
||||
* Date: 2018-12-25
|
||||
* Time: 17:13
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ProductSpecial extends Model
|
||||
{
|
||||
|
||||
}
|
||||
18
app/common/model/ProductTwoImg.php
Executable file
18
app/common/model/ProductTwoImg.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ORICO
|
||||
* Date: 2018-10-22
|
||||
* Time: 10:37
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class ProductTwoImg extends Model {
|
||||
|
||||
use \app\common\traits\AdminModel;
|
||||
|
||||
}
|
||||
12
app/common/model/Question.php
Executable file
12
app/common/model/Question.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Question extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
}
|
||||
29
app/common/model/QuestionCategory.php
Executable file
29
app/common/model/QuestionCategory.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class QuestionCategory extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getList($where = null, $order = null, $field = null, $limit = null) {
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
29
app/common/model/Report.php
Executable file
29
app/common/model/Report.php
Executable file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Report extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getList($where = null, $order = null, $field = null, $limit = null) {
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->paginate($limit);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
155
app/common/model/Singlepage.php
Executable file
155
app/common/model/Singlepage.php
Executable file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Singlepage extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getSinglepageLists($where = null, $order = null, $field = null, $limit = 20, $level = 0, array &$alldata = array()) {
|
||||
if ($level > 3) {
|
||||
return;
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
$limit = $limit? : 12;
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
$row['level'] = $level;
|
||||
$alldata[] = $row;
|
||||
$where['pid'] = $row['id'];
|
||||
self::getSinglepageLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
}
|
||||
}
|
||||
return $alldata;
|
||||
}
|
||||
|
||||
public function getChildIDArray($id) {
|
||||
$list = $this->where(['pid' => $id])->field('id')->select();
|
||||
$childIDArray = array((int) $id);
|
||||
if ($list) {
|
||||
foreach ($list as $val) {
|
||||
$childArray = self::getChildIDArray($val['id']);
|
||||
$childIDArray = array_merge($childIDArray, $childArray);
|
||||
}
|
||||
}
|
||||
return $childIDArray;
|
||||
}
|
||||
|
||||
public function getTopParentID($id, $where = null) {
|
||||
$data = $this::get(function($query)use($id, $where) {
|
||||
$query->where(['id' => $id]);
|
||||
if ($where) {
|
||||
$query->where($where);
|
||||
}
|
||||
$query->field(['id', 'pid']);
|
||||
});
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
$topid = self::getTopParentID($data['pid'], $where);
|
||||
} else {
|
||||
$topid = $id;
|
||||
}
|
||||
return $topid;
|
||||
}
|
||||
|
||||
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
|
||||
if (!$id) {
|
||||
return array();
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
$data = $this->field(['id', 'name', 'pid'])->get($id);
|
||||
$catarr[] = $data;
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
self::getBreadCrumb($data['pid'], $where, $catarr);
|
||||
} else {
|
||||
return array_reverse($catarr);
|
||||
}
|
||||
return $catarr;
|
||||
}
|
||||
|
||||
public function getOption($id = 0, $where = null, $order = null, $field = null, $limit = 20) {
|
||||
$options = '';
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
|
||||
$options = '';
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
$where['pid'] = $row['id'];
|
||||
$options.=self::getOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
||||
17
app/common/model/Ssd.php
Executable file
17
app/common/model/Ssd.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ORICO
|
||||
* Date: 2019-07-24
|
||||
* Time: 16:28
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Ssd extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
}
|
||||
85
app/common/model/Sysconfig.php
Executable file
85
app/common/model/Sysconfig.php
Executable file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Sysconfig extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
/**
|
||||
* 获取数据库中的配置列表
|
||||
* @return array 配置数组
|
||||
*/
|
||||
public function configLists($where = null) {
|
||||
$data = $this::all(function($query)use($where) {
|
||||
$query->where(['stat' => 0])->field('type,name,value,extra');
|
||||
if ($where) {
|
||||
$query->where($where);
|
||||
}
|
||||
$query->order(['sort' => 'asc', 'id' => 'asc']);
|
||||
});
|
||||
$config = [];
|
||||
if ($data && is_array($data)) {
|
||||
foreach ($data as $value) {
|
||||
$config[$value->data['name']] = self::parse($value->data['type'], $value->data['value'], $value->data['extra']);
|
||||
}
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据配置类型解析配置
|
||||
* @param integer $type 配置类型
|
||||
* @param string $value 配置值
|
||||
* @param string $extra 配置项
|
||||
*/
|
||||
private function parse($type, $value, $extra = '') {
|
||||
switch ($type) {
|
||||
// case 'number':
|
||||
// $value = intval($value);
|
||||
// break;
|
||||
case 'json':
|
||||
$value = json_decode($value, true);
|
||||
break;
|
||||
case 'array': //解析数组
|
||||
$array = preg_split('/[,;\r\n]+/', trim($value, ",;\r\n"));
|
||||
if (strpos($value, ':')) {
|
||||
$value = array();
|
||||
foreach ($array as $val) {
|
||||
list($k, $v) = explode(':', $val);
|
||||
$value[$k] = $v;
|
||||
}
|
||||
} else {
|
||||
$value = $array;
|
||||
}
|
||||
break;
|
||||
// case 'enum': //解析数组
|
||||
// $array = preg_split('/[,;\r\n]+/', trim($extra, ",;\r\n"));
|
||||
// if (strpos($value, ':')) {
|
||||
// $valarr = array();
|
||||
// foreach ($array as $val) {
|
||||
// list($k, $v) = explode(':', $val);
|
||||
// $valarr[$k] = $v;
|
||||
// }
|
||||
// } else {
|
||||
// $valarr = $array;
|
||||
// }
|
||||
// $value = isset($valarr[$value]) ? $valarr[$value] : $value;
|
||||
// break;
|
||||
case 'dump':
|
||||
dump($value);
|
||||
// die;
|
||||
break;
|
||||
default:
|
||||
//dump($value);
|
||||
// die;
|
||||
break;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
||||
18
app/common/model/Tbpl.php
Executable file
18
app/common/model/Tbpl.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: ORICO
|
||||
* Date: 2019-01-09
|
||||
* Time: 10:20
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
class Tbpl extends Model
|
||||
{
|
||||
use \app\common\traits\IndexModel;
|
||||
}
|
||||
59
app/common/model/Video.php
Executable file
59
app/common/model/Video.php
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class Video extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getCateVideoList($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('video_category c', 'a.cid=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$data = $this->select();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getCateVideoLists($where = null, $order = null, $field = null, $limit = null) {
|
||||
$this->alias('a')->join('video_category c', 'a.cid=c.id', 'LEFT');
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['a.stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows') > 0 ? Config::get('list_rows') : 12;
|
||||
}
|
||||
//$this->fetchsql(true);
|
||||
$object = $this->paginate($limit);
|
||||
// header("content-type:text/html;charset=utf8;");
|
||||
// print_r($object);
|
||||
// exit;
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
||||
196
app/common/model/VideoCategory.php
Executable file
196
app/common/model/VideoCategory.php
Executable file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
use think\Request;
|
||||
use think\Config;
|
||||
|
||||
class VideoCategory extends Model {
|
||||
|
||||
use \app\common\traits\IndexModel;
|
||||
|
||||
public function getCategoryLists($where = null, $order = null, $field = null, $limit = 20, $level = 0, array &$alldata = array()) {
|
||||
if ($level > 5) {
|
||||
return;
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => 0], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
$limit = $limit? : 12;
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
$row['level'] = $level;
|
||||
$alldata[] = $row;
|
||||
$where['pid'] = $row['id'];
|
||||
//self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
!$row['haschild'] ? '' : self::getCategoryLists($where, $order, $field, $limit, $level + 1, $alldata);
|
||||
}
|
||||
}
|
||||
return $alldata;
|
||||
}
|
||||
|
||||
public function getChildIDArray($id) {
|
||||
$list = $this->where(['pid' => $id, 'stat' => 0])->field(['id', 'haschild'])->select();
|
||||
$childIDArray = array((int) $id);
|
||||
if ($list) {
|
||||
foreach ($list as $val) {
|
||||
$childArray = $val['haschild'] ? self::getChildIDArray($val['id']) : array((int) $val['id']);
|
||||
$childIDArray = array_merge($childIDArray, $childArray);
|
||||
}
|
||||
}
|
||||
return $childIDArray;
|
||||
}
|
||||
|
||||
public function getTopParentID($id, $where = null) {
|
||||
$data = $this::get(function($query)use($id, $where) {
|
||||
$query->where(['id' => $id]);
|
||||
if ($where) {
|
||||
$query->where($where);
|
||||
}
|
||||
$query->field(['id', 'pid']);
|
||||
});
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
$topid = self::getTopParentID($data['pid'], $where);
|
||||
} else {
|
||||
$topid = $id;
|
||||
}
|
||||
return $topid;
|
||||
}
|
||||
|
||||
public function getBreadCrumb($id, $where = null, array &$catarr = array()) {
|
||||
if (!$id) {
|
||||
return array();
|
||||
}
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
$data = $this->field(['id', 'name', 'pid'])->get($id);
|
||||
$catarr[] = $data;
|
||||
if (isset($data['pid']) && $data['pid']) {
|
||||
self::getBreadCrumb($data['pid'], $where, $catarr);
|
||||
} else {
|
||||
return array_reverse($catarr);
|
||||
}
|
||||
return $catarr;
|
||||
}
|
||||
|
||||
public function getCategoryOption($id = 0, $where = null, $order = null, $field = null, $limit = null) {
|
||||
$options = '';
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getCategoryOptions($id = 0, $where = null, $order = null, $field = null, $limit = null, $level = 0) {
|
||||
$options = '';
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if (empty($limit)) {
|
||||
$limit = Config::get('list_rows');
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select();
|
||||
if ($list) {
|
||||
foreach ($list as $k => $row) {
|
||||
if ($row['id'] == $id) {
|
||||
$options.='<option value="' . $row['id'] . '" selected>' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
} else {
|
||||
$options.='<option value="' . $row['id'] . '">' . ($level ? str_repeat('    ', $level) . '⌊' : '') . $row['name'] . '</option>' . "\n";
|
||||
}
|
||||
$where['pid'] = $row['id'];
|
||||
//$options.=self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
$options.=!$row['haschild'] ? '' : self::getCategoryOptions($id, $where, $order, $field, $limit, $level + 1);
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getCategoryTree($where = null, $order = null, $field = null, $limit = 50, $level = 0) {
|
||||
if (is_array($where)) {
|
||||
$where = array_merge(['stat' => ['eq', '0']], $where);
|
||||
}
|
||||
$result = array();
|
||||
if ($level > 5) {
|
||||
return $result;
|
||||
}
|
||||
if ($where) {
|
||||
$this->where($where);
|
||||
}
|
||||
if ($order) {
|
||||
$this->order($order);
|
||||
}
|
||||
if ($field) {
|
||||
$this->field($field);
|
||||
}
|
||||
if ($limit) {
|
||||
$this->limit($limit);
|
||||
}
|
||||
$list = $this->select(); // 获取
|
||||
if ($list) {
|
||||
foreach ($list as $row) {
|
||||
$row['level'] = $level;
|
||||
$where['pid'] = $row['id'];
|
||||
//$row['child'] = self::getCategoryTree($where, $order, $field, $limit, $level + 1);
|
||||
$row['child'] = !$row['haschild'] ? array() : self::getCategoryTree($where, $order, $field, $limit, $level + 1);
|
||||
$result[] = $row;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user