source = $this->request->header('source'); $this->merId = $this->request->header('merId'); } /** * 计算国盛小程序市场管理分红 */ public function gscm($mer_id=1){ // $enterprise=Db::name('enterprise')->where('type',1)->select(); $enterprise=Db::name('enterprise')->where('mer_id',$mer_id)->where('type',1)->find(); if(!$enterprise){ return false; } $reward[6]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',6)->column('uid'); $reward[5]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',5)->column('uid'); $reward[4]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',4)->column('uid'); $reward[3]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',3)->column('uid'); $reward[2]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',2)->column('uid'); $reward[1]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',1)->column('uid'); // $uids = array_merge($reward[6],$reward[5],$reward[4],$reward[3],$reward[2],$reward[1]); $uids_money=[]; $enterprise_money=Db::name('enterprise_bill')->where('mer_id',$mer_id)->sum('money'); $amoney=$enterprise_money*0.05; $divvy=decimal2($amoney*0.3);//平均分红 $jiaquan_divvy=$amoney-$divvy;//加权分红 //平均分红金额不足每人0.01 就不分了 if($divvy > 0 || decimal2($divvy/(count($reward[6])*6+count($reward[5])*5+count($reward[4])*4+count($reward[3])*3+count($reward[2])*2+count($reward[1]))) > 0 ){ //0-普通用户 1-微店 2-云店 3-旗舰店 4-消费合伙人 5-创业合伙人 6-股东合伙人 for ($i=6;$i>0;$i--) { if ($i == 6) { $mergedArray = $reward[6]; }elseif($i==5){ $mergedArray = array_merge($reward[6],$reward[5]); }elseif($i==4){ $mergedArray = array_merge($reward[6],$reward[5],$reward[4]); }elseif($i==3){ $mergedArray = array_merge($reward[6],$reward[5],$reward[4],$reward[3]); }elseif($i==2){ $mergedArray = array_merge($reward[6],$reward[5],$reward[4],$reward[3],$reward[2]); }else{ $mergedArray = array_merge($reward[6],$reward[5],$reward[4],$reward[3],$reward[2],$reward[1]); } $fenhong=decimal2($divvy/count($mergedArray)); foreach ($mergedArray as $v){ if(!isset($uids_money[$v])){ $uids_money[$v]=$fenhong; }else{ $uids_money[$v]+=$fenhong; } } } dump($uids_money); } } 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 importExcel() { $file = request()->file('file'); // 创建一个新的Excel读取器对象 $objReader = \PHPExcel_IOFactory::createReader('Excel2007'); $objPHPExcel = $objReader->load($file); // 选择活动工作表 $objPHPExcel->setActiveSheetIndex(0); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); // 循环遍历行和列 $yonghu=[]; foreach ($sheetData as $k=>$row) { if($k==1){ continue; } if($row['A'] && $row['A']!=NULL && $row['A']!=''){ $yonghu[]=array('a'=>$row['A'],'b'=>$row['B']); } } $repository = app()->make(UserRepository::class); foreach ($yonghu as $k=>$v){ $user = $repository->accountByUser($v['a']); if ($user){ // return app('json')->fail('手机号已存在'); $yonghu[$k]['user'] = $user; }else{ $yonghu[$k]['user'] = $repository->registr($v['a'],'A123456','APP',0); } } foreach ($yonghu as $v){ $user=$v['user']; if($v['b'] && $v['b']!=null && $v['b']!=''){ $pid=Db::name('user')->where('account',$v['b'])->value('uid'); if($pid){ $repository->bindSpread($user, intval($pid)); } } } } public function test() { $this->importExcel(); echo '导入成功'; die; $storeOrderRepository = app()->make(StoreOrderRepository::class); // $storeOrderRepository->yihuchashengji();//一壶茶身份升级 // $storeOrderRepository->yunyingjiangli();//运营中心奖励 // $storeOrderRepository->yihuchafenxiang();//一壶茶分红逻辑memberSettings // $this->jinjian();die; var_dump(11); die; $order_id = (int)$this->request->param('id'); $order=Db::name('store_order')->find($order_id); if(!$order){ return '订单不存在'; } //在rrx_store_order_product 表中查到product_id ,在rrx_store_product 查spu_id 在rrx_douhuomall表中查goods_id $out_order_no=$order['douhuomall_order_no']; $after_type='1';//1=未收货退款,2=退货退款,3=换货补发,4=不退货仅退款 $explain='测试退货'; $can_after_data=GongApiRequest::is_can_after( $out_order_no); dump($can_after_data); if(isset($can_after_data['result']['order_goods'])){ foreach ($can_after_data['result']['order_goods'] as $v){ $order_goods_id=$v['order_goods_id']; $after_num=$v['after_num']; $res=GongApiRequest::apply_after_sales( $order_goods_id,$out_order_no, $after_type, $explain, $after_num); dump($res); } } // // $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class); // $res=$storeGroupOrderRepository->ProductOutCancel(6105); // $res = GongApiRequest::order_details('wx1698916402673749101'); $res2=GongApiRequest::after_status_new($out_order_no); dump($res2); // dump($repository->getBangFu(9640)); // dump($userRepository -> getCountUId(18)); // echo '开发者测试'; // echo systemConfig("pay_wx"); // $res = [ // "completeDateTime"=>"2022-05-31 14:27:09", // "remark"=>"1", // "orderAmount"=>"100", // "merchantId"=>"899104033", // "requestId"=>"wx1653980751822534740_5366", // "hmac"=>"yivznJKbCfPpnXpwsalGDz7tnRyjr9pqbeVSkVKZ5VvtnJqn4helUkGC+S2tsaF8oknwvN\/ZeoDcgtRPqT1uanOWyalSFip6qxkBDkbc\/sJBVMCR2vzp38+YEHbusuxH1O9D696bt\/PSuhFjItD9pFi+Qteha1zN8X4oxpWFEob4wOVcFnMHLkgehNoWy1NRqjz+RmD6osAzJrIS27RJmUaqt83e0ejcjfEzAEw74rq4Yafyx9PohjvF35iwVLCpOcdyxVsfuJ4D59ayqsgUs0\/80GMRvNkgXrO6bsN7m1t6PLSQgPkD6ruEX\/i4l4uhrpHLvnpc4wl9YsGS1k4SrQ==", // "clearingOrg"=>"UNION_PAY", // "totalRefundCount"=>"0", // "serialNumber"=>"ddd", // "realBankSerialNumber"=>"4200001429202205315964134213", // "orderCurrency"=>"CNY", // "realBankRequestNumber"=>"1531522625975881728N", // "totalRefundAmount"=>"0", // "paymentModeAlias"=>"MINIAPPS_WEIXIN_PAY", // "status"=>"SUCCESS" // ]; // $requestId = []; // if(strpos($res['requestId'],'_') !== false){ // $requestId = explode("_",$res['requestId']); // } // if($res['status'] == 'SUCCESS'){ // Db::name('store_group_order') -> where('group_order_sn',$requestId[0]) -> update(['rand'=>$requestId[1],'serialNumber'=>$res['serialNumber']]); // $pay_type = $res['paymentModeAlias'] == 'MINIAPPS_WEIXIN_PAY' ? 1 : 4; // event('pay_success_order', ['order_sn' => $requestId[0],'pay_type'=>$pay_type]); // } // Db::name('test') -> insert(['date'=>date('Y-m-d H:i:s')]); // try { // $merch_no = $this->request->param('merch_no'); // $mer_name = $this->request->param('mer_name'); // $mer_short_name = $this->request->param('mer_short_name'); // $response = $this->merchantModify(['merch_no' => $merch_no,'mer_name' => $mer_name, 'mer_short_name' => $mer_short_name,'agent_apply_no' => (string)time()]); // return app('json')->success($response); // } catch (\Throwable $e) { // return app('json')->fail($e->getMessage()); // } } //商户进件 private function jinjian(){ // $returndata=[ // 'request_id'=>time().rand(111111,999999), // 'usr_phone'=>'15732652759', // 'cont_name'=>'吴国珍', // 'cont_phone'=>'13911251783', // 'customer_email'=>'312009092@qq.com', // 'mer_name'=>'北京天地博爱科技有限公司', // 'mer_short_name'=>'天地博爱科技', // 'reg_addr'=>'北京市北京经济技术开发区科创十三街31号院二区14号楼9层901-3(北京自贸试验区高端产业片区亦庄组团)', // 'cust_addr'=>'北京市北京经济技术开发区科创十三街31号院二区14号楼9层901-3(北京自贸试验区高端产业片区亦庄组团)', // 'cust_tel'=>'010-53327000', // 'legal_name'=>'吴国珍', // 'legal_type'=>0, // 'legal_idno'=>'321123196710192020', // 'legal_mp'=>'13911251783', // 'legal_start_cert_id_expires'=>'20061129', // 'legal_id_expires'=>'20261129', // 'card_id_mask'=>'629966688', // 'card_name'=>'北京天地博爱科技有限公司', // 'bank_acct_type'=>'1', // 'bank_code'=>'03050000', // 'prov_code'=>'0011',//省份编码 (省市编码), // 'area_code'=>'1100',//地区编码 (省市编码) // 'license_code'=>'91110105697724649E', // 'mer_valid_date'=>'20291118', // 'mer_start_valid_date'=>'20091119', // 'entry_mer_type'=>'1', // 'rsa_public_key'=>'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxTpMESsdhyjKQC+y1G++eXCEu5pXqK7fvkZJdubSTCQn/RM3soOMcCwTekULCxEUwM0SnPxFLcZuP/a8w87zWeAXoBCPJl1gVK4KZ+3tWq/BJPCET3Vy66M7pXfXL+ekd8gf2LWtEfpJoAn59guVfsbTOp44ppDkrb3SuXDcKhQIDAQAB' // ]; $returndata=[ 'request_id'=>time().rand(111111,999999), 'usr_phone'=>'13911251783',//注册手机号 'cont_name'=>'陈立军',//联系人姓名 'cont_phone'=>'13911251783',//联系人手机号码 'customer_email'=>'312009092@qq.com',//电子邮箱 'mer_name'=>'河北省一壶茶电子商务有限公司',//商户名称 'mer_short_name'=>'一壶茶电子商务',//商户简称 商户简称,长度为10个中文 'reg_addr'=>'河北省秦皇岛市经济技术开发区华山中路8号银通大厦',//注册地址 'cust_addr'=>'河北省秦皇岛市经济技术开发区华山中路8号银通大厦',//经营地址 'cust_tel'=>'010-53327000',//商户电话 'legal_name'=>'陈立军',//法人/负责人 姓名 'legal_type'=>0,//法人/负责人证件号码 'legal_idno'=>'130302196709281432',//法人/负责人证件号码 'legal_mp'=>'13911251783',//法人/负责人手机号 'legal_start_cert_id_expires'=>'20230310',//法人/负责人身份证有效期(始),格式 YYYYMMDD 'legal_id_expires'=>'20991231',//法人/负责人身份证有效期(至),格式 YYYYMMDD 'card_id_mask'=>'13050163560800002447',//结算银行卡号 'card_name'=>'河北省一壶茶电子商务有限公司',//结算银行卡开户姓名 'bank_acct_type'=>'1',//结算银行账户类型,1 : 对公, 2 : 对私。小微只能是对私 'bank_code'=>'01050000',//结算银行卡所属银行code 'prov_code'=>'0013',//结算银行卡省份编码, 'area_code'=>'1308',//结算银行卡省份编码 'license_code'=>'91130301MAD48PT00A',//营业执照编码 'mer_valid_date'=>'20991231',//商户有效日期(至),格式 YYYYMMDD(若为长期有效,固定为“20991231”;若开户企业类商户,必填) 'mer_start_valid_date'=>'20231107',//商户有效日期(至),格式 YYYYMMDD(若为长期有效,固定为“20991231”;若开户企业类商户,必填) 'entry_mer_type'=>'1',//商户类型:1-企业;2-小微。默认为企业 'rsa_public_key'=>'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxTpMESsdhyjKQC+y1G++eXCEu5pXqK7fvkZJdubSTCQn/RM3soOMcCwTekULCxEUwM0SnPxFLcZuP/a8w87zWeAXoBCPJl1gVK4KZ+3tWq/BJPCET3Vy66M7pXfXL+ekd8gf2LWtEfpJoAn59guVfsbTOp44ppDkrb3SuXDcKhQIDAQAB' ]; dump($returndata); $arr= $this->incoming_parts($returndata,'config'); dump($arr);die; } /** * 业绩奖-服务中心分红-发放 * @return mixed */ public function yihuchafenxiang(){ $storeOrderRepository = app()->make(StoreOrderRepository::class); $storeOrderRepository->yihuchafenxiang(); $storeOrderRepository->yunyingjiangli(); return app('json')->success('业绩奖-服务中心分红-运营中心-发放完成'); } /** * 一壶茶身份升级 * @return mixed */ public function yihuchashengji(){ $storeOrderRepository = app()->make(StoreOrderRepository::class); $storeOrderRepository->yihuchashengji(); return app('json')->success('一壶茶身份升级-完成'); } public function shareImgesList(){ $where['mer_id']=$this->merId; $where['status']=0; $classify=$this->request->param('classify',0); if($classify){ $where['classify']=$classify; } $pageNum=$this->request->param('pageNum',1); $limit=$this->request->param('pageSize',10); $type=$this->request->param('type',0); if($type){ $where['type']=$type; } $data['pageInfo']['list']=Db::name('share_posters')->where($where)->page($pageNum,$limit)->order('sort desc,id desc')->select(); $data['pageInfo']['total']=Db::name('share_posters')->where($where)->count(); return app('json')->success($data); } public function classifyList(){ $data=Db::name('share_posters_classify')->field('id,name')->where('mer_id',$this->merId)->where('is_del',0)->order('sort desc,id desc')->select(); return app('json')->success($data); } public function agreement_detail(){ $type = $this->request->param('type',1); // $where['mer_id']=$this->merId; $where['type']=$type; $data=Db::name('enterprise_agreement')->where($where)->find(); if(!$data){ $data['title']=''; $data['content']=''; } return app('json')->success($data); } public function agreement(){ $type = $this->request->param('type',1); // $where['mer_id']=$this->merId; $where['type']=$type; $data=Db::name('enterprise_agreement')->where($where)->find(); if(!$data){ $data['title']=''; $data['content']=''; } $html='
";
dump($data);
return 1;
}
public function createUserNumberAll(){
$userRepository = app()->make(UserRepository::class);
$user = Db::name('user') -> select();
foreach($user as $key => $value){
$userRepository -> createUserNumber($value['uid']);
}
}
/**
* @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();
}
}
public function yijianlogin(UserRepository $repository)
{
try {
// Db::name('log')->insert(['data'=>'一键登录进来了']);
$token = $this->request->params(['token'])['token'];
AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
->regionId('cn-hangzhou')
->asDefaultClient();
$result = AlibabaCloud::rpc()
->product('Dypnsapi')
->scheme('https')// https | http
->version('2017-05-25')
->action('GetMobile')
->method('POST')
->host('dypnsapi.aliyuncs.com')
->options([
'query' => [
'RegionId' => "cn-hangzhou",
'AccessToken' => $token
],
])
->request();
// 将返回的结果转化为数组
$result = $result->toArray();
// Db::name('log')->insert(['data'=>json_encode($result)]);
//判断当前数组不为空
if (isset($result['GetMobileResultDTO']['Mobile'])) {
// token不为空返回手机号码
$phone = $result['GetMobileResultDTO']['Mobile'];
$user_res=Db::name('user')->where('account',$phone)->find();
if(!$user_res){
$repository->registr($phone, 123456,'APP',"http://app.bjtdba.com");
}
$user = $repository->accountByUser($phone);
$user = $repository->mainUser($user);
$tokenInfo = $repository->createToken($user);
return app('json')->success($repository->returnToken($user, $tokenInfo));
} else {
//如果token为空
$res = [
'state' => 0,
'msg' => 'token无效'
];
return app('json')->fail($res);
}
}catch (\Exception $e) {
Db::name('log')->insert(['data'=>'一键登录出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
}
}
//小程序获取 用户手机号
public function applet_phone(UserRepository $repository)
{
try {
// Db::name('log')->insert(['data'=>json_encode($this->request->param())]);
$sessionKey=$this->request->params(['sessionKey']);
$encryptedData=$this->request->params(['encryptedData']);
$share_id = $this->request->params(['share_id']);
$iv=$this->request->params(['iv']);
if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
return app('json')->fail('参数不正确');
}
// $appid = 'wx82986c4471ce7efc';
// if($this->source=='yhc'){
// $appid = 'wx82986c4471ce7efc';
// }
// $appid = 'wx7b4d857deb0447f3';
$appid = 'wx9082e5ac2fdb513f';
$sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
$encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
$iv =str_replace(' ','+', $iv['iv']);
// dump($iv,$encryptedData);
// return ;
$pc = new WXBizDataCrypt($appid, $sessionKey);
// dump($pc);
$errCode = $pc->decryptData($encryptedData, $iv, $data );
// dump($errCode);
if ($errCode != 0) {
return app('json')->fail('没有获取到手机号1');
}
// dump($data);
$data=json_decode($data,true);
$phone=$data['purePhoneNumber']??'';
if($phone==''){
return app('json')->fail('没有获取到手机号2');
}
if (!preg_match("/^1[3456789]{1}\d{9}$/", $phone)){
return app('json')->fail('手机号格式错误');
}
$user_res=Db::name('user')->where('account',$phone)->find();
if(!$user_res){
$spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
$repository->registr($phone, 123456,'APP',$spread_uid);
}
$user = $repository->accountByUser($phone);
if($this->source=='yhc' && $this->merId){
$where=['mer_id'=>$this->merId,'uid'=>$user['uid']];
$count=Db::name('enterprise_user')->where($where)->count();
if($count<1){
$insert=['mer_id'=>$this->merId,'uid'=>$user['uid']];
$data = $this->request->params(['spread', 'share_id']);
if(isset($data['spread']) && $data['spread']){
$insert['puid']= $data['spread'];
$insert['node_uid']= $data['spread'];
}else if(isset($data['share_id']) && $data['share_id']){
$spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
$insert['puid']= $spread_uid;
$insert['node_uid']= $spread_uid;
}
if(!isset($insert['node_uid']) || !$insert['node_uid']){
return app('json')->fail('必须要有邀请人才能注册',['is'=>1]);
}
if(isset($data['spread']) && isset($zhuce)){
$insert['puid']= $data['spread'];
$insert['node_uid']= $data['spread'];
}
Db::name('enterprise_user')->insert($insert);
}
}
$user = $repository->mainUser($user);
$tokenInfo = $repository->createToken($user);
return app('json')->success($repository->returnToken($user, $tokenInfo));
}catch (Exception $exception){
Db::name('log')->insert(['data'=>'获取手机号失败--'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
}
}
public function phone_name()
{
try {
$phone=$this->request->params(['phone']);
if(empty($phone['phone'])){
return app('json')->fail('请填写手机号码');
}
$phone=$phone['phone'];
$uid=Db::name('user')->where('account',$phone)->find();
$user_name=Db::name('merchant')->where('uid',$uid['uid'])->value('mer_name');
if(!$user_name){
$user_name=$uid['nickname'];
}
return app('json')->success($user_name);
}catch (\Exception $e) {
Db::name('log')->insert(['data'=>'订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
}
}
public function get_auth_token(){
$params=$this->request->params(['url','origin']);
try {
AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
->regionId('cn-hangzhou')
->asDefaultClient()->options([
]);
$result = AlibabaCloud::rpc()
->product('Dypnsapi')
->scheme('https')// https | http
->version('2017-05-25')
->action('GetAuthToken')
->method('POST')
->host('dypnsapi.aliyuncs.com')
->options([
'query' => [
'Url' => $params['url'],
'Origin' => $params['origin'],
],
])
->request();
$result = $result->toArray();
return app('json')->success($result);
}catch (Exception $e) {
return app('json')->success();
}
}
public function get_phone_with_token(){
$params=$this->request->params(['token']);
AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
->regionId('cn-hangzhou')
->asDefaultClient()->options([]);
$result = AlibabaCloud::rpc()
->product('Dypnsapi')
->scheme('https')// https | http
->version('2017-05-25')
->action('GetPhoneWithToken')
->method('POST')
->host('dypnsapi.aliyuncs.com')
->options([
'query' => [
'SpToken' => $params['token'],
],
])
->request();
$result = $result->toArray();
return app('json')->success($result);
}
public function getconlev(){
// $userid = 17;
// $datas = $this->getPerformance_getcon($userid);
// var_dump($datas);
$dats = db::name("store_order")->whereIn("status",[0,1,2,3])->select();
var_dump($dats);
}
/**
* 获取当前用户大小部门贡献值
*/
public function getPerformance_getcon($user_id) {
$team_amount = 0;
$person_amount = 0;
$user_id = 593; //598 523 536
$result_big_team_arr = [];
$get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
//共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
$common_nums = $this->getCommonNums_getcon($user_id);
//var_dump($common_nums);
$get_teams_comm_num = 0;
$get_teams_comm_pv = 0;
$get_teams_per_num = 0;//小部门人数
//1.0系统中有下级,需要在2.0中再加下级数据
if($user_id < 611){
//梅红在2.0中的ID是780
//var_dump( $common_nums);
//用户三峡所有在2.0系统下面的业绩和人数 start
$child_nums = [];
//获取当前用户
foreach($common_nums as $v){
$child_nums[] = $this->getRecursiveChildren_getcon($v);
}
//去除空数组,并重新组合有数据的数组
$filteredData = array_filter($child_nums, function($array) {
return !empty($array); // 如果数组不为空,则保留
});
// 合并所有非空数组
foreach ($filteredData as $array) {
$result_big_team_arr = array_merge($result_big_team_arr, $array);
}
//var_dump($result_big_team_arr);
//获取当前用户下面在2.0中的下级所有PV
//$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
$t_pv = $this->getteampv_getcon($result_big_team_arr);
$get_teams_comm_pv = $t_pv;
//var_dump($get_teams_comm_pv);echo "ttt";
//用户伞下小部门所有在2.0系统下面的业绩和人数 end
}else{
//当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
$child_nums = $this->getChildren_getcon($user_id);
//获取父级子级下面的个人
$num_teams = $this->getTeamSize_getcon($child_nums);
//var_dump($num_teams);
foreach($child_nums as $v){
$get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
}
//$s = $this->getparents_child_pv($user_id);
//var_dump($get_teams_comm_datas);
//如果只有一个部门,就是默认大部门
if( count($get_teams_comm_datas) ==1 ){
$get_teams_comm_pv =$get_teams_comm_datas[0];
$get_teams_comm_num = $num_teams[0]['total_count'];
}else if(count($get_teams_comm_datas) >1){
// var_dump( $get_teams_comm_datas);
//获取一个最大值,设为大部门,其他的加载一块是小部门
$getss = $this->processArray_getcon($get_teams_comm_datas);
//var_dump($getss);
$max_value_count = $num_teams[$getss['max_index']]['total_count'];
unset($num_teams[$getss['max_index']]);
//获取小部门的人数
$per_num = 0;
foreach($num_teams as $k=>$v){
$per_num +=$v['total_count'];
}
//找到最大值的(大部门)
//$get_teams_comm_num = $max_value_count;
//小部门的数量
// $get_teams_per_num = $per_num;
//var_dump($getss['max_value']);
$person_amount = $getss['remaining_sum'];
$get_teams_comm_pv = $getss['max_value'];
}
}
//var_dump($get_teams_comm_pv);
//合并业绩和人数
$team_amount += $get_teams_comm_pv;
//var_dump($team_amount);
//1.0获取小区业绩
$person_nums = $this->getPersonageNums_getcon($user_id);
//var_dump($person_nums);
$result_small_team_arr = [];
//1.0系统中有下级,需要在2.0中再加下级数据
//用户三峡所有在2.0系统下面的业绩和人数 start
$child_nums_mix = [];
//获取当前用户
foreach($person_nums as $v){
$child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
}
//去除空数组,并重新组合有数据的数组
$filteredData_1 = array_filter($child_nums_mix, function($array) {
return !empty($array); // 如果数组不为空,则保留
});
// 合并所有非空数组
$result_small_team_arr = [];
foreach ($filteredData_1 as $array) {
$result_small_team_arr = array_merge($result_small_team_arr, $array);
}
//var_dump($result_small_team_arr);
//获取当前用户下面在2.0中的下级所有PV
// $get_teams_per_pv = $this->getteampv($result_small_team_arr);
$t_pv = $this->getteampv_getcon($result_small_team_arr);
$get_teams_per_pv =$t_pv;
//var_dump( $get_teams_per_pv);
//获取当前用户下面在2.0中的下级所有人数
// $get_teams_per_num += count($result_small_team_arr);
//合并业绩和人数
$person_amount += $get_teams_per_pv;
//当前会员直属的业绩(1.0大部门)
$t_pv = $this->getteampv_getcon($common_nums);
$team_amount += $t_pv;
//当前会员直属的业绩(1.0大部门)
$p_pv = $this->getteampv_getcon($person_nums);
$person_amount += $p_pv;
//var_dump($team_amount,$person_amount);
//如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
if($user_id < 611){
//获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
//例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
$b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
$team_amount = $b_s[0];
$person_amount = $b_s[1];
}
$return_data = [
'common_nums_pv'=> $team_amount,
'person_nums_pv'=> $person_amount,
];
return $return_data;
}
/**
* 获取该用户共建联盟
*/
public function getCommonNums_getcon($user_id){
//先获取共建联盟下用户的id
$son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
$new_array_ids =[];
foreach ($son_ids as $key => $value) {
# code...
$son_id = $value['id'];
$new_array_ids = array_merge($new_array_ids,[$son_id]);
$son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
if(count($son_value_ids) > 0) {
$son_value_ids = array_column($son_value_ids,"id");
$new_array_ids = array_merge($new_array_ids,$son_value_ids);
}
}
return $new_array_ids;
}
/**
* 获取该用户个人联盟
*/
public function getPersonageNums_getcon($user_id){
$son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
$new_array_ids =[];
// return 3343;
foreach ($son_ids as $key => $value) {
# code...
$son_id = $value['id'];
$new_array_ids = array_merge($new_array_ids,[$son_id]);
$son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
if(count($son_value_ids) > 0) {
$son_value_ids = array_column($son_value_ids,"id");
$new_array_ids = array_merge($new_array_ids,$son_value_ids);
}
}
return $new_array_ids;
}
// 根据父级uid,递归获取所有子级UID数组
public function getRecursiveChildren_getcon($parentUid) {
$result = []; // 用于存储所有子级的 uid
// 定义递归函数
$recursion = function ($parentUid) use (&$result, &$recursion) {
// 查询当前父级的所有直接子级
$children = Db::name("user")
->where("spread_uid", $parentUid)
->column("uid"); // 获取子级的 uid 列表
// 如果没有子级,直接返回
if (empty($children)) {
return;
}
// 遍历每个子级
foreach ($children as $childUid) {
$result[] = $childUid; // 将子级的 uid 添加到结果数组
$recursion($childUid); // 递归查询子级的子级
}
};
// 从初始父级开始递归查询
$recursion($parentUid);
return array_unique($result); // 返回结果数组,并去重
}
//只获取数组中的业绩
public function getteampv_getcon($common_nums) {
// // 查询当前用户及其子级的所有订单
$orders_gongxian = Db::name("user_sign_gongxian")
->whereIn('status', [1])
->whereIn("uid", $common_nums)
->select();
//var_dump( $common_nums);
$total_gongxian = 0;
// // 遍历订单计算业绩
foreach ($orders_gongxian as $order) {
if (strpos($order['mark'], "购买") !== false) {
$total_gongxian += $order['number'];
}
}
return $total_gongxian;
// // // 查询当前用户及其子级的所有订单
// $orders = Db::name("store_order")
// ->whereIn('status', [0, 1, 2, 3])
// ->whereIn("uid", $common_nums)
// ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
// ->select();
// // 初始化业绩和人数
// $totalPv = 0;
// $totalUsers = count($common_nums); // 初始化人数为子级总数
// // 遍历订单计算业绩
// foreach ($orders as $order) {
// if ($order['total_price'] == 1180) {
// $totalPv += 700;
// } else if ($order['total_price'] == 11800) {
// $totalPv += 7000;
// } else if ($order['total_price'] == 10620) {
// $totalPv += 6300;
// } else if ($order['total_price'] == 2360) {
// $totalPv += 1400;
// } else if ($order['total_price'] == 9440) {
// $totalPv += 5600;
// }
// }
// // 返回业绩和人数
// return [
// 'totalPv' => $totalPv,
// 'totalUsers' => $totalUsers
// ];
}
// 2.0 根据父级uid,找到当前用户下面的UID
public function getChildren_getcon($parentUid) {
$result = []; // 用于存储所有子级的 uid
$children = Db::name("user")
->where("spread_uid", $parentUid)
->column("uid"); // 获取子级的 uid 列表
return $children; // 返回结果数组,并去重
}
// 递归获取所有子级 UID 的业绩
public function getTeamPv11_getcon($parentUid) {
$getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
$children = Db::name("user")
->where("spread_uid", $parentUid)
->column("uid");
$allChildren = [];
foreach ($children as $childUid) {
$allChildren[] = $childUid;
$allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
}
return $allChildren;
};
// 获取当前用户及其所有子级的 UID
$allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
$orders_gongxian = Db::name("user_sign_gongxian")
->whereIn('status', [1])
->whereIn("uid", $allUids)
->select();
$total_gongxian = 0;
// // 遍历订单计算业绩
foreach ($orders_gongxian as $order) {
if (strpos($order['mark'], "购买") !== false) {
$total_gongxian += $order['number'];
}
}
return $total_gongxian;
// // 查询当前用户及其子级的所有订单
// $orders = Db::name("store_order")
// ->whereIn('status', [0, 1, 2, 3])
// ->whereIn("uid", $allUids)
// ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
// ->select();
// // 计算总业绩
// $totalPv = 0;
// foreach ($orders as $order) {
// switch ($order['total_price']) {
// case 1180:
// $totalPv += 700;
// break;
// case 11800:
// $totalPv += 7000;
// break;
// case 10620:
// $totalPv += 6300;
// break;
// case 2360:
// $totalPv += 1400;
// break;
// case 9440:
// $totalPv += 5600;
// break;
// }
// }
// return $totalPv;
}
//根据传递的父级数组,返回他的对应子级的个数
public function getTeamSize_getcon($parentUids) {
// 初始化结果数组
$result = [];
// 遍历每个父级ID
foreach ($parentUids as $parentUid) {
// 递归获取所有子级 UID
$getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
$children = Db::name("user")
->where("spread_uid", $parentUid)
->column("uid");
// 确保返回的是数组
if (!is_array($children)) {
return [];
}
$allChildren = [];
foreach ($children as $childUid) {
$allChildren[] = $childUid;
$allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
}
return $allChildren;
};
// 获取当前父级及其所有子级的 UID
$allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
// 计算总个数(包括父级自身)
$totalUids = count($allUids);
// 将结果存入数组
$result[] = [
'parent_uid' => $parentUid,
'total_count' => $totalUids
];
}
return $result;
}
public function processArray_getcon($array) {
// 初始化结果数组
$result = [
'max_value' => null, // 最大值
'max_index' => null, // 最大值的下标
'remaining_sum' => 0 // 剩余值的总和
];
// 检查数组是否为空
if (empty($array)) {
return $result;
}
// 找出最大值及其下标
$maxValue = $array[0];
$maxIndex = 0;
for ($i = 1; $i < count($array); $i++) {
if ($array[$i] > $maxValue) {
$maxValue = $array[$i];
$maxIndex = $i;
}
}
// 计算剩余值的总和
$remainingSum = 0;
for ($i = 0; $i < count($array); $i++) {
if ($i != $maxIndex) {
$remainingSum += $array[$i];
}
}
// 将结果存入数组
$result['max_value'] = $maxValue;
$result['max_index'] = $maxIndex;
$result['remaining_sum'] = $remainingSum;
return $result;
}
/**
* 获取流水信息
*/
public function getPerformance1_getcon($user_id) {
// $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
// $amount = isset($amount) ? round($amount*0.7,2) : 0;
// return $amount;
$money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
$money1180Sum = 0;
foreach ($money1180Records as $record) {
$money1180Sum += $record['money'] - 300 - 180;
}
// var_dump($money1180Sum);
$money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
//var_dump($person_nums);
//计算个人的11800单价的业绩 集合
$money11800Sum = 0;
foreach ($money11800Records as $record) {
$money11800Sum += $record['money'] - 3000 - 1800;
}
$money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
//var_dump($person_nums);
//计算个人的11800单价的业绩 集合
$money10620Sum = 0;
foreach ($money10620Records as $record) {
$money10620Sum += $record['money'] - 2700 - 1620;
}
// 计算除去特定值后的总和
$otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
$otherMoneySum = 0;
foreach ($otherMoneyRecords as $record) {
$otherMoneySum += $record['money'];
}
// 分别处理特定值的情况并加上其他值的总和
$user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
return $user_person_amount;
}
//1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
// 获取直接下级的 UID 列表
$get_childs = Db::name("user")
->where("spread_uid", $user_id)
->column("uid");
// 初始化变量
$all_departments = []; // 用于存储所有直属下级的业绩
// 遍历每个直属下级
foreach ($get_childs as $child) {
// 获取当前下级及其子级
$child_group = [$child];
$recursive_children = $this->getRecursiveChildren_getcon($child);
$child_group = array_merge($child_group, $recursive_children);
// 获取当前分组的业绩
$result = $this->getteampv_getcon($child_group);
// 将直属下级的业绩加入数组
$all_departments[] = $result;
}
// 将传入的 $bigamount 和 $smallamount 加入数组
$all_departments[] = $bigamount;
$all_departments[] = $smallamount;
// 检查是否所有业绩都是 0
if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
return [0, 0];
}
// 初始化最大部门和小部门
$max_department = 0;
$small_department = 0;
// 遍历 $all_departments,找出最大值并累加小部门的值
foreach ($all_departments as $department) {
if ($department > $max_department) {
// 如果当前部门的业绩大于最大部门的业绩,更新最大部门
if ($max_department != 0) {
$small_department += $max_department; // 将旧的最大值累加到小部门
}
$max_department = $department; // 更新最大部门
} else {
// 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
$small_department += $department;
}
}
// 返回结果
return [
$max_department, // 大部门业绩
$small_department // 小部门业绩
];
//拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
// 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
}
//获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
public function getparents_child_pv_getcon($user_id){
// 获取直接下级的 UID 列表
//$user_id = 593;
// $get_childs = $this->getRecursiveChildren($user_id);
$get_childs = Db::name("user")
->where("spread_uid", $user_id)
->column("uid"); // 获取子级的 uid 列表
//根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
//获取直接下级
$children_group = []; // 用于存储每个直接下级及其子级的分组
// 遍历每个直接下级
foreach ($get_childs as $child) {
$child_group = [$child]; // 将直接下级加入分组
$recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
$child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
$children_group[] = $child_group; // 将分组加入最终结果
}
$get_teams_comm_datas = [];
foreach($children_group as $v){
$get_teams_comm_datas[] = $this->getteampv($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
}
if(count($get_teams_comm_datas) > 0){
// 找到最大值作为大部门
$max_value = max($get_teams_comm_datas);
$total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
// 小部门为总和减去最大值
$small_department = $total_sum - $max_value;
//返回大部门和小部门
return [
$max_value,
$small_department
];
}else{
return [
0,
0
];
}
}
}