Açıklama Yok

OrderExcelAdd.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Symfony\Component\Console\Input\InputOption;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use TopClient;
  7. use DB;
  8. use App\Order;
  9. use PHPExcel_Reader_Excel2007;
  10. use PHPExcel_Reader_Excel5;
  11. use PHPExcel;
  12. use PHPExcel_Writer_Excel2007;
  13. class OrderExcelAdd extends Command {
  14. protected $signature = 'OrderExcelAdd';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '导入订单';
  21. public function handle()
  22. {
  23. $this->OrderExcelAdd();
  24. }
  25. public function OrderExcelAdd(){
  26. $excelFile = './order_history.xlsx';
  27. //实例化Excel读取类
  28. $objReader = new PHPExcel_Reader_Excel2007();
  29. if(!$objReader->canRead($excelFile)){
  30. $objReader = new PHPExcel_Reader_Excel5();
  31. if(!$objReader->canRead($excelFile)){
  32. echo "\n".'无法识别的Excel文件!';
  33. return false;
  34. }
  35. }
  36. $objPHPExcel=$objReader->load($excelFile);
  37. $worksheet=$objPHPExcel->getSheet(0);//获取第一个工作表
  38. $highestRow=$worksheet->getHighestRow();//取得总行数
  39. $highestColumn=$worksheet->getHighestColumn(); //取得总列数
  40. $lines = $highestRow - 1;
  41. if ($lines <= 0) {
  42. //'Excel表格中没有数据';
  43. return false;
  44. }
  45. $errorArr=[];
  46. $okStr = '';
  47. for ($row = 2; $row <= $highestRow; ++$row) {
  48. $t = trim($worksheet->getCellByColumnAndRow(0, $row)->getValue());
  49. $n = intval(($t - 25569) * 3600 * 24);
  50. $createTime = gmdate('Y-m-d',$n);
  51. $receiverName = trim($worksheet->getCellByColumnAndRow(1, $row)->getValue());
  52. $receiverMobile = trim($worksheet->getCellByColumnAndRow(2, $row)->getValue());
  53. $receiverAddress = trim($worksheet->getCellByColumnAndRow(3, $row)->getValue());
  54. $goods_note = trim($worksheet->getCellByColumnAndRow(4, $row)->getValue());
  55. $receivedAmount = trim($worksheet->getCellByColumnAndRow(5, $row)->getValue());
  56. $f = trim($worksheet->getCellByColumnAndRow(7, $row)->getValue());
  57. if(!empty($f)){
  58. $n = intval(($f - 25569) * 3600 * 24);
  59. $fanTime = gmdate('Y-m-d',$n);
  60. }else{
  61. $fanTime = '';
  62. }
  63. $is_fugou = trim($worksheet->getCellByColumnAndRow(8, $row)->getValue());
  64. //数据库-新增数据
  65. $order = array();
  66. if( empty($receiverMobile) ){
  67. continue;
  68. }
  69. if( !empty($createTime) ){
  70. $order['createTime'] = date('Y-m-d H:i:s', strtotime($createTime));
  71. }
  72. if( !empty($receiverName) ){
  73. $order['receiverName'] = $receiverName;
  74. }
  75. if( !empty($receiverMobile) ){
  76. $order['receiverMobile'] = $receiverMobile;
  77. }
  78. if( !empty($receiverAddress) ){
  79. $order['receiverAddress'] = $receiverAddress;
  80. }
  81. if( !empty($goods_note) ){
  82. $order['goods_note'] = $goods_note;
  83. }
  84. if( !empty($receivedAmount) ){
  85. $order['receivedAmount'] = $receivedAmount;
  86. }
  87. if( empty($fanTime) ){
  88. $fanTime = $createTime;
  89. }
  90. if( !empty($is_fugou) ){
  91. $order['is_fugou'] = 1;
  92. }else{
  93. $order['is_fugou'] = 0;
  94. }
  95. $order['eshopCode'] = '99|34881'; //默认
  96. $order['outerCode'] = Order::createOuterCode();//随机生成
  97. $order['status'] = 0;
  98. $order['customerName'] = $order['receiverName']; //买家名称
  99. $order['shippingType'] = '卖家包邮';
  100. $order['expressCompanyCode'] = '10084';
  101. $order['expressCompanyName'] = '顺丰快递';
  102. $order['buyerPostageFee'] = 0; //买家邮费
  103. $order['discountFee'] = 0; //订单优惠
  104. $order['adjustFee'] = 0; //订单调价
  105. $order['serviceFee'] = 0; //服务费
  106. $order['paymentMethod'] = '在线付款';
  107. $order['paymentType'] = '网银';
  108. $order['paymentAccount'] = '18322225555'; // 付款账号,暂时默认写死
  109. $order['paymentTime'] = $order['createTime']; // 付款时间
  110. $order['warehouse'] = 0; //仓库
  111. $order['delivery_date'] = $createTime; //发货日期
  112. #更新客户表
  113. $customer = array();
  114. $customers['name'] = $receiverName;
  115. $customers['receiverAddress'] = $receiverAddress;
  116. $if_e = DB::table('customers')->select('id')->where('phone', $order['receiverMobile'])->first();
  117. if(isset($if_e->id)){
  118. //$up_c = DB::table('customers')->where('id', $if_e->id)->update($customers);
  119. }else{
  120. $customers['phone'] = $order['receiverMobile'];
  121. $customers['fanTime'] = $fanTime;
  122. $customers['is_fugou'] = $order['is_fugou'];
  123. $in_c = DB::table('customers')->insert($customers);
  124. }
  125. $order['admin_id'] = 3;
  126. $order['admin_name'] = '测试账号';
  127. $order['team_id'] = 4;
  128. $res = DB::table('order')->insert($order);
  129. echo "\n行数:".$row. " 结果:".$res;
  130. }
  131. }
  132. }