rabin 1 年間 前
コミット
4cf1921a38
54 ファイル変更2271 行追加393 行削除
  1. 83 0
      src/bao/connect/api/Notify.php
  2. 8 86
      src/bao/connect/lib/Func/Api.php
  3. 168 90
      src/bao/connect/lib/Func/Base.php
  4. 20 0
      src/bao/connect/table/api.php
  5. 0 39
      src/bao/connect/table/api_notify.php
  6. 0 6
      src/bao/connect/table/api_notify_code.php
  7. 48 0
      src/bao/connect/table/api_uri.php
  8. 26 0
      src/bao/connect/table/info.php
  9. 1 0
      src/bao/connect/table/manage/api.php
  10. 13 0
      src/bao/connect/table/manage/api_notify_code.php
  11. 2 0
      src/bao/connect/table/manage/api_request_body.php
  12. 2 0
      src/bao/connect/table/manage/api_request_header.php
  13. 12 0
      src/bao/connect/table/manage/api_response.php
  14. 14 0
      src/bao/connect/table/manage/api_uri.php
  15. 21 13
      src/bao/connect/table/manage/connect_api.php
  16. 15 11
      src/bao/connect/table/manage/connect_info.php
  17. 1 1
      src/bao/connect/table/manage/core.php
  18. 2 2
      src/dai/channel/api/Manage.php
  19. 1 1
      src/dai/channel/lib/Manage.php
  20. 6 0
      src/dai/channel/table/info.php
  21. 3 1
      src/dai/channel/table/manage/goods.php
  22. 15 0
      src/dai/channel/table/manage/info.php
  23. 12 0
      src/dai/channel/table/manage/set.php
  24. 25 0
      src/dai/channel/table/set.php
  25. 0 10
      src/dai/seller/api/Channel.php
  26. 41 0
      src/dai/seller/api/Manage.php
  27. 68 58
      src/dai/seller/api/Order.php
  28. 201 0
      src/dai/seller/api/Task.php
  29. 19 0
      src/dai/seller/api/Test.php
  30. 40 0
      src/dai/seller/lib/Info.php
  31. 316 1
      src/dai/seller/lib/Manage.php
  32. 145 42
      src/dai/seller/lib/Order.php
  33. 8 0
      src/dai/seller/table/info.php
  34. 55 0
      src/dai/seller/table/log.php
  35. 53 2
      src/dai/seller/table/manage/core.php
  36. 11 3
      src/dai/seller/table/manage/info.php
  37. 104 0
      src/dai/seller/table/manage/log.php
  38. 85 19
      src/dai/seller/table/manage/order_list.php
  39. 110 0
      src/dai/seller/table/manage/order_log_list.php
  40. 46 0
      src/dai/seller/table/manage/order_push.php
  41. 49 0
      src/dai/seller/table/manage/order_stat.php
  42. 51 0
      src/dai/seller/table/manage/order_stat_channel.php
  43. 51 0
      src/dai/seller/table/manage/order_stat_seller.php
  44. 75 3
      src/dai/seller/table/order.php
  45. 15 0
      src/dai/seller/table/order_bak.php
  46. 4 0
      src/dai/seller/table/order_log.php
  47. 38 0
      src/dai/seller/table/order_push.php
  48. 73 0
      src/dai/seller/table/order_stat.php
  49. 15 0
      src/dai/seller/table/order_stat_channel.php
  50. 15 0
      src/dai/seller/table/order_stat_seller.php
  51. 1 1
      src/yuan/goods/api/Manage.php
  52. 60 4
      src/yuan/goods/lib/Manage.php
  53. 1 0
      src/yuan/goods/table/cate.php
  54. 23 0
      src/yuan/goods/table/manage/cate.php

+ 83 - 0
src/bao/connect/api/Notify.php

@@ -0,0 +1,83 @@
+<?php namespace Connect\Api;
+use Dever;
+use Connect\Lib\Func\Api;
+class Notify extends Api
+{
+    public function common()
+    {
+        //$param = '{"s":"132dcszvteLAx3r5eKrjarbGyJilBFECGu2F7mCX-H6K2_w","appid":"app483393213726","order_id":"Q202401040798155761553480","merchant_order_id":"yk18f2401040253000002","status":2,"cash":1000,"msg":"充值成功","actual_cash":1004.9999999999999,"time":1704308034101,"nonce":"fa0912fcfeb3ddfec4e821c26","signature":"d58295706e069e61a4a4ef9428ae0d155b36fae6"}';
+        //$input = Dever::json_decode($param);
+        $input = Dever::input();
+        Dever::log($input, 'notify');
+        if (!isset($input['s'])) {
+            $this->error('error');
+        }
+        $s = \Dever\Helper\Str::decode($input['s']);
+        list($connect_id, $api_id, $order_id) = explode('|', $s);
+        unset($input['s']);
+        $this->connect = Dever::db('info', 'connect')->find($connect_id);
+        $this->info = Dever::db('api', 'connect')->find($api_id);
+        $order = Dever::db('order', 'seller')->find($order_id);
+        if (!$order || $order['status'] >= 10) {
+            $this->error('order error');
+        }
+        $channel = Dever::db('info', 'channel')->find($order['channel_id']);
+        if (!$channel) {
+            $this->error('channel error');
+        }
+        $this->connect['appsecret'] = $channel['appsecret'];
+
+        $code = Dever::db('api_notify_code', 'connect')->select(array('api_id' => $api_id));
+
+        $status = 0;
+        if ($code) {
+            foreach ($code as $k => $v) {
+                if (isset($input[$v['key']]) && $input[$v['key']] == $v['value']) {
+                    $status = $v['type'];
+                }
+            }
+        }
+        $data = $input;
+        $data['status'] = $status;
+        $data = $this->service($data);
+
+        $msg = '';
+        if ($status == 1) {
+            $msg = 'ok';
+        } elseif ($status == 2) {
+            $msg = 'error';
+        }
+        if ($this->info['notify_sign_col']) {
+            $this->info['sign_col'] = $this->info['notify_sign_col'];
+        }
+        if ($sign = Dever::isset($input, $this->connect['sign_name'])) {
+            unset($input[$this->connect['sign_name']]);
+            unset($input['l']);
+            if ($sign != $this->sign($input)) {
+                $this->error('sign error');
+            }
+        }
+        if ($msg) {
+            $update = array();
+            $update['official_msg'] = $data['official_msg'] ?? '';
+            $update['official_order_num'] = $data['official_order_num'] ?? '';
+            $update['channel_callback'] = Dever::json_encode($input);
+            $update['channel_callback_date'] = time();
+            Dever::load('order', 'seller')->notify($order, $msg, $update);
+        }
+        echo $this->info['notify_success'];die;
+    }
+
+    private function error($msg)
+    {
+        if ($this->info['notify_error']) {
+            if ($this->info['notify_error'] == 500) {
+                header("HTTP/1.1 500 Internal Server Error");
+                header("Status: 500 Internal Server Error");
+            } else {
+                echo $this->info['notify_error'];die;
+            }
+        }
+        echo $msg;die;
+    }
+}

+ 8 - 86
src/bao/connect/lib/Func/Api.php

@@ -5,103 +5,25 @@ class Api extends Base
     protected $type = 'api';
 
     # 执行某个业务接口
-    public function run($type, $channel, $param = array())
+    public function run($type, $cate_id, $channel, $param = array())
     {
-        $state = $this->setting($type, $channel, $param);
+        $state = $this->setting($type, $cate_id, $channel, $param);
         if (!$state) {
             return $state;
         }
         return $this->curl();
     }
 
-    # 回调
-    public function notify_commit(){}
-    public function notify()
-    {
-        $input = Dever::input();
-        $log['type'] = 'notify';
-        $log['data'] = $input;
-        Dever::log($log, 'channel');
-
-        $this->init();
-
-        $code = Dever::db('channel/connect_api_notify_code')->select(array('api_id' => $this->info['id']));
-
-        $notify = Dever::db('channel/connect_api_notify')->select(array('api_id' => $this->info['id']));
-
-        $result = 'error';
-        $status = 0;
-        if ($code) {
-            foreach ($code as $k => $v) {
-                if (isset($input[$v['key']]) && $input[$v['key']] == $v['value']) {
-                    $status = $v['type'];
-                }
-            }
-        }
-
-        if ($status == 1) {
-            $result = $this->info['notify_notify_success'];
-        }
-
-        if ($notify) {
-            foreach ($notify as $k => $v) {
-                if (isset($input[$v['key']])) {
-                    $input[$v['key']] = $this->value($input, $v['key'], $v['key'], $v['type'] * 100);
-                }
-            }
-        }
-
-        $input['status'] = $status;
-
-        # 业务处理
-        $this->service($input);
-
-        return $result;
-    }
-
-    # 获取token
-    public function token($channel, $connect, $api, $type = 'token')
-    {
-        $db = Dever::db('channel/connect_' . $type);
-        $data['connect_id'] = $connect['id'];
-        $data['api_id'] = $api['id'];
-        $info = $db->find($data);
-        if ($info && time() - $info['mdate'] >= $info['expires']) {
-            
-        } elseif ($info) {
-            return $info['value'];
-        }
-        $this->channel = $channel;
-        $this->connect = $connect;
-        $this->info = $api;
-        $result = $this->init()->curl();
-        if (isset($result[$type])) {
-            $data['value'] = $result[$type];
-            $data['expires'] = '7200';
-            if (isset($result['expires'])) {
-                $data['expires'] = $result['expires'];
-            }
-            if ($info) {
-                $data['where_id'] = $info['id'];
-                $db->update($data);
-            } else {
-                $db->insert($data);
-            }
-            return $result[$type];
-        }
-        return '';
-    }
-
     # 构建请求头
     protected function requestHeader(&$header)
     {
-    	$this->request($header, 'api_request_header', array('api_id' => $this->info['id']));
+        $this->request($header, 'api_request_header', array('api_id' => $this->info['id']));
     }
 
     # 构建请求体
     protected function requestBody(&$body)
     {
-    	$this->request($body, 'api_request_body', array('api_id' => $this->info['id']));
+        $this->request($body, 'api_request_body', array('api_id' => $this->info['id']));
     }
 
     # 数据响应格式处理
@@ -115,13 +37,13 @@ class Api extends Base
                 }
             }
         }
-        # 业务处理
         $data = $this->service($data);
     }
 
-    protected function createNotify()
+    # 生成回调
+    protected function createNotify($order_id)
     {
-        $encode = Dever::encode($this->connect['id'] . '|' . $this->info['id']);
-        return Dever::url('api.notify?s=' . $encode, 'connect');
+        $encode = \Dever\Helper\Str::encode($this->connect['id'] . '|' . $this->info['id'] . '|' . $order_id);
+        return Dever::url('connect/notify.common', array('s' => $encode));
     }
 }

+ 168 - 90
src/bao/connect/lib/Func/Base.php

@@ -6,21 +6,31 @@ class Base
     protected $info;
     protected $domain;
     protected $param = array();
-    protected $signname = 'signature';
 
     # 设置基本信息
-    protected function setting($type, $channel, $param = array())
+    protected function setting($type, $cate_id, $channel, $param = array())
     {
         $this->connect = Dever::db('info', 'connect')->find($channel['connect_id']);
         if (!$this->connect) {
             return false;
         }
+        $this->connect['channel_id'] = $channel['id'];
         $this->connect['host'] = $channel['host'];
         $this->connect['appkey'] = $channel['appkey'];
         $this->connect['appsecret'] = $channel['appsecret'];
-        $this->info = Dever::db('api', 'connect')->find(array('type' => $type, 'connect_id' => $this->connect['id']));
+        $set = Dever::db('set', 'channel')->select(array('channel_id' => $channel['id']));
+        $this->connect['set'] = array();
+        if ($set) {
+            foreach ($set as $k => $v) {
+                $this->connect['set'][$v['key']] = $v['value'];
+            }
+        }
+        $this->info = Dever::db($this->type, 'connect')->find(array('type' => $type, 'cate_id' => $cate_id, 'connect_id' => $this->connect['id']));
         if (!$this->info) {
-            return false;
+            $this->info = Dever::db($this->type, 'connect')->find(array('type' => $type, 'connect_id' => $this->connect['id']));
+            if (!$this->info) {
+                return false;
+            }
         }
         $this->param = $param;
         return $this;
@@ -60,21 +70,23 @@ class Base
             $this->requestBody($body);
         }
         $this->sign($body);
-
-        $log['type'] = 'request';
-        $log['url'] = $url;
-        $log['body'] = $body;
-        $log['method'] = $method;
-        $log['json'] = $json;
-        $log['header'] = $header;
-        Dever::log($log, 'api');
-
-        print_r($body);die;
-
-        $response = Dever::curl($url, $body, $method, $json, $header);
+        $response = Dever::curl($url, $body, $method, $json, $header)->result();
+        $test = Dever::input('test');
+        if ($test && $test == 1) {
+            $result = array
+            (
+                'url' => $url,
+                'header' => $header,
+                'method' => $method,
+                'json' => $json,
+                'body' => $body,
+                'response' => $response,
+            );
+            echo Dever::json_encode($result);die;
+        }
+        //$response = '{"code":1,"info":"ok","data":{"order":"Q202401037683854738260576","account":"15810090845","status":1}}';
         $response = $this->response($response);
-        $response['request'] = $log;
-
+        $response['request'] = $body;
         return $response;
     }
 
@@ -84,6 +96,34 @@ class Base
         if (strstr($this->info['uri'], 'http')) {
             $this->connect['host'] = '';
         }
