This commit is contained in:
wanyongkang
2020-10-13 09:38:55 +08:00
parent 517b026891
commit 7d7d8f09ad
5 changed files with 245 additions and 102 deletions

View File

@@ -1,13 +1,20 @@
<?php
/*
* @Author: 万永康
* @Date: 2020-10-11 12:32:50
* @LastEditTime: 2020-10-12 10:29:34
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /phptest/alipay/Alipay.php
*/
namespace alipay;
require_once APP_PATH.'aop/AopClient.php';
require_once APP_PATH.'aop/AopCertification.php';
require_once APP_PATH.'aop/request/AlipayTradeQueryRequest.php';
require_once APP_PATH.'aop/request/AlipayTradePagePayRequest.php';
require_once APP_PATH.'aop/request/AlipayTradeAppPayRequest.php';
require_once APP_PATH . 'aop/AopClient.php';
require_once APP_PATH . 'aop/AopCertification.php';
require_once APP_PATH . 'aop/request/AlipayTradeQueryRequest.php';
require_once APP_PATH . 'aop/request/AlipayTradePagePayRequest.php';
require_once APP_PATH . 'aop/request/AlipayFundTransUniTransferRequest.php';
/**
* 证书类型AopClient功能方法使用测试
@@ -16,18 +23,19 @@ require_once APP_PATH.'aop/request/AlipayTradeAppPayRequest.php';
* 3、pageExecute 调用示例
*/
class Alipay {
class Alipay
{
//配置内容
protected static $config = [];
public function __construct()
{
self::$config = require APP_PATH.'config/config.php';
self::$config = require APP_PATH . 'config/config.php';
}
/**
*
*
* web 付款
* $param = [
* 'body' => '123',
@@ -37,12 +45,12 @@ require_once APP_PATH.'aop/request/AlipayTradeAppPayRequest.php';
* 'product_code' => "FAST_INSTANT_TRADE_PAY",//QUICK_WAP_PAY
* 'timeout_express'=>"15m"
*];
*
*
*
*
*/
public static function pay($param){
//1、execute 使用
$aop = new \AopClient ();
public static function pay($param)
{
$aop = new \AopClient();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = self::$config['alipay']['app_id'];
@@ -53,13 +61,57 @@ require_once APP_PATH.'aop/request/AlipayTradeAppPayRequest.php';
$aop->postCharset = 'utf-8';
$aop->format = 'json';
$request = new \AlipayTradePagePayRequest ();
$request = new \AlipayTradePagePayRequest();
$param = json_encode($param);
$request->setBizContent($param);
$result = $aop->pageExecute($request);
echo $result;
}
}
/**
* @description: 转帐到支付宝账户
* @param {type}$param
* [
* 'out_biz_no'=>'201806300001',
* 'trans_amount' => '0.01',
* 'product_code' => 'TRANS_ACCOUNT_NO_PWD',
* 'payee_info' => {
* 'identity' => '208812*****41234',
* 'identity_type' => 'ALIPAY_LOGON_ID',
* 'name' => 'peter'
* },
* 'remark' => '提现-单笔转帐'
* ]
* @return {type}
*/
public static function transfer()
{
$aop = new \AopClient();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = self::$config['alipay']['app_id'];
$aop->rsaPrivateKey = self::$config['alipay']['private_key'];
$aop->alipayrsaPublicKey = self::$config['alipay']['public_key'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'utf-8';
$aop->format = 'json';
$request = new \AlipayFundTransUniTransferRequest();
$param = json_encode($param);
$request->setBizContent($param);
$result = $aop->execute ( $request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
return true;
} else {
return false;
}
}
}

View File

@@ -1,10 +1,17 @@
<?php
/*
* @Descripttion:
* @version:
* @Author: kangkang
* @Date: 2020-10-11 11:22:56
* @LastEditors: kangkang
* @LastEditTime: 2020-10-12 12:06:20
*/
namespace app\order\controller;
use app\order\model\CashOut as CashMoedl;
use fastphp\base\Controller;
use alipay\Alipay;
class Admin extends Controller
{
@@ -36,7 +43,13 @@ class Admin extends Controller
}
$page = ($_GET['page'] - 1) * 50;
$cash = new CashMoedl;
$list = $cash->getListPage('*', 'id desc', "$page,50");
$list = $cash->getListPage([], '*', 'id desc', "$page,50");
//提现状态
$status = ['待处理', '同意', '拒绝'];
foreach ($list as &$v) {
$v['status'] = $status[$v['status']];
$v['alipay_account'] = substr($v['alipay_account'], 0, 3) . '***' . substr($v['alipay_account'], -3);
}
$data = [
'Code' => 10000,
'data' => $list,
@@ -44,28 +57,56 @@ class Admin extends Controller
echo json_encode($data);
}
//处理提现申请
/**
* @description: 订单搜索
* @param {type} 搜索会员账号
* @return {type} 该会员所有的订单信息 按照id倒序
*/
public function handle()
{
$data = json_decode(file_get_contents("php://input"),true)['info'];
$data = json_decode(file_get_contents("php://input"), true)['info'];
$id = $data['id'];
unset($data['update_time']);
unset($data['create_time']);
unset($data['id']);
$user = $this->userinfo;
$data['op_user'] = $user['LoginName'];
$status = ['0', '1', '2'];
if(!in_array($data['status'],$status)){
if (!in_array($data['status'], $status)) {
unset($data['status']);
}
$cash = new CashMoedl;
$up_status = $cash->where(['id'=>$id])->update($data);
$up_status = $cash->where(['id' => $id])->update($data);
$return_info = [
'Code' => 10000,
];
echo json_encode($return_info);
}
//获取记录
public function search()
{
$username = json_decode(file_get_contents("php://input"), true)['username'];
$cash = new CashMoedl;
if ($username) {
$list = $cash->getListPage(['username' => $username], '*', 'id desc', '100');
} else {
$list = $cash->getListPage();
$count = $cash->getCount();
}
//提现状态
$status = ['待处理', '同意', '拒绝'];
foreach ($list as &$v) {
$v['status'] = $status[$v['status']];
$v['alipay_account'] = substr($v['alipay_account'], 0, 3) . '***' . substr($v['alipay_account'], -3);
}
$data = [
'Code' => 10000,
'count' => $count['count'] ?? 0,
'data' => $list,
];
echo json_encode($data);
}
}

View File

@@ -1,4 +1,12 @@
<?php
/*
* @Author: your name
* @Date: 2020-10-10 13:58:14
* @LastEditTime: 2020-10-12 11:15:09
* @LastEditors: your name
* @Description: In User Settings Edit
* @FilePath: /phptest/app/order/controller/Index.php
*/
namespace app\order\controller;
@@ -26,4 +34,24 @@ class Index extends Controller
}
}
//获取记录
public function getData()
{
$cash = new CashMoedl;
$list = $cash->getListPage([],'username,money,apply_reason,alipay_account,status,create_time');
//提现状态
$status = ['待处理', '提现成功', '提现未成功'];
foreach ($list as &$v) {
$v['status'] = $status[$v['status']];
$v['alipay_account'] = substr($v['alipay_account'], 0, 3) . '***' . substr($v['alipay_account'], -5);
}
$count = $cash->getCount();
$data = [
'Code' => 10000,
'count' => $count['count'],
'data' => $list,
];
echo json_encode($data);
}
}

