作者 sgj

add goods admin

@@ -59,9 +59,49 @@ class ShopController extends AdminBaseController @@ -59,9 +59,49 @@ class ShopController extends AdminBaseController
59 public function goodAdd(){ 59 public function goodAdd(){
60 if (request()->isAjax()){ 60 if (request()->isAjax()){
61 $data=input(); 61 $data=input();
62 - dump($data); 62 + if (!empty( $data['post']['content'])){
  63 + $data['post']['content']=saveContent($data['post']['content']);
  64 + }
  65 + $img=input('photo_urls/a');
  66 + if (!empty($img)){
  67 + $data['post']['pic']=json_encode($img,true);
  68 + }
  69 + $data['post']['add_time']=time();
  70 + $result=$this->GoodsModel->insert($data['post']);
  71 + if ($result==1){
  72 + $this->success('添加成功!');
  73 + }
63 } 74 }
64 return $this->fetch(); 75 return $this->fetch();
65 } 76 }
66 77
  78 +
  79 + public function goodedit(){
  80 + if (request()->isAjax()){
  81 + $map['id']=input('id');
  82 +
  83 + $data=input();
  84 + if (!empty( $data['post']['content'])){
  85 + $data['post']['content']=saveContent($data['post']['content']);
  86 + }
  87 +
  88 + $img=input('photo_urls/a');
  89 + if (!empty($img)){
  90 + $data['post']['pic']=json_encode($img,true);
  91 + }
  92 +
  93 + $result=$this->GoodsModel->where($map)->Update($data['post']);
  94 + if ($result==1){
  95 + $this->success('修改成功!');
  96 + }else{
  97 + $this->error('修改失败!');
  98 + }
  99 + }else{
  100 + $id=input('id');
  101 + $good=$this->GoodsModel->where('id',$id)->find();
  102 + $good['pic']=json_decode($good['pic'],true);
  103 + $this->assign('good',$good);
  104 + return $this->fetch();
  105 + }
  106 + }
67 } 107 }
@@ -18,4 +18,6 @@ class GoodsModel extends Model @@ -18,4 +18,6 @@ class GoodsModel extends Model
18 return $goods; 18 return $goods;
19 } 19 }
20 20
  21 +
  22 +