+        $uri = Dever::db('api_uri', 'connect')->select(array('api_id' => $this->info['id']));
+        if ($uri) {
+            $path = array();
+            $param = array();
+            foreach ($uri as $k => $v) {
+                $v['value'] = $this->value(array(), $v['key'], $v['value']);
+                if ($v['type'] == 1) {
+                    $path[] = $v['value'];
+                } elseif ($v['type'] == 2) {
+                    $path[] = $v['key'] . '/' . $v['value'];
+                } elseif ($v['type'] == 3) {
+                    $path[] = $v['key'] . '=' . $v['value'];
+                } elseif ($v['type'] == 4) {
+                    $param[] = $v['value'];
+                } elseif ($v['type'] == 5) {
+                    $param[] = $v['key'] . '=' . $v['value'];
+                }
+            }
+            if ($path) {
+                $this->info['uri'] .= implode('/', $path);
+            }
+            if ($param) {
+                if (!strstr($this->info['uri'], '?')) {
+                    $this->info['uri'] .= '?';
+                }
+                $this->info['uri'] .= implode('&', $param);
+            }
+        }
         return $this->domain = $this->connect['host'] . $this->info['uri'];
     }
 
@@ -94,7 +134,7 @@ class Base
         if ($body) {
             foreach ($body as $k => $v) {
                 $value = $this->value($data, $v['key'], $v['default'], $v['type']);
-                if ($value || Dever::zero($value)) {
+                if ($value) {
                     $data[$v['key']] = $value;
                 }
             }
@@ -104,36 +144,31 @@ class Base
     # 数据响应格式处理
     protected function response($response)
     {
-        $log['type'] = 'response';
-        $log['data'] = $response;
-        Dever::log($log, 'api');
-
         if ($this->connect['response_type'] == 1) {
             $response = $this->filter($response);
-        	return array
-	        (
-	            'status' => 1,
-	            'msg' => 'ok',
-	            'response' => false,
-	            'request' => array(),
-	            'data' => $response,
-	        );
+            return array
+            (
+                'status' => 1,
+                'msg' => 'ok',
+                'response' => false,
+                'request' => array(),
+                'data' => $response,
+            );
         }
         if ($this->connect['response_type'] == 2) {
             $response = Dever::json_decode($response);
         } elseif ($this->connect['response_type'] == 3) {
             $response = (array) simplexml_load_string($response);
         } else {
-        	if (strstr($response, ',')) {
-        		$response = explode(',', $response);
-        	} elseif (strstr($response, ' ')) {
-        		$response = explode(' ', $response);
-        	} elseif (strstr($response, '|')) {
-        		$response = explode('|', $response);
-        	} else {
-        		$response = explode("\n", $response);
-        	}
-
+            if (strstr($response, ',')) {
+                $response = explode(',', $response);
+            } elseif (strstr($response, ' ')) {
+                $response = explode(' ', $response);
+            } elseif (strstr($response, '|')) {
+                $response = explode('|', $response);
+            } else {
+                $response = explode("\n", $response);
+            }
         }
         $msg = '';
         $status = 2;
@@ -143,7 +178,7 @@ class Base
                 $status = 1;
             }
         }
-        $msg = $response[$this->connect['response_msg']] ?? : 'no';
+        $msg = $response[$this->connect['response_msg']] ?? 'no';
         $data = '';
         if (strstr($this->connect['response_data'], ',')) {
             $temp = explode(',', $this->connect['response_data']);
@@ -176,102 +211,125 @@ class Base
 
     protected function sign(&$body)
     {
-        $config = Dever::db('sign', 'connect')->find(array('connect_id' => $this->connect['id']));
-        if (!$config || ($config && $config['method'] == 1)) {
+        if ($this->connect['sign_method'] == 1) {
             return;
         }
+        if (!$this->connect['sign_name']) {
+            $this->connect['sign_name'] = 'signature';
+        }
         $sign = array();
-        if ($config['col']) {
-            $col = explode('+', $config['col']);
+        if ($this->info['sign_col']) {
+            $col = explode('+', $this->info['sign_col']);
             foreach ($col as $k => $v) {
                 $sign[$v] = $this->value($body, $v, $v, 1);
             }
-        }
-        if ($this->info && isset($this->info['sign_col']) && $this->info['sign_col']) {
-            $col = explode('+', $this->info['sign_col']);
+        } elseif ($this->connect['sign_col']) {
+            $col = explode('+', $this->connect['sign_col']);
             foreach ($col as $k => $v) {
                 $sign[$v] = $this->value($body, $v, $v, 1);
             }
+        } else {
+            $sign = $body;
         }
 
-        if ($config['sort'] == 2) {
+        if ($this->connect['sign_appsecret'] && $this->connect['sign_appsecret_location'] == 1) {
+            $sign[$this->connect['sign_appsecret']] = $this->connect['appsecret'];
+        }
+
+        if ($this->connect['sign_sort'] == 2) {
             ksort($sign);
         }
 
         $string = '';
         foreach ($sign as $k => $v) {
-            if ($config['empty'] == 2 && !Dever::zero($v) && !$v) {
+            if ($this->connect['sign_empty'] == 2 && !$v) {
                 continue;
             }
-            if ($config['encode'] == 2 && strstr($v, 'http')) {
+            if ($this->connect['sign_encode'] == 2 && strstr($v, 'http')) {
                 $v = urlencode($v);
             }
-            if ($config['type'] == 1) {
+            if ($this->connect['sign_type'] == 1) {
                 $string .= $v;
-            } else {
+            } elseif ($this->connect['sign_type'] == 2) {
                 $string .= $k . '=' . $v . '&';
+            } elseif ($this->connect['sign_type'] == 3) {
+                $string .= $k . $v;
+            } elseif ($this->connect['sign_type'] == 4) {
+                $string .= $k . $v . '&';
             }
         }
 
         $sign = rtrim($string, '&');
 
+        if ($this->connect['sign_appsecret'] && $this->connect['sign_appsecret_location'] == 2) {
+            if ($this->connect['sign_type'] == 1) {
+                $sign .= $this->connect['appsecret'];
+            } elseif ($this->connect['sign_type'] == 2) {
+                $sign .= '&' . $this->connect['sign_appsecret'] . '=' . $this->connect['appsecret'];
+            } elseif ($this->connect['sign_type'] == 3) {
+                $sign .= $this->connect['sign_appsecret'] . $this->connect['appsecret'];
+            } elseif ($this->connect['sign_type'] == 4) {
+                $sign .= '&' . $this->connect['sign_appsecret'] . $this->connect['appsecret'];
+            }
+        }
+
         # 如果是ssl 这里需要处理一下,后续处理吧
 
-        if ($config['method'] == 2) {
+        if ($this->connect['sign_method'] == 2) {
             $sign = md5($sign);
-        } elseif ($config['method'] == 3) {
+        } elseif ($this->connect['sign_method'] == 3) {
             $sign = hash("sha256", $sign);
-        } elseif ($config['method'] == 4) {
+        } elseif ($this->connect['sign_method'] == 4) {
             $sign = sha1($sign);
         }
 
-        if ($config['after'] == 2) {
+        if ($this->connect['sign_after'] == 2) {
             $sign = strtoupper($sign);
-        } elseif ($config['after'] == 2) {
+        } elseif ($this->connect['sign_after'] == 2) {
             $sign = strtolower($sign);
         }
 
-        $body[$this->signname] = $sign;
+        $body[$this->connect['sign_name']] = $sign;
+        return $sign;
     }
 
-    protected function value(&$data, $key, $value, $type = 1)
+    protected function value($data, $key, $value, $type = 1)
     {
-        $key = trim($key);
         $value = trim($value);
 
         if ($this->param && isset($this->param[$value])) {
             $value = $this->param[$value];
         } elseif ($data && isset($data[$value])) {
             $value = $data[$value];
+        } elseif (isset($this->connect['set'][$value]) && $this->connect['set'][$value]) {
+            $value = $this->connect['set'][$value];
         } elseif (isset($this->connect[$value]) && $this->connect[$value]) {
             $value = $this->connect[$value];
-        } elseif (isset($this->channel[$value]) && $this->channel[$value]) {
-            $value = $this->channel[$value];
-        } elseif ($value == 'signature') {
-            $this->signname = $key;
         } elseif ($value == 'notify') {
-            $value = $this->createNotify();
+            $value = $this->createNotify($this->param['order_id'] ?? '');
         } elseif ($value == 'api_request') {
             $value = $data;
         } elseif ($value == 'timestamp') {
-            $value = Dever::timestamp();
+            $value = \Dever\Helper\Secure::timestamp();
         } elseif ($value == 'nonce') {
-            $value = Dever::nonce();
+            $value = \Dever\Helper\Secure::nonce();
         } elseif ($value == 'token') {
             $value = $this->token(1, 'token');
         } elseif ($value == 'ticket') {
             $value = $this->token(2, 'ticket');
-        } elseif (strstr($value, 'Dever::')) {
+        } elseif ($a = strstr($value, '{') || strstr($value, '(')) {
+            if ($a) {
+                $func = function ($r) use($data) {
+                    return $this->value($data, $r[1], $r[1]);
+                };
+                $value = preg_replace_callback('/{(.*?)}/', $func, $value);
+            }
             $value = '$value = '.$value.';';
             eval($value);
-        } else {
-        	$set = Dever::db('channel/info_set')->find(array('info_id' => $this->channel['id'], 'key' => $value));
-        	if ($set) {
-        		$value = $set['value'];
-        	}
         }
 
-        if (!Dever::zero($value) && !$value) {
+        if (!$value) {
+            $key = trim($key);
             return Dever::input($key);
         }
 
@@ -294,7 +352,7 @@ class Base
 
     protected function service($data)
     {
-    	# 转换处理
+        # 转换处理
         $convert = Dever::db('convert', 'connect')->select(array('connect_id' => $this->connect['id']));
 
         $param = array();
@@ -318,26 +376,46 @@ class Base
             $param = $data;
         }
 
-        Dever::load('channel/lib/service')->act($this->channel['id'], $this->info['service_id'], $this->type, $this->info['id'], $param);
+        # 具体业务处理,这里先不做
+        //Dever::load('channel/lib/service')->act($this->channel['id'], $this->info['service_id'], $this->type, $this->info['id'], $param);
         return $param;
     }
 
     protected function token($id = 1, $type = 'token')
     {
-        $api = Dever::db('api', 'connect')->find(array('connect_id' => $this->connect['id'], 'service_id' => $id));
-        if ($api) {
-            return Dever::load('channel/lib/api')->token($this->channel, $this->connect, $api, $type);
-        } else {
-            return 'error';
+        return '';
+        $db = Dever::db($type, 'connect');
+        $data['connect_id'] = $connect['id'];
+        $data['api_id'] = $api['id'];
+        $info = $db->find($data);
+        if ($info && time() - $info['mdate'] >= $info['expires']) {
+            
+        } elseif ($info) {
+            return $info['value'];
+        }
+        $result = $this->init()->curl();
+        if (isset($result[$type])) {
+            $data['value'] = $result[$type];
+            $data['expires'] = '7200';
+            if (isset($result['expires'])) {
+                $data['expires'] = $result['expires'];
+            }
+            if ($info) {
+                $data['where_id'] = $info['id'];
+                $db->update($data);
+            } else {
+                $db->insert($data);
+            }
+            return $result[$type];
         }
+        return '';
     }
 
     protected function encrypt($value)
     {
-        $config = Dever::db('ssl', 'connect')->find(array('connect_id' => $this->connect['id']));
-        if ($config && $config['method'] && $config['key']) {
-            $value = openssl_encrypt($value, $config['method'], $config['key'], $config['option'], $config['iv']);
-            if ($config['after'] == 2) {
+        if ($this->connect['ssl_method'] && $this->connect['ssl_key']) {
+            $value = openssl_encrypt($value, $this->connect['ssl_method'], $this->connect['ssl_key'], $this->connect['ssl_option'], $this->connect['ssl_iv']);
+            if ($this->connect['ssl_after'] == 2) {
                 $value = base64_encode($value);
             }
         }
@@ -347,12 +425,12 @@ class Base
 
     protected function decrypt($value)
     {
-        if ($config['method'] && $config['key']) {
+        if ($this->connect['ssl_method'] && $this->connect['ssl_key']) {
             if (is_array($value)) {
                 $value = Dever::json_encode($value);
             }
-            $value = openssl_decrypt($value, $config['method'], $config['key'], $config['option'], $config['iv']);
-            if ($config['after'] == 2) {
+            $value = openssl_decrypt($value, $this->connect['ssl_method'], $this->connect['ssl_key'], $this->connect['ssl_option'], $this->connect['ssl_iv']);
+            if ($this->connect['ssl_after'] == 2) {
                 $value = base64_decode($value);
             }
         }

+ 20 - 0
src/bao/connect/table/api.php

@@ -35,6 +35,14 @@ return array
             'type'      => 'varchar(1000)',
         ),
 
+        'cate_id' => array
+        (
+            'name'      => '商品分类',
+            'type'      => 'tinyint(1)',
+            'default'   => '-1',
+            'value'     => 'Dever::load("goods/manage.getCate")',
+        ),
+
         'sign_col' => array
         (
             'name'      => '签名加密参数',
@@ -84,5 +92,17 @@ return array
             'name'      => '回调成功响应',
             'type'      => 'varchar(500)',
         ),
+
+        'notify_error' => array
+        (
+            'name'      => '回调失败响应',
+            'type'      => 'varchar(500)',
+        ),
+
+        'notify_sign_col' => array
+        (
+            'name'      => '签名加密参数',
+            'type'      => 'varchar(1000)',
+        ),
     ),
 );

+ 0 - 39
src/bao/connect/table/api_notify.php

@@ -1,39 +0,0 @@
-<?php
-return array
-(
-    'name' => '回调参数配置',
-    'struct' => array
-    (
-        'api_id' => array
-        (
-            'name'      => '接口id',
-            'type'      => 'int(11)',
-        ),
-
-        'name' => array
-        (
-            'name'      => '接口名称',
-            'type'      => 'varchar(150)',
-        ),
-
-        'key' => array
-        (
-            'name'      => '参数标识',
-            'type'      => 'varchar(150)',
-        ),
-
-        'type' => array
-        (
-            'name'      => '参数类型',
-            'type'      => 'tinyint(1)',
-            'default'   => '1',
-            'value'     => array
-            (
-                1 => '字符串',
-                2 => '数值',
-                3 => 'JSON',
-                4 => '对称加密',
-            ),
-        ),
-    ),
-);

+ 0 - 6
src/bao/connect/table/api_notify_code.php

@@ -10,12 +10,6 @@ return array
             'type'      => 'int(11)',
         ),
 
-        'name' => array
-        (
-            'name'      => '接口名称',
-            'type'      => 'varchar(150)',
-        ),
-
         'key' => array
         (
             'name'      => '状态码标识',

+ 48 - 0
src/bao/connect/table/api_uri.php

@@ -0,0 +1,48 @@
+<?php
+return array
+(
+    'name' => '接口地址参数',
+    'order' => 'sort asc',
+    'struct' => array
+    (
+        'api_id' => array
+        (
+            'name'      => '接口id',
+            'type'      => 'int(11)',
+        ),
+
+        'key' => array
+        (
+            'name'      => '参数标识',
+            'type'      => 'varchar(150)',
+        ),
+
+        'value' => array
+        (
+            'name'      => '参数值',
+            'type'      => 'varchar(150)',
+        ),
+
+        'type' => array
+        (
+            'name'      => '参数位置',
+            'type'      => 'tinyint(1)',
+            'default'   => '1',
+            'value'     => array
+            (
+                1 => '接口路径:value形式',
+                2 => '接口路径:key/value形式',
+                3 => '接口路径:key=value形式',
+                4 => '接口参数:value形式',
+                5 => '接口参数:key=value形式',
+            ),
+        ),
+
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+    ),
+);

+ 26 - 0
src/bao/connect/table/info.php

@@ -66,6 +66,12 @@ return array
             'type'      => 'varchar(100)',
         ),
 
+        'sign_name' => array
+        (
+            'name'      => '签名名称',
+            'type'      => 'varchar(100)',
+        ),
+
         'sign_method' => array
         (
             'name'      => '签名加密方式',
@@ -95,6 +101,8 @@ return array
             (
                 1 => 'value+value形式',
                 2 => 'key=value&key=value形式',
+                3 => 'key+value+key+value形式',
+                4 => 'key+value&key+value形式',
             ),
         ),
 
@@ -110,6 +118,24 @@ return array
             ),
         ),
 
+        'sign_appsecret' => array
+        (
+            'name'      => 'appsecret名称',
+            'type'      => 'varchar(100)',
+        ),
+
+        'sign_appsecret_location' => array
+        (
+            'name'      => 'appsecret位置',
+            'type'      => 'tinyint(1)',
+            'default'   => '1',
+            'value'     => array
+            (
+                1 => '按照签名加密排序',
+                2 => '最后边',
+            ),
+        ),
+
         'sign_encode' => array
         (
             'name'      => '签名加密转码',

+ 1 - 0
src/bao/connect/table/manage/api.php

@@ -7,6 +7,7 @@ return array
         (
             'type',
             'uri',
+            'cate_id',
         ),
     ),
 );

+ 13 - 0
src/bao/connect/table/manage/api_notify_code.php

@@ -0,0 +1,13 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'key',
+            'value',
+            'type',
+        ),
+    ),
+);

+ 2 - 0
src/bao/connect/table/manage/api_request_body.php

@@ -0,0 +1,2 @@
+<?php
+return include('request_body.php');

+ 2 - 0
src/bao/connect/table/manage/api_request_header.php

@@ -0,0 +1,2 @@
+<?php
+return include('request_body.php');

+ 12 - 0
src/bao/connect/table/manage/api_response.php

@@ -0,0 +1,12 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'key',
+            'type',
+        ),
+    ),
+);

+ 14 - 0
src/bao/connect/table/manage/api_uri.php

@@ -0,0 +1,14 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'key',
+            'value',
+            'type',
+        ),
+        'drag' => 'sort',
+    ),
+);

+ 21 - 13
src/bao/connect/table/manage/connect_api.php

@@ -32,10 +32,10 @@ return array
     (
         'tab' => array
         (
-            '基本设置' => 'type,uri,sign_col',
+            '基本设置' => 'type,sign_col,uri,connect/api_uri',
             '请求参数' => 'method,post_method,connect/api_request_body,connect/api_request_header',
             '响应参数' => 'connect/api_response',
-            '回调设置' => 'notify_type,notify_success,connect/api_notify_code,connect/api_notify',
+            '回调设置' => 'notify_type,notify_success,notify_error,connect/api_notify_code',
         ),
         'field'    => array
         (
@@ -45,10 +45,16 @@ return array
                 'type' => 'radio',
                 //'control' => true,
             ),
-            'uri',
             'sign_col' => array
             (
-                'desc' => '',
+                'desc' => '按顺序做加密,用+号隔开,为空则所有字段均参与加密,这里填写后,将替换规则中的加密参数',
+            ),
+            'uri',
+            'connect/api_uri' => array
+            (
+                'name' => '接口地址生成',
+                'where'  => array('api_id' => 'id'),
+                'desc' => '如果需要动态生成接口地址,这里填写参数即可,同样支持变量',
             ),
 
             'method' => array
@@ -65,7 +71,7 @@ return array
             (
                 'name' => '业务请求体',
                 'where'  => array('api_id' => 'id'),
-                'desc' => '[变量:timestamp毫秒时间戳,nonce随机值,appkey渠道的appkey,appsecret渠道的appsecret,signature签名后的信息,api_request当前字段之前的业务参数, notify请求回调地址,token获取access_token(需要设置字段转换:token和expires),ticket获取ticket(需要设置字段转换:ticket和expires),支持Dever自带的所有方法,如Dever::uuid(),就是获取唯一值,传入参数字符串请使用双引号]',
+                'desc' => '[变量:timestamp毫秒时间戳,nonce随机值,appkey渠道的appkey, notify请求回调地址, order_num当前订单号,account当前账号,cash为当前面值,code渠道商品编码,支持函数,如果函数中需要添加变量,请用{}隔开,如{code},请求头也支持此变量]',
             ),
             'connect/api_request_header' => array
             (
@@ -89,16 +95,17 @@ return array
             (
                 'desc' => '填写回调成功后,返回给渠道的信息',
             ),
-            'connect/api_notify_code' => array
+            'notify_error' => array
             (
-                'name' => '回调状态码',
-                'where'  => array('api_id' => 'id'),
+                'desc' => '填写回调失败后,返回给渠道的信息,如果填写500,则会返回HTTP Status Code 500,默认返回HTTP Status Code 200',
             ),
-
-            'connect/api_notify' => array
+            'notify_sign_col' => array
             (
-                'name' => '回调参数',
-                'desc' => '仅设置需要的参数即可',
+                'desc' => '回调签名参数,不填写则使用接口的回调签名参数',
+            ),
+            'connect/api_notify_code' => array
+            (
+                'name' => '回调状态码',
                 'where'  => array('api_id' => 'id'),
             ),
         ),
@@ -117,10 +124,11 @@ return array
             (
                 'notify_type' => 1,
             ),
+            /*
             'connect/api_notify' => array
             (
                 'notify_type' => 1,
-            ),
+            ),*/
         ),
     ),
 );

