1]; $list = Db::name('active')->field('content',true)->where($where)->order('weigh desc')->autopage()->select(); $list = list_domain_image($list,['image']); if(!empty($list)){ foreach($list as $key => &$item){ $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['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,['image']); $this->success(1,$info); } //报名 public function join(){ $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, ]; $check = Db::name('order')->where($map)->find(); if($check){ if($check['status'] == 0){ $this->error('您已经报名,请及时支付'); } $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, ]; $order_id = Db::name('order')->insertGetId($data); if(!$order_id){ Db::rollback(); $this->error('报名失败'); } //支付订单 $pay_order = [ 'user_id' => $this->auth->id, 'out_trade_no' => $data['order_no'], 'order_amount' => $info['pay_fee'], 'createtime' => time(), 'pay_type' => 'wechat', 'platform' => 'miniapp', 'order_status' => 0, 'table_name' => 'order', 'table_id' => $order_id, ]; $order_id = Db::name('pay_order')->insertGetId($data); if(!$order_id){ Db::rollback(); $this->error('报名失败'); } //拉起支付 $notifyurl = $this->request->root(true) . '/api/notify/order_notify_base/paytype/wechat'; $returnurl = config('h5_url') . '/#/pages/public/paySuc'; $params = [ 'type' => 'wechat', 'orderid' => $pay_order['out_trade_no'], 'title' => '报名活动', 'amount' => $pay_order['order_amount'], 'method' => 'miniapp', 'openid' => $this->auth->mini_openid, 'notifyurl' => $notifyurl, 'returnurl' => $returnurl, ]; $res = Service::submitOrder($params); $this->success('success',json_decode($res,true)); } }