renderSuccess('', compact('category')); } /** * 活动列表 */ public function index($category_id = 0) { $model = new ActivityModel; $list = $model->getList($category_id, $this->postData(), $this->getUser()); $words = BranchSettingModel::getItem('words'); return $this->renderSuccess('', compact('list', 'words')); } /** *活动详情 */ public function detail($activity_id) { $detail = ActivityModel::detail($activity_id); $user = $this->getUser(); $detail["balance"] = $user["balance"]; // 余额 $detail["points"] = $user["points"]; // 积分 // 用户是否已报名 $detail['is_reg'] = ActivityUserModel::isReg($user['user_id'], $activity_id); // 用户是否已加入分会 $detail['is_member'] =/*MemberModel::isMember($user['user_id'])*/false; // 用户是否已签到 $detail['is_verify'] = ActivityUserModel::isVerify($user['user_id'], $activity_id); $store = SettingModel::getItem('store'); $detail['store_name'] = $store['name']; // 平台名称 $points = SettingModel::getItem('points'); $detail['points_ratio'] = $points['discount']['discount_ratio']; // 积分抵扣比例 // 获取报名用户列表 $userList = (new ActivityUserModel())->getListForActivity(['activity_id' => $activity_id], false, 7); return $this->renderSuccess('', compact('detail', 'userList')); } /** *提交活动报名 */ public function submit() { $params = json_decode($this->postData()['params'], true); // 用户信息 $user = $this->getUser(); // 生成报名用户 $model = new ActivityUserModel(); if (!$model->addUser($user, $params)) { return $this->renderError($model->getError() ?: '报名失败'); } $order_id = $model['order_id']; // 如果需要在线支付 if ($model['online_money'] > 0) { // 处理微信支付 $payment = ActivityUserModel::onOrderPayment($user, $model['order_no'], $params['pay_type'], $params['pay_source'], $model['online_money']); // 返回结算信息 return $this->renderSuccess(['success' => '支付成功', 'error' => '未支付'], [ 'order_id' => $order_id, // 订单id 'online_money' => $model['online_money'], 'pay_type' => $params['pay_type'], // 支付方式 'payment' => $payment, // 微信支付参数 'order_type' => OrderTypeEnum::BRANCHACTIVITY, //订单类型 ]); } else { return $this->renderSuccess('', compact('order_id')); } } public function getRegistrationInformation($user_id = 0,$activity_id=0) { // 生成报名用户 $model = new ActivityUserModel(); $user=$this->getUser(); $userId = $user_id!=0?$user_id:$user['user_id']; $registrationInformation = $model->getRegistrationInformation($userId,$activity_id); return $this->renderSuccess('', compact('registrationInformation')); } /** * 生成活动海报 */ public function poster($activity_id, $source) { // 活动详情 $detail = ActivityModel::detail($activity_id); $Qrcode = new BranchActivityService($detail, $this->getUser(false), $source); return $this->renderSuccess('', [ 'qrcode' => $Qrcode->getImage(), ]); } /** * 获取活动相册 */ public function fileLists($activity_id) { $data = $this->postData(); $model = new ActivityFileModel; $list = $model->getList($activity_id, $data); return $this->renderSuccess('', compact('list')); } /** * 检查用户是否有足够积分下载活动文件 */ public function checkUserPoints($points = 0) { $is_enough = false; $user = $this->getUser(); if ($user['points'] >= $points) { $is_enough = true; } return $this->renderSuccess('', compact('is_enough')); } /** * 获取活动相关积分设置 */ public function pointsSetting() { $setting = BranchSettingModel::getItem('basic'); return $this->renderSuccess('', compact('setting')); } /** * 获取文件路径 */ public function getFilePath($file_id, $is_original = false) { $detail = ActivityFileModel::detail(['file_id' => $file_id], ['original']); $file_path = $is_original ? $detail['original_path'] : $detail['file_path']; return $this->renderSuccess('', compact('file_path')); } /** * 扣除积分 */ public function deductPoints($points) { $user = $this->getUser(); $describe = "下载活动文件消费"; $user->setIncPoints(-$points, $describe); return $this->renderSuccess('', '扣除成功'); } /** * 活动商品列表 **/ public function productLists($activity_id) { $model = new ActivityModel(); $activityDetail = $model->detail(['activity_id'=>$activity_id],[]); if (!$activityDetail) { return $this->renderError('活动不存在'); } if ($activityDetail['status_text']['status'] != 1) { return $this->renderError('活动未开始'); } $data = $this->postData(); $user = $this->getUser(); $check_result = $model->checkUserCanSome($activityDetail,$user,$data); if(!$check_result){ return $this->renderError($model->getError()); } $list = $model->getGoodsList($activity_id); $cart_total_num = ( new ActivityCartModel())->where(['activity_id'=>$activity_id,'user_id'=>$user['user_id']])->count(); return $this->renderSuccess('', compact('list','cart_total_num', 'activityDetail')); } }