+ 15 - 11
src/bao/connect/table/manage/connect_info.php

@@ -14,13 +14,13 @@ return array
         (
             '编辑' => 'edit',
             '接口' => array('route', array
+            (
+                'path' => 'supplier/connect_api',
+                'param' => array
                 (
-                    'path' => 'supplier/connect_api',
-                    'param' => array
-                    (
-                        'set' => array('connect_id' => 'id', 'menu' => 'supplier/connect_info', 'parent' => 'supplier/connect_api'),
-                    ),
-                ), 'ChatLineSquare'),
+                    'set' => array('connect_id' => 'id', 'menu' => 'supplier/connect_info', 'parent' => 'supplier/connect_api'),
+                ),
+            ), 'ChatLineSquare'),
         ),
         'button' => array
         (
@@ -39,8 +39,8 @@ return array
             '标准请求' => 'connect/request_body,connect/request_header',
             '响应设置' => 'response_type,response_data,response_msg,response_code,connect/response_code',
             '字段转换' => 'connect/convert',
-            '签名设置' => 'sign_method,sign_col,sign_type,sign_sort,sign_encode,sign_empty,sign_after',
-            '对称加密[暂时不支持]' => 'ssl_method,ssl_key,ssl_option,ssl_iv,ssl_after',
+            '签名设置' => 'sign_name,sign_method,sign_col,sign_type,sign_sort,sign_appsecret,sign_appsecret_location,sign_encode,sign_empty,sign_after',
+            //'对称加密[暂时不支持]' => 'ssl_method,ssl_key,ssl_option,ssl_iv,ssl_after',
             '接口设置' => 'connect/api',
         ),
         'field'    => array
@@ -61,6 +61,7 @@ return array
                 'name' => '请求体设置',
                 'desc' => '标准请求body,没有标准请求体可以不填写',
                 'where'  => array('connect_id' => 'id'),
+                'desc' => '[变量:timestamp毫秒时间戳,nonce随机值,appkey渠道的appkey, notify请求回调地址, order_num当前订单号,account当前账号,cash为当前面值,code渠道商品编码,支持函数,如果函数中需要添加变量,请用{}隔开,如{code},请求头也支持此变量]',
             ),
             'connect/request_header' => array
             (
@@ -72,7 +73,7 @@ return array
             'connect/convert' => array
             (
                 'name' => '字段转换',
-                'desc' => '设置字段转换后,响应的数据名称将根据这些字段进行转换',
+                'desc' => '设置字段转换后,响应和回调的数据名称将根据这些字段进行转换,official_order_num和official_msg是官方流水号和官方返回信息,这里需要绑定一下,未绑定则无法拿到官方流水号',
                 'where'  => array('connect_id' => 'id'),
             ),
 
@@ -91,6 +92,7 @@ return array
                 'where'  => array('connect_id' => 'id'),
             ),
 
+            'sign_name',
             'sign_method' => 'radio',
             'sign_col' => array
             (
@@ -98,15 +100,17 @@ return array
             ),
             'sign_type' => 'radio',
             'sign_sort' => 'radio',
+            'sign_appsecret',
+            'sign_appsecret_location' => 'radio',
             'sign_encode' => array
             (
                 'type' => 'radio',
-                'desc' => '如果签名中包含有特殊字符,是否进行转码',
+                'desc' => '如果签名中包含有特殊字符,是否进行转码',
             ),
             'sign_empty' => array
             (
                 'type' => 'radio',
-                //'desc' => '如果签名中有空值,是否参与加密',
+                'desc' => '如果签名中有空值,是否参与加密',
             ),
             'sign_after' => 'radio',
 

+ 1 - 1
src/bao/connect/table/manage/core.php

@@ -17,7 +17,7 @@ return array
             'name'      => '通信接口',
             'icon'      => 'amazon-line',
             'sort'      => '10',
-            'show'      => 2,
+            'show'      => 3,
         ),
     ),
 );

+ 2 - 2
src/dai/channel/api/Manage.php

@@ -11,7 +11,7 @@ class Manage extends Auth
             return $result;
         }
         $result = array();
