DataController.php 123 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Activity;
  4. use App\Models\ActivityLimit;
  5. use App\Models\Address;
  6. use App\Models\EveryActData;
  7. use App\Models\OrderGift;
  8. use App\Models\Goodattr;
  9. use App\Models\Goodtest;
  10. use App\Models\Orderdetail;
  11. use App\Models\OrderRemark;
  12. use App\Models\Ordertest;
  13. use App\Models\Store;
  14. use App\Models\User;
  15. use App\Models\Warea;
  16. use App\Models\Gifts;
  17. use Carbon\Carbon;
  18. use App\Models\CrownCount;
  19. use Illuminate\Http\Request;
  20. use Illuminate\Support\Facades\DB;
  21. use Illuminate\Support\Facades\Log;
  22. use Illuminate\Support\Facades\Cache;
  23. use Illuminate\Support\Facades\Auth;
  24. class DataController extends Controller
  25. {
  26. public function datas()
  27. {
  28. $order = Ordertest::where('is_deleted', 0)->with(['get_address', 'get_order_detail'])->get();
  29. $attr = Goodattr::where('pid', 0)->get();
  30. $hard_id = [];
  31. $simple_id = [];
  32. $old_id = [];
  33. $hard_good = [];
  34. $simple_good = [];
  35. $old_good = [];
  36. foreach ($attr as $k => $v) {
  37. if ($v->name == '大卫博士精装版') {
  38. $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id');
  39. $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray();
  40. } elseif ($v->name == '大卫博士简约版') {
  41. $simple_id = Goodattr::where('pid', $v->id)->pluck('id');
  42. $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray();
  43. } elseif ($v->name == '大卫博士老人版') {
  44. $old_id = Goodattr::where('pid', $v->id)->pluck('id');
  45. $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray();
  46. }
  47. }
  48. $money = 0;
  49. $hard = 0;
  50. $simple = 0;
  51. $old = 0;
  52. $re = [];
  53. foreach ($order as $k => $v) {
  54. $hard_pro = 0;
  55. $simple_pro = 0;
  56. $old_pro = 0;
  57. foreach ($v->get_order_detail as $ke => $va) {
  58. if (in_array($va->goods_id, $hard_good)) {
  59. $hard += $va->num;
  60. $hard_pro = $va->num;
  61. } elseif (in_array($va->goods_id, $simple_good)) {
  62. $simple += $va->num;
  63. $simple_pro = $va->num;
  64. } elseif (in_array($va->goods_id, $old_good)) {
  65. $old += $va->num;
  66. $old_pro = $va->num;
  67. }
  68. }
  69. $money += $v->money;
  70. }
  71. $datas = [
  72. 'hard' => $hard,
  73. 'simple' => $simple,
  74. 'old' => $old,
  75. 'money' => $money,
  76. ];
  77. return $this->success($datas);
  78. }
  79. public function data()
  80. {
  81. $active = Activity::where('is_ing', 1)->first();
  82. $now = Carbon::now()->toDateTimeString();
  83. $order = Ordertest::where('is_deleted', 0)->whereBetween('created_at', [$active->start_time, $active->end_time])->with(['get_address', 'get_order_detail']);
  84. $order_1=clone $order;
  85. $order_2=clone $order;
  86. $order=$order->get();
  87. $order_1=$order_1->where('store_id',17)->sum('money');
  88. $order_2=$order_2->where('store_id',18)->sum('money');
  89. $order_today = [];
  90. if ($now < $active->end_time && $now > $active->start_time) {
  91. if (Carbon::now()->toDateString() == Carbon::parse($active->start_time)->toDateString()) {
  92. $start_time = $active->start_time;
  93. } else {
  94. $start_time = Carbon::today();
  95. }
  96. if (Carbon::now()->toDateString() == Carbon::parse($active->end_time)->toDateString()) {
  97. $end_time = $active->end_time;
  98. } else {
  99. $end_time = Carbon::tomorrow();
  100. }
  101. $order_today = Ordertest::where('is_deleted', 0)->with(['get_order_detail'])->whereBetween('created_at', [$start_time, $end_time])->get();
  102. }
  103. $act_gifts = Gifts::where('activity_id',$active->id)->get();//活动所有礼品
  104. $gifts_num=[];
  105. if(count($act_gifts)>0){
  106. foreach($act_gifts as $key=>$val){
  107. $gifts_num[$val->name]=OrderGift::whereHas('order_test',function($query){
  108. $query->where('is_deleted',0);
  109. })->where('activity_id',$active->id)->where('gift_id',$val->id)->sum('num');
  110. // $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');
  111. }
  112. }
  113. $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');
  114. $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');
  115. $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'))
  116. ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id')
  117. ->where('order_test.is_deleted',0)
  118. ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time])
  119. ->groupBy('users.id')
  120. ->having('account','>=',$active->big_gift)
  121. ->orderBy('type','asc')
  122. ->orderBy('pay_account','desc')
  123. ->orderBy('account','desc');
  124. $count = $user_data->get()->count();
  125. $honor_limit=ActivityLimit::where('activity_id',$active->id)->where('type',1)->get();
  126. $honor_num=[];
  127. if(count($honor_limit)>0){
  128. foreach($honor_limit as $key=>$val){
  129. $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'))
  130. ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id')
  131. ->where('order_test.is_deleted',0)
  132. ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time])
  133. ->groupBy('users.id')
  134. ->having('account','>=',$val->account)
  135. ->orderBy('type','asc')
  136. ->orderBy('pay_account','desc')
  137. ->orderBy('account','desc')->get()->count();
  138. }
  139. }
  140. $down_limit=Activity::where('id',$active->id)->value('crown_down');
  141. // $down_info=[];
  142. if($down_limit>0){
  143. // foreach($down_limit as $key=>$val){
  144. // foreach(Activity::$levels as $k=>$v){
  145. // if($val->title==$v){
  146. // $level=$k;
  147. // }
  148. // }
  149. // User::withCount('order_test',function($query){
  150. // $query->select(DB::raw('SUM(money) as account'), DB::raw('SUM(pay_money) as pay_account'));
  151. // })
  152. ////
  153. // User::with('order_test')
  154. // ->whereHas('order_test',function($query)use($active){
  155. // $query->where('is_deleted',0)->whereBetween('order_test.created_at',[$active->start_time,$active->end_time]);})
  156. // ->where('level',$level)->get();
  157. $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'))
  158. ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id')
  159. ->where('users.level',3)
  160. ->where('order_test.is_deleted',0)
  161. ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time])
  162. ->groupBy('users.id')
  163. ->having('account','>=',$down_limit)
  164. ->orderBy('type','asc')
  165. ->orderBy('pay_account','desc')
  166. ->orderBy('account','desc')->get()->count();
  167. $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'))
  168. ->leftJoin('order_test', 'order_test.user_id', '=', 'users.id')
  169. ->where('users.level',3)
  170. ->where('order_test.is_deleted',0)
  171. ->whereBetween('order_test.created_at',[$active->start_time,$active->end_time])
  172. ->groupBy('users.id')
  173. ->having('account','<',$down_limit)
  174. ->orderBy('type','asc')
  175. ->orderBy('pay_account','desc')
  176. ->orderBy('account','desc')->get()->count();
  177. // }
  178. }else{
  179. $down_info['up']=0;
  180. $down_info['down']=0;
  181. }
  182. $attr = Goodattr::where('pid', 0)->get();
  183. $hard_id = [];
  184. $simple_id = [];
  185. $old_id = [];
  186. $hard_good = [];
  187. $simple_good = [];
  188. $old_good = [];
  189. $newold_good = [];
  190. foreach ($attr as $k => $v) {
  191. if ($v->name == '大卫博士精装版') {
  192. $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id');
  193. $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray();
  194. } elseif ($v->name == '大卫博士简约版') {
  195. $simple_id = Goodattr::where('pid', $v->id)->pluck('id');
  196. $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray();
  197. } elseif ($v->name == '大卫博士老人版') {
  198. $old_id = Goodattr::where('pid', $v->id)->pluck('id');
  199. $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray();
  200. } elseif ($v->name == '大卫博士纯棉老人版') {
  201. $newold_id = Goodattr::where('pid', $v->id)->pluck('id');
  202. $newold_good = Goodtest::whereIn('attr_id', $newold_id)->pluck('id')->toArray();
  203. }
  204. }
  205. $money = 0;
  206. $hard = 0;
  207. $simple = 0;
  208. $old = 0;
  209. $newold = 0;
  210. $hard_today = 0;
  211. $newold_today = 0;
  212. $simple_today = 0;
  213. $old_today = 0;
  214. $money_today = 0;
  215. $re = [];
  216. // dd($order);
  217. foreach ($order_today as $k => $v) {
  218. foreach ($v->get_order_detail as $ke => $va) {
  219. if (in_array($va->goods_id, $hard_good)) {
  220. $hard_today += $va->num;
  221. } elseif (in_array($va->goods_id, $simple_good)) {
  222. $simple_today += $va->num;
  223. } elseif (in_array($va->goods_id, $old_good)) {
  224. $old_today += $va->num;
  225. } elseif (in_array($va->goods_id, $newold_good)) {
  226. $newold_today += $va->num;
  227. }
  228. }
  229. $money_today += $v->money;
  230. }
  231. $h = 0;
  232. $hard_pro = 0;
  233. $simple_pro = 0;
  234. $old_pro = 0;
  235. $newold_pro = 0;
  236. $money_pro = 0;
  237. $hard_money = 0;
  238. $simple_money = 0;
  239. $old_money = 0;
  240. $newold_money = 0;
  241. foreach ($order as $k => $v) {
  242. $hard_pro = 0;
  243. $simple_pro = 0;
  244. $old_pro = 0;
  245. $newold_pro = 0;
  246. foreach ($v->get_order_detail as $ke => $va) {
  247. if (in_array($va->goods_id, $hard_good)) {
  248. $hard += $va->num;
  249. $hard_money += $va->money;
  250. $hard_pro += $va->num;
  251. } if (in_array($va->goods_id, $simple_good)) {
  252. $simple += $va->num;
  253. $simple_money += $va->money;
  254. $simple_pro += $va->num;
  255. } if (in_array($va->goods_id, $old_good)) {
  256. $old += $va->num;
  257. $old_money += $va->money;
  258. $old_pro += $va->num;
  259. } if (in_array($va->goods_id, $newold_good)) {
  260. $newold += $va->num;
  261. $newold_money += $va->money;
  262. $newold_pro += $va->num;
  263. }
  264. }
  265. $money += $v->money;
  266. $h += $newold_pro;
  267. $re = $this->province($v->get_address->province, $hard_pro, $simple_pro, $old_pro, $newold_pro, $v->money, $re);
  268. }
  269. $datas = [
  270. 'hard' => $hard,
  271. 'simple' => $simple,
  272. 'old' => $old,
  273. 'newold' => $newold,
  274. 'money' => $money,
  275. 'hard_today' => $hard_today,
  276. 'simple_today' => $simple_today,
  277. 'old_today' => $old_today,
  278. 'newold_today' => $newold_today,
  279. 'money_today' => $money_today,
  280. 'activity_title'=>$active->title,
  281. 'shouhuan'=>$gift_sh,
  282. 'xianglian'=>$gift_xl,
  283. 'big_gift'=>$count,
  284. '临沭体验店'=>$order_1,
  285. '吴桥体验店'=>$order_2,
  286. 'activity_time'=>'('.date('m月d日',strtotime($active->start_time)).'-'.date('d日',strtotime($active->end_time)).')',
  287. 'list' => $re,
  288. 'gifts_num'=>$gifts_num,
  289. 'honor_num'=>$honor_num,
  290. 'down_info'=>$down_info,
  291. 'hard_money' => $hard_money,
  292. 'simple_money' =>$simple_money,
  293. 'old_money' => $old_money,
  294. 'newold_money' => $newold_money,
  295. ];
  296. return $this->success($datas);
  297. // $data=['北京', '天津', '上海', '重庆', '河北', '河南', '云南', '辽宁', '黑龙江', '湖南', '安徽', '山东', '新疆', '江苏','浙江', '江西', '湖北', '广西', '甘肃', '山西', '内蒙古', '陕西', '吉林', '福建', '贵州', '广东', '青海', '西藏', '四川', '宁夏', '海南', '台湾','香港', '澳门'];
  298. }
  299. public function province($name, $hard, $simple, $old, $newold, $money, $res = [])
  300. {
  301. // $data=['北京', '天津', '上海', '重庆', '河北', '河南', '云南', '辽宁', '黑龙江', '湖南', '安徽', '山东', '新疆', '江苏','浙江', '江西', '湖北', '广西', '甘肃', '山西', '内蒙古', '陕西', '吉林', '福建', '贵州', '广东', '青海', '西藏', '四川', '宁夏', '海南', '台湾','香港', '澳门'];
  302. // $s='河北省、山西省、辽宁省、吉林省、黑龙江省、江苏省、浙江省、安徽省、福建省、江西省、山东省、河南省、湖北省、湖南省、广东省、海南省、四川省、贵州省、云南省、陕西省、甘肃省、青海省、台湾省';
  303. // $ss='内蒙古自治区、广西壮族自治区、西藏自治区、宁夏回族自治区、新疆维吾尔自治区';
  304. // $sss='北京市、天津市、上海市、重庆市';
  305. // $ssss='香港特别行政区、澳门特别行政区';
  306. $datas = [
  307. ['北京', '北京市'], ['天津', '天津市'], ['上海', '上海市'], ['重庆', '重庆市'], ['河北', '河北省'], ['河南', '河南省'], ['云南', '云南省'], ['辽宁', '辽宁省'], ['黑龙江', '黑龙江省'], ['湖南', '湖南省'], ['安徽', '安徽省'], ['山东', '山东省'], ['新疆', '新疆维吾尔自治区'], ['江苏', '江苏省'], ['浙江', '浙江省'], ['江西', '江西省'], ['湖北', '湖北省'], ['广西', '广西壮族自治区'], ['甘肃', '甘肃省'], ['山西', '山西省'], ['内蒙古', '内蒙古自治区'], ['陕西', '陕西省'], ['吉林', '吉林省'], ['福建', '福建省'], ['贵州', '贵州省'], ['广东', '广东省'], ['青海', '青海省'], ['西藏', '西藏自治区'], ['四川', '四川省'], ['宁夏', '宁夏回族自治区'], ['海南', '海南省'], ['台湾', '台湾'], ['香港', '香港'], ['澳门', '澳门']
  308. ];
  309. foreach ($datas as $k => $v) {
  310. $re[$k]['name'] = $v[0];
  311. if ($res) {
  312. if ($v[1] == $name) {
  313. $re[$k]['hard'] = $hard + $res[$k]['hard'];
  314. $re[$k]['simple'] = $simple + $res[$k]['simple'];
  315. $re[$k]['old'] = $old + $res[$k]['old'];
  316. $re[$k]['newold'] = $newold + $res[$k]['newold'];
  317. $re[$k]['value'] = $money + $res[$k]['value'];
  318. } else {
  319. $re[$k]['hard'] = $res[$k]['hard'];
  320. $re[$k]['simple'] = $res[$k]['simple'];
  321. $re[$k]['old'] = $res[$k]['old'];
  322. $re[$k]['newold'] = $res[$k]['newold'];
  323. $re[$k]['value'] = $res[$k]['value'];
  324. }
  325. } else {
  326. if ($v[1] == $name) {
  327. $re[$k]['hard'] = $hard;
  328. $re[$k]['simple'] = $simple;
  329. $re[$k]['old'] = $old;
  330. $re[$k]['newold'] = $newold;
  331. $re[$k]['value'] = $money;
  332. // $re[$k]['money']=$money;
  333. } else {
  334. $re[$k]['hard'] = 0;
  335. $re[$k]['simple'] = 0;
  336. $re[$k]['old'] = 0;
  337. $re[$k]['newold'] = 0;
  338. $re[$k]['value'] = 0;
  339. }
  340. }
  341. }
  342. Log::error($re);
  343. $last_ages = array_column($re,'value');
  344. array_multisort($last_ages ,SORT_DESC,$re);
  345. Log::error($re);
  346. return $re;
  347. }
  348. public function crown_rank()
  349. {
  350. }
  351. public function money()
  352. {
  353. $order = Ordertest::where('is_deleted', 0)->with(['get_address', 'get_order_detail'])->get();
  354. $attr = Goodattr::where('pid', 0)->get();
  355. $hard_id = [];
  356. $simple_id = [];
  357. $old_id = [];
  358. $hard_good = [];
  359. $simple_good = [];
  360. $old_good = [];
  361. foreach ($attr as $k => $v) {
  362. if ($v->name == '大卫博士精装版') {
  363. $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id');
  364. $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray();
  365. } elseif ($v->name == '大卫博士简约版') {
  366. $simple_id = Goodattr::where('pid', $v->id)->pluck('id');
  367. $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray();
  368. } elseif ($v->name == '大卫博士老人版') {
  369. $old_id = Goodattr::where('pid', $v->id)->pluck('id');
  370. $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray();
  371. }
  372. }
  373. $money = 0;
  374. $hard = 0;
  375. $simple = 0;
  376. $old = 0;
  377. $re = [];
  378. foreach ($order as $k => $v) {
  379. $hard_pro = 0;
  380. $simple_pro = 0;
  381. $old_pro = 0;
  382. foreach ($v->get_order_detail as $ke => $va) {
  383. if (in_array($va->goods_id, $hard_good)) {
  384. $hard += $va->num;
  385. $hard_pro = $va->num;
  386. } elseif (in_array($va->goods_id, $simple_good)) {
  387. $simple += $va->num;
  388. $simple_pro = $va->num;
  389. } elseif (in_array($va->goods_id, $old_good)) {
  390. $old += $va->num;
  391. $old_pro = $va->num;
  392. }
  393. }
  394. $money += $v->money;
  395. }
  396. $datas = [
  397. 'hard' => $hard,
  398. 'simple' => $simple,
  399. 'old' => $old,
  400. 'money' => $money,
  401. ];
  402. return $this->success_list($datas);
  403. }
  404. // public function get_crown(){
  405. // $user=User::where('level',3)->get();
  406. // $attr=Goodattr::where('pid',0)->get();
  407. // $hard_id=[];
  408. // $simple_id=[];
  409. // $old_id=[];
  410. // foreach ($attr as $k=>$v){
  411. // if ($v->name=='大卫博士精装版'){
  412. // $hard_id=Goodattr::where('pid',$v->id)->select('id')->pluck('id');
  413. // $hard_good=Goodtest::whereIn('attr_id',$hard_id)->pluck('id')->toArray();
  414. // }elseif ($v->name=='大卫博士简约版'){
  415. // $simple_id=Goodattr::where('pid',$v->id)->pluck('id');
  416. // $simple_good=Goodtest::whereIn('attr_id',$simple_id)->pluck('id')->toArray();
  417. // }elseif ($v->name=='大卫博士老人版'){
  418. // $old_id=Goodattr::where('pid',$v->id)->pluck('id');
  419. // $old_good=Goodtest::whereIn('attr_id',$old_id)->pluck('id')->toArray();
  420. // }
  421. // }
  422. // foreach ($user as $k=>$v){
  423. // $money=0;
  424. // $hard=0;
  425. // $simple=0;
  426. // $old=0;
  427. // $order=Ordertest::where('user_id',$v->id)->where('is_deleted',0)->get();
  428. // $count=count($order);
  429. // if ($count==0){
  430. // $re[$k]['hard']=0;
  431. // $re[$k]['simple']=0;
  432. // $re[$k]['old']=0;
  433. // $re[$k]['money']=0;
  434. // }else{
  435. // foreach ($v->get_order_detail as $ke=>$va){
  436. // if (in_array($va->goods_id,$hard_good)){
  437. // $hard+=$va->num;
  438. // }elseif (in_array($va->goods_id,$simple_good)){
  439. // $simple+=$va->num;
  440. // }elseif (in_array($va->goods_id,$old_good)){
  441. // $old+=$va->num;
  442. // }
  443. // }
  444. // $money+=$v->money;
  445. // $re[$k]['money']=$money;
  446. // $re[$k]['hard']=$hard;
  447. // $re[$k]['simple']=$simple;
  448. // $re[$k]['old']=$old;
  449. // }
  450. // return $n;
  451. // $re[$k]['nickname']=$v->nickname;
  452. // }
  453. // return $this->success_list($re);
  454. // }
  455. //=======
  456. // foreach ($datas as $k=>$v){
  457. // $re[$k]['name']=$v[0];
  458. // if ($res){
  459. // if ($v[1]==$name){
  460. // $re[$k]['hard']=$hard+$res[$k]['hard'];
  461. // $re[$k]['simple']=$simple+$res[$k]['simple'];
  462. // $re[$k]['old']=$old+$res[$k]['old'];
  463. // $re[$k]['value']=$money+$res[$k]['value'];
  464. // }else{
  465. // $re[$k]['hard']=$res[$k]['hard'];
  466. // $re[$k]['simple']=$res[$k]['simple'];
  467. // $re[$k]['old']=$res[$k]['old'];
  468. // $re[$k]['value']=$res[$k]['value'];
  469. // }
  470. // }else{
  471. // if ($v[1]==$name){
  472. // $re[$k]['hard']=$hard;
  473. // $re[$k]['simple']=$simple;
  474. // $re[$k]['old']=$old;
  475. // $re[$k]['value']=$money;
  476. // // $re[$k]['money']=$money;
  477. // }else{
  478. // $re[$k]['hard']=0;
  479. // $re[$k]['simple']=0;
  480. // $re[$k]['old']=0;
  481. // $re[$k]['value']=0;
  482. // }
  483. // }
  484. //
  485. // }
  486. // return $re;
  487. // }
  488. //
  489. public function get_crown()
  490. {
  491. $active = Activity::where('is_ing', 1)->first();
  492. $start_time = $active->start_time;
  493. $end_time = $active->end_time;
  494. $user = User::where('level', 3)->with(['get_order_de' => function ($q) use ($start_time, $end_time) {
  495. $q->where('order_test.is_deleted', 0)->whereBetween('order_test.created_at', [$start_time, $end_time]);
  496. }])->get();
  497. $attr = Goodattr::where('pid', 0)->get();
  498. $hard_id = [];
  499. $simple_id = [];
  500. $old_id = [];
  501. foreach ($attr as $k => $v) {
  502. if ($v->name == '大卫博士精装版') {
  503. $hard_id = Goodattr::where('pid', $v->id)->select('id')->pluck('id');
  504. $hard_good = Goodtest::whereIn('attr_id', $hard_id)->pluck('id')->toArray();
  505. } elseif ($v->name == '大卫博士简约版') {
  506. $simple_id = Goodattr::where('pid', $v->id)->pluck('id');
  507. $simple_good = Goodtest::whereIn('attr_id', $simple_id)->pluck('id')->toArray();
  508. } elseif ($v->name == '大卫博士老人版') {
  509. $old_id = Goodattr::where('pid', $v->id)->pluck('id');
  510. $old_good = Goodtest::whereIn('attr_id', $old_id)->pluck('id')->toArray();
  511. } elseif ($v->name == '大卫博士纯棉老人版') {
  512. $newold_id = Goodattr::where('pid', $v->id)->pluck('id');
  513. $newold_good = Goodtest::whereIn('attr_id', $newold_id)->pluck('id')->toArray();
  514. }
  515. }
  516. foreach ($user as $k => $v) {
  517. $money = 0;
  518. $hard = 0;
  519. $simple = 0;
  520. $old = 0;
  521. $newold = 0;
  522. $count = count($v->get_order_de);
  523. if ($count == 0) {
  524. $re[$k]['hard'] = 0;
  525. $re[$k]['simple'] = 0;
  526. $re[$k]['old'] = 0;
  527. $re[$k]['newold'] = 0;
  528. $re[$k]['money'] = 0;
  529. } else {
  530. foreach ($v->get_order_de as $key => $value) {
  531. if (in_array($value->goods_id, $hard_good)) {
  532. $hard += $value->num;
  533. } elseif (in_array($value->goods_id, $simple_good)) {
  534. $simple += $value->num;
  535. } elseif (in_array($value->goods_id, $old_good)) {
  536. $old += $value->num;
  537. } elseif (in_array($value->goods_id, $newold_good)) {
  538. $newold += $value->num;
  539. }
  540. $money += $value->money;
  541. }
  542. $re[$k]['money'] = $money;
  543. $re[$k]['hard'] = $hard;
  544. $re[$k]['simple'] = $simple;
  545. $re[$k]['old'] = $old;
  546. $re[$k]['newold'] = $newold;
  547. }
  548. $re[$k]['nickname'] = $v->nickname;
  549. }
  550. return $this->success_list($re);
  551. }
  552. //
  553. //
  554. //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab
  555. /***数据统计---------按照种类---***/
  556. public function rank_type()
  557. {
  558. $hard_good = Goodtest::where('main_attr', '大卫博士精装版')->pluck('id')->toArray();
  559. $simple_good = Goodtest::where('main_attr', '大卫博士简约版')->pluck('id')->toArray();
  560. $old_good = Goodtest::where('main_attr', '大卫博士老人版')->pluck('id')->toArray();
  561. $old_good_nan = Goodtest::where('main_attr', '大卫博士老人版')->where('sec_attr', '男款')->pluck('id')->toArray();
  562. $old_good_nv = Goodtest::where('main_attr', '大卫博士老人版')->where('sec_attr', '女款')->pluck('id')->toArray();
  563. $simple_good_nan = Goodtest::where('main_attr', '大卫博士简约版')->where('sec_attr', '男款')->pluck('id')->toArray();
  564. $simple_good_nv = Goodtest::where('main_attr', '大卫博士简约版')->where('sec_attr', '女款')->pluck('id')->toArray();
  565. $hard_good_nan = Goodtest::where('main_attr', '大卫博士精装版')->where('sec_attr', '男款')->pluck('id')->toArray();
  566. $hard_good_nv = Goodtest::where('main_attr', '大卫博士精装版')->where('sec_attr', '女款')->pluck('id')->toArray();
  567. $where = function ($query) {
  568. $query->where('is_deleted', 0);
  569. };
  570. $orders = Ordertest::where($where)->get();
  571. $hard = 0;
  572. $simple = 0;
  573. $old = 0;
  574. $old_money = 0;
  575. $simple_money = 0;
  576. $hard_money = 0;
  577. $hard_nan = 0;
  578. $hard_nv = 0;
  579. $simple_nan = 0;
  580. $simple_nv = 0;
  581. $old_nan = 0;
  582. $old_nv = 0;
  583. $hard_nan_money = 0;
  584. $hard_nv_money = 0;
  585. $simple_nan_money = 0;
  586. $simple_nv_money = 0;
  587. $old_nan_money = 0;
  588. $old_nv_money = 0;
  589. foreach ($orders as $k => $v) {
  590. $order = Ordertest::where('id', $v->id)->with(['get_order_detail'])->first();
  591. foreach ($order->get_order_detail as $ke => $va) {
  592. if (in_array($va->goods_id, $hard_good)) {
  593. $hard += $va->num;
  594. $hard_money += $va->money;
  595. } elseif (in_array($va->goods_id, $simple_good)) {
  596. $simple += $va->num;
  597. $simple_money += $va->money;
  598. } elseif (in_array($va->goods_id, $old_good)) {
  599. $old += $va->num;
  600. $old_money += $va->money;
  601. }
  602. if (in_array($va->goods_id, $hard_good_nan)) {
  603. $hard_nan += $va->num;
  604. $hard_nan_money += $va->money;
  605. } elseif (in_array($va->goods_id, $hard_good_nv)) {
  606. $hard_nv += $va->num;
  607. $hard_nv_money += $va->money;
  608. } elseif (in_array($va->goods_id, $simple_good_nan)) {
  609. $simple_nan += $va->num;
  610. $simple_nan_money += $va->money;
  611. } elseif (in_array($va->goods_id, $simple_good_nv)) {
  612. $simple_nv += $va->num;
  613. $simple_nv_money += $va->money;
  614. } elseif (in_array($va->goods_id, $old_good_nan)) {
  615. $old_nan += $va->num;
  616. $old_nan_money += $va->money;
  617. } elseif (in_array($va->goods_id, $old_good_nv)) {
  618. $old_nv += $va->num;
  619. $old_nv_money += $va->money;
  620. }
  621. }
  622. }
  623. $data = [
  624. 'hard' => $hard,
  625. 'simple' => $simple,
  626. 'old' => $old,
  627. 'hard_money' => $hard_money,
  628. 'simple_money' => $simple_money,
  629. 'old_money' => $old_money,
  630. 'hard_nan' => $hard_nan,
  631. 'simple_nan' => $simple_nan,
  632. 'old_nan' => $old_nan,
  633. 'hard_nan_money' => $hard_nan_money,
  634. 'simple_nan_money' => $simple_nan_money,
  635. 'old_nan_money' => $old_nan_money,
  636. 'hard_nv' => $hard_nv,
  637. 'simple_nv' => $simple_nv,
  638. 'old_nv' => $old_nv,
  639. 'hard_nv_money' => $hard_nv_money,
  640. 'simple_nv_money' => $simple_nv_money,
  641. 'old_nv_money' => $old_nv_money,
  642. ];
  643. return $this->success($data);
  644. }
  645. public function rank_type2(Request $request)
  646. {
  647. $input = $request->all();
  648. $start_time = $input['start_time'];
  649. $end_time = $input['end_time'];
  650. $data = Ordertest::where('is_deleted', 0);
  651. if ($request->has('order_status')) {
  652. $order_status = $input['order_status'];
  653. } else {
  654. $order_status = [];
  655. }
  656. if ($order_status || $order_status == 0) {
  657. if ('-1' == $order_status) {
  658. } elseif ($order_status == 0) {
  659. $data->where('status', $order_status)->where('is_deleted', 0);
  660. } elseif ($order_status == 1) {
  661. $data->where('status', $order_status)->where('is_deleted', 0);
  662. } elseif ($order_status == 2) {
  663. $data->where('status', $order_status)->where('is_deleted', 0);
  664. } elseif ($order_status == 3) {
  665. $data->where('status', $order_status)->where('is_deleted', 0);
  666. } elseif ($order_status == 4) {
  667. $data->where('status', $order_status)->where('is_deleted', 0);
  668. }
  669. }
  670. if ($start_time && $end_time) {
  671. $data->whereBetween('created_at', [$start_time, $end_time]);
  672. }
  673. $orders = $data->get();
  674. $good_attrs = Goodtest::where('is_deleted', 0)->groupBy('main_attr')->select('id', 'name', 'main_attr')->get();
  675. foreach ($good_attrs as $k => $v) {
  676. $good_attr[$k]['ids'] = Goodtest::where('is_deleted', 0)->where('main_attr', $v->main_attr)->pluck('id')->toArray();
  677. $good_attr[$k]['name'] = $v->main_attr;
  678. }
  679. foreach ($good_attr as $key => $value) {
  680. if (empty($attr[$value['name']])) {
  681. $attr[$value['name']][0] = 0;
  682. $attr[$value['name']][1] = 0;
  683. }
  684. }
  685. $good_types = Goodtest::where('is_deleted', 0)->groupBy('attr_id')->orderBy('sort')->select('id', 'name', 'main_attr', 'attr_id')->get();
  686. foreach ($good_types as $k => $v) {
  687. $good_type[$k]['ids'] = Goodtest::where('is_deleted', 0)->where('attr_id', $v->attr_id)->pluck('id')->toArray();
  688. $good_type[$k]['name'] = $v->name;
  689. }
  690. foreach ($good_type as $key => $value) {
  691. if (empty($type[$value['name']])) {
  692. $type[$value['name']][0] = 0;
  693. $type[$value['name']][1] = 0;
  694. }
  695. }
  696. $good_singles = Goodtest::where('is_deleted', 0)->orderBy('sort')->orderBy('id')->select('id', 'name', 'size')->get();
  697. foreach ($good_singles as $k => $v) {
  698. $good_single[$k]['ids'] = $v->id;
  699. $good_single[$k]['name'] = $v->name . '(' . $v->size . ')';
  700. }
  701. foreach ($good_single as $key => $value) {
  702. $single[$value['name']][0] = 0;
  703. $single[$value['name']][1] = 0;
  704. }
  705. foreach ($orders as $k => $v) {
  706. $order = Ordertest::where('id', $v->id)->with(['get_order_detail'])->first();
  707. foreach ($order->get_order_detail as $ke => $va) {
  708. foreach ($good_attr as $key => $value) {
  709. if (in_array($va->goods_id, $value['ids'])) {
  710. $attr[$value['name']][0] += $va->num;
  711. $attr[$value['name']][1] += $va->money;
  712. }
  713. }
  714. foreach ($good_type as $key => $value) {
  715. if (in_array($va->goods_id, $value['ids'])) {
  716. $type[$value['name']][0] += $va->num;
  717. $type[$value['name']][1] += $va->money;
  718. }
  719. }
  720. foreach ($good_single as $key => $value) {
  721. if ($va->goods_id == $value['ids']) {
  722. $single[$value['name']][0] += $va->num;
  723. $single[$value['name']][1] += $va->money;
  724. }
  725. }
  726. }
  727. }
  728. $data = [
  729. 'attr' => $attr,
  730. 'type' => $type,
  731. 'single' => $single
  732. ];
  733. return $this->success($data);
  734. }
  735. public function getOrderListInfo(Request $request)
  736. {
  737. $input = $request->all();
  738. $start_time = $input['start_time'];
  739. $end_time = $input['end_time'];
  740. $type = $input['type'];
  741. $order_status = $input['order_status'];
  742. $search_name = $input['search_name'];
  743. $receive = $input['name'];
  744. $province = $input['provice'];
  745. $city = $input['city'];
  746. $area = $input['area'];
  747. // $activity_id=$input['activity_id'];
  748. $ids = $this->getOrderListIds($start_time, $end_time, $order_status, $search_name, $receive, $province, $city, $area);
  749. $data = Goodtest::leftJoin('order_detail', function ($query) use ($ids) {
  750. $query->on('goods_test.id', '=', 'order_detail.goods_id')
  751. ->whereIn('order_detail.order_id', $ids);
  752. });
  753. if ($type == 3) {//种类
  754. $data->select('goods_test.main_attr', DB::raw('sum(order_detail.num) as total'), DB::raw('sum(order_detail.money) as account'))
  755. ->groupBy('goods_test.main_attr');
  756. }
  757. if ($type == 2) {//款式
  758. $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'))
  759. ->groupBy('goods_test.main_attr', 'goods_test.sec_attr');
  760. }
  761. if ($type == 1) {//尺码
  762. $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'))
  763. ->groupBy('goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size');
  764. }
  765. $list = $data->get();
  766. return $this->success($list);
  767. }
  768. public function getOrderListIds($start_time, $end_time, $order_status, $search_name, $receive, $province, $city, $area)
  769. {
  770. $order = Ordertest::where('is_deleted', 0);
  771. if (!empty($order_status) || $order_status == '0') {
  772. $order->where('status', '=', $order_status);
  773. }
  774. if ($start_time && $end_time) {
  775. $order->whereBetween('created_at', [$start_time, $end_time]);
  776. }
  777. if ($search_name) {
  778. $user_ids = $this->getUserIds($search_name);
  779. $order->whereIn('user_id', $user_ids);
  780. }
  781. if ($receive) {
  782. $address_ids = $this->getReceiveAddressIds($receive);
  783. $order->whereIn('address_id', $address_ids);
  784. }
  785. if ($province && $province != '省') {
  786. $province_ids = $this->getProvinceIds($province);
  787. $order->whereIn('address_id', $province_ids);
  788. }
  789. if ($city && $city != '市') {
  790. if ($city == '北京城区') {
  791. $city = '市辖区';
  792. }
  793. if ($city == '天津城区') {
  794. $city = '市辖区';
  795. }
  796. if ($city == '上海城区') {
  797. $city = '市辖区';
  798. }
  799. $city_ids = $this->getCityIds($city);
  800. $order->whereIn('address_id', $city_ids);
  801. }
  802. if ($area && $area != '区') {
  803. $area_ids = $this->getProvinceIds($area);
  804. $order->whereIn('address_id', $area_ids);
  805. }
  806. return $order->pluck('id');
  807. }
  808. //获取代理Ids
  809. public function getUserIds($search = null)
  810. {
  811. return User::where(function ($query) use ($search) {
  812. $query->where('nickname', 'like', '%' . $search . '%')
  813. ->orwhere('realname', 'like', '%' . $search . '%')
  814. ->orwhere('mobile', $search);
  815. })->pluck('id');
  816. }
  817. //根据物流查询代理信息
  818. public function getReceiveAddressIds($search = null)
  819. {
  820. return Address::where('username', 'like', '%' . $search . '%')
  821. ->orWhere('mobile', $search)
  822. ->pluck('id');
  823. }
  824. //根据省查询代理信息
  825. public function getProvinceIds($search = null)
  826. {
  827. //<<<<<<< HEAD
  828. return Address::where('province', $search)
  829. ->pluck('id');
  830. }
  831. //根据市查询代理信息
  832. public function getCityIds($search = null)
  833. {
  834. if ($search == '北京城区' || $search == '天津城区' || $search == '上海城区') {
  835. $search = '市辖区';
  836. }
  837. return Address::where('city', $search)
  838. //=======
  839. // return Address::where('province',$search )
  840. // ->pluck('id');
  841. // }
  842. //
  843. // //根据省查询代理信息
  844. // public function getCityIds($search = null)
  845. // {
  846. // return Address::where('city', $search )
  847. //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab
  848. ->pluck('id');
  849. }
  850. //<<<<<<< HEAD
  851. //根据区查询代理信息
  852. public function getAreaIds($search = null)
  853. {
  854. return Address::where('town', $search)
  855. //=======
  856. // //根据省查询代理信息
  857. // public function getAreaIds($search = null)
  858. // {
  859. // return Address::where('town', $search )
  860. //>>>>>>> 9aa477479386789a8615d89285e74706ec72fbab
  861. ->pluck('id');
  862. }
  863. public function orderBreakUpCourier(Request $request)
  864. {
  865. ini_set('memory_limit', '1024M');
  866. $input = $request->all();
  867. if ($request->has('provice')) {
  868. $order_no = $input['order_no'];
  869. $start_time = $input['start_time'];
  870. $end_time = $input['end_time'];
  871. $activity_id = $input['activity_id'];
  872. $user_name = $input['user_name'];
  873. $receive_info = $input['receive_info'];
  874. $goods_info = $input['goods_info'];
  875. $province = $input['provice'];
  876. $city = $input['city'];
  877. $town = $input['area'];
  878. if ($request->has('order_status')) {
  879. $order_status = $input['order_status'];
  880. } else {
  881. $order_status = [];
  882. }
  883. if ($request->has('pay_status')) {
  884. $pay_status = $input['pay_status'];
  885. } else {
  886. $pay_status = [];
  887. }
  888. $order_type = $input['order_type'];
  889. $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  890. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  891. // ->join('warea','warea.id','=','users.warea_id')
  892. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  893. ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
  894. ->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'));
  895. $admin = Auth::user();
  896. if ($admin->role_id == 23) {
  897. $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
  898. $data->whereIn('users.warea_id', $warea_ids);
  899. }
  900. if ($order_no) {
  901. $data->where('order_test.order_num', $order_no);
  902. }
  903. if ($start_time && $end_time && empty($activity_id)) {
  904. $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
  905. }
  906. if ($activity_id) {
  907. // $data->where('order_test.activity_id', $activity_id);
  908. $actice=Activity::find($activity_id);
  909. $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]);
  910. }
  911. if ($user_name) {
  912. $user_id = $this->getUserNameIds($user_name);
  913. $data->whereIn('order_test.user_id', $user_id);
  914. }
  915. if ($receive_info) {
  916. $address_ids = $this->getReceiveAddressIds($receive_info);
  917. $data->whereIn('order_test.address_id', $address_ids);
  918. }
  919. if ($province && $province != '省') {
  920. $province_ids = $this->getProvinceIds($province);
  921. $data->whereIn('order_test.address_id', $province_ids);
  922. }
  923. if ($city && $city != '市') {
  924. $city_ids = $this->getCityIds($city);
  925. $data->whereIn('order_test.address_id', $city_ids);
  926. }
  927. if ($town && $town != '区') {
  928. $town_ids = $this->getAreaIds($town);
  929. $data->whereIn('order_test.address_id', $town_ids);
  930. }
  931. //商品信息
  932. if ($goods_info) {
  933. $order_ids = $this->getGoodsOrderIds($goods_info);
  934. $data->whereIn('order_test.id', $order_ids);
  935. }
  936. if ($order_status) {
  937. if (!in_array('-1', $order_status)) {
  938. if (!in_array('5', $order_status)) {
  939. $data->whereIn('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  940. } else {
  941. $data->where('order_test.is_deleted', 1)
  942. ->orWhere(function ($query) use ($order_status) {
  943. $query->where('order_test.is_deleted', 0)
  944. ->whereIn('order_test.status', $order_status);
  945. });
  946. }
  947. }
  948. }
  949. if ($pay_status) {
  950. if (!in_array('-1', $pay_status)) {
  951. $data->whereIn('order_test.pay_status', $pay_status);
  952. }
  953. }
  954. if (in_array($order_type, [0, 1])) {
  955. $data->where('order_test.order_type', $order_type);
  956. }
  957. $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  958. ->orderBy('order_test.id', 'order_detail.id')
  959. ->get()->toArray();
  960. } else {
  961. if ($request->has('id')) {
  962. $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  963. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  964. // ->join('warea','warea.id','=','users.warea_id')
  965. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  966. ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
  967. ->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'))
  968. ->whereIn('order_test.id', $request->id)
  969. ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  970. ->orderBy('order_test.id', 'order_detail.id')
  971. ->get()->toArray();
  972. } else {
  973. if ($request->has('order_no')) {
  974. $order_no = $input['order_no'];
  975. } else {
  976. $order_no = '';
  977. }
  978. $start_time = $input['start_time'] ?? '';
  979. $end_time = $input['end_time'] ?? '';
  980. $activity_id = $input['activity_id'] ?? '';
  981. $search_name = $input['search_name'] ?? '';
  982. if ($request->has('order_status')) {
  983. $order_status = $input['order_status'];
  984. } else {
  985. $order_status = [];
  986. }
  987. $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  988. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  989. // ->join('warea','warea.id','=','users.warea_id')
  990. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  991. ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
  992. ->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'));
  993. $admin = Auth::user();
  994. if ($admin->role_id == 23) {
  995. $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
  996. $data->whereIn('users.warea_id', $warea_ids);
  997. }
  998. if ($order_status || $order_status == 0) {
  999. if ('-1' == $order_status) {
  1000. $data->whereIn('order_test.is_deleted', [0, 1]);
  1001. } elseif ($order_status == 5) {
  1002. $data->where('order_test.is_deleted', 1);
  1003. } elseif ($order_status == 0) {
  1004. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1005. } elseif ($order_status == 1) {
  1006. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1007. } elseif ($order_status == 2) {
  1008. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1009. } elseif ($order_status == 3) {
  1010. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1011. } elseif ($order_status == 4) {
  1012. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1013. } elseif ($order_status == 6) {
  1014. $data->whereIn('order_test.pay_status', [0, 1])->where('order_test.order_test.is_deleted', 0);
  1015. }
  1016. }
  1017. if ($order_no) {
  1018. $data->where('order_test.order_num', $order_no);
  1019. }
  1020. if ($search_name) {
  1021. // $s=substr(trim($search_name),0,4);
  1022. // if($s=='DWBS'){
  1023. // $data->where('order_test.order_num',trim($search_name));
  1024. // }else{
  1025. $ids = $this->getUserIds($search_name);
  1026. $data->whereIn('order_test.user_id', $ids);
  1027. // }
  1028. }
  1029. if ($start_time && $end_time && empty($activity_id)) {
  1030. $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
  1031. }
  1032. if ($activity_id) {
  1033. $actice = Activity::find($activity_id);
  1034. $data->whereBetween('order_test.created_at', [$actice->start_time, $actice->end_time]);
  1035. }
  1036. // $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  1037. $list = $data->groupBy('order_detail.order_id', 'goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size')
  1038. ->orderBy('order_test.id', 'order_detail.id')
  1039. ->get()->toArray();
  1040. }
  1041. }
  1042. $dd = $this->dataGroup($list, 'order_num');
  1043. $d = [];
  1044. foreach ($dd as $key => $val) {
  1045. $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id')
  1046. ->where('order_gift.order_id', $val[0]['id'])
  1047. ->where('order_gift.num', '>', '0')
  1048. ->select('gifts.name', 'order_gift.num')->get();
  1049. $info['u_nickname'] = $val[0]['u_nickname'];
  1050. $info['u_name'] = $val[0]['u_name'];
  1051. $info['u_mobile'] = $val[0]['u_mobile'];
  1052. $info['username'] = $val[0]['username'];
  1053. $info['mobile'] = $val[0]['mobile'];
  1054. $info['address'] = $val[0]['address'];
  1055. $info['province'] = $val[0]['province'];
  1056. $info['city'] = $val[0]['city'];
  1057. $info['town'] = $val[0]['town'];
  1058. if ($val[0]['good_user_id']){
  1059. $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first();
  1060. $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')';
  1061. }else{
  1062. $info['belong']='';
  1063. }
  1064. $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name');
  1065. $info['admin_name'] =$admin_name;
  1066. $info['created_at'] = $val[0]['created_at'];
  1067. // $info['remark'] = (string)$val[0]['remark'];
  1068. $info['remark'] = $this->getOrderRemark($val[0]['id']);
  1069. $d[$key]['data'] = $info;
  1070. $d[$key]['精装'] = [];
  1071. $d[$key]['普通'] = [];
  1072. $d[$key]['精装混合'] = [];
  1073. $d[$key]['普通混合'] = [];
  1074. $x1 = 0;
  1075. $y1 = [];//精装
  1076. $x = 0;
  1077. $y = [];//普通
  1078. foreach ($val as $k => $v) {
  1079. if ($v['main_attr'] == '大卫博士精装版') {
  1080. $main_attr = '精';
  1081. $n = floor($v['total'] / 10);
  1082. for ($i = 0; $i < $n; $i++) {
  1083. $cc = [];
  1084. $cc['main_attr'] = $main_attr;
  1085. $cc['sec_attr'] = $v['sec_attr'];
  1086. $cc['size'] = $v['size'];
  1087. $cc['num'] = 10;
  1088. array_push($d[$key]['精装'], $cc);
  1089. }
  1090. if ($v['total'] % 10 > 0) {
  1091. $t1 = $v['total'] % 10;
  1092. if ($x1 + $t1 >= 10) {
  1093. $x1 = $x1 + $t1 - 10;
  1094. $z1['main_attr'] = $main_attr;
  1095. $z1['sec_attr'] = $v['sec_attr'];
  1096. $z1['size'] = $v['size'];
  1097. $z1['num'] = $t1 - $x1;
  1098. if ($y1) {
  1099. array_pop($d[$key]['精装混合']);
  1100. }
  1101. array_push($y1, $z1);
  1102. $z1 = [];
  1103. array_push($d[$key]['精装混合'], $y1);
  1104. $y1 = [];
  1105. if ($x1 > 0) {
  1106. $z1['main_attr'] = $main_attr;
  1107. $z1['sec_attr'] = $v['sec_attr'];
  1108. $z1['size'] = $v['size'];
  1109. $z1['num'] = $x1;
  1110. array_push($y1, $z1);
  1111. array_push($d[$key]['精装混合'], $y1);
  1112. }
  1113. } else {
  1114. $x1 += $t1;
  1115. $z1['main_attr'] = $main_attr;
  1116. $z1['sec_attr'] = $v['sec_attr'];
  1117. $z1['size'] = $v['size'];
  1118. $z1['num'] = $v['total'] % 10;
  1119. if ($y1) {
  1120. array_pop($d[$key]['精装混合']);
  1121. }
  1122. array_push($y1, $z1);
  1123. array_push($d[$key]['精装混合'], $y1);
  1124. }
  1125. }
  1126. } else {
  1127. $n = floor($v['total'] / 6);
  1128. if ($v['main_attr'] == '大卫博士老人版') {
  1129. $main_attr = '老';
  1130. } elseif ($v['main_attr'] == '大卫博士简约版') {
  1131. $main_attr = '简';
  1132. } else {
  1133. $main_attr = '棉';
  1134. }
  1135. for ($i = 0; $i < $n; $i++) {
  1136. $cc = [];
  1137. $cc['main_attr'] = $main_attr;
  1138. $cc['sec_attr'] = $v['sec_attr'];
  1139. $cc['size'] = $v['size'];
  1140. $cc['num'] = 6;
  1141. array_push($d[$key]['普通'], $cc);
  1142. }
  1143. if ($v['total'] % 6 > 0) {
  1144. $t = $v['total'] % 6;
  1145. if ($x + $t >= 6) {
  1146. $x = $x + $t - 6;
  1147. $z['main_attr'] = $main_attr;
  1148. $z['sec_attr'] = $v['sec_attr'];
  1149. $z['size'] = $v['size'];
  1150. $z['num'] = $t - $x;
  1151. if ($y) {
  1152. array_pop($d[$key]['普通混合']);
  1153. }
  1154. array_push($y, $z);
  1155. $z = [];
  1156. array_push($d[$key]['普通混合'], $y);
  1157. $y = [];
  1158. if ($x > 0) {
  1159. $z['main_attr'] = $main_attr;
  1160. $z['sec_attr'] = $v['sec_attr'];
  1161. $z['size'] = $v['size'];
  1162. $z['num'] = $x;
  1163. array_push($y, $z);
  1164. array_push($d[$key]['普通混合'], $y);
  1165. }
  1166. } else {
  1167. $x += $t;
  1168. $z['main_attr'] = $main_attr;
  1169. $z['sec_attr'] = $v['sec_attr'];
  1170. $z['size'] = $v['size'];
  1171. $z['num'] = $v['total'] % 6;
  1172. if ($y) {
  1173. array_pop($d[$key]['普通混合']);
  1174. }
  1175. array_push($y, $z);
  1176. array_push($d[$key]['普通混合'], $y);
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. return $this->success($d);
  1183. }
  1184. public function orderStoreBreakUpCourier(Request $request)
  1185. {
  1186. ini_set('memory_limit', '1024M');
  1187. $input = $request->all();
  1188. if (!$request->has('id')) {
  1189. $page_index = $input['page_index'];
  1190. $page_size = $input['page_size'];
  1191. $num = ($page_index - 1) * $page_size;
  1192. $order_no = $input['order_no'];
  1193. $start_time = $input['start_time'];
  1194. $end_time = $input['end_time'];
  1195. $search_name = $input['search_name'];
  1196. $activity_id = $input['activity_id'];
  1197. $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  1198. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  1199. // ->join('warea','warea.id','=','users.warea_id')
  1200. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  1201. ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
  1202. ->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'));
  1203. $admin = Auth::user();
  1204. if ($admin->role_id == 23) {
  1205. $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
  1206. $data->whereIn('users.warea_id', $warea_ids);
  1207. }
  1208. if ($order_no) {
  1209. $data->where('order_test.order_num', 'like','%'.$order_no.'%');
  1210. }
  1211. if ($search_name){
  1212. $ids=$this->getUserIds($search_name);
  1213. $data->whereIn('order_test.user_id', $ids);
  1214. }
  1215. if ($start_time && $end_time && empty($activity_id)) {
  1216. $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
  1217. }
  1218. if($activity_id){
  1219. $actice=Activity::find($activity_id);
  1220. $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]);
  1221. }
  1222. if ($request->store_id){
  1223. $data->where('order_test.store_id',$request->store_id);
  1224. }
  1225. $data->whereNotNull('order_test.store_id');
  1226. $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  1227. ->orderBy('order_test.id', 'order_detail.id')
  1228. ->get()->toArray();
  1229. } else {
  1230. $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  1231. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  1232. // ->join('warea','warea.id','=','users.warea_id')
  1233. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  1234. ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
  1235. ->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'))
  1236. ->whereIn('order_test.id', $request->id)
  1237. ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  1238. ->orderBy('order_test.id', 'order_detail.id')
  1239. ->get()->toArray();
  1240. }
  1241. $dd = $this->dataGroup($list, 'order_num');
  1242. $d = [];
  1243. foreach ($dd as $key => $val) {
  1244. $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id')
  1245. ->where('order_gift.order_id', $val[0]['id'])
  1246. ->where('order_gift.num', '>', '0')
  1247. ->select('gifts.name', 'order_gift.num')->get();
  1248. $info['u_nickname'] = $val[0]['u_nickname'];
  1249. $info['u_name'] = $val[0]['u_name'];
  1250. $info['u_mobile'] = $val[0]['u_mobile'];
  1251. $info['username'] = $val[0]['username'];
  1252. $info['mobile'] = $val[0]['mobile'];
  1253. $info['address'] = $val[0]['address'];
  1254. $info['province'] = $val[0]['province'];
  1255. $info['city'] = $val[0]['city'];
  1256. $info['town'] = $val[0]['town'];
  1257. $info['get_store'] =Store::where('id',$val[0]['store_id'])->select('name')->first();
  1258. if ($val[0]['good_user_id']){
  1259. $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first();
  1260. $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')';
  1261. }else{
  1262. $info['belong']='';
  1263. }
  1264. $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name');
  1265. $info['admin_name'] =$admin_name;
  1266. $info['created_at'] = $val[0]['created_at'];
  1267. // $info['remark'] = (string)$val[0]['remark'];
  1268. $info['remark'] = $this->getOrderRemark($val[0]['id']);
  1269. $d[$key]['data'] = $info;
  1270. $d[$key]['精装'] = [];
  1271. $d[$key]['普通'] = [];
  1272. $d[$key]['精装混合'] = [];
  1273. $d[$key]['普通混合'] = [];
  1274. $x1 = 0;
  1275. $y1 = [];//精装
  1276. $x = 0;
  1277. $y = [];//普通
  1278. foreach ($val as $k => $v) {
  1279. if ($v['main_attr'] == '大卫博士精装版') {
  1280. $main_attr = '精';
  1281. $n = floor($v['total'] / 10);
  1282. for ($i = 0; $i < $n; $i++) {
  1283. $cc = [];
  1284. $cc['main_attr'] = $main_attr;
  1285. $cc['sec_attr'] = $v['sec_attr'];
  1286. $cc['size'] = $v['size'];
  1287. $cc['num'] = 10;
  1288. array_push($d[$key]['精装'], $cc);
  1289. }
  1290. if ($v['total'] % 10 > 0) {
  1291. $t1 = $v['total'] % 10;
  1292. if ($x1 + $t1 >= 10) {
  1293. $x1 = $x1 + $t1 - 10;
  1294. $z1['main_attr'] = $main_attr;
  1295. $z1['sec_attr'] = $v['sec_attr'];
  1296. $z1['size'] = $v['size'];
  1297. $z1['num'] = $t1 - $x1;
  1298. if ($y1) {
  1299. array_pop($d[$key]['精装混合']);
  1300. }
  1301. array_push($y1, $z1);
  1302. $z1 = [];
  1303. array_push($d[$key]['精装混合'], $y1);
  1304. $y1 = [];
  1305. if ($x1 > 0) {
  1306. $z1['main_attr'] = $main_attr;
  1307. $z1['sec_attr'] = $v['sec_attr'];
  1308. $z1['size'] = $v['size'];
  1309. $z1['num'] = $x1;
  1310. array_push($y1, $z1);
  1311. array_push($d[$key]['精装混合'], $y1);
  1312. }
  1313. } else {
  1314. $x1 += $t1;
  1315. $z1['main_attr'] = $main_attr;
  1316. $z1['sec_attr'] = $v['sec_attr'];
  1317. $z1['size'] = $v['size'];
  1318. $z1['num'] = $v['total'] % 10;
  1319. if ($y1) {
  1320. array_pop($d[$key]['精装混合']);
  1321. }
  1322. array_push($y1, $z1);
  1323. array_push($d[$key]['精装混合'], $y1);
  1324. }
  1325. }
  1326. } else {
  1327. $n = floor($v['total'] / 6);
  1328. if ($v['main_attr'] == '大卫博士老人版') {
  1329. $main_attr = '老';
  1330. } elseif ($v['main_attr'] == '大卫博士简约版') {
  1331. $main_attr = '简';
  1332. } else {
  1333. $main_attr = '棉';
  1334. }
  1335. for ($i = 0; $i < $n; $i++) {
  1336. $cc = [];
  1337. $cc['main_attr'] = $main_attr;
  1338. $cc['sec_attr'] = $v['sec_attr'];
  1339. $cc['size'] = $v['size'];
  1340. $cc['num'] = 6;
  1341. array_push($d[$key]['普通'], $cc);
  1342. }
  1343. if ($v['total'] % 6 > 0) {
  1344. $t = $v['total'] % 6;
  1345. if ($x + $t >= 6) {
  1346. $x = $x + $t - 6;
  1347. $z['main_attr'] = $main_attr;
  1348. $z['sec_attr'] = $v['sec_attr'];
  1349. $z['size'] = $v['size'];
  1350. $z['num'] = $t - $x;
  1351. if ($y) {
  1352. array_pop($d[$key]['普通混合']);
  1353. }
  1354. array_push($y, $z);
  1355. $z = [];
  1356. array_push($d[$key]['普通混合'], $y);
  1357. $y = [];
  1358. if ($x > 0) {
  1359. $z['main_attr'] = $main_attr;
  1360. $z['sec_attr'] = $v['sec_attr'];
  1361. $z['size'] = $v['size'];
  1362. $z['num'] = $x;
  1363. array_push($y, $z);
  1364. array_push($d[$key]['普通混合'], $y);
  1365. }
  1366. } else {
  1367. $x += $t;
  1368. $z['main_attr'] = $main_attr;
  1369. $z['sec_attr'] = $v['sec_attr'];
  1370. $z['size'] = $v['size'];
  1371. $z['num'] = $v['total'] % 6;
  1372. if ($y) {
  1373. array_pop($d[$key]['普通混合']);
  1374. }
  1375. array_push($y, $z);
  1376. array_push($d[$key]['普通混合'], $y);
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. return $this->success($d);
  1383. }
  1384. //<<<<<<< HEAD
  1385. //订单拆分快递单
  1386. public function orderBreakUpCouriers(Request $request)
  1387. {
  1388. ini_set('memory_limit', '1024M');
  1389. $input = $request->all();
  1390. if ($request->has('provice')) {
  1391. $order_no = $input['order_no'];
  1392. $start_time = $input['start_time'];
  1393. $end_time = $input['end_time'];
  1394. $activity_id = $input['activity_id'];
  1395. $user_name = $input['user_name'];
  1396. $receive_info = $input['receive_info'];
  1397. $goods_info = $input['goods_info'];
  1398. $province = $input['provice'];
  1399. $city = $input['city'];
  1400. $town = $input['area'];
  1401. if ($request->has('order_status')) {
  1402. $order_status = $input['order_status'];
  1403. } else {
  1404. $order_status = [];
  1405. }
  1406. if ($request->has('pay_status')) {
  1407. $pay_status = $input['pay_status'];
  1408. } else {
  1409. $pay_status = [];
  1410. }
  1411. $order_type = $input['order_type'];
  1412. $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  1413. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  1414. // ->join('warea','warea.id','=','users.warea_id')
  1415. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  1416. ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
  1417. ->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'));
  1418. $admin = Auth::user();
  1419. if ($admin->role_id == 23) {
  1420. $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
  1421. $data->whereIn('users.warea_id', $warea_ids);
  1422. }
  1423. if ($order_no) {
  1424. $data->where('order_test.order_num', $order_no);
  1425. }
  1426. if ($start_time && $end_time && empty($activity_id)) {
  1427. $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
  1428. }
  1429. if ($activity_id) {
  1430. // $data->where('order_test.activity_id', $activity_id);
  1431. $actice=Activity::find($activity_id);
  1432. $data->whereBetween('order_test.created_at',[$actice->start_time,$actice->end_time]);
  1433. }
  1434. if ($user_name) {
  1435. $user_id = $this->getUserNameIds($user_name);
  1436. $data->whereIn('order_test.user_id', $user_id);
  1437. }
  1438. if ($receive_info) {
  1439. $address_ids = $this->getReceiveAddressIds($receive_info);
  1440. $data->whereIn('order_test.address_id', $address_ids);
  1441. }
  1442. if ($province && $province != '省') {
  1443. $province_ids = $this->getProvinceIds($province);
  1444. $data->whereIn('order_test.address_id', $province_ids);
  1445. }
  1446. if ($city && $city != '市') {
  1447. $city_ids = $this->getCityIds($city);
  1448. $data->whereIn('order_test.address_id', $city_ids);
  1449. }
  1450. if ($town && $town != '区') {
  1451. $town_ids = $this->getAreaIds($town);
  1452. $data->whereIn('order_test.address_id', $town_ids);
  1453. }
  1454. //商品信息
  1455. if ($goods_info) {
  1456. $order_ids = $this->getGoodsOrderIds($goods_info);
  1457. $data->whereIn('order_test.id', $order_ids);
  1458. }
  1459. if ($order_status) {
  1460. if (!in_array('-1', $order_status)) {
  1461. if (!in_array('5', $order_status)) {
  1462. $data->whereIn('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1463. } else {
  1464. $data->where('order_test.is_deleted', 1)
  1465. ->orWhere(function ($query) use ($order_status) {
  1466. $query->where('order_test.is_deleted', 0)
  1467. ->whereIn('order_test.status', $order_status);
  1468. });
  1469. }
  1470. }
  1471. }
  1472. if ($pay_status) {
  1473. if (!in_array('-1', $pay_status)) {
  1474. $data->whereIn('order_test.pay_status', $pay_status);
  1475. }
  1476. }
  1477. if (in_array($order_type, [0, 1])) {
  1478. $data->where('order_test.order_type', $order_type);
  1479. }
  1480. $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  1481. ->orderBy('order_test.id', 'order_detail.id')
  1482. ->get()->toArray();
  1483. } else {
  1484. if ($request->has('id')) {
  1485. $list = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  1486. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  1487. // ->join('warea','warea.id','=','users.warea_id')
  1488. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  1489. ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
  1490. ->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'))
  1491. ->whereIn('order_test.id', $request->id)
  1492. ->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  1493. ->orderBy('order_test.id', 'order_detail.id')
  1494. ->get()->toArray();
  1495. } else {
  1496. if ($request->has('order_no')) {
  1497. $order_no = $input['order_no'];
  1498. } else {
  1499. $order_no = '';
  1500. }
  1501. $start_time = $input['start_time'] ?? '';
  1502. $end_time = $input['end_time'] ?? '';
  1503. $activity_id = $input['activity_id'] ?? '';
  1504. $search_name = $input['search_name'] ?? '';
  1505. if ($request->has('order_status')) {
  1506. $order_status = $input['order_status'];
  1507. } else {
  1508. $order_status = [];
  1509. }
  1510. $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  1511. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  1512. // ->join('warea','warea.id','=','users.warea_id')
  1513. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  1514. ->leftJoin('address', 'address.id', '=', 'order_test.address_id')
  1515. ->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'));
  1516. $admin = Auth::user();
  1517. if ($admin->role_id == 23) {
  1518. $warea_ids = Warea::where('admin_id', $admin->id)->pluck('id');
  1519. $data->whereIn('users.warea_id', $warea_ids);
  1520. }
  1521. if ($order_status || $order_status == 0) {
  1522. if ('-1' == $order_status) {
  1523. $data->whereIn('order_test.is_deleted', [0, 1]);
  1524. } elseif ($order_status == 5) {
  1525. $data->where('order_test.is_deleted', 1);
  1526. } elseif ($order_status == 0) {
  1527. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1528. } elseif ($order_status == 1) {
  1529. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1530. } elseif ($order_status == 2) {
  1531. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1532. } elseif ($order_status == 3) {
  1533. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1534. } elseif ($order_status == 4) {
  1535. $data->where('order_test.status', $order_status)->where('order_test.is_deleted', 0);
  1536. } elseif ($order_status == 6) {
  1537. $data->whereIn('order_test.pay_status', [0, 1])->where('order_test.order_test.is_deleted', 0);
  1538. }
  1539. }
  1540. if ($order_no) {
  1541. $data->where('order_test.order_num', $order_no);
  1542. }
  1543. if ($search_name) {
  1544. // $s=substr(trim($search_name),0,4);
  1545. // if($s=='DWBS'){
  1546. // $data->where('order_test.order_num',trim($search_name));
  1547. // }else{
  1548. $ids = $this->getUserIds($search_name);
  1549. $data->whereIn('order_test.user_id', $ids);
  1550. // }
  1551. }
  1552. if ($start_time && $end_time && empty($activity_id)) {
  1553. $data->whereBetween('order_test.created_at', [$start_time, $end_time]);
  1554. }
  1555. if ($activity_id) {
  1556. $actice = Activity::find($activity_id);
  1557. $data->whereBetween('order_test.created_at', [$actice->start_time, $actice->end_time]);
  1558. }
  1559. $list = $data->groupBy('order_detail.order_id', 'goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  1560. ->orderBy('order_test.id', 'order_detail.id')
  1561. ->get()->toArray();
  1562. }
  1563. }
  1564. $dd = $this->dataGroup($list, 'order_num');
  1565. $d = [];
  1566. foreach ($dd as $key => $val) {
  1567. // if($key==0){
  1568. // return $val;
  1569. // }
  1570. $info['gift'] = OrderGift::leftJoin('gifts', 'order_gift.gift_id', '=', 'gifts.id')
  1571. ->where('order_gift.order_id', $val[0]['id'])
  1572. ->where('order_gift.num', '>', '0')
  1573. ->select('gifts.name', 'order_gift.num')->get();
  1574. $info['u_nickname'] = $val[0]['u_nickname'];
  1575. $info['u_name'] = $val[0]['u_name'];
  1576. $info['u_mobile'] = $val[0]['u_mobile'];
  1577. $info['username'] = $val[0]['username'];
  1578. $info['mobile'] = $val[0]['mobile'];
  1579. $info['address'] = $val[0]['address'];
  1580. $info['province'] = $val[0]['province'];
  1581. $info['city'] = $val[0]['city'];
  1582. $info['town'] = $val[0]['town'];
  1583. if ($val[0]['good_user_id']){
  1584. $gooduser=User::where('id',$val[0]['good_user_id'])->select('mobile','nickname')->first();
  1585. $info['belong']='('.$gooduser->nickname.','.$gooduser->mobile.')';
  1586. }else{
  1587. $info['belong']='';
  1588. }
  1589. $admin_name=Warea::where('id',$val[0]['warea_id'])->value('admin_name');
  1590. $info['admin_name'] =$admin_name;
  1591. $info['created_at'] = $val[0]['created_at'];
  1592. // $info['remark'] = (string)$val[0]['remark'];
  1593. $info['remark'] = $this->getOrderRemark($val[0]['id']);
  1594. $d[$key]['data'] = $info;
  1595. $d[$key]['精装'] = [];
  1596. $d[$key]['老'] = [];
  1597. $d[$key]['简'] = [];
  1598. $d[$key]['棉老'] = [];
  1599. $d[$key]['普通'] = [];
  1600. $d[$key]['精装混合'] = [];
  1601. $d[$key]['老混'] = [];
  1602. $d[$key]['简混'] = [];
  1603. $d[$key]['棉老混'] = [];
  1604. $d[$key]['普通混'] = [];
  1605. $x1 = 0;
  1606. $y1 = [];//精装
  1607. $x2 = 0;
  1608. $y2 = [];//老
  1609. $x3 = 0;
  1610. $y3 = [];//老
  1611. $x4 = 0;
  1612. $y4 = [];//老
  1613. $x = 0;
  1614. $y = [];//普通
  1615. foreach ($val as $k => $v) {
  1616. if ($v['main_attr'] == '大卫博士精装版') {
  1617. $main_attr = '精';
  1618. $n = floor($v['total'] / 10);
  1619. for ($i = 0; $i < $n; $i++) {
  1620. $cc = [];
  1621. $cc['main_attr'] = $main_attr;
  1622. $cc['sec_attr'] = $v['sec_attr'];
  1623. $cc['size'] = $v['size'];
  1624. $cc['num'] = 10;
  1625. array_push($d[$key]['精装'], $cc);
  1626. }
  1627. if ($v['total'] % 10 > 0) {
  1628. $t1 = $v['total'] % 10;
  1629. if ($x1 + $t1 >= 10) {
  1630. $x1 = $x1 + $t1 - 10;
  1631. $z1['main_attr'] = $main_attr;
  1632. $z1['sec_attr'] = $v['sec_attr'];
  1633. $z1['size'] = $v['size'];
  1634. $z1['num'] = $t1 - $x1;
  1635. if ($y1) {
  1636. array_pop($d[$key]['精装混合']);
  1637. }
  1638. array_push($y1, $z1);
  1639. $z1 = [];
  1640. array_push($d[$key]['精装混合'], $y1);
  1641. $y1 = [];
  1642. if ($x1 > 0) {
  1643. $z1['main_attr'] = $main_attr;
  1644. $z1['sec_attr'] = $v['sec_attr'];
  1645. $z1['size'] = $v['size'];
  1646. $z1['num'] = $x1;
  1647. array_push($y1, $z1);
  1648. array_push($d[$key]['精装混合'], $y1);
  1649. }
  1650. } else {
  1651. $x1 += $t1;
  1652. $z1['main_attr'] = $main_attr;
  1653. $z1['sec_attr'] = $v['sec_attr'];
  1654. $z1['size'] = $v['size'];
  1655. $z1['num'] = $v['total'] % 10;
  1656. if ($y1) {
  1657. array_pop($d[$key]['精装混合']);
  1658. }
  1659. array_push($y1, $z1);
  1660. array_push($d[$key]['精装混合'], $y1);
  1661. }
  1662. }
  1663. } else {
  1664. $n = floor($v['total'] / 6);
  1665. if ($v['main_attr'] == '大卫博士老人版') {
  1666. $main_attr = '老';
  1667. for ($i = 0; $i < $n; $i++) {
  1668. $cc = [];
  1669. $cc['main_attr'] = $main_attr;
  1670. $cc['sec_attr'] = $v['sec_attr'];
  1671. $cc['size'] = $v['size'];
  1672. $cc['num'] = 6;
  1673. array_push($d[$key]['老'], $cc);
  1674. }
  1675. if ($v['total'] % 6 > 0) {
  1676. $t2 = $v['total'] % 6;
  1677. if ($x2 + $t2 >= 6) {
  1678. $x2 = $x2 + $t2 - 6;
  1679. $z2['main_attr'] = $main_attr;
  1680. $z2['sec_attr'] = $v['sec_attr'];
  1681. $z2['size'] = $v['size'];
  1682. $z2['num'] = $t2 - $x2;
  1683. if ($y2) {
  1684. array_pop($d[$key]['老混']);
  1685. }
  1686. array_push($y2, $z2);
  1687. $z2 = [];
  1688. array_push($d[$key]['老混'], $y2);
  1689. $y2 = [];
  1690. if ($x2 > 0) {
  1691. $z2['main_attr'] = $main_attr;
  1692. $z2['sec_attr'] = $v['sec_attr'];
  1693. $z2['size'] = $v['size'];
  1694. $z2['num'] = $x2;
  1695. array_push($y2, $z2);
  1696. array_push($d[$key]['老混'], $y2);
  1697. }
  1698. } else {
  1699. $x2 += $t2;
  1700. $z2['main_attr'] = $main_attr;
  1701. $z2['sec_attr'] = $v['sec_attr'];
  1702. $z2['size'] = $v['size'];
  1703. $z2['num'] = $v['total'] % 6;
  1704. if ($y2) {
  1705. array_pop($d[$key]['老混']);
  1706. }
  1707. array_push($y2, $z2);
  1708. array_push($d[$key]['老混'], $y2);
  1709. }
  1710. }
  1711. } elseif ($v['main_attr'] == '大卫博士简约版') {
  1712. $main_attr = '简';
  1713. for ($i = 0; $i < $n; $i++) {
  1714. $cc = [];
  1715. $cc['main_attr'] = $main_attr;
  1716. $cc['sec_attr'] = $v['sec_attr'];
  1717. $cc['size'] = $v['size'];
  1718. $cc['num'] = 6;
  1719. array_push($d[$key]['简'], $cc);
  1720. }
  1721. if ($v['total'] % 6 > 0) {
  1722. $t3 = $v['total'] % 6;
  1723. if ($x3 + $t3 >= 6) {
  1724. $x3 = $x3 + $t3 - 6;
  1725. $z3['main_attr'] = $main_attr;
  1726. $z3['sec_attr'] = $v['sec_attr'];
  1727. $z3['size'] = $v['size'];
  1728. $z3['num'] = $t3 - $x3;
  1729. if ($y3) {
  1730. array_pop($d[$key]['简混']);
  1731. }
  1732. array_push($y3, $z3);
  1733. $z3 = [];
  1734. array_push($d[$key]['简混'], $y3);
  1735. $y3 = [];
  1736. if ($x3 > 0) {
  1737. $z3['main_attr'] = $main_attr;
  1738. $z3['sec_attr'] = $v['sec_attr'];
  1739. $z3['size'] = $v['size'];
  1740. $z3['num'] = $x3;
  1741. array_push($y3, $z3);
  1742. array_push($d[$key]['简混'], $y3);
  1743. }
  1744. } else {
  1745. $x3 += $t3;
  1746. $z3['main_attr'] = $main_attr;
  1747. $z3['sec_attr'] = $v['sec_attr'];
  1748. $z3['size'] = $v['size'];
  1749. $z3['num'] = $v['total'] % 6;
  1750. if ($y3) {
  1751. array_pop($d[$key]['简混']);
  1752. }
  1753. array_push($y3, $z3);
  1754. array_push($d[$key]['简混'], $y3);
  1755. }
  1756. }
  1757. } else {
  1758. $main_attr = '棉老';
  1759. for ($i = 0; $i < $n; $i++) {
  1760. $cc = [];
  1761. $cc['main_attr'] = $main_attr;
  1762. $cc['sec_attr'] = $v['sec_attr'];
  1763. $cc['size'] = $v['size'];
  1764. $cc['num'] = 6;
  1765. array_push($d[$key]['棉老'], $cc);
  1766. }
  1767. if ($v['total'] % 6 > 0) {
  1768. $t4 = $v['total'] % 6;
  1769. if ($x4 + $t4 >= 6) {
  1770. $x4 = $x4 + $t4 - 6;
  1771. $z4['main_attr'] = $main_attr;
  1772. $z4['sec_attr'] = $v['sec_attr'];
  1773. $z4['size'] = $v['size'];
  1774. $z4['num'] = $t4 - $x4;
  1775. if ($y4) {
  1776. array_pop($d[$key]['棉老混']);
  1777. }
  1778. array_push($y4, $z4);
  1779. $z4 = [];
  1780. array_push($d[$key]['棉老混'], $y4);
  1781. $y4 = [];
  1782. if ($x4 > 0) {
  1783. $z4['main_attr'] = $main_attr;
  1784. $z4['sec_attr'] = $v['sec_attr'];
  1785. $z4['size'] = $v['size'];
  1786. $z4['num'] = $x4;
  1787. array_push($y4, $z4);
  1788. array_push($d[$key]['棉老混'], $y4);
  1789. }
  1790. } else {
  1791. $x4 += $t4;
  1792. $z4['main_attr'] = $main_attr;
  1793. $z4['sec_attr'] = $v['sec_attr'];
  1794. $z4['size'] = $v['size'];
  1795. $z4['num'] = $v['total'] % 6;
  1796. if ($y4) {
  1797. array_pop($d[$key]['棉老混']);
  1798. }
  1799. array_push($y4, $z4);
  1800. array_push($d[$key]['棉老混'], $y4);
  1801. }
  1802. }
  1803. }
  1804. }
  1805. }
  1806. $nb=0;
  1807. $nd=[];
  1808. if(count($y2)>0){
  1809. foreach($y2 as $k=>$v){
  1810. $nb+=$v['num'];
  1811. array_push($nd, $v);
  1812. }
  1813. array_pop($d[$key]['老混']);
  1814. }
  1815. if(count($y3)>0){
  1816. foreach($y3 as $k=>$v){
  1817. $nb+=$v['num'];
  1818. if($nb>6){
  1819. $m=$v;
  1820. $m['num']=$v['num']-($nb-6);
  1821. array_push($nd, $m);
  1822. array_push($d[$key]['普通混'],$nd);
  1823. $nd=[];
  1824. $nb=$nb-6;
  1825. $l=$v;
  1826. $l['num']=$nb;
  1827. array_push($nd, $l);
  1828. }elseif($nb==6){
  1829. array_push($nd, $v);
  1830. array_push($d[$key]['普通混'],$nd);
  1831. $nd=[];
  1832. $nb=0;
  1833. }else{
  1834. array_push($nd, $v);
  1835. }
  1836. }
  1837. array_pop($d[$key]['简混']);
  1838. }
  1839. if(count($y4)>0){
  1840. foreach($y4 as $k=>$v){
  1841. $nb+=$v['num'];
  1842. if($nb>6){
  1843. $m=$v;
  1844. $m['num']=$v['num']-($nb-6);
  1845. array_push($nd, $m);
  1846. array_push($d[$key]['普通混'],$nd);
  1847. $nd=[];
  1848. $nb=$nb-6;
  1849. $l=$v;
  1850. $l['num']=$nb;
  1851. array_push($nd, $l);
  1852. }elseif($nb==6){
  1853. array_push($nd, $v);
  1854. array_push($d[$key]['普通混'],$nd);
  1855. $nd=[];
  1856. $nb=0;
  1857. }else{
  1858. array_push($nd, $v);
  1859. }
  1860. }
  1861. array_pop($d[$key]['棉老混']);
  1862. }
  1863. if(count($nd)>0){
  1864. array_push($d[$key]['普通混'],$nd);
  1865. }
  1866. }
  1867. return $this->success($d);
  1868. }
  1869. public function getMergerOrder(Request $request){
  1870. //<<<<<<< HEAD
  1871. //<<<<<<< HEAD
  1872. // $input=$request->all();
  1873. // $page_index=$input['page_index'];
  1874. // $page_size=$input['page_size'];
  1875. // $num=$page_size*($page_index-1);
  1876. // $activity_id=$input['activity_id'];
  1877. // $search_name=$input['search_name'];
  1878. // $activity=Activity::where('id',$activity_id)->first();
  1879. // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  1880. // ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  1881. // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  1882. // ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
  1883. // if($search_name){
  1884. // $address_ids=Address::where(function($query) use ($search_name){
  1885. // $query->where('username','like','%'.$search_name.'%')
  1886. // ->orWhere('mobile',$search_name);
  1887. // })->pluck('id');
  1888. // $data->whereIn('order_test.address_id',$address_ids);
  1889. // }
  1890. // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
  1891. // ->where('order_test.is_deleted',0)
  1892. // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
  1893. // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
  1894. // 'goods_test.unit',DB::raw('SUM(order_detail.num) as total'))
  1895. // ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit')
  1896. // ->orderBy('order_test.created_at')
  1897. // ->get();
  1898. // $array=[];
  1899. // foreach($list as $key => $val){
  1900. // $keys=$val->address_id.'-'.$val->u_id;
  1901. // $array[$keys]['name']=$val->username;
  1902. // $array[$keys]['mobile']=$val->mobile;
  1903. // $array[$keys]['address']=$val->address;
  1904. // $array[$keys]['address_id']=$val->address_id;
  1905. // $array[$keys]['user_id']=$val->u_id;
  1906. // $array[$keys]['province']=$val->province;
  1907. // $array[$keys]['city']=$val->city;
  1908. // $array[$keys]['town']=$val->town;
  1909. // $array[$keys]['u_nickname']=$val->u_nickname;
  1910. // $array[$keys]['u_mobile']=$val->u_mobile;
  1911. // $array[$keys]['u_name']=$val->u_name;
  1912. //
  1913. // if($val->unit=='套'){
  1914. // if(empty($array[$keys]['num'])){
  1915. // $array[$keys]['num']=$val->total;
  1916. // }else{
  1917. // $array[$keys]['num']+=$val->total;
  1918. // }
  1919. // }elseif($val->unit=='件'){
  1920. // if(empty($array[$keys]['num'])){
  1921. // $array[$keys]['num']=$val->total*2;
  1922. // }else{
  1923. // $array[$keys]['num']+=$val->total*2;
  1924. //=======
  1925. // $input=$request->all();
  1926. // $page_index=$input['page_index'];
  1927. // $page_size=$input['page_size'];
  1928. // $num=$page_size*($page_index-1);
  1929. // $activity_id=$input['activity_id'];
  1930. // $search_name=$input['search_name'];
  1931. // $activity=Activity::where('id',$activity_id)->first();
  1932. // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  1933. // ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  1934. // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  1935. // ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
  1936. // if($search_name){
  1937. // $address_ids=Address::where(function($query) use ($search_name){
  1938. // $query->where('username','like','%'.$search_name.'%')
  1939. // ->orWhere('mobile',$search_name);
  1940. // })->pluck('id');
  1941. // $data->whereIn('order_test.address_id',$address_ids);
  1942. // }
  1943. // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
  1944. // ->where('order_test.is_deleted',0)
  1945. // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
  1946. // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
  1947. // 'goods_test.unit',DB::raw('SUM(order_detail.num) as total'))
  1948. // ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit')
  1949. // ->orderBy('order_test.created_at')
  1950. // ->get();
  1951. // $array=[];
  1952. // foreach($list as $key => $val){
  1953. // $keys=$val->address_id.'-'.$val->u_id;
  1954. // $array[$keys]['name']=$val->username;
  1955. // $array[$keys]['mobile']=$val->mobile;
  1956. // $array[$keys]['address']=$val->address;
  1957. // $array[$keys]['address_id']=$val->address_id;
  1958. // $array[$keys]['user_id']=$val->u_id;
  1959. // $array[$keys]['province']=$val->province;
  1960. // $array[$keys]['city']=$val->city;
  1961. // $array[$keys]['town']=$val->town;
  1962. // $array[$keys]['u_nickname']=$val->u_nickname;
  1963. // $array[$keys]['u_mobile']=$val->u_mobile;
  1964. // $array[$keys]['u_name']=$val->u_name;
  1965. //
  1966. // if($val->unit=='套'){
  1967. // if(empty($array[$keys]['num'])){
  1968. // $array[$keys]['num']=$val->total;
  1969. // }else{
  1970. // $array[$keys]['num']+=$val->total;
  1971. // }
  1972. // }elseif($val->unit=='件'){
  1973. // if(empty($array[$keys]['num'])){
  1974. // $array[$keys]['num']=$val->total*2;
  1975. // }else{
  1976. // $array[$keys]['num']+=$val->total*2;
  1977. // }
  1978. //>>>>>>> 78008612722779b2a4d161ea6cec9067c149b72e
  1979. //=======
  1980. ini_set('memory_limit', '1024M');
  1981. $input=$request->all();
  1982. $page_index=$input['page_index'];
  1983. $page_size=$input['page_size'];
  1984. $num=$page_size*($page_index-1);
  1985. $activity_id=$input['activity_id'];
  1986. $search_name=$input['search_name'];
  1987. $activity=Activity::where('id',$activity_id)->first();
  1988. $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  1989. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  1990. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  1991. ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
  1992. $admin=Auth::user();
  1993. if($admin->role_id==23){
  1994. $warea_ids = Warea::where('admin_id',$admin->id)->pluck('id');
  1995. $data->whereHas('get_user', function($query) use ($warea_ids){
  1996. $query->whereIn('warea_id',$warea_ids);
  1997. });
  1998. }
  1999. if($search_name){
  2000. $address_ids=Address::where(function($query) use ($search_name){
  2001. $query->where('username','like','%'.$search_name.'%')
  2002. ->orWhere('mobile',$search_name);
  2003. })->pluck('id');
  2004. $data->whereIn('order_test.address_id',$address_ids);
  2005. }
  2006. $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
  2007. ->where('order_test.is_deleted',0)
  2008. ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
  2009. 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
  2010. 'goods_test.unit',DB::raw('SUM(order_detail.num) as total'))
  2011. ->groupBy('order_test.address_id','order_test.user_id','goods_test.unit')
  2012. ->orderBy('order_test.created_at')
  2013. ->get();
  2014. $array=[];
  2015. foreach($list as $key => $val) {
  2016. $keys = $val->address_id . '-' . $val->u_id;
  2017. $array[$keys]['name'] = $val->username;
  2018. $array[$keys]['mobile'] = $val->mobile;
  2019. $array[$keys]['address'] = $val->address;
  2020. $array[$keys]['address_id'] = $val->address_id;
  2021. $array[$keys]['user_id'] = $val->u_id;
  2022. $array[$keys]['province'] = $val->province;
  2023. $array[$keys]['city'] = $val->city;
  2024. $array[$keys]['town'] = $val->town;
  2025. $array[$keys]['u_nickname'] = $val->u_nickname;
  2026. $array[$keys]['u_mobile'] = $val->u_mobile;
  2027. $array[$keys]['u_name'] = $val->u_name;
  2028. if ($val->unit == '套') {
  2029. if (empty($array[$keys]['num'])) {
  2030. $array[$keys]['num'] = $val->total;
  2031. } else {
  2032. $array[$keys]['num'] += $val->total;
  2033. }
  2034. } elseif ($val->unit == '件') {
  2035. if (empty($array[$keys]['num'])) {
  2036. $array[$keys]['num'] = $val->total * 2;
  2037. } else {
  2038. $array[$keys]['num'] += $val->total * 2;
  2039. //>>>>>>> comissar
  2040. }
  2041. }
  2042. }
  2043. $gifts = Gifts::where('activity_id', $activity_id)->get();
  2044. foreach ($array as $key => $val) {
  2045. $arr = [];
  2046. foreach ($gifts as $k => $v) {
  2047. if (floor($val['num'] / $v->num) > 0) {
  2048. $arr[] = $v->name . '*' . floor($val['num'] / $v->num);
  2049. }
  2050. $array[$key]['gift'] = implode(',', $arr);
  2051. }
  2052. }
  2053. $count=count($array);
  2054. return $this->success_list(array_slice($array,$num,$page_size),'成功',$count);
  2055. }
  2056. public function getOrderGoodsInfo(Request $request){
  2057. $input=$request->all();
  2058. $address_id=$input['address_id'];
  2059. $user_id=$input['user_id'];
  2060. $activity_id=$input['activity_id'];
  2061. $activity=Activity::find($activity_id);
  2062. $info=Ordertest::with(['get_order_detail'=>function($query){
  2063. $query->with('get_goods');
  2064. }])->where('is_deleted',0)
  2065. ->where('address_id',$address_id)
  2066. ->where('user_id',$user_id)
  2067. ->whereBetween('created_at',[$activity->start_time,$activity->end_time])
  2068. ->get();
  2069. if($info){
  2070. return $this->success($info);
  2071. }else{
  2072. return $this->error();
  2073. }
  2074. }
  2075. //<<<<<<< HEAD
  2076. // public function exportMergerOrder(Request $request){
  2077. // $input=$request->all();
  2078. // $activity_id=$input['activity_id'];
  2079. // $search_name=$input['search_name'];
  2080. // $activity=Activity::where('id',$activity_id)->first();
  2081. // $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  2082. // ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  2083. // ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  2084. // ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
  2085. // if($search_name){
  2086. // $address_ids=Address::where(function($query) use ($search_name){
  2087. // $query->where('username','like','%'.$search_name.'%')
  2088. // ->orWhere('mobile',$search_name);
  2089. // })->pluck('id');
  2090. // $data->whereIn('order_test.address_id',$address_ids);
  2091. // }
  2092. // $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
  2093. // ->where('order_test.is_deleted',0)
  2094. // ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
  2095. // 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
  2096. // 'order_test.order_num',
  2097. // 'goods_test.unit','goods_test.name','goods_test.main_attr','goods_test.sec_attr','goods_test.size',
  2098. // DB::raw('SUM(order_detail.num) as total'))
  2099. // ->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')
  2100. // ->orderBy('order_test.created_at')
  2101. // ->get();
  2102. //// dd($list);
  2103. // $array=[];
  2104. // foreach($list as $key => $val){
  2105. // $keys=$val->address_id.'-'.$val->u_id;
  2106. // $array[$keys]['name']=$val->username;
  2107. // $array[$keys]['mobile']=$val->mobile;
  2108. // $array[$keys]['address']=$val->address;
  2109. // $array[$keys]['address_id']=$val->address_id;
  2110. // $array[$keys]['user_id']=$val->u_id;
  2111. // $array[$keys]['province']=$val->province;
  2112. // $array[$keys]['city']=$val->city;
  2113. // $array[$keys]['town']=$val->town;
  2114. // $array[$keys]['u_nickname']=$val->u_nickname;
  2115. // $array[$keys]['u_mobile']=$val->u_mobile;
  2116. // $array[$keys]['u_name']=$val->u_name;
  2117. // $array[$keys]['goods'][$val->order_num][]=$val->name.'-'.$val->sec_attr.'-'.$val->size.'*'.$val->total;
  2118. //// $array[$keys]['goods'][$val->order_num][]=[$val->name.$val->size,$val->name,$val->size,$val->sec_attr,$val->total];
  2119. // if($val->unit=='套'){
  2120. // if(empty($array[$keys]['num'])){
  2121. // $array[$keys]['num']=$val->total;
  2122. // }else{
  2123. // $array[$keys]['num']+=$val->total;
  2124. // }
  2125. // }elseif($val->unit=='件'){
  2126. // if(empty($array[$keys]['num'])){
  2127. // $array[$keys]['num']=$val->total*2;
  2128. // }else{
  2129. // $array[$keys]['num']+=$val->total*2;
  2130. // }
  2131. // }
  2132. // }
  2133. // $gifts=Gifts::where('activity_id',$activity_id)->get();
  2134. // foreach($array as $key=>$val){
  2135. // $array[$key]['shouhuan']=0;
  2136. // $array[$key]['xianglian']=0;
  2137. // $arr=[];
  2138. // foreach($gifts as $k => $v){
  2139. // if(floor($val['num']/$v->num)>0){
  2140. // if ($v->name=='手环'||$v->name=='赠品-手环'){
  2141. // $array[$key]['shouhuan']=floor($val['num']/$v->num);
  2142. // }
  2143. // if ($v->name=='项链'||$v->name=='赠品-项链'){
  2144. // $array[$key]['xianglian']=floor($val['num']/$v->num);
  2145. // }
  2146. // $arr[]=$v->name.'*'.floor($val['num']/$v->num);
  2147. public function exportMergerOrder(Request $request){
  2148. $input=$request->all();
  2149. $activity_id=$input['activity_id'];
  2150. $search_name=$input['search_name'];
  2151. $activity=Activity::where('id',$activity_id)->first();
  2152. $data = Ordertest::leftJoin('order_detail', 'order_test.id', '=', 'order_detail.order_id')
  2153. ->leftJoin('users', 'order_test.user_id', '=', 'users.id')
  2154. ->leftJoin('goods_test', 'goods_test.id', '=', 'order_detail.goods_id')
  2155. ->leftJoin('address', 'address.id', '=', 'order_test.address_id');
  2156. $admin=Auth::user();
  2157. if($admin->role_id==23){
  2158. $warea_ids = Warea::where('admin_id',$admin->id)->pluck('id');
  2159. $data->whereHas('get_user', function($query) use ($warea_ids){
  2160. $query->whereIn('warea_id',$warea_ids);
  2161. });
  2162. }
  2163. if($search_name){
  2164. $address_ids=Address::where(function($query) use ($search_name){
  2165. $query->where('username','like','%'.$search_name.'%')
  2166. ->orWhere('mobile',$search_name);
  2167. })->pluck('id');
  2168. $data->whereIn('order_test.address_id',$address_ids);
  2169. }
  2170. $list=$data->whereBetween('order_test.created_at',[$activity->start_time, $activity->end_time])
  2171. ->where('order_test.is_deleted',0)
  2172. ->select('users.id as u_id','users.nickname as u_nickname', 'users.mobile as u_mobile', 'users.realname as u_name',
  2173. 'address.id as address_id','address.username', 'address.mobile', 'address.address', 'address.province', 'address.city','address.town',
  2174. 'order_test.order_num',
  2175. 'goods_test.unit','goods_test.name','goods_test.main_attr','goods_test.sec_attr','goods_test.size',
  2176. DB::raw('SUM(order_detail.num) as total'))
  2177. ->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')
  2178. ->orderBy('order_test.created_at')
  2179. ->get();
  2180. $array=[];
  2181. foreach($list as $key => $val){
  2182. $keys=$val->address_id.'-'.$val->u_id;
  2183. $array[$keys]['name']=$val->username;
  2184. $array[$keys]['mobile']=$val->mobile;
  2185. $array[$keys]['address']=$val->address;
  2186. $array[$keys]['address_id']=$val->address_id;
  2187. $array[$keys]['user_id']=$val->u_id;
  2188. $array[$keys]['province']=$val->province;
  2189. $array[$keys]['city']=$val->city;
  2190. $array[$keys]['town']=$val->town;
  2191. $array[$keys]['u_nickname']=$val->u_nickname;
  2192. $array[$keys]['u_mobile']=$val->u_mobile;
  2193. $array[$keys]['u_name']=$val->u_name;
  2194. $array[$keys]['goods'][$val->order_num][]=$val->name.'-'.$val->sec_attr.'-'.$val->size.'*'.$val->total;
  2195. // $array[$keys]['goods'][$val->order_num][]=[$val->name.$val->size,$val->name,$val->size,$val->sec_attr,$val->total];
  2196. if($val->unit=='套'){
  2197. if(empty($array[$keys]['num'])){
  2198. $array[$keys]['num']=$val->total;
  2199. }else{
  2200. $array[$keys]['num']+=$val->total;
  2201. }
  2202. }elseif($val->unit=='件'){
  2203. if(empty($array[$keys]['num'])){
  2204. $array[$keys]['num']=$val->total*2;
  2205. }else{
  2206. $array[$keys]['num']+=$val->total*2;
  2207. }
  2208. }
  2209. }
  2210. $gifts=Gifts::where('activity_id',$activity_id)->get();
  2211. foreach($array as $key=>$val){
  2212. $array[$key]['shouhuan']=0;
  2213. $array[$key]['xianglian']=0;
  2214. foreach($gifts as $k => $v){
  2215. if(floor($val['num']/$v->num)>0){
  2216. if ($v->name=='手环'||$v->name=='赠品-手环'){
  2217. $array[$key]['shouhuan']=floor($val['num']/$v->num);
  2218. }
  2219. if ($v->name=='项链'||$v->name=='赠品-项链'){
  2220. $array[$key]['xianglian']=floor($val['num']/$v->num);
  2221. }
  2222. }
  2223. }
  2224. }
  2225. return $this->success($array);
  2226. }
  2227. //根据名称查询代理信息
  2228. public function getUserNameIds($search = null)
  2229. {
  2230. return User::where(function ($query) use ($search) {
  2231. $query->where('nickname', 'like', '%' . $search . '%')
  2232. ->orwhere('realname', 'like', '%' . $search . '%')
  2233. ->orwhere('mobile', $search);
  2234. })->pluck('id');
  2235. }
  2236. //根据商品名称获取订单id
  2237. public function getGoodsOrderIds($search = null)
  2238. {
  2239. return Orderdetail::where('goods_name', 'like', '%' . $search . '%')
  2240. ->pluck('order_id');
  2241. }
  2242. protected function dataGroup(array $dataArr, string $keyStr): array
  2243. {
  2244. $newArr = [];
  2245. foreach ($dataArr as $k => $val) { //数据根据日期分组
  2246. $newArr[$val[$keyStr]][] = $val;
  2247. }
  2248. return $newArr;
  2249. }
  2250. public function getGoodsInfo($order_id)
  2251. {
  2252. $goods = Goodtest::leftJoin('order_detail', function ($query) use ($order_id) {
  2253. $query->on('goods_test.id', '=', 'order_detail.goods_id')
  2254. ->where('order_id', $order_id);
  2255. })
  2256. ->select('goods_test.main_attr', 'goods_test.sec_attr', 'goods_test.size', DB::raw('SUM(order_detail.num) as total'))
  2257. ->groupBy('goods_test.sec_attr', 'goods_test.size', 'goods_test.main_attr')
  2258. ->get();
  2259. return $goods;
  2260. }
  2261. //=======
  2262. /***T恤统计*/
  2263. public function get_t_data(Request $request)
  2264. {
  2265. $input = $request->all();
  2266. $page_index = $input['page_index'];
  2267. $page_size = $input['page_size'];
  2268. $num = ($page_index - 1) * $page_size;
  2269. $data = CrownCount::orderBy('exchange')->orderBy('id');
  2270. $datas = CrownCount::orderBy('exchange')->orderBy('id');
  2271. if ($request->mobile) {
  2272. $data->where('mobile', $request->mobile)
  2273. ->orwhere('nickname', 'like', '%' . $request->mobile . '%');
  2274. $datas->where('mobile', $request->mobile)
  2275. ->orwhere('nickname', 'like', '%' . $request->mobile . '%');
  2276. }
  2277. if ($request->crown_mobile) {
  2278. $data->where('crown_mobile', $request->crown_mobile)
  2279. ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%');
  2280. $datas->where('crown_mobile', $request->crown_mobile)
  2281. ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%');
  2282. }
  2283. $count = $data->count();
  2284. $tt = clone $datas;
  2285. $count_surplus = $datas->where('exchange', 0)->count();
  2286. $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();
  2287. $count_write = $count - $count_surplus;
  2288. if ($count == 0) {
  2289. $percent = 0;
  2290. } else {
  2291. $percent = (round($count_write / $count, 4) * 100) . '%';
  2292. }
  2293. if ($count == 0) {
  2294. return $this->success_list([], '', $count);
  2295. }
  2296. $list = $data->skip($num)->take($page_size)->get();
  2297. $re = [];
  2298. foreach ($list as $k => $v) {
  2299. $re[$k]['序号'] = $v->id;
  2300. $re[$k]['下单人昵称'] = $v->crown_name;
  2301. $re[$k]['下单人手机号'] = $v->crown_mobile;
  2302. $re[$k]['收货人昵称'] = $v->nickname;
  2303. $re[$k]['收货人手机号'] = $v->mobile;
  2304. $re[$k]['T恤总量'] = $v->total;
  2305. $re[$k]['尺码:L'] = $v->type_l;
  2306. $re[$k]['尺码:XL'] = $v->type_xl;
  2307. $re[$k]['尺码:3XL'] = $v->type_3xl;
  2308. $re[$k]['已统计T恤'] = $v->type_l + $v->type_xl + $v->type_3xl;
  2309. $re[$k]['收货人省份'] = $v->province;
  2310. $re[$k]['收货人城市'] = $v->city;
  2311. $re[$k]['收货人地区'] = $v->area;
  2312. $re[$k]['收货人地址'] = $v->address;
  2313. }
  2314. $all = [
  2315. 'total' => $count,
  2316. 'write_count' => $count_write,
  2317. 'surplus_count' => $count_surplus,
  2318. 'percent' => $percent,
  2319. 'total_L' => $t[0]['total_L'],
  2320. 'total_XL' => $t[0]['total_XL'],
  2321. 'total_3XL' => $t[0]['total_3XL'],
  2322. 'total_all' => (string)($t[0]['total_3XL'] + $t[0]['total_XL'] + $t[0]['total_L']),
  2323. 'list' => $re
  2324. ];
  2325. return $this->success($all);
  2326. // return $this->success_list($re,'',$count);
  2327. }
  2328. /**下载T恤详情**/
  2329. public function get_t_excel(Request $request)
  2330. {
  2331. $data = CrownCount::orderBy('id');
  2332. if ($request->mobile) {
  2333. $data->where('mobile', $request->mobile)
  2334. ->orwhere('nickname', 'like', '%' . $request->mobile . '%');
  2335. }
  2336. if ($request->crown_mobile) {
  2337. $data->where('mobile', $request->crown_mobile)
  2338. ->orwhere('crown_name', 'like', '%' . $request->crown_mobile . '%');
  2339. }
  2340. $list = $data->get();
  2341. foreach ($list as $k => $v) {
  2342. $re[$k]['下单人昵称'] = $v->crown_name;
  2343. $re[$k]['下单人手机号'] = $v->crown_mobile;
  2344. $re[$k]['收货人昵称'] = $v->nickname;
  2345. $re[$k]['收货人手机号'] = $v->mobile;
  2346. $re[$k]['T恤总量'] = $v->total;
  2347. $re[$k]['尺码:L'] = $v->type_l;
  2348. $re[$k]['尺码:XL'] = $v->type_xl;
  2349. $re[$k]['尺码:3XL'] = $v->type_3xl;
  2350. $re[$k]['已统计T恤'] = $v->type_l + $v->type_xl + $v->type_3xl;
  2351. $re[$k]['收货人省份'] = $v->province;
  2352. $re[$k]['收货人城市'] = $v->city;
  2353. $re[$k]['收货人地区'] = $v->area;
  2354. $re[$k]['收货人地址'] = $v->address;
  2355. }
  2356. return $this->success_list($re);
  2357. }
  2358. /*
  2359. * 修改T恤统计信息
  2360. * */
  2361. public function update_t(Request $request)
  2362. {
  2363. $re = $request->all();
  2364. $v = CrownCount::where('id', $re['序号'])->first();
  2365. if (!$v) {
  2366. return $this->error(40013, '修改出错');
  2367. }
  2368. try {
  2369. $count = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL'];
  2370. if ($count > $re['T恤总量']) {
  2371. return $this->error(40013, '尺码数量总和大于T恤总量');
  2372. }
  2373. // if ($v->exchange!=$count){
  2374. // return $this->error(40013,'尺码数量总和不等于已统计数量');
  2375. // }
  2376. $v->crown_name = $re['下单人昵称'];
  2377. $v->crown_mobile = $re['下单人手机号'];
  2378. $v->nickname = $re['收货人昵称'];
  2379. $v->mobile = $re['收货人手机号'];
  2380. $v->total = $re['T恤总量'];
  2381. $v->type_l = $re['尺码:L'];
  2382. $v->type_xl = $re['尺码:XL'];
  2383. $v->type_3xl = $re['尺码:3XL'];
  2384. $v->exchange = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL'];
  2385. $v->province = $re['收货人省份'];
  2386. $v->city = $re['收货人城市'];
  2387. $v->area = $re['收货人地区'];
  2388. $v->address = $re['收货人地址'];
  2389. $v->save();
  2390. return $this->success([]);
  2391. } catch (\Exception $exception) {
  2392. return $this->error(40013, $exception);
  2393. }
  2394. }
  2395. /*
  2396. * 新增
  2397. * **/
  2398. public function add_t(Request $request)
  2399. {
  2400. $re = $request->all();
  2401. $v = new CrownCount();
  2402. try {
  2403. $count = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL'];
  2404. if ($count > $re['T恤总量']) {
  2405. return $this->error(40013, '尺码数量总和大于T恤总量');
  2406. }
  2407. $v->crown_name = $re['下单人昵称'];
  2408. $v->crown_mobile = $re['下单人手机号'];
  2409. $v->nickname = $re['收货人昵称'];
  2410. $v->mobile = $re['收货人手机号'];
  2411. $v->total = $re['T恤总量'];
  2412. $v->type_l = $re['尺码:L'];
  2413. $v->type_xl = $re['尺码:XL'];
  2414. $v->type_3xl = $re['尺码:3XL'];
  2415. $v->exchange = $re['尺码:L'] + $re['尺码:XL'] + $re['尺码:3XL'];
  2416. $v->province = $re['收货人省份'];
  2417. $v->city = $re['收货人城市'];
  2418. $v->area = $re['收货人地区'];
  2419. $v->address = $re['收货人地址'];
  2420. $v->save();
  2421. return $this->success([]);
  2422. } catch (\Exception $exception) {
  2423. return $this->error(40013, '修改失败');
  2424. }
  2425. }
  2426. /*
  2427. * 删除T恤统计
  2428. * **/
  2429. public function delete_t(Request $request)
  2430. {
  2431. $input = $request->all();
  2432. CrownCount::where('id', $input['序号'])->delete();
  2433. return $this->success([]);
  2434. }
  2435. public function get_user()
  2436. {
  2437. $data = [20218, 2533, 13649, 12336, 23488, 21256, 12487, 17769, 16377, 20363, 9736, 2568, 11718, 21221];
  2438. foreach ($data as $k => $v) {
  2439. $user = User::find($v);
  2440. $re[$k]['mobile'] = $user->mobile;
  2441. $re[$k]['nickname'] = $user->nickname;
  2442. $re[$k]['realname'] = $user->realname;
  2443. }
  2444. return $this->success_list($re);
  2445. }
  2446. /**尺码详情**/
  2447. public function size_data(){
  2448. $active=Activity::where('is_ing',1)->first();
  2449. $data=Orderdetail::join('order_test','order_test.id','=','order_detail.order_id')
  2450. ->where('order_test.is_deleted',0)
  2451. ->whereBetween('order_detail.created_at',[$active->start_time,$active->end_time])
  2452. ->select('order_detail.goods_id','order_detail.goods_name','order_detail.goods_size',DB::raw('sum(order_detail.num) as num'))
  2453. ->groupBy('order_detail.goods_id')->orderBy('order_detail.goods_id')->get();
  2454. return $this->success_list($data);
  2455. }
  2456. //获取订单备注
  2457. private function getOrderRemark($order_id)
  2458. {
  2459. $remark = OrderRemark::where('order_id', $order_id)
  2460. ->select('remark', 'name')->get();
  2461. $str_remark = '';
  2462. if ($remark) {
  2463. foreach ($remark as $k => $v) {
  2464. $str_remark .= '【' . $v->remark . '/---/' . $v->name . '】';
  2465. }
  2466. }
  2467. return $str_remark;
  2468. }
  2469. public function getActivityDataInfo(Request $request)
  2470. {
  2471. $input=$request->all();
  2472. $page_index=$input['page_index'];
  2473. $page_size=$input['page_size'];
  2474. $num=$page_size*($page_index-1);
  2475. $search_name=$input['search_name'];
  2476. $activity=Activity::where('disabled',0)->get();
  2477. foreach($activity as $key=>$val){
  2478. if($val->end_time <= date("Y-m-d H:i:s")){
  2479. $act_data_num = EveryActData::where('activity_id',$val->id)->count();
  2480. if($act_data_num <= 0){
  2481. $user=Ordertest::where('pay_status',2)->where('is_deleted',0)->whereBetween('created_at',[$val->start_time,$val->end_time])
  2482. ->groupBy('user_id')->pluck('user_id');
  2483. $info=User::select('id','nickname','realname','mobile','level')->withCount(['order_test as order_test_account'=>function($query)use($val){
  2484. $query->select(DB::raw('sum(pay_money)'))->whereBetween('created_at',[$val->start_time,$val->end_time]);
  2485. }])->whereIn('id',$user)->get();
  2486. $act=[];
  2487. foreach($info as $k=>$v){
  2488. $act[$k]['user_id']=$v->id;
  2489. $act[$k]['activity_id']=$val->id;
  2490. $act[$k]['account']=$v->order_test_account;
  2491. $act[$k]['created_at']=date("Y-m-d H:i:s");
  2492. $act[$k]['updated_at']=date("Y-m-d H:i:s");
  2493. }
  2494. EveryActData::insert($act);
  2495. }
  2496. }
  2497. }
  2498. $user_ids=EveryActData::groupBy('user_id')->pluck('user_id');
  2499. $info=User::select('id','nickname','realname','mobile','level')
  2500. ->with(['every_act_data'=>function($query){
  2501. $query->select('id','user_id','activity_id','account')->with(['activity:id,title']);
  2502. }])->whereIn('id',$user_ids);
  2503. if($search_name){
  2504. $info->where(function($query)use($search_name){
  2505. $query->where('nickname','like','%'.$search_name.'%')
  2506. ->where('mobile',$search_name);
  2507. });
  2508. }
  2509. $count=$info ->count();
  2510. $list=$info -> OrderByDesc('level')->OrderByDesc('id')->skip($num)->take($page_size)->get();
  2511. // return $this->success($list);
  2512. foreach($list as $key=>$val){
  2513. // $count[$key]=0;
  2514. foreach($val as $k=>$v){
  2515. // $list[$v->id]['nickname']=$v['nickname'];
  2516. // $list[$v->id]['realname']=$v['realname'];
  2517. // $list[$v->id]['mobile']=$v['mobile'];
  2518. // $list[$v->id]['level']=$v['level'];
  2519. // $list[$v->id][$key]=$v->order_test_account;
  2520. // $count[$key]+=$v->order_test_account;
  2521. }
  2522. }
  2523. $every_act=EveryActData::with(['activity:id,title'])->groupBy('activity_id')->orderByDesc('activity_id')->get();
  2524. $account=[];
  2525. foreach($every_act as $key=>$val){
  2526. $account[$val->activity_id]['title']=$val->activity->title;
  2527. $account[$val->activity_id]['account']=EveryActData::where('activity_id',$val->activity_id)->sum('account');
  2528. }
  2529. $data['list']=$list;
  2530. $data['account']=$account;
  2531. return $this->success_list($data,'',$count);
  2532. }
  2533. }