AgentController.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Util;
  5. use Carbon\Carbon;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Http\Request;
  8. class AgentController extends Controller
  9. {
  10. public function index()
  11. {
  12. }
  13. public function AriesCount(Request $request)
  14. {
  15. $yestoday=Carbon::yesterday()->format("Y-m-d");
  16. $today=Carbon::now()->format("Y-m-d");
  17. $tommorrow=Carbon::tomorrow()->format("Y-m-d");
  18. $start_time=$request->start_time?Carbon::parse($request->start_time)->format("Y-m-d"):$yestoday;
  19. $end_time=$request->end_time?Carbon::parse($request->end_time)->format("Y-m-d"):$today;
  20. // if($start_time==$today){
  21. // $end_time=$tommorrow;
  22. // }
  23. // if($end_time=$today){
  24. // $start_time=$yestoday;
  25. // }
  26. //
  27. // if($start_time==$end_time){
  28. // $start_time=$yestoday;
  29. // $end_time=$today;
  30. // }
  31. // $ccs='103,104,113,106,123,127,131,148,141,162,163,144,149,150,151,164,153,154,155,167,168,169,172,174,179,304,316,317';
  32. $ccs=DB::table('QPPlatformDB.dbo.ChannelPackageName')->select('Channel')->where('UnionSign',1)->pluck('Channel')->toArray();
  33. $ccs=array_unique($ccs);
  34. $ccs=implode(",",$ccs);
  35. $res= DB::connection('sqlsrv')->select("
  36. select
  37. o.Channel,
  38. cp.Remarks,
  39. ISNULL(o.amount, 0) AS amount,
  40. ISNULL(o.payment_fee, 0) AS payment_fee,
  41. ISNULL(o.amount-o.payment_fee , 0) AS amountReal,
  42. CAST(ISNULL(wd.WithDraw, 0) AS decimal(10,2)) AS WithDraw,
  43. CAST(ISNULL(wd.withdraw_fee, 0) AS decimal(10,2)) AS withdraw_fee,
  44. CAST(ISNULL(o.amount, 0) -ISNULL(o.payment_fee, 0) - ISNULL(wd.WithDraw, 0)-ISNULL(wd.withdraw_fee, 0) AS decimal(10,2)) AS NetAmount
  45. from
  46. (select cast(sum(amount)/100 as decimal(10,2)) as amount,cast(sum(payment_fee)/100 as decimal(10,2)) as payment_fee,Channel from agent.dbo.[order] where pay_at<'$end_time' and pay_at>'$start_time' and pay_status=1 and Channel in ($ccs) group by Channel) o
  47. left join (SELECT Channel,MAX(Remarks) AS Remarks FROM QPPlatformDB.dbo.ChannelPackageName group by Channel) cp
  48. on o.Channel=cp.Channel
  49. left join (select cast(sum(WithDraw) as float)/100 as WithDraw, cast(sum(withdraw_fee) as float)/100 as withdraw_fee,AI.Channel from QPAccountsDB.dbo.OrderWithDraw ow left join QPAccountsDB.dbo.AccountsInfo AI
  50. on ow.UserID = AI.UserID where AI.Channel in ($ccs)
  51. and ow.finishDate>'$start_time' and ow.finishDate<'$end_time' and ow.State=2 group by AI.Channel) wd
  52. on o.Channel=wd.Channel
  53. ORDER BY o.Channel");
  54. $total=(object)[];
  55. $total->amount=0;
  56. $total->amountReal=0;
  57. $total->WithDraw=0;
  58. $total->withdraw_fee=0;
  59. $total->payment_fee=0;
  60. $total->NetAmount=0;
  61. $total=array_reduce($res,function ($carry,$item){
  62. $carry->amount+=$item->amount;
  63. $carry->amountReal+=$item->amountReal;
  64. $carry->payment_fee+=$item->payment_fee;
  65. $carry->WithDraw+=$item->WithDraw;
  66. $carry->withdraw_fee+=$item->withdraw_fee;
  67. $carry->NetAmount+=$item->NetAmount;
  68. return $carry;
  69. },$total);
  70. $total->Channel=0;
  71. $total->Remarks='总重';
  72. $res[]=$total;
  73. return view('admin.agent.AriesCount',compact('res','start_time','end_time'));
  74. }
  75. }