-        $goods = Dever::db('goods', 'channel')->select(array('channel_id' => $value))->fetchAll();
+        $goods = Dever::db('goods', 'channel')->select(array('channel_id' => $value), array('group' => 'goods_id'));
         if ($goods) {
             $option = array();
             foreach ($goods as $k => $v) {
@@ -30,7 +30,7 @@ class Manage extends Auth
             return $result;
         }
         $result = array();
-        $goods = Dever::db('goods', 'channel')->select(array('channel_id' => $value))->fetchAll();
+        $goods = Dever::db('goods', 'channel')->select(array('channel_id' => $value));
         if ($goods) {
             $option = array();
             foreach ($goods as $k => $v) {

+ 1 - 1
src/dai/channel/lib/Manage.php

@@ -6,6 +6,6 @@ class Manage extends Auth
     # 获取渠道列表
     public function getInfo()
     {
-        return Dever::db('info', 'channel')->select(array('status' => 1))->fetchAll();
+        return Dever::db('info', 'channel')->select(array('status' => 1));
     }
 }

+ 6 - 0
src/dai/channel/table/info.php

@@ -35,6 +35,12 @@ return array
             'name'      => '主机域名',
             'type'      => 'varchar(2000)',
         ),
+
+        'discount' => array
+        (
+            'name'      => '默认折扣',
+            'type'      => 'varchar(200)',
+        ),
         
         'status' => array
         (

+ 3 - 1
src/dai/channel/table/manage/goods.php

@@ -7,6 +7,8 @@ return array
         (
             'goods' => array
             (
+                # 数据来源
+                //'source' => array('goods_id', 'sku_id'),
                 'name' => '商品',
                 'type' => 'cascader',
                 # 仅显示最后一级
@@ -19,7 +21,7 @@ return array
             ),
             'goods_id' => array
             (
-                'name' => '规格',
+                'name' => '商品',
                 'type' => 'hidden',
                 'rules' => true,
             ),

+ 15 - 0
src/dai/channel/table/manage/info.php

@@ -32,13 +32,28 @@ return array
     ),
     'update' => array
     (
+        'tab' => array
+        (
+            '基本设置' => 'name,discount,connect_id,appkey,appsecret,host,channel/set',
+            '商品设置' => 'channel/goods',
+        ),
         'field'    => array
         (
             'name',
+            'discount' => array
+            (
+                'name' => '默认折扣',
+                'type' => 'text',
+            ),
             'connect_id',
             'appkey',
             'appsecret',
             'host',
+            'channel/set' => array
+            (
+                'name' => '其他参数',
+                'where'  => array('channel_id' => 'id'),
+            ),
             'channel/goods' => array
             (
                 'name' => '商品设置',

+ 12 - 0
src/dai/channel/table/manage/set.php

@@ -0,0 +1,12 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'key',
+            'value',
+        ),
+    ),
+);

+ 25 - 0
src/dai/channel/table/set.php

@@ -0,0 +1,25 @@
+<?php
+return array
+(
+    'name' => '渠道参数表',
+    'struct' => array
+    (
+        'channel_id' => array
+        (
+            'name'      => '渠道id',
+            'type'      => 'int(11)',
+        ),
+
+        'key' => array
+        (
+            'name'      => '字段标识',
+            'type'      => 'varchar(150)',
+        ),
+
+        'value' => array
+        (
+            'name'      => '字段值',
+            'type'      => 'varchar(150)',
+        ),
+    ),
+);

+ 0 - 10
src/dai/seller/api/Channel.php

@@ -1,10 +0,0 @@
-<?php namespace Seller\Api;
-use Dever;
-class Channel
-{
-    # 渠道回调
-    public function callback()
-    {
-        
-    }
-}

+ 41 - 0
src/dai/seller/api/Manage.php

@@ -0,0 +1,41 @@
+<?php namespace Seller\Api;
+use Dever;
+use Manage\Lib\Auth;
+class Manage extends Auth
+{
+    public function showOrderExpand($value = false)
+    {
+        $data = Dever::db('order', 'seller')->find($value);
+        return Dever::load('manage', 'seller')->showOrderExpand($data);
+    }
+
+    public function showOrderLogExpand($value = false)
+    {
+        $data = Dever::db('order_log', 'seller')->find($value);
+        return Dever::load('manage', 'seller')->showOrderExpand($data);
+    }
+
+    # 补发回调
+    public function sendCallBack()
+    {
+        $id = Dever::input('id');
+        if ($id) {
+            $where['id'] = array('in', $id);
+            $order = Dever::db('order', 'seller')->load($where);
+            foreach ($order as $k => $v) {
+                $msg = '';
+                if ($v['status'] == 10) {
+                    $msg = 'ok';
+                } elseif ($v['status'] == 11) {
+                    $msg = 'error';
+                }
+                if ($msg) {
+                    Dever::load('order', 'seller')->notify($v, $msg, array(), 1000);
+                }
+            }
+        } else {
+            Dever::error('请选择发回调的订单');
+        }
+        return '回调发送成功';
+    }
+}

+ 68 - 58
src/dai/seller/api/Order.php

@@ -3,14 +3,30 @@ use Dever;
 class Order
 {
     private $info;
-    public function test()
+    public function signature()
     {
         $token = $this->token();
         $request = Dever::input();
-        return \Dever\Secure::get($request, $token);
+        unset($request['l']);
+        $result = \Dever\Helper\Secure::get($request, $token);
+        $string = '';
+        foreach ($result as $k => $v) {
+            $string .= $k . '=' . $v . '&';
+        }
+        $string = rtrim($string, '&');
+        return array('param' => $result, 'string' => $string);
+    }
+
+    # 检测加密是否正确
+    public function check_secure(){}
+    public function check_token(){return $this->token();}
+    public function check()
+    {
+        return 'ok';
     }
 
-    # 队列提交订单 不做任何数据库操作
+    # 队列提交订单 不做任何数据库操作 先不实现
+    //public function submit_commit(){}
     public function submit_secure(){}
     public function submit_token(){return $this->token();}
     public function submit()
@@ -19,13 +35,51 @@ class Order
         # 商户信息和折扣也保存在redis中
         # 扣款
         # 收单
+        # 按照一个商户一个进程去跑,保证单商户单应用
+        return $this->act();
+    }
+
+    # 查询订单
+    public function info_secure(){}
+    public function info_token(){return $this->token();}
+    public function info()
+    {
+        $order_num = Dever::input('order_num');
+        if (!$order_num) {
+            Dever::error('请传入订单号');
+        }
+        $info = Dever::db('order', 'seller')->find(array('seller_order_num' => $order_num));
+        if (!$info) {
+            $info = Dever::db('order_log', 'seller')->find(array('seller_order_num' => $order_num));
+            if (!$info) {
+                Dever::error('订单不存在');
+            }
+        }
+        $result['system_order_num'] = $info['order_num'];
+        $result['order_num'] = $info['seller_order_num'];
+        $result['order_status'] = $info['status'];
+        $result['order_cash'] = $info['cash'];
+        $result['order_num'] = $info['num'];
+        $result['order_price'] = $info['price'];
+        $result['order_cdate'] = date('Y-m-d H:i:s', $info['cdate']);
+        return $result;
+    }
+
+    # 查询账户
+    public function account_secure(){}
+    public function account_token(){return $this->token();}
+    public function account()
+    {
+        $result['name'] = $this->info['name'];
+        $result['yue'] = $this->info['cash'] + $this->info['credit'];
+        $result['cash'] = $this->info['cash'];
+        $result['credit'] = $this->info['credit'];
+        $result['payCash'] = $this->info['p_cash'];
+        return $result;
     }
 
     # 直接提交订单
-    public function act_commit(){}
-    //public function act_secure(){}
-    //public function act_token(){return $this->token();}
-    public function act()
+    private function act()
     {
         if (!$this->info) {
             $this->token();
@@ -54,62 +108,25 @@ class Order
         if ($goods['status'] == 2) {
             Dever::error('商品已下架');
         }
-        $cate = Dever::db('cate', 'goods')->find($goods['cate_id']);
-        if ($cate && $cate['rule'] && !preg_match($cate['rule'], $account)) {
-            Dever::error($account . '不符合规则');
-        }
-
-        # 查询折扣
-        $seller_goods = Dever::db('goods', 'seller')->find(array('seller_id' => $this->info['id'], 'goods_id' => $sku['info_id'], 'sku_id' => $sku['id']));
-        if ($seller_goods && $seller_goods['discount'] > 0) {
-            $this->info['discount'] = $seller_goods['discount'];
-        }
-        $cash = round($sku['value'] * $this->info['discount'], 2);
-
-        # 查询余额是否充足,看看这里是否需要用redis
-        /* start */
-        $this->info['yue'] = $this->info['credit'] + $this->info['cash'];
-        if ($this->info['yue'] < $cash) {
-            Dever::error('余额不足');
-        }
-        $state = Dever::db('info', 'seller')->update(array('id' => $this->info['id']), array('cash' => array('-', $cash)));
-        /* end */
-
-        # 验证订单号
-        $check = Dever::db('order', 'seller')->find(array('seller_id' => $this->info['id'], 'seller_order_num' => $order));
-        if ($check) {
-            Dever::error('订单重复');
-        }
-
-        # 开始下单
-        $data['account'] = $account;
-        $data['goods_id'] = $sku['info_id'];
-        $data['sku_id'] = $sku['id'];
-        $data['num'] = 1;
-        $data['cash'] = $sku['value'];
-        $data['price'] = $cash;
-        $data['seller_id'] = $this->info['id'];
-        $data['seller_order_num'] = $order;
-        $data['seller_request'] = Dever::json_encode(Dever::input());
-        $order_num = Dever::load('order', 'seller')->add($data);
-
+        Dever::load('order', 'seller')->add($this->info, $goods, $sku, $account, $order);
         return array
         (
             'order_status' => 1,
-            'order_num' => $order_num,
         );
     }
 
-    # 查询订单
-
-    # 查询账户
-
+    # 获取token
     private function token()
     {
         $appkey = Dever::input('appkey');
         if (!$appkey) {
             Dever::error('appkey错误');
         }
+        /*
+        $this->info = Dever::cache('seller_' . $appkey);
+        if (!$this->info) {
+            $this->info = Dever::db('info', 'seller')->find(array('appkey' => $appkey));
+        }*/
         $this->info = Dever::db('info', 'seller')->find(array('appkey' => $appkey));
         if (!$this->info) {
             Dever::error('商户不存在');
@@ -119,11 +136,4 @@ class Order
         }
         return $this->info['appsecret'];
     }
-
-    # 处理订单
-    public function handle()
-    {
-        Dever::load('order', 'seller')->handle();
-        return 'ok';
-    }
 }

+ 201 - 0
src/dai/seller/api/Task.php

@@ -0,0 +1,201 @@
+<?php namespace Seller\Api;
+use Dever;
+use \Dever\Helper\Redis;
+use \Dever\Helper\Str;
+class Task
+{
+    # 每个商户一个进程,暂时不做
+    public function act()
+    {
+        $seller = Dever::db('info', 'seller')->select(array('status' => 1));
+        if ($seller) {
+            foreach ($seller as $k => $v) {
+
+            }
+        }
+    }
+
+    public function cron()
+    {
+        while(1) {
+            try {
+                # 获取当前执行的进程数量
+                $num = $this->getNum();
+                if ($num >= 1000) {
+                    # 等会儿再执行
+                    sleep(30);
+                }
+                $data = Redis::pop('submit_' . DEVER_PROJECT);
+                if ($data) {
+                    $this->popen($data);
+                }
+            } catch (\Exception $e) {
+                $this->redis = false;
+            }
+        };
+    }
+
+    # 将数据推到子进程处理
+    private function popen($order)
+    {
+        $command = 'php /www/api/src/dai/seller/index.php \'{"l":"task.run","order":"'.Str::encode($order).'"}\'';
+        exec($command, $out);
+    }
+
+    # 获取当前执行的子进程数量
+    private function getNum()
+    {
+        $command = 'ps -ef | grep task.run | grep -v grep | wc -l';
+        $num = exec($command);
+        return $num;
+    }
+
+    public function run()
+    {
+        $order = Str::decode(Dever::input('order'));
+        $info = Dever::db('order', 'seller')->find($order);
+        if ($info) {
+            Dever::load('order', 'seller')->handle($info);
+        }
+    }
+
+    # 每日整理订单数据,删除,并统计订单数据
+    public function stat_commit(){}
+    public function stat()
+    {
+        # 获取昨天的时间
+        $time = \Dever\Helper\Date::day();
+        $where['cdate'] = array('<', $time[0]);
+        $where['status'] = array('>=', 10);
+        $order = Dever::db('order', 'seller')->load($where);
+        $data = array();
+        $default = array
+        (
+            'total_num' => 0,
+            'success_num' => 0,
+            'error_num' => 0,
+            'total_cash' => 0,
+            'success_cash' => 0,
+            'error_cash' => 0,
+            'seller_actual_cash' => 0,
+            'channel_actual_cash' => 0,
+            'profit_cash' => 0,
+            'data' => array(),
+        );
+        foreach ($order as $k => $v) {
+            if ($v['status'] >= 10) {
+                # 整理这一天成功的和失败的
+                $day = \Dever\Helper\Date::mktime(date('Y-m-d 00:00:00', ($v['finish_date'] ? $v['finish_date'] : $v['cdate'])));
+                $this->statItem($data, $day, '_1', $default, $v);
+                $this->statItem($data, $day, 'seller_' . $v['seller_id'], $default, $v, $v['channel_id']);
+                if ($v['channel_id']) {
+                    $this->statItem($data, $day, 'channel_' . $v['channel_id'], $default, $v, $v['seller_id']);
+                }
+
+                $state = Dever::db('order_bak', 'seller')->insert($v);
+                if ($state) {
+                    Dever::db('order', 'seller')->delete($v['id']);
+                }
+            }
+        }
+
+        if ($data) {
+            foreach ($data as $k => $v) {
+                foreach ($v as $k1 => $v1) {
+                    $v1['data'] = Dever::json_encode($v1['data']);
+                    $k1 = explode('_', $k1);
+                    $w = array();
+                    $w['day'] = $k;
+                    $table = 'order_stat';
+                    if ($k1[0]) {
+                        $w[$k1[0] . '_id'] = $k1[1];
+                        $table .= '_' . $k1[0];
+                    }
+                    $info = Dever::db($table, 'seller')->find($w);
+                    if ($info) {
+                        Dever::db($table, 'seller')->update($info['id'], $v1);
+                    } else {
+                        $v1 = array_merge($v1, $w);
+                        Dever::db($table, 'seller')->insert($v1);
+                    }
+                }
+            }
+        }
+    }
+
+    public function statItem(&$data, $day, $mid, $default, $v, $rid = false)
+    {
+        if (!isset($data[$day][$mid])) {
+            $data[$day][$mid] = $default;
+        }
+        if ($rid) {
+            if (!isset($data[$day][$mid]['data'][$rid])) {
+                $data[$day][$mid]['data'][$rid] = $default;
+            }
+        }
+        
+        $data[$day][$mid]['total_num'] += $v['num'];
+        $data[$day][$mid]['total_cash'] += $v['cash'];
+        if ($rid) {
+            $data[$day][$mid]['data'][$rid]['total_num'] += $v['num'];
+            $data[$day][$mid]['data'][$rid]['total_cash'] += $v['cash'];
+        }
+        if ($v['status'] == 10) {
+            $data[$day][$mid]['success_num'] += $v['num'];
+            $data[$day][$mid]['success_cash'] += $v['cash'];
+            $data[$day][$mid]['seller_actual_cash'] += $v['price'];
+            $data[$day][$mid]['channel_actual_cash'] += $v['buy_price'];
+            $data[$day][$mid]['profit_cash'] += ($v['price']-$v['buy_price']);
+            if ($rid) {
+                $data[$day][$mid]['data'][$rid]['success_num'] += $v['num'];
+                $data[$day][$mid]['data'][$rid]['success_cash'] += $v['cash'];
+                $data[$day][$mid]['data'][$rid]['seller_actual_cash'] += $v['price'];
+                $data[$day][$mid]['data'][$rid]['channel_actual_cash'] += $v['buy_price'];
+                $data[$day][$mid]['data'][$rid]['profit_cash'] += ($v['price']-$v['buy_price']);
+            }
+
+        } elseif ($v['status'] == 11) {
+            $data[$day][$mid]['error_num'] += $v['num'];
+            $data[$day][$mid]['error_cash'] += $v['cash'];
+            if ($rid) {
+                $data[$day][$mid]['data'][$rid]['error_num'] += $v['num'];
+                $data[$day][$mid]['data'][$rid]['error_cash'] += $v['cash'];
+            }
+        }
+    }
+
+    # 每小时统计一次正确的商户余额
+    public function yue()
+    {
+        $where['status'] = 1;
+        $seller = Dever::db('info', 'seller')->load($where);
+        foreach ($seller as $k => $v) {
+            $data = Dever::db('log', 'seller')->select(array('seller_id' => $v['id']), array('col' => 'sum(cash)'));
+            if ($data && isset($data[0]['sum'])) {
+                $sum = $data[0]['sum'] - $v['credit'];
+                Dever::db('info', 'seller')->update($v['id'], array('cash' => $sum));
+            }
+        }
+    }
+
+    # 每5分钟跑一次回调
+    public function callback()
+    {
+        $where['status'] = array('>=', 10);
+        $where['seller_callback_num'] = array('<=', 5);
+        $where['seller_callback_date'] = array('>=', time() + 300);
+        $where['seller_callback'] = array('!=', 'ok');
+        $order = Dever::db('order', 'seller')->load($where);
+        foreach ($order as $k => $v) {
+            $msg = '';
+            if ($v['status'] == 10) {
+                $msg = 'ok';
+            } elseif ($v['status'] == 11) {
+                $msg = 'error';
+            }
+            if ($msg) {
+                Dever::load('order', 'seller')->notify($v, $msg);
+            }
+        }
+    }
+}

+ 19 - 0
src/dai/seller/api/Test.php

@@ -0,0 +1,19 @@
+<?php namespace Seller\Api;
+use Dever;
+class Test
+{
+    # 测试商户回调
+    public function callback()
+    {
+        $input = Dever::input();
+        Dever::log($input, 'callback');
+        return 'ok';
+    }
+
+    public function run()
+    {
+        $order = Dever::input('order');
+        $info = Dever::db('order', 'seller')->find($order);
+        Dever::load('order', 'seller')->handle($info);
+    }
+}

+ 40 - 0
src/dai/seller/lib/Info.php

@@ -0,0 +1,40 @@
+<?php namespace Seller\Lib;
+use Dever;
+class Info
+{
+    # 余额扣款
+    public function dec($id, $cash)
+    {
+        $state = Dever::db('info', 'seller')->update($id, array('cash' => array('-', $cash)));
+        return $state;
+    }
+
+    # 余额加款
+    public function inc($id, $cash)
+    {
+        $state = Dever::db('info', 'seller')->update($id, array('cash' => array('+', $cash)));
+        return $state;
+    }
+
+    # 增加日志
+    public function log($seller_id, $order_id, $cash, $type = 3)
+    {
+        $where['seller_id'] = $seller_id;
+        $where['order_id'] = $order_id;
+        $where['type'] = $type;
+        $data = $where;
+        if ($type == 2 || $type == 3) {
+            $cash = -1*$cash;
+        }
+        $data['cash'] = $cash;
+        //$data['yue'] = $this->yue($seller_id) - $cash;
+        //Dever::db('log', 'seller')->up($where, $data);
+        Dever::db('log', 'seller')->insert($data);
+    }
+
+    # 获取余额
+    public function yue($seller_id)
+    {
+
+    }
+}

+ 316 - 1
src/dai/seller/lib/Manage.php

@@ -7,7 +7,7 @@ class Manage extends Auth
     # 获取商户列表
     public function getInfo()
     {
-        return Dever::db('info', 'seller')->select(array('status' => 1))->fetchAll();
+        return Dever::db('info', 'seller')->select(array('status' => 1));
     }
 
     # 为商户生成appkey
@@ -23,5 +23,320 @@ class Manage extends Auth
             }
             Dever::db('info', 'seller')->update($data['id'], $update);
         }
