12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\Activity;
- use App\Models\ActivityLimit;
- use App\Models\Address;
- use App\Models\EveryActData;
- use App\Models\OrderGift;
- use App\Models\Goodattr;
- use App\Models\Goodtest;
- use App\Models\Orderdetail;
- use App\Models\OrderRemark;
- use App\Models\Ordertest;
- use App\Models\Store;
- use App\Models\User;
- use App\Models\Warea;
- use App\Models\Gifts;
- use Carbon\Carbon;
- use App\Models\CrownCount;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Auth;
- class DataController extends Controller
- {
- public function datas()
- {
- $order = Ordertest::where('is_deleted', 0)->with(['get_address', 'get_order_detail'])->get();
- $attr = Goodattr::where('pid', 0)->get();
- $hard_id = [];
- $simple_id = [];
- $old_id = [];
- $hard_good = [];
- $simple_good = [];
- $old_good = [];
- foreach ($attr as $k => $v) {
- if ($v->name == '大卫博士精装版') {
- $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id');
- $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士简约版') {
- $simple_id = Goodattr::where('pid', $v->id)->pluck('id');
- $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士老人版') {
- $old_id = Goodattr::where('pid', $v->id)->pluck('id');
- $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray();
- }
- }
- $money = 0;
- $hard = 0;
- $simple = 0;
- $old = 0;
- $re = [];
- foreach ($order as $k => $v) {
- $hard_pro = 0;
- $simple_pro = 0;
- $old_pro = 0;
- foreach ($v->get_order_detail as $ke => $va) {
- if (in_array($va->goods_id, $hard_good)) {
- $hard += $va->num;
- $hard_pro = $va->num;
- } elseif (in_array($va->goods_id, $simple_good)) {
- $simple += $va->num;
- $simple_pro = $va->num;
- } elseif (in_array($va->goods_id, $old_good)) {
- $old += $va->num;
- $old_pro = $va->num;
- }
- }
- $money += $v->money;
- }
- $datas = [
- 'hard' => $hard,
- 'simple' => $simple,
- 'old' => $old,
- 'money' => $money,
- ];
- return $this->success($datas);
- }
- public function data()
- {
- $active = Activity::where('is_ing', 1)->first();
- $now = Carbon::now()->toDateTimeString();
- $order = Ordertest::where('is_deleted', 0)->whereBetween('created_at', [$active->start_time, $active->end_time])->with(['get_address', 'get_order_detail']);
- $order_1=clone $order;
- $order_2=clone $order;
- $order=$order->get();
- $order_1=$order_1->where('store_id',17)->sum('money');
- $order_2=$order_2->where('store_id',18)->sum('money');
- $order_today = [];
- if ($now < $active->end_time && $now > $active->start_time) {
- if (Carbon::now()->toDateString() == Carbon::parse($active->start_time)->toDateString()) {
- $start_time = $active->start_time;
- } else {
- $start_time = Carbon::today();
- }
- if (Carbon::now()->toDateString() == Carbon::parse($active->end_time)->toDateString()) {
- $end_time = $active->end_time;
- } else {
- $end_time = Carbon::tomorrow();
- }
- $order_today = Ordertest::where('is_deleted', 0)->with(['get_order_detail'])->whereBetween('created_at', [$start_time, $end_time])->get();
- }
- $act_gifts = Gifts::where('activity_id',$active->id)->get();//活动所有礼品
- $gifts_num=[];
- if(count($act_gifts)>0){
- foreach($act_gifts as $key=>$val){
- $gifts_num[$val->name]=OrderGift::whereHas('order_test',function($query){
- $query->where('is_deleted',0);
- })->where('activity_id',$active->id)->where('gift_id',$val->id)->sum('num');
- // $honor[$val->title]= OrderGift::join('order_test','order_test.id','=','order_gift.order_id')->where('order_test.is_deleted',0)->where('order_gift.activity_id',$active->id)->where('order_gift.gift_id',5)->sum('order_gift.num');
- }
- }
- $gift_sh=OrderGift::join('order_test','order_test.id','=','order_gift.order_id')->where('order_test.is_deleted',0)->where('order_gift.activity_id',$active->id)->where('order_gift.gift_id',5)->sum('order_gift.num');
- $gift_xl=OrderGift::join('order_test','order_test.id','=','order_gift.order_id')->where('order_test.is_deleted',0)->where('order_gift.activity_id',$active->id)->where('order_gift.gift_id',6)->sum('order_gift.num');
- $user_data=User::select('users.id','users.nickname','users.realname', DB::raw('SUM(order_test.money) as account'), DB::raw('SUM(order_test.pay_money) as pay_account'))
- ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id')
- ->where('order_test.is_deleted',0)
- ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time])
- ->groupBy('users.id')
- ->having('account','>=',$active->big_gift)
- ->orderBy('type','asc')
- ->orderBy('pay_account','desc')
- ->orderBy('account','desc');
- $count = $user_data->get()->count();
- $honor_limit=ActivityLimit::where('activity_id',$active->id)->where('type',1)->get();
- $honor_num=[];
- if(count($honor_limit)>0){
- foreach($honor_limit as $key=>$val){
- $honor_num[$val->title]=User::select('users.id','users.nickname','users.realname', DB::raw('SUM(order_test.money) as account'), DB::raw('SUM(order_test.pay_money) as pay_account'))
- ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id')
- ->where('order_test.is_deleted',0)
- ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time])
- ->groupBy('users.id')
- ->having('account','>=',$val->account)
- ->orderBy('type','asc')
- ->orderBy('pay_account','desc')
- ->orderBy('account','desc')->get()->count();
- }
- }
- $down_limit=Activity::where('id',$active->id)->value('crown_down');
- // $down_info=[];
- if($down_limit>0){
- // foreach($down_limit as $key=>$val){
- // foreach(Activity::$levels as $k=>$v){
- // if($val->title==$v){
- // $level=$k;
- // }
- // }
- // User::withCount('order_test',function($query){
- // $query->select(DB::raw('SUM(money) as account'), DB::raw('SUM(pay_money) as pay_account'));
- // })
- ////
- // User::with('order_test')
- // ->whereHas('order_test',function($query)use($active){
- // $query->where('is_deleted',0)->whereBetween('order_test.created_at',[$active->start_time,$active->end_time]);})
- // ->where('level',$level)->get();
- $down_info['up']=User::select('users.id','users.nickname','users.realname', DB::raw('SUM(order_test.money) as account'), DB::raw('SUM(order_test.pay_money) as pay_account'))
- ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id')
- ->where('users.level',3)
- ->where('order_test.is_deleted',0)
- ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time])
- ->groupBy('users.id')
- ->having('account','>=',$down_limit)
- ->orderBy('type','asc')
- ->orderBy('pay_account','desc')
- ->orderBy('account','desc')->get()->count();
- $down_info['down']=User::select('users.id','users.nickname','users.realname', DB::raw('SUM(order_test.money) as account'), DB::raw('SUM(order_test.pay_money) as pay_account'))
- ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id')
- ->where('users.level',3)
- ->where('order_test.is_deleted',0)
- ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time])
- ->groupBy('users.id')
- ->having('account','<',$down_limit)
- ->orderBy('type','asc')
- ->orderBy('pay_account','desc')
- ->orderBy('account','desc')->get()->count();
- // }
- }else{
- $down_info['up']=0;
- $down_info['down']=0;
- }
- $attr = Goodattr::where('pid', 0)->get();
- $hard_id = [];
- $simple_id = [];
- $old_id = [];
- $hard_good = [];
- $simple_good = [];
- $old_good = [];
- $newold_good = [];
- foreach ($attr as $k => $v) {
- if ($v->name == '大卫博士精装版') {
- $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id');
- $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士简约版') {
- $simple_id = Goodattr::where('pid', $v->id)->pluck('id');
- $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士老人版') {
- $old_id = Goodattr::where('pid', $v->id)->pluck('id');
- $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士纯棉老人版') {
- $newold_id = Goodattr::where('pid', $v->id)->pluck('id');
- $newold_good = Goodtest::whereIn('attr_id', $newold_id)->pluck('id')->toArray();
- }
- }
- $money = 0;
- $hard = 0;
- $simple = 0;
- $old = 0;
- $newold = 0;
- $hard_today = 0;
- $newold_today = 0;
- $simple_today = 0;
- $old_today = 0;
- $money_today = 0;
- $re = [];
- // dd($order);
- foreach ($order_today as $k => $v) {
- foreach ($v->get_order_detail as $ke => $va) {
- if (in_array($va->goods_id, $hard_good)) {
- $hard_today += $va->num;
- } elseif (in_array($va->goods_id, $simple_good)) {
- $simple_today += $va->num;
- } elseif (in_array($va->goods_id, $old_good)) {
- $old_today += $va->num;
- } elseif (in_array($va->goods_id, $newold_good)) {
- $newold_today += $va->num;
- }
- }
- $money_today += $v->money;
- }
- $h = 0;
- $hard_pro = 0;
- $simple_pro = 0;
- $old_pro = 0;
- $newold_pro = 0;
- $money_pro = 0;
- $hard_money = 0;
- $simple_money = 0;
- $old_money = 0;
- $newold_money = 0;
- foreach ($order as $k => $v) {
- $hard_pro = 0;
- $simple_pro = 0;
- $old_pro = 0;
- $newold_pro = 0;
- foreach ($v->get_order_detail as $ke => $va) {
- if (in_array($va->goods_id, $hard_good)) {
- $hard += $va->num;
- $hard_money += $va->money;
- $hard_pro += $va->num;
- } if (in_array($va->goods_id, $simple_good)) {
- $simple += $va->num;
- $simple_money += $va->money;
- $simple_pro += $va->num;
- } if (in_array($va->goods_id, $old_good)) {
- $old += $va->num;
- $old_money += $va->money;
- $old_pro += $va->num;
- } if (in_array($va->goods_id, $newold_good)) {
- $newold += $va->num;
- $newold_money += $va->money;
- $newold_pro += $va->num;
- }
- }
- $money += $v->money;
- $h += $newold_pro;
- $re = $this->province($v->get_address->province, $hard_pro, $simple_pro, $old_pro, $newold_pro, $v->money, $re);
- }
- $datas = [
- 'hard' => $hard,
- 'simple' => $simple,
- 'old' => $old,
- 'newold' => $newold,
- 'money' => $money,
- 'hard_today' => $hard_today,
- 'simple_today' => $simple_today,
- 'old_today' => $old_today,
- 'newold_today' => $newold_today,
- 'money_today' => $money_today,
- 'activity_title'=>$active->title,
- 'shouhuan'=>$gift_sh,
- 'xianglian'=>$gift_xl,
- 'big_gift'=>$count,
- '临沭体验店'=>$order_1,
- '吴桥体验店'=>$order_2,
- 'activity_time'=>'('.date('m月d日',strtotime($active->start_time)).'-'.date('d日',strtotime($active->end_time)).')',
- 'list' => $re,
- 'gifts_num'=>$gifts_num,
- 'honor_num'=>$honor_num,
- 'down_info'=>$down_info,
- 'hard_money' => $hard_money,
- 'simple_money' =>$simple_money,
- 'old_money' => $old_money,
- 'newold_money' => $newold_money,
- ];
- return $this->success($datas);
- // $data=['北京', '天津', '上海', '重庆', '河北', '河南', '云南', '辽宁', '黑龙江', '湖南', '安徽', '山东', '新疆', '江苏','浙江', '江西', '湖北', '广西', '甘肃', '山西', '内蒙古', '陕西', '吉林', '福建', '贵州', '广东', '青海', '西藏', '四川', '宁夏', '海南', '台湾','香港', '澳门'];
- }
- public function province($name, $hard, $simple, $old, $newold, $money, $res = [])
- {
- // $data=['北京', '天津', '上海', '重庆', '河北', '河南', '云南', '辽宁', '黑龙江', '湖南', '安徽', '山东', '新疆', '江苏','浙江', '江西', '湖北', '广西', '甘肃', '山西', '内蒙古', '陕西', '吉林', '福建', '贵州', '广东', '青海', '西藏', '四川', '宁夏', '海南', '台湾','香港', '澳门'];
- // $s='河北省、山西省、辽宁省、吉林省、黑龙江省、江苏省、浙江省、安徽省、福建省、江西省、山东省、河南省、湖北省、湖南省、广东省、海南省、四川省、贵州省、云南省、陕西省、甘肃省、青海省、台湾省';
- // $ss='内蒙古自治区、广西壮族自治区、西藏自治区、宁夏回族自治区、新疆维吾尔自治区';
- // $sss='北京市、天津市、上海市、重庆市';
- // $ssss='香港特别行政区、澳门特别行政区';
- $datas = [
- ['北京', '北京市'], ['天津', '天津市'], ['上海', '上海市'], ['重庆', '重庆市'], ['河北', '河北省'], ['河南', '河南省'], ['云南', '云南省'], ['辽宁', '辽宁省'], ['黑龙江', '黑龙江省'], ['湖南', '湖南省'], ['安徽', '安徽省'], ['山东', '山东省'], ['新疆', '新疆维吾尔自治区'], ['江苏', '江苏省'], ['浙江', '浙江省'], ['江西', '江西省'], ['湖北', '湖北省'], ['广西', '广西壮族自治区'], ['甘肃', '甘肃省'], ['山西', '山西省'], ['内蒙古', '内蒙古自治区'], ['陕西', '陕西省'], ['吉林', '吉林省'], ['福建', '福建省'], ['贵州', '贵州省'], ['广东', '广东省'], ['青海', '青海省'], ['西藏', '西藏自治区'], ['四川', '四川省'], ['宁夏', '宁夏回族自治区'], ['海南', '海南省'], ['台湾', '台湾'], ['香港', '香港'], ['澳门', '澳门']
- ];
- foreach ($datas as $k => $v) {
- $re[$k]['name'] = $v[0];
- if ($res) {
- if ($v[1] == $name) {
- $re[$k]['hard'] = $hard + $res[$k]['hard'];
- $re[$k]['simple'] = $simple + $res[$k]['simple'];
- $re[$k]['old'] = $old + $res[$k]['old'];
- $re[$k]['newold'] = $newold + $res[$k]['newold'];
- $re[$k]['value'] = $money + $res[$k]['value'];
- } else {
- $re[$k]['hard'] = $res[$k]['hard'];
- $re[$k]['simple'] = $res[$k]['simple'];
- $re[$k]['old'] = $res[$k]['old'];
- $re[$k]['newold'] = $res[$k]['newold'];
- $re[$k]['value'] = $res[$k]['value'];
- }
- } else {
- if ($v[1] == $name) {
- $re[$k]['hard'] = $hard;
- $re[$k]['simple'] = $simple;
- $re[$k]['old'] = $old;
- $re[$k]['newold'] = $newold;
- $re[$k]['value'] = $money;
- // $re[$k]['money']=$money;
- } else {
- $re[$k]['hard'] = 0;
- $re[$k]['simple'] = 0;
- $re[$k]['old'] = 0;
- $re[$k]['newold'] = 0;
- $re[$k]['value'] = 0;
- }
- }
- }
- Log::error($re);
- $last_ages = array_column($re,'value');
- array_multisort($last_ages ,SORT_DESC,$re);
- Log::error($re);
- return $re;
- }
- public function crown_rank()
- {
- }
- public function money()
- {
- $order = Ordertest::where('is_deleted', 0)->with(['get_address', 'get_order_detail'])->get();
- $attr = Goodattr::where('pid', 0)->get();
- $hard_id = [];
- $simple_id = [];
- $old_id = [];
- $hard_good = [];
- $simple_good = [];
- $old_good = [];
- foreach ($attr as $k => $v) {
- if ($v->name == '大卫博士精装版') {
- $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id');
- $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士简约版') {
- $simple_id = Goodattr::where('pid', $v->id)->pluck('id');
- $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士老人版') {
- $old_id = Goodattr::where('pid', $v->id)->pluck('id');
- $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray();
- }
- }
- $money = 0;
- $hard = 0;
- $simple = 0;
- $old = 0;
- $re = [];
- foreach ($order as $k => $v) {
- $hard_pro = 0;
- $simple_pro = 0;
- $old_pro = 0;
- foreach ($v->get_order_detail as $ke => $va) {
- if (in_array($va->goods_id, $hard_good)) {
- $hard += $va->num;
- $hard_pro = $va->num;
- } elseif (in_array($va->goods_id, $simple_good)) {
- $simple += $va->num;
- $simple_pro = $va->num;
- } elseif (in_array($va->goods_id, $old_good)) {
- $old += $va->num;
- $old_pro = $va->num;
- }
- }
- $money += $v->money;
- }
- $datas = [
- 'hard' => $hard,
- 'simple' => $simple,
- 'old' => $old,
- 'money' => $money,
- ];
- return $this->success_list($datas);
- }
- // public function get_crown(){
- // $user=User::where('level',3)->get();
- // $attr=Goodattr::where('pid',0)->get();
- // $hard_id=[];
- // $simple_id=[];
- // $old_id=[];
- // foreach ($attr as $k=>$v){
- // if ($v->name=='大卫博士精装版'){
- // $hard_id=Goodattr::where('pid',$v->id)->select('id')->pluck('id');
- // $hard_good=Goodtest::whereIn('attr_id',$hard_id)->pluck('id')->toArray();
- // }elseif ($v->name=='大卫博士简约版'){
- // $simple_id=Goodattr::where('pid',$v->id)->pluck('id');
- // $simple_good=Goodtest::whereIn('attr_id',$simple_id)->pluck('id')->toArray();
- // }elseif ($v->name=='大卫博士老人版'){
- // $old_id=Goodattr::where('pid',$v->id)->pluck('id');
- // $old_good=Goodtest::whereIn('attr_id',$old_id)->pluck('id')->toArray();
- // }
- // }
- // foreach ($user as $k=>$v){
- // $money=0;
- // $hard=0;
- // $simple=0;
- // $old=0;
- // $order=Ordertest::where('user_id',$v->id)->where('is_deleted',0)->get();
- // $count=count($order);
- // if ($count==0){
- // $re[$k]['hard']=0;
- // $re[$k]['simple']=0;
- // $re[$k]['old']=0;
- // $re[$k]['money']=0;
- // }else{
- // foreach ($v->get_order_detail as $ke=>$va){
- // if (in_array($va->goods_id,$hard_good)){
- // $hard+=$va->num;
- // }elseif (in_array($va->goods_id,$simple_good)){
- // $simple+=$va->num;
- // }elseif (in_array($va->goods_id,$old_good)){
- // $old+=$va->num;
- // }
- // }
- // $money+=$v->money;
- // $re[$k]['money']=$money;
- // $re[$k]['hard']=$hard;
- // $re[$k]['simple']=$simple;
- // $re[$k]['old']=$old;
- // }
- // return $n;
- // $re[$k]['nickname']=$v->nickname;
- // }
- // return $this->success_list($re);
- // }
- //=======
- // foreach ($datas as $k=>$v){
- // $re[$k]['name']=$v[0];
- // if ($res){
- // if ($v[1]==$name){
- // $re[$k]['hard']=$hard+$res[$k]['hard'];
- // $re[$k]['simple']=$simple+$res[$k]['simple'];
- // $re[$k]['old']=$old+$res[$k]['old'];
- // $re[$k]['value']=$money+$res[$k]['value'];
- // }else{
- // $re[$k]['hard']=$res[$k]['hard'];
- // $re[$k]['simple']=$res[$k]['simple'];
- // $re[$k]['old']=$res[$k]['old'];
- // $re[$k]['value']=$res[$k]['value'];
- // }
- // }else{
- // if ($v[1]==$name){
- // $re[$k]['hard']=$hard;
- // $re[$k]['simple']=$simple;
- // $re[$k]['old']=$old;
- // $re[$k]['value']=$money;
- // // $re[$k]['money']=$money;
- // }else{
- // $re[$k]['hard']=0;
- // $re[$k]['simple']=0;
- // $re[$k]['old']=0;
- // $re[$k]['value']=0;
- // }
- // }
- //
- // }
- // return $re;
- // }
- //
- public function get_crown()
- {
- $active = Activity::where('is_ing', 1)->first();
- $start_time = $active->start_time;
- $end_time = $active->end_time;
- $user = User::where('level', 3)->with(['get_order_de' => function ($q) use ($start_time, $end_time) {
- $q->where('order_test.is_deleted', 0)->whereBetween('order_test.created_at', [$start_time, $end_time]);
- }])->get();
- $attr = Goodattr::where('pid', 0)->get();
- $hard_id = [];
- $simple_id = [];
- $old_id = [];
- foreach ($attr as $k => $v) {
- if ($v->name == '大卫博士精装版') {
- $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id');
- $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士简约版') {
- $simple_id = Goodattr::where('pid', $v->id)->pluck('id');
- $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士老人版') {
- $old_id = Goodattr::where('pid', $v->id)->pluck('id');
- $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray();
- } elseif ($v->name == '大卫博士纯棉老人版') {
- $newold_id = Goodattr::where('pid', $v->id)->pluck('id');
- $newold_good = Goodtest::whereIn('attr_id', $newold_id)->pluck('id')->toArray();
- }
- }
- foreach ($user as $k => $v) {
- $money = 0;
- $hard = 0;
- $simple = 0;
- $old = 0;
- $newold = 0;
- $count = count($v->get_order_de);
- if ($count == 0) {
- $re[$k]['hard'] = 0;
- $re[$k]['simple'] = 0;
- $re[$k]['old'] = 0;
- $re[$k]['newold'] = 0;
- $re[$k]['money'] = 0;
- } else {
- foreach ($v->get_order_de as $key => $value) {
- if (in_array($value->goods_id, $hard_good)) {
- $hard += $value->num;
- } elseif (in_array($value->goods_id, $simple_good)) {
- $simple += $value->num;
- } elseif (in_array($value->goods_id, $old_good)) {
- $old += $value->num;
- } elseif (in_array($value->goods_id, $newold_good)) {
- $newold += $value->num;
- }
- $money += $value->money;
- }
- $re[$k]['money'] = $money;
- $re[$k]['hard'] = $hard;
- $re[$k]['simple'] = $simple;
- $re[$k]['old'] = $old;
- $re[$k]['newold'] = $newold;
- }
- $re[$k]['nickname'] = $v->nickname;
- }
- return $this->success_list($re);
- }
- //
- //
- //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab
- /***数据统计---------按照种类---***/
- public function rank_type()
- {
- $hard_good = Goodtest::where('main_attr', '大卫博士精装版')->pluck('id')->toArray();
- $simple_good = Goodtest::where('main_attr', '大卫博士简约版')->pluck('id')->toArray();
- $old_good = Goodtest::where('main_attr', '大卫博士老人版')->pluck('id')->toArray();
- $old_good_nan = Goodtest::where('main_attr', '大卫博士老人版')->where('sec_attr', '男款')->pluck('id')->toArray();
- $old_good_nv = Goodtest::where('main_attr', '大卫博士老人版')->where('sec_attr', '女款')->pluck('id')->toArray();
- $simple_good_nan = Goodtest::where('main_attr', '大卫博士简约版')->where('sec_attr', '男款')->pluck('id')->toArray();
- $simple_good_nv = Goodtest::where('main_attr', '大卫博士简约版')->where('sec_attr', '女款')->pluck('id')->toArray();
- $hard_good_nan = Goodtest::where('main_attr', '大卫博士精装版')->where('sec_attr', '男款')->pluck('id')->toArray();
- $hard_good_nv = Goodtest::where('main_attr', '大卫博士精装版')->where('sec_attr', '女款')->pluck('id')->toArray();
- $where = function ($query) {
- $query->where('is_deleted', 0);
- };
- $orders = Ordertest::where($where)->get();
- $hard = 0;
- $simple = 0;
- $old = 0;
- $old_money = 0;
- $simple_money = 0;
- $hard_money = 0;
- $hard_nan = 0;
- $hard_nv = 0;
- $simple_nan = 0;
- $simple_nv = 0;
- $old_nan = 0;
- $old_nv = 0;
- $hard_nan_money = 0;
- $hard_nv_money = 0;
- $simple_nan_money = 0;
- $simple_nv_money = 0;
- $old_nan_money = 0;
- $old_nv_money = 0;
- foreach ($orders as $k => $v) {
- $order = Ordertest::where('id', $v->id)->with(['get_order_detail'])->first();
- foreach ($order->get_order_detail as $ke => $va) {
- if (in_array($va->goods_id, $hard_good)) {
- $hard += $va->num;
- $hard_money += $va->money;
- } elseif (in_array($va->goods_id, $simple_good)) {
- $simple += $va->num;
- $simple_money += $va->money;
- } elseif (in_array($va->goods_id, $old_good)) {
- $old += $va->num;
- $old_money += $va->money;
- }
- if (in_array($va->goods_id, $hard_good_nan)) {
- $hard_nan += $va->num;
- $hard_nan_money += $va->money;
- } elseif (in_array($va->goods_id, $hard_good_nv)) {
- $hard_nv += $va->num;
- $hard_nv_money += $va->money;
- } elseif (in_array($va->goods_id, $simple_good_nan)) {
- $simple_nan += $va->num;
- $simple_nan_money += $va->money;
- } elseif (in_array($va->goods_id, $simple_good_nv)) {
- $simple_nv += $va->num;
- $simple_nv_money += $va->money;
- } elseif (in_array($va->goods_id, $old_good_nan)) {
- $old_nan += $va->num;
- $old_nan_money += $va->money;
- } elseif (in_array($va->goods_id, $old_good_nv)) {
- $old_nv += $va->num;
- $old_nv_money += $va->money;
- }
- }
- }
- $data = [
- 'hard' => $hard,
- 'simple' => $simple,
- 'old' => $old,
- 'hard_money' => $hard_money,
- 'simple_money' => $simple_money,
- 'old_money' => $old_money,
- 'hard_nan' => $hard_nan,
- 'simple_nan' => $simple_nan,
- 'old_nan' => $old_nan,
- 'hard_nan_money' => $hard_nan_money,
- 'simple_nan_money' => $simple_nan_money,
- 'old_nan_money' => $old_nan_money,
- 'hard_nv' => $hard_nv,
- 'simple_nv' => $simple_nv,
- 'old_nv' => $old_nv,
- 'hard_nv_money' => $hard_nv_money,
- 'simple_nv_money' => $simple_nv_money,
- 'old_nv_money' => $old_nv_money,
- ];
- return $this->success($data);
- }
- public function rank_type2(Request $request)
- {
- $input = $request->all();
- $start_time = $input['start_time'];
- $end_time = $input['end_time'];
- $data = Ordertest::where('is_deleted', 0);
- if ($request->has('order_status')) {
- $order_status = $input['order_status'];
- } else {
- $order_status = [];
- }
- if ($order_status || $order_status == 0) {
- if ('-1' == $order_status) {
- } elseif ($order_status == 0) {
- $data->where('status', $order_status)->where('is_deleted', 0);
- } elseif ($order_status == 1) {
- $data->where('status', $order_status)->where('is_deleted', 0);
- } elseif ($order_status == 2) {
- $data->where('status', $order_status)->where('is_deleted', 0);
- } elseif ($order_status == 3) {
- $data->where('status', $order_status)->where('is_deleted', 0);
- } elseif ($order_status == 4) {
- $data->where('status', $order_status)->where('is_deleted', 0);
- }
- }
- if ($start_time && $end_time) {
- $data->whereBetween('created_at', [$start_time, $end_time]);
- }
- $orders = $data->get();
- $good_attrs = Goodtest::where('is_deleted', 0)->groupBy('main_attr')->select('id', 'name', 'main_attr')->get();
- foreach ($good_attrs as $k => $v) {
- $good_attr[$k]['ids'] = Goodtest::where('is_deleted', 0)->where('main_attr', $v->main_attr)->pluck('id')->toArray();
- $good_attr[$k]['name'] = $v->main_attr;
- }
- foreach ($good_attr as $key => $value) {
- if (empty($attr[$value['name']])) {
- $attr[$value['name']][0] = 0;
- $attr[$value['name']][1] = 0;
- }
- }
- $good_types = Goodtest::where('is_deleted', 0)->groupBy('attr_id')->orderBy('sort')->select('id', 'name', 'main_attr', 'attr_id')->get();
- foreach ($good_types as $k => $v) {
- $good_type[$k]['ids'] = Goodtest::where('is_deleted', 0)->where('attr_id', $v->attr_id)->pluck('id')->toArray();
- $good_type[$k]['name'] = $v->name;
- }
- foreach ($good_type as $key => $value) {
- if (empty($type[$value['name']])) {
- $type[$value['name']][0] = 0;
- $type[$value['name']][1] = 0;
- }
- }
- $good_singles = Goodtest::where('is_deleted', 0)->orderBy('sort')->orderBy('id')->select('id', 'name', 'size')->get();
- foreach ($good_singles as $k => $v) {
- $good_single[$k]['ids'] = $v->id;
- $good_single[$k]['name'] = $v->name . '(' . $v->size . ')';
- }
- foreach ($good_single as $key => $value) {
- $single[$value['name']][0] = 0;
- $single[$value['name']][1] = 0;
- }
- foreach ($orders as $k => $v) {
- $order = Ordertest::where('id', $v->id)->with(['get_order_detail'])->first();
- foreach ($order->get_order_detail as $ke => $va) {
- foreach ($good_attr as $key => $value) {
- if (in_array($va->goods_id, $value['ids'])) {
- $attr[$value['name']][0] += $va->num;
- $attr[$value['name']][1] += $va->money;
- }
- }
- foreach ($good_type as $key => $value) {
- if (in_array($va->goods_id, $value['ids'])) {
- $type[$value['name']][0] += $va->num;
- $type[$value['name']][1] += $va->money;
- }
- }
- foreach ($good_single as $key => $value) {
- if ($va->goods_id == $value['ids']) {
- $single[$value['name']][0] += $va->num;
- $single[$value['name']][1] += $va->money;
- }
- }
- }
- }
- $data = [
- 'attr' => $attr,
- 'type' => $type,
- 'single' => $single
- ];
- return $this->success($data);
- }
- public function getOrderListInfo(Request $request)
- {
- $input = $request->all();
- $start_time = $input['start_time'];
- $end_time = $input['end_time'];
- $type = $input['type'];
- $order_status = $input['order_status'];
- $search_name = $input['search_name'];
- $receive = $input['name'];
- $province = $input['provice'];
- $city = $input['city'];
- $area = $input['area'];
- // $activity_id=$input['activity_id'];
- $ids = $this->getOrderListIds($start_time, $end_time, $order_status, $search_name, $receive, $province, $city, $area);
- $data = Goodtest::leftJoin('order_detail', function ($query) use ($ids) {
- $query->on('goods_test.id', '=', 'order_detail.goods_id')
- ->whereIn('order_detail.order_id', $ids);
- });
- if ($type == 3) {//种类
- $data->select('goods_test.main_attr', DB::raw('sum(order_detail.num) as total'), DB::raw('sum(order_detail.money) as account'))
- ->groupBy('goods_test.main_attr');
- }
- if ($type == 2) {//款式
- $data->select('goods_test.main_attr', 'goods_test.sec_attr', DB::raw('sum(order_detail.num) as total'), DB::raw('sum(order_detail.money) as account'))
- ->groupBy('goods_test.main_attr', 'goods_test.sec_attr');
- }
- if ($type == 1) {//尺码
- $data->select('goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'), DB::raw('SUM(order_detail.money) as account'))
- ->groupBy('goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size');
- }
- $list = $data->get();
- return $this->success($list);
- }
- public function getOrderListIds($start_time, $end_time, $order_status, $search_name, $receive, $province, $city, $area)
- {
- $order = Ordertest::where('is_deleted', 0);
- if (!empty($order_status) || $order_status == '0') {
- $order->where('status', '=', $order_status);
- }
- if ($start_time && $end_time) {
- $order->whereBetween('created_at', [$start_time, $end_time]);
- }
- if ($search_name) {
- $user_ids = $this->getUserIds($search_name);
- $order->whereIn('user_id', $user_ids);
- }
- if ($receive) {
- $address_ids = $this->getReceiveAddressIds($receive);
- $order->whereIn('address_id', $address_ids);
- }
- if ($province && $province != '省') {
- $province_ids = $this->getProvinceIds($province);
- $order->whereIn('address_id', $province_ids);
- }
- if ($city && $city != '市') {
- if ($city == '北京城区') {
- $city = '市辖区';
- }
- if ($city == '天津城区') {
- $city = '市辖区';
- }
- if ($city == '上海城区') {
- $city = '市辖区';
- }
- $city_ids = $this->getCityIds($city);
- $order->whereIn('address_id', $city_ids);
- }
- if ($area && $area != '区') {
- $area_ids = $this->getProvinceIds($area);
- $order->whereIn('address_id', $area_ids);
- }
- return $order->pluck('id');
- }
- //获取代理Ids
- public function getUserIds($search = null)
- {
- return User::where(function ($query) use ($search) {
- $query->where('nickname', 'like', '%' . $search . '%')
- ->orwhere('realname', 'like', '%' . $search . '%')
- ->orwhere('mobile', $search);
- })->pluck('id');
- }
- //根据物流查询代理信息
- public function getReceiveAddressIds($search = null)
- {
- return Address::where('username', 'like', '%' . $search . '%')
- ->orWhere('mobile', $search)
- ->pluck('id');
- }
- //根据省查询代理信息
- public function getProvinceIds($search = null)
- {
- //<<<<<<< HEAD
- return Address::where('province', $search)
- ->pluck('id');
- }
- //根据市查询代理信息
- public function getCityIds($search = null)
- {
- if ($search == '北京城区' || $search == '天津城区' || $search == '上海城区') {
- $search = '市辖区';
- }
- return Address::where('city', $search)
- //=======
- // return Address::where('province',$search )
- // ->pluck('id');
- // }
- //
- // //根据省查询代理信息
- // public function getCityIds($search = null)
- // {
- // return Address::where('city', $search )
- //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab
- ->pluck('id');
- }
- //<<<<<<< HEAD
- //根据区查询代理信息
- public function getAreaIds($search = null)
- {
- return Address::where('town', $search)
- //=======
- // //根据省查询代理信息
- // public function getAreaIds($search = null)
- // {
- // return Address::where('town', $search )
- //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab
- ->pluck('id');
- }
- public function orderBreakUpCourier(Request $request)
- {
- ini_set('memory_limit', '1024M');
- $input = $request->all();
- if ($request->has('provice')) {
- $order_no = $input['order_no'];
- $start_time = $input['start_time'];
- $end_time = $input['end_time'];
- $activity_id = $input['activity_id'];
- $user_name = $input['user_name'];
- $receive_info = $input['receive_info'];
- $goods_info = $input['goods_info'];
- $province = $input['provice'];
- $city = $input['city'];
- $town = $input['area'];
- if ($request->has('order_status')) {
- $order_status = $input['order_status'];
- } else {
- $order_status = [];
- }
- if ($request->has('pay_status')) {
- $pay_status = $input['pay_status'];
- } else {
- $pay_status = [];
- }
- $order_type = $input['order_type'];
- $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->join('warea','warea.id','=','users.warea_id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
- ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','users.warea_id','order_test.id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'));
- $admin = Auth::user();
- if ($admin->role_id == 23) {
- $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
- $data->whereIn('users.warea_id', $warea_ids);
- }
- if ($order_no) {
- $data->where('order_test.order_num', $order_no);
- }
- if ($start_time && $end_time && empty($activity_id)) {
- $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
- }
- if ($activity_id) {
- // $data->where('order_test.activity_id', $activity_id);
- $actice=Activity::find($activity_id);
- $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]);
- }
- if ($user_name) {
- $user_id = $this->getUserNameIds($user_name);
- $data->whereIn('order_test.user_id', $user_id);
- }
- if ($receive_info) {
- $address_ids = $this->getReceiveAddressIds($receive_info);
- $data->whereIn('order_test.address_id', $address_ids);
- }
- if ($province && $province != '省') {
- $province_ids = $this->getProvinceIds($province);
- $data->whereIn('order_test.address_id', $province_ids);
- }
- if ($city && $city != '市') {
- $city_ids = $this->getCityIds($city);
- $data->whereIn('order_test.address_id', $city_ids);
- }
- if ($town && $town != '区') {
- $town_ids = $this->getAreaIds($town);
- $data->whereIn('order_test.address_id', $town_ids);
- }
- //商品信息
- if ($goods_info) {
- $order_ids = $this->getGoodsOrderIds($goods_info);
- $data->whereIn('order_test.id', $order_ids);
- }
- if ($order_status) {
- if (!in_array('-1', $order_status)) {
- if (!in_array('5', $order_status)) {
- $data->whereIn('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } else {
- $data->where('order_test.is_deleted', 1)
- ->orWhere(function ($query) use ($order_status) {
- $query->where('order_test.is_deleted', 0)
- ->whereIn('order_test.status', $order_status);
- });
- }
- }
- }
- if ($pay_status) {
- if (!in_array('-1', $pay_status)) {
- $data->whereIn('order_test.pay_status', $pay_status);
- }
- }
- if (in_array($order_type, [0, 1])) {
- $data->where('order_test.order_type', $order_type);
- }
- $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- ->orderBy('order_test.id', 'order_detail.id')
- ->get()->toArray();
- } else {
- if ($request->has('id')) {
- $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->join('warea','warea.id','=','users.warea_id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
- ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','order_test.id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile','users.warea_id', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'))
- ->whereIn('order_test.id', $request->id)
- ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- ->orderBy('order_test.id', 'order_detail.id')
- ->get()->toArray();
- } else {
- if ($request->has('order_no')) {
- $order_no = $input['order_no'];
- } else {
- $order_no = '';
- }
- $start_time = $input['start_time'] ?? '';
- $end_time = $input['end_time'] ?? '';
- $activity_id = $input['activity_id'] ?? '';
- $search_name = $input['search_name'] ?? '';
- if ($request->has('order_status')) {
- $order_status = $input['order_status'];
- } else {
- $order_status = [];
- }
- $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->join('warea','warea.id','=','users.warea_id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
- ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id', 'order_test.id','users.warea_id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'));
- $admin = Auth::user();
- if ($admin->role_id == 23) {
- $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
- $data->whereIn('users.warea_id', $warea_ids);
- }
- if ($order_status || $order_status == 0) {
- if ('-1' == $order_status) {
- $data->whereIn('order_test.is_deleted', [0, 1]);
- } elseif ($order_status == 5) {
- $data->where('order_test.is_deleted', 1);
- } elseif ($order_status == 0) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 1) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 2) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 3) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 4) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 6) {
- $data->whereIn('order_test.pay_status', [0, 1])->where('order_test.order_test.is_deleted', 0);
- }
- }
- if ($order_no) {
- $data->where('order_test.order_num', $order_no);
- }
- if ($search_name) {
- // $s=substr(trim($search_name),0,4);
- // if($s=='DWBS'){
- // $data->where('order_test.order_num',trim($search_name));
- // }else{
- $ids = $this->getUserIds($search_name);
- $data->whereIn('order_test.user_id', $ids);
- // }
- }
- if ($start_time && $end_time && empty($activity_id)) {
- $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
- }
- if ($activity_id) {
- $actice = Activity::find($activity_id);
- $data->whereBetween('order_test.created_at', [$actice->start_time, $actice->end_time]);
- }
- // $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- $list = $data->groupBy('order_detail.order_id', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size')
- ->orderBy('order_test.id', 'order_detail.id')
- ->get()->toArray();
- }
- }
- $dd = $this->dataGroup($list, 'order_num');
- $d = [];
- foreach ($dd as $key => $val) {
- $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id')
- ->where('order_gift.order_id', $val[0]['id'])
- ->where('order_gift.num', '>', '0')
- ->select('gifts.name', 'order_gift.num')->get();
- $info['u_nickname'] = $val[0]['u_nickname'];
- $info['u_name'] = $val[0]['u_name'];
- $info['u_mobile'] = $val[0]['u_mobile'];
- $info['username'] = $val[0]['username'];
- $info['mobile'] = $val[0]['mobile'];
- $info['address'] = $val[0]['address'];
- $info['province'] = $val[0]['province'];
- $info['city'] = $val[0]['city'];
- $info['town'] = $val[0]['town'];
- if ($val[0]['good_user_id']){
- $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first();
- $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')';
- }else{
- $info['belong']='';
- }
- $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name');
- $info['admin_name'] =$admin_name;
- $info['created_at'] = $val[0]['created_at'];
- // $info['remark'] = (string)$val[0]['remark'];
- $info['remark'] = $this->getOrderRemark($val[0]['id']);
- $d[$key]['data'] = $info;
- $d[$key]['精装'] = [];
- $d[$key]['普通'] = [];
- $d[$key]['精装混合'] = [];
- $d[$key]['普通混合'] = [];
- $x1 = 0;
- $y1 = [];//精装
- $x = 0;
- $y = [];//普通
- foreach ($val as $k => $v) {
- if ($v['main_attr'] == '大卫博士精装版') {
- $main_attr = '精';
- $n = floor($v['total'] / 10);
- for ($i = 0; $i < $n; $i++) {
- $cc = [];
- $cc['main_attr'] = $main_attr;
- $cc['sec_attr'] = $v['sec_attr'];
- $cc['size'] = $v['size'];
- $cc['num'] = 10;
- array_push($d[$key]['精装'], $cc);
- }
- if ($v['total'] % 10 > 0) {
- $t1 = $v['total'] % 10;
- if ($x1 + $t1 >= 10) {
- $x1 = $x1 + $t1 - 10;
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $t1 - $x1;
- if ($y1) {
- array_pop($d[$key]['精装混合']);
- }
- array_push($y1, $z1);
- $z1 = [];
- array_push($d[$key]['精装混合'], $y1);
- $y1 = [];
- if ($x1 > 0) {
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $x1;
- array_push($y1, $z1);
- array_push($d[$key]['精装混合'], $y1);
- }
- } else {
- $x1 += $t1;
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $v['total'] % 10;
- if ($y1) {
- array_pop($d[$key]['精装混合']);
- }
- array_push($y1, $z1);
- array_push($d[$key]['精装混合'], $y1);
- }
- }
- } else {
- $n = floor($v['total'] / 6);
- if ($v['main_attr'] == '大卫博士老人版') {
- $main_attr = '老';
- } elseif ($v['main_attr'] == '大卫博士简约版') {
- $main_attr = '简';
- } else {
- $main_attr = '棉';
- }
- for ($i = 0; $i < $n; $i++) {
- $cc = [];
- $cc['main_attr'] = $main_attr;
- $cc['sec_attr'] = $v['sec_attr'];
- $cc['size'] = $v['size'];
- $cc['num'] = 6;
- array_push($d[$key]['普通'], $cc);
- }
- if ($v['total'] % 6 > 0) {
- $t = $v['total'] % 6;
- if ($x + $t >= 6) {
- $x = $x + $t - 6;
- $z['main_attr'] = $main_attr;
- $z['sec_attr'] = $v['sec_attr'];
- $z['size'] = $v['size'];
- $z['num'] = $t - $x;
- if ($y) {
- array_pop($d[$key]['普通混合']);
- }
- array_push($y, $z);
- $z = [];
- array_push($d[$key]['普通混合'], $y);
- $y = [];
- if ($x > 0) {
- $z['main_attr'] = $main_attr;
- $z['sec_attr'] = $v['sec_attr'];
- $z['size'] = $v['size'];
- $z['num'] = $x;
- array_push($y, $z);
- array_push($d[$key]['普通混合'], $y);
- }
- } else {
- $x += $t;
- $z['main_attr'] = $main_attr;
- $z['sec_attr'] = $v['sec_attr'];
- $z['size'] = $v['size'];
- $z['num'] = $v['total'] % 6;
- if ($y) {
- array_pop($d[$key]['普通混合']);
- }
- array_push($y, $z);
- array_push($d[$key]['普通混合'], $y);
- }
- }
- }
- }
- }
- return $this->success($d);
- }
- public function orderStoreBreakUpCourier(Request $request)
- {
- ini_set('memory_limit', '1024M');
- $input = $request->all();
- if (!$request->has('id')) {
- $page_index = $input['page_index'];
- $page_size = $input['page_size'];
- $num = ($page_index - 1) * $page_size;
- $order_no = $input['order_no'];
- $start_time = $input['start_time'];
- $end_time = $input['end_time'];
- $search_name = $input['search_name'];
- $activity_id = $input['activity_id'];
- $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->join('warea','warea.id','=','users.warea_id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
- ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','users.warea_id','order_test.id','order_test.store_id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'));
- $admin = Auth::user();
- if ($admin->role_id == 23) {
- $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
- $data->whereIn('users.warea_id', $warea_ids);
- }
- if ($order_no) {
- $data->where('order_test.order_num', 'like','%'.$order_no.'%');
- }
- if ($search_name){
- $ids=$this->getUserIds($search_name);
- $data->whereIn('order_test.user_id', $ids);
- }
- if ($start_time && $end_time && empty($activity_id)) {
- $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
- }
- if($activity_id){
- $actice=Activity::find($activity_id);
- $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]);
- }
- if ($request->store_id){
- $data->where('order_test.store_id',$request->store_id);
- }
- $data->whereNotNull('order_test.store_id');
- $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- ->orderBy('order_test.id', 'order_detail.id')
- ->get()->toArray();
- } else {
- $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->join('warea','warea.id','=','users.warea_id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
- ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','order_test.id','order_test.store_id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile','users.warea_id', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'))
- ->whereIn('order_test.id', $request->id)
- ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- ->orderBy('order_test.id', 'order_detail.id')
- ->get()->toArray();
- }
- $dd = $this->dataGroup($list, 'order_num');
- $d = [];
- foreach ($dd as $key => $val) {
- $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id')
- ->where('order_gift.order_id', $val[0]['id'])
- ->where('order_gift.num', '>', '0')
- ->select('gifts.name', 'order_gift.num')->get();
- $info['u_nickname'] = $val[0]['u_nickname'];
- $info['u_name'] = $val[0]['u_name'];
- $info['u_mobile'] = $val[0]['u_mobile'];
- $info['username'] = $val[0]['username'];
- $info['mobile'] = $val[0]['mobile'];
- $info['address'] = $val[0]['address'];
- $info['province'] = $val[0]['province'];
- $info['city'] = $val[0]['city'];
- $info['town'] = $val[0]['town'];
- $info['get_store'] =Store::where('id',$val[0]['store_id'])->select('name')->first();
- if ($val[0]['good_user_id']){
- $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first();
- $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')';
- }else{
- $info['belong']='';
- }
- $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name');
- $info['admin_name'] =$admin_name;
- $info['created_at'] = $val[0]['created_at'];
- // $info['remark'] = (string)$val[0]['remark'];
- $info['remark'] = $this->getOrderRemark($val[0]['id']);
- $d[$key]['data'] = $info;
- $d[$key]['精装'] = [];
- $d[$key]['普通'] = [];
- $d[$key]['精装混合'] = [];
- $d[$key]['普通混合'] = [];
- $x1 = 0;
- $y1 = [];//精装
- $x = 0;
- $y = [];//普通
- foreach ($val as $k => $v) {
- if ($v['main_attr'] == '大卫博士精装版') {
- $main_attr = '精';
- $n = floor($v['total'] / 10);
- for ($i = 0; $i < $n; $i++) {
- $cc = [];
- $cc['main_attr'] = $main_attr;
- $cc['sec_attr'] = $v['sec_attr'];
- $cc['size'] = $v['size'];
- $cc['num'] = 10;
- array_push($d[$key]['精装'], $cc);
- }
- if ($v['total'] % 10 > 0) {
- $t1 = $v['total'] % 10;
- if ($x1 + $t1 >= 10) {
- $x1 = $x1 + $t1 - 10;
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $t1 - $x1;
- if ($y1) {
- array_pop($d[$key]['精装混合']);
- }
- array_push($y1, $z1);
- $z1 = [];
- array_push($d[$key]['精装混合'], $y1);
- $y1 = [];
- if ($x1 > 0) {
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $x1;
- array_push($y1, $z1);
- array_push($d[$key]['精装混合'], $y1);
- }
- } else {
- $x1 += $t1;
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $v['total'] % 10;
- if ($y1) {
- array_pop($d[$key]['精装混合']);
- }
- array_push($y1, $z1);
- array_push($d[$key]['精装混合'], $y1);
- }
- }
- } else {
- $n = floor($v['total'] / 6);
- if ($v['main_attr'] == '大卫博士老人版') {
- $main_attr = '老';
- } elseif ($v['main_attr'] == '大卫博士简约版') {
- $main_attr = '简';
- } else {
- $main_attr = '棉';
- }
- for ($i = 0; $i < $n; $i++) {
- $cc = [];
- $cc['main_attr'] = $main_attr;
- $cc['sec_attr'] = $v['sec_attr'];
- $cc['size'] = $v['size'];
- $cc['num'] = 6;
- array_push($d[$key]['普通'], $cc);
- }
- if ($v['total'] % 6 > 0) {
- $t = $v['total'] % 6;
- if ($x + $t >= 6) {
- $x = $x + $t - 6;
- $z['main_attr'] = $main_attr;
- $z['sec_attr'] = $v['sec_attr'];
- $z['size'] = $v['size'];
- $z['num'] = $t - $x;
- if ($y) {
- array_pop($d[$key]['普通混合']);
- }
- array_push($y, $z);
- $z = [];
- array_push($d[$key]['普通混合'], $y);
- $y = [];
- if ($x > 0) {
- $z['main_attr'] = $main_attr;
- $z['sec_attr'] = $v['sec_attr'];
- $z['size'] = $v['size'];
- $z['num'] = $x;
- array_push($y, $z);
- array_push($d[$key]['普通混合'], $y);
- }
- } else {
- $x += $t;
- $z['main_attr'] = $main_attr;
- $z['sec_attr'] = $v['sec_attr'];
- $z['size'] = $v['size'];
- $z['num'] = $v['total'] % 6;
- if ($y) {
- array_pop($d[$key]['普通混合']);
- }
- array_push($y, $z);
- array_push($d[$key]['普通混合'], $y);
- }
- }
- }
- }
- }
- return $this->success($d);
- }
- //<<<<<<< HEAD
- //订单拆分快递单
- public function orderBreakUpCouriers(Request $request)
- {
- ini_set('memory_limit', '1024M');
- $input = $request->all();
- if ($request->has('provice')) {
- $order_no = $input['order_no'];
- $start_time = $input['start_time'];
- $end_time = $input['end_time'];
- $activity_id = $input['activity_id'];
- $user_name = $input['user_name'];
- $receive_info = $input['receive_info'];
- $goods_info = $input['goods_info'];
- $province = $input['provice'];
- $city = $input['city'];
- $town = $input['area'];
- if ($request->has('order_status')) {
- $order_status = $input['order_status'];
- } else {
- $order_status = [];
- }
- if ($request->has('pay_status')) {
- $pay_status = $input['pay_status'];
- } else {
- $pay_status = [];
- }
- $order_type = $input['order_type'];
- $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->join('warea','warea.id','=','users.warea_id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
- ->select('order_test.order_num','order_test.created_at', 'order_test.good_user_id','users.warea_id','order_test.id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'));
- $admin = Auth::user();
- if ($admin->role_id == 23) {
- $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
- $data->whereIn('users.warea_id', $warea_ids);
- }
- if ($order_no) {
- $data->where('order_test.order_num', $order_no);
- }
- if ($start_time && $end_time && empty($activity_id)) {
- $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
- }
- if ($activity_id) {
- // $data->where('order_test.activity_id', $activity_id);
- $actice=Activity::find($activity_id);
- $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]);
- }
- if ($user_name) {
- $user_id = $this->getUserNameIds($user_name);
- $data->whereIn('order_test.user_id', $user_id);
- }
- if ($receive_info) {
- $address_ids = $this->getReceiveAddressIds($receive_info);
- $data->whereIn('order_test.address_id', $address_ids);
- }
- if ($province && $province != '省') {
- $province_ids = $this->getProvinceIds($province);
- $data->whereIn('order_test.address_id', $province_ids);
- }
- if ($city && $city != '市') {
- $city_ids = $this->getCityIds($city);
- $data->whereIn('order_test.address_id', $city_ids);
- }
- if ($town && $town != '区') {
- $town_ids = $this->getAreaIds($town);
- $data->whereIn('order_test.address_id', $town_ids);
- }
- //商品信息
- if ($goods_info) {
- $order_ids = $this->getGoodsOrderIds($goods_info);
- $data->whereIn('order_test.id', $order_ids);
- }
- if ($order_status) {
- if (!in_array('-1', $order_status)) {
- if (!in_array('5', $order_status)) {
- $data->whereIn('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } else {
- $data->where('order_test.is_deleted', 1)
- ->orWhere(function ($query) use ($order_status) {
- $query->where('order_test.is_deleted', 0)
- ->whereIn('order_test.status', $order_status);
- });
- }
- }
- }
- if ($pay_status) {
- if (!in_array('-1', $pay_status)) {
- $data->whereIn('order_test.pay_status', $pay_status);
- }
- }
- if (in_array($order_type, [0, 1])) {
- $data->where('order_test.order_type', $order_type);
- }
- $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- ->orderBy('order_test.id', 'order_detail.id')
- ->get()->toArray();
- } else {
- if ($request->has('id')) {
- $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->join('warea','warea.id','=','users.warea_id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
- ->select('order_test.order_num','order_test.good_user_id','order_test.created_at','order_test.id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile','users.warea_id', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'))
- ->whereIn('order_test.id', $request->id)
- ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- ->orderBy('order_test.id', 'order_detail.id')
- ->get()->toArray();
- } else {
- if ($request->has('order_no')) {
- $order_no = $input['order_no'];
- } else {
- $order_no = '';
- }
- $start_time = $input['start_time'] ?? '';
- $end_time = $input['end_time'] ?? '';
- $activity_id = $input['activity_id'] ?? '';
- $search_name = $input['search_name'] ?? '';
- if ($request->has('order_status')) {
- $order_status = $input['order_status'];
- } else {
- $order_status = [];
- }
- $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->join('warea','warea.id','=','users.warea_id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
- ->select('order_test.order_num','order_test.good_user_id','order_test.created_at', 'order_test.id','users.warea_id', 'order_test.remark', 'users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name', 'address.username', 'address.mobile', 'address.address', 'address.province', 'address.city', 'address.town', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'));
- $admin = Auth::user();
- if ($admin->role_id == 23) {
- $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
- $data->whereIn('users.warea_id', $warea_ids);
- }
- if ($order_status || $order_status == 0) {
- if ('-1' == $order_status) {
- $data->whereIn('order_test.is_deleted', [0, 1]);
- } elseif ($order_status == 5) {
- $data->where('order_test.is_deleted', 1);
- } elseif ($order_status == 0) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 1) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 2) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 3) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 4) {
- $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
- } elseif ($order_status == 6) {
- $data->whereIn('order_test.pay_status', [0, 1])->where('order_test.order_test.is_deleted', 0);
- }
- }
- if ($order_no) {
- $data->where('order_test.order_num', $order_no);
- }
- if ($search_name) {
- // $s=substr(trim($search_name),0,4);
- // if($s=='DWBS'){
- // $data->where('order_test.order_num',trim($search_name));
- // }else{
- $ids = $this->getUserIds($search_name);
- $data->whereIn('order_test.user_id', $ids);
- // }
- }
- if ($start_time && $end_time && empty($activity_id)) {
- $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
- }
- if ($activity_id) {
- $actice = Activity::find($activity_id);
- $data->whereBetween('order_test.created_at', [$actice->start_time, $actice->end_time]);
- }
- $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- ->orderBy('order_test.id', 'order_detail.id')
- ->get()->toArray();
- }
- }
- $dd = $this->dataGroup($list, 'order_num');
- $d = [];
- foreach ($dd as $key => $val) {
- // if($key==0){
- // return $val;
- // }
- $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id')
- ->where('order_gift.order_id', $val[0]['id'])
- ->where('order_gift.num', '>', '0')
- ->select('gifts.name', 'order_gift.num')->get();
- $info['u_nickname'] = $val[0]['u_nickname'];
- $info['u_name'] = $val[0]['u_name'];
- $info['u_mobile'] = $val[0]['u_mobile'];
- $info['username'] = $val[0]['username'];
- $info['mobile'] = $val[0]['mobile'];
- $info['address'] = $val[0]['address'];
- $info['province'] = $val[0]['province'];
- $info['city'] = $val[0]['city'];
- $info['town'] = $val[0]['town'];
- if ($val[0]['good_user_id']){
- $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first();
- $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')';
- }else{
- $info['belong']='';
- }
- $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name');
- $info['admin_name'] =$admin_name;
- $info['created_at'] = $val[0]['created_at'];
- // $info['remark'] = (string)$val[0]['remark'];
- $info['remark'] = $this->getOrderRemark($val[0]['id']);
- $d[$key]['data'] = $info;
- $d[$key]['精装'] = [];
- $d[$key]['老'] = [];
- $d[$key]['简'] = [];
- $d[$key]['棉老'] = [];
- $d[$key]['普通'] = [];
- $d[$key]['精装混合'] = [];
- $d[$key]['老混'] = [];
- $d[$key]['简混'] = [];
- $d[$key]['棉老混'] = [];
- $d[$key]['普通混'] = [];
- $x1 = 0;
- $y1 = [];//精装
- $x2 = 0;
- $y2 = [];//老
- $x3 = 0;
- $y3 = [];//老
- $x4 = 0;
- $y4 = [];//老
- $x = 0;
- $y = [];//普通
- foreach ($val as $k => $v) {
- if ($v['main_attr'] == '大卫博士精装版') {
- $main_attr = '精';
- $n = floor($v['total'] / 10);
- for ($i = 0; $i < $n; $i++) {
- $cc = [];
- $cc['main_attr'] = $main_attr;
- $cc['sec_attr'] = $v['sec_attr'];
- $cc['size'] = $v['size'];
- $cc['num'] = 10;
- array_push($d[$key]['精装'], $cc);
- }
- if ($v['total'] % 10 > 0) {
- $t1 = $v['total'] % 10;
- if ($x1 + $t1 >= 10) {
- $x1 = $x1 + $t1 - 10;
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $t1 - $x1;
- if ($y1) {
- array_pop($d[$key]['精装混合']);
- }
- array_push($y1, $z1);
- $z1 = [];
- array_push($d[$key]['精装混合'], $y1);
- $y1 = [];
- if ($x1 > 0) {
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $x1;
- array_push($y1, $z1);
- array_push($d[$key]['精装混合'], $y1);
- }
- } else {
- $x1 += $t1;
- $z1['main_attr'] = $main_attr;
- $z1['sec_attr'] = $v['sec_attr'];
- $z1['size'] = $v['size'];
- $z1['num'] = $v['total'] % 10;
- if ($y1) {
- array_pop($d[$key]['精装混合']);
- }
- array_push($y1, $z1);
- array_push($d[$key]['精装混合'], $y1);
- }
- }
- } else {
- $n = floor($v['total'] / 6);
- if ($v['main_attr'] == '大卫博士老人版') {
- $main_attr = '老';
- for ($i = 0; $i < $n; $i++) {
- $cc = [];
- $cc['main_attr'] = $main_attr;
- $cc['sec_attr'] = $v['sec_attr'];
- $cc['size'] = $v['size'];
- $cc['num'] = 6;
- array_push($d[$key]['老'], $cc);
- }
- if ($v['total'] % 6 > 0) {
- $t2 = $v['total'] % 6;
- if ($x2 + $t2 >= 6) {
- $x2 = $x2 + $t2 - 6;
- $z2['main_attr'] = $main_attr;
- $z2['sec_attr'] = $v['sec_attr'];
- $z2['size'] = $v['size'];
- $z2['num'] = $t2 - $x2;
- if ($y2) {
- array_pop($d[$key]['老混']);
- }
- array_push($y2, $z2);
- $z2 = [];
- array_push($d[$key]['老混'], $y2);
- $y2 = [];
- if ($x2 > 0) {
- $z2['main_attr'] = $main_attr;
- $z2['sec_attr'] = $v['sec_attr'];
- $z2['size'] = $v['size'];
- $z2['num'] = $x2;
- array_push($y2, $z2);
- array_push($d[$key]['老混'], $y2);
- }
- } else {
- $x2 += $t2;
- $z2['main_attr'] = $main_attr;
- $z2['sec_attr'] = $v['sec_attr'];
- $z2['size'] = $v['size'];
- $z2['num'] = $v['total'] % 6;
- if ($y2) {
- array_pop($d[$key]['老混']);
- }
- array_push($y2, $z2);
- array_push($d[$key]['老混'], $y2);
- }
- }
- } elseif ($v['main_attr'] == '大卫博士简约版') {
- $main_attr = '简';
- for ($i = 0; $i < $n; $i++) {
- $cc = [];
- $cc['main_attr'] = $main_attr;
- $cc['sec_attr'] = $v['sec_attr'];
- $cc['size'] = $v['size'];
- $cc['num'] = 6;
- array_push($d[$key]['简'], $cc);
- }
- if ($v['total'] % 6 > 0) {
- $t3 = $v['total'] % 6;
- if ($x3 + $t3 >= 6) {
- $x3 = $x3 + $t3 - 6;
- $z3['main_attr'] = $main_attr;
- $z3['sec_attr'] = $v['sec_attr'];
- $z3['size'] = $v['size'];
- $z3['num'] = $t3 - $x3;
- if ($y3) {
- array_pop($d[$key]['简混']);
- }
- array_push($y3, $z3);
- $z3 = [];
- array_push($d[$key]['简混'], $y3);
- $y3 = [];
- if ($x3 > 0) {
- $z3['main_attr'] = $main_attr;
- $z3['sec_attr'] = $v['sec_attr'];
- $z3['size'] = $v['size'];
- $z3['num'] = $x3;
- array_push($y3, $z3);
- array_push($d[$key]['简混'], $y3);
- }
- } else {
- $x3 += $t3;
- $z3['main_attr'] = $main_attr;
- $z3['sec_attr'] = $v['sec_attr'];
- $z3['size'] = $v['size'];
- $z3['num'] = $v['total'] % 6;
- if ($y3) {
- array_pop($d[$key]['简混']);
- }
- array_push($y3, $z3);
- array_push($d[$key]['简混'], $y3);
- }
- }
- } else {
- $main_attr = '棉老';
- for ($i = 0; $i < $n; $i++) {
- $cc = [];
- $cc['main_attr'] = $main_attr;
- $cc['sec_attr'] = $v['sec_attr'];
- $cc['size'] = $v['size'];
- $cc['num'] = 6;
- array_push($d[$key]['棉老'], $cc);
- }
- if ($v['total'] % 6 > 0) {
- $t4 = $v['total'] % 6;
- if ($x4 + $t4 >= 6) {
- $x4 = $x4 + $t4 - 6;
- $z4['main_attr'] = $main_attr;
- $z4['sec_attr'] = $v['sec_attr'];
- $z4['size'] = $v['size'];
- $z4['num'] = $t4 - $x4;
- if ($y4) {
- array_pop($d[$key]['棉老混']);
- }
- array_push($y4, $z4);
- $z4 = [];
- array_push($d[$key]['棉老混'], $y4);
- $y4 = [];
- if ($x4 > 0) {
- $z4['main_attr'] = $main_attr;
- $z4['sec_attr'] = $v['sec_attr'];
- $z4['size'] = $v['size'];
- $z4['num'] = $x4;
- array_push($y4, $z4);
- array_push($d[$key]['棉老混'], $y4);
- }
- } else {
- $x4 += $t4;
- $z4['main_attr'] = $main_attr;
- $z4['sec_attr'] = $v['sec_attr'];
- $z4['size'] = $v['size'];
- $z4['num'] = $v['total'] % 6;
- if ($y4) {
- array_pop($d[$key]['棉老混']);
- }
- array_push($y4, $z4);
- array_push($d[$key]['棉老混'], $y4);
- }
- }
- }
- }
- }
- $nb=0;
- $nd=[];
- if(count($y2)>0){
- foreach($y2 as $k=>$v){
- $nb+=$v['num'];
- array_push($nd, $v);
- }
- array_pop($d[$key]['老混']);
- }
- if(count($y3)>0){
- foreach($y3 as $k=>$v){
- $nb+=$v['num'];
- if($nb>6){
- $m=$v;
- $m['num']=$v['num']-($nb-6);
- array_push($nd, $m);
- array_push($d[$key]['普通混'],$nd);
- $nd=[];
- $nb=$nb-6;
- $l=$v;
- $l['num']=$nb;
- array_push($nd, $l);
- }elseif($nb==6){
- array_push($nd, $v);
- array_push($d[$key]['普通混'],$nd);
- $nd=[];
- $nb=0;
- }else{
- array_push($nd, $v);
- }
- }
- array_pop($d[$key]['简混']);
- }
- if(count($y4)>0){
- foreach($y4 as $k=>$v){
- $nb+=$v['num'];
- if($nb>6){
- $m=$v;
- $m['num']=$v['num']-($nb-6);
- array_push($nd, $m);
- array_push($d[$key]['普通混'],$nd);
- $nd=[];
- $nb=$nb-6;
- $l=$v;
- $l['num']=$nb;
- array_push($nd, $l);
- }elseif($nb==6){
- array_push($nd, $v);
- array_push($d[$key]['普通混'],$nd);
- $nd=[];
- $nb=0;
- }else{
- array_push($nd, $v);
- }
- }
- array_pop($d[$key]['棉老混']);
- }
- if(count($nd)>0){
- array_push($d[$key]['普通混'],$nd);
- }
- }
- return $this->success($d);
- }
- public function getMergerOrder(Request $request){
- //<<<<<<< HEAD
- //<<<<<<< HEAD
- // $input=$request->all();
- // $page_index=$input['page_index'];
- // $page_size=$input['page_size'];
- // $num=$page_size*($page_index-1);
- // $activity_id=$input['activity_id'];
- // $search_name=$input['search_name'];
- // $activity=Activity::where('id',$activity_id)->first();
- // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- // ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- // ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
- // if($search_name){
- // $address_ids=Address::where(function($query) use ($search_name){
- // $query->where('username','like','%'.$search_name.'%')
- // ->orWhere('mobile',$search_name);
- // })->pluck('id');
- // $data->whereIn('order_test.address_id',$address_ids);
- // }
- // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
- // ->where('order_test.is_deleted',0)
- // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
- // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
- // 'goods_test.unit',DB::raw('SUM(order_detail.num) as total'))
- // ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit')
- // ->orderBy('order_test.created_at')
- // ->get();
- // $array=[];
- // foreach($list as $key => $val){
- // $keys=$val->address_id.'-'.$val->u_id;
- // $array[$keys]['name']=$val->username;
- // $array[$keys]['mobile']=$val->mobile;
- // $array[$keys]['address']=$val->address;
- // $array[$keys]['address_id']=$val->address_id;
- // $array[$keys]['user_id']=$val->u_id;
- // $array[$keys]['province']=$val->province;
- // $array[$keys]['city']=$val->city;
- // $array[$keys]['town']=$val->town;
- // $array[$keys]['u_nickname']=$val->u_nickname;
- // $array[$keys]['u_mobile']=$val->u_mobile;
- // $array[$keys]['u_name']=$val->u_name;
- //
- // if($val->unit=='套'){
- // if(empty($array[$keys]['num'])){
- // $array[$keys]['num']=$val->total;
- // }else{
- // $array[$keys]['num']+=$val->total;
- // }
- // }elseif($val->unit=='件'){
- // if(empty($array[$keys]['num'])){
- // $array[$keys]['num']=$val->total*2;
- // }else{
- // $array[$keys]['num']+=$val->total*2;
- //=======
- // $input=$request->all();
- // $page_index=$input['page_index'];
- // $page_size=$input['page_size'];
- // $num=$page_size*($page_index-1);
- // $activity_id=$input['activity_id'];
- // $search_name=$input['search_name'];
- // $activity=Activity::where('id',$activity_id)->first();
- // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- // ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- // ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
- // if($search_name){
- // $address_ids=Address::where(function($query) use ($search_name){
- // $query->where('username','like','%'.$search_name.'%')
- // ->orWhere('mobile',$search_name);
- // })->pluck('id');
- // $data->whereIn('order_test.address_id',$address_ids);
- // }
- // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
- // ->where('order_test.is_deleted',0)
- // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
- // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
- // 'goods_test.unit',DB::raw('SUM(order_detail.num) as total'))
- // ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit')
- // ->orderBy('order_test.created_at')
- // ->get();
- // $array=[];
- // foreach($list as $key => $val){
- // $keys=$val->address_id.'-'.$val->u_id;
- // $array[$keys]['name']=$val->username;
- // $array[$keys]['mobile']=$val->mobile;
- // $array[$keys]['address']=$val->address;
- // $array[$keys]['address_id']=$val->address_id;
- // $array[$keys]['user_id']=$val->u_id;
- // $array[$keys]['province']=$val->province;
- // $array[$keys]['city']=$val->city;
- // $array[$keys]['town']=$val->town;
- // $array[$keys]['u_nickname']=$val->u_nickname;
- // $array[$keys]['u_mobile']=$val->u_mobile;
- // $array[$keys]['u_name']=$val->u_name;
- //
- // if($val->unit=='套'){
- // if(empty($array[$keys]['num'])){
- // $array[$keys]['num']=$val->total;
- // }else{
- // $array[$keys]['num']+=$val->total;
- // }
- // }elseif($val->unit=='件'){
- // if(empty($array[$keys]['num'])){
- // $array[$keys]['num']=$val->total*2;
- // }else{
- // $array[$keys]['num']+=$val->total*2;
- // }
- //>>>>>>> 78008612722779b2a4d161ea6cec9067c149b72e
- //=======
- ini_set('memory_limit', '1024M');
- $input=$request->all();
- $page_index=$input['page_index'];
- $page_size=$input['page_size'];
- $num=$page_size*($page_index-1);
- $activity_id=$input['activity_id'];
- $search_name=$input['search_name'];
- $activity=Activity::where('id',$activity_id)->first();
- $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
- $admin=Auth::user();
- if($admin->role_id==23){
- $warea_ids = Warea::where('admin_id',$admin->id)->pluck('id');
- $data->whereHas('get_user', function($query) use ($warea_ids){
- $query->whereIn('warea_id',$warea_ids);
- });
- }
- if($search_name){
- $address_ids=Address::where(function($query) use ($search_name){
- $query->where('username','like','%'.$search_name.'%')
- ->orWhere('mobile',$search_name);
- })->pluck('id');
- $data->whereIn('order_test.address_id',$address_ids);
- }
- $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
- ->where('order_test.is_deleted',0)
- ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
- 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
- 'goods_test.unit',DB::raw('SUM(order_detail.num) as total'))
- ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit')
- ->orderBy('order_test.created_at')
- ->get();
- $array=[];
- foreach($list as $key => $val) {
- $keys = $val->address_id . '-' . $val->u_id;
- $array[$keys]['name'] = $val->username;
- $array[$keys]['mobile'] = $val->mobile;
- $array[$keys]['address'] = $val->address;
- $array[$keys]['address_id'] = $val->address_id;
- $array[$keys]['user_id'] = $val->u_id;
- $array[$keys]['province'] = $val->province;
- $array[$keys]['city'] = $val->city;
- $array[$keys]['town'] = $val->town;
- $array[$keys]['u_nickname'] = $val->u_nickname;
- $array[$keys]['u_mobile'] = $val->u_mobile;
- $array[$keys]['u_name'] = $val->u_name;
- if ($val->unit == '套') {
- if (empty($array[$keys]['num'])) {
- $array[$keys]['num'] = $val->total;
- } else {
- $array[$keys]['num'] += $val->total;
- }
- } elseif ($val->unit == '件') {
- if (empty($array[$keys]['num'])) {
- $array[$keys]['num'] = $val->total * 2;
- } else {
- $array[$keys]['num'] += $val->total * 2;
- //>>>>>>> comissar
- }
- }
- }
- $gifts = Gifts::where('activity_id', $activity_id)->get();
- foreach ($array as $key => $val) {
- $arr = [];
- foreach ($gifts as $k => $v) {
- if (floor($val['num'] / $v->num) > 0) {
- $arr[] = $v->name . '*' . floor($val['num'] / $v->num);
- }
- $array[$key]['gift'] = implode(',', $arr);
- }
- }
- $count=count($array);
- return $this->success_list(array_slice($array,$num,$page_size),'成功',$count);
- }
- public function getOrderGoodsInfo(Request $request){
- $input=$request->all();
- $address_id=$input['address_id'];
- $user_id=$input['user_id'];
- $activity_id=$input['activity_id'];
- $activity=Activity::find($activity_id);
- $info=Ordertest::with(['get_order_detail'=>function($query){
- $query->with('get_goods');
- }])->where('is_deleted',0)
- ->where('address_id',$address_id)
- ->where('user_id',$user_id)
- ->whereBetween('created_at',[$activity->start_time,$activity->end_time])
- ->get();
- if($info){
- return $this->success($info);
- }else{
- return $this->error();
- }
- }
- //<<<<<<< HEAD
- // public function exportMergerOrder(Request $request){
- // $input=$request->all();
- // $activity_id=$input['activity_id'];
- // $search_name=$input['search_name'];
- // $activity=Activity::where('id',$activity_id)->first();
- // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- // ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- // ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
- // if($search_name){
- // $address_ids=Address::where(function($query) use ($search_name){
- // $query->where('username','like','%'.$search_name.'%')
- // ->orWhere('mobile',$search_name);
- // })->pluck('id');
- // $data->whereIn('order_test.address_id',$address_ids);
- // }
- // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
- // ->where('order_test.is_deleted',0)
- // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
- // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
- // 'order_test.order_num',
- // 'goods_test.unit','goods_test.name','goods_test.main_attr','goods_test.sec_attr','goods_test.size',
- // DB::raw('SUM(order_detail.num) as total'))
- // ->groupBy('order_test.address_id','order_test.user_id','order_test.order_num','goods_test.unit','goods_test.main_attr','goods_test.sec_attr','goods_test.size')
- // ->orderBy('order_test.created_at')
- // ->get();
- //// dd($list);
- // $array=[];
- // foreach($list as $key => $val){
- // $keys=$val->address_id.'-'.$val->u_id;
- // $array[$keys]['name']=$val->username;
- // $array[$keys]['mobile']=$val->mobile;
- // $array[$keys]['address']=$val->address;
- // $array[$keys]['address_id']=$val->address_id;
- // $array[$keys]['user_id']=$val->u_id;
- // $array[$keys]['province']=$val->province;
- // $array[$keys]['city']=$val->city;
- // $array[$keys]['town']=$val->town;
- // $array[$keys]['u_nickname']=$val->u_nickname;
- // $array[$keys]['u_mobile']=$val->u_mobile;
- // $array[$keys]['u_name']=$val->u_name;
- // $array[$keys]['goods'][$val->order_num][]=$val->name.'-'.$val->sec_attr.'-'.$val->size.'*'.$val->total;
- //// $array[$keys]['goods'][$val->order_num][]=[$val->name.$val->size,$val->name,$val->size,$val->sec_attr,$val->total];
- // if($val->unit=='套'){
- // if(empty($array[$keys]['num'])){
- // $array[$keys]['num']=$val->total;
- // }else{
- // $array[$keys]['num']+=$val->total;
- // }
- // }elseif($val->unit=='件'){
- // if(empty($array[$keys]['num'])){
- // $array[$keys]['num']=$val->total*2;
- // }else{
- // $array[$keys]['num']+=$val->total*2;
- // }
- // }
- // }
- // $gifts=Gifts::where('activity_id',$activity_id)->get();
- // foreach($array as $key=>$val){
- // $array[$key]['shouhuan']=0;
- // $array[$key]['xianglian']=0;
- // $arr=[];
- // foreach($gifts as $k => $v){
- // if(floor($val['num']/$v->num)>0){
- // if ($v->name=='手环'||$v->name=='赠品-手环'){
- // $array[$key]['shouhuan']=floor($val['num']/$v->num);
- // }
- // if ($v->name=='项链'||$v->name=='赠品-项链'){
- // $array[$key]['xianglian']=floor($val['num']/$v->num);
- // }
- // $arr[]=$v->name.'*'.floor($val['num']/$v->num);
- public function exportMergerOrder(Request $request){
- $input=$request->all();
- $activity_id=$input['activity_id'];
- $search_name=$input['search_name'];
- $activity=Activity::where('id',$activity_id)->first();
- $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
- ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
- ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
- ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
- $admin=Auth::user();
- if($admin->role_id==23){
- $warea_ids = Warea::where('admin_id',$admin->id)->pluck('id');
- $data->whereHas('get_user', function($query) use ($warea_ids){
- $query->whereIn('warea_id',$warea_ids);
- });
- }
- if($search_name){
- $address_ids=Address::where(function($query) use ($search_name){
- $query->where('username','like','%'.$search_name.'%')
- ->orWhere('mobile',$search_name);
- })->pluck('id');
- $data->whereIn('order_test.address_id',$address_ids);
- }
- $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
- ->where('order_test.is_deleted',0)
- ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
- 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
- 'order_test.order_num',
- 'goods_test.unit','goods_test.name','goods_test.main_attr','goods_test.sec_attr','goods_test.size',
- DB::raw('SUM(order_detail.num) as total'))
- ->groupBy('order_test.address_id','order_test.user_id','order_test.order_num','goods_test.unit','goods_test.main_attr','goods_test.sec_attr','goods_test.size')
- ->orderBy('order_test.created_at')
- ->get();
- $array=[];
- foreach($list as $key => $val){
- $keys=$val->address_id.'-'.$val->u_id;
- $array[$keys]['name']=$val->username;
- $array[$keys]['mobile']=$val->mobile;
- $array[$keys]['address']=$val->address;
- $array[$keys]['address_id']=$val->address_id;
- $array[$keys]['user_id']=$val->u_id;
- $array[$keys]['province']=$val->province;
- $array[$keys]['city']=$val->city;
- $array[$keys]['town']=$val->town;
- $array[$keys]['u_nickname']=$val->u_nickname;
- $array[$keys]['u_mobile']=$val->u_mobile;
- $array[$keys]['u_name']=$val->u_name;
- $array[$keys]['goods'][$val->order_num][]=$val->name.'-'.$val->sec_attr.'-'.$val->size.'*'.$val->total;
- // $array[$keys]['goods'][$val->order_num][]=[$val->name.$val->size,$val->name,$val->size,$val->sec_attr,$val->total];
- if($val->unit=='套'){
- if(empty($array[$keys]['num'])){
- $array[$keys]['num']=$val->total;
- }else{
- $array[$keys]['num']+=$val->total;
- }
- }elseif($val->unit=='件'){
- if(empty($array[$keys]['num'])){
- $array[$keys]['num']=$val->total*2;
- }else{
- $array[$keys]['num']+=$val->total*2;
- }
- }
- }
- $gifts=Gifts::where('activity_id',$activity_id)->get();
- foreach($array as $key=>$val){
- $array[$key]['shouhuan']=0;
- $array[$key]['xianglian']=0;
- foreach($gifts as $k => $v){
- if(floor($val['num']/$v->num)>0){
- if ($v->name=='手环'||$v->name=='赠品-手环'){
- $array[$key]['shouhuan']=floor($val['num']/$v->num);
- }
- if ($v->name=='项链'||$v->name=='赠品-项链'){
- $array[$key]['xianglian']=floor($val['num']/$v->num);
- }
- }
- }
- }
- return $this->success($array);
- }
- //根据名称查询代理信息
- public function getUserNameIds($search = null)
- {
- return User::where(function ($query) use ($search) {
- $query->where('nickname', 'like', '%' . $search . '%')
- ->orwhere('realname', 'like', '%' . $search . '%')
- ->orwhere('mobile', $search);
- })->pluck('id');
- }
- //根据商品名称获取订单id
- public function getGoodsOrderIds($search = null)
- {
- return Orderdetail::where('goods_name', 'like', '%' . $search . '%')
- ->pluck('order_id');
- }
- protected function dataGroup(array $dataArr, string $keyStr): array
- {
- $newArr = [];
- foreach ($dataArr as $k => $val) { //数据根据日期分组
- $newArr[$val[$keyStr]][] = $val;
- }
- return $newArr;
- }
- public function getGoodsInfo($order_id)
- {
- $goods = Goodtest::leftJoin('order_detail', function ($query) use ($order_id) {
- $query->on('goods_test.id', '=', 'order_detail.goods_id')
- ->where('order_id', $order_id);
- })
- ->select('goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'))
- ->groupBy('goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
- ->get();
- return $goods;
- }
- //=======
- /***T恤统计*/
- public function get_t_data(Request $request)
- {
- $input = $request->all();
- $page_index = $input['page_index'];
- $page_size = $input['page_size'];
- $num = ($page_index - 1) * $page_size;
- $data = CrownCount::orderBy('exchange')->orderBy('id');
- $datas = CrownCount::orderBy('exchange')->orderBy('id');
- if ($request->mobile) {
- $data->where('mobile', $request->mobile)
- ->orwhere('nickname', 'like', '%' . $request->mobile . '%');
- $datas->where('mobile', $request->mobile)
- ->orwhere('nickname', 'like', '%' . $request->mobile . '%');
- }
- if ($request->crown_mobile) {
- $data->where('crown_mobile', $request->crown_mobile)
- ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%');
- $datas->where('crown_mobile', $request->crown_mobile)
- ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%');
- }
- $count = $data->count();
- $tt = clone $datas;
- $count_surplus = $datas->where('exchange', 0)->count();
- $t = $tt->select(DB::raw('sum(crown_count.type_l) as total_L'), DB::raw('sum(crown_count.type_xl) as total_XL'), DB::raw('sum(crown_count.type_3XL) as total_3XL'))->get();
- $count_write = $count - $count_surplus;
- if ($count == 0) {
- $percent = 0;
- } else {
- $percent = (round($count_write / $count, 4) * 100) . '%';
- }
- if ($count == 0) {
- return $this->success_list([], '', $count);
- }
- $list = $data->skip($num)->take($page_size)->get();
- $re = [];
- foreach ($list as $k => $v) {
- $re[$k]['序号'] = $v->id;
- $re[$k]['下单人昵称'] = $v->crown_name;
- $re[$k]['下单人手机号'] = $v->crown_mobile;
- $re[$k]['收货人昵称'] = $v->nickname;
- $re[$k]['收货人手机号'] = $v->mobile;
- $re[$k]['T恤总量'] = $v->total;
- $re[$k]['尺码:L'] = $v->type_l;
- $re[$k]['尺码:XL'] = $v->type_xl;
- $re[$k]['尺码:3XL'] = $v->type_3xl;
- $re[$k]['已统计T恤'] = $v->type_l + $v->type_xl + $v->type_3xl;
- $re[$k]['收货人省份'] = $v->province;
- $re[$k]['收货人城市'] = $v->city;
- $re[$k]['收货人地区'] = $v->area;
- $re[$k]['收货人地址'] = $v->address;
- }
- $all = [
- 'total' => $count,
- 'write_count' => $count_write,
- 'surplus_count' => $count_surplus,
- 'percent' => $percent,
- 'total_L' => $t[0]['total_L'],
- 'total_XL' => $t[0]['total_XL'],
- 'total_3XL' => $t[0]['total_3XL'],
- 'total_all' => (string)($t[0]['total_3XL'] + $t[0]['total_XL'] + $t[0]['total_L']),
- 'list' => $re
- ];
- return $this->success($all);
- // return $this->success_list($re,'',$count);
- }
- /**下载T恤详情**/
- public function get_t_excel(Request $request)
- {
- $data = CrownCount::orderBy('id');
- if ($request->mobile) {
- $data->where('mobile', $request->mobile)
- ->orwhere('nickname', 'like', '%' . $request->mobile . '%');
- }
- if ($request->crown_mobile) {
- $data->where('mobile', $request->crown_mobile)
- ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%');
- }
- $list = $data->get();
- foreach ($list as $k => $v) {
- $re[$k]['下单人昵称'] = $v->crown_name;
- $re[$k]['下单人手机号'] = $v->crown_mobile;
- $re[$k]['收货人昵称'] = $v->nickname;
- $re[$k]['收货人手机号'] = $v->mobile;
- $re[$k]['T恤总量'] = $v->total;
- $re[$k]['尺码:L'] = $v->type_l;
- $re[$k]['尺码:XL'] = $v->type_xl;
- $re[$k]['尺码:3XL'] = $v->type_3xl;
- $re[$k]['已统计T恤'] = $v->type_l + $v->type_xl + $v->type_3xl;
- $re[$k]['收货人省份'] = $v->province;
- $re[$k]['收货人城市'] = $v->city;
- $re[$k]['收货人地区'] = $v->area;
- $re[$k]['收货人地址'] = $v->address;
- }
- return $this->success_list($re);
- }
- /*
- * 修改T恤统计信息
- * */
- public function update_t(Request $request)
- {
- $re = $request->all();
- $v = CrownCount::where('id', $re['序号'])->first();
- if (!$v) {
- return $this->error(40013, '修改出错');
- }
- try {
- $count = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL'];
- if ($count > $re['T恤总量']) {
- return $this->error(40013, '尺码数量总和大于T恤总量');
- }
- // if ($v->exchange!=$count){
- // return $this->error(40013,'尺码数量总和不等于已统计数量');
- // }
- $v->crown_name = $re['下单人昵称'];
- $v->crown_mobile = $re['下单人手机号'];
- $v->nickname = $re['收货人昵称'];
- $v->mobile = $re['收货人手机号'];
- $v->total = $re['T恤总量'];
- $v->type_l = $re['尺码:L'];
- $v->type_xl = $re['尺码:XL'];
- $v->type_3xl = $re['尺码:3XL'];
- $v->exchange = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL'];
- $v->province = $re['收货人省份'];
- $v->city = $re['收货人城市'];
- $v->area = $re['收货人地区'];
- $v->address = $re['收货人地址'];
- $v->save();
- return $this->success([]);
- } catch (\Exception $exception) {
- return $this->error(40013, $exception);
- }
- }
- /*
- * 新增
- * **/
- public function add_t(Request $request)
- {
- $re = $request->all();
- $v = new CrownCount();
- try {
- $count = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL'];
- if ($count > $re['T恤总量']) {
- return $this->error(40013, '尺码数量总和大于T恤总量');
- }
- $v->crown_name = $re['下单人昵称'];
- $v->crown_mobile = $re['下单人手机号'];
- $v->nickname = $re['收货人昵称'];
- $v->mobile = $re['收货人手机号'];
- $v->total = $re['T恤总量'];
- $v->type_l = $re['尺码:L'];
- $v->type_xl = $re['尺码:XL'];
- $v->type_3xl = $re['尺码:3XL'];
- $v->exchange = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL'];
- $v->province = $re['收货人省份'];
- $v->city = $re['收货人城市'];
- $v->area = $re['收货人地区'];
- $v->address = $re['收货人地址'];
- $v->save();
- return $this->success([]);
- } catch (\Exception $exception) {
- return $this->error(40013, '修改失败');
- }
- }
- /*
- * 删除T恤统计
- * **/
- public function delete_t(Request $request)
- {
- $input = $request->all();
- CrownCount::where('id', $input['序号'])->delete();
- return $this->success([]);
- }
- public function get_user()
- {
- $data = [20218, 2533, 13649, 12336, 23488, 21256, 12487, 17769, 16377, 20363, 9736, 2568, 11718, 21221];
- foreach ($data as $k => $v) {
- $user = User::find($v);
- $re[$k]['mobile'] = $user->mobile;
- $re[$k]['nickname'] = $user->nickname;
- $re[$k]['realname'] = $user->realname;
- }
- return $this->success_list($re);
- }
- /**尺码详情**/
- public function size_data(){
- $active=Activity::where('is_ing',1)->first();
- $data=Orderdetail::join('order_test','order_test.id','=','order_detail.order_id')
- ->where('order_test.is_deleted',0)
- ->whereBetween('order_detail.created_at',[$active->start_time,$active->end_time])
- ->select('order_detail.goods_id','order_detail.goods_name','order_detail.goods_size',DB::raw('sum(order_detail.num) as num'))
- ->groupBy('order_detail.goods_id')->orderBy('order_detail.goods_id')->get();
- return $this->success_list($data);
- }
- //获取订单备注
- private function getOrderRemark($order_id)
- {
- $remark = OrderRemark::where('order_id', $order_id)
- ->select('remark', 'name')->get();
- $str_remark = '';
- if ($remark) {
- foreach ($remark as $k => $v) {
- $str_remark .= '【' . $v->remark . '/---/' . $v->name . '】';
- }
- }
- return $str_remark;
- }
- public function getActivityDataInfo(Request $request)
- {
- $input=$request->all();
- $page_index=$input['page_index'];
- $page_size=$input['page_size'];
- $num=$page_size*($page_index-1);
- $search_name=$input['search_name'];
- $activity=Activity::where('disabled',0)->get();
- foreach($activity as $key=>$val){
- if($val->end_time <= date("Y-m-d H:i:s")){
- $act_data_num = EveryActData::where('activity_id',$val->id)->count();
- if($act_data_num <= 0){
- $user=Ordertest::where('pay_status',2)->where('is_deleted',0)->whereBetween('created_at',[$val->start_time,$val->end_time])
- ->groupBy('user_id')->pluck('user_id');
- $info=User::select('id','nickname','realname','mobile','level')->withCount(['order_test as order_test_account'=>function($query)use($val){
- $query->select(DB::raw('sum(pay_money)'))->whereBetween('created_at',[$val->start_time,$val->end_time]);
- }])->whereIn('id',$user)->get();
- $act=[];
- foreach($info as $k=>$v){
- $act[$k]['user_id']=$v->id;
- $act[$k]['activity_id']=$val->id;
- $act[$k]['account']=$v->order_test_account;
- $act[$k]['created_at']=date("Y-m-d H:i:s");
- $act[$k]['updated_at']=date("Y-m-d H:i:s");
- }
- EveryActData::insert($act);
- }
- }
- }
- $user_ids=EveryActData::groupBy('user_id')->pluck('user_id');
- $info=User::select('id','nickname','realname','mobile','level')
- ->with(['every_act_data'=>function($query){
- $query->select('id','user_id','activity_id','account')->with(['activity:id,title']);
- }])->whereIn('id',$user_ids);
- if($search_name){
- $info->where(function($query)use($search_name){
- $query->where('nickname','like','%'.$search_name.'%')
- ->where('mobile',$search_name);
- });
- }
- $count=$info ->count();
- $list=$info -> OrderByDesc('level')->OrderByDesc('id')->skip($num)->take($page_size)->get();
- // return $this->success($list);
- foreach($list as $key=>$val){
- // $count[$key]=0;
- foreach($val as $k=>$v){
- // $list[$v->id]['nickname']=$v['nickname'];
- // $list[$v->id]['realname']=$v['realname'];
- // $list[$v->id]['mobile']=$v['mobile'];
- // $list[$v->id]['level']=$v['level'];
- // $list[$v->id][$key]=$v->order_test_account;
- // $count[$key]+=$v->order_test_account;
- }
- }
- $every_act=EveryActData::with(['activity:id,title'])->groupBy('activity_id')->orderByDesc('activity_id')->get();
- $account=[];
- foreach($every_act as $key=>$val){
- $account[$val->activity_id]['title']=$val->activity->title;
- $account[$val->activity_id]['account']=EveryActData::where('activity_id',$val->activity_id)->sum('account');
- }
- $data['list']=$list;
- $data['account']=$account;
- return $this->success_list($data,'',$count);
- }
- }
|