Browse Source

监控异常运费订单

shensong00 4 years ago
parent
commit
3fd2f164ad
2 changed files with 106 additions and 0 deletions
  1. 105 0
      app/Console/Commands/MonitorEmptyFreightCost.php
  2. 1 0
      app/Console/Kernel.php

+ 105 - 0
app/Console/Commands/MonitorEmptyFreightCost.php

@@ -0,0 +1,105 @@
1
+<?php namespace App\Console\Commands;
2
+
3
+use Illuminate\Console\Command;
4
+use Illuminate\Support\Facades\DB;
5
+define("YP_SMS_KEY_1", "fbdb5f2ddae13c2f4a592348bfe52137");
6
+
7
+class MonitorEmptyFreightCost extends Command {
8
+
9
+
10
+    protected $name = 'MonitorEmptyFreightCost';
11
+    protected $description = '监控分销商C仓已发货订单运费是否需要手动处理';
12
+    protected $templateId = '3750860';
13
+    protected $phoneArr = ['13161864516'];
14
+    protected $dr_name = '清平乐';
15
+
16
+
17
+    public function __construct()
18
+    {
19
+        parent::__construct();
20
+    }
21
+
22
+    public function handle()
23
+    {
24
+        $this->MonitorEmptyFreightCost();
25
+    }
26
+
27
+    public function MonitorEmptyFreightCost()
28
+    {
29
+        //查询2天前C仓已发货但订单运费为0的订单
30
+        $endTime = date('Y-m-d', strtotime('-2 days'));
31
+        $orderIdList = DB::table('order')->where('send_time','<',$endTime)->where('warehouse',3)->where('is_del',0)
32
+            ->where('logistics_id','>','')->where('status',3)->whereNull('freight_cost')->lists('id');
33
+        if(count($orderIdList) > 0) {
34
+            foreach($this->phoneArr as $phone) {
35
+                $this->sendMsg($phone, $orderIdList);
36
+            }
37
+        }
38
+        echo 'SUCCESS';
39
+    }
40
+
41
+    public function sendMsg($phone, $orders)
42
+    {
43
+        $orders = json_encode($orders,JSON_UNESCAPED_UNICODE);//防止中文被转义
44
+        $params = ('#order#').'='.$orders;
45
+        //提醒销售
46
+        self::sendMsgWithParams($phone,$params, $this->templateId);
47
+    }
48
+
49
+    private static function init(){
50
+        $ch = curl_init();
51
+        /* 设置验证方式 */
52
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
53
+            'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
54
+        /* 设置返回结果为流 */
55
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
56
+
57
+        /* 设置超时时间*/
58
+        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
59
+
60
+        /* 设置通信方式 */
61
+        curl_setopt($ch, CURLOPT_POST, 1);
62
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
63
+        return $ch;
64
+
65
+    }
66
+    private static function checkErr($result,$error) {
67
+        if($result === false)
68
+        {
69
+            echo 'Curl error: ' . $error;
70
+        }
71
+//        else
72
+//        {
73
+//            echo '操作完成没有任何错误';
74
+//        }
75
+    }
76
+    private static function send($ch,$data){
77
+        curl_setopt ($ch, CURLOPT_URL, 'https://sms.yunpian.com/v2/sms/single_send.json');
78
+        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
79
+        $result = curl_exec($ch);
80
+        $error = curl_error($ch);
81
+        self::checkErr($result,$error);
82
+        return $result;
83
+    }
84
+
85
+    //有参数发送短信验证码
86
+    public static function sendMsgWithParams($phone, $params, $template_id) {
87
+        $ch=self::init();
88
+        $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone,'tpl_value'=>$params);
89
+        $json_data = self::send($ch,$data);
90
+        $array = json_decode($json_data,true);
91
+        curl_close($ch);
92
+        return $array;
93
+    }
94
+
95
+    //无参数发送短信验证码
96
+    public static function sendMsgSimple($phone, $template_id) {
97
+        $ch=self::init();
98
+        $data=array('tpl_id' => $template_id,'apikey'=>YP_SMS_KEY_1,'mobile'=>$phone);
99
+        $json_data = self::send($ch,$data);
100
+        $array = json_decode($json_data,true);
101
+        curl_close($ch);
102
+        return $array;
103
+    }
104
+
105
+}

+ 1 - 0
app/Console/Kernel.php

@@ -57,6 +57,7 @@ class Kernel extends ConsoleKernel {
57 57
         'App\Console\Commands\MonitorSkuToRedis',
58 58
         'App\Console\Commands\ErrorLogMonitor',
59 59
         'App\Console\Commands\GroupFanAmountByMonth',
60
+        'App\Console\Commands\MonitorEmptyFreightCost',
60 61
     ];
61 62
 
62 63
 	/**