作者 景龙
1 个管道 的构建 失败 耗费 3 秒

增加绑定银行卡,充值功能

... ... @@ -14,7 +14,6 @@ return array(
'mch_id' => '1515355581', //支付商户ID
'key' => 'cccccccccccccccccccccccccccccc00',
// 'notify_url' => '/addons/epay/api/notify/type/wechat', //请勿修改此配置
// 'notify_url' => 'http://feipin.w.brotop.cn/api/Wxpay/notify', //请勿修改此配置
'cert_client' => '/epay/certs/apiclient_cert.pem', // 可选, 退款,红包等情况时需要用到
'cert_key' => '/epay/certs/apiclient_key.pem',// 可选, 退款,红包等情况时需要用到
'log' => 1,
... ...
... ... @@ -105,9 +105,6 @@ class Api extends Controller
echo '签名错误';
return;
}
//你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
// $porderModel = new Porder();
// $porderModel->where(['pay_order_sn' => $pay->out_trade_no, 'uid' => $this->user_id])->update(['status'=>$this->order_status[1]]);
//下面这句必须要执行,且在此之前不能有任何输出
echo $pay->success();
return;
... ...
... ... @@ -3,6 +3,7 @@
namespace app\api\controller;
use app\common\controller\Api;
use app\admin\model\Bank;
use think\Db;
use think\Validate;
/**
... ... @@ -42,6 +43,7 @@ class Person extends Api
"company_name": "",//公司名字
"license_num": "",//公司编码
"license_img": ""//公司营业执照
"money":100//账户余额
}
})
*/
... ... @@ -49,7 +51,7 @@ class Person extends Api
if($this->request->isGet()){
$data = Db::table('gc_user')
->where(['id'=>$this->user_id])
->field('id,username,mobile,type,address,id_num,id_img,company_name,license_num,license_img')
->field('id,username,mobile,type,address,id_num,id_img,company_name,license_num,license_img,money')
->find();
$this->success('成功', $data);
}else{
... ... @@ -158,4 +160,84 @@ class Person extends Api
}
$this->success('上传成功',rtrim($images,','));
}
/**
* @ApiTitle (账单明细)
* @ApiSummary (账单明细)
* @ApiMethod (POST)
* @ApiRoute (/api/person/accountDetail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1554270371",
"data": [
{
"id": 1,
"type": 0,//类型 0:充值 1:提现
"money": 0.01,//充值或提现金额
"createtime": "2019-04-03 13:03:57"//时间
}
]
})
*/
public function accountDetail(){
if($this->request->isGet()){
$page = $this->request->get('page');//分页页码
$limit = config('site.page_limit');//分页限制数量
$rule = config('site.gift_pages');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$data = Db::table('gc_account')
->where(['uid'=>$this->user_id])
->page($page,$limit)
->field('id,type,money,createtime')
->select();
foreach($data as &$value){
$value['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
}
$this->success('成功', $data);
}else{
$this->error('请求方式错误');
}
}
/**
* @ApiTitle (绑定银行卡)
* @ApiSummary (绑定银行卡)
* @ApiMethod (POST)
* @ApiRoute (/api/person/bindBank)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="bank_num", type="integer", required=true, description="银行卡号")
* @ApiParams (name="open_bank", type="string", required=true, description="开会行")
* @ApiReturn ({
"code": 1,
"msg": "保存成功",
"time": "1554270371",
"data": null
})
*/
public function bindBank(){
if($this->request->isPost()) {
$bank_num = $this->request->post('bank_num');//银行卡号
$open_bank = $this->request->post('open_bank');//开户行
$rule = config('site.bank');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['bank_num'=>$bank_num,'open_bank'=>$open_bank])) {
$this->error($validate->getError());
}
$bank = new Bank();
$data = $bank::create(['uid'=>$this->user_id,'bank_num'=>$bank_num,'open_bank'=>$open_bank]);
if($data){
$this->success('保存成功');
}else{
$this->error('保存失败');
}
}else{
$this->error('请求方式错误');
}
}
}
... ...
... ... @@ -4,7 +4,7 @@ namespace app\api\controller;
use app\common\controller\Api;
use app\admin\model\User;
use app\admin\model\OffLine;
use app\admin\model\off\Line;
use think\Validate;
/**
* 卖废品接口**
... ... @@ -54,7 +54,7 @@ class Sell extends Api
$score = config('site.share_sell');
$user = new User();
$user->where(['id'=>$sell_data['share_uid'],'status'=>'normal'])->setInc('score', $score);
$offlineModel = new OffLine();
$offlineModel = new Line();
$offlineModel->create(['uid'=>$sell_data['share_uid'],'s_score'=>$score,'off_uid'=>$this->user_id]);
}
$sell = new \app\admin\model\Sell();
... ...
... ... @@ -8,7 +8,7 @@ use think\Validate;
/**
* 系统消息接口
*/
class Messages extends Api
class Smessages extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
... ... @@ -24,7 +24,7 @@ class Messages extends Api
* @ApiTitle (系统消息列表)
* @ApiSummary (系统消息列表)
* @ApiMethod (GET)
* @ApiRoute (/api/messages/getMessageList)
* @ApiRoute (/api/smessages/getMessageList)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
... ... @@ -32,15 +32,17 @@ class Messages extends Api
"msg": "成功",
"time": "1553777266",
"data":{
"id": 1,
"title": "系统消息",//系统消息标题
"is_read": 0 //系统消息是否已读 0:未读,1:已读
"id": 1,
"title": "您有一个系统消息提示,请及时查看。",//提现系统消息标题
"type": 1,//类型 0:充值,1:提现
"is_read": 0 //系统消息是否已读 0:未读,1:已读
},
{
"id": 5,
"title": "重大好消息1",
"is_read": 0
}
"id": 2,
"title": "您有一个系统消息提示,请及时查看。",//提现系统消息标题
"type": 1,//类型 0:充值,1:提现
"is_read": 0 //系统消息是否已读 0:未读,1:已读
},
})
*/
public function getMessageList(){
... ... @@ -52,12 +54,13 @@ class Messages extends Api
if (!$validate->check(['page'=>$page])) {
$this->error($validate->getError());
}
$withdrawal = config('site.withdrawal');
$data = Db::table('gc_message')
->alias('l')
->join('gc_message m','l.message_id = m.id','LEFT')
->where(['l.user_id'=>$this->user_id])
->alias('m')
->join('gc_account a','m.account_id = a.id','LEFT')
->where(['a.uid'=>$this->user_id,'a.type'=>$withdrawal])
->page($page,$limit)
->field('m.id,m.title,l.is_read')
->field('m.id,m.title,m.type,m.is_read')
->select();
$this->success('成功',$data);
}else{
... ... @@ -69,19 +72,22 @@ class Messages extends Api
* @ApiTitle (系统消息详情)
* @ApiSummary (系统消息详情)
* @ApiMethod (GET)
* @ApiRoute (/api/messages/messageDetail)
* @ApiRoute (/api/smessages/messageDetail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="分页页码")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1553777266",
"data":{
"id": 5,
"title": "重大好消息1",//系统消息标题
"description": "系统消息系统消息详情“,
"createtime": "2019-03-20 16:24:48"
"time": "1554262435",
"data": [
{
"id": 1,
"title": "您有一个系统消息提示,请及时查看。",
"type": 1,//类型 0:充值,1:提现
"money": 0.01,//充值或提现金额
"createtime": "2019-04-03 11:00:29"//时间
}
]
})
*/
public function messageDetail(){
... ... @@ -92,17 +98,18 @@ class Messages extends Api
if (!$validate->check(['id'=>$message_id])) {
$this->error($validate->getError());
}
$data = Db::table('gc_message_log')
->alias('l')
->join('gc_message m','l.message_id = m.id','LEFT')
->where(['l.user_id'=>$this->user_id,'m.id'=>$message_id])
->field('m.id,m.title,m.description,l.createtime')
$withdrawal = config('site.withdrawal');
$data = Db::table('gc_message')
->alias('m')
->join('gc_account a','m.account_id = a.id','LEFT')
->where(['m.id'=>$message_id,'a.uid'=>$this->user_id,'a.type'=>$withdrawal])
->field('m.id,m.title,m.type,a.money,m.createtime')
->select();
foreach($data as &$value){
$value['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
}
Db::table('gc_message_log')
->where(['message_id'=>$message_id,'user_id'=>$this->user_id])
Db::table('gc_message')
->where(['id'=>$message_id])
->update(['is_read'=>$this->read,'readtime'=>time()]);
$this->success('成功',$data);
}else{
... ...
... ... @@ -9,6 +9,8 @@ use think\Db;
use Yansongda\Pay\Pay;
use app\admin\model\Account;
use app\admin\model\User;
use app\admin\model\Message;
use app\admin\model\off\Line;
use think\Log;
use fast\Http;
use think\Validate;
... ... @@ -18,8 +20,8 @@ use Exception;
*/
class Wxpay extends Api
{
protected $noNeedLogin = ['notify','wechatReturn','notifyCharge'];
protected $noNeedRight = ['notify','wechatReturn','notifyCharge'];
protected $noNeedLogin = ['notify','notifyCharge'];
protected $noNeedRight = ['notify','notifyCharge'];
protected $user_id = '';//token存贮user_id
protected $order_status = [];//订单状态
public function _initialize()
... ... @@ -37,6 +39,7 @@ class Wxpay extends Api
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="openid", type="string", required=true, description="小程序openid")
* @ApiParams (name="pay_order_sn", type="string", required=true, description="支付订单号")
* @ApiParams (name="share_uid", type="integer", required=false, description="分享用户id")
* @ApiReturn ({code: 0, msg: "无效的订单", time: "1554176100", data: null})
*/
public function pay(){
... ... @@ -45,7 +48,7 @@ class Wxpay extends Api
$pay = Pay::wechat(Service::getConfig('wechat'));
$openid = $this->request->post('openid');//小程序传递openid
$pay_order_sn = $this->request->post('pay_order_sn');//支付订单号
$share_uid = $this->request->post('share_uid');//分享用户uid
if(empty($openid) && empty($pay_order_sn)){
$this->error('无效的参数');
}
... ... @@ -76,9 +79,12 @@ class Wxpay extends Api
// 'total_fee' => 1,
'total_fee' => floatval($total_price)*100,//单位:分
'openid' => $openid,
'notify_url' => url('api/Wxpay/notify','','',true),
'return_url' => url('api/Wxpay/wechatReturn','','',true),
];
if(!empty($share_uid)){
$order['notify_url'] = url('api/Wxpay/notify/share_uid/'.$share_uid,'','',true);
}else{
$order['notify_url'] = url('api/Wxpay/notify','','',true);
}
//跳转或输出
$this->success('成功',$pay->miniapp($order));
... ... @@ -125,36 +131,35 @@ class Wxpay extends Api
}
/**
* 支付成功回调
* 微信异步通知
*/
public function notify(){
$pay = Service::checkNotify('wechat');
if (!$pay) {
$this->error('签名错误');
}
//你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
$data = $pay->verify();
if($data['return_code'] == 'SUCCESS' && $data['result_code'] == 'SUCCESS') {
$porderModel = new Porder();
$porderModel->where(['pay_order_sn'=>$data['out_trade_no']])->update(['status'=>$this->order_status[1]]);
//下面这句必须要执行,且在此之前不能有任何输出
$this->success('成功',$pay->success());
}
$this->success();
}
$pay = Pay::wechat(Service::getConfig('wechat'));
$share_uid = $this->request->param('share_uid');
try {
$data = $pay->verify();
if($data['result_code'] == 'SUCCESS' && $data['return_code'] == 'SUCCESS'){
$porderModel = new Porder();
$porderModel->where(['pay_order_sn'=>$data['out_trade_no']])->update(['status'=>$this->order_status[1]]);
/**
* 微信异步通知
*/
public function wechatReturn(){
$pay = Service::checkReturn('wechat');
if (!$pay) {
$this->error('签名错误');
//如果携带分享uid,则按照积分增加
if(!empty($share_uid)){
$score = config('site.share_purchase');
//给分享用户增加积分
$user = new User();
$user->where(['id'=>$share_uid,'status'=>'normal'])->setInc('score', $score);
//成为分享用户的下线
$offlineModel = new Line();
$offlineModel->create(['uid'=>$share_uid,'s_score'=>$score,'off_uid'=>$this->user_id]);
}
}
} catch (Exception $e) {
echo "验签失败";
return;
}
//你可以在这里定义你的提示信息,但切记不可在此编写逻辑
$this->success("恭喜你!支付成功!");
return;
return $pay->success()->send();
}
/**
* @ApiTitle (充值)
* @ApiSummary (充值)
... ... @@ -188,7 +193,6 @@ class Wxpay extends Api
'total_fee' => floatval($amount)*100,//单位:分
'openid' => $openid,
'notify_url' => url('api/Wxpay/notifyCharge','','',true),
'return_url' => url('api/Wxpay/wechatReturn','','',true),
];
//跳转或输出
$this->success('成功',$pay->miniapp($order));
... ... @@ -198,25 +202,35 @@ class Wxpay extends Api
}
/**
* 充值成功回调
* 微信异步通知
*/
public function notifyCharge(){
$pay = Service::checkNotify('wechat');
if (!$pay) {
$this->error('签名错误');
}
//你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
$data = $pay->verify();
if($data['return_code'] == 'SUCCESS' && $data['result_code'] == 'SUCCESS') {
$userModel = new User();
$user = $userModel->where(['openid'=>$data['openid']])->find();
$accountModel = new Account();
$money = $data['total_fee']/100;
$accountModel::create(['uid'=>$user['id'],'type'=>config('site.pay_charge'),'money'=>$money]);
//下面这句必须要执行,且在此之前不能有任何输出
$this->success('成功',$pay->success());
$pay = Pay::wechat(Service::getConfig('wechat'));
try {
$data = $pay->verify();
//你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
if($data['result_code'] == 'SUCCESS' && $data['return_code'] == 'SUCCESS'){
$money = $data['total_fee'] / 100;
$userModel = new User();
$user = $userModel->where(['openid' => $data['openid']])->find();
//给用户增加充值金额
$userModel->where(['openid' => $data['openid']])->setInc('money',$money);
//充值记录
$accountModel = new Account();
$account = $accountModel::create(['uid' => $user['id'], 'money' => $money]);
//系统充值消息
$messageModel = new Message();
$messageModel::create(['account_id' => $account->id, 'title' => config('site.message')]);
Log::info('执行一次');
}
} catch (Exception $e) {
echo "验签失败";
return;
}
$this->success();
//下面这句必须要执行,且在此之前不能有任何输出
return $pay->success()->send();
}
}
... ...
... ... @@ -54,7 +54,9 @@ return array (
//消息已读
'is_read' => 1,
//充值
'pay_charge' => 1,
'pay_charge' => 0,
//提现
'withdrawal' => 1,
//系统消息提示
'message'=>'您有一个系统消息提示,请及时查看。',
//设置积分规则(分享购买,分享卖废品)
... ... @@ -280,4 +282,16 @@ return array (
'o_id.number' => '订单id必须是数字',
]
],
'bank' => [
'rule' => [
'bank_num' => ['require','regex'=>'/^(\d{16}|\d{19})$/'],
'open_bank' => 'require|max:10',
],
'msg' => [
'bank_num.require' => '银行卡号不能为空',
'bank_num' => '银行卡号格式不正确',
'open_bank.require' => '开户行不能为空',
'open_bank' => '开户行最多不超过10个字符',
]
],
);
\ No newline at end of file
... ...