+        # 写到redis中
+        $info = Dever::db('info', 'seller')->find($data['id']);
+        Dever::cache('seller_' . $info['appkey'], $info);
+    }
+
+    # 订单手动充值
+    public function createOrder($data)
+    {
+        if (!$data['seller_id']) {
+            Dever::error('未选择商户');
+        }
+        if (!$data['data']) {
+            Dever::error('未输入充值数据');
+        }
+        $goods = explode(',', $data['goods']);
+        $goods_id = end($goods);
+        $sku_id = $data['sku_id'];
+        $seller_id = $data['seller_id'];
+        $seller = Dever::db('info', 'seller')->find($seller_id);
+        if (!$seller) {
+            Dever::error('商户不存在');
+        }
+        if ($seller && $seller['status'] == 2) {
+            Dever::error('商户已封禁');
+        }
+        if (!$goods_id) {
+            Dever::error('未选择商品');
+        }
+        if (!$sku_id) {
+            Dever::error('未选择规格');
+        }
+        $goods = Dever::db('info', 'goods')->find($goods_id);
+        $sku = Dever::db('info_sku', 'goods')->find($sku_id);
+        if (!$goods) {
+            Dever::error('商品不存在');
+        }
+        if (!$sku) {
+            Dever::error('规格不存在');
+        }
+        if ($sku['info_id'] != $goods['id']) {
+            Dever::error('商品['.$goods['name'].']下无此规格');
+        }
+        $param = explode("\r\n", $data['data']);
+        $class = Dever::load('order', 'seller');
+        foreach ($param as $k => $v) {
+            $order = Str::order('PAY') . '_' . $k;
+            $class->add($seller, $goods, $sku, $v, $order);
+        }
+        return $data;
+    }
+
+    # 修改订单状态
+    public function editOrder($id, $data)
+    {
+        if ($data['status'] <= 10) {
+            Dever::error('请选择订单状态');
+        }
+        $newid = array();
+        $id = explode(',', $id);
+        foreach ($id as $k => $v) {
+            $info = Dever::db('order', 'seller')->find($v);
+            if ($info['status'] < 10) {
+                $newid[] = $v;
+                if (!$info['order_num']) {
+                    $update['order_num'] = Dever::load('order', 'seller')->createOrder();
+                    Dever::db('order', 'seller')->update($v, $update);
+                }
+            }
+        }
+        if (!$newid) {
+            Dever::error('请选择未完成订单');
+        }
+        $newid = implode(',', $newid);
+        $data['finish'] = 1;
+        $data['finish_date'] = time();
+        return array($newid, $data);
+    }
+
+    # 将订单插入到订单日志中
+    public function addOrderLog($id, $data)
+    {
+        $id = explode(',', $id);
+        foreach ($id as $k => $v) {
+            $info = Dever::db('order', 'seller')->find($v);
+            if ($info['status'] >= 10) {
+                if ($info['status'] == 11) {
+                    # 失败,余额加回来
+                    Dever::load('info', 'seller')->inc($info['seller_id'], $info['price']);
+                    Dever::load('info', 'seller')->log($info['seller_id'], $info['id'], $info['price'], 4);
+                }
+                Dever::db('order_log', 'seller')->insert($info);
+            }
+        }
+    }
+
+    # 后台充值、提现
+    public function operCash($data)
+    {
+        if ($data['type'] == 1) {
+            Dever::load('info', 'seller')->inc($data['seller_id'], $data['cash']);
+            Dever::db('info', 'seller')->update($id, array('p_cash' => array('+', $cash)));
+        } elseif ($data['type'] == 2) {
+            Dever::load('info', 'seller')->dec($data['seller_id'], $data['cash']);
+            $data['cash'] = -1*$data['cash'];
+        }
+        return $data;
+    }
+
+    # 展示订单信息
+    public function showOrder($order_id)
+    {
+        $result = '';
+        if ($order_id) {
+            $order = Dever::db('order', 'seller')->find($order_id);
+            if ($order) {
+                $result = $order['order_num'];
+            }
+        }
+        
+        return $result;
+    }
+
+    # 展示订单金额
+    public function showOrderCash($cate_id, $goods_id, $sku_id, $cash, $price)
+    {
+        $goods = Dever::db('info', 'goods')->find($goods_id);
+
+        $result = $goods['name'] . ' / ' . $cash . ' / ' . $price;
+        return $result;
+    }
+
+    # 展示订单状态
+    public function showOrderStatus($status)
+    {
+        $value = Dever::db('order', 'seller')->config['struct']['status']['value'][$status];
+        if ($status < 10) {
+            return $value;
+        } elseif ($status == 10) {
+            return '<span style="color:blue">'.$value.'</span>';
+        } elseif ($status == 11) {
+            return '<span style="color:red">'.$value.'</span>';
+        }
+    }
+
+    # 展示订单统计信息
+    public function showOrderStat($where)
+    {
+        $db = Dever::db('order', 'seller');
+        $total = $db->count($where);
+
+        $zongjine = $db->find($where, array('col' => 'sum(cash) as cash'));
+
+        $where['status'] = 10;
+        $yes = $db->count($where);
+        if ($total <= 0) {
+            $lv = '0%';
+        } else {
+            $lv = round($yes/$total*100, 2) . '%';
+        }
+        $czongjine = $db->find($where, array('col' => 'sum(cash) as cash'));
+        $szongjine = $db->find($where, array('col' => 'sum(price) as cash'));
+        
+        $where['status'] = array('<', 10);
+        $chu = $db->count($where);
+
+        $where['status'] = 11;
+        $shibai = $db->count($where);
+
+        return array
+        (
+            array
+            (
+                # 一共24
+                'span' => '3',
+                'name' => '总订单数',
+                'value' => $total,
+            ),
+            array
+            (
+                'span' => '3',
+                'name' => '成功订单数',
+                'value' => $yes,
+            ),
+            array
+            (
+                'span' => '3',
+                'name' => '成功率',
+                'value' => $lv,
+            ),
+            array
+            (
+                'span' => '3',
+                'name' => '处理中订单数',
+                'value' => $chu,
+            ),
+            array
+            (
+                'span' => '3',
+                'name' => '失败订单数',
+                'value' => $shibai,
+            ),
+            array
+            (
+                'span' => '3',
+                'name' => '总金额',
+                'value' => $zongjine['cash'] ?? 0,
+            ),
+            array
+            (
+                'span' => '3',
+                'name' => '成功金额',
+                'value' => $czongjine['cash'] ?? 0,
+            ),
+            array
+            (
+                'span' => '3',
+                'name' => '实际成功金额',
+                'value' => $szongjine['cash'] ?? 0,
+            ),
+        );
+    }
+
+    # 展示订单扩展信息
+    public function showOrderExpand($data)
+    {
+        $seller = Dever::db('info', 'seller')->find($data['seller_id']);
+        $channel = array();
+        if ($data['channel_id']) {
+            $channel = Dever::db('info', 'channel')->find($data['channel_id']);
+        }
+        $value = $this->showOrderStatus($data['status']);
+        $goods = $this->showOrderCash($data['cate_id'], $data['goods_id'], $data['sku_id'], $data['cash'], $data['price']);
+        $result['type'] = 'desc';
+        $result['content'][] = array
+        (
+            'title' => '商户发起请求',
+            'border' => true,
+            'direction' => 'horizontal',
+            'size' => 'small',
+            'column' => 1,
+            'content' => array
+            (
+                array('商户名称', $seller['name']),
+                array('商户订单号', $data['seller_order_num']),
+                array('商品', $goods),
+                array('商户请求参数', $data['seller_request']),
+                array('请求时间', date('Y-m-d H:i', $data['cdate'])),
+            ), 
+        );
+        $result['content'][] = array
+        (
+            'title' => '系统下单',
+            'border' => true,
+            'direction' => 'horizontal',//'vertical' | 'horizontal'
+            'size' => 'small',//'' | 'large' | 'default' | 'small'
+            'column' => 1,
+            'content' => array
+            (
+                array('系统订单ID', $data['id']),
+                array('系统订单号', $data['order_num']),
+                array('订单状态', $value),
+                array('系统发起请求', $data['channel_request']),
+                array('请求时间', $data['channel_order_date'] ? date('Y-m-d H:i', $data['channel_order_date']) : '-'),
+            ), 
+        );
+        if ($channel) {
+            $result['content'][] = array
+            (
+                'title' => '渠道响应信息',
+                'border' => true,
+                'direction' => 'horizontal',
+                'size' => 'small',
+                'column' => 1,
+                'content' => array
+                (
+                    array('渠道名称', $channel['name']),
+                    array('渠道订单号', $data['channel_order_num']),
+                    array('渠道响应信息', $data['channel_response']),
+                ), 
+            );
+        }
+        
+        if ($data['channel_callback']) {
+            $result['content'][] = array
+            (
+                'title' => '渠道回调信息',
+                'border' => true,
+                'direction' => 'horizontal',
+                'size' => 'small',
+                'column' => 1,
+                'content' => array
+                (
+                    array('渠道回调信息', $data['channel_callback']),
+                    array('回调时间', date('Y-m-d H:i', $data['channel_callback_date'])),
+                    array('官方流水号', $data['official_order_num']),
+                    array('官方充值结果', $data['official_msg']),
+                ), 
+            );
+        }
+        
+        $result['content'][] = array
+        (
+            'title' => '系统向商户发起回调',
+            'border' => true,
+            'direction' => 'horizontal',
+            'size' => 'small',
+            'column' => 1,
+            'content' => array
+            (
+                array('商户响应信息', $data['seller_callback']),
+                array('响应时间', $data['seller_callback_date'] ? date('Y-m-d H:i', $data['seller_callback_date']) : '-'),
+                array('响应次数', $data['seller_callback_num']),
+            ), 
+        );
+        return $result;
     }
 }

+ 145 - 42
src/dai/seller/lib/Order.php

