<?php
|
|
namespace app\api\controller\plus\regactivity;
|
|
use app\api\controller\Controller;
|
use app\api\model\plus\regactivity\Activity as ActivityModel;
|
use app\api\model\plus\regactivity\Category as CategoryModel;
|
use app\api\model\plus\regactivity\User as UserModel;
|
use app\api\model\user\BalanceOrder as BalanceOrderModel;
|
use app\common\enum\order\OrderPayTypeEnum;
|
use app\common\enum\order\OrderTypeEnum;
|
|
/**
|
* 活动控制器
|
*/
|
class Index extends Controller
|
{
|
/**
|
*获取分类
|
*/
|
public function category()
|
{
|
// 分类
|
$category = CategoryModel::getAll();
|
return $this->renderSuccess('', compact('category'));
|
}
|
|
/**
|
* 活动列表
|
*/
|
public function index($category_id = 0)
|
{
|
$model = new ActivityModel;
|
$list = $model->getList($category_id, $this->postData());
|
return $this->renderSuccess('', compact('list'));
|
}
|
|
/**
|
*活动详情
|
*/
|
public function detail($activity_id)
|
{
|
$detail = ActivityModel::detail($activity_id);
|
$user = $this->getUser();
|
$detail["balance"]=$user["balance"];
|
return $this->renderSuccess('', compact('detail'));
|
}
|
|
/**
|
*提交活动报名
|
*/
|
public function submit()
|
{
|
$params = $this->request->param();
|
// 用户信息
|
$user = $this->getUser();
|
// 生成报名用户
|
$model = new UserModel();
|
$order_id = $model->addUser($user,$params);
|
if(!$order_id){
|
return $this->renderError($model->getError() ?: '报名失败');
|
}
|
if($params['activity_fee'] > 0){
|
// 处理微信支付
|
$payment = UserModel::onOrderPayment($user, $model, $params['pay_type'], $params['pay_source']);
|
// 返回结算信息
|
return $this->renderSuccess(['success' => '支付成功', 'error' => '未支付'], [
|
'order_id' => $order_id, // 订单id
|
'activity_fee' => $params['activity_fee'], // 活动费用
|
'pay_type' => $params['pay_type'], // 支付方式
|
'payment' => $payment, // 微信支付参数
|
'order_type' => OrderTypeEnum::REGACTIVITY, //订单类型
|
]);
|
}else{
|
return $this->renderSuccess('', compact('order_id'));
|
}
|
}
|
|
}
|