BillsController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Http\Controllers\Channel\Finance;
  3. use App\Http\Controllers\Channel\Finance\Transformers\BillTransformer;
  4. use App\Modules\Finance\Services\BillService;
  5. use Illuminate\Http\Request;
  6. class BillsController extends BaseController
  7. {
  8. /**
  9. * @apiDefine Finance 结算提现模块
  10. */
  11. /**
  12. * @apiVersion 1.0.0
  13. * @apiDescription 获取结算列表
  14. * @api {GET} bills 获取结算列表
  15. * @apiGroup Finance
  16. * @apiName bills
  17. * @apiParam {String} [search_name] 搜索名称
  18. * @apiParam {String} [start_time] 开始时间2017-01-01.(可不传)
  19. * @apiParam {String} [end_time] 结束时间2017-02-01.(可不传)
  20. * @apiSuccess {String} date 日期.
  21. * @apiSuccess {Number} recharge_amount 充值金额.
  22. * @apiSuccess {Number} settlement_price 结算金额.
  23. * @apiSuccess {Number} tallage 扣税金额.
  24. * @apiSuccess {String} rate 比例.
  25. * @apiSuccessExample {json} Success-Response:
  26. *
  27. * {
  28. * "code": 0,
  29. * "msg": "",
  30. * "data":
  31. * {
  32. * "list":[
  33. * {
  34. * "date": "2017-11-18",
  35. * "recharge_amount": 1100,
  36. * "settlement_price": 440,
  37. * "tallage": 0,
  38. * "rate": "0.40%"
  39. * }
  40. * ]
  41. * "meta":{
  42. * "total": 4,
  43. * "per_page": 15,
  44. * "current_page": 1,
  45. * "last_page": 1,
  46. * "next_page_url": "",
  47. * "prev_page_url": ""
  48. * }
  49. * }
  50. * }
  51. */
  52. function get_list(Request $request) {
  53. $distribution_channel_id = $this->getChannelId();
  54. $distribution_channel_name = $this->getChannelName();
  55. $distribution_channel_name = '';
  56. $start_time = $request->has('start_time') && !empty($request->input('start_time')) ? date('Ymd',strtotime($request->input('start_time'))) : '';
  57. $end_time = $request->has('end_time') && !empty($request->input('end_time')) ? date('Ymd',strtotime($request->input('end_time'))) : '';
  58. $end_time = self::getMaxDay($end_time);
  59. $search_name = $request->has('search_name') ? $request->input('search_name') : '';
  60. $params = [
  61. 'channel_id'=>$distribution_channel_id,
  62. 'channel_name'=>$distribution_channel_name,
  63. 'search_name'=>$search_name,
  64. 'start_date'=>$start_time,
  65. 'end_date'=>$end_time,
  66. ];
  67. $bills = BillService::getBillList($params);
  68. return response()->pagination(new BillTransformer(), $bills);
  69. }
  70. /**
  71. * @apiVersion 1.0.0
  72. * @apiDescription 获取结算导出
  73. * @api {GET} exportBills 获取结算导出
  74. * @apiGroup Finance
  75. * @apiName exportBills
  76. * @apiParam {String} [search_name] 搜索名称
  77. * @apiParam {String} [start_time] 开始时间2017-01-01.(可不传)
  78. * @apiParam {String} [end_time] 结束时间2017-02-01.(可不传)
  79. */
  80. function export(Request $request) {
  81. $distribution_channel_id = $this->getChannelId();
  82. $distribution_channel_name = $this->getChannelName();
  83. $distribution_channel_name = '';
  84. $start_time = $request->has('start_time') ? date('Ymd',strtotime($request->input('start_time'))) : '';
  85. $end_time = $request->has('end_time') ? date('Ymd',strtotime($request->input('end_time'))) : '';
  86. $end_time = self::getMaxDay($end_time);
  87. $search_name = $request->has('search_name') ? $request->input('search_name') : '';
  88. $params = [
  89. 'channel_id'=>$distribution_channel_id,
  90. 'channel_name'=>$distribution_channel_name,
  91. 'search_name'=>$search_name,
  92. 'start_date'=>$start_time,
  93. 'end_date'=>$end_time,
  94. ];
  95. $bills = BillService::getBillList($params, true);
  96. header("Content-type:application/vnd.ms-excel");
  97. header("Content-Disposition:attachment;filename=" . "结算" . date("YmdHis") . ".csv");
  98. echo iconv("UTF-8","GBK","\"结算日期\",\"充值金额\",\"佣金比例\",\"扣税金额\",\"结算金额\"\r\n");
  99. if($bills)
  100. {
  101. foreach($bills as $bill)
  102. {
  103. echo("\"" . iconv("UTF-8","GBK",date('Y-m-d',strtotime($bill->date))) . "\",");
  104. echo("\"" . (float)$bill->recharge_amount . "\",");
  105. echo("\"" . ($bill->rate).'%' . "\",");
  106. echo("\"" . (float)$bill->tallage . "\",");
  107. echo("\"" . (float)$bill->settlement_price. "\"\r\n");
  108. }
  109. }
  110. exit();
  111. }
  112. }