123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413 |
- <?php
- namespace App\Http\Controllers;
- use App\Events\WechatMessageEvent;
- use App\Http\Requests\UserRequest;
- use App\Models\Address;
- use App\Models\Banner;
- use App\Models\Demo;
- use App\Models\Demodemo;
- use App\Models\DemoTest;
- use App\Models\Infos;
- use App\Models\MoneyUser;
- use App\Models\Notice;
- use App\Models\OrderDetailW;
- use App\Models\Ordertest;
- use App\Models\OrderW;
- use App\Models\RecomCodeExpire;
- use App\Models\Store;
- use App\Models\User;
- use App\Models\UserPay;
- use App\Models\UserW;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use GuzzleHttp\Client;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Config;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\File;
- use Illuminate\Support\Facades\Log;
- use Validator;
- use Intervention\Image\Facades\Image as Image;
- use Endroid\QrCode\LabelAlignment;
- use Endroid\QrCode\ErrorCorrectionLevel;
- use Endroid\QrCode\QrCode;
- class IndexController extends Controller{
- public function AddQrCode(Request $request){
- $id=Auth::user()->id;
- $user=User::find($id);
- $recom_ex=RecomCodeExpire::where('user_id',$id)->first();
- if ($user->qr_code && $recom_ex && $recom_ex->qr_code && $recom_ex->expired_at>Carbon::now()){
- $data=$user->qr_code;
- $expire_time=$recom_ex->expired_at;
- }else{
- $expire_time=Carbon::parse('+24 hours')->toDateTimeString();
- $data=$this->make_code($id,null,$expire_time);
- }
- $imgA=Image::canvas(343,552,'#FFFFFF');
- $img=Image::make($data)->resize(160,160);
- $imgB=Image::make(env('APP_URL').'/bg_red.png')->resize(343,552);
- $imgC=Image::make(env('APP_URL').'/bg_white.png')->resize(283,365);
- $imgL=Image::make(env('APP_URL').'/bg_logo.png')->resize(267,44);
- $imgA->insert($imgB,'',0,0);
- $imgA->insert($imgC,'',30,100);
- $imgA->insert($imgL,'',38,32);
- $imgA->insert($img,'',91,237);
- //匹配Unicode编码表对应字符
- $nickname=preg_replace("/[^\x{4e00}-\x{9fa5}^\x{0021}-\x{007e}]+/u", '', $user->nickname);
- if (mb_strlen($nickname)>6){
- $nickname=mb_substr($nickname,0,6);
- }
- if(empty($nickname)){
- $nickname=substr_replace($user->mobile,'****',3,4);
- }
- $imgA->text($nickname, 178, 160,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(24);
- $font->color('333333');
- $font->align('center');
- $font->angle(0);
- });
- $imgA->text('邀请您加入大卫博士', 109, 190,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(14);
- $font->color('333333');
- $font->angle(0);
- });
- $imgA->text('识别图中二维码填写信息', 85, 429,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(14);
- $font->color('333333');
- $font->angle(0);
- });
- $imgA->text('有效期至:'.$expire_time, 75, 480,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(12);
- $font->color('FFFFFF');
- $font->angle(0);
- });
- return $imgA->response("png");
- }
- public function AddQrCodeUp(Request $request){
- $user_id=$request->input('id');
- if(empty($user_id)){
- return $this->error('450001','','未获取到客户信息');
- }
- $id=Auth::user()->id;
- $expire_time=Carbon::parse('+24 hours')->toDateTimeString();
- $data=$this->make_code($id,$user_id,$expire_time);
- $imgA=Image::canvas(310,469,'#FFFFFF');
- $img=Image::make($data)->resize(178,178);
- $imgB=Image::make(env('APP_URL').'/bg_tan.png')->resize(310,469);
- $imgA->insert($imgB,'',0,0);
- $imgA->insert($img,'',67,122);
- $user=UserW::find($user_id);
- //匹配Unicode编码表对应字符
- $nickname=preg_replace("/[^\x{4e00}-\x{9fa5}^\x{0021}-\x{007e}]+/u", '', $user->nickname);
- if (mb_strlen($nickname)>6){
- $nickname=mb_substr($nickname,0,6);
- }
- if(empty($nickname)){
- $nickname=substr_replace($user->phone,'****',3,4);
- }
- $imgA->text($nickname, 157, 60,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(24);
- $font->color('FFFFFF');
- $font->align('center');
- $font->angle(0);
- });
- $imgA->text('· 欢迎您加入大卫博士 ·', 70, 90,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(14);
- $font->color('FFFFFF');
- $font->angle(0);
- });
- $imgA->text('识别图中二维码填写信息', 65, 340,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(14);
- $font->color('FFFFFF');
- $font->angle(0);
- });
- $imgA->text('有效期至:'.$expire_time, 50, 365,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(12);
- $font->color('FE9C9C');
- $font->angle(0);
- });
- return $imgA->response("png");
- }
- public function AddAppQrCode(Request $request){
- $id=Auth::user()->id;
- $user=User::find($id);
- $recom_ex=RecomCodeExpire::where('user_id',$id)->first();
- if ($user->qr_code && $recom_ex && $recom_ex->qr_code && $recom_ex->expired_at>Carbon::now()){
- $data=$user->qr_code;
- $expire_time=$recom_ex->expired_at;
- }else{
- $expire_time=Carbon::parse('+24 hours')->toDateTimeString();
- $data=$this->make_code($id,null,$expire_time);
- }
- $imgA=Image::canvas(343,552,'#FFFFFF');
- $img=Image::make($data)->resize(160,160);
- $imgB=Image::make(env('APP_URL').'/bg_red.png')->resize(343,552);
- $imgC=Image::make(env('APP_URL').'/bg_white.png')->resize(283,365);
- $imgL=Image::make(env('APP_URL').'/bg_logo.png')->resize(267,44);
- $imgA->insert($imgB,'',0,0);
- $imgA->insert($imgC,'',30,100);
- $imgA->insert($imgL,'',38,32);
- $imgA->insert($img,'',91,237);
- //匹配Unicode编码表对应字符
- $nickname=preg_replace("/[^\x{4e00}-\x{9fa5}^\x{0021}-\x{007e}]+/u", '', $user->nickname);
- if (mb_strlen($nickname)>6){
- $nickname=mb_substr($nickname,0,6);
- }
- if(empty($nickname)){
- $nickname=substr_replace($user->mobile,'****',3,4);
- }
- $imgA->text($nickname, 178, 160,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(24);
- $font->color('333333');
- $font->align('center');
- $font->angle(0);
- });
- $imgA->text('邀请您加入大卫博士', 109, 190,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(14);
- $font->color('333333');
- $font->angle(0);
- });
- $imgA->text('识别图中二维码填写信息', 85, 429,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(14);
- $font->color('333333');
- $font->angle(0);
- });
- $imgA->text('有效期至:'.$expire_time, 75, 480,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(12);
- $font->color('FFFFFF');
- $font->angle(0);
- });
- // return $imgA->response("png");
- return $imgA->encode('data-url');
- }
- public function AddQrCodess(Request $request){
- $id=39516;
- // $id=$request->id;
- // $id=39516;
- $user=User::find($id);
- $data=$this->make_code($id);
- $imgA=Image::canvas(380,560,'#FFFFFF');
- $img=Image::make($data)->resize(300,300);
- // $img=Image::make($qrCode);
- $imgB=Image::make(env('APP_URL').'/logo.jpg')->resize(80,80);
- $imgA->insert($img,'',40,160);
- $imgA->insert($imgB,'',150,10);
- $user=User::find($id);
- // try{
- // $imgC=Image::make($user->headimgurl)->resize(80,80);
- // }catch (\Exception $exception){
- $imgC=Image::make(env('APP_URL').'/logo.jpg')->resize(80,80);
- // }
- $imgA->insert($imgC,'',150,270);
- if (mb_strlen($user->nickname)>=6){
- $x=120;
- }elseif (mb_strlen($user->nickname)>=4 && mb_strlen($user->nickname)<6){
- $x=140;
- }elseif (mb_strlen($user->nickname)>=2 && mb_strlen($user->nickname)<4){
- $x=160;
- }else{
- $x=200;
- }
- $imgA->text('"'.mb_substr($user->nickname,0,6).'"', $x, 120,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(25);
- $font->color('000000');
- $font->angle(0);
- });
- $imgA->text('邀请你加入大卫博士', 90, 150,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(22);
- $font->color('000000');
- $font->angle(0);
- });
- $imgA->text('长按-识别二维码-填写信息', 45, 510,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(22);
- $font->color('F76454');
- $font->angle(0);
- });
- return $imgA->encode('data-url');
- }
- public function GetCrown(){
- $ids=User::where('level',3)->pluck('id');
- $re=Store::whereIn('user_id',$ids)->select('name','username','idCard')->get();
- return $this->success($re);
- }
- public function AddQrCodes(Request $request){
- $id=Auth::user()->id;
- // $id=$request->id;
- // $id=39516;
- $user=User::find($id);
- // $re=new WechatController();
- // $data=$re->makeQrCode();
- $data=$this->make_code($id);
- $imgA=Image::canvas(380,560,'#FFFFFF');
- $img=Image::make($data)->resize(300,300);
- // $img=Image::make($qrCode);
- $imgB=Image::make(env('APP_URL').'/logo.jpg')->resize(80,80);
- $imgA->insert($img,'',40,160);
- $imgA->insert($imgB,'',150,10);
- try{
- $imgC=Image::make($user->headimgurl)->resize(80,80);
- }catch (\Exception $exception){
- $imgC=Image::make(env('APP_URL').'/logo.jpg')->resize(80,80);
- }
- $imgA->insert($imgC,'',150,270);
- $imgA->text('"'.$user->nickname.'"', 120, 120,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(25);
- $font->color('000000');
- $font->angle(0);
- });
- $imgA->text('邀请你加入大卫博士', 90, 150,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(22);
- $font->color('000000');
- $font->angle(0);
- });
- $imgA->text('长按-识别二维码-填写信息', 45, 510,function ($font){
- $font->file('./ziti/fangzheng.TTF');
- $font->size(22);
- $font->color('F76454');
- $font->angle(0);
- });
- return $imgA->response('png');
- }
- public function make_code($id,$type=null,$expire){
- $user=User::find($id);
- $url=env('APP_URL').'/api/gzh?id='.$id.'&time='.strtotime($expire);
- // if($type){
- $url.='&type='.$type;
- // }
- // else{
- // $recom_ex=RecomCodeExpire::where('user_id',$id)->first();
- // if ($user->qr_code && $recom_ex && $recom_ex->qr_code && $recom_ex->expired_at>Carbon::now()){
- // return $user->qr_code;
- // }
- // }
- $qrCode = new \Endroid\QrCode\QrCode($url);
- // 内容区域宽高,默认为300
- $qrCode->setSize(600);
- // 外边距大小,默认为10
- // $qrCode->setMargin(10);
- // 设置编码
- $qrCode->setEncoding('UTF-8');
- // 设置容错等级
- $qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());
- // 设置二维码颜色,默认为黑色
- $qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0]);
- // 设置二维码背景色,默认为白色
- $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0]);
- // 设置二维码下方的文字
- $qrCode->setLogoPath('./logo.jpg');
- $qrCode->setLogoSize(200, 200);
- // $qrCode->setLogoPath('/www/wwwroot/test.woaidakele.cn/app-api/public/logo.jpg');
- // $qrCode->setLogoSize(80, 80);
- // $path='public/code/';
- // $path = public_path().'/code/';
- // File::makeDirectory($path,$mode = 0777,true,true);
- $folder_name = "upload/images/Qrcode/202103";
- // $folder_name = "upload/images/Qrcode/" . date("Ym", time());
- // 文件具体存储的物理路径,`public_path()` 获取的是 `public` 文件夹的物理路径。
- // 值如:/home/vagrant/Code/larabbs/public/uploads/images/avatars/201709/21/
- $upload_path = 'public/' . $folder_name;
- // 获取文件的后缀名,因图片从剪贴板里黏贴时后缀名为空,所以此处确保后缀一直存在
- $extension = 'png';
- // 拼接文件名,加前缀是为了增加辨析度,前缀可以是相关数据模型的 ID
- // 值如:1_1493521050_7BVc9v9ujP.png
- $filename = '/'.$id . '_' . time() . '_' . str_random(10) . '.' . $extension;
- if($type){
- header('Content-Type: '.$qrCode->getContentType());
- return $qrCode->writeString();
- }else{
- File::isDirectory($upload_path) or File::makeDirectory($upload_path,077,true,true);
- $qrCode->writeFile(base_path().'/public/'.$upload_path.$filename);
- DB::beginTransaction();
- try{
- $user->qr_code=env('APP_URL').'/'.$upload_path.'/'.$filename;
- $user->save();
- $recom_ex=RecomCodeExpire::where('user_id',$id)->first();
- if($recom_ex){
- $recom_ex->expired_at=$expire;
- $recom_ex->qr_code=env('APP_URL').'/'.$upload_path.'/'.$filename;
- $recom_ex->save();
- }else{
- RecomCodeExpire::create([
- 'user_id'=>$id,
- 'qr_code'=>env('APP_URL').'/'.$upload_path.'/'.$filename,
- 'expired_at'=>$expire,
- ]);
- }
- DB::commit();
- }catch(\Exception $e){
- DB::rollback();
- }
- return env('APP_URL').'/'.$upload_path.'/'.$filename;
- }
- }
- //获取微店购买满5套客户
- public function getStoreMeetFive(Request $request){
- $agent_id=Auth::user()->id;
- $store=Store::where('user_id',$agent_id)->select('id','name','phone')->first();
- if($store){
- $user_ids=OrderW::where('store_id',$store->id)->whereNull('recomer_agent_id')->groupBy('user_id')->pluck('user_id')->toArray();
- $recomer_ids=OrderW::where('store_id',$store->id)->whereNull('recomer_agent_id')->groupBy('recomer_id')->pluck('recomer_id')->toArray();
- }else{
- $user_ids=[];
- $recomer_ids=[];
- }
- $recom_agent_ids=OrderW::where('recomer_agent_id',$agent_id)->groupBy('user_id')->pluck('user_id')->toArray();
- $user_ids=array_merge($user_ids,$recomer_ids,$recom_agent_ids);
- $user=UserW::with(['recom:id,nickname,phone'])->whereIn('id',$user_ids);
- $search_name=$request->input('search_name');
- if(!empty($search_name)){
- $user->where(function($query)use($search_name){
- $query->where('nickname','like','%'.$search_name.'%')
- ->orWhere('phone','like','%'.$search_name.'%');
- });
- }
- $list=$user->select('id','nickname','avatar','phone','recomer_id','recomer_agent_id')->get()->toArray();
- foreach($list as $key=>$val){
- if(User::where('mobile',$val['phone'])->exists()){ //存在代理账号
- unset($list[$key]);
- }else{
- if($agent_id==$val['recomer_agent_id']){
- $list[$key]['is_recom']=1;
- $agent=User::find($agent_id);
- $agent_recom_id=$agent->recom_id;
- // $agent_recom_id=User::where('id',$agent_id)->value('recom_id');
- // $agent_user_id=UserW::where('phone',$store->phone)->value('id');
- $agent_user_id=UserW::where('phone',$agent->mobile)->value('id');
- $recom_store_id=Store::where('user_id',$agent_recom_id)->value('id');
- $list[$key]['sale_total']=(int)OrderW::where(function($query)use($val,$recom_store_id,$agent_user_id){
- $query->where('store_id',$recom_store_id)
- ->where(function($que)use($val,$agent_user_id){
- $que->where(function($q)use($val,$agent_user_id){
- $q->where('user_id',$val['id'])->whereIn('recomer_status',[0,2])->where('recomer_id',$agent_user_id);
- })->orWhere(function($q)use($val){
- $q->where('recomer_id',$val['id'])->whereIn('recomer_status',[0,1]);
- });
- });
- })
- ->whereIn('status',[2,3])
- ->sum('total');
- $list[$key]['self_total']=(int)OrderW::query()
- ->where('store_id',$recom_store_id)->where('user_id',$val['id'])->where('recomer_id',$agent_user_id)
- ->whereIn('recomer_status',[0,2])
- ->whereIn('status',[2,3])
- ->sum('total');
- $list[$key]['recom_total']=(int)OrderW::query()
- ->where('store_id',$recom_store_id)->where('recomer_id',$val['id'])
- ->whereIn('recomer_status',[0,1])
- ->whereIn('status',[2,3])
- ->sum('total');
- }else{ //自买或介绍客户
- $list[$key]['is_recom']=0;
- $list[$key]['sale_total']=(int)OrderW::where(function($query)use($val,$store){
- $query->where('store_id',$store->id)
- ->where(function($que)use($val,$store){
- $que->where(function($q)use($val){
- $q->where('user_id',$val['id'])->whereIn('recomer_status',[0,2]);
- })->orWhere(function($q)use($val){
- $q->where('recomer_id',$val['id'])->whereIn('recomer_status',[0,1]);
- });
- });
- })
- ->whereIn('status',[2,3])
- ->sum('total');
- $list[$key]['self_total']=(int)OrderW::query()
- ->where('store_id',$store->id)->where('user_id',$val['id'])
- ->whereIn('recomer_status',[0,2])
- ->whereIn('status',[2,3])
- ->sum('total');
- $list[$key]['recom_total']=(int)OrderW::query()
- ->where('store_id',$store->id)->where('recomer_id',$val['id'])
- ->whereIn('recomer_status',[0,1])
- ->whereIn('status',[2,3])
- ->sum('total');
- }
- if(empty($val['recomer_id']) || empty($val['recom'])){
- $list[$key]['recom_info']=0;
- }
- }
- }
- $sale_total = array_column( $list, 'sale_total'); //取出数组中status的一列,返回一维数组
- array_multisort($sale_total, SORT_DESC, $list);//排序,根据$status 排序
- return $this->success(['list'=>array_values($list),'store'=>$store]);
- }
- public function getMeetFiveDetail123(Request $request){
- $agent_id=Auth::user()->id;
- $store_id=$request->input('store_id');
- $user_id=$request->input('user_id');
- $self['user']=UserW::with(['recom:id,nickname,phone'])->where('id',$user_id)->select('id','nickname','phone','avatar','recomer_id','recomer_agent_id')->first();
- if($self['user']->recomer_agent_id==$agent_id){
- $agent=User::where('id',$agent_id)->first();
- $agent_user_id=UserW::where('phone',$agent->mobile)->value('id');
- $agent_recom_id=$agent->recom_id;
- $store_id=Store::where('user_id',$agent_recom_id)->value('id');
- $self['order']= OrderDetailW::with(['goods:id,name,img'])
- ->whereHas('order',function($query)use($store_id,$user_id,$agent_user_id){
- $query->whereIn('status',[2,3])->where('store_id',$store_id)->where('user_id',$user_id)
- ->where('recomer_id',$agent_user_id)->whereIn('recomer_status',[0,2]);
- })
- ->select(DB::raw('sum(num) as num'),'goods_id')->groupBy('goods_id')->get();
- }else{
- $self['order']= OrderDetailW::with(['goods:id,name,img'])
- ->whereHas('order',function($query)use($store_id,$user_id){
- $query->whereIn('status',[2,3])->where('store_id',$store_id)->where('user_id',$user_id)->whereIn('recomer_status',[0,2]);
- })
- ->select(DB::raw('sum(num) as num'),'goods_id')->groupBy('goods_id')->get();
- }
- $recom_user_ids=OrderW::where('store_id',$store_id)->where('recomer_id',$user_id)->whereIn('status',[2,3])
- ->whereIn('recomer_status',[0,1])
- ->groupBy('user_id')->pluck('user_id')->toArray();
- $recom=[];
- foreach($recom_user_ids as $key=>$val){
- $recom[$key]['user']=UserW::where('id',$val)->select('id','nickname','phone')->first();
- $recom[$key]['order']=OrderDetailW::with(['goods:id,name,img'])
- ->whereHas('order',function($query)use($store_id,$val,$user_id){
- $query->whereIn('status',[2,3])->where('store_id',$store_id)
- ->where('user_id',$val)->where('recomer_id',$user_id)
- ->whereIn('recomer_status',[0,1]);
- })
- ->select(DB::raw('sum(num) as num'),'goods_id')->groupBy('goods_id')->get();
- }
- $list['self']=$self;
- $list['recom']=$recom;
- return $this->success($list);
- }
- public function getMeetFiveDetail(Request $request){
- $agent_id=Auth::user()->id;
- $store_id=$request->input('store_id');
- $user_id=$request->input('user_id');
- $self['user']=UserW::with(['recom:id,nickname,phone'])->where('id',$user_id)->select('id','nickname','phone','avatar','recomer_id','recomer_agent_id')->first();
- if(empty($self['user']->recomer_id) || empty($self['user']->recom)){
- $self['user']->has_recome=0;
- }else{
- $self['user']->has_recome=1;
- }
- if($self['user']->recomer_agent_id==$agent_id){
- $self['user']->is_recom=1;
- $agent=User::where('id',$agent_id)->first();
- $agent_user_id=UserW::where('phone',$agent->mobile)->value('id');
- $agent_recom_id=$agent->recom_id;
- $store_id=Store::where('user_id',$agent_recom_id)->value('id');
- $order_ids= OrderW::whereIn('status',[2,3])
- ->where('store_id',$store_id)->where('user_id',$user_id)
- ->where('recomer_id',$agent_user_id)->whereIn('recomer_status',[0,2])->pluck('id');
- $self['order']= OrderDetailW::with(['goods:id,name,img'])
- ->whereIn('order_id',$order_ids)
- // ->whereHas('order',function($query)use($store_id,$user_id,$agent_user_id){
- // $query->whereIn('status',[2,3])->where('store_id',$store_id)->where('user_id',$user_id)
- // ->where('recomer_id',$agent_user_id)->whereIn('recomer_status',[0,2]);
- // })
- ->select(DB::raw('sum(num) as num'),'goods_id')->groupBy('goods_id')->get();
- }else{
- $self['user']->is_recom=0;
- $order_ids= OrderW::whereIn('status',[2,3])
- ->where('store_id',$store_id)->where('user_id',$user_id)
- ->whereIn('recomer_status',[0,2])->pluck('id');
- $self['order']= OrderDetailW::with(['goods:id,name,img'])
- ->whereIn('order_id',$order_ids)
- ->select(DB::raw('sum(num) as num'),'goods_id')->groupBy('goods_id')->get();
- }
- $recom_user_ids=OrderW::where('store_id',$store_id)->where('recomer_id',$user_id)->whereIn('status',[2,3])
- ->whereIn('recomer_status',[0,1])
- ->groupBy('user_id')->pluck('user_id')->toArray();
- $recom=[];
- foreach($recom_user_ids as $key=>$val){
- $recom[$key]['user']=UserW::where('id',$val)->select('id','nickname','phone')->first();
- $order_ids= OrderW::whereIn('status',[2,3])
- ->where('store_id',$store_id)->where('user_id',$val)
- ->where('recomer_id',$user_id)->whereIn('recomer_status',[0,1])->pluck('id');
- $recom[$key]['order']=OrderDetailW::with(['goods:id,name,img'])
- ->whereIn('order_id',$order_ids)
- // ->whereHas('order',function($query)use($store_id,$val,$user_id){
- // $query->whereIn('status',[2,3])->where('store_id',$store_id)
- // ->where('user_id',$val)->where('recomer_id',$user_id)
- // ->whereIn('recomer_status',[0,1]);
- // })
- ->select(DB::raw('sum(num) as num'),'goods_id')->groupBy('goods_id')->get();
- }
- $list['self']=$self;
- $list['recom']=$recom;
- return $this->success($list);
- }
- public function get_address(Request $request){
- $Address=Address::groupBy('mobile','province','address')->get()->toArray();
- foreach ($Address as $k=>$v){
- $re=Address::where('mobile',$v->mobile)->get();
- if (count($re)>1){
- Log::error(json_encode($re));
- }
- }
- dd(1);
- }
- function indes(Request $request){
- $mes['openid']='oVd_5w6zZm-7DfHEB00lheLtjkK0';
- $mes['data']=[
- 'first' => '很抱歉,邀请人审核被驳回!',
- 'keyword1' => '邀请人审核失败',
- 'keyword2' => '邀请人审核失败',
- 'keyword3' => date("Y-m-d H:i"),
- 'remark' => '点击链接进入系统,查看详情',
- ];
- event(new WechatMessageEvent($mes));
- }
- public function rand_code($num){
- $code='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- $str=$num."_";
- $str_1='';
- for ($i=0;$i<20;$i++){
- $int=rand(0,34);
- $str_1.=mb_substr($code,$int,1);
- }
- $str=$str.mb_substr(time(),2,3).$str_1;
- return $str.mb_substr(time(),7,3);
- }
- public function login(){
- $app=app('wechat.official_account');
- $shortUrl = $app->url->shorten('https://easywechat.com');
- dd($shortUrl['short_url']);
- $user=User::where('mobile',15236877164)->first();
- $token = Auth::guard('api')->fromUser($user);
- return $this->success($token);
- }
- public function info(Request $request){
- $rule=[
- 'dwbs_weapp'=>'required',
- 'dwbs_weapp_secret'=>'required',
- 'mobile'=>'required'
- ];
- $message=[
- 'dwbs_weapp.required'=>'参数不正确',
- 'dwbs_weapp_secret.required'=>'参数不正确'
- ];
- $va=Validator::make($request->all(),$rule,$message);
- if ($va->fails()){
- return $this->error(300,'',$va->errors()->first());
- }
- $acc=\config('config.dwbs_weapp');
- $secret=\config('config.dwbs_weapp_secret');
- if ($request->dwbs_weapp==$acc&&$request->dwbs_weapp_secret==$secret){
- $user=User::where('mobile',$request->mobile)->whereIn('cert_status',[3,6])->where('status',0)->where('deleted_at','=',null)->where('service_status',0)->first();
- if ($user){
- if ($user->level==3){
- $re['level_name']=judge_level($user->level);
- }else{
- $data=$this->look($user->agent_user->mobile);
- $re['level_name']=judge_level($user->level);
- $re['up_name']=$data['nickname'];
- $re['up_phone']=$data['mobile'];
- }
- $re['dwbs_id']=$user->id;
- $re['nickname']=$user->nickname==null?$user->name:$user->nickname;
- }else{
- $re=[];
- }
- return $this->success($re);
- }
- return $this->error(400);
- }
- public function look($phone){
- $user=User::where('mobile',$phone)->first();
- if ($user->level==3){
- return ['mobile'=>$user->mobile,'nickname'=>$user->nickname];
- }else{
- $data=$this->look($user->agent_user->mobile);
- return $data;
- }
- }
- public function index(Request $request){
- $phone=15236877164;
- $client=new Client();
- $url='http://api.woaidakele.cn/api/index/info';
- $array = [
- 'form_params' => [
- 'mobile' => $phone,
- 'dwbs_weapp' => 'acc',
- 'dwbs_weapp_secret' =>'secret',
- ]
- ];
- $response = $client->request('POST', $url,$array);
- $ad = json_decode($response->getBody()->getContents());
- dd($ad->data->up_name);
- if ($ad->code==300){
- dd('ceshi');
- }else{
- dd('success');
- }
- $avatarResponse = $client->get($url);
- //
- $img = Image::make($avatarResponse->getBody()->getContents());
- // $img=Image::make(public_path().'/138.jpg');
- $data=['争霸赛张奇','15236877164'];
- $img->text('争霸赛张奇', 400, 565,function ($font){
- $font->file(base_path().'/public/fangzheng.ttf');
- $font->size(25);
- $font->angle(0);
- });
- $img->text('15236877164', 400, 635,function ($font){
- $font->file(base_path().'/public/fangzheng.ttf');
- $font->size(25);
- $font->angle(0);
- });
- $img->text('顶级代理', 350, 820,function ($font){
- $font->file(base_path().'/public/fangzheng.ttf');
- $font->size(60);
- $font->angle(0);
- });
- $img->text('DWBS0001620031130100336179', 285, 965,function ($font){
- $font->file(base_path().'/public/fangzheng.ttf');
- $font->size(25);
- $font->angle(0);
- });
- $year=mb_substr($time_start,0,4);
- $month=mb_substr($time_start,5,2);
- $day=mb_substr($time_start,8,2);
- $year_t=mb_substr($time_end,0,4);
- $month_t=mb_substr($time_end,5,2);
- $day_t=mb_substr($time_end,8,2);
- $img->text("{$year}年{$month}月{$day}日 - {$year_t}年{$month_t}月{$day_t}日", 285, 1050,function ($font){
- $font->file(base_path().'/public/fangzheng.ttf');
- $font->size(25);
- $font->angle(0);
- });
- $name=$this->rand_code(100);
- // $img->save(base_path().'/public/'.$name.'.jpg');
- return $img->response("png");
- $rules=[
- 'type'=>'required',
- 'page'=>'required'
- ];
- $message=[
- 'type.required'=>'type不能为空',
- 'page.required'=>'page不能为空'
- ];
- $v=Validator::make($request->all(),$rules,$message);
- if ($v->fails()){
- dd($v->errors()->first());
- return $this->error(600,[],$v->errors()->first());
- }
- return 's';
- // $seconds=1000;
- // $value=Cache::get('users');
- // if ($value){
- // return $value;
- // }else{
- // Cache::remember('users', $seconds, function () {
- // return DB::table('users')->where('id','>',30000)->get();
- // });
- // }
- // $value=Cache::get('users');
- // return $value;
- //// return User::where('id','>',30000)->get();
- $phone='15103562283';
- $code = mb_substr($phone, 3, 2) . mb_substr($phone, 8, 2) . mb_substr($phone, 6, 2);
- return $code;
- // $chars=null;
- // dump('1');
- // $len=6;
- // if (is_null($chars)) {
- // $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- // }
- // dump('1');
- // mt_srand(10000000*(double)microtime());
- // for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++) {
- // $str .= $chars[mt_rand(0, $lc)];
- // }
- // dump('1');
- // return $str;
- // $count=User::where('recom_code',$str)->count();
- // if($count>0) {
- //// $str=$this->auth_code(6);
- // return $str;
- // }else{
- // return $str;
- // }
- //
- //
- //// return $this->indes();
- // $user=Auth::user();
- // $user=User::where('mobile','13779416168')->first();
- $re=[
- ['name'=>'蜕变/毕中平','phone'=>'18636496182'],
- ['name'=>'张红梅','phone'=>'13835690160'],
- ['name'=>'张妮','phone'=>'13303564360'],
- ['name'=>'小u妈 /冯江丽','phone'=>'13327566969'],
- ['name'=>'仙/姬国仙','phone'=>'13513561649'],
- ['name'=>'苏广荣 ','phone'=>'15703461531'],
- ['name'=>'任志北','phone'=>'18635613103'],
- ['name'=>'栗玲梅','phone'=>'13393469347'],
- ['name'=>'李春霞','phone'=>'13782683735'],
- ['name'=>'米粒','phone'=>'15299405680'],
- ['name'=>'丽丽','phone'=>'15739201119'],
- ['name'=>'婧茹','phone'=>'13363413419'],
- ['name'=>'许越畅','phone'=>'13387234678']
- ];
- if ($request->has('page')){
- $page=($request->page)-1;
- }else{
- $page=0;
- }
- $data=[];
- if ($request->type==0){
- $user_all=User::where('agent_id',$user->id)->where('status',0)->whereIn('cert_status',[3,6])->where('deleted_at','=',null)->orderBy('id')->get();
- $arr_per=[];
- foreach ($user_all as $k=>$v){
- $arr_per[$k]['id']=$v->id;
- $arr_per[$k]['avatar']=$v->headimgurl;
- $arr_per[$k]['nickname']=$v->nickname;
- $arr_per[$k]['level_name']=judge_level($v->level);
- }
- $num=count($arr_per);
- // return $num;
- $num1=$num-$page*15;
- if ($num1>=15){
- $j=15;
- }else{
- $j=$num1;
- }
- for ($i=0;$i<$j;$i++){
- $data[$i]['id']=$arr_per[$page*15+$i]['id'];
- $data[$i]['avatar']=$arr_per[$page*15+$i]['avatar'];
- $data[$i]['nickname']=$arr_per[$page*15+$i]['nickname'];
- $data[$i]['level_name']=$arr_per[$page*15+$i]['level_name'];
- }
- // return $this->success($data);
- }else{
- $user_all=User::where('agent_id',$user->id)->where('status',0)->where('deleted_at','=',null)->orderBy('id')->whereIn('cert_status',[3,6])->get();
- // $user_all_1=User::where('agent_id',$user->id)->where('recom_id',$user->id)->where('status',0)->whereIn('cert_status',[3,6])->where('deleted_at','=',null)->orderBy('id')->get();
- $user_data=[];
- $arr_per=[];
- $all=[];
- $all_1=[];
- foreach ($user_all as $k=>$v){
- $arr=[];
- // $arr_per[$k]['id']=$v->id;
- // $arr_per[$k]['avatar']=$v->headimgurl;
- // $arr_per[$k]['nickname']=$v->nickname;
- // $arr_per[$k]['level_name']=judge_level($v->level);
- $user_per=User::where('agent_id',$v->id)->where('status',0)->where('deleted_at','=',null)->orderBy('id')->whereIn('cert_status',[3,6])->get();
- if ($user){
- foreach ($user_per as $key=>$value){
- $arr[$key]['id']=$value->id;
- $arr[$key]['avatar']=$value->headimgurl;
- $arr[$key]['nickname']=$value->nickname;
- $arr[$key]['level_name']=judge_level($value->level);
- }
- $all=array_merge($all,$arr);
- }
- }
- $user_data=array_merge($all,$arr_per);
- // foreach ($user_all as $k=>$v){
- // $arr_per=[];
- // $user_per=User::where('agent_id',$v->id)->where('status',0)->where('deleted_at','=',null)->orderBy('id')->whereIn('cert_status',[3,6])->get();
- // if ($user){
- // foreach ($user_per as $key=>$value){
- // $arr_per[$key]['id']=$value->id;
- // $arr_per[$key]['avatar']=$value->headimgurl;
- // $arr_per[$key]['nickname']=$value->nickname;
- // $arr_per[$key]['level_name']=judge_level($value->level);
- // }
- // $all_1=array_merge($all_1,$arr_per);
- // }
- // }
- // $user_data=array_merge($user_data,$all_1);
- $num=count($user_data);
- $num1=$num-$page*15;
- if ($num1>=15){
- $j=15;
- }else{
- $j=$num1;
- }
- // return $num;
- for ($i=0;$i<$j;$i++){
- $data[$i]['id']=$user_data[$page*15+$i]['id'];
- $data[$i]['avatar']=$user_data[$page*15+$i]['avatar'];
- $data[$i]['nickname']=$user_data[$page*15+$i]['nickname'];
- $data[$i]['level_name']=$user_data[$page*15+$i]['level_name'];
- }
- }
- return $this->success($data);
- // $user=User::where('mobile','18635680853')->first();
- // $today=Carbon::today()->toDateTimeString();
- // $month=Carbon::now()->firstOfMonth()->toDateTimeString();
- // $user_all=User::whereIn('cert_status',[3,6])->where('created_at','>',$today)->get();
- // $num=0;
- // foreach ($user_all as $k=>$v){
- // if ($v->agent_id==$user->id){
- // $num=$num+1;
- // }else{
- // $arr=User::where('id',$v->agent_id)->first();
- // if ($arr->agent_id==$user->id){
- // $num=$num+1;
- // }
- // }
- // }
- //
- // $user_all=User::whereIn('cert_status',[3,6])->where('created_at','>',$month)->get();
- // $num_all=0;
- // foreach ($user_all as $k=>$v){
- // if ($v->agent_id==$user->id){
- // $num_all=$num_all+1;
- // }else{
- // $arr=User::where('id',$v->agent_id)->first();
- // if ($arr->agent_id==$user->id){
- // $num_all=$num_all+1;
- // }
- // }
- // }
- //
- // $data=['num'=>$num,'all_num'=>$num_all];
- //// Log::error('{-0-----新增代理-------}'.json_encode($data));
- // return $this->success($data);
- // return
- return $this->success($data);
- // }else{
- // if ($request->type==0){
- // $user_all=User::where('agent_id',$user->id)->where('recom_id',$user->id)->where('status',0)->whereIn('cert_status',[3,6])->where('deleted_at','=',null)->orderBy('id')->get();
- // foreach ($user_all as $k=>$v){
- // $arr_per[$k]['id']=$v->id;
- // $arr_per[$k]['avatar']=$v->headimgurl;
- // $arr_per[$k]['nickname']=$v->nickname;
- // $arr_per[$k]['level_name']=judge_level($v->level);
- // }
- // for ($i=0;$i<15;$i++){
- // $data[$i]['id']=$arr_per[$page*15+$i]['id'];
- // $data[$i]['avatar']=$arr_per[$page*15+$i]['avatar'];
- // $data[$i]['nickname']=$arr_per[$page*15+$i]['nickname'];
- // $data[$i]['level_name']=$arr_per[$page*15+$i]['level_name'];
- // }
- // return $this->success($data);
- // }else{
- // $user_all=User::where('agent_id',$user->id)->where('recom_id','<>',$user->id)->where('status',0)->where('deleted_at','=',null)->orderBy('id')->whereIn('cert_status',[3,6])->get();
- // foreach ($user_all as $k=>$v){
- // $arr_per[$k]['id']=$v->id;
- // $arr_per[$k]['avatar']=$v->headimgurl;
- // $arr_per[$k]['nickname']=$v->nickname;
- // $arr_per[$k]['level_name']=judge_level($v->level);
- // }
- // for ($i=0;$i<15;$i++){
- // $data[$i]['id']=$arr_per[$page*15+$i]['id'];
- // $data[$i]['avatar']=$arr_per[$page*15+$i]['avatar'];
- // $data[$i]['nickname']=$arr_per[$page*15+$i]['nickname'];
- // $data[$i]['level_name']=$arr_per[$page*15+$i]['level_name'];
- // }
- // return $this->success($data);
- // }
- // }
- // foreach ($user_all as $k=>$v){
- // $data[$k]['id']=$v->id;
- // $data[$k]['avatar']=$v->headimgurl;
- // $data[$k]['nickname']=$v->nickname;
- // $data[$k]['level_name']=judge_level($v->level);
- // }
- // $arr=$this->new_per();
- // $re= $arr->original;
- // $res=[
- // 'today_new'=>$re['data']['num'],
- // 'month_new'=>$re['data']['all_num'],
- // 'size'=>15,
- // 'total'=>$count,
- // 'list'=>$data
- // ];
- // Log::error('{-------代理数量-----}'.json_encode($res));
- return $this->success($user_data);
- // 、 $user=User::where('mobile',15236877164)->first();
- // return $user->recom_user->name;
- $user= (new User())->newQuery();
- $search_name='';
- $agent_name='';
- $recom_name='15236877164';
- if($search_name){
- $user->where('mobile','like',"%{$search_name}%")
- ->orWhere('cre_num', 'like', '%' . $search_name . '%')
- ->orWhere('nickname', 'like', '%' . $search_name . '%')
- ->orWhere('realname', 'like', '%' . $search_name . '%');
- }
- if($agent_name){
- $agent_id = User::where('nickname', 'like', '%' . $agent_name . '%')
- ->orWhere('mobile', 'like', '%' . $agent_name . '%')
- ->orWhere('cre_num', 'like', '%' . $agent_name . '%')
- ->orWhere('realname', 'like', '%' . $agent_name . '%')
- ->pluck('id');
- $user->where('id','in',$agent_id);
- }
- if($recom_name){
- $recom_id = User::where('nickname', 'like', '%' . $recom_name . '%')
- ->orWhere('mobile', 'like', '%' . $recom_name . '%')
- ->orWhere('cre_num', 'like', '%' . $recom_name . '%')
- ->orWhere('realname', 'like', '%' . $recom_name . '%')
- ->pluck('id');
- $user->whereIn('id',$recom_id);
- }
- $count = $user->with(['recom_user','agent_user'])->get();
- // dd($count);
- foreach ($count as $k=>$v){
- if ($v->recom_user==null){
- $data[$k]['reaom_nickname']='';
- $data[$k]['reaom_name']='';
- $data[$k]['recom_realname']='';
- }else{
- $data[$k]['reaom_nickname']=$v->recom_user->nickname;
- $data[$k]['reaom_name']=$v->recom_user->reaom_name;
- $data[$k]['recom_realname']=$v->recom_user->recom_realname;
- }
- $data[$k]['name']=$v->name;
- $data[$k]['nickname']=$v->nickname;
- $data[$k]['mobile']=$v->mobile;
- $data[$k]['realname']=$v->realname;
- }
- dd($data);
- return $data;
- // $user_id = User::where(function ($q)use($search_name){
- // $q->where('nickname', 'like', '%' . $search_name . '%')
- // ->orWhere('mobile', 'like', '%' . $search_name . '%')
- // ->orWhere('cre_num', 'like', '%' . $search_name . '%')
- // ->orWhere('realname', 'like', '%' . $search_name . '%');
- // })->value('id');
- //
- // $count = User::where('recom_id',$user_id)->count();
- // return $count;
- // ''
- // if ($search_name==''&&$agent_name==''&&$recom_name!='')
- // DB::connection()->enableQueryLog();
- $count=$user->where(function ($query) use ($search_name) {
- if($search_name != ''){
- $query->where('nickname', 'like', '%' . $search_name . '%')
- ->orWhere('mobile', 'like', '%' . $search_name . '%')
- ->orWhere('cre_num', 'like', '%' . $search_name . '%')
- ->orWhere('realname', 'like', '%' . $search_name . '%');
- }
- })
- ->whereIn('cert_status',[3,6])
- // ->where($where)
- ->with([
- // 'recom:id,nickname,mobile','agent:id,nickname,mobile',
- 'recom_user'=> function ($recom_user) use ($recom_name) {
- $recom_user->where('nickname', 'like', '%' . $recom_name . '%')
- ->orWhere('mobile', 'like', '%' . $recom_name . '%')
- ->orWhere('cre_num', 'like', '%' . $recom_name . '%')
- ->orWhere('realname', 'like', '%' . $recom_name . '%');
- },
- // 'agent_user'=>function ($agent_user) use ($agent_name) {
- // $agent_user->where('nickname', 'like', '%' . $agent_name . '%')
- // ->orWhere('mobile', 'like', '%' . $agent_name . '%')
- // ->orWhere('cre_num', 'like', '%' . $agent_name . '%')
- // ->orWhere('realname', 'like', '%' . $agent_name . '%');
- // }
- ])
- ->get();
- //dd(DB::getQueryLog());
- return $count;
- // $num=3;
- //
- // try {
- // DB::beginTransaction();
- // $demo=new Demo();
- // $demo->name='kele';
- //// $demo->names='kele';
- // $demo->save();
- // $this->demo();
- // DB::commit();
- // }catch (\Exception $exception){
- // DB::rollBack();
- // Log::error('ssssss');
- // }
- // $user=User::find(24);
- // $user->auth_code=auth_code($user->mobile);
- // $user->auth_startime=Carbon::now()->toDateTimeString();
- // $user->auth_endtime=Carbon::now()->toDateTimeString();
- // $user->save();
- // $re="[{\"price\":\"299.00\",\"name\":\"\\u5927\\u536b\\u535a\\u58eb\\u6d4b\\u8bd5\\u5546\\u54c15\",\"img\":\"http:\\\/\\\/192.168.0.15:8011\\\/storage\\\/goods\\\/8HyLVAxW8en9TrveWfrqDKeCqLlU4vUkfKQgMgea.jpeg\",\"num\":\"7\"}]";
- // $res=json_decode($re);
- // $re=code('15236877164');
- // DB::table('users_copy1')->update(['recom_id'=>null]);
- $user=User::find(33);
- return $this->success($user);
- if ($user){
- return $user->nickname;
- }
- return 's';
- dd($user);
- return $this->success(['num'=>20]);
- $data=$this->indes();
- $re=$data->original;
- return $re['data']['num'];
- $user_all=User::where('agent_id',33)->where('recom_id',33)->where('status',0)->whereIn('cert_status',[3,6])->get();
- return $this->success($user_all);
- return md5('877164');
- $user=User::all();
- foreach ($user as $k=>$v){
- $ress=[];
- if ($v->id==24){
- }else{
- $re[$k]['id']=$v->id;
- $re[$k]['name']=$v->name;
- }
- $res=array_merge($ress,$re);
- }
- return $this->success($res);
- $time='2020-01-16 22:08:06';
- $time=strtotime($time);
- $now=Carbon::now()->timestamp;
- $data=$now-$time;
- $n=$data/3600;
- return $n;
- $up_phone=DB::table('app_user')->where('cellphone','=','15236877163')->value('upper_cellphone');
- if ($up_phone){
- $id=DB::table('users_copy1')->where('mobile',$up_phone)->value('id');
- // if ($id){
- // DB::table('users_copy1')->where('id',$v->id)->update(['agent_id'=>$id]);
- // }
- return $id;
- }
- return 's';
- $phone=13608638531;
- $date='20200229';
- $data=DB::select("select recom_code FROM users_copy1 GROUP BY recom_code HAVING COUNT(recom_code)>1;");
- return $data;
- $res=DB::table('app_user')->whereIn('id',['4058','26536'])->get();
- return $res;
- return Carbon::now()->addYear('1')->firstOfMonth()->toDateTimeString();
- return date('Y-m-d H:i:s',strtotime($date));
- $code = mb_substr($phone, 3, 2) . mb_substr($phone, 8, 2) . mb_substr($phone, 6, 2);
- return $code;
- $user=User::where('id','>',2)->paginate(15);
- Log::error('{--------}'.json_encode($user));
- foreach ($user as $k=>$v){
- $re[$k]=$v->id;
- }
- return $re;
- return Carbon::now()->addYear('1')->startOfDay()->toDateTimeString();
- return substr('15236877164',8,3);
- return auth_code(15236877164);
- echo base_convert($request->num,10,32);
- }
- public function demo(){
- $demo=new Demodemo();
- $demo->name='kele';
- $demo->names='kele';
- $demo->save();
- }
- public function test(Request $request){
- $client=new Client();
- $url="https://api.weixin.qq.com/sns/userinfo";
- $array=[
- 'query' => [
- 'access_token' =>$request->access_token,
- 'openid'=>$request->openid
- ]
- ];
- $data=$client->request('GET',$url,$array);
- $ad = json_decode($data->getBody()->getContents());
- echo $ad->nickname;
- dd($ad);
- // $address=Address::find(1);
- }
- public function json(Request $request){
- return md5_file('https://api.jiuweiyun.cn/public/uploads/images/img/201912/24/5850_1577162472_WD3doBoiDT.png');
- $data='1000050001202001071103128744231';
- $d='100005000120200107110312844231';
- similar_text($data,$d,$percent);
- return $percent;
- $address=new Address();
- $address->provice='河南';
- $address->uid=120;
- $address->save();
- return $address->id;
- $data=[
- [
- "name"=> "男款(黑色)",
- "size"=> 's',
- 'num'=>'2',
- ],
- [
- "name"=> "男款(黑色)",
- "size"=> 'l',
- 'num'=>'3,'
- ],
- [
- "name"=> "男款(黑色)",
- "size"=> 'xl',
- 'num'=>'4',
- ],
- [
- "name"=> "男款(肤色)",
- "size"=> 'l',
- 'num'=>'5,'
- ],
- [
- "name"=> "男款(肤色)",
- "size"=> 's',
- 'num'=>'6',
- ],
- [
- "name"=> "女款(黑色)",
- "size"=> 'l',
- 'num'=>'10,'
- ]
- ];
- $result= array();
- foreach ($data as $key => $value) {
- $result[$value['name']][] = $value;
- }
- $i=0;
- foreach ($result as $k=>$v){
- foreach ($v as $key=>$val){
- $dat[$key]=$val['size'];
- $dats[$key]=$val['num'];
- }
- $datas[$i]['name']=$v[0]['name'];
- $datas[$i]['size']=$dat;
- $datas[$i]['num']=$dats;
- $i++;
- }
- return $datas;
- // for($i=0;$i<$count-1;$i++){
- // for ($j=$i+1;$j<$count;$j++){
- // if ($data[$i]['name']==$data[$j]['name']){
- // $name[$i]=$data[$i]['name'];
- // $size=$data[$i]['size'];
- // }
- // }
- // $dat[$i]=$data[$i]['size'];
- // }
- return $dat;
- }
- public function getMessageInfo(){
- $user_id=Auth::user()->id;
- $notice=Notice::where('user_id',$user_id)->orderByDesc('id')->limit(1)->get();
- $info=Infos::where('disabled','0')->orderBy('is_top','desc')->orderBy('top_at','desc')->limit(2)->get();
- if(count($notice)>0){
- $data['notice']=$notice[0];
- }else{
- $data['notice']=null;
- }
- $data['info']=$info;
- $data['banner']=Banner::where('status',1)->orderBy('sort')->orderByDesc('id')->get();
- return $this->success_list($data);
- }
- //获取公告通知列表
- public function getMessageList(Request $request){
- $page_index=$request->input('page_index');
- $page_size=$request->input('page_size');
- $num=$page_size*($page_index-1);
- $user_id=Auth::user()->id;
- $data=Infos::query()->where(function($query){
- $query->whereIn('type',[1,4])->where('disabled','0');
- })
- ->orWhere(function($query)use($user_id){
- $query->whereIn('type',[2,3,5,6])->where('user_id',$user_id);
- });
- $count=$data->count();
- $list=$data->orderByDesc('is_top','top_at')
- ->skip($num)->take($page_size)->get();
- return $this->success_list($list,'',$count);
- }
- public function get_infos(){
- $order=Ordertest::where('is_deleted',0)->where('created_at','>=','2020-08-24 21:00:00')->with(['order_detail','get_pay'=>function($q){
- $q->whereIn('type',[1,2,3]);
- },'get_user'])->get();
- $i=0;
- foreach ($order as $k=>$v){
- $money=0;
- $pay_money=0;
- $pay=0;
- $pay1=0;
- $pay2=0;
- foreach ($v->order_detail as $ke=>$va){
- $money+=$va->money;
- // $pay_money+=$va->pay_money;
- //该订单总金额
- }
- foreach ($v->get_pay as $ke=>$value){
- //订单支付的金额
- if ($value->type==1){
- $pay+=$value->pay_money;
- }elseif ($value->type==2){
- //带订单退款金额
- $pay1+=$value->pay_money;
- }elseif ($value->type==3){
- $pay2+=$value->money;
- }
- }
- if (($pay1-$pay2)>$money){
- echo $v->order_num.'<br/>';
- }
- }
- // echo 1;
- }
- public function get_count(){
- $re=MoneyUser::with(['get_pay'=>function($q){
- $q->whereIn('user_pay_log.type',[0,3])->where('user_pay_log.created_at','>','2020-08-23 00:00:00');
- }])->get();
- foreach ($re as $k=>$v){
- $money=0;
- $moneys=0;
- if ($v->get_pay->isEmpty()){
- $money=0;
- }else{
- foreach ($v->get_pay as $ke=>$va){
- if ($va->type==0){
- $money+=$va->pay_money;
- }else{
- $moneys+=$va->pay_money;
- }
- }
- }
- if ($moneys>20){
- $money-=$moneys;
- }
- if ($money!=$v->money){
- echo '充值金额为'.$money.'------------'.$v->mobile.'-----Excel数据中的金额-----'.$v->money.'<br/>';
- }
- }
- }
- public function get_user_money(){
- $user=User::where('level',3)->with(['get_money'=>function($q){
- $q->where('created_at','>=','2020-08-22 00:00:00')->orderByDesc('id');
- },'get_moneyss'=>function($q){
- $q->where('created_at','<','2020-08-22 00:00:00')->orderByDesc('id');
- },'get_order'=>function($q){
- $q->where('created_at','>=','2020-08-22 00:00:00')->where('is_deleted',0);
- },'get_moneys'=>function($q){
- $q->where('created_at','<','2020-08-28 00:00:00')->orderByDesc('id');
- }])->get();
- $money=0;
- $pay_money=0;
- $p_money=0;
- $now_money=0;
- $old_money=0;
- $k_money=0;
- foreach ($user as $k=>$v){
- $pay_money=0;
- $p_money=0;
- $now_money=0;
- $old_money=0;
- $k_money=0;
- if ($v->get_money->isEmpty()){
- $p_money=0;
- $old_money=0;
- }else{
- //22号进行充值的
- foreach ($v->get_money as $ke=>$va){
- if ($va->type==0){
- $p_money+=$va->pay_money;
- }elseif ($va->type==3){
- $k_money+=$va->pay_money;
- }
- }
- }
- if ($v->get_moneyss->isEmpty()){
- $old_money=0;
- }else{
- //距离22号最近一天的余额
- foreach ($v->get_moneyss as $ke=>$va){
- if ($ke==0){
- $old_money=$va->user_money;
- }
- }
- }
- if ($v->get_moneys->isEmpty()){
- $now_money=0;
- }else{
- foreach ($v->get_moneys as $ke=>$va){
- if ($ke==0){
- $now_money=$va->user_money;
- }
- }
- }
- if ($v->get_order->isEmpty()){
- }else{
- foreach ($v->get_order as $ke=>$va){
- $pay_money+=$va->pay_money;
- }
- }
- if ($old_money+$p_money-$pay_money-$k_money!=$now_money){
- echo '代理ID为-------------'.$v->nickname.'-----初始金额为-----'.$old_money.'-------充值金额为------'.$p_money.'-----支付金额为-----'.$pay_money.'--扣款金额------'.$k_money.'------现在金额为-'.$now_money.'<br/>';
- }
- }
- dd(1);
- }
- }
|