Browse Source

mch task‘

xiaoyu 2 years atrás
parent
commit
93e4f69d12
2 changed files with 56 additions and 2 deletions
  1. 2 2
      helper/task/manager.php
  2. 54 0
      mchsrv/control/merchant_order.php

+ 2 - 2
helper/task/manager.php

@@ -13,7 +13,7 @@ class manager
         $this->mHandler = new handler();
     }
 
-    public function add_task($method,$params,$is_show = 1,$del_timeout = -1,$title='')
+    public function add_task($method, $params, $is_show = 1, $del_timeout = -1, $title = '', $mchid = 0)
     {
         if(empty($method) || empty($params)) {
             return false;
@@ -46,7 +46,7 @@ class manager
         {
             $item = ['type' => $method, 'title' => $title,
                      'params' => serialize($params), 'task_hash' => $task_hash,
-                     'add_time' => time(), 'is_show' => $is_show];
+                     'add_time' => time(), 'is_show' => $is_show, 'mchid' => $mchid];
             $task_id = $mod_task->insert($item);
             $item = $mod_task->where(['task_id' => $task_id])->master(true)->find();
         }

+ 54 - 0
mchsrv/control/merchant_order.php

@@ -413,4 +413,58 @@ class merchant_orderControl extends mbMerchantControl
 
         return ['title' => $title , 'data' => $datas];
     }
+
+    public function create_taskOp()
+    {
+        if(empty($_GET['time_type']) || empty($_GET['start_time']) || empty($_GET['end_time'])) {
+            return self::outerr(errcode::ErrInputParam, "参数错误.");
+        }
+        $normal_cond['inner_status'] = 0;
+        $normal_cond['order_state'] = ORDER_STATE_SUCCESS;
+        $time_type = $_GET['time_type'];
+        $start = $_GET['start_time'];
+        $end = $_GET['end_time'];
+        $title = $_GET['task_title'] ?? '';
+
+        $start_date = strtotime(date('Y-m-d',$start));
+        $end_date = strtotime(date('Y-m-d',$end));
+        $today = strtotime(date('Y-m-d',time()));
+        $tomorrow = $today + 86400;
+
+        if ($time_type === 'order_time')
+        {
+            $add_end = $end_date + 86400 * 5;
+            if($add_end > $tomorrow) {
+                $add_end = $tomorrow;
+            }
+            $scope = ['order_time' => [$start, $end], 'add_time' => [$start, $add_end]];
+        } elseif ($time_type === 'notify_time') {
+            $add_begin = $start_date - 86400 * 5;
+            $scope = ['order_time' => [$add_begin, $end], 'add_time' => [$add_begin, $end], 'notify_time' => [$start, $end]];
+        } else {
+            return self::outerr(errcode::ErrInputParam, "筛选日期类型错误.");
+        }
+        $manager = new task\manager();
+
+        $cond = ['normal' => $normal_cond, 'time_scope' => $scope, 'export_type' => 'merchant'];
+
+        $task = $manager->add_task('refill_order_export',$cond,1,-1, $title, $this->mchid());
+        $file_path = '';
+        if ($task->completed() && $task->success()) {
+            $file_name = $task->result();
+            $file_path = UPLOAD_SITE_URL . '/' . ATTACH_TASK . DS . $file_name;
+        }
+        return self::outsuccess(['file_path' => $file_path]);
+    }
+
+    public function task_listOp()
+    {
+        $model = Model('task');
+        $condition['is_show'] = 1;
+        $condition['mchid'] = $this->mchid();
+        $task_list = $model->getList($condition, $this->page, '*', 'add_time desc', 20);
+        $result['data'] = $task_list;
+        $result['total'] = $model->gettotalpage();
+        return self::outsuccess($result);
+    }
 }