TestController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Components\Database;
  5. use App\Components\ErrorPush;
  6. use App\MaterialBox;
  7. use App\MaterialBoxModel;
  8. use App\Services\RejectedService;
  9. use App\User;
  10. use App\Waybill;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Support\Facades\Log;
  14. use Oursdreams\Export\Export;
  15. class TestController extends Controller
  16. {
  17. use AsyncResponse, ErrorPush, Database;
  18. const ASNREFERENCE_2 = 'ASNREFERENCE2';
  19. public function __construct()
  20. {
  21. $this->data["active_test"] = "active";
  22. }
  23. public function method(Request $request, $method)
  24. {
  25. try {
  26. return call_user_func([$this, $method], $request);
  27. }catch (\BadMethodCallException $e){
  28. dd("方法不存在");
  29. }
  30. }
  31. public function test(Request $request)
  32. {
  33. $sql = <<<SQL
  34. select rejected_bills.*,
  35. CASE rejected_bills.is_loaded
  36. WHEN 0 THEN '否'
  37. WHEN 1 THEN '是'
  38. WHEN 2 THEN '待推单'
  39. WHEN 3
  40. THEN '上传异常'
  41. WHEN 4 THEN '待确认'
  42. ELSE '无需入库' END loaded,
  43. owners.name owner_name,
  44. logistics.name logistic_name,
  45. rejected_bill_items.created_at item_created_at,
  46. rejected_bill_items.barcode_goods item_barcode,
  47. rejected_bill_items.name_goods item_name,
  48. rejected_bill_items.remark item_remark,
  49. rejected_bill_items.amount item_amount,
  50. rejected_bill_items.batch_number item_batch_number,
  51. rejected_bill_items.made_at item_made_at,
  52. rejected_bill_items.validity_at item_validity_at,
  53. rejected_bill_items.remark item_remark,
  54. quality_labels.name quality_label_name,
  55. users.name operator_name
  56. from rejected_bills
  57. left join owners on rejected_bills.id_owner = owners.id
  58. left join logistics on
  59. rejected_bills.id_logistic_return = logistics.id
  60. left join rejected_bill_items on rejected_bills.id =
  61. rejected_bill_items.id_rejected_bill
  62. left join quality_labels on rejected_bill_items.id_quality_label = quality_labels.id
  63. left join users on rejected_bills.id_operator = users.id
  64. where rejected_bills.deleted_at is null
  65. and rejected_bill_items.deleted_at is null and rejected_bills.created_at between '2021-12-01 00:00:00' and '2021-12-31 23:59:59'
  66. order by rejected_bills.id desc
  67. SQL;
  68. $limit=$request->input("limit");
  69. $mapper = [
  70. "created_at"=>"日期","checked_numbers"=>"审核号",
  71. "owner_name"=>"客户名称","order_number"=>"订单号",
  72. "sender"=>"姓名","mobile_sender"=>"手机",
  73. "logistic_number"=>"原单单号","logistic_number_return"=>"退回单号","logistic_name"=>"退回公司",
  74. "fee_collected"=>"到付费用","loaded"=>"是否入库",
  75. "item_barcode"=>"商品条码","item_name"=>"商品名称",
  76. "item_amount"=>"商品数量","quality_label_name"=>"商品质量","item_remark"=>"备注","operator_name"=>"录入人","remark"=>"退单备注"
  77. ];
  78. $column = array_values($mapper);
  79. $data = DB::select(DB::raw($sql." limit {$limit},10000"));
  80. if (count($data)==0){
  81. dd("完成了");
  82. }
  83. $list = [];
  84. foreach ($data as $item){
  85. $list[] = [
  86. $item->created_at,
  87. $item->checked_numbers,
  88. $item->owner_name,
  89. $item->order_number,
  90. $item->sender,
  91. $item->mobile_sender,
  92. $item->logistic_number,
  93. $item->logistic_number_return,
  94. $item->logistic_name,
  95. $item->fee_collected,
  96. $item->loaded,
  97. $item->item_barcode,
  98. $item->item_name,
  99. $item->item_amount,
  100. $item->quality_label_name,
  101. $item->item_remark,
  102. $item->operator_name,
  103. $item->remark,
  104. ];
  105. }
  106. return Export::make($column,$list,"退货记录");
  107. Log::error(json_encode($request->header(),JSON_UNESCAPED_UNICODE));
  108. return json_encode($request->header(),JSON_UNESCAPED_UNICODE);
  109. }
  110. private function paramDefault($waybill):array
  111. {
  112. $update = [];
  113. if (!$waybill->order_type){
  114. $update["order_type"] = $waybill->order_type = Waybill::ORDER_TYPE_DEFAULT;
  115. }
  116. if (!$waybill->transport_type){
  117. $update["transport_type"] = $waybill->transport_type = "JZKH";
  118. }
  119. if (!$waybill->cargo_name){
  120. $update["cargo_name"] = $waybill->cargo_name = "补货";
  121. }
  122. if (!$waybill->total_number){
  123. $update["total_number"] = $waybill->total_number = 1;
  124. }
  125. if (!$waybill->total_weight){
  126. $update["total_weight"] = $waybill->total_weight = 1;
  127. }
  128. if (!$waybill->package_service){
  129. $update["package_service"] = $waybill->package_service = '托膜';
  130. }
  131. if (!$waybill->deliveryType_id){
  132. $update["deliveryType_id"] = $waybill->deliveryType_id = 3;
  133. }
  134. if (!$waybill->pay_type){
  135. $update["pay_type"] = $waybill->pay_type = Waybill::PAY_TYPE_DEFAULT;
  136. }
  137. if (!$waybill->back_sign_bill){
  138. $update["back_sign_bill"] = $waybill->back_sign_bill = Waybill::BACK_SIGN_BILL_DEFAULT;
  139. }
  140. return array($update,$waybill);
  141. }
  142. }