| | |
| | | |
| | | 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) |
| | |
| | | { |
| | | $detail = ActivityModel::detail($params["activity_id"]); |
| | | // 如果用户还没加入连盟并且不是帮朋友报名 |
| | | if (!$params['is_member'] && !$params['is_friend']) { |
| | | /*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, |
| | | ]; |
| | | // 如果是帮朋友报名,把用户信息记录下来 |
| | |
| | | $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) { |
| | |
| | | } |
| | | return $this; |
| | | } |
| | | public function getRegistrationInformation($user_id,$activity_id=0) |
| | | { |
| | | $list=$this->where('user_id', '=', $user_id) |
| | | ->order('create_time', 'desc')->find(); |
| | | $data=[ |
| | | 'province_id'=>'', |
| | | 'city_id'=>'', |
| | | 'region_id'=>'', |
| | | 'recommend_name'=>'', |
| | | 'recommend_mobile'=>'', |
| | | 'real_name'=>'', |
| | | 'mobile'=>'', |
| | | 'branch_id'=>'', |
| | | 'company'=>'', |
| | | 'branch_name'=>'', |
| | | 'region'=>'', |
| | | ]; |
| | | 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'], |
| | |
| | | $detail->save($data); |
| | | // 发放奖励 |
| | | $setting = BranchSettingModel::getItem('basic'); |
| | | if ($setting['participate_user'] > 0) { |
| | | $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($setting['participate_user'], $describe); |
| | | $user->setIncPoints($participate_points, $describe); |
| | | } |
| | | return true; |
| | | } |