1]; $list = Db::name('active')->field('content',true)->where($where)->order('weigh desc')->autopage()->select(); $list = list_domain_image($list,['images']); if(!empty($list)){ foreach($list as $key => &$item){ //第一个图 $item['image'] = isset($item['images'][0]) ? $item['images'][0] : ''; //状态 $status_text = '进行中'; $status = 2; if(time() < $item['activestarttime']){ $status_text = '报名中'; $status = 1; } if(time() > $item['activeendtime']){ $status_text = '已结束'; $status = 3; } $item['status_text'] = $status_text; $item['active_status'] = $status; } } $this->success(1,$list); } public function info(){ $id = input('id',0); $info = Db::name('active')->where('is_show',1)->where('id',$id)->find(); if(!$info){ $this->error('不存在的活动'); } $info = info_domain_image($info,['images']); $info['tags'] = !empty($info['tags']) ? explode(',',$info['tags']) : []; //几人已报名 $info['payednumber'] = Db::name('order')->where('active_id',$id)->where('status',1)->count(); $this->success(1,$info); } //报名 public function join(){ $remark = input('remark',0); $active_id = input('id',0); $info = Db::name('active')->where('is_show',1)->where('id',$active_id)->find(); if(!$info){ $this->error('不存在的活动'); } $student_id = input('student_id',0); if(!$student_id){ $this->error('请选择学生'); } //匹配学生 $check = Db::name('user_student')->where('id',$student_id)->where('user_id',$this->auth->id)->find(); if(!$check){ $this->error('不存在的学生'); } //重复报名 $map = [ 'active_id' => $active_id, 'user_id' => $this->auth->id, 'student_id' => $student_id, 'status' => 1, ]; $check = Db::name('order')->where($map)->find(); if($check){ $this->error('该学生已经报名本次活动'); } Db::startTrans(); //下单 $data = [ 'order_no' => createUniqueNo('A',$this->auth->id), 'active_id' => $active_id, 'user_id' => $this->auth->id, 'student_id' => $student_id, 'createtime' => time(), 'pay_fee' => $info['pay_fee'], 'status' => 0, 'remark' => $remark, ]; $order_id = Db::name('order')->insertGetId($data); if(!$order_id){ Db::rollback(); $this->error('报名失败'); } Db::commit(); $this->success(1,$order_id); } }