No Description

FxStatisticsController.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Created by Sublime.
  4. * User: hao
  5. * Date: 19/08/30
  6. * Time: 上午11:20
  7. */
  8. namespace App\Http\Controllers\Admin;
  9. use App\Http\Controllers\Controller;
  10. use App\Logs;
  11. use App\Order;
  12. use App\FxOrder;
  13. use App\FxOrderGoodsSkus;
  14. use App\Admin;
  15. use App\Goods;
  16. use App\GoodsSkus;
  17. use App\RedisModel as Redis;
  18. use Illuminate\Http\Request;
  19. use Illuminate\Support\Facades\DB;
  20. class FxStatisticsController extends Controller
  21. {
  22. protected $warehouse = [];
  23. public function __construct()
  24. {
  25. $this->warehouse = config('constants.WAREHOUSE');
  26. $is_fx = env('IS_FX');
  27. if($is_fx > 0) {
  28. unset($this->warehouse[1]);
  29. unset($this->warehouse[2]);
  30. }
  31. }
  32. /**
  33. * 发货财务明细
  34. */
  35. public function sendFinanceList(Request $request){
  36. $team_id = (int)$request->input('team_id');
  37. //分銷商只能看自己团队
  38. $self_id = session('admin_id');
  39. $team_id = Admin::where('id', $self_id)->pluck('team_id');
  40. $stime = $request->input('stime');
  41. $etime = $request->input('etime');
  42. $warehouse = 3;
  43. $page = (int)$request->input('page');
  44. $pageSize = 20;
  45. if($page<=0){
  46. $page = 1;
  47. }
  48. $offset = ($page-1) * $pageSize;
  49. $count = FxOrder::where(function($query) use($team_id, $stime, $etime, $warehouse){
  50. if($team_id) $query->where('team_id', $team_id);
  51. if($warehouse) $query->where('warehouse', $warehouse);
  52. if($stime) $query->where('send_time', '>=', $stime);
  53. if($etime) $query->where('send_time', '<=', $etime);
  54. })->where('is_del', 0)->where('status','>=',2)->where('logistics_id', '>', '')->count();
  55. if ($count > 1) {
  56. // 总页数
  57. $pages = ceil($count/$pageSize);
  58. }else{
  59. // 总页数
  60. $pages = 1;
  61. }
  62. $teams = DB::table('teams')->lists('name', 'id');
  63. $resultQuery = FxOrder::select('team_id', 'createTime', 'id', 'receivedAmount', 'cost', 'freight_cost', 'payment_type', 'send_time', 'warehouse', 'receiverName', 'logistics_id')->where(function($query) use($team_id, $stime, $etime, $warehouse){
  64. if($team_id) $query->where('team_id', $team_id);
  65. if($warehouse) $query->where('warehouse', $warehouse);
  66. if($stime ) $query->where('send_time', '>=', $stime);
  67. if($etime ) $query->where('send_time', '<=', $etime);
  68. })->where('is_del', 0)->where('status','>=',2)->where('logistics_id', '>', '');
  69. $result = $resultQuery->orderBy('send_time','desc')->offset($offset)->limit($pageSize)->get();
  70. $result = json_decode(json_encode($result), true);
  71. $payArr = [1=>'微信支付', 2=>'付款码支付', 3=>'个体户支付', 4=>'充值卡支付'];
  72. $wareArr = $this->warehouse;
  73. foreach($result as $k=>&$v){
  74. $v['team_name'] = $v['team_id']>0 ? $teams[$v['team_id']] : '';;
  75. $v['payment_type'] = $payArr[$v['payment_type']];
  76. $v['ctime'] = $v['send_time'];
  77. $v['warehouse'] = $wareArr[$v['warehouse']];
  78. }
  79. return view('/fxstatistics/sendFinanceList',[
  80. 'result' => $result,
  81. 'team_id' => $team_id,
  82. 'stime' => $stime,
  83. 'etime' => $etime,
  84. 'page' => $page,
  85. 'count' => $count,
  86. 'pages' => $pages,
  87. ]);
  88. }
  89. /**
  90. * 发货财务明细
  91. */
  92. public function sendFinanceList_export(Request $request){
  93. $team_id = (int)$request->input('team_id');
  94. $self_id = session('admin_id');
  95. $team_id = Admin::where('id', $self_id)->pluck('team_id');
  96. $stime = $request->input('stime');
  97. $etime = $request->input('etime');
  98. $warehouse = 3;
  99. $teams = DB::table('teams')->lists('name', 'id');
  100. $resultQuery = FxOrder::select('team_id', 'createTime', 'id', 'receivedAmount', 'cost', 'freight_cost', 'payment_type', 'send_time', 'warehouse', 'receiverName', 'logistics_id')->where(function($query) use($team_id, $stime, $etime, $warehouse){
  101. if($team_id) $query->where('team_id', $team_id);
  102. if($warehouse) $query->where('warehouse', $warehouse);
  103. if($stime ) $query->where('send_time', '>=', $stime);
  104. if($etime ) $query->where('send_time', '<=', $etime);
  105. })->where('is_del', 0)->where('status','>=',2)->where('logistics_id', '>', '');
  106. $result = $resultQuery->orderBy('send_time','desc')->get();
  107. $result = json_decode(json_encode($result), true);
  108. $payArr = [1=>'微信支付', 2=>'付款码支付', 3=>'个体户支付', 4=>'充值卡支付'];
  109. $wareArr = $this->warehouse;
  110. foreach($result as $k=>&$v){
  111. $v['team_name'] = $v['team_id']>0 ? $teams[$v['team_id']] : '';;
  112. $v['payment_type'] = $payArr[$v['payment_type']];
  113. $v['ctime'] = $v['send_time'];
  114. $v['warehouse'] = $wareArr[$v['warehouse']];
  115. }
  116. $indexKey = ['team_name','ctime','id','receivedAmount', 'cost', 'freight_cost', 'payment_type', 'receiverName', 'logistics_id'];
  117. $title = ['团队', '发货时间', '订单编号', '成交金额','货品成本', '物流成本', '支付方式', '收货人', '物流单号'];
  118. $filename = 'fahuomingxi_'.date('Y-m-d_H').'.xlsx';
  119. return Order::export_excel($result, $filename, $indexKey, $title);
  120. }
  121. }