Browse Source

爬取卖家云订单脚本以及用户订单统计

shensong 5 years ago
parent
commit
77da5da3a9
1 changed files with 35 additions and 8 deletions
  1. 35 8
      app/Console/Commands/freightCost.php

+ 35 - 8
app/Console/Commands/freightCost.php

2
 
2
 
3
 use App\Order;
3
 use App\Order;
4
 use Illuminate\Console\Command;
4
 use Illuminate\Console\Command;
5
+use Illuminate\Support\Facades\DB;
5
 use Symfony\Component\Console\Input\InputOption;
6
 use Symfony\Component\Console\Input\InputOption;
6
 use Symfony\Component\Console\Input\InputArgument;
7
 use Symfony\Component\Console\Input\InputArgument;
7
 
8
 
33
 //        if(1 == $this->script){
34
 //        if(1 == $this->script){
34
 //            $this->getSession();
35
 //            $this->getSession();
35
 //        } else if(2 == $this->script){
36
 //        } else if(2 == $this->script){
37
+        try{
38
+            $message = ' info start';
39
+            $this->log($message);
36
             $this->getFreightCost();
40
             $this->getFreightCost();
41
+        } catch (\Exception $exception) {
42
+            $message = ' error line:'.$exception->getLine().' message:'.$exception->getMessage();
43
+            $this->log($message);
44
+        }
45
+
37
 //        }
46
 //        }
38
     }
47
     }
39
 
48
 
40
-    public function getSession() {
49
+    public function log($message = '') {
50
+        error_log(date('Y-m-d H:i:s',time()).$message." \n ",3,"/log/seafood_log/".date('Y-m-d',time()).'freightCost.log');
51
+//        print_r($message."\n");
52
+    }
53
+
54
+    public function getSession($times = 0) {
55
+        $message = ' info getSession';
56
+        $this->log($message);
41
         //获取图片验证码
57
         //获取图片验证码
42
         $imgArr = $this->getImage();
58
         $imgArr = $this->getImage();
43
         //百度OCR图片识别
59
         //百度OCR图片识别
83
         );
99
         );
84
 
100
 
85
         $res = $this->curlWithIpPorxy($method,$url,$params,$header);
101
         $res = $this->curlWithIpPorxy($method,$url,$params,$header);
86
-        return $res['words_result'][0]['words'];
102
+        if($res['words_result'][0]['words']){
103
+            return $res['words_result'][0]['words'];
104
+        } else {
105
+            $this->getSession();
106
+        }
107
+
87
     }
108
     }
88
 
109
 
89
     //卖家云登录接口获取HTSESSIONID
110
     //卖家云登录接口获取HTSESSIONID
106
 
127
 
107
     //根据日期获取发货订单列表
128
     //根据日期获取发货订单列表
108
     public function getFreightCost($times = 0) {
129
     public function getFreightCost($times = 0) {
130
+        $message = ' info getFreightCost times:'.$times.' page:'.$this->page;
131
+        $this->log($message);
109
         $url = 'http://erp.maijiayun.cn/dd/print/statistics/list/deliver.ht';
132
         $url = 'http://erp.maijiayun.cn/dd/print/statistics/list/deliver.ht';
110
         $method = 'post';
133
         $method = 'post';
111
 //        $startDate = '2019-10-15 00:00:00';
134
 //        $startDate = '2019-10-15 00:00:00';
112
-        $startDate = date('Y-m-d 00:00:00',strtotime('-5 days'));
135
+        $startDate = date('Y-m-d 00:00:00',strtotime('-30 days'));
113
         $endDate = date('Y-m-d 23:59:59',time());
136
         $endDate = date('Y-m-d 23:59:59',time());
114
 
137
 
115
         $params = array(
138
         $params = array(
136
 
159
 
137
         //失败次数超过3次自动停止
160
         //失败次数超过3次自动停止
138
         if($times >= 3){
161
         if($times >= 3){
139
-            print_r($res);
162
+//            print_r($res);
163
+            $message = ' fail getFreightCost times:'.$times.' page:'.$this->page;
164
+            $this->log($message);
140
             echo 'FAIL';die;
165
             echo 'FAIL';die;
141
         }
166
         }
142
 
167
 
158
         }
183
         }
159
     }
184
     }
160
 
185
 
161
-    //更新近十日订单
186
+    //更新近五日C仓订单
162
     public function updateFiveDaysOrder( $data ) {
187
     public function updateFiveDaysOrder( $data ) {
163
         foreach( $data as $value ) {
188
         foreach( $data as $value ) {
164
             if( $value['logisticsCost'] > 0 ){
189
             if( $value['logisticsCost'] > 0 ){
165
                 $freightCost = $value['logisticsCost'];
190
                 $freightCost = $value['logisticsCost'];
166
-                $re = Order::where('logistics_id',$value['expressCode'])->where('is_del',0)->where('warehouse',3)
191
+                $re = DB::table('order_copy')->where('logistics_id',$value['expressCode'])->where('is_del',0)->where('warehouse',3)
167
                     ->update(['freight_cost'=>$freightCost]);
192
                     ->update(['freight_cost'=>$freightCost]);
168
-                echo $value['expressCode'].' ';
193
+//                echo $value['expressCode'].' ';
194
+                $message = ' success update code:'.$value['logisticsCost'];
195
+                $this->log($message);
169
             } else {
196
             } else {
170
                 continue;
197
                 continue;
171
             }
198
             }
242
         if(preg_match('/Set-Cookie:[\s]+([^=]+)=([^;]+)/i', $result,$match)) {
269
         if(preg_match('/Set-Cookie:[\s]+([^=]+)=([^;]+)/i', $result,$match)) {
243
             $cookies[$match[1]] = $match[2];
270
             $cookies[$match[1]] = $match[2];
244
             $this->HTSESSIONID = $cookies['HTSESSIONID'];
271
             $this->HTSESSIONID = $cookies['HTSESSIONID'];
245
-            print_r($cookies['HTSESSIONID']);
272
+//            print_r($cookies['HTSESSIONID']);
246
             return $cookies['HTSESSIONID'];
273
             return $cookies['HTSESSIONID'];
247
 //            foreach ($cookies as $cookieKey => $cookieVal ) {
274
 //            foreach ($cookies as $cookieKey => $cookieVal ) {
248
 //                setcookie($cookieKey,$cookieVal);
275
 //                setcookie($cookieKey,$cookieVal);