1
0

EngineerBillController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\financial\MasterSettlementDetailsLogic;
  19. use app\adminapi\logic\master_worker\EngineerBillLogic;
  20. use app\adminapi\logic\master_worker\EngineerSettlementLogic;
  21. use app\common\service\ExcelExportService;
  22. use excel\ExcelWriter;
  23. use phpseclib3\Common\Functions\Strings;
  24. use think\facade\Db;
  25. use think\facade\Log;
  26. /**
  27. * EngineerSettlement控制器
  28. * Class EngineerSettlementController
  29. * @package app\adminapi\controller
  30. */
  31. class EngineerBillController extends BaseAdminController
  32. {
  33. /**
  34. * @notes 获取列表
  35. * @return \think\response\Json
  36. * @author likeadmin
  37. * @date 2024/11/15 17:21
  38. */
  39. public function lists()
  40. {
  41. // 导入数据
  42. $res = EngineerSettlementLogic::insertSettlementDetails();
  43. if($res === false){
  44. return $this->fail('导入失败');
  45. }
  46. return $this->dataLists(new EngineerBillLists());
  47. }
  48. public function download()
  49. {
  50. /*$firstDay = date('Y-m-01 00:00:00', strtotime('first day of last month'));
  51. $lastDay = date('Y-m-t 23:59:59', strtotime('last day of last month'));
  52. $filename = date('Y-m-d',strtotime($firstDay))."-至-".date('Y-m-d',strtotime($lastDay))."最后结算余额";
  53. $result = ExportLogic::add([
  54. 'download_type' => 1,
  55. 'params' => ['firstDay'=>$firstDay,'lastDay'=>$lastDay],
  56. 'name' => $filename,
  57. 'admin_id' => $this->adminId,
  58. ]);
  59. if (false === $result) {
  60. return $this->fail(ExportLogic::getError());
  61. }*/
  62. $params = $this->request->get();
  63. $deadline_time = strtotime($params['deadline_time'])+86400;
  64. $settlement_type = $params['settlement_type'];
  65. $allData = $this->dataLists(new EngineerBillLists())->getData()['data']['lists'];
  66. if(empty($allData)) return $this->fail('无数据');
  67. $type = [
  68. 1=>'周(7天)',
  69. 2=>'半月',
  70. 3=>'整月'
  71. ];
  72. $filename = "截止到".$params['deadline_time'].$type[$settlement_type].'型结算单';
  73. $result = ExportLogic::add([
  74. 'download_type' => 1,
  75. 'params' => ['settlement_type'=>$settlement_type,'deadline_time'=>$deadline_time],
  76. 'name' => $filename,
  77. 'admin_id' => $this->adminId,
  78. ]);
  79. if (false === $result) {
  80. return $this->fail(ExportLogic::getError());
  81. }
  82. Log::info('导出参数:'.json_encode([$params,$result]));
  83. // 暂时 - 立即生成导出文件
  84. (new ExcelExportService)->download($result);
  85. return $this->success('添加成功-'.$result, [], 1, 1);
  86. }
  87. public function submitForm()
  88. {
  89. $params = $this->request->post();
  90. $params['adminId'] = $this->adminId;
  91. $result = EngineerBillLogic::submitForm($params);
  92. if ($result === false){
  93. return $this->fail(EngineerBillLogic::getError());
  94. }
  95. return $this->success('打款成功', [], 1, 1);
  96. }
  97. }