123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- namespace app\controller\api;
- use app\service\api\UserServiceFacade;
- use app\service\MoneyServiceFacade;
- use app\service\ConfServiceFacade;
- use laytp\controller\Api;
- use laytp\library\Random;
- use laytp\traits\Error;
- use think\facade\Db;
- /**
- * 会员相关
- * @ApiWeigh (90)
- */
- class Commission extends Api
- {
- use Error;
- protected function _initialize()
- {
- $this->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);
- }
- }
|