View File

@@ -1,5 +1,12 @@
<?php
/*
* @Author: your name
* @Date: 2020-09-30 17:32:46
* @LastEditTime: 2020-10-12 11:16:10
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /phptest/fastphp/base/Model.php
*/
namespace fastphp\base;
@@ -12,12 +19,12 @@ class Model extends Sql
public function __construct()
{
//获取数据库表名
if(!$this->table){
if (!$this->table) {
//获取模型类名称
$this->model = get_class($this);
//删除模型名最后的model
$this->model = substr($this->model,0,-5);
$this->model = substr($this->model, 0, -5);
//数据库表名与类名一致
$this->table = strtolower($this->model);
@@ -26,10 +33,11 @@ class Model extends Sql
/**
* 获取总数目
*
*
*/
public function getCount(){
return $this->field('count(1) as count')->fetch();
public function getCount($where = [])
{
return $this->field('count(1) as count')->where($where)->fetch();
}
/**
@@ -39,9 +47,10 @@ class Model extends Sql
* @param $limit = '100' 限制查询100条
* $limit = '2,100' 查询第二页 100条数据
*/
public function getListPage($fields = '*',$order = 'id desc', $page = '50')
public function getListPage($where = [],$fields = '*', $order = 'id desc', $limit = '50')
{
return $this->field($fields)->order($order)->limit($page)->fetchAll();
return $this->field($fields)->where($where)->order($order)->limit($limit)->fetchAll();
}
}
}

View File

@@ -1,6 +1,5 @@
<?php
namespace fastphp\db;
use \PDOStatement;
@@ -27,31 +26,32 @@ class Sql
* 多条件查询
* ['id'=>['<',100]]
*/
public function where($where){
public function where($where)
{
$this->param = [];
$this->filter = '';
if($where){
if ($where) {
$this->filter .= ' WHERE ';
if(is_string($where)){
$this->filter .= ' '.$where;
if (is_string($where)) {
$this->filter .= ' ' . $where;
} else {
$flag = true;
foreach ($where as $key => $value){
if($flag){
foreach ($where as $key => $value) {
if ($flag) {
$flag = false;
if(is_array($value)){
$this->filter .= ' `'.$key.'` '.$value[0].' :'.$key;
if (is_array($value)) {
$this->filter .= ' `' . $key . '` ' . $value[0] . ' :' . $key;
$this->param[$key] = $value[1];
} else {
$this->filter .= ' `'.$key.'` = :'.$key;
$this->filter .= ' `' . $key . '` = :' . $key;
$this->param[$key] = $value;
}
} else {
if(is_array($value)){
$this->filter .= ' AND `'.$key.'` '.$value[0].' :'.$key;
if (is_array($value)) {
$this->filter .= ' AND `' . $key . '` ' . $value[0] . ' :' . $key;
$this->param[$key] = $value[1];
} else {
$this->filter .= ' AND `'.$key.'` = :'.$key;
$this->filter .= ' AND `' . $key . '` = :' . $key;
$this->param[$key] = $value;
}
}
@@ -67,37 +67,39 @@ class Sql
* @return $this
* $order='id desc'
*/
public function order($order = 'id desc'){
if($order){
$this->filter .= ' ORDER BY '.$order.' ';
public function order($order = 'id desc')
{
if ($order) {
$this->filter .= ' ORDER BY ' . $order . ' ';
}
return $this;
}
/**
* group by
* @param array $order
* @return $this
* $group=['sex','name']
*/
public function group($group = []){
if($order){
public function group($group = [])
{
if ($order) {
$this->filter .= ' GROUP BY ';
$this->filter .= ' '.implode(' ,',$group).' ';
$this->filter .= ' ' . implode(' ,', $group) . ' ';
}
return $this;
}
/**
* 查询limit
* @param string
* @param string
* @return $this
* $limit = '100' 限制查询100条
* $limit = '2,100' 查询第二页 100条数据
*/
public function limit($limit = '100'){
$this->filter .= ' LIMIT '.$limit.' ';
public function limit($limit = '100')
{
$this->filter .= ' LIMIT ' . $limit . ' ';
return $this;
}
@@ -107,7 +109,8 @@ class Sql
* @return $this
* $field = 'id,count(1),sub(num)'
*/
public function field($field = '*'){
public function field($field = '*')
{
$this->field = $field;
return $this;
}
@@ -116,11 +119,12 @@ class Sql
* 查询所有
* @return mixed
*/
public function fetchAll(){
$sql = sprintf('SELECT %s FROM `%s` %s',$this->field,$this->table,$this->filter);
public function fetchAll()
{
$sql = sprintf('SELECT %s FROM `%s` %s', $this->field, $this->table, $this->filter);
$this->filter = '';
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth,$this->param);
$sth = $this->formatParam($sth, $this->param);
$sth->execute();
return $sth->fetchAll();
@@ -130,11 +134,12 @@ class Sql
* 查询一条
* @return mixed
*/
public function fetch(){
$sql = sprintf('SELECT %s FROM `%s` %s',$this->field,$this->table,$this->filter);
public function fetch()
{
$sql = sprintf('SELECT %s FROM `%s` %s', $this->field, $this->table, $this->filter);
$this->filter = '';
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth,$this->param);
$sth = $this->formatParam($sth, $this->param);
$sth->execute();
return $sth->fetch();
@@ -145,11 +150,12 @@ class Sql
* @param $id
* @return mixed
*/
public function delete(){
$sql = sprintf('DELETE FROM `%s` %s',$this->table,$this->filter);
public function delete()
{
$sql = sprintf('DELETE FROM `%s` %s', $this->table, $this->filter);
$this->filter = '';
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth,$this->param);
$sth = $this->formatParam($sth, $this->param);
$sth->execute();
return $sth->rowCount();
@@ -160,10 +166,11 @@ class Sql
* @param $data
* @return mixed
*/
public function add($data){
$sql = sprintf('INSERT INTO `%s` %s',$this->table,$this->formatInsert($data));
public function add($data)
{
$sql = sprintf('INSERT INTO `%s` %s', $this->table, $this->formatInsert($data));
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth,$data);
$sth = $this->formatParam($sth, $data);
$sth->execute();
return $sth->rowCount();
@@ -174,8 +181,9 @@ class Sql
* @param $data
* @return int
*/
public function addAll($data){
$sql = sprintf('INSERT INTO `%s` %s',$this->table,$this->formatInsertAll($data));
public function addAll($data)
{
$sql = sprintf('INSERT INTO `%s` %s', $this->table, $this->formatInsertAll($data));
$sth = Db::pdo()->prepare($sql);
$sth->execute();
@@ -187,12 +195,13 @@ class Sql
* @param $data
* @return mixed
*/
public function update($data){
$sql = sprintf('UPDATE `%s` SET %s %s',$this->table,$this->formatUpdate($data),$this->filter);
public function update($data)
{
$sql = sprintf('UPDATE `%s` SET %s %s', $this->table, $this->formatUpdate($data), $this->filter);
$this->filter = '';
$sth = Db::pdo()->prepare($sql);
$sth = $this->formatParam($sth,$data);
$sth = $this->formatParam($sth,$this->param);
$sth = $this->formatParam($sth, $data);
$sth = $this->formatParam($sth, $this->param);
$sth->execute();
return $sth->rowCount();
@@ -204,10 +213,11 @@ class Sql
* @param array $params
* @return PDOStatement
*/
public function formatParam(PDOStatement $sth,$params = []){
foreach ($params as $param=>&$value){
$param = is_int($param)?$param+1:':'.ltrim($param,':');
$sth->bindParam($param,$value);
public function formatParam(PDOStatement $sth, $params = [])
{
foreach ($params as $param => &$value) {
$param = is_int($param) ? $param + 1 : ':' . ltrim($param, ':');
$sth->bindParam($param, $value);
}
return $sth;
}
@@ -217,16 +227,17 @@ class Sql
* @param $data
* @return string
*/
private function formatInsert($data){
private function formatInsert($data)
{
$fields = [];
$names = [];
foreach ($data as $key=>$value) {
$fields[] = sprintf('`%s`',$key);
$names[] = sprintf(':%s',$key);
foreach ($data as $key => $value) {
$fields[] = sprintf('`%s`', $key);
$names[] = sprintf(':%s', $key);
}
$field = implode(',',$fields);
$name = implode(',',$names);
return sprintf('(%s) VALUES(%s)',$field,$name);
$field = implode(',', $fields);
$name = implode(',', $names);
return sprintf('(%s) VALUES(%s)', $field, $name);
}
/**
@@ -234,18 +245,19 @@ class Sql
* @param $data
* @return string
*/
private function formatInsertAll($data){
private function formatInsertAll($data)
{
$fields = [];
$values ='';
foreach ($data[0] as $key=>$value) {
$fields[] = sprintf('`%s`',$key);
$values = '';
foreach ($data[0] as $key => $value) {
$fields[] = sprintf('`%s`', $key);
}
foreach ($data as $k=>$v){
$values .= '(\''.implode('\',\'',$v).'\'),';
foreach ($data as $k => $v) {
$values .= '(\'' . implode('\',\'', $v) . '\'),';
}
$field = implode(',',$fields);
$values = rtrim($values,',');
return sprintf('(%s) VALUES %s',$field,$values);
$field = implode(',', $fields);
$values = rtrim($values, ',');
return sprintf('(%s) VALUES %s', $field, $values);
}
/**
@@ -253,12 +265,13 @@ class Sql
* @param $data
* @return string
*/
private function formatUpdate($data){
private function formatUpdate($data)
{
$fields = [];
foreach ($data as $key=>$value){
$fields[] = sprintf('`%s`=:%s',$key,$key);
foreach ($data as $key => $value) {
$fields[] = sprintf('`%s`=:%s', $key, $key);
$this->param[$key] = $value;
}
return implode(',',$fields);
return implode(',', $fields);
}
}
}