|
...
|
...
|
@@ -10,6 +10,7 @@ use App\Models\News\News; |
|
|
|
use App\Models\News\NewsCategory as NewsCategoryModel;
|
|
|
|
use App\Models\RouteMap;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use mysql_xdevapi\Exception;
|
|
|
|
|
|
|
|
class NewsLogic extends BaseLogic
|
|
|
|
{
|
|
...
|
...
|
@@ -68,7 +69,7 @@ class NewsLogic extends BaseLogic |
|
|
|
$rs = $this->model->insertGetId($this->param);
|
|
|
|
//产品计数
|
|
|
|
$category_data = explode(',',trim($this->param['category_id'],','));
|
|
|
|
$this->_set_num(NewsCategoryModel::class,$category_data);
|
|
|
|
$this->set_num(NewsCategoryModel::class,$category_data);
|
|
|
|
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
|
|
|
|
DB::commit();
|
|
|
|
}catch (\Exception $e){
|
|
...
|
...
|
@@ -95,7 +96,7 @@ class NewsLogic extends BaseLogic |
|
|
|
}
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
//多个分类按逗号隔开
|
|
|
|
$this->param['category_id'] = ','.$this->param['category_id'].',';
|
|
|
|
$this->param['category_id'] = $this->param['category_id'];
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
//上传图片
|
|
...
|
...
|
@@ -112,6 +113,7 @@ class NewsLogic extends BaseLogic |
|
|
|
}
|
|
|
|
$this->param['image'] = $this->upload();
|
|
|
|
}
|
|
|
|
//设置路由
|
|
|
|
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);
|
|
|
|
$this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
DB::commit();
|
|
...
|
...
|
@@ -181,10 +183,36 @@ class NewsLogic extends BaseLogic |
|
|
|
*/
|
|
|
|
public function news_del(){
|
|
|
|
$ids = $this->param['id'];
|
|
|
|
$this->param['id'] = ['in',$this->param['id']];
|
|
|
|
$this->del($this->param,$ids);
|
|
|
|
//数量自减
|
|
|
|
$this->set_num(NewsCategoryModel::class,'id','del',count($ids));
|
|
|
|
$str = $this->get_category_id($ids);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
if(!empty($str)){
|
|
|
|
$category_data = explode(',',$str);
|
|
|
|
$this->set_num(NewsCategoryModel::class,$category_data,'del');
|
|
|
|
$this->param['id'] = ['in',$this->param['id']];
|
|
|
|
$this->del($this->param,$ids);
|
|
|
|
}
|
|
|
|
DB::commit();
|
|
|
|
}catch (Exception $e){
|
|
|
|
DB::rollBack();
|
|
|
|
$this->fail('当前数据不存在');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $ids
|
|
|
|
* @name :删除数据时获取所有数据的分类id
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function get_category_id($ids){
|
|
|
|
$str = '';
|
|
|
|
$list = $this->model->list(['id'=>['in',$ids]],'id',['id','category_id']);
|
|
|
|
foreach ($list as $v){
|
|
|
|
$str .= trim($v['category_id'],',').',';
|
|
|
|
}
|
|
|
|
return trim($str,',');
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|