21 } 23 }
  1 +<include file="public@header"/>
  2 +<style type="text/css">
  3 + .pic-list li {
  4 + margin-bottom: 5px;
  5 + }
  6 +</style>
  7 +<script type="text/html" id="photos-item-tpl">
  8 + <li id="saved-image{id}">
  9 + <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
  10 + <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
  11 + style="width: 200px;" title="图片名称">
  12 + <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
  13 + onclick="imagePreviewDialog(this.src);">
  14 + <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
  15 + <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
  16 + </li>
  17 +</script>
  18 +<script type="text/html" id="files-item-tpl">
  19 + <li id="saved-file{id}">
  20 + <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
  21 + <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
  22 + style="width: 200px;" title="文件名称">
  23 + <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
  24 + <a href="javascript:uploadOne('图片上传','#file-{id}','file');">替换</a>
  25 + <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
  26 + </li>
  27 +</script>
  28 +</head>
  29 +<body>
  30 +<div class="wrap js-check-wrap">
  31 + <ul class="nav nav-tabs">
  32 + <li><a href="{:url('index')}">商品管理</a></li>
  33 + <li class="active"><a href="">编辑商品</a></li>
  34 + </ul>
  35 + <form action="{:url('goodEdit')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
  36 + <div class="row">
  37 + <div class="col-md-9">
  38 + <table class="table table-bordered">
  39 + <input name="id" type="hidden" value="{$good.id}">
  40 + <tr>
  41 + <th>商品名称<span class="form-required">*</span></th>
  42 + <td>
  43 + <input class="form-control" type="text" name="post[name]"
  44 + id="title" required value="{$good.name}" placeholder="请输入标题"/>
  45 + </td>
  46 + </tr>
  47 +
  48 + <tr>
  49 + <th>简介</th>
  50 + <td>
  51 + <textarea class="form-control" name="post[describe]" style="height: 50px;"
  52 + placeholder="请填写摘要">{$good.describe}</textarea>
  53 + </td>
  54 + </tr>
  55 + <tr>
  56 + <th>消耗积分数</th>
  57 + <td>
  58 + <input type="number" class="form-control" name="post[fee]" style="height: 50px;"
  59 + value="{$good.fee}">
  60 + </td>
  61 + </tr>
  62 + <tr>
  63 + <th>内容</th>
  64 + <td>
  65 + <script type="text/plain" id="content" name="post[content]">{:getContent($good.content)}</script>
  66 + </td>
  67 + </tr>
  68 + <tr>
  69 + <th>相册</th>
  70 + <td>
  71 + <ul id="photos" class="pic-list list-unstyled form-inline">
  72 + <notempty name="good.pic">
  73 +
  74 + <foreach name="good.pic" item="vo">
  75 + <php>$img_url=cmf_get_image_preview_url($vo);</php>
  76 + <li id="saved-image{$key}">
  77 + <input id="photo-{$key}" type="hidden" name="photo_urls[]"
  78 + value="{$vo}">
  79 + <img id="photo-{$key}-preview"
  80 + src="{:cmf_get_image_preview_url($vo)}"
  81 + style="height:36px;width: 36px;"
  82 + onclick="parent.imagePreviewDialog(this.src);">
  83 + <a href="javascript:uploadOneImage('图片上传','#photo-{$key}');">替换</a>
  84 + <a href="javascript:(function(){$('#saved-image{$key}').remove();})();">移除</a>
  85 + </li>
  86 + </foreach>
  87 + </notempty>
  88 + </ul>
  89 + <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
  90 + class="btn btn-sm btn-default">选择图片</a>
  91 + </td>
  92 + </tr>
  93 + </table>
  94 + <div class="form-group">
  95 + <div class="col-sm-offset-2 col-sm-10">
  96 + <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('EDIT')}</button>
  97 + <a class="btn btn-default" href="{:url('AdminArticle/index')}">{:lang('BACK')}</a>
  98 + </div>
  99 + </div>
  100 + </div>
  101 + <div class="col-md-3">
  102 + <table class="table table-bordered">
  103 + <tr>
  104 + <th>缩略图</th>
  105 + </tr>
  106 + <tr>
  107 + <td>
  108 + <div style="text-align: center;">
  109 + <input type="hidden" name="post[thumbnail]" id="thumbnail"
  110 + value="{$good.thumbnail|default=''}">
  111 + <a href="javascript:uploadOneImage('图片上传','#thumbnail');">
  112 + <if condition="empty($good.thumbnail)">
  113 + <img src="__TMPL__/public/assets/images/default-thumbnail.png"
  114 + id="thumbnail-preview"
  115 + width="135" style="cursor: pointer"/>
  116 + <else/>
  117 + <img src="{:cmf_get_image_preview_url($good.thumbnail)}"
  118 + id="thumbnail-preview"
  119 + width="135" style="cursor: pointer"/>
  120 + </if>
  121 + </a>
  122 + <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
  123 + </div>
  124 + </td>
  125 + </tr>
  126 + </table>
  127 + </div>
  128 + </div>
  129 + </form>
  130 +</div>
  131 +<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
  132 +<script type="text/javascript">
  133 + //编辑器路径定义
  134 + var editorURL = GV.WEB_ROOT;
  135 +</script>
  136 +<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
  137 +<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
  138 +<script type="text/javascript">
  139 + $(function () {
  140 +
  141 + editorcontent = new baidu.editor.ui.Editor();
  142 + editorcontent.render('content');
  143 + try {
  144 + editorcontent.sync();
  145 + } catch (err) {
  146 + }
  147 +
  148 + $('.btn-cancel-thumbnail').click(function () {
  149 + $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
  150 + $('#thumbnail').val('');
  151 + });
  152 +
  153 + });
  154 + function doSelectUsers() {
  155 + var selectedUsersId = $('#js-users-id-input').val();
  156 + openIframeLayer("{:url('Common/selectUsers')}?ids=" + selectedUsersId, '请选择分类', {
  157 + area: ['1200px', '800px'],
  158 + btn: ['确定', '取消'],
  159 + yes: function (index, layero) {
  160 + //do something
  161 +
  162 + var iframeWin = window[layero.find('iframe')[0]['name']];
  163 + var selectedUsers = iframeWin.confirm();
  164 + if (selectedUsers.selectedUsersId.length == 0) {
  165 + layer.msg('请选择分类');
  166 + return;
  167 + }
  168 + $('#js-users-id-input').val(selectedUsers.selectedUsersId.join(','));
  169 + $('#js-users-name-input').val(selectedUsers.selectedUsersName.join(' '));
  170 + //console.log(layer.getFrameIndex(index));
  171 + layer.close(index); //如果设定了yes回调,需进行手工关闭
  172 + }
  173 + });
  174 + }
  175 +
  176 +
  177 +
  178 +
  179 + function doSelectCategory() {
  180 + console.log('打开页面');
  181 + var selectedCategoriesId = $('#js-categories-id-input').val();
  182 + openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {
  183 + area: ['700px', '400px'],
  184 + btn: ['确定', '取消'],
  185 + yes: function (index, layero) {
  186 + //do something
  187 +
  188 + var iframeWin = window[layero.find('iframe')[0]['name']];
  189 + var selectedCategories = iframeWin.confirm();
  190 + if (selectedCategories.selectedCategoriesId.length == 0) {
  191 + layer.msg('请选择分类');
  192 + return;
  193 + }
  194 + $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
  195 + $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
  196 + //console.log(layer.getFrameIndex(index));
  197 + layer.close(index); //如果设定了yes回调,需进行手工关闭
  198 + }
  199 + });
  200 + }
  201 +</script>
  202 +</body>
  203 +</html>
