You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
9.8 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
use Common\Api\GameApi;
use Callback\Controller\BaseController;
/**
* 后台首页控制器
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
*/
class RepairController extends ThinkController {
public function repairEdit($orderNo=null,$is_uc=0){
$param['out_trade_no'] = $orderNo;
$game = new GameApi();
if($is_uc){
$result=$game->game_pay_notify($param,1,1);
}else{
$result=$game->game_pay_notify($param,1);
}
$spend = M('Spend',"tab_");
if($result == "success"){
$auth = session('user_auth');
// 补单记录
M('repair_pay', 'tab_')->add([
'admin_id' => $auth['uid'],
'admin_name' => $auth['username'],
'pay_order_number' => $orderNo,
'ip' => get_client_ip(),
'tab' => 'spend',
'create_time' => time(),
'type' => 1 // 补单
]);
$sp = $spend->where([
'pay_order_number' => $orderNo
])->find();
$rr = $spend->where(array('pay_order_number'=>$orderNo))->save(array('pay_game_status'=>1));
if ($sp['extend']) {
$spend->where([
'extend' => $sp['extend'],
'pay_status' => 1,
'user_id' => $sp['user_id']
])->save(array('pay_game_status' => 1));
}
//操作日志
addOperationLog(array(
"op_type"=>1,
"key"=> $orderNo,
"url"=>U("Spend/lists",array("pay_order_number"=>$orderNo))
));
$this->ajaxReturn(array('status'=>1,'msg'=>'补单成功'));
}else{
$this->ajaxReturn(array('status'=>0,'msg'=>'补单失败'));
}
}
/**
*编辑绑币补单
*/
public function repairBindEdit($orderNo=null){
$bindspend = M('BindSpend',"tab_");
$param['out_trade_no'] = $orderNo;
$param['distinction'] = 'bind';
$game = new GameApi();
$result=$game->game_pay_notify($param,2);
if($result == "success"){
$rr = $bindspend->where(array('pay_order_number'=>$orderNo))->save(array('pay_game_status'=>1));
$this->ajaxReturn(array('status'=>1,'msg'=>'补单成功'));
}else{
$this->ajaxReturn(array('status'=>0,'msg'=>'补单失败'));
}
}
/**
* 退款接口
* @param null $orderNo
*/
public function Refund($orderNo=null){
$map['pay_order_number'] = $orderNo;
$order=sp_random_string(4);
$res=D('Spend')->Refund($map,$order,md5("mcaseqwezdsi".$order));
if(get_spend_pay_way($orderNo)==1){
if($res=="10000")$this->ajaxReturn(['status'=>1,'msg'=>'退款成功']);
if(res&&strlen($res)>50){
$this->ajaxReturn(['status'=>1,'msg'=>$res]);
}else{
$this->ajaxReturn(['status'=>1,'msg'=>'错误']);
}
}elseif(get_spend_pay_way($orderNo)==3){
if($res==1){
$this->ajaxReturn(['status'=>1,'msg'=>'退款申请成功']);
}else{
$this->ajaxReturn(['status'=>0,'msg'=>$res]);
}
}elseif(get_spend_pay_way($orderNo)==4){
if($res==0){
$this->ajaxReturn(['status'=>1,'msg'=>'退款申请成功']);
}else{
$this->ajaxReturn(['status'=>0,'msg'=>$res]);
}
}elseif(get_spend_pay_way($orderNo)==0){
$this->ajaxReturn(['status'=>1,'msg'=>'退款成功']);
}
}
/**
* 退款查询借口
* @param [type] $orderNo [订单号]
* @param integer $type [1 威富通 2官方]
* @return [type] [description]
*/
public function find_refund($orderNo=null,$type=1){
if($type==1){
$spen=D('Spend')->swiftpass_refund($orderNo);
}else{
$spen=D('Spend')->weixin_refundquery($orderNo);
}
$res=json_decode($spen,true);
if($res['status']==1){
$this->ajaxReturn(['status'=>1,'msg'=>'退款成功']);
}else{
$this->ajaxReturn(['status'=>1,'msg'=>$res['msg']]);
}
}
/**
* 游戏充值补单
*/
public function noticePayed($orderNo, $second, $type) {
$auth = session('user_auth');
if (IS_AJAX) {
if ($type != 'spend' && $type != 'deposit') {
$this->ajaxReturn(['status'=>0,'msg'=>'参数有误']);
}
$tab = $type;
if (!$orderNo || !$second) {
$this->ajaxReturn(['status'=>0,'msg'=>'参数不足']);
}
$r = D('Member')->check_sc_pwd($second);
if (!$r) {
$this->ajaxReturn(['status'=>0,'msg'=>'二级密码错误']);
}
M($tab, 'tab_')->startTrans();
$order = M($tab, 'tab_')->where(['pay_order_number' => $orderNo])->find();
if ($order['pay_status'] == 1) {
M($tab, 'tab_')->rollback();
$this->ajaxReturn(['status'=>0,'msg'=>'支付成功,无需补单']);
}
$r = M($tab, 'tab_')->where([
'pay_order_number' => $orderNo,
'pay_status' => 0
])->save([
'pay_status' => 1,
'payed_time' => time()
]);
if ($r) {
$cpFlag = 0; // 0 通知cp失败 1 成功
// 通知cp
if ($tab == 'spend') {
$param['out_trade_no'] = $orderNo;
$game = new GameApi();
$result=$game->game_pay_notify($param,1);
$spend = M($tab, "tab_");
if($result == "success"){
$rr = $spend->where(array('pay_order_number'=>$orderNo))->save(array('pay_game_status'=>1));
PromoteStatistics($orderNo);
if ($rr !== false) {
$cpFlag = 1;
M($tab, 'tab_')->commit();
} else {
M($tab, 'tab_')->rollback();
$this->ajaxReturn(array('status'=>1,'msg'=>'补单失败.'));
}
}else{
PromoteStatistics($orderNo);
M($tab, 'tab_')->commit();
}
} else { // deposit
$user = M("user","tab_");
$r = $user->where("id=".$order['user_id'])->setInc("balance", $order['pay_amount']);
if ($r === false) {
M($tab, 'tab_')->rollback();
$this->ajaxReturn(array('status'=>1,'msg'=>'数据有误.'));
}
$r = $user->where("id=".$order['user_id'])->setInc("cumulative", $order['pay_amount']);
if ($r === false) {
M($tab, 'tab_')->rollback();
$this->ajaxReturn(array('status'=>1,'msg'=>'数据有误..'));
}
M('spend', 'tab_')->commit();
}
// 通知到账记录
M('repair_pay', 'tab_')->add([
'admin_id' => $auth['uid'],
'admin_name' => $auth['username'],
'pay_order_number' => $orderNo,
'ip' => get_client_ip(),
'tab' => $tab,
'create_time' => time(),
'type' => 0
]);
if ($tab == 'spend' && $cpFlag === 1) {
// 补单记录
M('repair_pay', 'tab_')->add([
'admin_id' => $auth['uid'],
'admin_name' => $auth['username'],
'pay_order_number' => $orderNo,
'ip' => get_client_ip(),
'tab' => $tab,
'create_time' => time(),
'type' => 1
]);
}
// todo: 分红 上级奖励等
if ($tab == 'spend' && $cpFlag == 0) {
$this->ajaxReturn(['status'=>0,'msg'=>'充值补单成功通知CP失败']);
}
//操作日志
$optionarr = array(
"op_type"=>1,
"key"=> $orderNo
);
$pay_where = substr($orderNo, 0, 2);
if($pay_where == 'SP'){
//游戏充值通知到账
$optionarr['menu'] = "充值-游戏订单-游戏充值-通知到账";
$optionarr['url'] = U("Spend/lists",array("pay_order_number"=>$orderNo));
}elseif($pay_where == 'PF'){
//平台币充值通知到账
$optionarr['menu'] = "充值-平台币订单-平台币充值-通知到账";
$optionarr['url'] = U("Deposit/lists",array("pay_order_number"=>$orderNo));
}
addOperationLog($optionarr);
$this->ajaxReturn(['status'=>1,'msg'=>'充值补单成功!']);
} else {
M('spend', 'tab_')->rollback();
$this->ajaxReturn(['status'=>0,'msg'=>'补单失败,请重试']);
}
}
}
/**
* 平台币充值补单
*/
public function platform($orderNo) {
if (IS_AJAX) {
$payOrderNumber = I('request.pay_order_number');
}
}
}