| | |
| | | |
| | | namespace app\api\model\branch; |
| | | |
| | | use app\api\model\user\User; |
| | | use app\common\enum\order\OrderPayTypeEnum; |
| | | use app\common\model\branch\ActivityUser as ActivityUserModel; |
| | | use app\api\model\branch\Member as MemberModel; |
| | |
| | | use app\common\model\user\BalanceLog as BalanceLogModel; |
| | | use app\common\model\branch\User as BranchUserModel; |
| | | use app\common\model\branch\Setting as BranchSettingModel; |
| | | |
| | | use app\common\model\settings\Region as RegionModel; |
| | | use app\api\model\user\User as UserModel; |
| | | /** |
| | | * 用户模型 |
| | | */ |
| | |
| | | ]; |
| | | |
| | | /** |
| | | * 获取报名用户列表 |
| | | * 获取用户报名的活动列表 |
| | | */ |
| | | public function getList($user_id, $params = []) |
| | | public function getListForUser($user_id, $params = []) |
| | | { |
| | | // 构建查询规则 |
| | | $model = $this->alias('A')->with(['activity' => ['branch', 'image']]) |
| | |
| | | { |
| | | // 构建查询规则 |
| | | $model = $this->alias('auser') |
| | | ->field('auser.*,user.nickName,user.real_name,user.avatarUrl') |
| | | ->field('auser.*,user.nickName,auser.real_name,user.avatarUrl') |
| | | ->join('user', 'user.user_id = auser.user_id') |
| | | ->where('auser.is_delete', '=', 0) |
| | | ->where('auser.status', '=', 1) |
| | |
| | | public function addUser($user, $params) |
| | | { |
| | | $detail = ActivityModel::detail($params["activity_id"]); |
| | | // 如果用户还没加入连盟 |
| | | if (!$params['is_member']) { |
| | | // 如果用户还没加入连盟并且不是帮朋友报名 |
| | | /*if (!$params['is_member'] && !$params['is_friend']) { |
| | | $this->addMember($detail, $params, $user); |
| | | } |
| | | }*/ |
| | | // 验证数据 |
| | | if (!$this->validateData($detail, $params, $user)) { |
| | | return false; |
| | | } |
| | | |
| | | $data = [ |
| | | 'user_id' => $user['user_id'], |
| | | 'order_no' => $this->orderNo(), |
| | | 'activity_id' => $detail['activity_id'], |
| | | 'total_price' => $detail['fee'], |
| | | 'pay_price' => $detail['fee'], |
| | | 'points_num' => $params['points_num'], // 积分抵扣数量 |
| | | 'points_money' => $params['points_money'], // 积分抵扣金额 |
| | | 'balance' => $params['balance'], // 余额 |
| | | 'online_money' => $params['online_money'], // 需在线支付的金额 |
| | | 'activity_id' => $detail['activity_id']?:0, |
| | | 'total_price' => $detail['fee']?:0, |
| | | 'pay_price' => $detail['fee']?:0, |
| | | 'points_num' => $params['points_num']?:0, // 积分抵扣数量 |
| | | 'points_money' => $params['points_money']?:0, // 积分抵扣金额 |
| | | 'balance' => $params['balance']?:0, // 余额 |
| | | 'online_money' => $params['online_money']?:0, // 需在线支付的金额 |
| | | 'status' => $params['online_money'] > 0 ? 0 : 1, //报名状态,如果不需要在线支付则则直接报名成功 |
| | | 'pay_type' => $params['pay_type'], |
| | | 'in_radius' => $params['in_radius'], |
| | | 'pay_type' => $params['pay_type']?:0, |
| | | 'in_radius' => $params['in_radius']?:0, |
| | | 'province_id' => $params['province_id']?:0, |
| | | 'city_id' => $params['city_id']?:0, |
| | | 'region_id' => $params['region_id']?:0, |
| | | 'company' => $params['company']?:'', |
| | | 'recommend_name' => $params['recommend_name']?:'', |
| | | 'recommend_mobile' => $params['recommend_mobile']?:'', |
| | | 'real_name' => $params['real_name']?:'', |
| | | 'mobile' => $params['mobile']?:'', |
| | | 'branch_id' => $params['branch_id']?:0, |
| | | 'app_id' => self::$app_id, |
| | | ]; |
| | | // 如果是帮朋友报名,把用户信息记录下来 |
| | | if ($params['is_friend']) { |
| | | $data['real_name'] = $params['real_name']; |
| | | $data['mobile'] = $params['mobile']; |
| | | $data['company'] = $params['company']; |
| | | $data['is_friend'] = 1; |
| | | $data['reg_user_id'] = $user['user_id']; // 记录是谁帮注册的,因为核销的时候会把user_id改为实际报名人的 |
| | | } |
| | | $data['trade_no'] = $data['order_no']; |
| | | $refereeUser=(new UserModel())->where(['real_name'=>$params['recommend_name'],'mobile'=>$params['recommend_mobile']])->find(); |
| | | if ($refereeUser){ |
| | | $data['referee_id']=$refereeUser['user_id']; |
| | | } |
| | | $this->save($data); |
| | | // 如果不需要在线支付 |
| | | if ($data['online_money'] == 0) { |
| | | $this->onPayOffline($data['order_no']); |
| | | } |
| | | return $this; |
| | | |
| | | // $order_id = $this['order_id']; |
| | | // if (!$order_id) { |
| | | // $this->error = '报名失败'; |
| | | // return false; |
| | | // } |
| | | // // 处理支付 |
| | | // if ($detail['fee'] > 0) { |
| | | // // 如果使用了积分 |
| | | // if ($params['points_num']) { |
| | | // $describe = "活动报名消费:{$data['order_no']}"; |
| | | // $user->setIncPoints(-$params['points_num'], $describe); |
| | | // } |
| | | // // 如果使用了余额 |
| | | // if ($params['balance']) { |
| | | // BalanceLogModel::add(BalanceLogSceneEnum::RECHARGE, [ |
| | | // 'user_id' => $user['user_id'], |
| | | // 'money' => $params['balance'], |
| | | // 'app_id' => self::$app_id |
| | | // ], ['order_no' => $data['order_no']]); |
| | | // $user->where('user_id', '=', $user['user_id']) |
| | | // ->dec('balance', $params['balance']) |
| | | // ->update(); |
| | | // } |
| | | // // 如果还需要在线支付 |
| | | // if ($params['online_money']) { |
| | | // $payment = self::onOrderPayment($user, $data['order_no'], $params['pay_type'], $params['pay_source'], $params['online_money']); |
| | | // } else { |
| | | // // 报名直接完成 |
| | | |
| | | // } |
| | | // } |
| | | // return $this['order_id']; |
| | | } |
| | | public function getRegistrationInformation($user_id,$activity_id=0) |
| | | { |
| | | $list=$this->where('user_id', '=', $user_id) |
| | | ->order('create_time', 'desc')->find(); |
| | | $data=[]; |
| | | if ($list){ |
| | | $branch=(new Branch())->detail($list['branch_id']); |
| | | $data=[ |
| | | 'province_id'=>$list['province_id'], |
| | | 'city_id'=>$list['city_id'], |
| | | 'region_id'=>$list['region_id'], |
| | | 'recommend_name'=>$list['recommend_name'], |
| | | 'recommend_mobile'=>$list['recommend_mobile'], |
| | | 'real_name'=>$list['real_name'], |
| | | 'mobile'=>$list['mobile'], |
| | | 'branch_id'=>$list['branch_id'], |
| | | 'company'=>$list['company'], |
| | | 'branch_name'=>$branch?$branch['name']:'', |
| | | 'region'=>RegionModel::getNameById($list['province_id']).','.RegionModel::getNameById($list['city_id']).','.RegionModel::getNameById($list['region_id']), |
| | | |
| | | ]; |
| | | } |
| | | if($activity_id){ |
| | | $activity=(new ActivityModel())->find($activity_id); |
| | | if ($activity){ |
| | | $data['activity_number']=(new ActivityModel())->where(['branch_id'=>$activity['branch_id'],'category_id'=>$activity['category_id']])->count(); |
| | | } |
| | | } |
| | | return $data; |
| | | } |
| | | public function addMember($activity, $params, $user) |
| | | { |
| | | $data = [ |
| | | 'user_id' => $user['user_id'], |
| | | 'branch_id' => $activity['branch_id'], |
| | | 'branch_id' => $params['branch_id'], |
| | | 'real_name' => $params['real_name'], |
| | | 'mobile' => $params['mobile'], |
| | | 'company' => $params['company'], |
| | |
| | | return PaymentService::wechat( |
| | | $user, |
| | | $order_no, |
| | | OrderTypeEnum::MASTER, |
| | | OrderTypeEnum::BRANCHACTIVITY, |
| | | $pay_source, |
| | | $online_money |
| | | ); |
| | |
| | | } |
| | | if ($activity["limit_num"] > 0 && $activity["total"] >= $activity["limit_num"]){ |
| | | $this->error = '报名名额已满'; |
| | | return false; |
| | | } |
| | | // 如果是帮朋友报名,验证手机号是不是已报过 |
| | | if ($params['is_friend'] && ActivityUserModel::isRegByFriend($params['mobile'], $activity['activity_id'])) { |
| | | $this->error = '该手机号已经报过名了'; |
| | | return false; |
| | | } |
| | | // 如果需要支付报名费 |
| | |
| | | /** |
| | | * 完成核销 |
| | | */ |
| | | public function onVerify($user, $activity_id) |
| | | public function onVerify($user, $activity_id, $params = []) |
| | | { |
| | | $activity = ActivityModel::detail($activity_id); |
| | | if ($activity['status_text']['status'] == 2) { |
| | | $this->error = '活动已经结束了,不能签到啦'; |
| | | return false; |
| | | } |
| | | $detail = ActivityUserModel::detail(['activity_id' => $activity_id, 'user_id' => $user['user_id']]); |
| | | $detail = ActivityUserModel::detail(['activity_id' => $activity_id, 'user_id' => $user['user_id'], 'is_friend' => 0]); |
| | | if (!$detail) { |
| | | // 如果朋友帮报名 |
| | | if (!empty($params['verify_mobile'])) { |
| | | $detail = ActivityUserModel::detail(['activity_id' => $activity_id, 'mobile' => $params['verify_mobile'], 'is_friend' => 1]); |
| | | if (!$detail) { |
| | | $this->error = '很抱歉,没有找到报名记录'; |
| | | return false; |
| | | } |
| | | // 更新信息 |
| | | $userData = []; |
| | | if ($user['real_name'] == '') { |
| | | $userData['real_name'] = $detail['real_name']; |
| | | } |
| | | if ($user['mobile'] == '') { |
| | | $userData['mobile'] = $detail['mobile']; |
| | | } |
| | | if ($userData) { |
| | | $user->save($userData); |
| | | } |
| | | } else { |
| | | $this->error = 'not_reg'; |
| | | return false; |
| | | } |
| | | } |
| | | if($detail['is_verify'] == 1) { |
| | | $this->error = '您已经签到过啦'; |
| | | return false; |
| | | } |
| | | $detail->save([ |
| | | $data = [ |
| | | 'is_verify' => 1, |
| | | 'verify_time' => time() |
| | | ]); |
| | | ]; |
| | | // 如果是帮报名的签到,将user_id改成真正报名的人 |
| | | if (!empty($params['verify_mobile'])) { |
| | | $data['user_id'] = $user['user_id']; |
| | | } |
| | | $detail->save($data); |
| | | // 发放奖励 |
| | | $setting = BranchSettingModel::getItem('basic'); |
| | | if ($setting['participate_user'] > 0) { |
| | | $describe = "活动签到获得奖励[活动ID:{$activity_id}]"; |
| | | $user->setIncPoints($setting['participate_user'], $describe); |
| | | $participate_points = $setting['participate_user']; |
| | | $member = MemberModel::detail($user['user_id'], ['position']); |
| | | if ($member && $member['position'] && $member['position']['participate_points'] > 0) { |
| | | $participate_points = $member['position']['participate_points']; |
| | | } |
| | | |
| | | if ($participate_points > 0) { |
| | | $describe = "活动签到获得奖励[活动ID:{$activity_id}]"; |
| | | $user->setIncPoints($participate_points, $describe); |
| | | } |
| | | return true; |
| | | } |
| | | |