diff --git a/app/admin/controller/MallNews.php b/app/admin/controller/MallNews.php index 8107e6f9..3f56ed1b 100755 --- a/app/admin/controller/MallNews.php +++ b/app/admin/controller/MallNews.php @@ -99,6 +99,7 @@ class MallNews extends AdminBase return view(); } + // 快讯商品列表 public function shop() { if ($this->request->isAjax()) { @@ -109,6 +110,7 @@ class MallNews extends AdminBase return view(''); } + // 添加快讯商品 public function add_shop() { if ($this->request->isAjax()) { @@ -123,4 +125,37 @@ class MallNews extends AdminBase 'max_upload_file' => MallNewsLogic::$MAX_UPLOAD_FILE, ]); } + + // 修改快讯商品 + public function audit_shop() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $result = MallNewsLogic::edit_shop($post); + if ($result['code'] == 1) { + return JsonServer::success('修改成功'); + } + return JsonServer::error($result['msg']); + } + + $id = $this->request->get('id'); + return view('', [ + 'detail' => MallNewsLogic::shop_detail($id), + 'max_upload_file' => MallNewsLogic::$MAX_UPLOAD_FILE, + ]); + } + + // 删除快讯商品 + public function del_shop() + { + if ($this->request->isAjax()) { + $post = $this->request->post(); + $result = MallNewsLogic::del_shop($post['id']); + if ($result) { + return JsonServer::success('删除成功'); + } + + return JsonServer::error('删除失败'); + } + } } \ No newline at end of file diff --git a/app/admin/logic/MallNewsLogic.php b/app/admin/logic/MallNewsLogic.php index c8582084..6b3a1db5 100755 --- a/app/admin/logic/MallNewsLogic.php +++ b/app/admin/logic/MallNewsLogic.php @@ -186,11 +186,11 @@ class MallNewsLogic extends Logic // 快讯商品列表 public static function shop_list($get) { - $where[] = ['delete_time', '=', 0]; + $where[] = ['mns.delete_time', '=', 0]; $model = new MallNewsShop(); $lists = $model->alias('mns') ->join('goods g', 'mns.shop_id = g.id') - ->field('mns.id, g.id, g.name, g.image') + ->field('mns.id, g.id as gid, g.name, g.image') ->where($where) ->order('mns.create_time desc') ->paginate([ @@ -203,6 +203,24 @@ class MallNewsLogic extends Logic return ['count' => $lists['total'], 'lists' => $lists['data']]; } + // 获取快讯商品详情 + public static function shop_detail($id) + { + $result = MallNewsShop::with('files')->where(['id' => $id, 'delete_time' => 0])->find(); + if (isset($result['files'])) { + foreach ($result['files'] as &$v) { + if ($result['type'] == 0) { + $v['src'] = UrlServer::getFileUrl('uploads/images/' . $v['src']); + } else { + $v['src'] = Config::get('aliyunoss.domain') . self::$FILE_VIDEO_PATH . '/'. $v['src']; + } + } + } + + $result['shop'] = Db::name('goods')->where('id', $result['shop_id'])->find(); + return $result; + } + // 创建快讯商品 public static function create_shop($post) { @@ -222,6 +240,44 @@ class MallNewsLogic extends Logic return ['code' => 1, 'msg' => '添加成功']; } + // 修改表单信息 + public static function edit_shop($post) + { + $arr['shop_id'] = $post['shop_id']; + $arr['content'] = $post['content']; + $arr['update_time'] = time(); + + MallNewsShop::where('id', $post['id'])->update($arr); + + if (isset($post['mall_news_images'])) { + MallNewsFile::where('mall_news_shop_id', $post['id'])->delete(); + + foreach ($post['mall_news_images'] as &$v) { + MallNewsFile::create([ + 'mall_news_shop_id' => $post['id'], + 'src' => basename($v) + ]); + } + } + + return ['code' => 1, 'msg' => '修改成功']; + } + + // 删除文章 + public static function del_shop($id) + { + $result = MallNewsShop::where([ + 'id' => $id + ])->update([ + 'delete_time' => time(), + ]); + + if ($result) { + return true; + } + return false; + } + private static function checkForm(&$form) { if (empty($form)) { diff --git a/app/admin/view/mall_news/audit_shop.html b/app/admin/view/mall_news/audit_shop.html new file mode 100755 index 00000000..5bc8f5ba --- /dev/null +++ b/app/admin/view/mall_news/audit_shop.html @@ -0,0 +1,225 @@ +{layout name="layout2" /} + + +
+ + + + \ No newline at end of file diff --git a/app/admin/view/mall_news/shop.html b/app/admin/view/mall_news/shop.html index 6a0c2754..499fb015 100755 --- a/app/admin/view/mall_news/shop.html +++ b/app/admin/view/mall_news/shop.html @@ -128,7 +128,7 @@ layer.open({ type: 2 , title: '编辑' - , content: '{:url("mallNews/audit")}?id=' + obj.data.id + , content: '{:url("mallNews/audit_shop")}?id=' + obj.data.id , area: ['90%', '90%'] ,btn: ['确定', '取消'] , yes: function (index, layero) { @@ -138,7 +138,7 @@ iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) { var field = data.field; like.ajax({ - url: '{:url("mallNews/audit")}', + url: '{:url("mallNews/audit_shop")}', data: field, type: "post", success: function (res) { @@ -156,9 +156,9 @@ }, // 删除 del: function (obj) { - layer.confirm('确定要删除该文章吗?', function (index) { + layer.confirm('确定要删除该快讯商品吗?', function (index) { like.ajax({ - url: '{:url("mallNews/del")}', + url: '{:url("mallNews/del_shop")}', data: {id: obj.data.id}, type: "post", success: function (res) {