You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.0 KiB
174 lines
5.0 KiB
<?php
|
|
|
|
namespace app\service\Goods;
|
|
|
|
use app\model\Classify;
|
|
use app\model\OperationLog;
|
|
use app\service\BaseService;
|
|
|
|
class ClassifyService extends BaseService
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
|
|
public function list($top_class, $son_class, $user_id, $usestatus, $createtime, $page, $limit){
|
|
|
|
$where = [];
|
|
$where['classify.is_deleted'] = 0;
|
|
if(!empty($top_class)){
|
|
$where['classify.top_class'] = $top_class;
|
|
}
|
|
if(!empty($son_class)){
|
|
$where['classify.son_class'] = $son_class;
|
|
}
|
|
if(!empty($user_id)){
|
|
$where['classify.user_id'] = $user_id;
|
|
}
|
|
if(!empty($usestatus) || $usestatus >= 0){
|
|
$where['classify.status'] = $usestatus;
|
|
}
|
|
if(!empty($createtime)){
|
|
$where['createtime'] = $createtime;
|
|
}
|
|
|
|
$search = $this->buildSearch(['createtime', 'order'], $where);
|
|
$list = (new Classify())->list($search, $where, $limit, ['admin']);
|
|
$list->hidden(['admin']);
|
|
$list = $list->toArray();
|
|
$start = ($page - 1) * $limit + 1;
|
|
$end = $page * $limit;
|
|
if($list['total'] < $end){
|
|
$end = $list['total'];
|
|
}
|
|
if($list['total'] < $start){
|
|
$start = $end = $list['total'];
|
|
}
|
|
$list['start'] = $start;
|
|
$list['end'] = $end;
|
|
return $list;
|
|
}
|
|
|
|
|
|
public function getTop(){
|
|
$where = [];
|
|
$where['classify.is_deleted'] = 0;
|
|
$result = [];
|
|
Classify::where($where)->field('top_class')->select()->each(function($item) use(&$result){
|
|
if(count($result) >= 1){
|
|
$result[count($result)+1] = $item['top_class'];
|
|
}else{
|
|
$result[1] = $item['top_class'];
|
|
}
|
|
});
|
|
$result = array_unique($result);
|
|
return $result;
|
|
|
|
}
|
|
|
|
public function getSon($top_class){
|
|
$where = [];
|
|
$where['is_deleted'] = 0;
|
|
$where['top_class'] = $top_class;
|
|
$result = Classify::where($where)->field('son_class')->select()->toArray();
|
|
$result = array_column($result, "son_class");
|
|
return $result;
|
|
}
|
|
|
|
|
|
public function addClass($pull_top_class, $top_class, $son_class){
|
|
if(!empty($pull_top_class)){
|
|
$addclass = [
|
|
'top_class' => $pull_top_class,
|
|
'son_class' => $son_class,
|
|
'user_id' => $this->admin_id,
|
|
];
|
|
$id = (new Classify())->insertGetId($addclass);
|
|
// 插入操作日志
|
|
$log = [
|
|
'type' => 'class',
|
|
'log_id' => $id,
|
|
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}创建",
|
|
];
|
|
(new OperationLog())->insert($log);
|
|
return;
|
|
}
|
|
$where = [];
|
|
$where['is_deleted'] = 0;
|
|
$where['top_class'] = $top_class;
|
|
$result = Classify::where($where)->find();
|
|
if($result){
|
|
|
|
$addclass = [
|
|
'top_class' => $top_class,
|
|
'son_class' => $son_class,
|
|
'user_id' => $this->admin_id,
|
|
];
|
|
$id = (new Classify())->insertGetId($addclass);
|
|
// 插入操作日志
|
|
$log = [
|
|
'type' => 'class',
|
|
'log_id' => $id,
|
|
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}创建",
|
|
];
|
|
(new OperationLog())->insert($log);
|
|
}else{
|
|
|
|
$addclass = [
|
|
'top_class' => $top_class,
|
|
'son_class' => $son_class,
|
|
'user_id' => $this->admin_id,
|
|
];
|
|
$id = (new Classify())->insertGetId($addclass);
|
|
// 插入操作日志
|
|
$log = [
|
|
'type' => 'class',
|
|
'log_id' => $id,
|
|
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}创建",
|
|
];
|
|
(new OperationLog())->insert($log);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function updateStatus($id){
|
|
|
|
$where = [];
|
|
$where['is_deleted'] = 0;
|
|
$where['id'] = $id;
|
|
$result = Classify::where($where)->find();
|
|
if(!$result){
|
|
throw new \think\Exception('该分类不存在', 400);
|
|
}
|
|
|
|
if($result->status == 0){
|
|
$result->status = 1;
|
|
$result->save();
|
|
// 插入操作日志
|
|
$log = [
|
|
'type' => 'class',
|
|
'log_id' => $id,
|
|
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}停用",
|
|
];
|
|
(new OperationLog())->insert($log);
|
|
}else{
|
|
$result->status = 0;
|
|
$result->save();
|
|
// 插入操作日志
|
|
$log = [
|
|
'type' => 'class',
|
|
'log_id' => $id,
|
|
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}启用",
|
|
];
|
|
(new OperationLog())->insert($log);
|
|
}
|
|
}
|
|
|
|
|
|
}
|