diff --git a/alipay/Alipay.php b/alipay/Alipay.php index d220bd5..71885be 100644 --- a/alipay/Alipay.php +++ b/alipay/Alipay.php @@ -1,13 +1,20 @@ '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; + } + } +} diff --git a/app/order/controller/Admin.php b/app/order/controller/Admin.php index 48bf51e..50163b2 100644 --- a/app/order/controller/Admin.php +++ b/app/order/controller/Admin.php @@ -1,10 +1,17 @@ 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); + } + } diff --git a/app/order/controller/Index.php b/app/order/controller/Index.php index d466f0e..264f6bc 100644 --- a/app/order/controller/Index.php +++ b/app/order/controller/Index.php @@ -1,4 +1,12 @@ 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); + } + } diff --git a/fastphp/base/Model.php b/fastphp/base/Model.php index d4cdb7d..bdf1466 100644 --- a/fastphp/base/Model.php +++ b/fastphp/base/Model.php @@ -1,5 +1,12 @@ 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(); } -} \ No newline at end of file + +} diff --git a/fastphp/db/Sql.php b/fastphp/db/Sql.php index 35314e9..7090b1f 100644 --- a/fastphp/db/Sql.php +++ b/fastphp/db/Sql.php @@ -1,6 +1,5 @@ ['<',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); } -} \ No newline at end of file +}