作者 Cool
1 个管道 的构建 通过 耗费 0 秒

Merge branch 'master' of http://114.215.101.231:8099/guosheng/community into liuzhen

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/7/10
* Time: 17:32
*/
namespace app\api\controller;
use app\common\controller\Api;
use think\Cache;
use think\Db;
use think\Validate;
use app\api\model\HouseAdmin as HouseAdminModel;
/**
* 社区管理员
*/
class HouseAdmin extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (社区管理员-首页)
* @ApiSummary (社区管理员-首页)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"is_binding"://是否绑定1已绑定2未绑定
"house"://社区信息
"house_board"://最新公告信息
}
})
*/
public function index()
{
$info = HouseAdminModel::get(['user_id'=>$this->auth->id]);
$this->success('success',$info);
}
}
\ No newline at end of file
... ...
... ... @@ -666,7 +666,7 @@ class HouseBoard extends Api
'payment' => [
'merchant_id' => $config['MCHIDGZH'],
'key' => $config['APIKEYGZH'],
'notify_url' => \think\Request::instance()->domain().'/index/ajax/callback_for_wxgzh',
'notify_url' => \think\Request::instance()->domain().'/index/notify/notifyHouseJoin',
],
];
... ...
... ... @@ -87,34 +87,35 @@ class User extends Api
* @ApiRoute (/api/user/index)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1598667600",
"data": {
"id": 2, //用户ID
"username": "何先生", //用户名
"nickname": "何先生", //昵称
"avatar": "http://cloud.caiyunpan.brotop.cn/assets/img/avatar.png", //头像
"money": "0.00", //余额
"id_num": "100001", //ID
"url": "/u/2",
"house": { //小区信息
"id": 17, //小区ID
"name": "碧海花园小区" //小区名称
},
"today_money": 10, //今日收益
"total_money": 10, //总收益
"message_num": 0 //未读消息数量
}
})
"code": 1,
"msg": "成功",
"time": "1598667600",
"data": {
"id": 2, //用户ID
"username": "何先生", //用户名
"nickname": "何先生", //昵称
"avatar": "http://cloud.caiyunpan.brotop.cn/assets/img/avatar.png", //头像
"money": "0.00", //余额
"id_num": "100001", //ID
"identity": 0, //身份0普通用户1主管理员2子管理员3商家
"url": "/u/2",
"house": { //小区信息
"id": 17, //小区ID
"name": "碧海花园小区" //小区名称
},
"today_money": 10, //今日收益
"total_money": 10, //总收益
"message_num": 0 //未读消息数量
}
})
*/
public function index()
{
$user = $this->auth->getUser();
$house = \app\api\model\House::get($user['house_id']);
$data = [
// 当前小区信息
'house' => \app\api\model\House::get($user['house_id'])
->visible(['id','name'])->toArray(),
'house' => !empty($house) ? $house->visible(['id','name'])->toArray() : [],
// 今日收益
'today_money' => UserMoneyLog::where('user_id',$this->auth->id)
->where('money','>',0)
... ... @@ -135,7 +136,8 @@ class User extends Api
'nickname',
'avatar',
'id_num',
'money'
'money',
'identity'
])->toArray();
$this->success('成功', array_merge($user,$data));
}
... ...
<?php
namespace app\api\model;
class HouseAdmin extends Base
{
}
\ No newline at end of file
... ...
<?php
namespace app\index\controller;
use addons\wechat\library\Config as ConfigService;
use app\common\controller\Frontend;
use EasyWeChat\Foundation\Application as WXPAY_APP;
use think\Db;
/**
* 支付回调
* @internal
*/
class Notify extends Frontend
{
protected $noNeedLogin = ['notify'];
protected $noNeedRight = ['*'];
protected $layout = '';
public function _initialize()
{
parent::_initialize();
}
/**
* 社区活动报名支付回调
*/
public function notifyHouseJoin(){
$app = new WXPAY_APP(ConfigService::load());
$response = $app->payment->handleNotify(function($notify, $successful){
/*这里是支付回调逻辑处理,一下是DEMO*/
// 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
$out_trade_no=$notify->out_trade_no;
$info = Db::name('house_join')->where(['order_no'=>$out_trade_no])->find();
if (!$info) { // 如果订单不存在
return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
}
// 检查订单是否已经更新过支付状态
if ($info['transaction_id']) { // 假设订单字段“支付时间”不为空代表已经支付
return true; // 已经支付成功了就不再更新了
}
// 用户是否支付成功
if ($successful) {
Db::startTrans();
// 回填微信的订单号
$update['transaction_id'] = $notify->transaction_id;
$update['pay_status'] = '1'; //付款成功
$update['pay_time'] = time();
$update['join_status'] = '1'; //报名成功
//更新状态: 已购买
$res_order = Db::name('house_join')->where(['id' => $info['id']])->update($update);
if(!$res_order) {
Db::rollback();
return false; // 返回处理完成
}
Db::commit();
}
return true; // 返回处理完成
});
$response->send();
}
}
... ...