@@ -29,8 +29,8 @@ @@ -29,8 +29,8 @@
29 <body> 29 <body>
30 <div class="wrap js-check-wrap"> 30 <div class="wrap js-check-wrap">
31 <ul class="nav nav-tabs"> 31 <ul class="nav nav-tabs">
32 - <li><a href="{:url('AdminArticle/index')}">商品管理</a></li>  
33 - <li class="active"><a href="{:url('AdminArticle/add')}">添加商品</a></li> 32 + <li><a href="{:url('index')}">商品管理</a></li>
  33 + <li class="active"><a href="">添加商品</a></li>
34 </ul> 34 </ul>
35 <form action="{:url('goodadd')}" method="post" class="form-horizontal js-ajax-form margin-top-20"> 35 <form action="{:url('goodadd')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
36 <div class="row"> 36 <div class="row">
@@ -44,8 +44,6 @@ @@ -44,8 +44,6 @@
44 id="title" required value="" placeholder="请输入标题"/> 44 id="title" required value="" placeholder="请输入标题"/>
45 </td> 45 </td>
46 </tr> 46 </tr>
47 -  
48 -  
49 <tr> 47 <tr>
50 <th>简介</th> 48 <th>简介</th>
51 <td> 49 <td>
@@ -56,8 +54,8 @@ @@ -56,8 +54,8 @@
56 <tr> 54 <tr>
57 <th>消耗积分数</th> 55 <th>消耗积分数</th>
58 <td> 56 <td>
59 - <textarea class="form-control" name="post[fee]" style="height: 50px;"  
60 - placeholder="请填写摘要"></textarea> 57 + <input type="number" class="form-control" name="post[fee]" style="height: 50px;"
  58 + placeholder="1"></textarea>
