dever 6 years ago
parent
commit
147081a654
5 changed files with 147 additions and 6 deletions
  1. 1 1
      config/base.php
  2. 19 0
      database/order.php
  3. 91 0
      database/project.php
  4. 30 4
      lib/Core.php
  5. 6 1
      src/Api.php

+ 1 - 1
config/base.php

@@ -9,7 +9,7 @@ $config['base'] = array
 		(
 			'wechat' => '微信支付',
 			//'alipay' => '支付宝',
-			'cmbc' => '招商支付',
+			//'cmbc' => '招商支付',
 		),
 
 		'status' => array

+ 19 - 0
database/order.php

@@ -7,6 +7,11 @@ $account = function()
 	return Dever::db('pay/account')->state();
 };
 
+$project = function()
+{
+	return Dever::db('pay/project')->state();
+};
+
 $status = Dever::config('base', 'pay')->pay['status'];
 
 return array
@@ -122,6 +127,19 @@ return array
 			'list'		=> true,
 		),
 
+		'project_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属项目',
+			'default' 	=> '0',
+			'desc' 		=> '所属项目',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $project,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
 		'cash'		=> array
 		(
 			'type' 		=> 'varchar-11',
@@ -194,5 +212,6 @@ return array
 		'insert' => false,
 		'edit' => false,
 		'delete' => false,
+		'excel' => true,
 	),
 );

+ 91 - 0
database/project.php

@@ -0,0 +1,91 @@
+<?php
+
+$type = Dever::config('base', 'pay')->pay['type'];
+
+return array
+(
+	# 表名
+	'name' => 'project',
+	# 显示给用户看的名称
+	'lang' => '项目管理',
+	'order' => 8,
+	# 数据结构
+	'struct' => array
+	(
+	
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			'list'		=> true,
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '项目名称',
+			'default' 	=> '',
+			'desc' 		=> '项目名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '密匙key',
+			'default' 	=> '',
+			'desc' 		=> '密匙key',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'notify'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '支付完成回调接口',
+			'default' 	=> '',
+			'desc' 		=> '支付完成回调接口',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '申请时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'search'	=> 'date',
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	# 默认值
+	'default' => array
+	(
+		'col' => 'name,key,state,cdate',
+		'value' => array
+		(
+			'"默认项目","dever_pay_2018",1,' . time(),
+		),
+	),
+);

+ 30 - 4
lib/Core.php

@@ -22,10 +22,36 @@ class Core
 			$this->log($msg, $info);
 			$db->update($param);
 
-			$state = Dever::config('base', 'project')->pay_notify;
-			if ($state) {
-				$this->log($state, $param);
-				Dever::load($state, $info['product_id'], $info['uid'], $info['cash'], $order_id, $param['status'], $msg);
+			$notify = false;
+			$key = false;
+			if (isset($info['project_id']) && $info['project_id']) {
+				$project = Dever::db('pay/project')->one($info['project_id']);
+				if ($project && $project['notify']) {
+					$notify = $project['notify'];
+					$key = md5($project['key']);
+				}
+			}
+
+			if (!$notify) {
+				$notify = Dever::config('base', 'project')->pay_notify;
+				$key = md5($notify);
+			}
+			
+			if ($notify && $key) {
+				$this->log($notify, $param);
+				$send = array();
+				$send['product_id'] = $info['product_id'];
+				$send['uid'] = $info['uid'];
+				$send['cash'] = $info['cash'];
+				$send['order_id'] = $order_id;
+				$send['status'] = $param['status'];
+				$send['msg'] = $msg;
+				$send['time'] = time();
+				$send['nonce'] = Dever::nonce();
+				ksort($send);
+				$send['signature'] = md5($key . '&' . http_build_query($send));
+
+				Dever::load($notify, $send);
 			}
 		} else {
 			$this->log('支付失败', '错误的订单id:' . $order_id);

+ 6 - 1
src/Api.php

@@ -22,7 +22,7 @@ class Api
 				return $order;
 			}
 		}
-		return $this->method->order($this->account_id, $this->uid, $this->username, $this->product_id, $this->name, $this->cash, $this->openid, $type, $this->order_id);
+		return $this->method->order($this->account_id, $this->project_id, $this->uid, $this->username, $this->product_id, $this->name, $this->cash, $this->openid, $type, $this->order_id);
 	}
 
 	/**
@@ -89,6 +89,7 @@ class Api
 			return;
 		}
 		$this->account_id = $this->getParam($param, 'account_id');
+		$this->project_id = $this->getParam($param, 'project_id');
 		$this->uid = $this->getParam($param, 'uid');
 		$this->username = $this->getParam($param, 'username');
 		$this->product_id = $this->getParam($param, 'product_id');
@@ -98,6 +99,10 @@ class Api
 		$this->order_id = $this->getParam($param, 'order_id');
 		$this->openid = $this->getParam($param, 'openid');
 
+		if (!$this->project_id) {
+			$this->project_id = false;
+		}
+
 		if (!$this->order_id) {
 			$this->order_id = false;
 		}