124 lines
3.3 KiB
PHP
124 lines
3.3 KiB
PHP
<?php
|
|
|
|
|
|
namespace Yunshop\VideoShare\admin;
|
|
|
|
|
|
use app\common\components\BaseController;
|
|
use Yunshop\VideoShare\common\model\CategoryModel;
|
|
use Yunshop\VideoShare\common\model\VideoShareGoods;
|
|
|
|
class CategoryController extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$search = request()->search;
|
|
|
|
$list = CategoryModel::uniacid()->search($search)->orderBy("id","desc")->paginate(15);
|
|
$list = empty($list) ? [] : $list->toArray();
|
|
|
|
if (!empty($list['data'])) {
|
|
foreach ($list['data'] as $kk=>$vv) {
|
|
$amount_total = VideoShareGoods::uniacid()->where("category_id",$vv['id'])->count();
|
|
$list['data'][$kk]['amount_total'] = $amount_total;
|
|
}
|
|
}
|
|
return view('Yunshop\VideoShare::category.list',[
|
|
'list' => json_encode($list),
|
|
'search' => json_encode($search)
|
|
])->render();
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
$cate_id = request()->get("cate_id");
|
|
|
|
$cate_data = request()->cate_data;
|
|
|
|
$cate = [];
|
|
|
|
if (!empty($cate_data)) {
|
|
if ($cate_id) {
|
|
$category = CategoryModel::uniacid()->where("id",$cate_id)->first();
|
|
} else {
|
|
$category = new CategoryModel();
|
|
}
|
|
|
|
$data = [
|
|
"uniacid" => \YunShop::app()->uniacid,
|
|
"name" => $cate_data['name'],
|
|
"sort" => $cate_data['sort'],
|
|
"is_show" => $cate_data['is_show']
|
|
];
|
|
|
|
$category->fill($data);
|
|
|
|
if ($category->save()) {
|
|
return $this->successJson("编辑成功");
|
|
}
|
|
|
|
return $this->errorJson("编辑失败");
|
|
}
|
|
|
|
if ($cate_id) {
|
|
$cate = CategoryModel::uniacid()->where("id",$cate_id)->first();
|
|
$cate = empty($cate) ? [] : $cate->toArray();
|
|
}
|
|
|
|
return view('Yunshop\VideoShare::category.edit',[
|
|
"cate" => $cate
|
|
])->render();
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$search = request()->search;
|
|
|
|
$list = CategoryModel::uniacid()->search($search)->paginate(15);
|
|
$list = empty($list) ? [] : $list->toArray();
|
|
|
|
if (!empty($list['data'])) {
|
|
foreach ($list['data'] as $kk=>$vv) {
|
|
$amount_total = VideoShareGoods::uniacid()->where("category_id",$vv['id'])->count();
|
|
$list['data'][$kk]['amount_total'] = $amount_total;
|
|
}
|
|
}
|
|
|
|
return $this->successJson("",["list"=>$list]);
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
$id = request()->get("id");
|
|
|
|
$cate = CategoryModel::uniacid()->where("id",$id)->first();
|
|
|
|
if (empty($cate)) {
|
|
return $this->errorJson("分类不存在");
|
|
}
|
|
|
|
$rel = CategoryModel::uniacid()->where("id",$id)->delete();
|
|
|
|
if ($rel) {
|
|
return $this->successJson("删除成功");
|
|
} else {
|
|
return $this->errorJson("删除失败");
|
|
}
|
|
}
|
|
|
|
public function changeStatus()
|
|
{
|
|
$id = request()->get("id");
|
|
|
|
$cate = CategoryModel::uniacid()->where("id",$id)->first();
|
|
|
|
if (empty($cate)) {
|
|
return $this->errorJson("分类不存在");
|
|
}
|
|
|
|
$cate->is_show = ($cate->is_show == 1) ? 2 : 1;
|
|
$cate->save();
|
|
return $this->successJson('成功', []);
|
|
}
|
|
|
|
} |