...
|
...
|
@@ -14,22 +14,42 @@ class ChanceEventsController extends HomebaseController { |
|
|
|
|
|
protected $chance_events_model;
|
|
|
protected $chance_events_apply_model;
|
|
|
protected $order_model;
|
|
|
|
|
|
function _initialize() {
|
|
|
parent::_initialize(); // TODO: Change the autogenerated stub
|
|
|
$this->chance_events_model = D('Common/ChanceEvents');
|
|
|
$this->chance_events_apply_model = D('Common/ChanceEventsApply');
|
|
|
$this->order_model = D('Common/Order');
|
|
|
}
|
|
|
|
|
|
// 活动列表
|
|
|
public function index() {
|
|
|
$user_id = sp_get_current_userid();
|
|
|
$list = $this->chance_events_model->where(array('is_del'=>0))->order(array('stime'=>'DESC'))->select();
|
|
|
foreach($list as $k=>$v) {
|
|
|
$is_apply = 0;
|
|
|
$count = $this->chance_events_apply_model->where(array('cid'=>$v['id']))->count();
|
|
|
$list[$k]['surplus'] = $v['num'] - $count;
|
|
|
$applyInfo = $this->chance_events_apply_model->where(array('cid'=>$v['id'],'user_id'=>$user_id))->find();
|
|
|
if($applyInfo) {
|
|
|
$is_apply = 1;
|
|
|
$is_pay = $applyInfo['is_pay'];
|
|
|
// $order_id = $this->order_model->where(array('sheet_id'=>$v['id'],'user_id'=>$user_id))->getField('id');
|
|
|
}
|
|
|
if(strtotime($v['endtime']) < time()) {
|
|
|
$list[$k]['sign'] = '<a href="javascript:;" class="gx-singup gx-disbale">报名已结束</a>';
|
|
|
} else {
|
|
|
if(strtotime($v['starttime']) < time()) {
|
|
|
$list[$k]['sign'] = '<a href="#myModal" class="gx-singup" data-toggle="modal"><span>立即报名</span></a>';
|
|
|
if($is_apply == 1) {
|
|
|
if($is_pay == 1) {
|
|
|
$list[$k]['sign'] = '<a href="javascript:;" class="gx-singup"><span>已报名</span></a>';
|
|
|
} else {
|
|
|
$list[$k]['sign'] = '<a href="'.U('User/Index/apply_pay',array('order_id'=>$order_id)).'" class="gx-singup"><span>去支付</span></a>';
|
|
|
}
|
|
|
} else {
|
|
|
$list[$k]['sign'] = '<a href="#myModal" class="gx-singup" data-toggle="modal"><span>立即报名</span></a>';
|
|
|
}
|
|
|
} else {
|
|
|
$list[$k]['sign'] = '<a href="javascript:;" class="gx-singup gx-disbale">报名未开始</a>';
|
|
|
}
|
...
|
...
|
@@ -42,13 +62,31 @@ class ChanceEventsController extends HomebaseController { |
|
|
// 活动详情
|
|
|
public function detail() {
|
|
|
$id= I("get.id",0,'intval');
|
|
|
$user_id = sp_get_current_userid();
|
|
|
|
|
|
$info = $this->chance_events_model->where(array('id'=>$id,'is_del'=>0))->find();
|
|
|
if(strtotime($info['endtime']) < time()) {
|
|
|
$info['sign'] = '<a href="javascript:;" class="gx-singup gx-disbale">报名已结束</a>';
|
|
|
} else {
|
|
|
if(strtotime($info['starttime']) < time()) {
|
|
|
$info['sign'] = '<a href="#myModal" class="gx-singup" data-toggle="modal"><span>立即报名</span></a>';
|
|
|
$is_apply = 0;
|
|
|
$count = $this->chance_events_apply_model->where(array('cid'=>$info['id']))->count();
|
|
|
$info['surplus'] = $info['num'] - $count;
|
|
|
$applyInfo = $this->chance_events_apply_model->where(array('cid'=>$info['id'],'user_id'=>$user_id))->find();
|
|
|
if($applyInfo) {
|
|
|
$is_apply = 1;
|
|
|
$is_pay = $applyInfo['is_pay'];
|
|
|
$order_id = $this->order_model->where(array('sheet_id'=>$info['id'],'user_id'=>$user_id))->getField('id');
|
|
|
}
|
|
|
if($is_apply == 1) {
|
|
|
if($is_pay == 1) {
|
|
|
$info['sign'] = '<a href="javascript:;" class="gx-singup"><span>已报名</span></a>';
|
|
|
} else {
|
|
|
$info['sign'] = '<a href="'.U('User/Index/apply_pay',array('order_id'=>$order_id)).'" class="gx-singup"><span>去支付</span></a>';
|
|
|
}
|
|
|
} else {
|
|
|
$info['sign'] = '<a href="#myModal" class="gx-singup" data-toggle="modal"><span>立即报名</span></a>';
|
|
|
}
|
|
|
} else {
|
|
|
$info['sign'] = '<a href="javascript:;" class="gx-singup gx-disbale">报名未开始</a>';
|
|
|
}
|
...
|
...
|
@@ -69,15 +107,40 @@ class ChanceEventsController extends HomebaseController { |
|
|
if(!$user_id) {
|
|
|
$this->ajaxReturn(array('status'=>false,'msg'=>'用户未登录'));
|
|
|
}
|
|
|
M('ChanceEventsApply')->startTrans();
|
|
|
$post['ctime'] = $post['utime'] = time();
|
|
|
if(!$this->chance_events_apply_model->create($post)) {
|
|
|
M('ChanceEventsApply')->rollback();
|
|
|
$this->ajaxReturn(array('status'=>false,'msg'=>$this->chance_events_apply_model->getError()));
|
|
|
}
|
|
|
$id = $this->chance_events_apply_model->add($post);
|
|
|
if(!$id) {
|
|
|
M('ChanceEventsApply')->rollback();
|
|
|
$this->ajaxReturn(array('status'=>false,'msg'=>'提交失败'));
|
|
|
}
|
|
|
$this->ajaxReturn(array('status'=>true,'msg'=>'提交成功'));
|
|
|
$chanceEventsInfo = $this->chance_events_model->getInfo($post['cid']);
|
|
|
// 如需支付,添加支付订单
|
|
|
$order_sn = $info['order_sn'] = sp_get_order_sn();
|
|
|
$info['user_id'] = $user_id;
|
|
|
$info['price_count'] = $chanceEventsInfo['price'];
|
|
|
$info['ctime'] = time();
|
|
|
$info['sort'] = 2;
|
|
|
$info['sheet'] = 'ChanceEvents';
|
|
|
$info['sheet_id'] = $post['cid'];
|
|
|
if($chanceEventsInfo['is_pay'] == 0) {
|
|
|
$info['price_count'] = 0;
|
|
|
$info['status'] = 2;
|
|
|
}
|
|
|
$order_id = $this->order_model->add($info);
|
|
|
if(!$order_id) {
|
|
|
M('ChanceEventsApply')->rollback();
|
|
|
$this->ajaxReturn(array('status'=>false,'msg'=>'支付订单生成失败'));
|
|
|
}
|
|
|
if($chanceEventsInfo['is_pay'] == 1) {
|
|
|
$redirect_url = U('User/Index/apply_pay',array('order_id'=>$order_id));
|
|
|
}
|
|
|
M('ChanceEventsApply')->commit();
|
|
|
$this->ajaxReturn(array('status'=>true,'msg'=>'提交成功','data'=>$redirect_url));
|
|
|
} else {
|
|
|
$this->error('非法操作');
|
|
|
}
|
...
|
...
|
|