BillsController.php 5.6 KB

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