repository = $repository; $this->source = $this->request->header('source'); $this->merId = $this->request->header('merId'); } /** * 创建环信账户 * @return mixed */ public function hxim_create() { $uid = $this->request->uid(); try { $im = new Im(); $user = Db::name('user')->where('uid', $uid)->field('im_uuid,im_userid as im_user_id,im,uid,nickname,im_password as im_pass')->find(); if (isset($user['im_uuid']) && $user['im_user_id']) { return app('json')->success($user); } $im_user_id = 'user' . $user['uid']; $data = []; $data['im_pass'] = mt_rand(100000, 999999); $data['im_user_id'] = $im_user_id; // 获取用户是否存在 $imUser = $im->getImUser('user' . $uid); if (isset($imUser['activated']) && $imUser['activated'] == true) { $data['im_uuid'] = $imUser['uuid']; } else { $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']); } Db::name('User')->where(['uid' => $uid])->update([ 'im' => 1, 'im_uuid' => $data['im_uuid'], 'im_userid' => $im_user_id, 'im_password' => $data['im_pass'] ]); return app('json')->success($data); } catch (\Exception $e) { Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]); } return app('json')->fail('注册失败'); } /** * @return mixed * @author xaboy * @day 2020/6/22 */ public function we_com() { $where2['mer_id'] = $this->merId; $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find(); return app('json')->success($user); } public function spread_image() { $type = $this->request->param('type'); $res = $type == 'routine' ? $this->repository->routineSpreadImage($this->request->userInfo()) : $this->repository->wxSpreadImage($this->request->userInfo()); return app('json')->success($res); } /** * @return mixed * 分享每日海报 */ public function share_day() { /** * 1242 * 2208 */ $user = $this->request->userInfo(); $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg'; $siteUrl = systemConfig('site_url'); $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);//二维码链接 $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']); if (is_string($imageInfo)) throw new ValidateException('二维码生成失败'); $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg'; $qrcode = $imageInfo['dir']; dump($qrcode); $config = array( 'image' => array( array( 'url' => $qrcode,//二维码资源 'stream' => 0, 'left' => 533, 'top' => 1941, 'right' => 0, 'bottom' => 0, 'width' => 184, 'height' => 182, 'opacity' => 100 ) ), 'background' => $filename ); $data = setSharePoster($config, 'routine/spread/poster'); dump($data); return app('json')->success($data); } public function spread_info() { $user = $this->request->userInfo(); $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']); $data = [ 'lock_brokerage' => $user->lock_brokerage, 'one_level_count' => $user->one_level_count, 'two_level_count' => $user->two_level_count, 'spread_total' => $user->spread_total, 'yesterday_brokerage' => $user->yesterday_brokerage, 'total_extract' => $user->total_extract, 'total_brokerage' => $user->total_brokerage, 'brokerage_price' => $user->brokerage_price, 'member_brokerage_price' => $user->member_brokerage_price, 'now_money' => $user->now_money, 'broken_day' => (int)systemConfig('lock_brokerage_timer') ]; return app('json')->success($data); } //红包 public function hongbao_info(){ log::info("============hongbao"); $user = $this->request->userInfo(); if($user->uid>0){ //已经入账红包 $data['total_source']=$user->hongbao; //为生效红包 $data['no_total_source']=Db::name('user_sign_hongbao')->where('status', -1)->where('uid', $user->uid)->sum('number');; log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}"); return app('json')->success($data); } } public function vr_name() { $uid = $this->request->uid(); $data = [ "name"=>"VR转账", "url"=>'https://show.gdjbp.com/?uid=' .$uid, ]; return app('json')->success($data); } public function hongbao_list(){ $pm = $this->request->param('pm'); [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); log::info("hongbao_list==={$uid}"); $where['uid'] = $uid; if ($pm==0){ $data = DB::name('user_sign_hongbao')->where($where)->where('type', 1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } if($pm==1){ $data = DB::name('user_sign_hongbao')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } if($pm==2){ $data = DB::name('user_sign_hongbao')->where($where)->where('status', -1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } log::info("=======date==={$data}"); return app("json")->success($data); } //贡献值 public function gongxian_info(){ log::info("============gongxianinfo"); $user = $this->request->userInfo(); if($user->uid>0){ // $dateObj=DB::name('user_sign_hongbao')->where('uid', $user->uid)->select(); //已经入账贡献值 $data['total_source']=$user->contribute; //为生贡献值 $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');; log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}"); return app('json')->success($data); } } public function gongxian_list(){ $pm = $this->request->param('pm'); [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); log::info("green_integral_list==={$uid}"); $where['uid'] = $uid; if ($pm==0){ $data = DB::name('user_sign_gongxian')->where($where)->where('status', 1)->field('id,mark,number,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } // if($pm==1){ // $data = DB::name('user_sign_gongxian')->where($where)->where('pm', 2)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select(); // // } if($pm==2){ $data = DB::name('user_sign_gongxian')->where($where)->where('status', -1)->field('id,mark,number,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } log::info("=======date==={$data}"); return app("json")->success($data); } //京豆 public function jingdou_info(){ log::info("============hongbao"); $user = $this->request->userInfo(); if($user->uid>0){ //已经入账京豆 //$data['total_source']=$user->vr;//原件 $data['total_source'] = 0;//临时使用 //为生效京豆 $data['no_total_source']=Db::name('user_sign_jingdou')->where('status', -1)->where('uid', $user->uid)->sum('number');; log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}"); return app('json')->success($data); } } public function jingdou_list(){ return; $pm = $this->request->param('pm'); [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); log::info("jingdou_list==={$uid}"); $where['uid'] = $uid; if ($pm==0){ $data = DB::name('user_sign_jingdou')->where($where)->where('type', 1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } if($pm==1){ $data = DB::name('user_sign_jingdou')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } // if($pm==2){ // $data = DB::name('user_sign_jingdou')->where($where)->where('status', -1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select(); // } // $data['total'] =111; log::info("=======date==={$data}"); return app("json")->success($data); } //复购金 public function fugou_info(){ log::info("============fugou"); $user = $this->request->userInfo(); if($user->uid>0){ //已经入账京豆 $data['total_source']=$user->fugou; //为生效京豆 $data['no_total_source']=Db::name('user_sign_fugou')->where('status', -1)->where('uid', $user->uid)->sum('number');; log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}"); return app('json')->success($data); } } public function fugou_list(){ $pm = $this->request->param('pm'); [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); log::info("fugou_list==={$uid}"); $where['uid'] = $uid; if ($pm==0){ $data = DB::name('user_sign_fugou')->where($where)->where('type', 1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } if($pm==1){ $data = DB::name('user_sign_fugou')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } if($pm==2){ $data = DB::name('user_sign_fugou')->where($where)->where('status', -1)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } log::info("=======date==={$data}"); return app("json")->success($data); } //VR 购物金 public function vr_info(){ log::info("============vr"); $user = $this->request->userInfo(); if($user->uid>0){ //已经入账京豆 $data['total_source'] = $user->vr; //为生效京豆 $data['no_total_source']=0; //$data['no_total_source']=Db::name('user_sign_vr')->where('status', -1)->where('uid', $user->uid)->sum('number');; log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}"); return app('json')->success($data); } } public function vr_list(){ $pm = $this->request->param('pm'); [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); log::info("vr_list==={$uid}"); $where['uid'] = $uid; $data = DB::name('user_sign_vr')->page($page, $limit)->order("id desc")->select(); if ($pm==0){ $data = DB::name('user_sign_vr')->where($where)->where('type', 1)->page($page, $limit)->order("id desc")->select(); } if($pm==2){ $data = DB::name('user_sign_vr')->where($where)->where('type', 2)->page($page, $limit)->order("id desc")->select(); } // if($pm==2){ // $data = DB::name('user_sign_vr')->where($where)->where('status', -1)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select(); // // } log::info("=======date==={$data}"); return app("json")->success($data); } public function spread_info_yhc() { log::info("============ddddddddd"); $user = $this->request->userInfo(); if($user->uid>0){ //已经入账积分 $data['total_source']=$user->score; //为生效积分 $data['no_total_source']=Db::name('user_sign_score')->where('status', -1)->where('uid', $user->uid)->sum('reward_socre');; log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}"); return app('json')->success($data); } // if ($this->source == 'yhc' && $this->merId) { // $where['mer_id'] = $this->merId; // $where['uid'] = $user->uid; // $enterprise_user = Db::name('enterprise_user')->where($where)->find(); // if ($enterprise_user) { // $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额 // $data['unsettled_balance'] = 0;//未结算 // $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price'); // $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现 // $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现 // $data['identity'] = $enterprise_user['identity']; // $data['level'] = $enterprise_user['level']; // $data['partnership'] = $enterprise_user['partnership']; // $data['green_integral'] = $enterprise_user['green_integral']; // $data['green_integral_is'] = $enterprise_user['green_integral_is']; // $data['operate'] = $enterprise_user['operate']; // $data['operate_icon'] = ''; // $data['operate_text'] = ''; // $member_settings = merchantConfig($this->merId, 'member_settings'); // if ($data['operate'] == 101) { // $data['operate_icon'] = $member_settings['yy_one_img']; // $data['operate_text'] = $member_settings['yy_one_text']; // } // if ($data['operate'] == 102) { // $data['operate_icon'] = $member_settings['yy_two_img']; // $data['operate_text'] = $member_settings['yy_two_text']; // } // // // $data['nickname'] = $user->nickname; // $data['avatar'] = $enterprise_user['avatar']; // // $arr = $this->jisuan_fans($user->uid); // $data['fans_num'] = count($arr);//粉丝总数 // // $yanglao = 0; // $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0]; // $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number'); // $yanglao += $offLine1; // $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number'); // $yanglao += $offLine2; // // // $data['ylj'] = set_price_rtrim($yanglao); // // $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money'); // // // $data['uid'] = $enterprise_user['uid']; // if ($enterprise_user['identity'] > 100) { // $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find(); // if (!$data['identity_data']) { // $data['identity_data'] = null; // $data['identity'] = '100'; // } // } else { // $data['identity_data'] = null; // } // // $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find(); // // // return app('json')->success($data); // } // } return app('json')->fail('用户不存在'); } /** * @param UserBillRepository $billRepository * @return mixed * @author xaboy * @day 2020/6/22 */ public function bill(UserBillRepository $billRepository) { [$page, $limit] = $this->getPage(); $where = [ // 'now_money' => $this->request->param('type', 0), 'status' => $this->request->param('status'), ]; if ($this->request->param('is_red') == true) { $where['is_red_brokerage'] = 1; } return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit)); } /** * @param UserBillRepository $billRepository * @return mixed * @author xaboy * @day 2020/6/22 */ public function brokerage_list(UserBillRepository $billRepository) { [$page, $limit] = $this->getPage(); return app('json')->success($billRepository->userList([ 'category' => 'brokerage', ], $this->request->uid(), $page, $limit)); } /** * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author xaboy * @day 2020/6/22 */ public function spread_order() { [$page, $limit] = $this->getPage(); return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit)); } /** * TODO * @return mixed * @author Qinii * @day 2020-06-18 */ public function binding() { $data = $this->request->params(['phone', 'sms_code']); if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确'); $user = $this->repository->accountByUser($data['phone']); if ($user) { $data = ['phone' => $data['phone']]; } else { $data = ['account' => $data['phone'], 'phone' => $data['phone']]; } $this->repository->update($this->request->uid(), $data); return app('json')->success('绑定成功'); } /** * TODO * @return mixed * @author Qinii * @day 2020-06-18 */ public function binding_verify() { $data = $this->request->params(['user_id', 'captcha']); $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone"); $data['sms_code'] = $data['captcha']; if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确'); return app('json')->success('验证成功'); } public function checkSmsCode($phone, $code) { $sms_key = 'api.auth.sms.' . $phone; if (!$cache_code = Cache::get($sms_key)) return false; if ($code != $cache_code) return false; Cache::delete($sms_key); return true; } /** * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author xaboy * @day 2020/6/22 */ public function spread_list() { [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true); $uid = $this->request->uid(); [$page, $limit] = $this->getPage(); return app('json')->success($level == 2 ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit) : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit)); } /** * @return mixed * @author xaboy * @day 2020/6/22 */ public function spread_top() { [$page, $limit] = $this->getPage(); $type = $this->request->param('type', 0); return app('json')->success($type == 1 ? $this->repository->spreadMonthTop($page, $limit) : $this->repository->spreadWeekTop($page, $limit)); } /** * @return mixed * @author xaboy * @day 2020/6/22 */ public function brokerage_top() { [$page, $limit] = $this->getPage(); $type = $this->request->param('type', 0); return app('json')->success($type == 1 ? $this->repository->brokerageMonthTop($page, $limit) : $this->repository->brokerageWeekTop($page, $limit)); } public function history(UserVisitRepository $repository) { $uid = $this->request->uid(); [$page, $limit] = $this->getPage(); return app('json')->success($repository->getHistory($uid, $page, $limit)); } public function deleteHistory($id, UserVisitRepository $repository) { $uid = $this->request->uid(); if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid])) return app('json')->fail('数据不存在'); $repository->delete($id); return app('json')->success('删除成功'); } public function account() { $user = $this->request->userInfo(); if (!$user->phone) return app('json')->fail('请绑定手机号'); return app('json')->success($this->repository->selfUserList($user->phone)); } public function switchUser() { $uid = (int)$this->request->param('uid'); if (!$uid) return app('json')->fail('用户不存在'); $userInfo = $this->request->userInfo(); if (!$userInfo->phone) return app('json')->fail('请绑定手机号'); $user = $this->repository->switchUser($userInfo, $uid); $tokenInfo = $this->repository->createToken($user); $this->repository->loginAfter($user); return app('json')->success($this->repository->returnToken($user, $tokenInfo)); } /** * 签到 获取积分 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function sub_signin() { $member_id = $this->request->uid(); if (!$member_id) return app('json')->fail('用户不存在'); $res = $this->repository->sub_signin($member_id); return app('json')->success($res); } /** * 获取用户签到记录 * data1 开始时间 * data2 结束时间 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function get_signin() { $member_id = $this->request->uid(); if (!$member_id) return app('json')->fail('用户不存在'); $where = []; $data1 = input('data1'); $data2 = input('data2'); if ($data1 && $data2) { $where["data1"] = $data1; $where["data2"] = $data2; } $res = $this->repository->get_signin($member_id, $where); return app('json')->success($res); } /** * 提交实名认证 * * @return void */ public function add_certification() { $member_id = $this->request->uid(); $type = input("type", 0); if ($type == 1) { $data = $this->repository->get_cer(["uid" => $member_id]); return app('json')->success($data); } if (!$member_id) return app('json')->fail('用户不存在'); $params = $this->request->params([ 'user_name', 'mobile', 'user_card', 'card_positive', 'card_reverse', ]); $params['create_time'] = time(); $params['uid'] = $member_id; $baidu = new Ocr(); $image = file_get_contents($params['card_positive']); $idCardSide = "front"; $result = $baidu->idcard($image, $idCardSide); $real_user_name = $result['words_result']['姓名']['words'] ?? ''; $real_user_card = $result['words_result']['公民身份号码']['words'] ?? ''; if ($real_user_name != $params['user_name']) { return app('json')->fail('姓名或身份证号输入有误~'); } if ($real_user_card != $params['user_card']) { return app('json')->fail('姓名或身份证号输入有误~'); } if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) { $params['status'] = 1; $res = $this->repository->add_cer($params, $member_id); if ($res) { //赠送积分 完善实名送90个积分,同时送邀请人50个积分 $this->sign_add($member_id, 90,1,'完善实名系统赠送90个积分','',''); $member_info = Db::name('user')->where( array('uid' => $member_id) )->find(); if($member_info['spread_uid']){ //好友完善实名系统赠送50个积分 $spreadUid = $member_info['spread_uid']; $this->sign_add($spreadUid, 50,1,'好友完善实名系统赠送50个积分','',''); } return app('json')->success($res); } else { return app('json')->fail('认证失败'); } } else { return app('json')->fail('认证失败,请重新认证'); } } /** * @param int $uid 用户ID * @param string $score 积分 * @param int $status 积分状态 * @param string $mark 备注 * @param string $has_qian 连续签到天数 * @param string $today_signintime 签到时间 * @param int $order_id 订单ID * @param int $pm 1-收入。2-支出 * @param string $order_type * @throws DbException */ public function sign_add($uid, $score, $status, $mark, $has_qian = '', $today_signintime = '', $order_id = 0, $pm = 1, $order_type = '',$type='',$settlement_time = '') { if(!in_array($type,[1,2])){ // 其他情况都直接返回,因为目前只有365专区购买才可以获得 return false; } $ins_data['uid'] = $uid; $ins_data['continuity_day'] = $has_qian; $ins_data['reward_socre'] = $score; $ins_data['signin_time'] = $today_signintime; $ins_data['addtime'] = time(); $ins_data['status'] = $status; $ins_data['mark'] = $mark; $ins_data['type'] = $type; $ins_data['settlement_time'] = $settlement_time;// 结算时间 真正到了结算时间会结算 $ins_data['order_id'] = $order_id; $ins_data['pm'] = $pm; $ins_data['order_type'] = $order_type; Db::name('user_sign_score')->insertGetId($ins_data); if($pm == 1 && $status == 1){ Db::name('user')->where('uid',$uid)->inc('score', $score)->update(); } if($pm == 2){ Db::name('user')->where('uid', $uid)->dec('score', $score)->update(); } } /** * 申请代理 * name:公司名称 * identity:身份 * license:营业执照 */ public function apply_agent() { $name = input("name", ""); $identity = input("identity", 1); $license = input("license", ""); $province_id = input("province_id", ""); $city_id = input("city_id", ""); $area_id = input("area_id", ""); $street_id = input("street_id", ""); $spread_account = input("spread_account", ""); $member_id = $this->request->uid(); if ($identity != 6 && (!$name || !$identity || !$license)) { return app('json')->fail('请检查参数'); } if ($identity == 6 && (!$name || !$identity)) { return app('json')->fail('请检查参数'); } $data = [ "name" => $name, "identity" => $identity, "license" => $license, "user_id" => $member_id, "province_id" => $province_id, "city_id" => $city_id, "area_id" => $area_id, "street_id" => $street_id, 'spread_account' => $spread_account, "add_time" => time(), "update_time" => time() ]; $res = $this->repository->agent($data); if ($res['code'] == 400) { return app('json')->fail($res['msg']); } return app('json')->success("申请成功", $res); } /*查询是否有已申请或者审核中的代理信息*/ public function isAgent() { $uid = $this->request->uid(); $data = $this->repository->isAgent($uid); return app("json")->success($data); } /*查询是否有审核成功的未支付或支付失败的订单*/ public function AgentPayDetail() { $uid = $this->request->uid(); if (!$uid) { return app('json')->fail('请检查参数'); } $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid]; $data = $this->repository->getAgentPayDetail($where); return app('json')->success("成功", $data); } /** * 获取信息 全民营销首页 * @return mixed */ public function get_agent_info() { $member_id = $this->request->uid(); $res = $this->repository->get_agent_info($member_id); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 推广统计 * search 搜索 * @return mixed */ public function get_extension_info() { $search = input("search", ""); $where = $this->request->params(["identity"]); $member_id = $this->request->uid(); $res = $this->repository->get_extension_info($member_id, $search, $where); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 收益统计 * type 搜索 * @return mixed */ public function get_profit_info() { $where = $this->request->params([ 'commission_type', 'date_on', 'date_off', 'order' ]); $member_id = $this->request->uid(); $res = $this->repository->get_profit_info($member_id, $where); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 订单统计 * search 搜索 * @return mixed */ public function get_tuiguang_order() { $member_id = $this->request->uid(); $res = $this->repository->get_tuiguang_order($member_id); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /* * 攒金明细统计 * */ public function get_commission_all() { $uid = $this->request->uid(); $where['date_on'] = 1; $where['date_off'] = 0; // $where['commission_type'] = ''; $date = $this->request->params(['date']);//"today","yesterday","week","month","year" $where['order'] = $date['date']; $res = $this->repository->get_profit_info($uid, $where); return app('json')->success($res); } /* * 攒金明细列表 * */ public function get_commission_list() { $uid = $this->request->uid(); [$where['page'], $where['limit']] = $this->getPage(); $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year" $where['type'] = $data['type'];//0线上;1线下 $where['order'] = $data['date'];//"today","yesterday","week","month","year" $res = $this->repository->get_tuiguang_list($uid, $where); return app('json')->success($res); } /* * 越攒越多佣金 * */ public function get_com_list() { $uid = $this->request->uid(); [$where['page'], $where['limit']] = $this->getPage(); $data = $this->request->params(['date']);//"today","yesterday","week","month","year" $where['order'] = $data['date'];//"today","yesterday","week","month","year" $res = $this->repository->get_com_list($uid, $where); return app('json')->success($res); } /* * 越攒越多统计 * */ public function get_com_all() { $uid = $this->request->uid(); $data = $this->request->params(['date']);//"today","yesterday","week","month","year" $where['order'] = $data['date'];//"today","yesterday","week","month","year" $res = $this->repository->get_com_all($uid, $where); return app('json')->success($res); } /** * 养老金详情 * @return mixed */ public function get_yanglao() { $member_id = $this->request->uid(); $res = $this->repository->get_yanglao($member_id); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 养老金明细 */ public function yanglaolog() { $member_id = $this->request->uid(); [$page, $limit] = $this->getPage(); $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0]; if ($this->source == 'yhc' && $this->merId) { $where['mer_id'] = $this->merId; } $month = $this->request->param('month', '');//年月搜索 $status = $this->request->param('status', 1); //1-全部 2-已结算 3-未结算 4-已取消 if ($status == 2) { $where['status'] = 1; } else if ($status == 3) { // $where['gzc']=0; $where['status'] = 0; } else if ($status == 4) { $where['status'] = -1; } $source = $this->request->param('source', -1); if ($source > -1) { $where['source'] = $source; } $res = $this->repository->yanglaolog($where, $page, $limit, $month); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /*养老金详情*/ public function YangLaoDetail($id) { $member_id = $this->request->uid(); $data = $this->request->params([ 'type', ]); $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id]; $res = $this->repository->yanglaoDetail($where); return app('json')->success($res); } /** * 消费明细 * @return mixed */ public function tripartite() { $member_id = $this->request->uid(); $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]]; $res = $this->repository->yanglaolog($where); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 提现明细 * @return mixed */ public function withdrawal() { $member_id = $this->request->uid(); $data = $this->request->params([ 'type', ]); $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2]; if ($this->source == 'yhc') { $where['mer_id'] = $this->merId; } $res = $this->repository->withdrawal_user($where); if ($res) { return app('json')->success($res); } else { return app('json')->fail('获取失败'); } } /** * 提现详情 * @return mixed * @author cabbage * @day 2020/10/31 */ public function withdrawalDetail() { $member_id = $this->request->uid(); $extract_id = input("extract_id", 0); return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id)); } /* * 修改个人信息*/ public function updateUser() { $data = $this->request->params([ 'nickname', 'avatar', 'sex', 'birthday', 'addres', 'mark' ]); $uid = $this->request->uid(); $res = ''; if ($this->source == 'yhc') { $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]); unset($data['avatar']); } $data = $this->repository->updateUser($uid, $data); if ($data || $res) { return app("json")->success("修改成功", $data); } return app("json")->fail("未做任何修改"); } /*积分记录*/ public function socreList() { [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); $data = $this->repository->socreList($uid, $page, $limit); return app("json")->success($data); } function jisuan_fans($uid) { $where22['node_uid'] = $uid; $where22['mer_id'] = $this->merId; $arr = $this->jisuantuandui($where22); $where['puid'] = $uid; $where['mer_id'] = $this->merId; $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');//直属粉丝数量 $result = array_unique(array_merge($arr, $direct_fans)); return $result; } function jisuantuandui($where, $data = []) { $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid'); $arr = array_merge($data, $enterprise_user_team); foreach ($enterprise_user_team as $v) { $where['node_uid'] = $v; $arr = $this->jisuantuandui($where, $arr); } return $arr; } /** * 一壶茶-团队列表 */ public function team_list_1() { $teamid = $this->request->uid(); //$teamid = $this->request->param('teamid');//测试ID $teamid = 17; $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员 $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推 if(!empty($datas_jbp)){ $team_userinfo_old_jbp1 = $this->getPerformance($teamid); //判断大小团队(业绩多的是大部门,业绩小的是小部门) $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人 // 获取分页参数 $data1= [ "total"=>100, "per_page"=> 10, "current_page"=> 1, "last_page"=> 1, ]; if($type != 2){ //小部门和大部门列表数据 foreach($tes as $k=>$v){ $curr_pv = ''; if($v['curr_type']==0){ $curr_pv = $team_userinfo_old_jbp1['person_nums_pv']; }else if($v['curr_type']==1){ $curr_pv = $team_userinfo_old_jbp1['common_nums_pv']; }else{ $curr_pv = 0; } $data1['data'][$k] = [ "uid"=>$v["id"], "nickname"=> $v['user_name'] . $curr_pv, "phone"=> "137****3315", "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png", "create_time"=>"2025-01-25 11:00:18", "identity"=>"11", "level"=> "40002", "partnership"=>"22", "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩 "new_performance"=> 0,//新增业绩 "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数) ]; } }else{ //直推列表 foreach($tes as $k=>$v){ $data1['data'][$k] = [ "uid"=>$v["uid"], "nickname"=> $v['nickname'], "avatar"=>$v['avatar'], "create_time"=>"2025-01-25 11:00:18", ]; } } $data['team_list'] = $data1; $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数 $data['new_performance'] = 0;//新增业绩 $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩 $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟 $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟 $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV // $data['effective_fans_num'] = DB::name('enterprise_user') } //var_dump($data); //把新表中的新增邀请用户加到数组中 //$spread_usersdata = Db::name('user')->where("spread_uid",$teamid)->select();//查询旗下会员 // 查询当前会员旗下的会员数据 // 获取分页参数 [$page, $limit] = $this->getPage(); // 查询当前会员旗下的会员数据(分页) $subordinate_members = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $teamid) // 查询旗下会员 ->where("so.mer_id", 496) // ->where("so.douhuomall", 1) // ->where("so.douhuomall_status", 9) // ->where("so.status", 0) ->group('u.uid') // 确保每个用户只出现一次 ->page($page, $limit) // 分页查询 ->select(); // 获取分页数据 //计算团队总业绩 // $total_amount=0; // foreach($subordinate_members as $k=>$v){ // } // 获取总会员数 $total_members = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $teamid) // 查询旗下会员 ->where("so.mer_id", 496) // ->where("so.douhuomall", 1) // ->where("so.douhuomall_status", 9) // ->where("so.status", 0) ->group('u.uid') // 确保每个用户只出现一次 ->page($page, $limit) // 分页查询 ->count(); // 获取分页数据 // 构造分页信息 $data1 = [ "total" => $total_members, "per_page" => $limit, "current_page" => $page, "last_page" => ceil($total_members / $limit), "data" => [] ]; $total_amount_pv_team = 0;//计算总业绩 //获取团队总数量 $team_count_total = 0; $small_count = 0;//小部门人数 //var_dump($this->calculatePerformance($subordinate_members)); //获取大小部门数据(新表) $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);//下标0是大部门 //var_dump( $get_big_small_datas); //判断大小部门的人数(根据业绩多的就是大部门,业绩小的就是小部门来计算展示的部门人数); $big_team_count = $get_big_small_datas[0]['team_count']; $smallteam_count = $get_big_small_datas[1]['team_count']; //end // 遍历分页数据,构造每个会员的详细信息 foreach ($subordinate_members as $k => $v) { //计算自己和旗下的业绩 $t_teams_pv = $this->calculatePerformance($v['uid']); $total_amount_pv_team += $t_teams_pv['total_performance']; $data1['data'][$k] = [ "uid" => $v["uid"], "nickname" => $v['nickname'], // 假设昵称字段为 nickname "phone" => substr_replace($v['phone'], '****', 3, 4), // 隐藏手机号中间四位 "avatar" => $v['avatar'], // 假设头像字段为 avatar "create_time" => $v['create_time'], // 假设创建时间为 create_time "total_performance" => $t_teams_pv['total_performance'], // 假设总业绩字段需要额外计算 "new_performance" => $t_teams_pv['total_performance'], // 假设新增业绩字段需要额外计算 "team_count" => $t_teams_pv['team_count'], // 假设团购人数需要额外计算 ]; } // 根据 type 参数处理数据 if ($type == 1) { // 大部门:取 total_performance 最大的一个数组 usort($data1['data'], function ($a, $b) { return $b['total_performance'] <=> $a['total_performance']; }); $data1['data'] = array_slice($data1['data'], 0, 1); // 只保留最大的一个 } elseif ($type == 0) { // 小部门:去掉 total_performance 最大的一个数组 usort($data1['data'], function ($a, $b) { return $b['total_performance'] <=> $a['total_performance']; }); $data1['data'] = array_slice($data1['data'], 1); // 去掉第一个 } elseif ($type == 2) { // 直推:不做任何处理 } // 构造最终返回的数据 $data = [ 'team_list' => $data1, 'fans_num' => $get_big_small_datas[0]['team_count'] + $get_big_small_datas[1]['team_count'], // 粉丝数 'new_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 新增业绩 'total_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 总业绩 'person_nums' => $big_team_count, // 大部门人数 'common_nums' => $smallteam_count, // 小部门人数 'common_nums_pv' => $get_big_small_datas[0]['total_performance'], // 公共联盟PV 'person_nums_pv' => $get_big_small_datas[1]['total_performance'], // 个人联盟PV ]; return app("json")->success($data); } /** * 一壶茶-团队列表 */ public function team_list() { $teamid = $this->request->uid(); //$teamid = $this->request->param('teamid');//测试ID //$teamid = 17; $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员 $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推 // 初始化最终返回的数据 $data = [ 'team_list' => [], 'fans_num' => 0, // 粉丝数 'new_performance' => 0, // 新增业绩 'total_performance' => 0, // 总业绩 'person_nums' => 0, // 个人联盟人数 'common_nums' => 0, // 公共联盟人数 'common_nums_pv' => 0, // 公共联盟PV 'person_nums_pv' => 0, // 个人联盟PV ]; // 如果在旧系统中有数据 if (!empty($datas_jbp)) { $team_userinfo_old_jbp1 = $this->getPerformance($teamid); $tes = $this->teamPeople($teamid, $type); // 1:团队, 2:个人 $data1 = [ "total" => 100, "per_page" => 10, "current_page" => 1, "last_page" => 1, "data" => [] ]; if ($type != 2) { foreach ($tes as $k => $v) { $curr_pv = ''; if ($v['curr_type'] == 0) { $curr_pv = $team_userinfo_old_jbp1['person_nums_pv']; } elseif ($v['curr_type'] == 1) { $curr_pv = $team_userinfo_old_jbp1['common_nums_pv']; } else { $curr_pv = 0; } $data1['data'][$k] = [ "uid" => $v["id"], "nickname" => $v['user_name'] . $curr_pv, "phone" => "137****3315", "avatar" => "https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png", "create_time" => "2025-01-25 11:00:18", "identity" => "11", "level" => "40002", "partnership" => "22", "total_performance" => $curr_pv, "new_performance" => 0, "team_count" => $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1, ]; } } else { foreach ($tes as $k => $v) { $data1['data'][$k] = [ "uid" => $v["uid"], "nickname" => $v['nickname'], "avatar" => $v['avatar'], "create_time" => "2025-01-25 11:00:18", ]; } } // 旧系统中的公共部分数据 $data['team_list'] = $data1; $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums']; $data['new_performance'] = 0; $data['total_performance'] = $team_userinfo_old_jbp1['sum_nums_pv']; $data['person_nums'] = $team_userinfo_old_jbp1['person_nums']; $data['common_nums'] = $team_userinfo_old_jbp1['common_nums']; $data['common_nums_pv'] = max($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']); $data['person_nums_pv'] = min($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']); } // 查询当前会员旗下的会员数据(分页) [$page, $limit] = $this->getPage(); $subordinate_members = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $teamid) ->where("so.mer_id", 496) ->group('u.uid') ->page($page, $limit) ->select(); $total_members = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $teamid) ->where("so.mer_id", 496) ->group('u.uid') ->count(); $data1 = [ "total" => $total_members, "per_page" => $limit, "current_page" => $page, "last_page" => ceil($total_members / $limit), "data" => [] ]; $total_amount_pv_team = 0; $team_count_total = 0; foreach ($subordinate_members as $k => $v) { $t_teams_pv = $this->calculatePerformance($v['uid']); $total_amount_pv_team += $t_teams_pv['total_performance']; $team_count_total += $t_teams_pv['team_count']; $data1['data'][$k] = [ "uid" => $v["uid"], "nickname" => $v['nickname'], "phone" => substr_replace($v['phone'], '****', 3, 4), "avatar" => $v['avatar'], "create_time" => $v['create_time'], "total_performance" => $t_teams_pv['total_performance'], "new_performance" => $t_teams_pv['total_performance'], "team_count" => $t_teams_pv['team_count'], ]; } // 获取大小部门数据 $get_big_small_datas = $this->getbig_samll_datas($subordinate_members); // 判断大小部门的人数 $big_team_count = $get_big_small_datas[0]['team_count']; $small_team_count = $get_big_small_datas[1]['team_count']; // 根据 type 参数处理数据 if ($type == 1) { usort($data1['data'], function ($a, $b) { return $b['total_performance'] <=> $a['total_performance']; }); $data1['data'] = array_slice($data1['data'], 0, 1); } elseif ($type == 0) { usort($data1['data'], function ($a, $b) { return $b['total_performance'] <=> $a['total_performance']; }); $data1['data'] = array_slice($data1['data'], 1); } // 合并数据 if (!empty($datas_jbp)) { // 如果旧系统中有数据,合并新旧数据 $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']); $data['fans_num'] += $team_count_total; $data['new_performance'] += $total_amount_pv_team; $data['total_performance'] += $total_amount_pv_team; $data['person_nums'] += $big_team_count; $data['common_nums'] += $small_team_count; $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance']; $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance']; } else { // 如果旧系统中没有数据,直接使用新数据 $data['team_list'] = $data1; $data['fans_num'] = $team_count_total; $data['new_performance'] = $total_amount_pv_team; $data['total_performance'] = $total_amount_pv_team; $data['person_nums'] = $big_team_count; $data['common_nums'] = $small_team_count; $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance']; $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance']; } return app("json")->success($data); } //计算自己和自己团队下面的业绩。新表 //计算自己和自己团队下面的业绩。新表 public function calculatePerformance($uid) { // 初始化业绩数组 $performance = [ 'personal_performance' => 0, // 个人业绩 'team_performance' => 0, // 团队业绩 'total_performance' => 0, // 总业绩 'team_count' => 0, // 加上自己的团队数量 ]; // 定义业绩换算规则 $performanceMapping = [ 1180 => 700, 10620 => 6300, 11800 => 7000 ]; // 计算个人业绩 $personalOrder = Db::name('store_order')->where("uid", $uid)->find(); if ($personalOrder) { // 将浮点数转换为整数 $totalPrice = (int)$personalOrder['total_price']; if (isset($performanceMapping[$totalPrice])) { $performance['personal_performance'] = $performanceMapping[$totalPrice]; } } // 计算旗下团队成员的业绩 $teamOrders = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $uid) // 查询旗下会员 ->where("so.mer_id", 496) // ->where("so.douhuomall", 1) // ->where("so.douhuomall_status", 9) // ->where("so.status", 0) ->select(); $teamOrders_count = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $uid) // 查询旗下会员 ->where("so.mer_id", 496) // ->where("so.douhuomall", 1) // ->where("so.douhuomall_status", 9) // ->where("so.status", 0) ->count(); $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量 foreach ($teamOrders as $order) { if ($order['total_price']) { // 将浮点数转换为整数 $totalPrice = (int)$order['total_price']; if (isset($performanceMapping[$totalPrice])) { $performance['team_performance'] += $performanceMapping[$totalPrice]; } } } // 计算总业绩 $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance']; // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false return $performance; } //获取大小部门业绩(新表) public function getbig_samll_datas($subordinate_members){ //单独写一个方法获取大小部门的数据 $arr_team = []; foreach ($subordinate_members as $k => $v) { //计算自己和旗下的业绩 $arr_team[] = $this->calculatePerformance($v['uid']); } // 初始化变量 $maxPerformance = 0; $maxIndex = -1; // 找出 total_performance 最高的记录 foreach ($arr_team as $index => $item) { if ($item['total_performance'] > $maxPerformance) { $maxPerformance = $item['total_performance']; $maxIndex = $index; } } // 如果找到了最高记录 if ($maxIndex !== -1) { // 提取最高记录 $maxRecord = $arr_team[$maxIndex]; // 从原数组中移除该记录 unset($arr_team[$maxIndex]); // 重新索引数组 $arr_team = array_values($arr_team); } else { // 如果没有找到记录,可以设置一个默认值 $maxRecord = null; } // 计算大部门和小部门的汇总信息 $majorDepartmentSummary = [ "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0, "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0, "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0, "team_count" => $maxRecord ? $maxRecord['team_count'] : 0, "data" => $maxRecord ? [$maxRecord] : [] ]; $minorDepartmentSummary = [ "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')), "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')), "total_performance" => array_sum(array_column($arr_team, 'total_performance')), "team_count" => array_sum(array_column($arr_team, 'team_count')), "data" => $arr_team ]; // 输出结果 // echo "大部门汇总信息:\n"; // print_r($majorDepartmentSummary); // echo "小部门汇总信息:\n"; // print_r($minorDepartmentSummary); return array($majorDepartmentSummary,$minorDepartmentSummary); } //计算自己和自己团队下面的业绩。新表 public function calculatePerformance_copy($uid) { // 初始化业绩数组 $performance = [ 'personal_performance' => 0, // 个人业绩 'team_performance' => 0, // 团队业绩 'total_performance' => 0, // 总业绩 'team_count' =>0, //加上自己的团队数量 //'team_count_pr'=>0,//实际团队数量(没有加上自己) ]; // 定义业绩换算规则 $performanceMapping = [ 1180 => 700, 10620 => 6300, 11800 => 7000 ]; // 计算个人业绩 $personalOrder = Db::name('store_order')->where("uid", $uid)->find(); if ($personalOrder) { // 将浮点数转换为整数 $totalPrice = (int)$personalOrder['total_price']; if (isset($performanceMapping[$totalPrice])) { $performance['personal_performance'] = $performanceMapping[$totalPrice]; } } // 计算旗下团队成员的业绩 $teamOrders = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $uid) // 查询旗下会员 ->where("so.mer_id", 496) // ->where("so.douhuomall", 1) // ->where("so.douhuomall_status", 9) // ->where("so.status", 0) ->select(); $teamOrders_count = Db::name('user') ->alias('u') ->join('store_order so', 'u.uid = so.uid', 'LEFT') ->where("u.spread_uid", $uid) // 查询旗下会员 ->where("so.mer_id", 496) // ->where("so.douhuomall", 1) // ->where("so.douhuomall_status", 9) // ->where("so.status", 0) ->count(); $performance['team_count'] = $teamOrders_count+1;//赋值团队数量 //$performance['team_count_pr'] = $teamOrders_count;//没有加上父级赋值团队数量 foreach ($teamOrders as $order) { if ($order['total_price']) { // 将浮点数转换为整数 $totalPrice = (int)$order['total_price']; if (isset($performanceMapping[$totalPrice])) { $performance['team_performance'] += $performanceMapping[$totalPrice]; } } } // 计算总业绩 $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance']; return $performance; } public function team_list_copy旧表使用() { $teamid = $this->request->uid(); //$teamid = $this->request->param('teamid');//测试ID $teamid = 17; $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推 $team_userinfo_old_jbp1= $this->getPerformance($teamid); //判断大小团队(业绩多的是大部门,业绩小的是小部门) $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人 $data1= [ "total"=>100, "per_page"=> 10, "current_page"=> 1, "last_page"=> 1, ]; if($type != 2){ //小部门和大部门列表数据 foreach($tes as $k=>$v){ $curr_pv = ''; if($v['curr_type']==0){ $curr_pv = $team_userinfo_old_jbp1['person_nums_pv']; }else if($v['curr_type']==1){ $curr_pv = $team_userinfo_old_jbp1['common_nums_pv']; }else{ $curr_pv = 0; } $data1['data'][$k] = [ "uid"=>$v["id"], "nickname"=> $v['user_name'] . $curr_pv, "phone"=> "137****3315", "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png", "create_time"=>"2025-01-25 11:00:18", "identity"=>"11", "level"=> "40002", "partnership"=>"22", "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩 "new_performance"=> 0,//新增业绩 "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数) ]; } }else{ //直推列表 foreach($tes as $k=>$v){ $data1['data'][$k] = [ "uid"=>$v["uid"], "nickname"=> $v['nickname'], "avatar"=>$v['avatar'], "create_time"=>"2025-01-25 11:00:18", ]; } } $data['team_list'] = $data1; $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数 $data['new_performance'] = 0;//新增业绩 $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩 $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟 $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟 $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV // $data['effective_fans_num'] = DB::name('enterprise_user') //把新表中的新增邀请用户加到数组中 return app("json")->success($data); } /** * 一壶茶-团队列表 */ public function team_list_copy() { $uid = $this->request->uid(); $where['puid'] = $uid; $where['mer_id'] = $this->merId; $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();//直属粉丝数量 //var_dump($uid); $arr = $this->jisuan_fans($uid); $data['fans_num'] = count($arr);//粉丝总数 $data['total_performance'] = 12555;//总业绩 $data['new_performance'] = 15;//新增业绩 [$page, $limit] = $this->getPage(); $where2['eu.mer_id'] = $this->merId; $type = $this->request->param('type', 0);//1:大部门,0:小部门 // var_dump($where2); $enterprise_user_team = DB::name('enterprise_user') ->alias('eu') ->join('user u', 'eu.uid=u.uid') ->where($where2) ->when($type < 1 || $type == 2, function ($q) use ($arr) { $q->whereIn('eu.uid', $arr); }) ->when($type == 1, function ($q) use ($uid) { $q->whereIn('eu.puid', $uid); }) ->when($type == 2, function ($q) use ($uid) { $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]); }) ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership') ->order('eu.enterprise_user_id desc') ->paginate($limit) ->each(function ($item) { $item['phone'] = substr_replace($item['phone'], '****', 3, 4); return $item; }); //var_dump($enterprise_user_team); $data['team_list'] = $enterprise_user_team; $data['effective_fans_num'] = DB::name('enterprise_user') ->alias('eu') ->join('user u', 'eu.uid=u.uid') ->where($where2) ->whereIn('eu.uid', $arr) ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]) ->count();//有效粉丝数量 return app("json")->success($data); } public function team_details() { $uid = $this->request->param('uid', 0); $where2['eu.uid'] = $uid; $where2['eu.mer_id'] = $this->merId; $enterprise_user_team = DB::name('enterprise_user') ->alias('eu') ->join('user u', 'eu.uid=u.uid') ->where($where2) ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid') ->find();; if ($enterprise_user_team) { $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4); $enterprise_user_team['p_nickname'] = ''; $enterprise_user_team['p_phone'] = ''; $yanglao = 0; $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0]; $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number'); $yanglao += $offLine1; $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number'); $yanglao += $offLine2; $enterprise_user_team['ylj'] = set_price_rtrim($yanglao); if ($enterprise_user_team['puid'] > 0) { $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find(); if ($user) { $enterprise_user_team['p_nickname'] = $user['nickname']; $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4); } } } return app("json")->success($enterprise_user_team); } /** * 率积分明细 */ public function green_integral_list() { $pm = $this->request->param('pm'); $status = $this->request->param('status'); [$page, $limit] = $this->getPage(); $uid = $this->request->uid(); log::info("green_integral_list==={$uid}"); $where['uid'] = $uid; // $where['mer_id'] = $this->merId; // if ($pm == 1) { // $pm_arr = [1, 3]; // } else { // $pm_arr = [2, 4]; // } if ($pm==0){ $data = DB::name('user_sign_score')->where($where)->where('pm', 1)->where('status', 1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } if($pm==1){ $data = DB::name('user_sign_score')->where($where)->where('pm', 2)->where('status', 1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } if($pm==2){ $data = DB::name('user_sign_score')->where($where)->where('status', -1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select(); } log::info("=======date==={$data}"); return app("json")->success($data); } public function user_invite_profit_list() { $uid = $this->request->uid(); [$page, $limit] = $this->getPage(); $commission_type = $this->request->param('commission_type', 0); if ($commission_type) { $where['commission_type'] = $commission_type; } $month = $this->request->param('month', '') ?: date('Y-m'); $startMonth = date('Y-m-01 00:00:00', strtotime($month)); $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))); $data['yanglao_clear_all'] = Db::name('user_bill') ->where('uid', $uid) ->whereBetween('create_time', [$startMonth, $endMonth]) ->where('commission_type', 5) ->where('pm', 1) ->where('status', 1) ->sum('number'); $data['yanglao_nclear_all'] = Db::name('user_bill') ->where('uid', $uid) ->whereBetween('create_time', [$startMonth, $endMonth]) ->where('commission_type', 5) ->where('pm', 1) ->where('status', 0) ->sum('number'); $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all']; $where['uid'] = $uid; $data['totel_money'] = Db::name('user_bill')->where($where) ->whereNotIn('commission_type', [5, 7, 17, 19]) ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) { $query->whereBetween('create_time', [$startMonth, $endMonth]); }, function ($query) use ($where, $month, $startMonth, $endMonth) { $query->where('commission_type', '<>', 5) ->whereBetween('create_time', [$startMonth, $endMonth]); }) ->sum('number'); $pageInfo = Db::name('user_bill') ->where($where) ->whereNotIn('commission_type', [5, 7, 17, 19]) ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) { $query->whereBetween('create_time', [$startMonth, $endMonth]); }, function ($query) use ($where, $month, $startMonth, $endMonth) { $query->where('commission_type', '<>', 5) ->whereBetween('create_time', [$startMonth, $endMonth]); }) ->order('bill_id desc') ->paginate($limit); $data_arr = []; foreach ($pageInfo->items() as $k => $v) { $v['money'] = set_price_rtrim($v['number']); $v['order_money'] = set_price_rtrim(0); $v['commission_rate'] = set_price_rtrim(0); $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find(); if (!empty($order)) { $v['order_money'] = set_price_rtrim($order['total_price']); $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2)); } if ($v['status'] == 0) { // $v['create_time'] = '--'; } if ($v['status'] == 1) { // $v['create_time'] = $v['take_time']; } $data_arr[] = $v; } $data['pageInfo']['current_page'] = $pageInfo->currentPage(); $data['pageInfo']['data'] = $data_arr; $data['pageInfo']['last_page'] = $pageInfo->lastPage(); return app("json")->success($data); } /*导航转链-用于用户下单绑定*/ public function changeLink() { $uid = $this->request->uid(); if (!$uid) { return app("json")->error("请登录"); } $data = $data = $this->request->params([ 'url', 'name' ]); $data['url'] = urldecode($data['url']); $data['name'] = urldecode($data['name']); if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) { if ($data['name'] == '京东') { $url = app()->make(Jd::class)->linkChange($data['url'], $uid); } if ($data['name'] == '拼多多') { $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid); } if ($data['name'] == '唯品会') { $url = app()->make(Vip::class)->changeLink($data['url'], $uid); } if ($data['name'] == '苏宁易购') { $url = $data['url']; //$url = app()->make(Su::class)->changeLink($data['url'],$uid); } if ($data['name'] == '饿了么') {//获取饿了么官方活动链接 //如果用户没有拉取relation_id, $where = ['uid' => $uid, 'type' => 5]; $isRelation = UserThirdModel::where($where)->find(); if ($isRelation) { $result = DaTaoKe::activityChangeLink('20150318020002597', $uid); if ($result['code'] == 0) { return \app('json')->fail("获取饿了么链接出错", $result['raw']); } $url = $result['link']; } else {//如果还没有获取用户的relation_id还需要拉淘宝授权 $state = "{$uid}_h5"; $url = \app()->make(TaoBao::class)->getAuthUrl($state); } } } return app("json")->success($url); } /*获取协议*/ public function xieyi() { $data = $this->request->params([ 'type' ]); $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']); return app("json")->success($data); } /*获取规则文章*/ public function guize() { $id = $this->request->param('id'); $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($id); if(!$data){ $data['title']=''; $data['content']=''; } $html='