@@ -4,45 +4,82 @@ use Dever\Helper\Str;
 class Order
 {
     # 新增订单
-    public function add($data)
+    public function add($info, $goods, $sku, $account, $order)
     {
-        $data['order_num'] = $this->createOrder();
-        $id = Dever::db('order', 'seller')->insert($data);
-        if (!$id) {
-            Dever::error('下单失败');
+        $cate = Dever::db('cate', 'goods')->find($goods['cate_id']);
+        if ($cate && $cate['rule'] && !preg_match($cate['rule'], $account)) {
+            Dever::error($account . '不符合规则');
         }
-        return $data['order_num'];
-    }
 
-    # 处理已下单的订单
-    public function handle_commit(){}
-    public function handle()
-    {
-        $data = Dever::db('order', 'seller')->select(array('status' => 1), array('limit' => 100))->fetchAll();
-        foreach ($data as $k => $v) {
-            //Dever::db('order', 'seller')->update($v['id'], array('status' => 2));
-            $status = $this->handleItem($v);
-            if ($status) {
-                //Dever::db('order', 'seller')->update($v['id'], array('status' => $status));
-            }
+        # 查询折扣
+        $seller_goods = Dever::db('goods', 'seller')->find(array('seller_id' => $info['id'], 'goods_id' => $sku['info_id'], 'sku_id' => $sku['id']));
+        if ($seller_goods && $seller_goods['discount'] > 0) {
+            $info['discount'] = $seller_goods['discount'];
+        }
+        if (!$info['discount']) {
+            $info['discount'] = 1;
+        }
+        $cash = round($sku['value'] * $info['discount'], 2);
+
+        # 查询余额是否充足
+        $info['yue'] = $info['credit'] + $info['cash'];
+        if ($info['yue'] < $cash) {
+            Dever::error('余额不足');
+        }
+        $state = Dever::load('info', 'seller')->dec($info['id'], $cash);
+
+        # 验证订单号
+        $check = Dever::db('order', 'seller')->find(array('seller_id' => $info['id'], 'seller_order_num' => $order));
+        if ($check) {
+            Dever::error('订单重复');
+        }
+
+        # 开始下单
+        $data = array();
+        $data['account'] = $account;
+        $data['cate_id'] = $goods['cate_id'];
+        $data['goods_id'] = $sku['info_id'];
+        $data['sku_id'] = $sku['id'];
+        $data['num'] = 1;
+        $data['cash'] = $sku['value'];
+        $data['price'] = $cash;
+        $data['seller_id'] = $info['id'];
+        $data['seller_order_num'] = $order;
+        $data['seller_request'] = Dever::json_encode(Dever::input());
+
+        $order_id = Dever::db('order', 'seller')->insert($data);
+        if (!$order_id) {
+            Dever::error('下单失败');
         }
+        //\Dever\Helper\Redis::push('submit_' . $data['seller_id'], $order_id);
+        $state = \Dever\Helper\Redis::push('submit_' . DEVER_PROJECT, $order_id);
+        Dever::load('info', 'seller')->log($info['id'], $order_id, $data['price'], 3);
+        return $order_id;
     }
 
-    private function handleItem($info, $selected = array())
+    public function handle($info, $selected = array())
     {
+        if ($info['status'] >= 10) {
+            return;
+        }
+        $update['status'] = 2;
+        if (!$info['order_num']) {
+            $info['order_num'] = $update['order_num'] = $this->createOrder();
+        }
+        Dever::db('order', 'seller')->update($info['id'], $update);
         # 查找渠道
-        $channel_list = Dever::db('channel', 'seller')->select(array('seller_id' => $info['seller_id'], 'goods_id' => $info['goods_id']))->fetchAll();
+        $channel_list = Dever::db('channel', 'seller')->select(array('seller_id' => $info['seller_id'], 'goods_id' => $info['goods_id']));
         if (!$channel_list) {
-            return $this->notify($info, '通道未开启');
+            return $this->notify($info, '通道未开启', $update);
         }
-        $channel = array();
+        $channel = $channel_goods = array();
         foreach ($channel_list as $k => $v) {
             if ($selected && isset($selected[$v['channel_id']])) {
                 continue;
             }
             if (!$v['sku_id']) {
-                $channel_sku = Dever::db('goods', 'channel')->find(array('channel_id' => $v['channel_id'], 'goods_id' => $info['goods_id'], 'sku_id' => $info['sku_id']));
-                if ($channel_sku) {
+                $channel_goods = Dever::db('goods', 'channel')->find(array('channel_id' => $v['channel_id'], 'goods_id' => $info['goods_id'], 'sku_id' => $info['sku_id']));
+                if ($channel_goods) {
                     $channel = $v['channel_id'];
                     break;
                 }
@@ -55,49 +92,115 @@ class Order
             }
         }
         if (!$channel) {
-            return $this->notify($info, '通道未开启');
+            return $this->notify($info, '通道未开启', $update);
         }
 
         $channel = Dever::db('info', 'channel')->find($channel);
         if (!$channel) {
-            return $this->notify($info, '通道未开启');
+            return $this->notify($info, '通道未开启', $update);
         }
         if ($channel['status'] == 2) {
-            return $this->notify($info, '通道未开启');
+            return $this->notify($info, '通道未开启', $update);
         }
 
-        print_r($channel);die;
-
-        //向渠道发起请求 下单
-        Dever::load('func/api', 'connect')->add(1, $channel);
+        # 向渠道发起请求 下单
+        $param['order_id'] = $info['id'];
+        $param['order_num'] = $info['order_num'];
+        $param['account'] = $info['account'];
+        $param['cash'] = $info['cash'];
+        if ($info['other']) {
+            $info['other'] = Dever::json_decode($info['other']);
+            $param = array_merge($info['other'], $param);
+        }
+        if (isset($channel_goods['code'])) {
+            $param['code'] = $channel_goods['code'];
+        }
+        $result = Dever::load('func/api', 'connect')->run(1, $info['cate_id'], $channel, $param);
+        $update = array();
 
-        return false;
+        $update['channel_id'] = $channel['id'];
+        $update['channel_order_date'] = time();
+        $update['channel_request'] = Dever::json_encode($result['request']);
+        $update['channel_response'] = Dever::json_encode($result['response']);
+        if (isset($channel_goods['id'])) {
+            $update['channel_goods_id'] = $channel_goods['id'];
+        }
+        $update['channel_goods_discount'] = $channel['discount'];
+        if (isset($channel_goods['discount']) && $channel_goods['discount']) {
+            $update['channel_goods_discount'] = $channel_goods['discount'];
+        }
+        if (!$update['channel_goods_discount']) {
+            $update['channel_goods_discount'] = 1;
+        }
+        $update['buy_price'] = round($info['cash'] * $update['channel_goods_discount'], 2);
+        if ($result['status'] == 1) {
+            # 下单成功
+            Dever::db('order', 'seller')->update($info['id'], $update);
+            return 'ok';
+        } else {
+            # 下单失败
+            return $this->notify($info, '下单失败', $update);
+        }
     }
 
-    # 商户发起回调
-    public function notify($info, $msg, $other = array())
+    # 商户发起回调
+    public function notify($info, $msg, $update = array(), $total = 5)
     {
+        $seller = Dever::db('info', 'seller')->find($info['seller_id']);
         $status = 11;
         if ($msg == 'ok') {
             $status = 10;
         }
-
         # 获取商户回调地址,向商户发起回调
         $seller_request = Dever::json_decode($info['seller_request']);
         if (isset($seller_request['notify']) && $seller_request['notify']) {
             $notify = $seller_request['notify'];
+        } else {
+            $notify = $seller['notify'];
+        }
+        if ($notify && $info['seller_callback'] != 'ok' && $info['seller_callback_num'] <= $total) {
             $param = array();
-            $param['seller_order_num'] = $info['seller_order_num'];
-            $param['order_num'] = $info['order_num'];
+            $param['appkey'] = $seller['appkey'];
+            $param['order_num'] = $info['seller_order_num'];
+            $param['system_order_num'] = $info['order_num'];
             $param['order_status'] = $status;
             $param['order_cash'] = $info['cash'];
+            $param['official_order_num'] = $param['official_msg'] = '';
+            if (isset($update['official_order_num'])) {
+                $param['official_order_num'] = $update['official_order_num'];
+            }
+            if (isset($update['official_msg'])) {
+                $param['official_msg'] = $update['official_msg'];
+            }
+            $param = \Dever\Helper\Secure::get($param, $seller['appsecret']);
+            $response = Dever::curl($notify, $param, 'post')->result();
+            # ok是成功
+            $update['seller_callback'] = $response;
+            $update['seller_callback_date'] = time();
+            $update['seller_callback_num'] = $info['seller_callback_num'] + 1;
         }
-
-        if ($status == 11) {
-            # 失败,余额加回来
-            Dever::db('info', 'seller')->update(array('id' => $info['id']), array('cash' => array('+', $info['price'])));
+        $id = $info['id'];
+        if ($info['status'] < 10 && $status >= 10) {
+            # 订单完成
+            $update['status'] = $status;
+            $update['finish'] = 1;
+            $update['finish_date'] = time();
+            if ($status == 11) {
+                # 失败,余额加回来
+                Dever::load('info', 'seller')->inc($info['seller_id'], $info['price']);
+                Dever::load('info', 'seller')->log($info['seller_id'], $info['id'], $info['price'], 4);
+            } elseif ($status == 10) {
+                # 成功
+            }
+            # 将记录写到influx中
+            $info = array_merge($info, $update);
+            Dever::db('order_log', 'seller')->insert($info);
+        }
+        if (!$info['order_num']) {
+            $update['order_num'] = $this->createOrder();
         }
-        return $status;
+        Dever::db('order', 'seller')->update($id, $update);
+        return $msg;
     }
 
     public function createOrder()

+ 8 - 0
src/dai/seller/table/info.php

@@ -9,6 +9,7 @@ return array
         (
             'name'      => '商户名称',
             'type'      => 'varchar(32)',
+            'fields'    => true,
         ),
 
         'discount' => array
@@ -29,6 +30,12 @@ return array
             'type'      => 'varchar(2000)',
         ),
 
+        'notify' => array
+        (
+            'name'      => '回调地址',
+            'type'      => 'varchar(1000)',
+        ),
+
         'cash'      => array
         (
             'type'      => 'decimal(11,2)',
@@ -47,6 +54,7 @@ return array
             'name'      => '总充值金额',
         ),
 
+        # 暂时无用
         't_cash'        => array
         (
             'type'      => 'decimal(11,2)',

+ 55 - 0
src/dai/seller/table/log.php

@@ -0,0 +1,55 @@
+<?php
+return array
+(
+    'name' => '商户账户记录表',
+    'store' => 'log',
+    'struct' => array
+    (
+        'seller_id' => array
+        (
+            'name'      => '商户id',
+            'type'      => 'int(11)',
+            'value'     => 'seller/info',
+        ),
+
+        'type' => array
+        (
+            'name'      => '类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '充值',
+                2 => '提现',
+                3 => '下单',
+                4 => '失败返还',
+            ),
+        ),
+
+        'cash'      => array
+        (
+            'type'      => 'decimal(11,2)',
+            'name'      => '金额',
+            'fields'    => true,
+        ),
+
+        'yue'      => array
+        (
+            'type'      => 'decimal(11,2)',
+            'name'      => '余额',
+            'fields'    => true,
+        ),
+
+        'order_id' => array
+        (
+            'name'      => '订单id',
+            'type'      => 'int(11)',
+        ),
+
+        'desc'      => array
+        (
+            'type'      => 'varchar(500)',
+            'name'      => '操作备注',
+        ),
+    ),
+);

+ 53 - 2
src/dai/seller/table/manage/core.php

@@ -17,7 +17,14 @@ return array
             'icon'      => 'mickey-line',
             'sort'      => '1',
         ),
-
+        'log' => array
+        (
+            'parent'    => 'dealer',
+            'name'      => '资金日志',
+            'icon'      => 'article-line',
+            'sort'      => '2',
+            'show'      => 3,
+        ),
         'data' => array
         (
             'name' => '数据',
@@ -35,9 +42,53 @@ return array
         'order_list' => array
         (
             'parent'    => 'order',
-            'name'      => '订单列表',
+            'name'      => '今日订单',
             'icon'      => 'album-line',
             'sort'      => '1',
         ),
+        'order_log_list' => array
+        (
+            'parent'    => 'order',
+            'name'      => '已完成订单',
+            'icon'      => 'bank-card-line',
+            'sort'      => '2',
+        ),
+        'order_push' => array
+        (
+            'parent'    => 'order',
+            'name'      => '手动充值',
+            'icon'      => 'bank-card-line',
+            'sort'      => '3',
+            'show'      => 3,
+        ),
+
+        'stat' => array
+        (
+            'parent' => 'data',
+            'name' => '数据统计',
+            'icon' => 'database-line',
+            'sort' => '2',
+        ),
+        'order_stat' => array
+        (
+            'parent'    => 'stat',
+            'name'      => '平台订单统计',
+            'icon'      => 'cloud-windy-line',
+            'sort'      => '1',
+        ),
+        'order_stat_seller' => array
+        (
+            'parent'    => 'stat',
+            'name'      => '商户订单统计',
+            'icon'      => 'cloudy-2-line',
+            'sort'      => '2',
+        ),
+        'order_stat_channel' => array
+        (
+            'parent'    => 'stat',
+            'name'      => '渠道订单统计',
+            'icon'      => 'cloudy-line',
+            'sort'      => '3',
+        ),
     ),
 );

+ 11 - 3
src/dai/seller/table/manage/info.php

@@ -24,9 +24,17 @@ return array
         ),
         'data_button' => array
         (
-            '编辑' => array('fastedit', 'name,credit,discount'),
+            '编辑' => array('fastedit', 'name,credit,discount,notify'),
             '渠道设置' => array('edit', 'seller/channel', 'Operation'),
             '折扣设置' => array('edit', 'seller/goods', 'Odometer'),
+            '资金流水' => array('route', array
+            (
+                'path' => 'dealer/log',
+                'param' => array
+                (
+                    'set' => array('seller_id' => 'id', 'menu' => 'dealer/info', 'parent' => 'dealer/log'),
+                ),
+            ), 'ChatLineSquare'),
             '查看账户' => array('fastedit', 'doc,host,appkey,appsecret', 'View'),
         ),
         'button' => array
@@ -46,7 +54,7 @@ return array
             (
                 'name' => '接口文档',
                 'type' => 'show',
-                'default' => 'http://www.docway.net/project/1euEYXnqSa9/1euEYZQ2rUu',
+                'default' => '地址:https://www.showdoc.com.cn/2445802255699675 密码:d04359f11c7d4bc85153cc3e49907e7d',
             ),
             'host' => array
             (
@@ -62,6 +70,7 @@ return array
             (
                 'desc' => '直接填写折扣数值,如0.98',
             ),
+            'notify',
             'seller/channel' => array
             (
                 'name' => '渠道设置',
@@ -72,7 +81,6 @@ return array
                 'name' => '折扣设置',
                 'desc' => '设置之后,默认折扣将失效',
                 'where'  => array('seller_id' => 'id'),
-                'show' => false,
             ),
         ),
         'end' => 'seller/manage.createAppKey',

+ 104 - 0
src/dai/seller/table/manage/log.php

@@ -0,0 +1,104 @@
+<?php
+$seller_id = Dever::input('set')['seller_id'] ?? 0;
+return array
+(
+    'list' => array
+    (
+        'where' => array('seller_id' => $seller_id),
+        'field'      => array
+        (
+            'seller_id' => array
+            (
+                'name' => '商户',
+                'width' => '300',
+            ),
+            'type' => array
+            (
+                'width' => '120',
+            ),
+            'cash' => array
+            (
+                'width' => '150',
+            ),
+            //'yue',
+            'desc' => array
+            (
+                'name' => '操作备注/订单号',
+                'show' => '"{desc}" ? "{desc}" : Dever::load("manage", "seller")->showOrder({order_id})',
+            ),
+            'cdate' => array
+            (
+                'name' => '时间',
+                'width' => '150',
+            ),
+        ),
+        'data_button' => array
+        (
+            
+        ),
+        'button' => array
+        (
+            '账户操作' => array('fastadd', array('seller_id' => $seller_id)),
+        ),
+        'export' => array
+        (
+            'out' => '导出',
+            //'manage/common.out' => '自定义导出',
+        ),
+        'search' => array
+        (
+            'type',
+            //'desc',
+            'order_id' => array
+            (
+                'name' => '系统订单号',
+                'search' => array
+                (
+                    'table' => 'seller/order',
+                    'where' => array('order_num' => '{value}'),
+                    'set' => array(),
+                    'field' => 'id',
+                ),
+            ),
+            'cdate' => array
+            (
+                'name' => '时间',
+                'type' => 'date',
+                'date_type' => 'datetimerange',
+                'value_format' => 'YYYY-MM-DD HH:mm:ss',
+                'start_placeholder' => '开始时间',
+                'end_placeholder' => '结束时间',
+                'range_separator' => '至',
+            ),
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'seller_id' => 'text',
+            'type' => array
+            (
+                'type' => 'radio',
+                'option' => array
+                (
+                    1 => '充值',
+                    2 => '提现',
+                ),
+            ),
+            'cash' => array
+            (
+                'type' => 'text',
+                'rules' => true,
+                'desc' => '充值和提现均输入正数即可',
+            ),
+            'desc' => array
+            (
+                'type' => 'textarea',
+                'rows' => 2,
+                'rules' => true,
+            ),
+        ),
+        'start' => 'seller/manage.operCash',
+    ),
+);

+ 85 - 19
src/dai/seller/table/manage/order_list.php

@@ -4,28 +4,47 @@ return array
     'source' => 'seller/order',
     'list' => array
     (
+        //'expand' => 'seller/manage.showOrderExpand',
+        'stat' => 'seller/manage.showOrderStat',
         'field'      => array
         (
-            'order_num',
+            'seller_id',
+            'seller_order_num',
+            'order_num' => array
+            (
+                //'fixed' => true,
+                'width' => '230',
+                'show' => '"{order_num}" ? "{order_num}" : "-"',
+            ),
             'account',
-            'cash',
+            'cash' => array
+            (
+                'width' => '230',
+                'name' => '商品 / 面值 / 实付',
+                'show' => 'Dever::load("manage", "seller")->showOrderCash("{cate_id}", "{goods_id}", "{sku_id}", "{cash}", "{price}")',
+            ),
             //'num',
             //'price',
-            'seller_id',
-            'seller_order_num',
             //'channel_id',
-            'status',
-            /*
-            'channel_callback_date' => array
+            'status' => array
             (
-                'name' => '回调时间',
-                'type' => 'show',
-                'show' => '{channel_callback_date} > 0 ? date("Y-m-d H:i", {channel_callback_date}) : "-"',
-            ),*/
+                'width' => '100',
+                'type' => 'tag',
+                # 会alert弹出
+                'remote' => 'seller/manage.showOrderExpand',
+                'style' => 'info',
+                'show' => 'Dever::load("manage", "seller")->showOrderStatus("{status}")',
+            ),
             'cdate' => array
             (
                 'name' => '下单时间',
             ),
+            'finish_date' => array
+            (
+                'name' => '完成时间',
+                'type' => 'show',
+                'show' => '{finish_date} > 0 ? date("Y-m-d H:i", {finish_date}) : "-"',
+            ),
         ),
         'data_button' => array
         (
@@ -33,7 +52,18 @@ return array
         ),
         'button' => array
         (
-            
+            '手动下单' => array('fastadd', array
+            (
+                'path' => 'order/order_push',
+                'param' => array(),
+            )),
+            '更改订单状态' => array('oper', 'status,official_order_num,official_msg'),
+            '发回调' => array('api', 'seller/manage.sendCallBack'),
+        ),
+        'export' => array
+        (
+            'out' => '导出',
+            //'manage/common.out' => '自定义导出',
         ),
         'search' => array
         (
@@ -48,16 +78,27 @@ return array
             ),
             'order_num',
             'seller_order_num',
-            'channel_order_num',
+            //'channel_order_num',
             'account',
-            'channel_callback_date' => array
+            'sku_id' => array
             (
-                'name' => '回调时间',
+                'name' => '商品',
+                'placeholder' => '请选择商品',
+                'type' => 'cascader',
+                'option'    => 'Dever::load("goods/manage.getGoodsSku")',
+                'search' => function($key, $type, $value) {
+                    $value = end($value);
+                    return $value;
+                }
+            ),
+            'finish_date' => array
+            (
+                'name' => '完成时间',
                 'type' => 'date',
                 'date_type' => 'datetimerange',
                 'value_format' => 'YYYY-MM-DD HH:mm:ss',
-                'start_placeholder' => '开始回调时间',
-                'end_placeholder' => '结束回调时间',
+                'start_placeholder' => '完成时间',
+                'end_placeholder' => '完成时间',
                 'range_separator' => '至',
             ),
             'cdate' => array
@@ -66,10 +107,35 @@ return array
                 'type' => 'date',
                 'date_type' => 'datetimerange',
                 'value_format' => 'YYYY-MM-DD HH:mm:ss',
-                'start_placeholder' => '开始下单时间',
-                'end_placeholder' => '结束下单时间',
+                'start_placeholder' => '下单时间',
+                'end_placeholder' => '下单时间',
                 'range_separator' => '至',
             ),
         ),
     ),
