作者 lihan

后端完善活动批次管理相关内容、加入实际报名人数、虚拟报名人数功能,联动前端报名时选择数量功能

@@ -10,21 +10,23 @@ namespace app\admin\controller; @@ -10,21 +10,23 @@ namespace app\admin\controller;
10 use cmf\controller\AdminBaseController; 10 use cmf\controller\AdminBaseController;
11 use think\Db; 11 use think\Db;
12 12
13 -class ActivityController extends AdminBaseController { 13 +class ActivityController extends AdminBaseController
  14 +{
14 15
15 - public function index() {  
16 - $search=[];  
17 - $search['is_del']=['eq', 0];  
18 - $post=request()->param();  
19 - $t_id=(isset($post['t_id'])) ? $post['t_id'] : 0;  
20 - $name=(isset($post['name'])) ? $post['name'] : null;  
21 - if($t_id != 0) {  
22 - $search['t_id']=['eq', $_POST['t_id']];  
23 - }  
24 - if($name != null) {  
25 - $search['name']=['like', "%$_POST[name]%"];  
26 - }  
27 - $res=Db::name('activity')->alias('a') 16 + public function index()
  17 + {
  18 + $search = [];
  19 + $search['is_del'] = ['eq', 0];
  20 + $post = request()->param();
  21 + $t_id = (isset($post['t_id'])) ? $post['t_id'] : 0;
  22 + $name = (isset($post['name'])) ? $post['name'] : null;
  23 + if ($t_id != 0) {
  24 + $search['t_id'] = ['eq', $_POST['t_id']];
  25 + }
  26 + if ($name != null) {
  27 + $search['name'] = ['like', "%$_POST[name]%"];
  28 + }
  29 + $res = Db::name('activity')->alias('a')
28 ->field('a.*,t.type_name,q.qr_code') 30 ->field('a.*,t.type_name,q.qr_code')
29 ->join('type t', 'a.t_id=t.id') 31 ->join('type t', 'a.t_id=t.id')
30 ->join('qr q', 'q.activity_id=a.id') 32 ->join('qr q', 'q.activity_id=a.id')
@@ -40,35 +42,37 @@ class ActivityController extends AdminBaseController { @@ -40,35 +42,37 @@ class ActivityController extends AdminBaseController {
40 ]); 42 ]);
41 } 43 }
42 44
43 - public function add() {  
44 - $request=request();  
45 - if($request->isPost()) {  
46 - $post=$request->param();  
47 - $post['is_down_payment']=(isset($post['is_down_payment'])) ? 1 : 0;  
48 - $post['is_new']=(isset($post['is_new'])) ? 1 : 0;  
49 - $post['is_hot']=(isset($post['is_hot'])) ? 1 : 0;  
50 - $post['is_on_sale']=(isset($post['is_on_sale'])) ? 1 : 0;  
51 - if(!empty($post['thumb'])) { 45 + public function add()
  46 + {
  47 + $request = request();
  48 + if ($request->isPost()) {
  49 + $post = $request->param();
  50 + $post['is_down_payment'] = (isset($post['is_down_payment'])) ? 1 : 0;
  51 + $post['is_new'] = (isset($post['is_new'])) ? 1 : 0;
  52 + $post['is_hot'] = (isset($post['is_hot'])) ? 1 : 0;
  53 + $post['is_on_sale'] = (isset($post['is_on_sale'])) ? 1 : 0;
  54 + $post['date_type'] = 1;
  55 + if (!empty($post['thumb'])) {
52 $post['thumb'] = cmf_get_image_url($post['thumb']); 56 $post['thumb'] = cmf_get_image_url($post['thumb']);
53 } 57 }
54 - if(!empty($post['content'])) { 58 + if (!empty($post['content'])) {
55 $post['content'] = htmlspecialchars_decode($post['content']); 59 $post['content'] = htmlspecialchars_decode($post['content']);
56 } 60 }
57 - if(!empty($post['banner'])) {  
58 - $banner='';  
59 - for($j=0; $j<count($post['banner']); $j++) {  
60 - $banner.=cmf_get_image_url($post['banner'][$j]).','; 61 + if (!empty($post['banner'])) {
  62 + $banner = '';
  63 + for ($j = 0; $j < count($post['banner']); $j++) {
  64 + $banner .= cmf_get_image_url($post['banner'][$j]) . ',';
61 } 65 }
62 - $post['banner']=substr($banner, 0, strlen($banner)-1); 66 + $post['banner'] = substr($banner, 0, strlen($banner) - 1);
63 } 67 }
64 Db::startTrans(); 68 Db::startTrans();
65 - $schedule=$post['schedule']; 69 + $schedule = $post['schedule'];
66 unset($post['schedule']); 70 unset($post['schedule']);
67 - if(Db::name('activity')->insert($post)) {  
68 - $activity_id=Db::name('activity')->getLastInsID();  
69 - $data=[];  
70 - for ($i=0; $i<count($schedule); $i++) {  
71 - $data[$i]=[ 71 + if (Db::name('activity')->insert($post)) {
  72 + $activity_id = Db::name('activity')->getLastInsID();
  73 + $data = [];
  74 + for ($i = 0; $i < count($schedule); $i++) {
  75 + $data[$i] = [
72 'activity_id' => $activity_id, 76 'activity_id' => $activity_id,
73 'start_time' => strtotime($schedule[$i]['start_time']), 77 'start_time' => strtotime($schedule[$i]['start_time']),
74 'end_time' => strtotime($schedule[$i]['end_time']), 78 'end_time' => strtotime($schedule[$i]['end_time']),
@@ -77,98 +81,71 @@ class ActivityController extends AdminBaseController { @@ -77,98 +81,71 @@ class ActivityController extends AdminBaseController {
77 'deadline' => strtotime($schedule[$i]['deadline']) 81 'deadline' => strtotime($schedule[$i]['deadline'])
78 ]; 82 ];
79 } 83 }
80 - if(Db::name('activity_schedule')->insertAll($data)) { 84 + if (Db::name('activity_schedule')->insertAll($data)) {
81 //生成二维码 85 //生成二维码
82 - $qr=[ 86 + $qr = [
83 'activity_id' => $activity_id, 87 'activity_id' => $activity_id,
84 'qr_code' => $this->qrCode($activity_id), 88 'qr_code' => $this->qrCode($activity_id),
85 ]; 89 ];
86 - if(Db::name('qr')->insert($qr)) { 90 + if (Db::name('qr')->insert($qr)) {
87 Db::commit(); 91 Db::commit();
88 $this->success('添加成功'); 92 $this->success('添加成功');
89 - }else { 93 + } else {
90 Db::rollback(); 94 Db::rollback();
91 $this->error('添加失败'); 95 $this->error('添加失败');
92 } 96 }
93 - }else { 97 + } else {
94 Db::rollback(); 98 Db::rollback();
95 $this->error('添加失败'); 99 $this->error('添加失败');
96 } 100 }
97 - }else { 101 + } else {
98 Db::rollback(); 102 Db::rollback();
99 $this->error('添加失败'); 103 $this->error('添加失败');
100 } 104 }
101 - }else { 105 + } else {
102 return $this->fetch('add', [ 106 return $this->fetch('add', [
103 'type' => Db::name('type')->field('id,type_name')->select() 107 'type' => Db::name('type')->field('id,type_name')->select()
104 ]); 108 ]);
105 } 109 }
106 } 110 }
107 111
108 - public function edit() {  
109 - $request=request();  
110 - if($request->isPost()) {  
111 - $post=$request->param();  
112 - $post['is_down_payment']=(isset($post['is_down_payment'])) ? 1 : 0;  
113 - $post['is_new']=(isset($post['is_new'])) ? 1 : 0;  
114 - $post['is_hot']=(isset($post['is_hot'])) ? 1 : 0;  
115 - $post['is_on_sale']=(isset($post['is_on_sale'])) ? 1 : 0;  
116 - if($post['is_down_payment'] == 0) {  
117 - $post['down_price']=0;  
118 - }  
119 - if(!empty($post['thumb'])) { 112 + public function edit()
  113 + {
  114 + $request = request();
  115 + if ($request->isPost()) {
  116 + $post = $request->param();
  117 + $post['is_down_payment'] = (isset($post['is_down_payment'])) ? 1 : 0;
  118 + $post['is_new'] = (isset($post['is_new'])) ? 1 : 0;
  119 + $post['is_hot'] = (isset($post['is_hot'])) ? 1 : 0;
  120 + $post['is_on_sale'] = (isset($post['is_on_sale'])) ? 1 : 0;
  121 + $post['date_type'] = 1;
  122 + if ($post['is_down_payment'] == 0) {
  123 + $post['down_price'] = 0;
  124 + }
  125 + if (!empty($post['thumb'])) {
120 $post['thumb'] = cmf_get_image_url($post['thumb']); 126 $post['thumb'] = cmf_get_image_url($post['thumb']);
121 } 127 }
122 - if(!empty($post['content'])) { 128 + if (!empty($post['content'])) {
123 $post['content'] = htmlspecialchars_decode($post['content']); 129 $post['content'] = htmlspecialchars_decode($post['content']);
124 } 130 }
125 - if(!empty($post['banner'])) {  
126 - $banner='';  
127 - for($j=0; $j<count($post['banner']); $j++) {  
128 - $banner.=cmf_get_image_url($post['banner'][$j]).','; 131 + if (!empty($post['banner'])) {
  132 + $banner = '';
  133 + for ($j = 0; $j < count($post['banner']); $j++) {
  134 + $banner .= cmf_get_image_url($post['banner'][$j]) . ',';
129 } 135 }
130 - $post['banner']=substr($banner, 0, strlen($banner)-1); 136 + $post['banner'] = substr($banner, 0, strlen($banner) - 1);
131 } 137 }
132 - $schedule=(isset($post['schedule'])) ? $post['schedule'] : null;  
133 - if(empty($schedule)) {  
134 - $this->error('请添加批次');  
135 - }  
136 - $schedule=$post['schedule'];  
137 unset($post['schedule']); 138 unset($post['schedule']);
138 - Db::startTrans();  
139 - if(Db::name('activity')->update($post) >= 0) {  
140 - if(Db::name('activity_schedule')->where(['activity_id'=>$request->param('id')])->delete()) {  
141 - $data=[];  
142 - for ($i=0; $i<count($schedule); $i++) {  
143 - $data[$i]=[  
144 - 'activity_id' => $request->param('id'),  
145 - 'start_time' => strtotime($schedule[$i]['start_time']),  
146 - 'end_time' => strtotime($schedule[$i]['end_time']),  
147 - 'price' => $schedule[$i]['price'],  
148 - 'maximum' => $schedule[$i]['maximum'],  
149 - 'deadline' => strtotime($schedule[$i]['deadline'])  
150 - ];  
151 - }  
152 - if(Db::name('activity_schedule')->insertAll($data)) {  
153 - Db::commit(); 139 + if (Db::name('activity')->update($post)) {
154 $this->success('编辑成功'); 140 $this->success('编辑成功');
155 - }else {  
156 - Db::rollback();  
157 - $this->error('编辑失败');  
158 - }  
159 - }else {  
160 - Db::rollback();  
161 - $this->error('编辑失败'); 141 + } else {
  142 + $this->error('您为做出任何修改');
162 } 143 }
163 - }else {  
164 - Db::rollback();  
165 - $this->error('编辑失败');  
166 - }  
167 - }else { 144 + } else {
168 $info = Db::name('activity')->where(['id' => $request->param('id')])->find(); 145 $info = Db::name('activity')->where(['id' => $request->param('id')])->find();
169 $banner = $info['banner']; 146 $banner = $info['banner'];
170 $arr = []; 147 $arr = [];
171 - if(!empty($banner)) { 148 + if (!empty($banner)) {
172 $temp = explode(',', $banner); 149 $temp = explode(',', $banner);
173 for ($i = 0; $i < count($temp); $i++) { 150 for ($i = 0; $i < count($temp); $i++) {
174 $arr[$i]['url'] = $temp[$i]; 151 $arr[$i]['url'] = $temp[$i];
@@ -183,11 +160,12 @@ class ActivityController extends AdminBaseController { @@ -183,11 +160,12 @@ class ActivityController extends AdminBaseController {
183 } 160 }
184 } 161 }
185 162
186 - public function del() {  
187 - $id=request()->param('id');  
188 - if(Db::name('activity')->update(['id'=>$id,'is_del'=>1])) { 163 + public function del()
  164 + {
  165 + $id = request()->param('id');
  166 + if (Db::name('activity')->update(['id' => $id, 'is_del' => 1])) {
189 $this->success('删除成功'); 167 $this->success('删除成功');
190 - }else { 168 + } else {
191 $this->error('删除失败'); 169 $this->error('删除失败');
192 } 170 }
193 } 171 }
@@ -197,7 +175,8 @@ class ActivityController extends AdminBaseController { @@ -197,7 +175,8 @@ class ActivityController extends AdminBaseController {
197 * @param $id 175 * @param $id
198 * @return string 176 * @return string
199 */ 177 */
200 - private function qrCode($id) { 178 + private function qrCode($id)
  179 + {
201 $savePath = APP_PATH . '/../Public/qrcode/'; 180 $savePath = APP_PATH . '/../Public/qrcode/';
202 $webPath = '/qrcode/'; 181 $webPath = '/qrcode/';
203 $qrData = 'https://www.baidu.com'; 182 $qrData = 'https://www.baidu.com';
@@ -208,8 +187,57 @@ class ActivityController extends AdminBaseController { @@ -208,8 +187,57 @@ class ActivityController extends AdminBaseController {
208 if ($filename = createQRcode($savePath, $qrData, $qrLevel, $qrSize, $savePrefix)) { 187 if ($filename = createQRcode($savePath, $qrData, $qrLevel, $qrSize, $savePrefix)) {
209 $pic = $webPath . $filename; 188 $pic = $webPath . $filename;
210 } 189 }
211 - $qr_code=cmf_get_image_url($pic); 190 + $qr_code = cmf_get_image_url($pic);
212 return $qr_code; 191 return $qr_code;
213 } 192 }
214 193
  194 + public function addSchedule()
  195 + {
  196 + $request = request();
  197 + if ($request->isPost()) {
  198 + $post = $request->param();
  199 + $schedule = $post['schedule'];
  200 + $data = [];
  201 + for ($i = 0; $i < count($schedule); $i++) {
  202 + $data[$i] = [
  203 + 'activity_id' => $request->param('activity_id'),
  204 + 'start_time' => strtotime($schedule[$i]['start_time']),
  205 + 'end_time' => strtotime($schedule[$i]['end_time']),
  206 + 'price' => $schedule[$i]['price'],
  207 + 'maximum' => $schedule[$i]['maximum'],
  208 + 'deadline' => strtotime($schedule[$i]['deadline'])
  209 + ];
  210 + }
  211 + if (Db::name('activity_schedule')->insertAll($data)) {
  212 + $this->success('新增批次成功');
  213 + } else {
  214 + $this->error('新增批次失败');
  215 + }
  216 + } else {
  217 + return $this->fetch('add_schedule', [
  218 + 'activity_id' => $request->param('id'),
  219 + 'schedule' => Db::name('activity_schedule')->where(['activity_id' => $request->param('id')])->select(),
  220 + ]);
  221 + }
  222 + }
  223 +
  224 + public function delSchedule()
  225 + {
  226 + $schedule_id = request()->param('id');
  227 + if (Db::name('activity_schedule')->delete($schedule_id)) {
  228 + return $this->success('', '', true);
  229 + }
  230 + }
  231 +
  232 + public function editSchedule()
  233 + {
  234 + $post = request()->param();
  235 + $post['start_time'] = strtotime($post['start_time']);
  236 + $post['end_time'] = strtotime($post['end_time']);
  237 + $post['deadline'] = strtotime($post['deadline']);
  238 + if (Db::name('activity_schedule')->update($post)) {
  239 + return $this->success('编辑批次成功', '', true);
  240 + }
  241 + }
  242 +
215 } 243 }
@@ -83,7 +83,7 @@ @@ -83,7 +83,7 @@
83 </tr> 83 </tr>
84 </table> 84 </table>
85 85
86 - <input id="B" type="button" value="新增" style="display: none;"> 86 + <input id="B" type="button" value="新增">
87 <div id="schedule" style="margin-bottom: 20px"> 87 <div id="schedule" style="margin-bottom: 20px">
88 <li id="li_0">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][maximum]">&nbsp;&nbsp;报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][deadline]"></li> 88 <li id="li_0">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][maximum]">&nbsp;&nbsp;报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][deadline]"></li>
89 </div> 89 </div>
@@ -145,16 +145,6 @@ @@ -145,16 +145,6 @@
145 </div> 145 </div>
146 </td> 146 </td>
147 </tr> 147 </tr>
148 -  
149 - <tr>  
150 - <td>  
151 - <div class="radio">  
152 - <label><input type="radio" class="date_type" name="date_type" value="0" checked>单批次</label>&nbsp;&nbsp;  
153 - <label><input type="radio" class="date_type" name="date_type" value="1">多批次</label>  
154 - </div>  
155 - </td>  
156 - </tr>  
157 -  
158 </table> 148 </table>
159 </div> 149 </div>
160 </div> 150 </div>
@@ -221,7 +211,7 @@ @@ -221,7 +211,7 @@
221 }else { 211 }else {
222 $("#B").show(); 212 $("#B").show();
223 } 213 }
224 - var text='<li id="li_0">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][maximum]">&nbsp;&nbsp;<input id="B" type="button" value="新增" style="display: none;">报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][deadline]"></li>' 214 + var text='<li id="li_0">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][maximum]">&nbsp;&nbsp;报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][deadline]"></li>'
225 $("#schedule").html(text); 215 $("#schedule").html(text);
226 }) 216 })
227 217
@@ -243,7 +233,7 @@ @@ -243,7 +233,7 @@
243 $("#B").click(function () { 233 $("#B").click(function () {
244 var length=$("#schedule li").length; 234 var length=$("#schedule li").length;
245 var html=$("#schedule").html(); 235 var html=$("#schedule").html();
246 - var text='<li id="li_'+length+'">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][maximum]">&nbsp;&nbsp;<input id="B" type="button" value="新增" style="display: none;">报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][deadline]">&nbsp;<span><font color="red" onclick="clearHtml('+length+')">删除</font></span></li>' 236 + var text='<li id="li_'+length+'">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][maximum]">&nbsp;&nbsp;报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][deadline]">&nbsp;<span><font color="red" onclick="clearHtml('+length+')">删除</font></span></li>'
247 $("#schedule").html(html+text); 237 $("#schedule").html(html+text);
248 }) 238 })
249 239
  1 +<include file="public@header"/>
  2 +<style type="text/css">
  3 + .pic-list li {
  4 + margin-bottom: 5px;
  5 + }
  6 + .detail{width: 150px!important; display: unset!important;}
  7 + #schedule li{margin-bottom: 10px; list-style: none}
  8 +</style>
  9 +<div class="wrap js-check-wrap">
  10 + <ul class="nav nav-tabs">
  11 + <li><a href="#X">增加批次</a></li>
  12 + </ul>
  13 +
  14 + <div style="padding: 20px">
  15 + <input id="B" type="button" value="新增">
  16 + <form action="{:url('Activity/addSchedule')}" method="post">
  17 + <div id="schedule" style="margin-bottom: 20px">
  18 + <li id="li_0">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule[0][maximum]">&nbsp;&nbsp;报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[0][deadline]"></li>
  19 + </div>
  20 + <div class="form-group">
  21 + <div class="col-sm-offset-2 col-sm-10">
  22 + <input type="hidden" name="activity_id" value="{$activity_id}">
  23 + <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
  24 + <a class="btn btn-default" href="{:url('Activity/index')}">{:lang('BACK')}</a>
  25 + </div>
  26 + </div>
  27 + </form>
  28 + </div>
  29 +</div>
  30 +<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
  31 +<script>
  32 + function showDate() {
  33 + var bootstrapDateTimeInput = $("input.js-bootstrap-datetime");
  34 + if (bootstrapDateTimeInput.length) {
  35 + Wind.css('bootstrapDatetimePicker');
  36 + Wind.use('bootstrapDatetimePicker', function () {
  37 + bootstrapDateTimeInput.datetimepicker({
  38 + language: 'zh-CN',
  39 + format: 'yyyy-mm-dd hh:ii',
  40 + todayBtn: 1,
  41 + autoclose: true
  42 + });
  43 + });
  44 + }
  45 + }
  46 +
  47 + $("#B").click(function () {
  48 + var length=$("#schedule li").length;
  49 + var html=$("#schedule").html();
  50 + var text='<li id="li_'+length+'">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][maximum]">&nbsp;&nbsp;报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][deadline]">&nbsp;<span><font color="red" onclick="clearHtml('+length+')">删除</font></span></li>'
  51 + $("#schedule").html(html+text);
  52 + })
  53 +
  54 + function clearHtml(n) {
  55 + $("#li_"+n).html('');
  56 + }
  57 +</script>
@@ -101,10 +101,19 @@ @@ -101,10 +101,19 @@
101 </tr> 101 </tr>
102 </table> 102 </table>
103 103
104 - <input id="B" type="button" value="新增" <if condition="$info['date_type'] eq '0'">style="display: none";</if>> 104 + <input id="B" type="button" value="新增" style="display: none">
105 <div id="schedule" style="margin-bottom: 20px"> 105 <div id="schedule" style="margin-bottom: 20px">
106 <foreach name="schedule" item="v" key="k"> 106 <foreach name="schedule" item="v" key="k">
107 - <li id="li_{$k}">开始时间:<input value="{$v['start_time']|date='Y-m-d H:i:s', ###}" required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[{$k}][start_time]">&nbsp;&nbsp;结束时间:<input value="{$v['end_time']|date='Y-m-d H:i:s', ###}" required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[{$k}][end_time]">&nbsp;&nbsp;价格:<input value="{$v['price']}" required autocomplete="off" class="form-control detail" type="text" name="schedule[{$k}][price]">&nbsp;&nbsp;允许参加人数:<input value="{$v['maximum']}" required autocomplete="off" class="form-control detail" type="text" name="schedule[{$k}][maximum]">&nbsp;&nbsp;报名截止时间:<input value="{$v.deadline|date='Y-m-d H:i:s', ###}" required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[{$k}][deadline]">&nbsp;&nbsp;<font color="red" onclick="clearHtml({$k})">删除</font></li> 107 + <li id="li_{$k}">
  108 + 开始:<input id="start_time_{$v.id}" value="{$v['start_time']|date='Y-m-d H:i:s', ###}" required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[{$k}][start_time]">&nbsp;&nbsp;
  109 + 结束:<input id="end_time_{$v.id}" value="{$v['end_time']|date='Y-m-d H:i:s', ###}" required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[{$k}][end_time]">&nbsp;&nbsp;
  110 + 价格:<input style="width: 70px!important;" id="price_{$v.id}" value="{$v['price']}" required autocomplete="off" class="form-control detail" type="text" name="schedule[{$k}][price]">&nbsp;&nbsp;
  111 + 名额:<input style="width: 50px!important;" id="maximum_{$v.id}" value="{$v['maximum']}" required autocomplete="off" class="form-control detail" type="text" name="schedule[{$k}][maximum]">&nbsp;&nbsp;
  112 + 参加人数:<input style="width: 50px!important;" id="real_join_num_{$v.id}" value="{$v['real_join_num']}" required autocomplete="off" class="form-control detail" type="text" name="schedule[{$k}][real_join_num_]">&nbsp;&nbsp;
  113 + 虚拟参加人数:<input style="width: 50px!important;" id="addition_join_num_{$v.id}" value="{$v['addition_join_num']}" required autocomplete="off" class="form-control detail" type="text" name="schedule[{$k}][addition_join_num]">&nbsp;&nbsp;
  114 + 报名截止时间:<input id="deadline_{$v.id}" value="{$v.deadline|date='Y-m-d H:i:s', ###}" required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule[{$k}][deadline]">&nbsp;&nbsp;
  115 + <font color="red" onclick="clearHtml({$k}, {$v.id})" style="cursor: pointer">删除</font>
  116 + <font color="#4169e1" onclick="edit({$v.id})" style="cursor: pointer">确定</font></li>
108 </foreach> 117 </foreach>
109 </div> 118 </div>
110 119
@@ -172,16 +181,6 @@ @@ -172,16 +181,6 @@
172 </div> 181 </div>
173 </td> 182 </td>
174 </tr> 183 </tr>
175 -  
176 - <tr>  
177 - <td>  
178 - <div class="radio">  
179 - <label><input <if condition="$info['date_type'] eq '0'">checked</if> type="radio" class="date_type" name="date_type" value="0" checked>单批次</label>&nbsp;&nbsp;  
180 - <label><input <if condition="$info['date_type'] eq '1'">checked</if> type="radio" class="date_type" name="date_type" value="1">多批次</label>  
181 - </div>  
182 - </td>  
183 - </tr>  
184 -  
185 </table> 184 </table>
186 </div> 185 </div>
187 </div> 186 </div>
@@ -270,14 +269,54 @@ @@ -270,14 +269,54 @@
270 $("#B").click(function () { 269 $("#B").click(function () {
271 var length=$("#schedule li").length; 270 var length=$("#schedule li").length;
272 var html=$("#schedule").html(); 271 var html=$("#schedule").html();
273 - var text='<li id="li_'+length+'">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][maximum]">&nbsp;&nbsp;报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][deadline]">&nbsp;&nbsp;<span><font color="red" onclick="clearHtml('+length+')">删除</font></span></li>' 272 + var text='<li id="li_'+length+'">开始时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][start_time]">&nbsp;&nbsp;结束时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][end_time]">&nbsp;&nbsp;价格:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][price]">&nbsp;&nbsp;允许参加人数:<input required autocomplete="off" class="form-control detail" type="text" name="schedule['+length+'][maximum]">&nbsp;&nbsp;报名截止时间:<input required autocomplete="off" onclick="showDate()" class="form-control js-bootstrap-datetime detail" type="text" name="schedule['+length+'][deadline]">&nbsp;&nbsp;<span><font color="red" onclick="clearHtml('+length+', null)">删除</font></span></li>'
274 $("#schedule").html(html+text); 273 $("#schedule").html(html+text);
275 }) 274 })
276 275
277 - function clearHtml(n) {  
278 - $("#li_"+n).html(''); 276 + function clearHtml(n, id) {
  277 + if (id != null) {
  278 + $.ajax({
  279 + url: "{:url('Activity/delSchedule')}",
  280 + data: {
  281 + id: id
  282 + },
  283 + type: "POST",
  284 + dataType: "JSON",
  285 +
  286 + success: function (data) {
  287 + if (data.data == true) {
  288 + $("#li_" + n).html('');
  289 + }
279 } 290 }
  291 + })
  292 + } else {
  293 + $("#li_" + n).html('');
  294 + }
  295 + }
  296 +
  297 + function edit(id) {
  298 + $.ajax({
  299 + url: "{:url('Activity/editSchedule')}",
  300 + data: {
  301 + id: id,
  302 + start_time:$("#start_time_"+id).val(),
  303 + end_time:$("#end_time_"+id).val(),
  304 + price:$("#price_"+id).val(),
  305 + maximum:$("#maximum_"+id).val(),
  306 + real_join_num:$("#real_join_num_"+id).val(),
  307 + addition_join_num:$("#addition_join_num_"+id).val(),
  308 + deadline:$("#deadline_"+id).val()
  309 + },
  310 + type: "POST",
  311 + dataType: "JSON",
280 312
  313 + success: function (data) {
  314 + if(data.data == true) {
  315 + alert(data.msg);
  316 + }
  317 + }
  318 + })
  319 + }
281 </script> 320 </script>
282 </body> 321 </body>
283 </html> 322 </html>
@@ -47,7 +47,11 @@ @@ -47,7 +47,11 @@
47 <td><if condition="$vo['is_hot'] eq '0'"><font color="red">×</font><else/><font color="green"></font></if></td> 47 <td><if condition="$vo['is_hot'] eq '0'"><font color="red">×</font><else/><font color="green"></font></if></td>
48 <td><if condition="$vo['is_on_sale'] eq '0'"><font color="red">下架</font><else/><font color="green">在售</font></if></td> 48 <td><if condition="$vo['is_on_sale'] eq '0'"><font color="red">下架</font><else/><font color="green">在售</font></if></td>
49 <td><img src="{$vo.qr_code}" width="100px" height="100px"></td> 49 <td><img src="{$vo.qr_code}" width="100px" height="100px"></td>
50 - <td><a href="{:url('Activity/edit',['id'=>$vo['id']])}">编辑</a> | <a href="{:url('Activity/del',['id'=>$vo['id']])}" onclick="return isDel()">删除</a></td> 50 + <td>
  51 + <a href="{:url('Activity/edit',['id'=>$vo['id']])}">编辑</a> |
  52 + <a href="{:url('Activity/del',['id'=>$vo['id']])}" onclick="return isDel()">删除</a> |
  53 + <a href="{:url('Activity/addSchedule',['id'=>$vo['id']])}">新增批次</a>
  54 + </td>
51 </tr> 55 </tr>
52 </volist> 56 </volist>
53 </table> 57 </table>