model = new \app\model\commission\Team(); } // 检测 public function auth() { $loginUserInfo = UserServiceFacade::getUserInfo(); $modelUser = new \app\model\commission\User(); $res = $modelUser::where('uid','=',$loginUserInfo['id'])->find(); if(!$res){ return $this->error('不是分销商',2); } $res['money_total'] = \app\model\commission\Income::where(['uid'=>$loginUserInfo['id']])->sum('money'); $res['on_cashout_money'] =\app\model\commission\Cashout::where(['uid'=>$loginUserInfo['id'],'status'=>0])->sum('extract_price'); return $this->success('数据获取成功', $res); } // 申请分销商 public function apply() { global $_GPC; $modelUser = new \app\model\commission\User(); $post = $this->request->post(); $realName = $this->request->post('real_name',''); $telnum = $this->request->post('telnum',''); if(!$realName || !$telnum){ return $this->error('请上传姓名或手机号'); } $loginUserInfo = UserServiceFacade::getUserInfo(); $conf = ConfServiceFacade::groupGet('system.commission', 0); $res = $modelUser::where('uid','=',$loginUserInfo['id'])->find(); $status =0; if(!empty($conf['is_examine']) && $conf['is_examine'] == 2){ $status = 1; } $post['uid'] = $loginUserInfo['id']; $post['uniacid'] = $_GPC['uniacid']; $post['status'] = $status; $post['paid'] = 0; if(!$res){ $a = $modelUser->save($post); return $this->success('数据获取成功', $a); } return $this->success('数据获取成功', $res); } // 完善提现信息 public function update() { global $_GPC; $modelUser = new \app\model\commission\User(); $post = $this->request->post(); if(!($post['qrcode_wechat'])){ return $this->error('修改失败,请上传二维码'); } $loginUserInfo = UserServiceFacade::getUserInfo(); $updateRes = $modelUser->where('uid', '=', $loginUserInfo['id'])->update($post); if (!$updateRes) return $this->error('数据更新失败'); return $this->success('获取结果', $post); } public function teamList() { global $_GPC; $loginUserInfo = UserServiceFacade::getUserInfo(); $where = ['pid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']]; $order = ['create_time' => 'desc']; $param = $this->request->param(); $limit = $this->request->param('limit', 10); $level = $this->request->param('level', 1); if($level == 1){ $data = $this->model->where($where)->with(['userinfo','payMoney'])->withCount(['question','gallery'])->order($order)->paginate($limit)->each(function ($item){ $item->payTotal = 0; foreach ($item->payMoney ?? [] as $value){ $item->payTotal += $value->pay_price; } unset($item->payMoney); })->toArray(); }elseif($level == 2){ $data = $this->model->where(['gid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']])->with(['userinfo','payMoney'])->withCount(['question','gallery'])->paginate($limit)->each(function ($item){ $item->payTotal = 0; foreach ($item->payMoney ?? [] as $value){ $item->payTotal += $value->pay_price; } unset($item->payMoney); })->toArray(); }elseif($level == 3){ $data = $this->model->where(['gfid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']])->with(['userinfo','payMoney'])->withCount(['question','gallery'])->paginate($limit)->each(function ($item){ $item->payTotal = 0; foreach ($item->payMoney ?? [] as $value){ $item->payTotal += $value->pay_price; } unset($item->payMoney); })->toArray(); } if(!$data){ return $this->error('数据获取失败'); } return $this->success('数据获取成功', $data); } // 加入团队 public function addTeam() { global $_GPC; $loginUserInfo = UserServiceFacade::getUserInfo(); $spm = $this->request->post('spm',0); if(!$spm){ return $this->error('数据获取失败,请上传spm',2); } $arr = explode('.',$spm); $shareuid = $arr[0]; if($shareuid == 0){ return $this->error('分销商用户id不能为0',2); } if($shareuid == $loginUserInfo['id']){ return $this->error('不能邀请自己',2); } $sharecheck = \app\model\commission\User::where(['uid'=>$shareuid])->find(); if(empty($sharecheck) && $sharecheck['status']!=1){ return $this->error('分享者不是分销商',2); } $sharecheckUserInfo = \app\model\User::where(['id'=>$shareuid])->find(); if($loginUserInfo['create_time_int'] < $sharecheckUserInfo['create_time_int']){ return $this->error('被绑定用户注册时间大于分销商用户注册时间',2); } $check = $this->model->where(['uid'=>$loginUserInfo['id']])->find(); if($check){ return $this->error('已经绑定,无需重复绑定',2); } // 说明没被绑定过 $gid = 0; $gfid = 0; // 查shareuid的信息 $pinfo = $this->model->where(['uid'=>$shareuid])->find(); if($pinfo){ if($loginUserInfo['id'] == $pinfo['pid']){ return $this->error('绑定关系错误,不支持逆向绑定',2); } $gid = $pinfo['pid']; if(!empty($pinfo['gid'])){ if($loginUserInfo['id'] == $pinfo['gid']){ return $this->error('绑定关系错误,不支持逆向绑定',2); } $gfid = $pinfo['gid']; } } $a = $this->model->save(['uid'=>$loginUserInfo['id'],'pid'=>$shareuid,'gid'=>$gid,'gfid'=>$gfid,'uniacid'=>$_GPC['uniacid'] ]); if(!$a){ return $this->error('数据获取失败'); } return $this->success('数据获取成功', $a); } // 申请提现 public function extract() { global $_GPC; $loginUserInfo = UserServiceFacade::getUserInfo(); $post = $this->request->post(); $extractPrice = $this->request->post('extract_price',0); $modelUser = new \app\model\commission\User(); $modelCashout = new \app\model\commission\Cashout(); $commissionUser = $modelUser::where('uid','=',$loginUserInfo['id'])->find(); if(!$commissionUser){ return $this->error('未找到您的分销信息'); } if($commissionUser['money'] < $extractPrice){ return $this->error('金额不足'); } if($extractPrice <= 0){ return $this->error('提现金额不能小于或等于0元'); } $mark = ''; $platform = $this->request->post('platform','wxOfficialAccount'); $post['uid'] = $loginUserInfo['id']; $post['uniacid'] = $_GPC['uniacid']; // if(!$post['real_name']) return $this->error('姓名输入有误'); if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $post['extract_price'])) return $this->error('提现金额输入有误'); $mark = '使用微信提现' . $post['extract_price'] . '元'; if($platform =='wxOfficialAccount' ){ $post['extract_type'] = 'wechat'; }else{ $post['extract_type'] = 'miniapp'; } $balance = bcsub($commissionUser['money'],$extractPrice,2) ?? 0; $post['balance'] = $balance;//用户余额 $post['mark'] = $mark; $saveRes = $modelCashout->save($post); if (!$saveRes) return $this->error('保存基础信息失败'); $balanceRes = \app\model\commission\User::where(['uid'=>$loginUserInfo['id']])->update(['money' => $balance]); return $this->success('数据获取成功', $saveRes); } // 收入记录 public function incomeLog() { global $_GPC; $order = ['id' => 'desc']; $modelIncome = new \app\model\commission\Income(); $loginUserInfo = UserServiceFacade::getUserInfo(); $where = ['uid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']]; $post = $this->request->param(); $limit = $this->request->param('limit', 10); $data = $modelIncome->order($order)->with(['userinfo','buy_userinfo'])->where($where)->paginate($limit)->toArray(); if(!$data){ return $this->error('数据获取失败'); } return $this->success('数据获取成功', $data); } // 提现记录 public function cashoutLog() { global $_GPC; $order = ['id' => 'desc']; $modelCashout = new \app\model\commission\Cashout(); $loginUserInfo = UserServiceFacade::getUserInfo(); $where = ['uid'=>$loginUserInfo['id'],'uniacid'=>$_GPC['uniacid']]; $post = $this->request->param(); $limit = $this->request->param('limit', 10); $data = $modelCashout->order($order)->where($where)->paginate($limit)->toArray(); if(!$data){ return $this->error('数据获取失败'); } return $this->success('数据获取成功', $data); } // 排行榜 public function ranking() { global $_GPC; $where = ['uniacid'=>$_GPC['uniacid']]; $model = new \app\model\commission\User(); $post = $this->request->param(); // $where[] = ['pm' ,'=', 1]; $order = ['income_sum' => 'desc']; $limit = $this->request->param('limit', 10); $data = $model->order($order)->where($where)->with('userinfo')->withSum('income','money')->paginate($limit)->toArray(); if(!$data){ return $this->error('数据获取失败'); } return $this->success('数据获取成功', $data); } }