+
+    'update' => array
+    (
+        'field'    => array
+        (
+            'status' => array
+            (
+                'desc' => '【只可以修改未完成状态的订单】',
+                'type' => 'radio',
+                'option' => array
+                (
+                    10 => '成功',
+                    11 => '失败',
+                ),
+            ),
+            'official_order_num',
+            'official_msg',
+        ),
+    ),
+
+    'oper' => array
+    (
+        'up_start' => 'seller/manage.editOrder',
+        'up_end' => 'seller/manage.addOrderLog',
+    ),
 );

+ 110 - 0
src/dai/seller/table/manage/order_log_list.php

@@ -0,0 +1,110 @@
+<?php
+return array
+(
+    'source' => 'seller/order_log',
+    'list' => array
+    (
+        //'expand' => 'seller/manage.showOrderExpand',
+        //'stat' => 'seller/manage.showOrderStat',
+        'field'      => array
+        (
+            'seller_id',
+            'seller_order_num',
+            'order_num' => array
+            (
+                //'fixed' => true,
+                'width' => '230',
+                'show' => '"{order_num}" ? "{order_num}" : "-"',
+            ),
+            'account',
+            'cash' => array
+            (
+                'width' => '230',
+                'name' => '商品 / 面值 / 实付',
+                'show' => 'Dever::load("manage", "seller")->showOrderCash("{cate_id}", "{goods_id}", "{sku_id}", "{cash}", "{price}")',
+            ),
+            //'num',
+            //'price',
+            //'channel_id',
+            'status' => array
+            (
+                'width' => '100',
+                'type' => 'tag',
+                # 会alert弹出
+                'remote' => 'seller/manage.showOrderLogExpand',
+                'style' => 'info',
+                'show' => 'Dever::load("manage", "seller")->showOrderStatus("{status}")',
+            ),
+            'cdate' => array
+            (
+                'name' => '下单时间',
+            ),
+            'finish_date' => array
+            (
+                'name' => '完成时间',
+                'type' => 'show',
+                'show' => '{finish_date} > 0 ? date("Y-m-d H:i", {finish_date}) : "-"',
+            ),
+        ),
+        'data_button' => array
+        (
+            
+        ),
+        'button' => array
+        (
+            
+        ),
+        'export' => array
+        (
+            'out' => '导出',
+            //'manage/common.out' => '自定义导出',
+        ),
+        'search' => array
+        (
+            'status',
+            'seller_id' => array
+            (
+                'name' => '选择商户',
+            ),
+            'channel_id' => array
+            (
+                'name' => '选择渠道',
+            ),
+            'order_num',
+            'seller_order_num',
+            //'channel_order_num',
+            'account',
+            'sku_id' => array
+            (
+                'name' => '商品',
+                'placeholder' => '请选择商品',
+                'type' => 'cascader',
+                'option'    => 'Dever::load("goods/manage.getGoodsSku")',
+                'search' => function($key, $type, $value) {
+                    $value = end($value);
+                    return $value;
+                }
+            ),
+            'finish_date' => array
+            (
+                'name' => '完成时间',
+                'type' => 'date',
+                'date_type' => 'datetimerange',
+                'value_format' => 'YYYY-MM-DD HH:mm:ss',
+                'start_placeholder' => '完成时间',
+                'end_placeholder' => '完成时间',
+                'range_separator' => '至',
+            ),
+            'cdate' => array
+            (
+                'name' => '下单时间',
+                'type' => 'date',
+                'date_type' => 'datetimerange',
+                'value_format' => 'YYYY-MM-DD HH:mm:ss',
+                'start_placeholder' => '下单时间',
+                'end_placeholder' => '下单时间',
+                'range_separator' => '至',
+            ),
+        ),
+    ),
+);

+ 46 - 0
src/dai/seller/table/manage/order_push.php

@@ -0,0 +1,46 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'start' => 'seller/manage.createOrder',
+        'field'    => array
+        (
+            'seller_id' => array
+            (
+                'rules' => true,
+            ),
+            'goods' => array
+            (
+                'name' => '商品',
+                'type' => 'cascader',
+                # 仅显示最后一级
+                //'all' => false,
+                'option'    => 'Dever::load("goods/manage.getGoods")',
+                'remote' => 'goods/manage.getSku',
+                # 无需默认值
+                'remote_default' => false,
+                'rules' => true,
+            ),
+            'goods_id' => array
+            (
+                'name' => '规格',
+                'type' => 'hidden',
+                'rules' => true,
+            ),
+            'sku_id' => array
+            (
+                'name' => '规格',
+                'type' => 'select',
+                'rules' => true,
+            ),
+            'data' => array
+            (
+                'type' => 'textarea',
+                'rows' => 10,
+                'placeholder' => '直接输出要充值的账号,如手机号、卡号等,多个用换行隔开',
+                'rules' => true,
+            ),
+        ),
+    ),
+);

+ 49 - 0
src/dai/seller/table/manage/order_stat.php

@@ -0,0 +1,49 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'day' => array
+            (
+                'show' => 'date("Y-m-d", {day})',
+            ),
+            'total_num',
+            'success_num',
+            'error_num',
+            'total_cash',
+            'success_cash',
+            'error_cash',
+            'seller_actual_cash',
+            'channel_actual_cash',
+            'profit_cash',
+            'cost' => array
+            (
+                'name' => '平均成本',
+                'show'  => 'round({channel_actual_cash} / {success_cash}, 4)',
+            ),
+        ),
+        'data_button' => array
+        (
+            
+        ),
+        'button' => array
+        (
+            
+        ),
+        'search' => array
+        (
+            'day' => array
+            (
+                'name' => '时间',
+                'type' => 'date',
+                'date_type' => 'datetimerange',
+                'value_format' => 'YYYY-MM-DD HH:mm:ss',
+                'start_placeholder' => '开始时间',
+                'end_placeholder' => '结束时间',
+                'range_separator' => '至',
+            ),
+        ),
+    ),
+);

+ 51 - 0
src/dai/seller/table/manage/order_stat_channel.php

@@ -0,0 +1,51 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'channel_id',
+            'day' => array
+            (
+                'show' => 'date("Y-m-d", {day})',
+            ),
+            'total_num',
+            'success_num',
+            'error_num',
+            'total_cash',
+            'success_cash',
+            'error_cash',
+            'seller_actual_cash',
+            'channel_actual_cash',
+            'profit_cash',
+            'cost' => array
+            (
+                'name' => '平均成本',
+                'show'  => 'round({channel_actual_cash} / {success_cash}, 4)',
+            ),
+        ),
+        'data_button' => array
+        (
+            
+        ),
+        'button' => array
+        (
+            
+        ),
+        'search' => array
+        (
+            'channel_id',
+            'day' => array
+            (
+                'name' => '时间',
+                'type' => 'date',
+                'date_type' => 'datetimerange',
+                'value_format' => 'YYYY-MM-DD HH:mm:ss',
+                'start_placeholder' => '开始时间',
+                'end_placeholder' => '结束时间',
+                'range_separator' => '至',
+            ),
+        ),
+    ),
+);

