1
0

EngineerBillController.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\controller\master_worker;
  15. use app\adminapi\controller\BaseAdminController;
  16. use app\adminapi\lists\master_worker\EngineerBillLists;
  17. use app\adminapi\logic\export\ExportLogic;
  18. use app\adminapi\logic\master_worker\EngineerSettlementLogic;
  19. use app\common\service\ExcelExportService;
  20. use excel\ExcelWriter;
  21. use phpseclib3\Common\Functions\Strings;
  22. use think\facade\Db;
  23. use think\facade\Log;
  24. /**
  25. * EngineerSettlement控制器
  26. * Class EngineerSettlementController
  27. * @package app\adminapi\controller
  28. */
  29. class EngineerBillController extends BaseAdminController
  30. {
  31. /**
  32. * @notes 获取列表
  33. * @return \think\response\Json
  34. * @author likeadmin
  35. * @date 2024/11/15 17:21
  36. */
  37. public function lists()
  38. {
  39. // 导入数据
  40. $res = EngineerSettlementLogic::insertSettlementDetails();
  41. if($res === false){
  42. return $this->fail('导入失败');
  43. }
  44. return $this->dataLists(new EngineerBillLists());
  45. }
  46. public function download()
  47. {
  48. /*$firstDay = date('Y-m-01 00:00:00', strtotime('first day of last month'));
  49. $lastDay = date('Y-m-t 23:59:59', strtotime('last day of last month'));
  50. $filename = date('Y-m-d',strtotime($firstDay))."-至-".date('Y-m-d',strtotime($lastDay))."最后结算余额";
  51. $result = ExportLogic::add([
  52. 'download_type' => 1,
  53. 'params' => ['firstDay'=>$firstDay,'lastDay'=>$lastDay],
  54. 'name' => $filename,
  55. 'admin_id' => $this->adminId,
  56. ]);
  57. if (false === $result) {
  58. return $this->fail(ExportLogic::getError());
  59. }*/
  60. $params = $this->request->get();
  61. $deadline_time = strtotime($params['deadline_time'])+86400;
  62. $settlement_type = $params['settlement_type'];
  63. $allData = $this->dataLists(new EngineerBillLists())->getData()['data']['lists'];
  64. if(empty($allData)) return $this->fail('无数据');
  65. $type = [
  66. 1=>'周(7天)',
  67. 2=>'半月',
  68. 3=>'整月'
  69. ];
  70. $filename = "截止到".$params['deadline_time'].$type[$settlement_type].'型结算单';
  71. $result = ExportLogic::add([
  72. 'download_type' => 1,
  73. 'params' => ['settlement_type'=>$settlement_type,'deadline_time'=>$deadline_time],
  74. 'name' => $filename,
  75. 'admin_id' => $this->adminId,
  76. ]);
  77. if (false === $result) {
  78. return $this->fail(ExportLogic::getError());
  79. }
  80. Log::info('导出参数:'.json_encode([$params,$result]));
  81. // 暂时 - 立即生成导出文件
  82. (new ExcelExportService)->download($result);
  83. return $this->success('添加成功-'.$result, [], 1, 1);
  84. }
  85. }