作者 liyuhang

gx

... ... @@ -88,12 +88,12 @@ class BaseController extends Controller
case "name":
$this->map['name'] = ['like','%'.$v.'%'];
break;
case "created_at":
case "start_at":
$this->_btw[0] = $v;
$this->_btw[1] = date('Y-m-d H:i:s',time());
$this->map['created_at'] = ['between', $this->_btw];
break;
case "updated_at":
case "end_at":
$this->_btw[1] = $v;
$this->map['updated_at'] = ['between', $this->_btw];
break;
... ...
... ... @@ -105,29 +105,13 @@ class NewsCategoryController extends BaseController
* @author :liyuhang
* @method
*/
public function del(Request $request,NewsCategoryModel $newsCategory,NewsModel $news){
public function del(Request $request,NewsCategoryLogic $newsCategoryLogic){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
foreach ($this->param['id'] as $v){
//查询是否有子分类
$rs = $newsCategory->read(['pid'=>$v],['id']);
if($rs !== false){
$this->response('当前分类拥有子分类不允许删除',Code::USER_ERROR);
}
//查看当前分内下是否有商品
$rs = $news->read(['category_id'=>$v],['id']);
if($rs !== false){
$this->response('当前分类拥有商品',Code::USER_ERROR);
}
}
$this->param['id'] = ['in',$this->param['id']];
$rs = $newsCategory->del($this->param);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$newsCategoryLogic->del_news_category();
$this->response('success');
}
}
... ...
... ... @@ -57,6 +57,36 @@ class NewsCategoryLogic extends BaseLogic
}
}
DB::commit();
$this->success();
return $this->success();
}
/**
* @name :删除新闻分类
* @return array
* @throws \App\Exceptions\BsideGlobalException
* @author :liyuhang
* @method
*/
public function del_news_category(){
$this->param = $this->requestAll;
foreach ($this->param['id'] as $v){
//查询是否有子分类
$rs = $this->model->read(['pid'=>$v],['id']);
if($rs !== false){
$this->fail('当前分类拥有子分类不允许删除',Code::USER_ERROR);
}
//查看当前分内下是否有商品
$newsModel = new NewsModel();
$rs = $newsModel->read(['category_id'=>$v],['id']);
if($rs !== false){
$this->fail('当前分类拥有商品',Code::USER_ERROR);
}
}
$this->param['id'] = ['in',$this->param['id']];
$rs = $this->model->del($this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success();
}
}
... ...