+ 51 - 0
src/dai/seller/table/manage/order_stat_seller.php

@@ -0,0 +1,51 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'seller_id',
+            'day' => array
+            (
+                'show' => 'date("Y-m-d", {day})',
+            ),
+            'total_num',
+            'success_num',
+            'error_num',
+            'total_cash',
+            'success_cash',
+            'error_cash',
+            'seller_actual_cash',
+            'channel_actual_cash',
+            'profit_cash',
+            'cost' => array
+            (
+                'name' => '平均成本',
+                'show'  => 'round({channel_actual_cash} / {success_cash}, 4)',
+            ),
+        ),
+        'data_button' => array
+        (
+            
+        ),
+        'button' => array
+        (
+            
+        ),
+        'search' => array
+        (
+            'seller_id',
+            'day' => array
+            (
+                'name' => '时间',
+                'type' => 'date',
+                'date_type' => 'datetimerange',
+                'value_format' => 'YYYY-MM-DD HH:mm:ss',
+                'start_placeholder' => '开始时间',
+                'end_placeholder' => '结束时间',
+                'range_separator' => '至',
+            ),
+        ),
+    ),
+);

+ 75 - 3
src/dai/seller/table/order.php

@@ -2,12 +2,15 @@
 return array
 (
     'name' => '商户订单表',
+    'cdate' => 'mtime',//mtime保存为微秒,wtime保存为毫秒,默认是秒 暂时不支持,后续升级
     'struct' => array
     (
         'order_num' => array
         (
             'name'      => '系统订单号',
             'type'      => 'varchar(100)',
+            # 记录为influxdb的fields字段
+            //'fields'    => true,
         ),
 
         'account' => array
@@ -16,6 +19,18 @@ return array
             'type'      => 'varchar(100)',
         ),
 
+        'other' => array
+        (
+            'name'      => '其他参数',
+            'type'      => 'varchar(2000)',
+        ),
+
+        'cate_id' => array
+        (
+            'name'      => '商品分类id',
+            'type'      => 'int(11)',
+        ),
+
         'goods_id' => array
         (
             'name'      => '商品id',
@@ -31,19 +46,29 @@ return array
         'num'        => array
         (
             'type'      => 'int(11)',
-            'name'      => '总数量',
+            'name'      => '数量',
+            'fields'    => true,
         ),
 
         'cash'      => array
         (
             'type'      => 'decimal(11,2)',
-            'name'      => '总面值',
+            'name'      => '面值',
+            'fields'    => true,
         ),
 
         'price'      => array
         (
             'type'      => 'decimal(11,2)',
             'name'      => '实付金额',
+            'fields'    => true,
+        ),
+
+        'buy_price'      => array
+        (
+            'type'      => 'decimal(11,2)',
+            'name'      => '采购金额',
+            'fields'    => true,
         ),
 
         'seller_id' => array
@@ -63,12 +88,16 @@ return array
         (
             'name'      => '商户请求数据',
             'type'      => 'varchar(2000)',
+            'fields'    => true,
+            'base64'    => true,
         ),
 
         'seller_callback' => array
         (
             'name'      => '商户回调数据',
-            'type'      => 'varchar(2000)',
+            'type'      => 'varchar(200)',
+            'fields'    => true,
+            'base64'    => true,
         ),
 
         'seller_callback_date' => array
@@ -81,6 +110,7 @@ return array
         (
             'name'      => '商户回调次数',
             'type'      => 'int(11)',
+            'default'   => '0',
         ),
 
         'channel_id' => array
@@ -90,6 +120,24 @@ return array
             'value'     => 'channel/info',
         ),
 
+        'channel_goods_id' => array
+        (
+            'name'      => '渠道商品id',
+            'type'      => 'int(11)',
+        ),
+
+        'channel_goods_discount' => array
+        (
+            'name'      => '渠道商品折扣',
+            'type'      => 'int(11)',
+        ),
+
+        'channel_order_date' => array
+        (
+            'name'      => '渠道下单时间',
+            'type'      => 'int(11)',
+        ),
+
         'channel_order_num' => array
         (
             'name'      => '渠道订单号',
@@ -100,18 +148,24 @@ return array
         (
             'name'      => '渠道请求数据',
             'type'      => 'varchar(2000)',
+            'fields'    => true,
+            'base64'    => true,
         ),
 
         'channel_response' => array
         (
             'name'      => '渠道响应数据',
             'type'      => 'varchar(2000)',
+            'fields'    => true,
+            'base64'    => true,
         ),
 
         'channel_callback' => array
         (
             'name'      => '渠道回调数据',
             'type'      => 'varchar(2000)',
+            'fields'    => true,
+            'base64'    => true,
         ),
 
         'channel_callback_date' => array
@@ -148,6 +202,24 @@ return array
                 11 => '失败',
             ),
         ),
+
+        'finish' => array
+        (
+            'name'      => '完成状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 2,
+            'value'     => array
+            (
+                1 => '已完成',
+                2 => '进行中',
+            ),
+        ),
+
+        'finish_date' => array
+        (
+            'name'      => '完成时间',
+            'type'      => 'int(11)',
+        ),
     ),
 
     'index' => array

+ 15 - 0
src/dai/seller/table/order_bak.php

@@ -0,0 +1,15 @@
+<?php
+$config = include('order.php');
+$config['partition'] = array
+(
+    'create' => true,
+    'database' => 'date("Y")',
+    'table' => 'date("Ym")',
+    'field' => array
+    (
+        'type' => 'range',
+        'field' => 'cdate', 
+        'value' => 'date("Y-m-d 23:60:60")'
+    ),
+);
+return $config;

+ 4 - 0
src/dai/seller/table/order_log.php

@@ -0,0 +1,4 @@
+<?php
+$config = include('order.php');
+$config['store'] = 'log';
+return $config;

+ 38 - 0
src/dai/seller/table/order_push.php

@@ -0,0 +1,38 @@
+<?php
+return array
+(
+    'name' => '后台下单记录表',
+    'struct' => array
+    (
+        'seller_id' => array
+        (
+            'name'      => '商户',
+            'type'      => 'int(11)',
+            'value'     => 'seller/info',
+        ),
+
+        'goods' => array
+        (
+            'name'      => '商品分类+商品id',
+            'type'      => 'varchar(100)',
+        ),
+
+        'goods_id' => array
+        (
+            'name'      => '商品id',
+            'type'      => 'int(11)',
+        ),
+
+        'sku_id' => array
+        (
+            'name'      => 'SKUid',
+            'type'      => 'int(11)',
+        ),
+
+        'data'      => array
+        (
+            'name'      => '充值数据',
+            'type'      => 'varchar(500)',
+        ),
+    ),
+);

+ 73 - 0
src/dai/seller/table/order_stat.php

@@ -0,0 +1,73 @@
+<?php
+return array
+(
+    'name' => '订单统计表',
+    'struct' => array
+    (
+        'day' => array
+        (
+            'name'      => '日期',
+            'type'      => 'int(11)',
+        ),
+
+        'total_num'      => array
+        (
+            'name'      => '订单总数',
+            'type'      => 'int(11)',
+        ),
+
+        'success_num'      => array
+        (
+            'name'      => '成功订单数',
+            'type'      => 'int(11)',
+        ),
+
+        'error_num'      => array
+        (
+            'name'      => '失败订单数',
+            'type'      => 'int(11)',
+        ),
+
+        'total_cash'      => array
+        (
+            'name'      => '总金额',
+            'type'      => 'decimal(11,2)',
+            'fields'    => true,
+        ),
+
+        'success_cash'      => array
+        (
+            'name'      => '成功金额',
+            'type'      => 'decimal(11,2)',
+            'fields'    => true,
+        ),
+
+        'error_cash'      => array
+        (
+            'name'      => '失败金额',
+            'type'      => 'decimal(11,2)',
+            'fields'    => true,
+        ),
+
+        'seller_actual_cash'      => array
+        (
+            'name'      => '实际成功金额',
+            'type'      => 'decimal(11,2)',
+            'fields'    => true,
+        ),
+
+        'channel_actual_cash'      => array
+        (
+            'name'      => '实际采购成功金额',
+            'type'      => 'decimal(11,2)',
+            'fields'    => true,
+        ),
+
+        'profit_cash'      => array
+        (
+            'name'      => '利润',
+            'type'      => 'decimal(11,4)',
+            'fields'    => true,
+        ),
+    ),
+);

+ 15 - 0
src/dai/seller/table/order_stat_channel.php

@@ -0,0 +1,15 @@
+<?php
+$config = include('order_stat.php');
+$config['name'] = '渠道订单统计表';
+$config['struct']['channel_id'] = array
+(
+    'name'      => '渠道',
+    'type'      => 'int(11)',
+    'value'     => 'channel/info',
+);
+$config['struct']['data'] = array
+(
+    'type'      => 'varchar(1000)',
+    'name'      => '子数据',
+);
+return $config;

+ 15 - 0
src/dai/seller/table/order_stat_seller.php

@@ -0,0 +1,15 @@
+<?php
+$config = include('order_stat.php');
+$config['name'] = '商户订单统计表';
+$config['struct']['seller_id'] = array
+(
+    'name'      => '商户',
+    'type'      => 'int(11)',
+    'value'     => 'seller/info',
+);
+$config['struct']['data'] = array
+(
+    'type'      => 'varchar(1000)',
+    'name'      => '子数据',
+);
+return $config;

+ 1 - 1
src/yuan/goods/api/Manage.php

@@ -31,7 +31,7 @@ class Manage extends Auth
         }
         $result = array();
         $result['goods_id']['value'] = $value;
-        $sku = Dever::db('info_sku', 'goods')->select(array('info_id' => $value))->fetchAll();
+        $sku = Dever::db('info_sku', 'goods')->select(array('info_id' => $value));
         if ($sku) {
             $option = array();
             foreach ($sku as $k => $v) {

+ 60 - 4
src/yuan/goods/lib/Manage.php

@@ -8,7 +8,7 @@ class Manage extends Auth
     {
         $result = array();
         if ($info_id) {
-            $result = Dever::db('info_spec', 'goods')->select(array('info_id' => $info_id))->fetchAll();
+            $result = Dever::db('info_spec', 'goods')->select(array('info_id' => $info_id));
             if ($result) {
                 foreach ($result as $k => $v) {
                     $result[$k]['type'] = 'show';
@@ -16,7 +16,7 @@ class Manage extends Auth
                     $result[$k]['show'] = true;
                     $result[$k]['fixed'] = true;
                     $result[$k]['key'] = $v['name'];
-                    $value = Dever::db('info_spec_value', 'goods')->select(array('info_id' => $info_id, 'spec_id' => $v['id']))->fetchAll();
+                    $value = Dever::db('info_spec_value', 'goods')->select(array('info_id' => $info_id, 'spec_id' => $v['id']));
                     if ($value) {
                         foreach ($value as $k1 => $v1) {
                             $value[$k1]['parent'] = $result[$k]['key'];
@@ -39,10 +39,10 @@ class Manage extends Auth
     # 获取商品
     public function getGoods()
     {
-        $cate = Dever::db('cate', 'goods')->select([])->fetchAll();
+        $cate = Dever::db('cate', 'goods')->select([]);
         $result = array();
         foreach ($cate as $k => $v) {
-            $goods = Dever::db('info', 'goods')->select(array('cate_id' => $v['id']))->fetchAll();
+            $goods = Dever::db('info', 'goods')->select(array('cate_id' => $v['id']));
             if ($goods) {
                 $result[] = array
                 (
@@ -54,4 +54,60 @@ class Manage extends Auth
         }
         return $result;
     }
+
+    # 获取商品规格
+    public function getGoodsSku()
+    {
+        $cate = Dever::db('cate', 'goods')->select([]);
+        $result = array();
+        foreach ($cate as $k => $v) {
+            $goods = Dever::db('info', 'goods')->select(array('cate_id' => $v['id']));
+            if ($goods) {
+                foreach ($goods as $k1 => $v1) {
+                    $sku = Dever::db('info_sku', 'goods')->select(array('info_id' => $v1['id']));
+                    $option = array();
+                    foreach ($sku as $k2 => $v2) {
+                        if ($v['key'] != -1) {
+                            $spec = Dever::db('info_spec_value', 'goods')->find(array('id' => array('in', $v2['key'])), array('col' => 'id,group_concat(value) as name', 'group' => 'info_id'));
+                            if ($spec) {
+                                $spec['id'] = $v2['id'];
+                                $option[] = $spec;
+                            }
+                        } else {
+                            $option = array();
+                        }
+                    }
+                    $goods[$k1]['children'] = $option;
+                }
+                $result[] = array
+                (
+                    'id' => $v['id'],
+                    'name' => $v['name'],
+                    'children' => $goods,
+                );
+            }
+        }
+        return $result;
+    }
+
+    # 将数据保存到redis中
+    public function saveRedis()
+    {
+        
+    }
+
+    # 获取商品分类
+    public function getCate()
+    {
+        $cate = array
+        (
+            array
+            (
+                'id' => -1,
+                'name' => '全部',
+            )
+        );
+        $cate = array_merge($cate, Dever::db('cate', 'goods')->select([]));
+        return $cate;
+    }
 }

+ 1 - 0
src/yuan/goods/table/cate.php

@@ -28,6 +28,7 @@ return array
             '"话费","hf","/^1\d{10}$/"',
             '"中石化","zsh","/^1\d{18}$/"',
             '"中石油","zsy","/^(?:7|9)\d{15}$/"',
+            '"权益卡","qyk",""',
         ),
         'num' => 1,
     ),

+ 23 - 0
src/yuan/goods/table/manage/cate.php

@@ -0,0 +1,23 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'id',
+            'name',
+            'key',
+            'rule',
+            'cdate',
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+        ),
+        'button' => array
+        (
+            '新增' => 'fastadd',
+        ),
+    ),
+);