208 lines
5.4 KiB
PHP
Executable File
208 lines
5.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\model;
|
|
|
|
use think\Model;
|
|
use think\Request;
|
|
use think\Config;
|
|
|
|
class ProductSeries extends Model {
|
|
|
|
use \app\common\traits\AdminModel;
|
|
|
|
protected $insert = ['createtime'];
|
|
|
|
//protected $update = [];
|
|
|
|
|
|
public function getSeriesLists($where = null, $order = null, $field = null, $limit = null, array &$alldata = array()) {
|
|
|
|
|
|
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) {
|
|
$row['level'] = $level;
|
|
$alldata[] = $row;
|
|
|
|
}
|
|
}
|
|
return $alldata;
|
|
}
|
|
|
|
public function getSeriesList($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 ($field) {
|
|
$this->field($field);
|
|
}
|
|
if ($order) {
|
|
$this->order($order);
|
|
}
|
|
if ($limit) {
|
|
$this->limit($limit);
|
|
}
|
|
$data = $this->select();
|
|
return $data;
|
|
}
|
|
|
|
|
|
|
|
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'])->get($id);
|
|
$catarr[] = $data;
|
|
|
|
|
|
return $catarr;
|
|
}
|
|
|
|
public function getSeriesOption($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 getSeriesOptions($where = null, $order = null, $field = null, $limit = null, $id = 0) {
|
|
$options = '';
|
|
$disable = '';
|
|
$separator = '';
|
|
$selected = '';
|
|
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 (is_array($id)) {
|
|
$selected = in_array($row['id'], $id) ? ' selected="selected"' : '';
|
|
} else {
|
|
$selected = ($row['id'] == $id) ? ' selected="selected"' : '';
|
|
}
|
|
$options.='<option value="' . $row['id'] . '"' . $disable . $selected . '>' . $separator . $row['name'] . '</option>' . "\n";
|
|
|
|
}
|
|
}
|
|
return $options;
|
|
}
|
|
|
|
public function getSeriesTree($where = null, $order = null, $field = null, $limit = 50) {
|
|
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) {
|
|
$result[] = $row;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
public function deleteRow($id, $stat = -1) {
|
|
//$result = $this::destroy($id);
|
|
$data = ['id' => $id, 'stat' => $stat,];
|
|
$object = $this::update($data);
|
|
return $object;
|
|
}
|
|
|
|
protected function setCreatetimeAttr($value, $data) {
|
|
return time();
|
|
}
|
|
|
|
protected function setContentAttr($content, $data) {
|
|
if (!empty($content)) {
|
|
$config = \HTMLPurifier_Config::createDefault();
|
|
$purifier = new \HTMLPurifier($config);
|
|
$content = $purifier->purify($content);
|
|
}
|
|
return $content;
|
|
}
|
|
|
|
}
|