xxxrrrdddd 3 年之前
父節點
當前提交
ecd43ff452

+ 1 - 1
addons/aliyunsms/config.php

@@ -126,7 +126,7 @@ return [
         'title' => '未支付通知模板',
         'type' => 'string',
         'content' => [],
-        'value' => '',
+        'value' => 'aaaaaaaaa',
         'rule' => '',
         'msg' => '',
         'tip' => '未支付通知模板',

+ 2 - 2
addons/aliyunsms/library/Aliyunsms.php

@@ -82,7 +82,7 @@ class Aliyunsms
             ->method('POST')
             ->host('dysmsapi.aliyuncs.com')
             ->options([
-                'query' => [
+                'query' => $allParams=[
                     'RegionId' => $this->config['regionId'],
                     'PhoneNumbers' => $this->_params['mobile'],
                     'SignName' => $this->config['signName'],
@@ -93,7 +93,7 @@ class Aliyunsms
             ->request();
 
         $result = $result->toArray();
-        user_log('sms',$result);
+        user_log('sms',compact('allParams','result'));
         if ($result['Code'] == "OK") {
             return true;
         } else {

+ 3 - 0
application/common/model/MobileOrder.php

@@ -77,6 +77,9 @@ class MobileOrder extends Model
     public function info(){
         return $this->hasOne(MobileOrderInfo::class);
     }
+    public function mind(){
+        return $this->hasOne(MobileOrderMind::class);
+    }
     public function operation(){
         return $this->hasMany(MobileOrderOperation::class)->order('mobile_order_operation.id','desc');
     }

+ 16 - 0
application/common/model/MobileOrderMind.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+use Yansongda\Supports\Str;
+
+/**
+ * 配置模型
+ */
+class MobileOrderMind extends Model
+{
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = true;
+    protected $updateTime=false;
+}

+ 16 - 8
commands/mobile_order_unpay_notify.php

@@ -1,11 +1,10 @@
 <?php
 use app\common\model\MobileOrder;
 use app\common\service\SmsSend;
-use think\Db;
-use think\Log;
+
 use Workerman\Worker as WO;
 
-class MobileOrderUnPayNotify{
+class MobileOrderUnPayNotify extends Com{
     public static function run()
     {
         $work=new WO();
@@ -18,17 +17,26 @@ class MobileOrderUnPayNotify{
                     ->whereNotExists('select * from mobile_order_mind where mobile_order.id=mobile_order_mind.mobile_order_id')
                     ->select()
                     ->toArray();
-                user_log(class_basename(__CLASS__),sprintf('%d条数据',count($orders)));
+                self::log(sprintf('%d条数据',count($orders)));
                 foreach ($orders as $orderId){
-                    $order=MobileOrder::find($orderId);
-                    if(!$order){
-                        continue;
+                    try {
+                        $order=MobileOrder::find($orderId);
+                        if(!$order){
+                            continue;
+                        }
+                        SmsSend::orderUnPay($order['phone'],$order['no']);
+                        $order->mind()->save([]);
+                    }catch (\Exception $e){
+                        self::logError($e);
                     }
-                    SmsSend::orderUnPay($order['phone'],$order['no']);
                 }
                 sleep(1);
             }
         };
     }
+
+    public static function logname(){
+        return class_basename(__CLASS__);
+    }
 }
 MobileOrderUnPayNotify::run();

+ 13 - 0
work

@@ -12,6 +12,19 @@ App::initCommon();
 WO::$logFile=sprintf('%s/workerman.log',RUNTIME_PATH);
 WO::$pidFile=sprintf('%s/workerman.pid',RUNTIME_PATH);
 
+abstract class Com{
+    protected static function log($data){
+        user_log('commands/'.class_basename(get_called_class()),$data);
+    }
+    protected static function logError(\Exception $exception){
+        user_log('commands/'.class_basename(get_called_class()),[
+            'exception'=>$exception->getMessage(),
+            'file'=>$exception->getFile().' line:'.$exception->getLine(),
+            'trace'=>$exception->getTrace()
+        ]);
+    }
+}
+
 //require __DIR__.'/commands/mobile_activity.php';
 //require __DIR__.'/commands/mobile_order_expired.php';
 require __DIR__.'/commands/mobile_order_unpay_notify.php';