作者 xieweiping
1 个管道 的构建 通过 耗费 7 秒

课表取消功能

@@ -162,7 +162,19 @@ class CourseStore extends Backend @@ -162,7 +162,19 @@ class CourseStore extends Backend
162 public function publish(){ 162 public function publish(){
163 if ($this->request->isPost()) { 163 if ($this->request->isPost()) {
164 $params = $this->request->post(); 164 $params = $this->request->post();
165 - $this->model->save(['status'=>'confirmed'],['id'=>$params['id']]); 165 + $courseStore = $this->model->where(['id'=>$params['id']])->find();
  166 + if(empty($courseStore)){
  167 + $this->error(__('没有课程安排', ''));
  168 + }
  169 + $courseStore = $courseStore->toArray();
  170 +
  171 + if($courseStore['status'] == 'new'){
  172 + $this->model->save(['status'=>'confirmed'],['id'=>$params['id']]);
  173 + }
  174 +
  175 + if($courseStore['status'] == 'confirmed'){
  176 + $this->model->save(['status'=>'cancel'],['id'=>$params['id']]);
  177 + }
166 178
167 $return = $this->model->where(['id'=>$params['id']])->find(); 179 $return = $this->model->where(['id'=>$params['id']])->find();
168 $this->success('ok', null,$return); 180 $this->success('ok', null,$return);
@@ -14,6 +14,7 @@ return [ @@ -14,6 +14,7 @@ return [
14 'Status' => '状态', 14 'Status' => '状态',
15 'confirmed' => '已发布', 15 'confirmed' => '已发布',
16 'new' => '未发布', 16 'new' => '未发布',
  17 + 'cancel' => '已取消',
17 'Publish' => '发布', 18 'Publish' => '发布',
18 'Detail' => '报名情况', 19 'Detail' => '报名情况',
19 ]; 20 ];
@@ -11,8 +11,8 @@ use WeChat\Exceptions\LocalCacheException; @@ -11,8 +11,8 @@ use WeChat\Exceptions\LocalCacheException;
11 use WeMini\Newtmpl; 11 use WeMini\Newtmpl;
12 12
13 /** 13 /**
14 - * 课程接口  
15 - */ 14 +* 课程接口
  15 +*/
16 class Course extends Api 16 class Course extends Api
17 { 17 {
18 protected $noNeedLogin = ['*']; 18 protected $noNeedLogin = ['*'];
@@ -219,26 +219,30 @@ class Course extends Api @@ -219,26 +219,30 @@ class Course extends Api
219 $m = cdnurl($m,true); 219 $m = cdnurl($m,true);
220 } 220 }
221 $course['banner'] = $banner; 221 $course['banner'] = $banner;
222 - //查询门店课程 222 +
  223 +
223 $courseStore = new \app\admin\model\CourseStore(); 224 $courseStore = new \app\admin\model\CourseStore();
224 $where['course_id'] = $id; 225 $where['course_id'] = $id;
225 $where['status'] = 'confirmed'; 226 $where['status'] = 'confirmed';
226 - $where['is_end'] = false;  
227 - $where['end'] = ['>',date('Y-m-d H:i:s')];  
228 if(!empty($store_id)){ 227 if(!empty($store_id)){
229 $where['store_id'] = $store_id; 228 $where['store_id'] = $store_id;
230 } 229 }
231 $courseStore = $courseStore->where($where)->order('date','asc')->select(); 230 $courseStore = $courseStore->where($where)->order('date','asc')->select();
  231 + $store_id = [];
232 $store = []; 232 $store = [];
233 - if(!empty($store_id)){ 233 +
  234 + foreach($courseStore as $k){
  235 + $store_id[$k['store_id']] = $k['store_id'];
  236 +
234 $store1 = new \app\admin\model\Store(); 237 $store1 = new \app\admin\model\Store();
235 - $store1 = $store1->where(['id'=>$store_id])->find(); 238 + $store1 = $store1->where(['id'=>$k['store_id']])->find();
236 $store1 = $store1->toArray(); 239 $store1 = $store1->toArray();
237 $store1['start'] = 2000000000; 240 $store1['start'] = 2000000000;
238 $store1['end'] = 1; 241 $store1['end'] = 1;
239 $store1['course'] = []; 242 $store1['course'] = [];
240 $store[$store_id] = $store1; 243 $store[$store_id] = $store1;
241 } 244 }
  245 +
242 foreach ($courseStore as $k){ 246 foreach ($courseStore as $k){
243 $k['enable'] = true; 247 $k['enable'] = true;
244 if(!empty($user_id)){ 248 if(!empty($user_id)){
@@ -275,15 +279,15 @@ class Course extends Api @@ -275,15 +279,15 @@ class Course extends Api
275 279
276 $course['store'] = array_values($store); 280 $course['store'] = array_values($store);
277 281
278 - /* foreach ($course['store'] as &$k){  
279 - $courseStore = new \app\admin\model\CourseStore();  
280 - $where['course_id'] = $id;  
281 - $where['store_id'] = $k['id'];  
282 - $where['status'] = 'confirmed';  
283 - $where['is_end'] = false;  
284 - $where['end'] = ['>',date('Y-m-d H:i:s')];  
285 - $k['course'] = $courseStore->with('store')->where($where)->order('date','desc')->select();  
286 - }*/ 282 + /* foreach ($course['store'] as &$k){
  283 + $courseStore = new \app\admin\model\CourseStore();
  284 + $where['course_id'] = $id;
  285 + $where['store_id'] = $k['id'];
  286 + $where['status'] = 'confirmed';
  287 + $where['is_end'] = false;
  288 + $where['end'] = ['>',date('Y-m-d H:i:s')];
  289 + $k['course'] = $courseStore->with('store')->where($where)->order('date','desc')->select();
  290 + }*/
287 291
288 //查询评价 292 //查询评价
289 $star = new \app\admin\model\CourseSignStart(); 293 $star = new \app\admin\model\CourseSignStart();
@@ -45,6 +45,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -45,6 +45,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
45 if (value === 'new') { 45 if (value === 'new') {
46 color = 'green'; 46 color = 'green';
47 } 47 }
  48 + if (value === 'cancel') {
  49 + color = 'black';
  50 + }
48 return '<span style="color:' + color + '">' + __(value) + '</span>'; 51 return '<span style="color:' + color + '">' + __(value) + '</span>';
49 }}, 52 }},
50 { 53 {
@@ -64,12 +67,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -64,12 +67,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
64 ], 67 ],
65 events: Table.api.events.operate, formatter: function (value, row, index) { 68 events: Table.api.events.operate, formatter: function (value, row, index) {
66 var that = $.extend({}, this); 69 var that = $.extend({}, this);
67 - that.buttons[0].extend = 'data-publish-id="' + row.id + '"'; 70 + that.buttons[0].extend = 'data-publish-id="' + row.id + '" data-publish-status="' + row.status + '"';
68 that.buttons[1].url = 'course_sign/index?ids=' + row.id; 71 that.buttons[1].url = 'course_sign/index?ids=' + row.id;
69 var table = $(that.table).clone(true); 72 var table = $(that.table).clone(true);
70 if (row.status === 'confirmed') { 73 if (row.status === 'confirmed') {
71 $(table).data("operate-edit", null); 74 $(table).data("operate-edit", null);
72 $(table).data("operate-del", null); 75 $(table).data("operate-del", null);
  76 + that.buttons[0].text = '取消';
  77 + }
  78 + if (row.status === 'cancel') {
  79 + $(table).data("operate-edit", null);
  80 + $(table).data("operate-del", null);
73 $(table).data("operate-publish", null); 81 $(table).data("operate-publish", null);
74 } 82 }
75 if (row.status === 'new') { 83 if (row.status === 'new') {
@@ -89,33 +97,60 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -89,33 +97,60 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
89 //发布 97 //发布
90 $(document).on("click",".btn-publish",function (e) { 98 $(document).on("click",".btn-publish",function (e) {
91 var id = $(this).data('publish-id'); 99 var id = $(this).data('publish-id');
  100 + var status = $(this).data('publish-status');
92 e.stopPropagation(); 101 e.stopPropagation();
93 e.preventDefault(); //事件冒泡阻止 102 e.preventDefault(); //事件冒泡阻止
94 var that = this; 103 var that = this;
95 var table = $(that).closest('table'); 104 var table = $(that).closest('table');
96 var options = table.bootstrapTable('getOptions'); 105 var options = table.bootstrapTable('getOptions');
97 - Layer.open({title: '发布', content: '是否发布此课程', btn: '确定',yes:function (row) {  
98 - $.ajax({  
99 - type : "POST",  
100 - url : "course_store/publish",  
101 - data : {  
102 - id : id  
103 - },  
104 - dataType: "json",  
105 - success : function (data) {  
106 - // console.log(data);  
107 - if (data.code === 1) {  
108 - Layer.msg('发布成功')  
109 - Layer.closeAll()  
110 - $('.btn-refresh').trigger('click')  
111 - } else {  
112 - Layer.msg('发布失败')  
113 - Layer.closeAll()  
114 - } 106 + if(status === 'confirmed'){
  107 + Layer.open({title: '取消', content: '是否取消此课程', btn: '确定',yes:function (row) {
  108 + $.ajax({
  109 + type : "POST",
  110 + url : "course_store/publish",
  111 + data : {
  112 + id : id
  113 + },
  114 + dataType: "json",
  115 + success : function (data) {
  116 + // console.log(data);
  117 + if (data.code === 1) {
  118 + Layer.msg('取消成功');
  119 + Layer.closeAll();
  120 + $('.btn-refresh').trigger('click')
  121 + } else {
  122 + Layer.msg('取消失败');
  123 + Layer.closeAll()
  124 + }
115 125
116 - }  
117 - })  
118 - }}) 126 + }
  127 + })
  128 + }})
  129 + }
  130 + if(status === 'new'){
  131 + Layer.open({title: '发布', content: '是否发布此课程', btn: '确定',yes:function (row) {
  132 + $.ajax({
  133 + type : "POST",
  134 + url : "course_store/publish",
  135 + data : {
  136 + id : id
  137 + },
  138 + dataType: "json",
  139 + success : function (data) {
  140 + // console.log(data);
  141 + if (data.code === 1) {
  142 + Layer.msg('发布成功');
  143 + Layer.closeAll();
  144 + $('.btn-refresh').trigger('click')
  145 + } else {
  146 + Layer.msg('发布失败');
  147 + Layer.closeAll()
  148 + }
  149 +
  150 + }
  151 + })
  152 + }})
  153 + }
119 }); 154 });
120 }, 155 },
121 add: function () { 156 add: function () {