优化商品、文章编辑新增方法
This commit is contained in:
parent
ff6c1c0d48
commit
4ffdc6f774
@ -171,29 +171,23 @@ class Article extends BaseController
|
||||
$param['update_time'] = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = ArticleList::strict(false)->field(true)->update($param);
|
||||
ArticleList::strict(false)->field(true)->update($param);
|
||||
$aid = $param['id'];
|
||||
if ($res) {
|
||||
//关联关键字
|
||||
if (isset($param['keyword_names']) && $param['keyword_names']) {
|
||||
Db::name('ArticleKeywords')->where(['aid'=>$aid])->delete();
|
||||
$keywordArray = explode(',', $param['keyword_names']);
|
||||
$res_keyword = (new ArticleList())->insertKeyword($keywordArray,$aid);
|
||||
}
|
||||
else{
|
||||
$res_keyword == true;
|
||||
}
|
||||
if($res_keyword!== false){
|
||||
add_log('edit', $param['id'], $param);
|
||||
Db::commit();
|
||||
$DbRes=true;
|
||||
}
|
||||
} else {
|
||||
Db::rollback();
|
||||
}
|
||||
//关联关键字
|
||||
if (isset($param['keyword_names']) && $param['keyword_names']) {
|
||||
Db::name('ArticleKeywords')->where(['aid'=>$aid])->delete();
|
||||
$keywordArray = explode(',', $param['keyword_names']);
|
||||
$res_keyword = (new ArticleList())->insertKeyword($keywordArray,$aid);
|
||||
}
|
||||
add_log('edit', $aid, $param);
|
||||
Db::commit();
|
||||
$DbRes=true;
|
||||
}
|
||||
catch (\Exception $e) { ##这里参数不能删除($e:错误信息)
|
||||
Db::rollback();
|
||||
catch (\Exception $e) {
|
||||
//回滚事务
|
||||
$DbRes = false;
|
||||
Db::rollback();
|
||||
return to_assign(1,'捕获到异常'.$e->getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
@ -209,27 +203,20 @@ class Article extends BaseController
|
||||
$param['desc'] = getDescriptionFromContent($param['content'], 100);
|
||||
}
|
||||
$aid = ArticleList::strict(false)->field(true)->insertGetId($param);
|
||||
if ($aid) {
|
||||
//关联关键字
|
||||
if (isset($param['keyword_names']) && $param['keyword_names']) {
|
||||
Db::name('ArticleKeywords')->where(['aid'=>$aid])->delete();
|
||||
$keywordArray = explode(',', $param['keyword_names']);
|
||||
$res_keyword = (new ArticleList())->insertKeyword($keywordArray,$aid);
|
||||
}
|
||||
else{
|
||||
$res_keyword == true;
|
||||
}
|
||||
if($res_keyword!== false){
|
||||
add_log('add', $aid, $param);
|
||||
Db::commit();
|
||||
$DbRes=true;
|
||||
}
|
||||
} else {
|
||||
Db::rollback();
|
||||
}
|
||||
//关联关键字
|
||||
if (isset($param['keyword_names']) && $param['keyword_names']) {
|
||||
$keywordArray = explode(',', $param['keyword_names']);
|
||||
$res_keyword = (new ArticleList())->insertKeyword($keywordArray,$aid);
|
||||
}
|
||||
add_log('add', $aid, $param);
|
||||
Db::commit();
|
||||
$DbRes=true;
|
||||
}
|
||||
catch (\Exception $e) { ##这里参数不能删除($e:错误信息)
|
||||
Db::rollback();
|
||||
catch (\Exception $e) {
|
||||
//回滚事务
|
||||
$DbRes = false;
|
||||
Db::rollback();
|
||||
return to_assign(1,'捕获到异常'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
if($DbRes){
|
||||
|
@ -174,29 +174,23 @@ class Goods extends BaseController
|
||||
$param['update_time'] = time();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$res = GoodsList::strict(false)->field(true)->update($param);
|
||||
GoodsList::strict(false)->field(true)->update($param);
|
||||
$aid = $param['id'];
|
||||
if ($res) {
|
||||
//关联关键字
|
||||
if (isset($param['keyword_names']) && $param['keyword_names']) {
|
||||
Db::name('GoodsKeywords')->where(['aid'=>$aid])->delete();
|
||||
$keywordArray = explode(',', $param['keyword_names']);
|
||||
$res_keyword = (new GoodsList())->insertKeyword($keywordArray,$aid);
|
||||
}
|
||||
else{
|
||||
$res_keyword == true;
|
||||
}
|
||||
if($res_keyword!== false){
|
||||
add_log('edit', $param['id'], $param);
|
||||
Db::commit();
|
||||
$DbRes=true;
|
||||
}
|
||||
} else {
|
||||
Db::rollback();
|
||||
}
|
||||
//关联关键字
|
||||
if (isset($param['keyword_names']) && $param['keyword_names']) {
|
||||
Db::name('GoodsKeywords')->where(['aid'=>$aid])->delete();
|
||||
$keywordArray = explode(',', $param['keyword_names']);
|
||||
$res_keyword = (new GoodsList())->insertKeyword($keywordArray,$aid);
|
||||
}
|
||||
add_log('edit', $aid, $param);
|
||||
Db::commit();
|
||||
$DbRes=true;
|
||||
}
|
||||
catch (\Exception $e) { ##这里参数不能删除($e:错误信息)
|
||||
Db::rollback();
|
||||
catch (\Exception $e) {
|
||||
//回滚事务
|
||||
$DbRes = false;
|
||||
Db::rollback();
|
||||
return to_assign(1,'捕获到异常'.$e->getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
@ -206,33 +200,26 @@ class Goods extends BaseController
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$param['create_time'] = time();
|
||||
if(empty($param['desc'])){
|
||||
$param['desc'] = getDescriptionFromContent($param['content'], 100);
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
if(empty($param['desc'])){
|
||||
$param['desc'] = getDescriptionFromContent($param['content'], 100);
|
||||
}
|
||||
$aid = GoodsList::strict(false)->field(true)->insertGetId($param);
|
||||
if ($aid) {
|
||||
//关联关键字
|
||||
if (isset($param['keyword_names']) && $param['keyword_names']) {
|
||||
Db::name('GoodsKeywords')->where(['aid'=>$aid])->delete();
|
||||
$keywordArray = explode(',', $param['keyword_names']);
|
||||
$res_keyword = (new GoodsList())->insertKeyword($keywordArray,$aid);
|
||||
}
|
||||
else{
|
||||
$res_keyword == true;
|
||||
}
|
||||
if($res_keyword!== false){
|
||||
add_log('add', $aid, $param);
|
||||
Db::commit();
|
||||
$DbRes=true;
|
||||
}
|
||||
} else {
|
||||
Db::rollback();
|
||||
}
|
||||
//关联关键字
|
||||
if (isset($param['keyword_names']) && $param['keyword_names']) {
|
||||
$keywordArray = explode(',', $param['keyword_names']);
|
||||
$res_keyword = (new GoodsList())->insertKeyword($keywordArray,$aid);
|
||||
}
|
||||
add_log('edit', $aid, $param);
|
||||
Db::commit();
|
||||
$DbRes=true;
|
||||
}
|
||||
catch (\Exception $e) { ##这里参数不能删除($e:错误信息)
|
||||
Db::rollback();
|
||||
catch (\Exception $e) {
|
||||
//回滚事务
|
||||
$DbRes = false;
|
||||
Db::rollback();
|
||||
return to_assign(1,'捕获到异常'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
if($DbRes){
|
||||
|
@ -15,8 +15,8 @@ class Article extends Model
|
||||
// 获取文章详情
|
||||
public function detail($id)
|
||||
{
|
||||
$article = \think\facade\Db::name('Article')->where(['id' => $id])->find();
|
||||
if (!empty($article)) {
|
||||
$detail = \think\facade\Db::name('Article')->where(['id' => $id])->find();
|
||||
if (!empty($detail)) {
|
||||
$keyword_array = \think\facade\Db::name('ArticleKeywords')
|
||||
->field('i.aid,i.keywords_id,k.title')
|
||||
->alias('i')
|
||||
@ -25,11 +25,11 @@ class Article extends Model
|
||||
->where(array('i.aid' => $id, 'k.status' => 1))
|
||||
->select()->toArray();
|
||||
|
||||
$article['keyword_ids'] = implode(",", array_column($keyword_array, 'keywords_id'));
|
||||
$article['keyword_names'] = implode(',', array_column($keyword_array, 'title'));
|
||||
$article['keyword_array'] = $keyword_array;
|
||||
$detail['keyword_ids'] = implode(",", array_column($keyword_array, 'keywords_id'));
|
||||
$detail['keyword_names'] = implode(',', array_column($keyword_array, 'title'));
|
||||
$detail['keyword_array'] = $keyword_array;
|
||||
}
|
||||
return $article;
|
||||
return $detail;
|
||||
}
|
||||
|
||||
//插入关键字
|
||||
|
@ -15,11 +15,11 @@ class Goods extends Model
|
||||
// 获取商品详情
|
||||
public function detail($id)
|
||||
{
|
||||
$goods = \think\facade\Db::name('Goods')->where(['id'=>$id])->find();
|
||||
if(!empty($goods)) {
|
||||
$detail = \think\facade\Db::name('Goods')->where(['id'=>$id])->find();
|
||||
if(!empty($detail)) {
|
||||
//轮播图
|
||||
if(!empty($goods['banner'])) {
|
||||
$goods['banner_array'] = explode(',',$goods['banner']);
|
||||
if(!empty($detail['banner'])) {
|
||||
$detail['banner_array'] = explode(',',$detail['banner']);
|
||||
}
|
||||
//关键字
|
||||
$keywrod_array = \think\facade\Db::name('GoodsKeywords')
|
||||
@ -30,35 +30,35 @@ class Goods extends Model
|
||||
->where(array('i.aid' => $id, 'k.status' => 1))
|
||||
->select()->toArray();
|
||||
|
||||
$goods['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id'));
|
||||
$goods['keyword_names'] = implode(',', array_column($keywrod_array, 'title'));
|
||||
$detail['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id'));
|
||||
$detail['keyword_names'] = implode(',', array_column($keywrod_array, 'title'));
|
||||
|
||||
//标签设置
|
||||
$goods['tag1'] = $goods['tag2'] = $goods['tag3'] = $goods['tag4'] = $goods['tag5'] = $goods['tag6'] =0;
|
||||
if(!empty($goods['tag_values'])) {
|
||||
$tag_values_array = explode(',', $goods['tag_values']);
|
||||
$detail['tag1'] = $detail['tag2'] = $detail['tag3'] = $detail['tag4'] = $detail['tag5'] = $detail['tag6'] =0;
|
||||
if(!empty($detail['tag_values'])) {
|
||||
$tag_values_array = explode(',', $detail['tag_values']);
|
||||
if(in_array('1', $tag_values_array)){
|
||||
$goods['tag1'] = 1;
|
||||
$detail['tag1'] = 1;
|
||||
}
|
||||
if(in_array('2', $tag_values_array)){
|
||||
$goods['tag2'] = 1;
|
||||
$detail['tag2'] = 1;
|
||||
}
|
||||
if(in_array('3', $tag_values_array)){
|
||||
$goods['tag3'] = 1;
|
||||
$detail['tag3'] = 1;
|
||||
}
|
||||
if(in_array('4', $tag_values_array)){
|
||||
$goods['tag4'] = 1;
|
||||
$detail['tag4'] = 1;
|
||||
}
|
||||
if(in_array('5', $tag_values_array)){
|
||||
$goods['tag5'] = 1;
|
||||
$detail['tag5'] = 1;
|
||||
}
|
||||
if(in_array('6', $tag_values_array)){
|
||||
$goods['tag6'] = 1;
|
||||
$detail['tag6'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $goods;
|
||||
return $detail;
|
||||
}
|
||||
|
||||
//插入关键字
|
||||
|
@ -5,8 +5,8 @@
|
||||
<table class="layui-hide" id="list" lay-filter="list"></table>
|
||||
</div>
|
||||
<script type="text/html" id="toolbarDemo">
|
||||
<div class="layui-btn-container">
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm addNew" type="button">+ 添加功能模块</button>
|
||||
<div>
|
||||
<span class="red">模块功能即将推出,该列表目前只是预设数据,不影响开发者进行二次开发。</span>
|
||||
</div>
|
||||
</script>
|
||||
{/block}
|
||||
|
Loading…
x
Reference in New Issue
Block a user