101 lines
3.7 KiB
PHP
101 lines
3.7 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\openapi\controller;
|
||
|
||
use app\common\model\MemberInfo;
|
||
use app\common\model\VipOrder;
|
||
use app\common\service\Account as AccountService;
|
||
use app\common\service\Wechat as WechatService;
|
||
use cjango\Wechat;
|
||
|
||
class Pay
|
||
{
|
||
|
||
public function vip()
|
||
{
|
||
WechatService::instance();
|
||
$res = Wechat\Pay::parsePayRequest();
|
||
if ($res) {
|
||
$order = VipOrder::where('orderid', $res['out_trade_no'])->find();
|
||
if ($order->status != 0) {
|
||
Wechat\Pay::returnNotify();
|
||
return;
|
||
}
|
||
$order->save(['status' => 20, 'model' => 'weixin']);
|
||
$MemberInfo = MemberInfo::get($order->uid);
|
||
if ($MemberInfo->is_vip == 1) {
|
||
if ($MemberInfo->vip_end_time > time()) {
|
||
$time = strtotime("+1 year", $MemberInfo->vip_end_time);
|
||
} else {
|
||
$time = strtotime("+1 year");
|
||
}
|
||
} else {
|
||
$time = strtotime("+1 year");
|
||
}
|
||
|
||
//赠送一年代理商
|
||
if ($MemberInfo->is_agent == 1) {
|
||
if ($MemberInfo->agent_end_time > time()) {
|
||
$agenttime = strtotime("+1 year", $MemberInfo->agent_end_time);
|
||
} else {
|
||
$agenttime = strtotime("+1 year");
|
||
}
|
||
} else {
|
||
$agenttime = strtotime("+1 year");
|
||
}
|
||
|
||
MemberInfo::update(['is_vip' => 1, 'is_fee' => 1, 'vip_time' => $time, 'is_agent' => 1, 'agent_time' => $agenttime], ['uid' => $order->uid]);
|
||
AccountService::commission($order->orderid);
|
||
Wechat\Pay::returnNotify();
|
||
} else {
|
||
Wechat\Pay::returnNotify('处理失败');
|
||
}
|
||
}
|
||
|
||
public function agent()
|
||
{
|
||
WechatService::instance();
|
||
$res = Wechat\Pay::parsePayRequest();
|
||
if ($res) {
|
||
$order = VipOrder::where('orderid', $res['out_trade_no'])->find();
|
||
if ($order->status != 0) {
|
||
Wechat\Pay::returnNotify();
|
||
return;
|
||
}
|
||
|
||
$order->save(['status' => 20, 'model' => 'weixin']);
|
||
$MemberInfo = MemberInfo::get($order->uid);
|
||
if ($MemberInfo->is_agent == 1) {
|
||
if ($MemberInfo->agent_end_time > time()) {
|
||
$agenttime = strtotime("+1 year", $MemberInfo->agent_end_time);
|
||
} else {
|
||
$agenttime = strtotime("+1 year");
|
||
}
|
||
} else {
|
||
$agenttime = strtotime("+1 year");
|
||
}
|
||
//赠送一年推广先锋
|
||
if ($MemberInfo->is_vip == 1) {
|
||
if ($MemberInfo->vip_end_time > time()) {
|
||
$time = strtotime("+1 year", $MemberInfo->vip_end_time);
|
||
} else {
|
||
$time = strtotime("+1 year");
|
||
}
|
||
} else {
|
||
$time = strtotime("+1 year");
|
||
}
|
||
MemberInfo::update(['is_agent' => 1, 'agent_time' => $agenttime, 'is_vip' => 1, 'is_fee' => 1, 'vip_time' => $time], ['uid' => $order->uid]);
|
||
AccountService::commission($order->orderid);
|
||
Wechat\Pay::returnNotify();
|
||
} else {
|
||
Wechat\Pay::returnNotify('处理失败');
|
||
}
|
||
}
|
||
}
|