61 </td> 59 </td>
62 </tr> 60 </tr>
63 <tr> 61 <tr>
@@ -74,15 +72,6 @@ @@ -74,15 +72,6 @@
74 class="btn btn-default btn-sm">选择图片</a> 72 class="btn btn-default btn-sm">选择图片</a>
75 </td> 73 </td>
76 </tr> 74 </tr>
77 - <tr>  
78 - <th>附件</th>  
79 - <td>  
80 - <ul id="files" class="pic-list list-unstyled form-inline">  
81 - </ul>  
82 - <a href="javascript:uploadMultiFile('附件上传','#files','files-item-tpl');"  
83 - class="btn btn-sm btn-default">选择文件</a>  
84 - </td>  
85 - </tr>  
86 </table> 75 </table>
87 <div class="form-group"> 76 <div class="form-group">
88 <div class="col-sm-offset-2 col-sm-10"> 77 <div class="col-sm-offset-2 col-sm-10">
@@ -99,7 +88,7 @@ @@ -99,7 +88,7 @@
99 <tr> 88 <tr>
100 <td> 89 <td>
101 <div style="text-align: center;"> 90 <div style="text-align: center;">
102 - <input type="hidden" name="post[more][thumbnail]" id="thumbnail" value=""> 91 + <input type="hidden" name="post[thumbnail]" id="thumbnail" value="">
103 <a href="javascript:uploadOneImage('图片上传','#thumbnail');"> 92 <a href="javascript:uploadOneImage('图片上传','#thumbnail');">
104 <img src="__TMPL__/public/assets/images/default-thumbnail.png" 93 <img src="__TMPL__/public/assets/images/default-thumbnail.png"
105 id="thumbnail-preview" 94 id="thumbnail-preview"
@@ -109,39 +98,8 @@ @@ -109,39 +98,8 @@
109 </div> 98 </div>
110 </td> 99 </td>
111 </tr> 100 </tr>
112 - <tr>  
113 - <th><b>发布时间</b></th>  
114 - </tr>  
115 - <tr>  
116 - <td>  
117 - <input class="form-control js-bootstrap-datetime" type="text" name="post[published_time]"  
118 - value="{:date('Y-m-d H:i:s',time())}">  
119 - </td>  
120 - </tr>  
121 - <tr>  
122 - <th><b>状态</b></th>  
123 - </tr>  
124 - <tr>  
125 - <td>  
126 - <div class="checkbox">  
127 - <label><input type="checkbox" name="post[post_status]" value="1" checked>发布</label>  
128 - </div>  
129 - </td>  
130 - </tr>  
131 - <tr>  
132 - <td>  
133 - <div class="checkbox">  
134 - <label><input type="checkbox" name="post[is_top]" value="1">置顶</label>  
135 - </div>  
136 - </td>  
137 - </tr>  
138 - <tr>  
139 - <td>  
140 - <div class="checkbox">  
141 - <label><input type="checkbox" name="post[recommended]" value="1">推荐</label>  
142 - </div>  
143 - </td>  
144 - </tr> 101 +
  102 +
145 103
146 </table> 104 </table>
147 </div> 105 </div>
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 <td>{$vo.id}</td> 25 <td>{$vo.id}</td>
26 <td>{$vo.name}</td> 26 <td>{$vo.name}</td>
27 <td><a href="{:url('office',['id'=>$vo.id])}"></a></td> 27 <td><a href="{:url('office',['id'=>$vo.id])}"></a></td>
28 - <td><a class="js-ajax-delete" href="{:url('jobDel',['id'=>$vo.id])}">删除</a></td> 28 + <td><a class="js-ajax-delete" href="{:url('goodDel',['id'=>$vo.id])}">删除</a><br/><a href="{:url('goodEdit',['id'=>$vo.id])}">查看</a></td>
29 </tr> 29 </tr>
30 </foreach> 30 </foreach>
31 </tbody> 31 </tbody>
@@ -195,6 +195,14 @@ function cmf_get_user_avatar_url($avatar) @@ -195,6 +195,14 @@ function cmf_get_user_avatar_url($avatar)
195 195
196 } 196 }
197 197
  198 +function saveContent($info){
  199 + return cmf_replace_content_file_url(htmlspecialchars_decode($info),true);
  200 +}
  201 +
  202 +function getContent($info){
  203 + return cmf_replace_content_file_url(htmlspecialchars_decode($info));
  204 +}
  205 +
198 /** 206 /**
199 * CMF密码加密方法 207 * CMF密码加密方法
200 * @param string $pw 要加密的原始密码 208 * @param string $pw 要加密的原始密码