Files
orico-official-website-old/app/admin/controller/ProductSeries.php
2024-10-29 17:57:44 +08:00

259 lines
9.1 KiB
PHP
Executable File

<?php
namespace app\admin\controller;
use think\Lang;
use think\Loader;
use think\Config;
use think\TransDb;
class ProductSeries extends BaseController {
public function index() {
$this->redirect('/admin/product_series/lists');
}
public function lists() {
$skeyword = $this->request->get('skeyword', '', 'urldecode');
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort', 'isshow', 'picture');
if (!empty($skeyword)) {
$arg_where = array('stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$skeyword = trim($skeyword);
$arg_where['name'] = ['like', '%' . $skeyword . '%'];
$search['skeyword'] = $skeyword;
Config::set('paginate.query', ['skeyword' => $skeyword]); //分页参数
$series_list = model('product_series')->getSeriesList($arg_where, $arg_order, $arg_field, 500);
} else {
$arg_where = array('stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$search['skeyword'] = '';
$series_list = model('product_series')->getSeriesList($arg_where, $arg_order, $arg_field, 24);
}
$value = ['list' => $series_list, 'search' => $search,];
$this->assign($value);
return $this->fetch();
}
public function add() {
$arg_where = array( 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort');
$seriesOptions = model('product_series')->getSeriesOptions( $arg_where, $arg_order, $arg_field, 100);
$value = ['seriesOptions' => $seriesOptions];
$this->assign($value);
return $this->fetch();
}
public function create() {
if ($this->request->isPost()) {
$data = $this->request->post();
// tiaoshi($data);die;
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$data['sort'] = intval($data['sort']);
$data['siteid'] = $this->siteid;
$data['country_code'] = $this->country_code;
$seriesModel = model('product_series');
$model = $seriesModel->insertGetId($data);
if ($model) {
return $this->redirect(url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function copy($id = 0) {
$seriesModel = model('product_series');
$id = intval($id);
if ($id > 0) {
$series = $seriesModel->getRow($id);
if (!$series && !is_array($series)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['product_series'] = $series;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$arg_where = array('pid' => 0, 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort');
$seriesOptions = $seriesModel->getSeriesOptions($arg_where, $arg_order, $arg_field, 100);
$value['seriesOptions'] = $seriesOptions;
$this->assign($value);
return $this->fetch();
}
public function edit($id = 0) {
$seriesModel = model('product_series');
$id = intval($id);
if ($id > 0) {
$series = $seriesModel->getRow($id);
if (empty($series)) {
return $this->error(Lang::get('incorrect operation'));
}
$value['product_series'] = $series;
} else {
return $this->error(Lang::get('incorrect operation'));
}
$arg_where = array( 'stat' => 0, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort');
$seriesOptions = $seriesModel->getSeriesOptions($arg_where, $arg_order, $arg_field, 100);
$value['seriesOptions'] = $seriesOptions;
$this->assign($value);
return $this->fetch();
}
public function update() {
if ($this->request->isPost()) {
$data = $this->request->post();
if (empty($data) || !is_array($data)) {
return $this->error(Lang::get('incorrect operation'));
}
$validaterule = ['name' => 'require'];
$validatemsg = ['name.require' => '名称不能为空'];
$valid_result = $this->validate($data, $validaterule, $validatemsg);
if (true !== $valid_result) {
// 验证失败 输出错误信息
return $this->error($valid_result);
}
$product_series = model('product_series')->find($data['id']);
if (empty($product_series)){
return $this->error(Lang::get('产品系列名称不存在'));
}
$data['sort'] = intval($data['sort']);
$seriesModel = model('product_series');
$model = $seriesModel->updateRow($data);
if ($model && $model->getData('id')) {
return $this->redirect(url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
} else {
return $this->error(Lang::get('operation failed'));
}
}
public function listseries() {
$seriesModel = model('product_series');
$arg_where = array('stat' => 0, 'siteid' => $this->siteid, 'country_code' => $this->country_code);
$arg_order = array('sort' => 'asc', 'id' => 'asc');
$arg_field = array('id', 'name', 'sort', 'isshow', 'picture');
$series_list = $seriesModel->getList($arg_where, $arg_order, $arg_field, 50);
$series_breadcrumb = $seriesModel->getBreadCrumb();
$value = ['list' => $series_list, 'breadcrumb' => $series_breadcrumb];
$this->assign($value);
return $this->fetch();
}
public function updatesort() {
$id = $this->request->param('id', 0);
$sort = $this->request->param('sort', 0);
$sort = intval($sort);
$id = intval($id);
if ($id && $sort < 2147483647) {
$model = model('product_series')->updateRow(['id' => $id, 'sort' => $sort]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function togglestat() {
$id = $this->request->get('id', 0);
$flag = $this->request->get('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('product_series')->updateRow(['id' => $id, 'stat' => !$flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function toggleisshow() {
$id = $this->request->param('id', 0);
$flag = $this->request->param('flag', 0);
$id = intval($id);
if ($id > 0) {
$model = model('product_series')->updateRow(['id' => $id, 'isshow' => $flag]);
if ($model && $model->getData('id')) {
return $this->success(Lang::get('operation successed'), url('/admin/product_series/lists'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
public function delete($id = 0) {
$id = intval($id);
if ($id > 0) {
$seriesModel = model('product_series');
$series= $seriesModel->getRow(['id' => $id, 'stat' => 0]);
$result = $seriesModel->destroyRow($id);
if ($result) {
return $this->success(Lang::get('operation successed'));
} else {
return $this->error(Lang::get('operation failed'));
}
}
return $this->error(Lang::get('incorrect operation'));
}
}