DeliveryBatch.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\shop\controller\order;
  20. use app\common\basics\ShopBase;
  21. use app\common\server\excel\Excel;
  22. use app\common\server\JsonServer;
  23. use app\shop\logic\order\DeliveryBatchLogic;
  24. use app\shop\validate\order\DeliveryBatchImportValidate;
  25. use PhpOffice\PhpSpreadsheet\Cell\DataType;
  26. use PhpOffice\PhpSpreadsheet\IOFactory;
  27. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  28. class DeliveryBatch extends ShopBase
  29. {
  30. /**
  31. * @notes 批量发货列表
  32. * @return \think\response\Json|\think\response\View
  33. * @author lbzy
  34. * @datetime 2025-03-06 18:10:51
  35. */
  36. function lists()
  37. {
  38. if ($this->request->isAjax()) {
  39. return JsonServer::success('', DeliveryBatchLogic::lists(input()));
  40. }
  41. return view();
  42. }
  43. /**
  44. * @notes 批量发货详情
  45. * @return \think\response\Json
  46. * @author lbzy
  47. * @datetime 2025-03-06 18:10:39
  48. */
  49. function detail()
  50. {
  51. return JsonServer::success('', [ 'detail' => DeliveryBatchLogic::detail(input('id/d')) ]);
  52. }
  53. /**
  54. * @notes 下载默认文件等
  55. * @return string|\think\response\File
  56. * @author lbzy
  57. * @datetime 2025-03-06 17:35:44
  58. */
  59. function down()
  60. {
  61. $filename = pathinfo(input('file/s'), PATHINFO_FILENAME);
  62. $path = app()->getRootPath() . 'public/static/excel/' . $filename . '.xls';
  63. if (! file_exists($path)) {
  64. return '文件不存在';
  65. }
  66. return download($path, $filename);
  67. }
  68. /**
  69. * @notes 下载导入失败的
  70. * @return void
  71. * @author lbzy
  72. * @datetime 2025-03-06 18:20:45
  73. */
  74. function down2()
  75. {
  76. $lists = DeliveryBatchLogic::getFailInfoLists(input('id/d'));
  77. Excel::out($lists, [
  78. [ 'field' => 'sn', 'title' => '订单编号', 'excel_data_type' => DataType::TYPE_STRING ],
  79. [ 'field' => 'express_name', 'title' => '快递公司名称' ],
  80. [ 'field' => 'express_no', 'title' => '快递单号' ],
  81. [ 'field' => 'fail_content', 'title' => '失败原因' ],
  82. ], '','', '导入失败订单');
  83. exit;
  84. }
  85. /**
  86. * @notes 立即导入
  87. * @return \think\response\Json
  88. * @author lbzy
  89. * @datetime 2025-03-06 17:56:34
  90. */
  91. function import()
  92. {
  93. $sheet = IOFactory::load($_FILES['file']['tmp_name'])->getActiveSheet();
  94. $sheet->getStyle('A')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT);
  95. $sheet->getStyle('B')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT);
  96. $sheet->getStyle('C')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_TEXT);
  97. $lists = $sheet->toArray(null, true, true, true);
  98. (new DeliveryBatchImportValidate())->goCheck('', [ 'lists' => $lists ]);
  99. $result = DeliveryBatchLogic::importLists($lists, $_FILES['file']['name']);
  100. return is_array($result) ? JsonServer::success('', $result) : JsonServer::error($result);
  101. }
  102. /**
  103. * @notes 执行导入页面
  104. * @return \think\response\Json|\think\response\View
  105. * @author lbzy
  106. * @datetime 2025-03-06 18:08:52
  107. */
  108. function delivery()
  109. {
  110. $detail = DeliveryBatchLogic::detail(input('id/d'));
  111. if ($this->request->isAjax()) {
  112. DeliveryBatchLogic::delivery($detail);
  113. return JsonServer::success('');
  114. }
  115. return view('', [
  116. 'detail' => $detail
  117. ]);
  118. }
  119. }