init: 从宝塔同步到 Gitea
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller;
|
||||
|
||||
use pay\Ybf;
|
||||
use think\Cache;
|
||||
use \think\Controller;
|
||||
use think\Db;
|
||||
use think\Request;
|
||||
|
||||
class Crypto Extends Controller{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* YBF支付回调
|
||||
*/
|
||||
public function callback_ybf()
|
||||
{
|
||||
$json = file_get_contents("php://input");
|
||||
$data = json_decode($json,true);
|
||||
|
||||
// 记录日志
|
||||
$logId = $this->addLog('YBF',$json);
|
||||
|
||||
$ybf = new Ybf();
|
||||
$res = $ybf->callback($data,$logId);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* YBF反查开放接口
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function query_order_ybf()
|
||||
{
|
||||
$json = file_get_contents("php://input");
|
||||
addLogToFile('反查报文:'.$json,'ybf_fc','ybf');
|
||||
parse_str($json,$data);
|
||||
// $data = Request::instance()->request();
|
||||
|
||||
$ybf = new Ybf();
|
||||
$res = $ybf->withdraw_query($data);
|
||||
|
||||
$res = json_encode($res,JSON_UNESCAPED_UNICODE);
|
||||
addLogToFile('反查报文返回信息:'.$res,'ybf_fc','ybf');
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值回调
|
||||
*/
|
||||
public function callback()
|
||||
{
|
||||
$json = file_get_contents("php://input");
|
||||
// $json = '{"key":"transaction","merch":{"tid":1002,"user_id":1001,"type":100,"address":"TMp3mUPf4U5zsnmVSSWTHc4YQSBjxFQqbC","update_time":1681266378741,"create_time":1673600766135,"status":200},"sign":"267e31e41087f80e441bd9759fbd62fd179633b9","timestamp":1681267421305,"transaction":{"tid":1001,"type":200,"txid":"07756fb10fe41d5c342c3f79396471ce3d0d93deae2081cfe8b6e7f730492563","from_addr":"TDunwvXBwazrLdV9jPD7uy4Bq3z8Eyb4UE","to_addr":"TJtfqKmvxZTPcrQNMEoP3sPxUwbtUN8MVA","asset":"TRX","amount":"1000000","fee_energy_usage":"0","fee_energy_trx":"0","fee_net_usage":"0","fee_net_trx":"0.1","fee_used":"0.1","fee_asset":"TRX","notified":1,"update_time":1681267421298,"create_time":1681267421298,"status":200}}';
|
||||
$data = json_decode($json,true);
|
||||
|
||||
if(!empty($data)){
|
||||
$type = $data['key'];
|
||||
$uniqueNo = "";
|
||||
|
||||
// 记录日志
|
||||
$logId = $this->addLog($type,$json);
|
||||
|
||||
// 校验签名
|
||||
$verify = $this->verifySign($data);
|
||||
if($verify){
|
||||
switch ($type){
|
||||
// 充值上分
|
||||
case "transaction":
|
||||
$uniqueNo = $data['transaction']['txid'];
|
||||
$res = $this->transaction($data);
|
||||
break;
|
||||
|
||||
// 提现转账
|
||||
case "processor":
|
||||
$uniqueNo = $data['processor']['uuid'];
|
||||
$res = $this->processor($data);
|
||||
break;
|
||||
|
||||
default:
|
||||
$res = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// 更新唯一识别值
|
||||
if($uniqueNo) $this->setUniqueNo($logId,$uniqueNo);
|
||||
//if($res) return "success";
|
||||
if($res) return json_encode(['code' => 0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理交易回调
|
||||
* @param $data
|
||||
*/
|
||||
private function transaction($data)
|
||||
{
|
||||
$data = $data['transaction'];
|
||||
|
||||
// 校验状态
|
||||
$status = $data['status'];
|
||||
if($status != 200){
|
||||
return false;
|
||||
}
|
||||
|
||||
$toAddr = $data['to_addr'];
|
||||
$fromAddr = $data['from_addr'];
|
||||
$amount = $data['amount'];
|
||||
$txid = $data['txid'];
|
||||
$userId = Db::name('user_wallet')->where('address',$toAddr)->value('user_id');
|
||||
if($userId){
|
||||
Db::startTrans();
|
||||
$user = Db::name('user')->where('id',$userId)->lock(true)->find();
|
||||
$recharge = Db::name('user_recharge')->where('out_trade_no',$txid)->find();
|
||||
if($recharge){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 计算兑换比率
|
||||
$system = Db::name('system')->find();
|
||||
$rechargeMoney = empty($system['recharge_money']) ? 100 : $system['recharge_money'];
|
||||
$money = $amount*($rechargeMoney/100);
|
||||
|
||||
// 上分
|
||||
$userMoney = $user['money'];
|
||||
$moneyAfter = $user['money'] + $money;
|
||||
|
||||
// 上分
|
||||
$res = Db::name('user')->where('id',$userId)->update([
|
||||
'money' => $moneyAfter,
|
||||
'last_recharge' => $money,
|
||||
'last_recharge_time' => time(),
|
||||
]);
|
||||
if(!$res) return;
|
||||
|
||||
// 充值记录
|
||||
$res = Db::name('user_recharge')->insert([
|
||||
'out_trade_no' => $txid,
|
||||
'user_id' => $userId,
|
||||
'amount' => $amount,
|
||||
'money' => $money,
|
||||
'old_money' => $userMoney,
|
||||
'new_money' => $moneyAfter,
|
||||
'from_addr' => $fromAddr,
|
||||
'to_addr' => $toAddr,
|
||||
'pay_channel' => 'USDT',
|
||||
'status' => 'SUCCESS',
|
||||
'create_time' => time(),
|
||||
'pay_time' => time(),
|
||||
]);
|
||||
if(!$res) return;
|
||||
|
||||
Db::commit();
|
||||
|
||||
return json_encode(['code' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理提现回调
|
||||
* @param $data
|
||||
*/
|
||||
private function processor($data)
|
||||
{
|
||||
$data = $data['processor'];
|
||||
|
||||
// 校验状态
|
||||
$status = $data['status'];
|
||||
if($status !== 200){
|
||||
return false;
|
||||
}
|
||||
$code = $data['result']['transfer']['code'];
|
||||
if($code !== 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$uuid = $data['uuid'];
|
||||
$fromAddr = $data['from_addr'];
|
||||
$toAddr = $data['to_addr'];
|
||||
$amount = $data['amount'];
|
||||
$asset = $data['asset'];
|
||||
$withdraw = Db::name('user_withdraw')->where('order_no',$uuid)->where('status','AGREE')->find();
|
||||
if($withdraw){
|
||||
Db::startTrans();
|
||||
if($withdraw['from_address'] != $fromAddr) return false;
|
||||
if($withdraw['to_address'] != $toAddr) return false;
|
||||
if($withdraw['amount'] != $amount) return false;
|
||||
if($withdraw['type'] != $asset) return false;
|
||||
|
||||
// 更改状态
|
||||
$res = Db::name('user_withdraw')->where('id',$withdraw['id'])->update([
|
||||
'status' => 'SUCCESS',
|
||||
'update_time' => time(),
|
||||
]);
|
||||
if(!$res) return;
|
||||
|
||||
Db::commit();
|
||||
|
||||
return json_encode(['code' => 0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验签名
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
private function verifySign($data)
|
||||
{
|
||||
$payChannelConfig = Db::name('pay_channel')->where('key','USDT')->value('value');
|
||||
$config = json_decode($payChannelConfig,true);
|
||||
|
||||
$key = urlencode($data['key']);
|
||||
$timestamp = urlencode($data['timestamp']);
|
||||
$signData = "key={$key}";
|
||||
$signData .= "&merch_addr={$config['merch_addr']}";
|
||||
$signData .= "&merch_type={$config['merch_type']}";
|
||||
$signData .= "×tamp={$timestamp}";
|
||||
$signData .= "&access_token={$config['access_token']}";
|
||||
$sign = sha1($signData);
|
||||
return $sign == $data['sign'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录日志
|
||||
* @param $type
|
||||
* @param $json
|
||||
* @return mixed
|
||||
*/
|
||||
private function addLog($type,$json)
|
||||
{
|
||||
$id = Db::name('pay_callback_log')->insertGetId([
|
||||
'pay_channel' => $type,
|
||||
'type' => $type,
|
||||
'json' => $json,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新唯一识别值
|
||||
* @param $id
|
||||
* @param $uniqueNo
|
||||
* @return mixed
|
||||
*/
|
||||
private function setUniqueNo($id,$uniqueNo)
|
||||
{
|
||||
$res = Db::name('pay_callback_log')->where('id',$id)->update([
|
||||
'unique_no' => $uniqueNo,
|
||||
]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller;
|
||||
use \think\Controller;
|
||||
|
||||
class Error Extends Controller{
|
||||
public function index(){
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller;
|
||||
use \think\Controller;
|
||||
use \think\Session;
|
||||
use \think\Request;
|
||||
use \think\Db;
|
||||
use think\Lang;
|
||||
|
||||
class Index Extends Controller{
|
||||
public function index(){
|
||||
// 获取语言包
|
||||
$lang = Lang::get();
|
||||
$lang = json_encode($lang);
|
||||
// 渲染参数和模板
|
||||
$this->assign('lang',$lang);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,910 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller;
|
||||
|
||||
use think\Cache;
|
||||
use \think\Controller;
|
||||
use \think\Request;
|
||||
use \think\Db;
|
||||
use \think\Lang;
|
||||
use \think\Session;
|
||||
use \think\Log;
|
||||
use \think\Config;
|
||||
use Waybill\WaybillDice;
|
||||
use Waybill\WaybillRoulette;
|
||||
use Waybill\WaybillToning;
|
||||
|
||||
class Managerapi extends Controller{
|
||||
//登录
|
||||
public function login(){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
if(Request::instance()->isPost()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
if($json_arr){
|
||||
$username = trim($json_arr['username']);
|
||||
$password = trim($json_arr['password']);
|
||||
if(empty($username) || empty($password)){
|
||||
return json(['Success' => 0, 'Msg' => '请填写账号密码']);
|
||||
}
|
||||
$find = Db::name('manager')->where(array('username' => $username, 'status' => 1))->find();
|
||||
if($find){
|
||||
if(think_ucenter_md5($password, UC_AUTH_KEY) === $find['password'] && $find['password']){
|
||||
$user_log = array();
|
||||
$user_log['user_id'] = $find['id'];
|
||||
$user_log['username'] = $find['username'];
|
||||
$user_log['nickname'] = $find['nickname'];
|
||||
$user_log['ip'] = getIP();
|
||||
$user_log['client'] = 'PC或H5';
|
||||
$user_log['create_time'] = time();
|
||||
$user_log['remark'] = '登录';
|
||||
Db::name('manager_log')->insert($user_log);
|
||||
$online_token = $this->create_online_token($find);
|
||||
$find['online_token'] = $online_token;
|
||||
$find['login_token'] = $online_token;
|
||||
$update = array();
|
||||
$update['login_token'] = $online_token;
|
||||
$update['last_login_time'] = time();
|
||||
$update['last_login_ip'] = getIP();
|
||||
$api_token = create_api_token($find['username'],$find['nickname']);
|
||||
$update['api_token'] = $api_token;
|
||||
Db::name('manager')->where(array('id' => $find['id']))->limit(1)->update($update);
|
||||
$find['api_token'] = $api_token;
|
||||
//存入session
|
||||
Db::name('manager_session')->where(array('last_time' => array('<', time() - Config::get('session_life_time'))))->delete();
|
||||
$DBSession = Db::name('manager_session')->where(array('session_id' => $api_token))->find();
|
||||
if($DBSession){
|
||||
Db::name('manager_session')->where(array('session_id' => $api_token))->update(array('last_time' => time(), 'user_id' => $find['id']));
|
||||
}else{
|
||||
Db::name('manager_session')->where(array('user_id' => $find['id']))->delete();
|
||||
Db::name('manager_session')->insert(array('session_id' =>$api_token, 'last_time' => time(), 'user_id' => $find['id']));
|
||||
}
|
||||
unset($find['password']);
|
||||
unset($find['encrypt']);
|
||||
|
||||
$data = encrypt_data($find);
|
||||
return json(['Success' => 1, 'Msg' => '登录成功', 'Data' => $data]);
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '账号或者密码错误']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '账号或者密码错误']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '登录出错']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '登录出错']);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_user_info(){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
if(Request::instance()->isPost()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
if($json_arr){
|
||||
$api_token = trim($json_arr['api_token']);
|
||||
$user_id = Db::name('manager_session')->where(array('session_id' =>$api_token))->value('user_id');
|
||||
$find = Db::name('manager')->where(array('id' => $user_id,'status' => 1))->find();
|
||||
if($find){
|
||||
$online_token = $this->create_online_token($find);
|
||||
$find['online_token'] = $online_token;
|
||||
$find['login_token'] = $online_token;
|
||||
$find['api_token'] = $api_token;
|
||||
|
||||
unset($find['password']);
|
||||
unset($find['encrypt']);
|
||||
$data = encrypt_data($find);
|
||||
return json(['Success' => 1, 'Msg' => '操作成功', 'Data' => $data]);
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '暂无数据']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '操作错误']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '操作错误']);
|
||||
}
|
||||
}
|
||||
//修改密码
|
||||
public function update_password(){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
if(Request::instance()->isPost()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
if($json_arr){
|
||||
$user_id = intval($json_arr['user_id']);
|
||||
$password_now = trim($json_arr['password_now']);
|
||||
$password_new = trim($json_arr['password_new']);
|
||||
$password_reply = trim($json_arr['password_reply']);
|
||||
$api_token = trim($json_arr['api_token']);
|
||||
if($user_id > 0){
|
||||
$find = Db::name('manager')->where(array('id' => $user_id))->find();
|
||||
if($find && $find['api_token'] == $api_token){
|
||||
if(empty($password_now) || empty($password_new) || empty($password_reply) || strlen($password_new) < 6){
|
||||
return json(['Success' => 0, 'Msg' => '请填写当前密码以及新密码,新密码不能小于6个字符']);
|
||||
}
|
||||
if($password_new != $password_reply){
|
||||
return json(['Success' => 0, 'Msg' => '两次密码不一致']);
|
||||
}
|
||||
if(think_ucenter_md5($password_now, UC_AUTH_KEY) == $find['password'] && $find['password']){
|
||||
$newPass = think_ucenter_md5($password_new, UC_AUTH_KEY);
|
||||
$res = Db::name('manager')->where(array('id' => $user_id))->limit(1)->update(array('password' => $newPass));
|
||||
if($res){
|
||||
return json(['Success' => 1, 'Msg' => '修改密码成功']);
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '修改密码失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '旧密码输入错误']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '修改密码失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '修改密码失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '修改密码失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '修改密码失败']);
|
||||
}
|
||||
}
|
||||
//获取玩家列表
|
||||
public function get_player_list(){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
if(Request::instance()->isPost()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
if($json_arr){
|
||||
$user_id = intval($json_arr['user_id']);
|
||||
$api_token = trim($json_arr['api_token']);
|
||||
$page = intval($json_arr['page']);
|
||||
$find = Db::name('manager')->where(array('id' => $user_id,'status' => 1))->find();
|
||||
$tableInfo = Db::name('table')->field(['id,table_name'])->select();
|
||||
$tableInfo = array_column($tableInfo,'table_name','id');
|
||||
if($find && $find['api_token'] == $api_token && $page > 0){
|
||||
$page_list = 15;
|
||||
if($page > 1){
|
||||
$limie_start = ($page - 1) * $page_list;
|
||||
}else{
|
||||
$limie_start = 0;
|
||||
}
|
||||
$where = [];
|
||||
$where['manager_id'] = $find['id'];
|
||||
$where['is_delete'] = 0;
|
||||
$where['status'] = 1;
|
||||
$where['agent'] = 0;
|
||||
$where['bet_type'] = 2;
|
||||
$findPlayer = Db::name('user')->where($where)->order('last_login_time DESC')->limit($limie_start,$page_list)->select();
|
||||
$player_num = Db::name('user')->where($where)->count();
|
||||
$page_num = ceil($player_num/$page_list);
|
||||
|
||||
$playerData = [];
|
||||
foreach ($findPlayer as $val){
|
||||
$data = [];
|
||||
$data['id'] = $val['id'];
|
||||
$data['username'] = $val['username'];
|
||||
$data['nickname'] = $val['nickname'];
|
||||
$data['last_login_time'] = $val['last_login_time'] ? date('Y-m-d H:i:s',$val['last_login_time']) : '-';
|
||||
$data['is_online'] = 0;
|
||||
$data['server_status'] = 0;
|
||||
$data['table_id'] = 0;
|
||||
$data['table_name'] = '';
|
||||
$data['bet_amount'] = 0;
|
||||
if($val['api_token']){
|
||||
$sessionInfo = Db::name('session')->where(['session_id' => $val['api_token'],'user_id' => $val['id']])->find();
|
||||
if((time() - $sessionInfo['last_time']) <= Config::get('session_life_time')){
|
||||
$data['server_status'] = $sessionInfo['server_status'];
|
||||
$data['is_online'] = 1;
|
||||
if($sessionInfo['table_id']){
|
||||
$data['table_id'] = $sessionInfo['table_id'];
|
||||
$data['table_name'] = $tableInfo[$sessionInfo['table_id']] ? $tableInfo[$sessionInfo['table_id']] : '';
|
||||
$numberTabInfo = Db::name('number_tab')->field(['id'])->where('table_id',$sessionInfo['table_id'])->order('id DESC')->limit(1)->find();
|
||||
if($numberTabInfo['id']){
|
||||
$betInfo = Db::name('bet')->where(['table_id' => $sessionInfo['table_id'],'number_tab_id' => $numberTabInfo['id'],'user_id' => $val['id']])->field(['amount'])->find();
|
||||
$data['bet_amount'] = (int)$betInfo['amount'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$playerData[] = $data;
|
||||
}
|
||||
$returnData['player_data'] = $playerData;
|
||||
$returnData['player_num'] = $player_num;
|
||||
$returnData['page_num'] = $page_num;
|
||||
$returnData = encrypt_data($returnData);
|
||||
return json(array('Success' => 1, 'Data' => $returnData));
|
||||
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '获取失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '获取失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '获取失败']);
|
||||
}
|
||||
}
|
||||
public function online_players() {
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
|
||||
if(Request::instance()->post()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
if ($json_arr) {
|
||||
$user_id = intval($json_arr['user_id']);
|
||||
$api_token = trim($json_arr['api_token']);
|
||||
$find = Db::name('manager')->where(array('id' => $user_id,'status' => 1, 'api_token' => $api_token))->find();
|
||||
$user_online = array();
|
||||
if ($find) {
|
||||
$session_user = Db::name('session')->select();
|
||||
foreach($session_user as $v){
|
||||
$time = time() - Config::get('session_life_time');
|
||||
if($v['last_time'] < $time){
|
||||
//30分钟内没操作,移除在线在在线玩家的列表
|
||||
Db::name('session')->where('user_id',$v['user_id'])->delete();
|
||||
}else{
|
||||
//30分钟内有操作的玩家,并且是该代理下面的直属玩家
|
||||
$user = Db::name('user')->where(['id'=>$v['user_id'], 'manager_id'=>$user_id])->find();
|
||||
if($user){
|
||||
$user_online[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return json(array('Success' => 1, 'Data' => encrypt_data($user_online)));
|
||||
|
||||
}
|
||||
return json(['Success' => 0, 'Msg' => '获取失败']);
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '获取失败']);
|
||||
}
|
||||
}
|
||||
|
||||
//开始/停止服务
|
||||
public function operate_server(){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
if(Request::instance()->isPost()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
if($json_arr){
|
||||
$user_id = intval($json_arr['user_id']);
|
||||
$player_id = intval($json_arr['player_id']);
|
||||
$operate_type = intval($json_arr['operate_type']);//1开启 0 关闭
|
||||
$api_token = trim($json_arr['api_token']);
|
||||
if($user_id && $player_id){
|
||||
$find = Db::name('manager')->where(array('id' => $user_id))->find();
|
||||
if($find && $find['api_token'] == $api_token){
|
||||
$findUserSession = Db::name('session')->where(array('user_id' => $player_id))->find();
|
||||
if($findUserSession && time() - $findUserSession['last_time'] <= Config::get('session_life_time')){
|
||||
$updateData = [];
|
||||
$updateData['server_status'] = $operate_type;
|
||||
$res = Db::name('session')->where('user_id',$player_id)->update($updateData);
|
||||
if($res){
|
||||
return json(['Success' => 1, 'Msg' => '操作成功']);
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '操作失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '操作失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '操作失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '操作失败']);
|
||||
}
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '操作失败']);
|
||||
}
|
||||
|
||||
}else{
|
||||
return json(['Success' => 0, 'Msg' => '操作失败']);
|
||||
}
|
||||
}
|
||||
|
||||
public function all_table(){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
if(Request::instance()->isPost()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
if($json_arr){
|
||||
$user_id = intval($json_arr['user_id']);
|
||||
$api_token = trim($json_arr['api_token']);
|
||||
$user = Db::name('manager')->where(array('id' => $user_id))->find();
|
||||
|
||||
if($user && $user['api_token'] == $api_token){
|
||||
$tableWhere = [];
|
||||
$tableWhere['status'] = 1;
|
||||
$tableWhere['table_type'] = 0;
|
||||
$tableWhere['bet_type'] = 2;
|
||||
$tables = Db::name('table')->where($tableWhere)->whereIn('game_id',[1,2])->order('sort DESC')->select();
|
||||
|
||||
$bootTabTable = 'boot';
|
||||
$numberTabTable = 'number_tab';
|
||||
$betTable = 'bet';
|
||||
|
||||
foreach($tables AS $key => $value){
|
||||
$tableData = [];
|
||||
$tableData['id'] = $value['id'];
|
||||
$tableData['table_name'] = $value['table_name'];
|
||||
$tableData['game_id'] = $value['game_id'];
|
||||
$tableData['table_num'] = $value['table_num'];
|
||||
$tableData['game_name'] = $value['game_name'];
|
||||
$tableData['limit_money'] = $value['limit_money'];
|
||||
$tableData['limit_money_tie'] = $value['limit_money_tie'];
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['limit_money_pair'] = $value['limit_money_pair'];
|
||||
}
|
||||
$tableData['in_checkout'] = $value['in_checkout'];
|
||||
|
||||
$tableData['bet_amount_msg']['banker_amount'] = 0;
|
||||
$tableData['bet_amount_msg']['player_amount'] = 0;
|
||||
$tableData['bet_amount_msg']['tie_amount'] = 0;
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['bet_amount_msg']['banker_pair_amount'] = 0;
|
||||
$tableData['bet_amount_msg']['player_pair_amount'] = 0;
|
||||
}
|
||||
|
||||
$tableData['status'] = $value['status'];
|
||||
$tableData['is_scavenging'] = $value['is_scavenging'];
|
||||
$tableData['wait_time'] = $value['wait_time'];
|
||||
$tableData['rob_time'] = $value['rob_time'];
|
||||
$tableData['media_far_rtmp'] = $value['media_far_rtmp'];
|
||||
$tableData['media_far_flv'] = $value['media_far_flv'];
|
||||
$tableData['media_far_ws'] = $value['media_far_ws'];
|
||||
$tableData['media_near_rtmp'] = $value['media_near_rtmp'];
|
||||
$tableData['media_near_flv'] = $value['media_near_flv'];
|
||||
$tableData['media_near_ws'] = $value['media_near_ws'];
|
||||
$tableData['bet_type'] = $value['bet_type'];
|
||||
$tableData['is_rob'] = $value['is_rob'];
|
||||
$tableData['limit_banker_amount'] = $value['limit_banker_amount'];
|
||||
$tableData['table_type'] = $value['table_type'];
|
||||
$tableData['is_localhost_control'] = $value['is_localhost_control'];
|
||||
$tableData['phone'] = $value['phone'];
|
||||
$tableData['interval_time'] = $value['interval_time'];
|
||||
$tableData['card_first_type'] = $value['card_first_type'];
|
||||
$tableData['spec_type'] = $value['spec_type'];
|
||||
$tableData['scanner_type'] = $value['scanner_type'];
|
||||
$tableData['seat_num'] = $value['seat_num'];
|
||||
|
||||
|
||||
$boot = Db::name($bootTabTable)->where('table_id',$value['id'])->order('id DESC')->find();
|
||||
if($boot){
|
||||
$tableData['boot_num'] = $boot['boot_num'];
|
||||
$tableData['boot_id'] = $boot['id'];
|
||||
$cur_number_tab = Db::name($numberTabTable)->where(array('table_id' => $value['id'], 'boot_id' => $boot['id']))->order('id DESC')->find();
|
||||
$tableData['number_tab_number'] = is_array($cur_number_tab) ? $cur_number_tab['number'] : 1;
|
||||
$tableData['number_tab_id'] = is_array($cur_number_tab) ? $cur_number_tab['id'] : 1;
|
||||
$tableData['bet_status'] = $cur_number_tab['bet_status'];
|
||||
$seat_arr = json_decode($cur_number_tab['seat_json'],true);
|
||||
//自动台返回牌型
|
||||
if($value['is_scavenging'] == 1 && $cur_number_tab['bet_status'] == 2){
|
||||
$card_info = getRedisCardByPosition($cur_number_tab['id']);
|
||||
if($card_info){
|
||||
$tableData['card_info']['banker_1'] = $card_info['banker_1'];
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['card_info']['banker_2'] = $card_info['banker_2'];
|
||||
$tableData['card_info']['banker_3'] = $card_info['banker_3'];
|
||||
}
|
||||
$tableData['card_info']['player_1'] = $card_info['player_1'];
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['card_info']['player_2'] = $card_info['player_2'];
|
||||
$tableData['card_info']['player_3'] = $card_info['player_3'];
|
||||
}
|
||||
}else{
|
||||
$tableData['card_info']['banker_1'] = 0;
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['card_info']['banker_2'] = 0;
|
||||
$tableData['card_info']['banker_3'] = 0;
|
||||
}
|
||||
$tableData['card_info']['player_1'] = 0;
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['card_info']['player_2'] = 0;
|
||||
$tableData['card_info']['player_3'] = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$tableData['card_info']['banker_1'] = 0;
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['card_info']['banker_2'] = 0;
|
||||
$tableData['card_info']['banker_3'] = 0;
|
||||
}
|
||||
$tableData['card_info']['player_1'] = 0;
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['card_info']['player_2'] = 0;
|
||||
$tableData['card_info']['player_3'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$tableData['bet_info'] = [];
|
||||
$sql = "SELECT u.id,u.username,s.last_time,s.server_status FROM cg_user u,cg_session s
|
||||
WHERE u.manager_id = ".$user['id']." AND u.api_token = s.session_id AND s.table_id = ".$value['id'];
|
||||
$res = Db::query($sql);
|
||||
foreach ($res as $val){
|
||||
if((time() - $val['last_time']) > Config::get('session_life_time')){
|
||||
continue;
|
||||
}
|
||||
$userData = [];
|
||||
$userData['user_id'] = $val['id'];
|
||||
$userData['username'] = $val['username'];
|
||||
$userData['server_status'] = $val['server_status'];
|
||||
$userData['bet_amount'] = 0;
|
||||
if(isset($seat_arr[$user_id])){
|
||||
$nowSeatNum = array_search($val['id'],$seat_arr[$user_id]);
|
||||
if($nowSeatNum){
|
||||
$userData['seat_num'] = $nowSeatNum;
|
||||
}else{
|
||||
$userData['seat_num'] = 0;
|
||||
}
|
||||
}else{
|
||||
$userData['seat_num'] = 0;
|
||||
}
|
||||
if($cur_number_tab['bet_status'] == 1 || $cur_number_tab['bet_status'] == 2){
|
||||
$bet = Db::name($betTable)->where(array('table_id' => $value['id'], 'boot_id' => $boot['id'], 'number_tab_id' => $cur_number_tab['id'], 'user_id' => $val['id']))->find();
|
||||
if($bet){
|
||||
$userData['seat_num'] = $bet['seat_num'];
|
||||
$userData['bet_amount'] = (int)$bet['amount'];
|
||||
$userData['banker_amount'] = (int)$bet['banker_amount'];
|
||||
$userData['player_amount'] = (int)$bet['player_amount'];
|
||||
$userData['tie_amount'] = (int)$bet['tie_amount'];
|
||||
if($value['game_id'] == 1){
|
||||
$userData['banker_pair_amount'] = (int)$bet['banker_pair_amount'];
|
||||
$userData['player_pair_amount'] = (int)$bet['player_pair_amount'];
|
||||
}
|
||||
|
||||
$tableData['bet_amount_msg']['banker_amount'] = (int)$tableData['bet_amount_msg']['banker_amount'] + (int)$bet['banker_amount'];
|
||||
$tableData['bet_amount_msg']['player_amount'] = (int)$tableData['bet_amount_msg']['player_amount'] + (int)$bet['player_amount'];
|
||||
$tableData['bet_amount_msg']['tie_amount'] = (int)$tableData['bet_amount_msg']['tie_amount'] + (int)$bet['tie_amount'];
|
||||
if($value['game_id'] == 1){
|
||||
$tableData['bet_amount_msg']['banker_pair_amount'] = (int)$tableData['bet_amount_msg']['banker_pair_amount'] + (int)$bet['banker_pair_amount'];
|
||||
$tableData['bet_amount_msg']['player_pair_amount'] = (int)$tableData['bet_amount_msg']['player_pair_amount'] + (int)$bet['player_pair_amount'];;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$tableData['bet_info'][] = $userData;
|
||||
}
|
||||
}else{
|
||||
$tableData['boot_num'] = 1;
|
||||
$tableData['boot_id'] = 0;
|
||||
$tableData['number_tab_number'] = 1;
|
||||
$tableData['number_tab_id'] = 0;
|
||||
$tableData['bet_status'] = 0;
|
||||
$tableData['bet_info'] = [];
|
||||
$tableData['bet_amount_msg'] = [];
|
||||
$tableData['card_info'] = [];
|
||||
|
||||
}
|
||||
$tables[$key] = $tableData;
|
||||
}
|
||||
$data = encrypt_data($tables);
|
||||
return json(array('Success' => 1, 'Data' => $data));
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
} else {
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
}
|
||||
|
||||
public function single_table(){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
if(Request::instance()->isPost()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
if($json_arr){
|
||||
$user_id = intval($json_arr['user_id']);
|
||||
$api_token = trim($json_arr['api_token']);
|
||||
$table_id = intval($json_arr['table_id']);
|
||||
$user = Db::name('manager')->where(array('id' => $user_id))->find();
|
||||
|
||||
if($user && $user['api_token'] == $api_token){
|
||||
$tableWhere = [];
|
||||
$tableWhere['status'] = 1;
|
||||
$tableWhere['table_type'] = 0;
|
||||
$tableWhere['bet_type'] = 2;
|
||||
$tableWhere['id'] = $table_id;
|
||||
$tableInfo = Db::name('table')->where($tableWhere)->whereIn('game_id',[1,2])->order('sort DESC')->find();
|
||||
|
||||
if($tableInfo){
|
||||
$bootTabTable = 'boot';
|
||||
$numberTabTable = 'number_tab';
|
||||
$betTable = 'bet';
|
||||
|
||||
$tableData = [];
|
||||
$tableData['id'] = $tableInfo['id'];
|
||||
$tableData['table_name'] = $tableInfo['table_name'];
|
||||
$tableData['game_id'] = $tableInfo['game_id'];
|
||||
$tableData['table_num'] = $tableInfo['table_num'];
|
||||
$tableData['game_name'] = $tableInfo['game_name'];
|
||||
$tableData['limit_money'] = $tableInfo['limit_money'];
|
||||
$tableData['limit_money_tie'] = $tableInfo['limit_money_tie'];
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['limit_money_pair'] = $tableInfo['limit_money_pair'];
|
||||
}
|
||||
$tableData['in_checkout'] = $tableInfo['in_checkout'];
|
||||
|
||||
$tableData['bet_amount_msg']['banker_amount'] = 0;
|
||||
$tableData['bet_amount_msg']['player_amount'] = 0;
|
||||
$tableData['bet_amount_msg']['tie_amount'] = 0;
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['bet_amount_msg']['banker_pair_amount'] = 0;
|
||||
$tableData['bet_amount_msg']['player_pair_amount'] = 0;
|
||||
}
|
||||
|
||||
$tableData['status'] = $tableInfo['status'];
|
||||
$tableData['is_scavenging'] = $tableInfo['is_scavenging'];
|
||||
$tableData['wait_time'] = $tableInfo['wait_time'];
|
||||
$tableData['rob_time'] = $tableInfo['rob_time'];
|
||||
$tableData['media_far_rtmp'] = $tableInfo['media_far_rtmp'];
|
||||
$tableData['media_far_flv'] = $tableInfo['media_far_flv'];
|
||||
$tableData['media_far_ws'] = $tableInfo['media_far_ws'];
|
||||
$tableData['media_near_rtmp'] = $tableInfo['media_near_rtmp'];
|
||||
$tableData['media_near_flv'] = $tableInfo['media_near_flv'];
|
||||
$tableData['media_near_ws'] = $tableInfo['media_near_ws'];
|
||||
$tableData['bet_type'] = $tableInfo['bet_type'];
|
||||
$tableData['is_rob'] = $tableInfo['is_rob'];
|
||||
$tableData['limit_banker_amount'] = $tableInfo['limit_banker_amount'];
|
||||
$tableData['table_type'] = $tableInfo['table_type'];
|
||||
$tableData['is_localhost_control'] = $tableInfo['is_localhost_control'];
|
||||
$tableData['phone'] = $tableInfo['phone'];
|
||||
$tableData['interval_time'] = $tableInfo['interval_time'];
|
||||
$tableData['card_first_type'] = $tableInfo['card_first_type'];
|
||||
$tableData['spec_type'] = $tableInfo['spec_type'];
|
||||
$tableData['scanner_type'] = $tableInfo['scanner_type'];
|
||||
$tableData['seat_num'] = $tableInfo['seat_num'];
|
||||
|
||||
|
||||
$boot = Db::name($bootTabTable)->where('table_id',$tableInfo['id'])->order('id DESC')->find();
|
||||
if($boot){
|
||||
$tableData['boot_num'] = $boot['boot_num'];
|
||||
$tableData['boot_id'] = $boot['id'];
|
||||
$cur_number_tab = Db::name($numberTabTable)->where(array('table_id' => $tableInfo['id'], 'boot_id' => $boot['id']))->order('id DESC')->find();
|
||||
$tableData['number_tab_number'] = is_array($cur_number_tab) ? $cur_number_tab['number'] : 1;
|
||||
$tableData['number_tab_id'] = is_array($cur_number_tab) ? $cur_number_tab['id'] : 1;
|
||||
$tableData['bet_status'] = $cur_number_tab['bet_status'];
|
||||
$seat_arr = json_decode($cur_number_tab['seat_json'],true);
|
||||
//自动台返回牌型
|
||||
if($tableInfo['is_scavenging'] == 1 && $cur_number_tab['bet_status'] == 2){
|
||||
$card_info = getRedisCardByPosition($cur_number_tab['id']);
|
||||
if($card_info){
|
||||
$tableData['card_info']['banker_1'] = $card_info['banker_1'];
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['card_info']['banker_2'] = $card_info['banker_2'];
|
||||
$tableData['card_info']['banker_3'] = $card_info['banker_3'];
|
||||
}
|
||||
$tableData['card_info']['player_1'] = $card_info['player_1'];
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['card_info']['player_2'] = $card_info['player_2'];
|
||||
$tableData['card_info']['player_3'] = $card_info['player_3'];
|
||||
}
|
||||
}else{
|
||||
$tableData['card_info']['banker_1'] = 0;
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['card_info']['banker_2'] = 0;
|
||||
$tableData['card_info']['banker_3'] = 0;
|
||||
}
|
||||
$tableData['card_info']['player_1'] = 0;
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['card_info']['player_2'] = 0;
|
||||
$tableData['card_info']['player_3'] = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$tableData['card_info']['banker_1'] = 0;
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['card_info']['banker_2'] = 0;
|
||||
$tableData['card_info']['banker_3'] = 0;
|
||||
}
|
||||
$tableData['card_info']['player_1'] = 0;
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['card_info']['player_2'] = 0;
|
||||
$tableData['card_info']['player_3'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$tableData['bet_info'] = [];
|
||||
$sql = "SELECT u.id,u.username,s.last_time,s.server_status FROM cg_user u,cg_session s
|
||||
WHERE u.manager_id = ".$user['id']." AND u.api_token = s.session_id AND s.table_id = ".$tableInfo['id'];
|
||||
$res = Db::query($sql);
|
||||
foreach ($res as $val){
|
||||
if((time() - $val['last_time']) > Config::get('session_life_time')){
|
||||
continue;
|
||||
}
|
||||
$userData = [];
|
||||
$userData['user_id'] = $val['id'];
|
||||
$userData['username'] = $val['username'];
|
||||
$userData['server_status'] = $val['server_status'];
|
||||
$userData['bet_amount'] = 0;
|
||||
if(isset($seat_arr[$user_id])){
|
||||
$nowSeatNum = array_search($val['id'],$seat_arr[$user_id]);
|
||||
if($nowSeatNum){
|
||||
$userData['seat_num'] = $nowSeatNum;
|
||||
}else{
|
||||
$userData['seat_num'] = 0;
|
||||
}
|
||||
}else{
|
||||
$userData['seat_num'] = 0;
|
||||
}
|
||||
if($cur_number_tab['bet_status'] == 1 || $cur_number_tab['bet_status'] == 2){
|
||||
$bet = Db::name($betTable)->where(array('table_id' => $tableInfo['id'], 'boot_id' => $boot['id'], 'number_tab_id' => $cur_number_tab['id'], 'user_id' => $val['id']))->find();
|
||||
if($bet){
|
||||
$userData['seat_num'] = $bet['seat_num'];
|
||||
$userData['bet_amount'] = $bet['amount'];
|
||||
$userData['banker_amount'] = (int)$bet['banker_amount'];
|
||||
$userData['player_amount'] = (int)$bet['player_amount'];
|
||||
$userData['tie_amount'] = (int)$bet['tie_amount'];
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$userData['banker_pair_amount'] = (int)$bet['banker_pair_amount'];
|
||||
$userData['player_pair_amount'] = (int)$bet['player_pair_amount'];
|
||||
}
|
||||
|
||||
$tableData['bet_amount_msg']['banker_amount'] = (int)$tableData['bet_amount_msg']['banker_amount'] + (int)$bet['banker_amount'];
|
||||
$tableData['bet_amount_msg']['player_amount'] = (int)$tableData['bet_amount_msg']['player_amount'] + $bet['player_amount'];
|
||||
$tableData['bet_amount_msg']['tie_amount'] = (int)$tableData['bet_amount_msg']['tie_amount'] + (int)$bet['tie_amount'];
|
||||
if($tableInfo['game_id'] == 1){
|
||||
$tableData['bet_amount_msg']['banker_pair_amount'] = (int)$tableData['bet_amount_msg']['banker_pair_amount'] + (int)$bet['banker_pair_amount'];
|
||||
$tableData['bet_amount_msg']['player_pair_amount'] = (int)$tableData['bet_amount_msg']['player_pair_amount'] + (int)$bet['player_pair_amount'];;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$tableData['bet_info'][] = $userData;
|
||||
}
|
||||
}else{
|
||||
$tableData['boot_num'] = 1;
|
||||
$tableData['boot_id'] = 0;
|
||||
$tableData['number_tab_number'] = 1;
|
||||
$tableData['number_tab_id'] = 0;
|
||||
$tableData['bet_status'] = 0;
|
||||
$tableData['bet_info'] = [];
|
||||
$tableData['bet_amount_msg'] = [];
|
||||
$tableData['card_info'] = [];
|
||||
|
||||
}
|
||||
$data = encrypt_data($tableData);
|
||||
return json(array('Success' => 1, 'Data' => $data));
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
} else {
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//游戏记录
|
||||
public function get_user_bets(){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header("Access-Control-Allow-Headers: token, Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE');
|
||||
if(Request::instance()->isPost()){
|
||||
$json_arr = decrypt_data(Request::instance()->post());
|
||||
|
||||
if($json_arr){
|
||||
// 语言包
|
||||
$langList = ['tw' => 'zh-tw.php','en' => 'en-us.php'];
|
||||
$langType = empty($json_arr['language']) ? 'cn' : $json_arr['language'];
|
||||
$langFile = empty($langList[$langType]) ? 'en-us.php' : $langList[$langType];
|
||||
$langFile = ROOT_PATH.'thinkphp/lang/'.$langFile;
|
||||
Lang::load($langFile);
|
||||
$lang = Lang::get();
|
||||
|
||||
$user_id = intval($json_arr['user_id']);
|
||||
$api_token = trim($json_arr['api_token']);
|
||||
|
||||
$game_id = empty($json_arr['game_id']) ? 0 : intval($json_arr['game_id']);
|
||||
$table_id = empty($json_arr['table_id']) ? 0 : intval($json_arr['table_id']);
|
||||
$username = empty($json_arr['username']) ? '' : trim($json_arr['username']);
|
||||
$page = intval($json_arr['page']);
|
||||
$user = Db::name('manager')->where(array('id' => $user_id))->find();
|
||||
|
||||
if($user && $user['api_token'] == $api_token && $page > 0){
|
||||
|
||||
$betWhere = array();
|
||||
$betWhere['manager_id'] = $user_id;
|
||||
if($game_id){
|
||||
$betWhere['game_id'] = $game_id;
|
||||
}
|
||||
if($table_id){
|
||||
$betWhere['table_id'] = $table_id;
|
||||
}
|
||||
if($username){
|
||||
$betWhere['username'] = $username;
|
||||
}
|
||||
$betWhere['status'] = array('>',0);
|
||||
$page_list = 15;
|
||||
if($page > 1){
|
||||
$limie_start = ($page - 1) * $page_list;
|
||||
}else{
|
||||
$limie_start = 0;
|
||||
}
|
||||
$bet = Db::name('bet')->where($betWhere)->whereIn('game_id',[1,2])->order('id desc')->limit($limie_start,$page_list)->select();
|
||||
$bet_num = Db::name('bet')->where($betWhere)->whereIn('game_id',[1,2])->order('id desc')->count();
|
||||
|
||||
$page_num = ceil($bet_num/$page_list);
|
||||
//组装注单信息
|
||||
$newBet = array();
|
||||
|
||||
$user_bets = array();
|
||||
foreach ($bet as $k => $v){
|
||||
$data = array();
|
||||
$v['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
|
||||
$v['game_num'] = $v['game_id'].$v['boot_num'].$v['number'];
|
||||
|
||||
if($v['game_id'] == 1){
|
||||
$number_info = Db::name('number_tab')->where('id',$v['number_tab_id'])->find();
|
||||
if($number_info['bet_status'] == 3){
|
||||
if($number_info['result'] == 1){
|
||||
$result = $lang['banker'];
|
||||
}elseif($number_info['result'] == 2){
|
||||
$result = $lang['player'];
|
||||
}elseif($number_info['result'] == 3){
|
||||
$result = $lang['tie'];
|
||||
}else{
|
||||
$result = '-';
|
||||
}
|
||||
if($number_info['pair'] == 1){
|
||||
$pair = ','.$lang['banker_pair'];
|
||||
}elseif($number_info['pair'] == 2){
|
||||
$pair = ','.$lang['player_pair'];
|
||||
}elseif($number_info['pair'] == 3){
|
||||
$pair = ','.$lang['both_pair'];
|
||||
}else{
|
||||
$pair = '';
|
||||
}
|
||||
if($number_info['luck_six'] > 1){
|
||||
$luck_six = ','.$lang['luck_6'];
|
||||
}else{
|
||||
$luck_six = '';
|
||||
}
|
||||
if($number_info['big_small'] == 1){
|
||||
$big_small = ','.$lang['big'];
|
||||
}elseif($number_info['big_small'] == 2){
|
||||
$big_small = ','.$lang['small'];
|
||||
}else{
|
||||
$big_small = '';
|
||||
}
|
||||
$v['card_result'] = $result.$pair.$luck_six.$big_small;
|
||||
}else{
|
||||
$v['card_result'] = '-';
|
||||
}
|
||||
if($v['status'] == 2){
|
||||
$v['card_result'] = $lang['void'];
|
||||
}
|
||||
$data['game_num'] = $v['game_num'];
|
||||
$data['table_name'] = $v['table_name'].'('.$v['boot_num'].'/'.$v['number'].')';
|
||||
$data['card_result'] = $v['card_result'];
|
||||
$data['user_bet'] = '';
|
||||
if($v['banker_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['banker'].'('.$v['banker_amount'].')';
|
||||
}
|
||||
if($v['player_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['player'].'('.$v['player_amount'].')';
|
||||
}
|
||||
if($v['tie_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['tie'].'('.$v['tie_amount'].')';
|
||||
}
|
||||
if($v['banker_pair_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['banker_pair'].'('.$v['banker_pair_amount'].')';
|
||||
}
|
||||
if($v['player_pair_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['player_pair'].'('.$v['player_pair_amount'].')';
|
||||
}
|
||||
if($v['luck_six_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['luck_6'].'('.$v['luck_six_amount'].')';
|
||||
}
|
||||
if($v['big_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['big'].'('.$v['big_amount'].')';
|
||||
}
|
||||
if($v['small_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['small'].'('.$v['small_amount'].')';
|
||||
}
|
||||
if($v['baccarat_type'] == 1){
|
||||
$data['user_bet'] = $data['user_bet'].'('.$lang['free_commission'].')';
|
||||
}else{
|
||||
$data['user_bet'] = $data['user_bet'].'('.$lang['commission'].')';
|
||||
}
|
||||
|
||||
$data['create_time'] = $v['create_time'];
|
||||
$data['money_before_bet'] = $v['money_before_bet'];
|
||||
$data['amount'] = $v['amount'];
|
||||
$data['win_total'] = $v['win_total'];
|
||||
$data['seat_num'] = $v['seat_num'];
|
||||
$data['user_id'] = $v['user_id'];
|
||||
$data['username'] = $v['username'];
|
||||
$data['nickname'] = $v['nickname'];
|
||||
$data['manager_id'] = $user['id'];
|
||||
$data['manager_username'] = $user['username'];
|
||||
$data['manager_nickname'] = $user['nickname'];
|
||||
$newBet[] = $data;
|
||||
}
|
||||
if($v['game_id'] == 2){
|
||||
$number_info = Db::name('number_tab')->where('id',$v['number_tab_id'])->find();
|
||||
if($number_info['bet_status'] == 3){
|
||||
if($number_info['result'] == 1){
|
||||
$result = $lang['dragon'];
|
||||
}elseif($number_info['result'] == 2){
|
||||
$result = $lang['tiger'];
|
||||
}elseif($number_info['result'] == 3){
|
||||
$result = $lang['tie'];
|
||||
}else{
|
||||
$result = '-';
|
||||
}
|
||||
$v['card_result'] = $result;
|
||||
}else{
|
||||
$v['card_result'] = '-';
|
||||
}
|
||||
if($v['status'] == 2){
|
||||
$v['card_result'] = $lang['void'];
|
||||
}
|
||||
$data['game_num'] = $v['game_num'];
|
||||
$data['table_name'] = $v['table_name'].'('.$v['boot_num'].'/'.$v['number'].')';
|
||||
$data['card_result'] = $v['card_result'];
|
||||
$data['user_bet'] = '';
|
||||
if($v['banker_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['dragon'].'('.$v['banker_amount'].')';
|
||||
}
|
||||
if($v['player_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['tiger'].'('.$v['player_amount'].')';
|
||||
}
|
||||
if($v['tie_amount'] > 0){
|
||||
$data['user_bet'] = $data['user_bet'].$lang['tie'].'('.$v['tie_amount'].')';
|
||||
}
|
||||
$data['create_time'] = $v['create_time'];
|
||||
$data['money_before_bet'] = $v['money_before_bet'];
|
||||
$data['amount'] = $v['amount'];
|
||||
$data['win_total'] = $v['win_total'];
|
||||
$data['seat_num'] = $v['seat_num'];
|
||||
$data['user_id'] = $v['user_id'];
|
||||
$data['username'] = $v['username'];
|
||||
$data['nickname'] = $v['nickname'];
|
||||
$data['manager_id'] = $user['id'];
|
||||
$data['manager_username'] = $user['username'];
|
||||
$data['manager_nickname'] = $user['nickname'];
|
||||
$newBet[] = $data;
|
||||
}
|
||||
}
|
||||
// 重新赋值
|
||||
$user_bets['bet_info'] = $newBet;
|
||||
$user_bets['bet_num'] = $bet_num;
|
||||
$user_bets['page_num'] = $page_num;
|
||||
$bet = encrypt_data($user_bets);
|
||||
return json(array('Success' => 1, 'Data' => $bet));
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function create_online_token($user){
|
||||
return md5($user['encrypt'].$user['password']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller;
|
||||
use \think\Controller;
|
||||
use think\Exception;
|
||||
use \think\Session;
|
||||
use \think\Request;
|
||||
use \think\Db;
|
||||
use \think\Log;
|
||||
class Order Extends Controller{
|
||||
use traits\yonghengPay;
|
||||
use traits\oneGoPay;
|
||||
use traits\hipPay;
|
||||
use traits\tingPay;
|
||||
use traits\happyPay;
|
||||
use traits\hengfuPay;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function test_post(){
|
||||
return $this->fetch();
|
||||
}
|
||||
public function index(){
|
||||
$user_id = intval(Request::instance()->get('uid'));
|
||||
$api_token = trim(Request::instance()->get('api_token'));
|
||||
$user = Db::name('user')->where(array('id' => $user_id))->find();
|
||||
$area_list = config('area_list');
|
||||
$pay_list = config('pay_list');
|
||||
if(!isset($area_list[$user['area_id']])){
|
||||
exit('所在地区暂不支持充值');
|
||||
}
|
||||
$pay_method = $area_list[$user['area_id']]['pay'];
|
||||
if($user && $user['api_token'] == $api_token){
|
||||
$this->assign('online_order_fac',$pay_list[$pay_method]['online_order_fac']);
|
||||
$this->assign('payMethod',$pay_list[$pay_method]['type']);
|
||||
$this->assign('client',1);
|
||||
$this->assign('user_info',$user);
|
||||
return $this->fetch();
|
||||
}else{
|
||||
exit('页面错误,请退出再登录!');
|
||||
}
|
||||
}
|
||||
|
||||
public function wappay(){
|
||||
$user_id = intval(Request::instance()->get('uid'));
|
||||
$api_token = trim(Request::instance()->get('api_token'));
|
||||
$user = Db::name('user')->where(array('id' => $user_id))->find();
|
||||
$area_list = config('area_list');
|
||||
$pay_list = config('pay_list');
|
||||
if(!isset($area_list[$user['area_id']])){
|
||||
exit('所在地区暂不支持充值');
|
||||
}
|
||||
$pay_method = $area_list[$user['area_id']]['pay'];
|
||||
if($user && $user['api_token'] == $api_token){
|
||||
$this->assign('online_order_fac',$pay_list[$pay_method]['online_order_fac']);
|
||||
$this->assign('payMethod',$pay_list[$pay_method]['type']);
|
||||
$this->assign('client',2);
|
||||
$this->assign('user_info',$user);
|
||||
return $this->fetch();
|
||||
}else{
|
||||
exit('页面错误,请退出再登录!');
|
||||
}
|
||||
}
|
||||
|
||||
//确认充值
|
||||
public function recharge(){
|
||||
$user_id = intval(Request::instance()->post('user_id'));
|
||||
$recharge_type = intval(Request::instance()->post('recharge_type'));
|
||||
$receivables_id = intval(Request::instance()->post('receivables_id'));
|
||||
if($recharge_type == 1){
|
||||
$recharge_bank = trim(Request::instance()->post('recharge_bank'));
|
||||
$recharge_cardnumber = trim(Request::instance()->post('recharge_cardnumber'));
|
||||
}
|
||||
$recharge_money = trim(Request::instance()->post('recharge_money'));
|
||||
if(!$recharge_money || $recharge_money <= 0){
|
||||
return json(array('Success' => 0, 'Msg' => '充值金额有误'));
|
||||
}
|
||||
$user = Db::name('user')->where(array('id' => $user_id))->find();
|
||||
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$area_list = config('area_list');
|
||||
//判断是否金流支线,如果不是的话,不允许充值
|
||||
$isAllow = false;
|
||||
foreach($area_list[$user['area_id']]['limit_agent'] as $allowAgentId){
|
||||
if(in_array($allowAgentId,$zdlIdArr)){
|
||||
$isAllow = true;
|
||||
}
|
||||
}
|
||||
if(!$isAllow){
|
||||
return json(array('status' => 0, 'message' => '该账号暂不支持充值'));
|
||||
}
|
||||
|
||||
|
||||
if($user && $recharge_type > 0 && $receivables_id > 0 && $recharge_money > 0){
|
||||
$add_record = array();
|
||||
$add_record['user_id'] = $user_id;
|
||||
$add_record['username'] = $user['username'];
|
||||
$add_record['record_type'] = 1;
|
||||
$add_record['recharge_type'] = $recharge_type;
|
||||
$add_record['receivables_id'] = $receivables_id;
|
||||
$recharge_info = Db::name('receivables')->where('id',$receivables_id)->find();
|
||||
$add_record['recharge_name'] = $recharge_info['receivables_name'];
|
||||
$add_record['recharge_name'] = $user['username'];
|
||||
if($add_record['recharge_type'] == 1){
|
||||
$add_record['recharge_bank'] = $recharge_bank;
|
||||
$add_record['recharge_cardnumber'] = $recharge_cardnumber;
|
||||
}
|
||||
$add_record['recharge_money'] = $recharge_money;
|
||||
$add_record['create_time'] = time();
|
||||
$add_record['status'] = 0;
|
||||
$is_add_record = Db::name('receivables_record')->insert($add_record);
|
||||
if($is_add_record){
|
||||
$record_info = array();
|
||||
$record_info['msg'] = '充值成功,请联系管理员确认';
|
||||
$record_info['finish_money'] = Db::name('receivables_record')->where('record_type',1)->where('user_id',$user_id)->where('status',1)->sum('recharge_money');
|
||||
$record_info['ongoing_money'] = Db::name('receivables_record')->where('record_type',1)->where('user_id',$user_id)->where('status',0)->sum('recharge_money');
|
||||
$data = $record_info;
|
||||
return json(array('Success' => 1, 'Data' => $data));
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '充值失败,请稍后再试'));
|
||||
}
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
}
|
||||
|
||||
//确认提现
|
||||
public function withdrawal(){
|
||||
$user_id = intval(Request::instance()->post('user_id'));
|
||||
$recharge_name = trim(Request::instance()->post('recharge_name'));
|
||||
$recharge_bank = trim(Request::instance()->post('recharge_bank'));
|
||||
$recharge_bank_branch = trim(Request::instance()->post('recharge_bank_branch'));
|
||||
$recharge_cardnumber = trim(Request::instance()->post('recharge_cardnumber'));
|
||||
$recharge_money = trim(Request::instance()->post('recharge_money'));
|
||||
if(!$recharge_name){
|
||||
return json(array('Success' => 0, 'Msg' => '持卡人不能为空'));
|
||||
}
|
||||
if(!$recharge_bank){
|
||||
return json(array('Success' => 0, 'Msg' => '提款银行不能为空'));
|
||||
}
|
||||
if(!$recharge_bank_branch){
|
||||
return json(array('Success' => 0, 'Msg' => '提款银行支行不能为空'));
|
||||
}
|
||||
if(!$recharge_cardnumber){
|
||||
return json(array('Success' => 0, 'Msg' => '提款银行卡号不能为空'));
|
||||
}
|
||||
if(!$recharge_money || $recharge_money <= 0){
|
||||
return json(array('Success' => 0, 'Msg' => '提款金额有误'));
|
||||
}
|
||||
$user = Db::name('user')->where(array('id' => $user_id))->find();
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$area_list = config('area_list');
|
||||
//判断是否金流支线,如果不是的话,不允许充值
|
||||
$isAllow = false;
|
||||
foreach($area_list[$user['area_id']]['limit_agent'] as $allowAgentId){
|
||||
if(in_array($allowAgentId,$zdlIdArr)){
|
||||
$isAllow = true;
|
||||
}
|
||||
}
|
||||
if(!$isAllow){
|
||||
return json(array('status' => 0, 'message' => '该账号暂不支持提现'));
|
||||
}
|
||||
if($user){
|
||||
$is_banke_info = Db::name('receivables')->where('user_id',$user_id)->where('receivables_bank',$recharge_bank)->where('type',2)->find();
|
||||
if(!$is_banke_info){
|
||||
$add_bank = array();
|
||||
$add_bank['user_id'] = $user_id;
|
||||
$add_bank['receivables_name'] = $recharge_name;
|
||||
$add_bank['receivables_bank'] = $recharge_bank;
|
||||
$add_bank['receivables_bank_branch'] = $recharge_bank_branch;
|
||||
$add_bank['receivables_bank_number'] = $recharge_cardnumber;
|
||||
$add_bank['create_time'] = time();
|
||||
$add_bank['status'] = 1;
|
||||
$add_bank['type'] = 2;
|
||||
Db::name('receivables')->insert($add_bank);
|
||||
}
|
||||
if($user['money'] > $recharge_money){
|
||||
$add_record = array();
|
||||
$add_record['user_id'] = $user_id;
|
||||
$add_record['username'] = $user['username'];
|
||||
$add_record['record_type'] = 2;
|
||||
$add_record['recharge_name'] = $recharge_name;
|
||||
$add_record['recharge_bank'] = $recharge_bank;
|
||||
$add_record['recharge_bank_branch'] = $recharge_bank_branch;
|
||||
$add_record['recharge_cardnumber'] = $recharge_cardnumber;
|
||||
$add_record['recharge_money'] = $recharge_money;
|
||||
$add_record['create_time'] = time();
|
||||
$add_record['status'] = 0;
|
||||
$is_add_record = Db::name('receivables_record')->insert($add_record);
|
||||
if($is_add_record){
|
||||
$record_info = array();
|
||||
$record_info['msg'] = '提现成功,请等待管理员放款';
|
||||
$record_info['newMoney'] = $user['money'] - $recharge_money;
|
||||
Db::name('user')->where(array('id' => $user_id))->limit(1)->update(array('money' => $record_info['newMoney']));
|
||||
$data = $record_info;
|
||||
return json(array('Success' => 1, 'Data' => $data));
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '提现失败,请稍后再试'));
|
||||
}
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '您的余额不足'));
|
||||
}
|
||||
}else{
|
||||
return json(array('Success' => 0, 'Msg' => '获取信息失败'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+4425
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller\traits;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
trait happyPay{
|
||||
|
||||
|
||||
public function happy_online_order(){
|
||||
$user_id = intval(Request::instance()->post('user_id'));
|
||||
$money = intval(Request::instance()->post('price'));
|
||||
$client = intval(Request::instance()->post('client'));
|
||||
$username = trim(Request::instance()->post('username'));
|
||||
$pay_type = intval(Request::instance()->post('pay_type'));
|
||||
$user = Db::name('user')->where(array('id' => $user_id, 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$area_list = config('area_list');
|
||||
//判断是否金流支线,如果不是的话,不允许充值
|
||||
$isAllow = false;
|
||||
foreach($area_list[$user['area_id']]['limit_agent'] as $allowAgentId){
|
||||
if(in_array($allowAgentId,$zdlIdArr)){
|
||||
$isAllow = true;
|
||||
}
|
||||
}
|
||||
if(!$isAllow){
|
||||
return json(array('status' => 0, 'message' => '该账号暂不支持在线充值'));
|
||||
}
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl){
|
||||
return json(array('status' => 0, 'message' => '所属代理账号异常,暂不能充值'));
|
||||
}
|
||||
if($zdl['money'] < $money){
|
||||
return json(array('status' => 0, 'message' => '所属代理余额不足,暂不能充值'));
|
||||
}
|
||||
$pay_list = config('pay_list');
|
||||
if($user && $user_id > 0 && $money > 0 && $client > 0){
|
||||
$pay_memberid = "API1362913582567500"; //商户CID
|
||||
$pay_orderid = 'E'.date("YmdHis").rand(100000,999999); //订单号
|
||||
$pay_amount = $money; //交易金额
|
||||
$pay_notifyurl = $pay_list['happyPay']['notify_url']; //服务端返回地址
|
||||
$pay_callbackurl = $pay_list['happyPay']['callback_url']; //页面跳转返回地址
|
||||
$Md5key = "77f4a079992f4e16b0d2cb4dbd1d7f0f"; //密钥
|
||||
$tjurl = "http://khgri4829.com:6084/api/pay/V2"; //提交地址
|
||||
$native = [
|
||||
'version'=>'V2',//版本号
|
||||
'signType'=>'MD5',//签名类型
|
||||
'merchantNo'=>$pay_memberid,//商户号
|
||||
'date'=>date('Ymdhis',time()),//时间戳格式:YYYYMMDDhhmmss
|
||||
'channleType'=>$pay_type,//通道类型
|
||||
'noticeUrl'=>$pay_notifyurl,
|
||||
'orderNo'=>$pay_orderid,
|
||||
'bizAmt'=>$pay_amount,
|
||||
];
|
||||
|
||||
|
||||
ksort($native);
|
||||
$md5str = "";
|
||||
foreach ($native as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
$md5str = trim($md5str,'&');
|
||||
$sign = md5($md5str . $Md5key);
|
||||
$native["sign"] = $sign;
|
||||
|
||||
$postData = http_build_query($native);
|
||||
$options = array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' =>[
|
||||
'Content-type:application/json',
|
||||
'Accept:application/json'
|
||||
],
|
||||
'content' => json_encode($native),
|
||||
'timeout' => 15 * 60 // 超时时间(单位:s)
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($tjurl, false, $context);
|
||||
$returnArray = json_decode($result,true);
|
||||
// print_r($returnArray);die;
|
||||
if(is_array($returnArray) && isset($returnArray['code'])){
|
||||
if($returnArray['code'] == 0){
|
||||
|
||||
if(isset($returnArray['detail']['PayURL'])){
|
||||
$returnUrl = $returnArray['detail']['PayURL'];
|
||||
}else{
|
||||
$parms = base64_encode(encrypt_data(['user_id'=>$user_id,'orderNo'=>$pay_orderid]));
|
||||
$returnUrl = $pay_callbackurl.'?value='.$parms;
|
||||
}
|
||||
$order_record = array();
|
||||
$order_record['pay_channel_id'] = 5;
|
||||
$order_record['pay_channel_name'] = 'happyPay';
|
||||
$order_record['user_id'] = $user_id;
|
||||
$order_record['order_sn'] = $pay_orderid;
|
||||
$order_record['appid'] = $pay_memberid;
|
||||
$order_record['api_key'] = $Md5key;
|
||||
$order_record['money'] = $pay_amount;
|
||||
$order_record['sign'] = $sign;
|
||||
$order_record['create_time'] = time();
|
||||
$order_record['back_order_sn'] = '';
|
||||
$order_record['client'] = $client;
|
||||
|
||||
if(isset($returnArray['detail']['PayHtml'])){
|
||||
$order_record['remake'] = $returnArray['detail']['PayHtml'];
|
||||
}
|
||||
$order_id = Db::name('order_record')->insertGetId($order_record);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 5;
|
||||
$order_log['pay_channel_name'] = 'happyPay';
|
||||
$order_log['money'] = $pay_amount;
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = 'user_id:'.$user_id.',用户名:'.$username.',发起充值:'.$pay_amount.',充值时间:'.date('Y-m-d H:i:s',time());
|
||||
$order_log['order_id'] = $order_id;
|
||||
$order_log['client'] = $client;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
|
||||
return json(array('status' => 1, 'message' => '发起支付成功,即将跳转...', 'url' => $returnUrl));
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => $returnArray['msg']));
|
||||
}
|
||||
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => '支付发起失败,请稍后再试'));
|
||||
}
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => '支付发起失败,请稍后再试'));
|
||||
}
|
||||
}
|
||||
public function happy_call_back_url(){
|
||||
$getData = Request::instance()->get('value');
|
||||
$content = '页面或订单已失效或订单';
|
||||
if(base64_decode($getData)){
|
||||
$data = decrypt_data(['encryptData'=>base64_decode($getData)]);
|
||||
if(isset($data['orderNo']) && isset($data['user_id'])){
|
||||
$orderInfo = Db::name('order_record')->where(['order_sn'=>$data['orderNo'],'user_id'=>$data['user_id']])->find();
|
||||
if($orderInfo){
|
||||
if($orderInfo['status'] == 3){
|
||||
$content = '订单已完成';
|
||||
}else{
|
||||
$content = $orderInfo['remake'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$this->assign('content',$content);
|
||||
return $this->fetch();
|
||||
|
||||
}
|
||||
public function happy_call_back(){
|
||||
$post = Request::instance()->post();
|
||||
$serializeData = json_encode($post);
|
||||
if(!is_array($post) || !isset($post['orderNo']) || !isset($post['bizAmt']) || !isset($post['status']) || !isset($post['sign']) || !isset($post['status'])){
|
||||
Log::record($post,'error_pay_callback');
|
||||
exit();
|
||||
}
|
||||
|
||||
Log::record($post,'callback');
|
||||
|
||||
if($post['status'] != 1){
|
||||
Log::record($post,'fail_pay_callback');
|
||||
exit('SUCCESS');
|
||||
}
|
||||
$order = Db::name('order_record')->where(['order_sn'=>$post['orderNo']])->find();
|
||||
if(!$order){
|
||||
$order_log['pay_channel_id'] = 5;
|
||||
$order_log['pay_channel_name'] = 'happyPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到订单号,回调内容:".$serializeData;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('SUCCESS');//订单不存在,回调失败
|
||||
}
|
||||
$user = Db::name('user')->where(array('id' => $order['user_id'], 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
if(!$user){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '收到回调,无法查询到会员';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log['pay_channel_id'] = 5;
|
||||
$order_log['pay_channel_name'] = 'happyPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到会员信息,会员可能已经删除或者停用,回调内容:".$serializeData;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('SUCCESS');//用户不存在,回调失败
|
||||
}
|
||||
//验证签名
|
||||
$Md5key = "77f4a079992f4e16b0d2cb4dbd1d7f0f"; //密钥
|
||||
$postData = $post;
|
||||
unset($postData['sign']);
|
||||
ksort($postData);
|
||||
$md5str = "";
|
||||
foreach ($postData as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
$md5str = trim($md5str,'&');
|
||||
$sign = md5($md5str . $Md5key);
|
||||
|
||||
if ($sign != $post['sign']) {
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '签名不对,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 5;
|
||||
$order_log['pay_channel_name'] = 'happyPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是签名不对,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('SUCCESS');//签名不对,回调失败
|
||||
}
|
||||
|
||||
//返回金额
|
||||
if(round($post['bizAmt'],2) != $order['money']){
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 5;
|
||||
$order_log['pay_channel_name'] = 'happyPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是金额不对,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('SUCCESS');//金额不对,回调失败
|
||||
}
|
||||
|
||||
//总代理金额
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl || $zdl['money'] < $order['money']){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '无法找到总代理,或者总代理账号余分不足,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 5;
|
||||
$order_log['pay_channel_name'] = 'happyPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "无法找到总代理,或者总代理账号余分不足,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('SUCCESS');//找不到总代理,回调失败
|
||||
}
|
||||
|
||||
|
||||
|
||||
//更新订单表
|
||||
$call_back_data['back_money'] = $post['bizAmt'];
|
||||
$call_back_data['back_sign'] = '';
|
||||
$call_back_data['back_time'] = time();
|
||||
|
||||
$call_back_data['status'] = 3;
|
||||
$call_back_data['agent_parent_id'] = $user['agent_parent_id'];
|
||||
$call_back_data['agent_parent_username'] = $user['agent_parent_username'];
|
||||
$call_back_data['zdl_id'] = $zdl['id'];
|
||||
$call_back_data['zdl_username'] = $zdl['username'];
|
||||
$call_back_data['zdl_money_before'] = $zdl['money'];
|
||||
$call_back_data['zdl_money_after'] = $zdl['money'] - $order['money'];
|
||||
$call_back_data['money_before'] = $user['money'];
|
||||
$call_back_data['money_after'] = $user['money'] + $order['money'];
|
||||
Db::name('order_record')->where(array('id' => $order['id']))->update($call_back_data);
|
||||
|
||||
//记录支付日志
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 5;
|
||||
$order_log['pay_channel_name'] = 'happyPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "回调支付成功";
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
//插入上分表并增加余分
|
||||
$recharge = array();
|
||||
$recharge['type'] = 4;
|
||||
$recharge['amount'] = $order['money'];
|
||||
$recharge['mode'] = 1;
|
||||
$recharge['agent_or_admin'] = 3;
|
||||
$recharge['controller_id'] = $zdl['id'];
|
||||
$recharge['controller_username'] = $zdl['username'];
|
||||
$recharge['controller_nickname'] = $zdl['nickname'];
|
||||
$recharge['controller_type'] = '第三方充值平台充值,扣取总代理余分';
|
||||
$recharge['controller_old_money'] = $zdl['money'];
|
||||
$recharge['controller_new_money'] = $zdl['money'] - $order['money'];
|
||||
$recharge['user_id'] = $order['user_id'];
|
||||
$recharge['user_type'] = $user['agent'];
|
||||
$recharge['user_agent_level'] = 0;
|
||||
$recharge['username_for'] = $user['username'];
|
||||
$recharge['nickname_for'] = $user['nickname'];
|
||||
$recharge['user_parent_id'] = $user['agent_parent_id'];
|
||||
$recharge['create_time'] = time();
|
||||
$recharge['old_money'] = $user['money'];
|
||||
$recharge['new_money'] = $user['money'] + $order['money'];
|
||||
$recharge['controller_system'] = 3;
|
||||
$recharge['remake'] = '第三方充值成功';
|
||||
Db::name('recharge')->insert($recharge);
|
||||
$updateZdl = array();
|
||||
$updateZdl['money'] = $zdl['money'] - $order['money'];
|
||||
$updateZdl['last_recharge_out'] = $order['money'];
|
||||
$updateZdl['last_recharge_out_time'] = time();
|
||||
$updateZdl['recharge_out_count'] = $zdl['recharge_out_count'] + 1;
|
||||
$updateZdl['recharge_out_total_amount'] = $zdl['recharge_out_total_amount'] + $order['money'];
|
||||
$updateUser = array();
|
||||
$updateUser['money'] = $user['money'] + $order['money'];
|
||||
$updateUser['last_recharge'] = $order['money'];
|
||||
$updateUser['last_recharge_time'] = time();
|
||||
$updateUser['recharge_count'] = $user['recharge_count'] + 1;
|
||||
$updateUser['recharge_total_amount'] = $user['recharge_total_amount'] + $order['money'];
|
||||
Db::name('user')->where(array('id' => $zdl['id']))->limit(1)->update($updateZdl);
|
||||
Db::name('user')->where(array('id' => $order['user_id']))->limit(1)->update($updateUser);
|
||||
exit('SUCCESS');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller\traits;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
trait hengfuPay{
|
||||
public function hengfu_online_order(){
|
||||
$user_id = intval(Request::instance()->post('user_id'));
|
||||
$money = intval(Request::instance()->post('price'));
|
||||
$client = intval(Request::instance()->post('client'));
|
||||
$username = trim(Request::instance()->post('username'));
|
||||
$pay_type = intval(Request::instance()->post('pay_type'));
|
||||
$user = Db::name('user')->where(array('id' => $user_id, 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$area_list = config('area_list');
|
||||
//判断是否金流支线,如果不是的话,不允许充值
|
||||
$isAllow = false;
|
||||
foreach($area_list[$user['area_id']]['limit_agent'] as $allowAgentId){
|
||||
if(in_array($allowAgentId,$zdlIdArr)){
|
||||
$isAllow = true;
|
||||
}
|
||||
}
|
||||
if(!$isAllow){
|
||||
return json(array('status' => 0, 'message' => '该账号暂不支持在线充值'));
|
||||
}
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl){
|
||||
return json(array('status' => 0, 'message' => '所属代理账号异常,暂不能充值'));
|
||||
}
|
||||
if($zdl['money'] < $money){
|
||||
return json(array('status' => 0, 'message' => '所属代理余额不足,暂不能充值'));
|
||||
}
|
||||
$pay_list = config('pay_list');
|
||||
if($user && $user_id > 0 && $money > 0 && $client > 0){
|
||||
$sn = '1965312301';
|
||||
$Authorization = 'aE86s4HKxKghfXLOmAPBKMIJymFedk6W99RJe4L9QOOwNvWFlKZgNyqfycP4lXVS';
|
||||
$PaymentType = $pay_type;
|
||||
$VendorSerialNumber = 'E'.date("YmdHis").rand(100000,999999); //订单号
|
||||
$SourceName = $user['username']; //来源名称
|
||||
$TransactionAmount = $money; //交易金额
|
||||
$CallBack = $pay_list['hengfuPay']['notify_url']; //回调返回地址
|
||||
$RedirectUrl = $pay_list['hengfuPay']['callback_url']; //页面跳转返回地址
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => "https://hengfu.cool/api/2.0.0/recharge/order/",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_CUSTOMREQUEST => "POST",
|
||||
CURLOPT_POSTFIELDS => "sn=".$sn."&PaymentType=".$PaymentType."&TransactionAmount=".$TransactionAmount."&VendorSerialNumber=".$VendorSerialNumber."&CallBack=".$CallBack."&RedirectUrl=".$RedirectUrl."&SourceName=".$SourceName,
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
"Authorization: ".$Authorization,
|
||||
"Content-Type: application/x-www-form-urlencoded"
|
||||
),
|
||||
));
|
||||
$response = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
$response = json_decode($response,true);
|
||||
//echo "<pre>";
|
||||
//print_r($response);
|
||||
//echo "</pre>";
|
||||
//exit();
|
||||
if($response['api_status'] == true){
|
||||
$orderUrl = $response['data']['path'];
|
||||
$back_order_sn = $response['data']['serial_number'];
|
||||
//创建订单
|
||||
$order_record = array();
|
||||
$order_record['pay_channel_id'] = 6;
|
||||
$order_record['pay_channel_name'] = 'hengfuPay';
|
||||
$order_record['user_id'] = $user_id;
|
||||
$order_record['order_sn'] = $VendorSerialNumber;
|
||||
$order_record['appid'] = $sn;
|
||||
$order_record['api_key'] = $Authorization;
|
||||
$order_record['money'] = $TransactionAmount;
|
||||
$order_record['create_time'] = time();
|
||||
$order_record['back_order_sn'] = $back_order_sn ;
|
||||
$order_record['client'] = $client;
|
||||
$order_id = Db::name('order_record')->insertGetId($order_record);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 6;
|
||||
$order_log['pay_channel_name'] = 'hengfuPay';
|
||||
$order_log['money'] = $TransactionAmount;
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = 'user_id:'.$user_id.',用户名:'.$username.',发起充值:'.$TransactionAmount.',充值时间:'.date('Y-m-d H:i:s',time());
|
||||
$order_log['order_id'] = $order_id;
|
||||
$order_log['client'] = $client;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
return json(array('status' => 1, 'message' => '发起支付成功,即将跳转...', 'url' => $orderUrl));
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => $response['code']));
|
||||
}
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => '支付发起失败,请稍后再试'));
|
||||
}
|
||||
}
|
||||
public function hengfu_call_back(){
|
||||
if(Request::instance()->isPost()){
|
||||
$serializeData = Request::instance()->post('data');
|
||||
$post = json_decode(Request::instance()->post('data'), true);
|
||||
if(isset($post['Status']) && intval($post['Status']) == 3){
|
||||
$order = Db::name('order_record')->where(['order_sn' => $post['VendorSerialNumber']])->find();
|
||||
if(!$order){
|
||||
//订单不存在,回调失败
|
||||
$order_log['pay_channel_id'] = 6;
|
||||
$order_log['pay_channel_name'] = 'hengfuPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到订单号,回调内容:".$serializeData;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');
|
||||
}
|
||||
$user = Db::name('user')->where(array('id' => $order['user_id'], 'status' => 1, 'is_delete' => 0, 'agent' => 0, 'username' => $post['SourceName']))->find();
|
||||
if(!$user){
|
||||
//用户不存在,回调失败
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '收到回调,无法查询到会员';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log['pay_channel_id'] = 6;
|
||||
$order_log['pay_channel_name'] = 'hengfuPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到会员信息,会员可能已经删除或者停用,回调内容:".$serializeData;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');
|
||||
}
|
||||
//验证签名
|
||||
$Md5key = "WYPJVZInmafDxRFCEc6Nn9Ss8FRG0U2FHaZ4sT8buxx0LCncIz9nM12dokbiJjWr";
|
||||
$postData = $post;
|
||||
unset($postData['Sign']);
|
||||
ksort($postData);
|
||||
$md5str = "";
|
||||
foreach ($postData as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
$sign = md5($md5str . "Key=" . $Md5key);
|
||||
if ($sign != $post['Sign']) {
|
||||
//签名不对,回调失败
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '签名不对,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 6;
|
||||
$order_log['pay_channel_name'] = 'hengfuPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是签名不对,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');
|
||||
}
|
||||
//返回金额
|
||||
if(round($post['TransactionAmount'],2) != $order['money']){
|
||||
//金额不对,回调失败
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 6;
|
||||
$order_log['pay_channel_name'] = 'hengfuPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是金额不对,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('success');
|
||||
}
|
||||
|
||||
//总代理金额
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl || $zdl['money'] < $order['money']){
|
||||
//找不到总代理,回调失败
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '无法找到总代理,或者总代理账号余分不足,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 6;
|
||||
$order_log['pay_channel_name'] = 'hengfuPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "无法找到总代理,或者总代理账号余分不足,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('success');
|
||||
}
|
||||
//更新订单表
|
||||
$call_back_data['back_money'] = $post['TransactionAmount'];
|
||||
$call_back_data['back_sign'] = $post['Sign'];
|
||||
$call_back_data['back_time'] = time();
|
||||
|
||||
$call_back_data['status'] = 3;
|
||||
$call_back_data['agent_parent_id'] = $user['agent_parent_id'];
|
||||
$call_back_data['agent_parent_username'] = $user['agent_parent_username'];
|
||||
$call_back_data['zdl_id'] = $zdl['id'];
|
||||
$call_back_data['zdl_username'] = $zdl['username'];
|
||||
$call_back_data['zdl_money_before'] = $zdl['money'];
|
||||
$call_back_data['zdl_money_after'] = $zdl['money'] - $order['money'];
|
||||
$call_back_data['money_before'] = $user['money'];
|
||||
$call_back_data['money_after'] = $user['money'] + $order['money'];
|
||||
Db::name('order_record')->where(array('id' => $order['id']))->update($call_back_data);
|
||||
|
||||
//记录支付日志
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 6;
|
||||
$order_log['pay_channel_name'] = 'hengfuPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "回调支付成功";
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
//插入上分表并增加余分
|
||||
$recharge = array();
|
||||
$recharge['type'] = 4;
|
||||
$recharge['amount'] = $order['money'];
|
||||
$recharge['mode'] = 1;
|
||||
$recharge['agent_or_admin'] = 3;
|
||||
$recharge['controller_id'] = $zdl['id'];
|
||||
$recharge['controller_username'] = $zdl['username'];
|
||||
$recharge['controller_nickname'] = $zdl['nickname'];
|
||||
$recharge['controller_type'] = '第三方充值平台充值,扣取总代理余分';
|
||||
$recharge['controller_old_money'] = $zdl['money'];
|
||||
$recharge['controller_new_money'] = $zdl['money'] - $order['money'];
|
||||
$recharge['user_id'] = $order['user_id'];
|
||||
$recharge['user_type'] = $user['agent'];
|
||||
$recharge['user_agent_level'] = 0;
|
||||
$recharge['username_for'] = $user['username'];
|
||||
$recharge['nickname_for'] = $user['nickname'];
|
||||
$recharge['user_parent_id'] = $user['agent_parent_id'];
|
||||
$recharge['create_time'] = time();
|
||||
$recharge['old_money'] = $user['money'];
|
||||
$recharge['new_money'] = $user['money'] + $order['money'];
|
||||
$recharge['controller_system'] = 3;
|
||||
$recharge['remake'] = '第三方充值成功';
|
||||
Db::name('recharge')->insert($recharge);
|
||||
$updateZdl = array();
|
||||
$updateZdl['money'] = $zdl['money'] - $order['money'];
|
||||
$updateZdl['last_recharge_out'] = $order['money'];
|
||||
$updateZdl['last_recharge_out_time'] = time();
|
||||
$updateZdl['recharge_out_count'] = $zdl['recharge_out_count'] + 1;
|
||||
$updateZdl['recharge_out_total_amount'] = $zdl['recharge_out_total_amount'] + $order['money'];
|
||||
$updateUser = array();
|
||||
$updateUser['money'] = $user['money'] + $order['money'];
|
||||
$updateUser['last_recharge'] = $order['money'];
|
||||
$updateUser['last_recharge_time'] = time();
|
||||
$updateUser['recharge_count'] = $user['recharge_count'] + 1;
|
||||
$updateUser['recharge_total_amount'] = $user['recharge_total_amount'] + $order['money'];
|
||||
Db::name('user')->where(array('id' => $zdl['id']))->limit(1)->update($updateZdl);
|
||||
Db::name('user')->where(array('id' => $order['user_id']))->limit(1)->update($updateUser);
|
||||
exit('OK');
|
||||
}else{
|
||||
Log::record(Request::instance()->post(),'error_pay_callback');
|
||||
exit('OK');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller\traits;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
|
||||
trait hipPay{
|
||||
|
||||
/**
|
||||
* 创建支付订单和返回支付链接
|
||||
* @return \think\response\Json
|
||||
* DateTime: 2019/12/27 18:42
|
||||
*/
|
||||
public function hip_online_order(){
|
||||
$user_id = intval(Request::instance()->post('user_id'));
|
||||
$money = intval(Request::instance()->post('price'));
|
||||
$client = intval(Request::instance()->post('client'));
|
||||
$username = trim(Request::instance()->post('username'));
|
||||
$user = Db::name('user')->where(array('id' => $user_id, 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
|
||||
$area_list = config('area_list');
|
||||
//判断是否金流支线,如果不是的话,不允许充值
|
||||
$isAllow = false;
|
||||
foreach($area_list[$user['area_id']]['limit_agent'] as $allowAgentId){
|
||||
if(in_array($allowAgentId,$zdlIdArr)){
|
||||
$isAllow = true;
|
||||
}
|
||||
}
|
||||
if(!$isAllow){
|
||||
return json(array('status' => 0, 'message' => '该账号暂不支持在线充值'));
|
||||
}
|
||||
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl){
|
||||
return json(array('status' => 0, 'message' => '所属代理账号异常,暂不能充值'));
|
||||
}
|
||||
if($zdl['money'] < $money){
|
||||
return json(array('status' => 0, 'message' => '所属代理余额不足,暂不能充值'));
|
||||
}
|
||||
$pay_list = config('pay_list');
|
||||
if($user && $user_id > 0 && $money > 0 && $client > 0){
|
||||
$pay_orderid = date("YmdHis").rand(10,99); //订单号
|
||||
$pay_amount = $money; //交易金额
|
||||
$pay_notifyurl = $pay_list['hipPay']['callback_url']; //服务端返回地址
|
||||
$pay_notifyurl_page = $pay_list['hipPay']['notify_url']; //服务端返回地址--页面
|
||||
$tjurl = "http://www.hip168.net/api/getway01/CodeRequest.ashx"; //提交地址
|
||||
$native = [
|
||||
'Merchent'=>'JF',
|
||||
'OrderID'=>$pay_orderid,
|
||||
'Total'=>$pay_amount,
|
||||
'ReAUrl'=>$pay_notifyurl,
|
||||
'ReBUrl'=>$pay_notifyurl_page,
|
||||
'Name'=>$user['username']
|
||||
];
|
||||
$postData = http_build_query($native);
|
||||
$orderUrl = $tjurl.'?'.$postData;
|
||||
//创建订单
|
||||
$order_record = array();
|
||||
$order_record['pay_channel_id'] = 3;
|
||||
$order_record['pay_channel_name'] = 'hipPay';
|
||||
$order_record['user_id'] = $user_id;
|
||||
$order_record['order_sn'] = $pay_orderid;
|
||||
$order_record['appid'] = 0;//不需要
|
||||
$order_record['api_key'] = '';//不需要
|
||||
$order_record['money'] = $pay_amount;
|
||||
$order_record['sign'] = '';//不需要
|
||||
$order_record['create_time'] = time();
|
||||
$order_record['back_order_sn'] = '';
|
||||
$order_record['client'] = $client;
|
||||
$order_id = Db::name('order_record')->insertGetId($order_record);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 3;
|
||||
$order_log['pay_channel_name'] = 'hipPay';
|
||||
$order_log['money'] = $pay_amount;
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = 'user_id:'.$user_id.',用户名:'.$username.',发起充值:'.$pay_amount.',充值时间:'.date('Y-m-d H:i:s',time());
|
||||
$order_log['order_id'] = $order_id;
|
||||
$order_log['client'] = $client;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
return json(array('status' => 1, 'message' => '发起支付成功,即将跳转...', 'url' => $orderUrl));
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => '支付发起失败,请稍后再试'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付码显示页面
|
||||
* @return mixed
|
||||
* @throws \think\Exception
|
||||
* DateTime: 2020/1/10 15:32
|
||||
*/
|
||||
public function hip_call_back_url(){
|
||||
if(Request::instance()->get()){
|
||||
$Ordernum = Request::instance()->get('Ordernum');
|
||||
$StoreCode = Request::instance()->get('StoreCode');
|
||||
$Total = Request::instance()->get('Total');
|
||||
$mobileUrl = Request::instance()->get('mobileUrl');
|
||||
if($Ordernum && $StoreCode && $Total && $mobileUrl){
|
||||
$order = Db::name('order_record')->where(['order_sn'=>$Ordernum,'status'=>0])->find();
|
||||
if($order && $order['money'] == $Total){
|
||||
Db::name('order_record')->where(['id'=>$order['id']])->update(['back_order_sn'=>$StoreCode]);
|
||||
$this->assign('StoreCode',$StoreCode);
|
||||
$this->assign('Total',$Total);
|
||||
$this->assign('mobileUrl',$mobileUrl);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 充值回调
|
||||
* @throws \think\Exception
|
||||
* DateTime: 2019/12/30 13:49
|
||||
*/
|
||||
public function hip_call_back(){
|
||||
$get = Request::instance()->get();
|
||||
$serializeData = json_encode($get);
|
||||
if(getIP() != '203.66.45.226'){
|
||||
Log::record(array_merge($get,['ip'=>getIP()]),'error_pay_callback_illegal_request');//非法请求
|
||||
exit();
|
||||
}
|
||||
|
||||
$Ordernum = Request::instance()->get('Ordernum');
|
||||
$StoreCode = Request::instance()->get('StoreCode');
|
||||
$Status = Request::instance()->get('Status');
|
||||
$Total = Request::instance()->get('Total');
|
||||
|
||||
Log::record(Request::instance()->get(),'callback');
|
||||
if($Status != '0000' || !$StoreCode || !$Ordernum || !$Total){
|
||||
Log::record(Request::instance()->get(),'error_pay_callback');
|
||||
exit();
|
||||
}
|
||||
$order = Db::name('order_record')->where(['order_sn'=>$Ordernum,'back_order_sn'=>$StoreCode])->find();
|
||||
if(!$order){
|
||||
$order_log['pay_channel_id'] = 3;
|
||||
$order_log['pay_channel_name'] = 'hipPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到订单号,回调内容:".$serializeData;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//订单不存在,回调失败
|
||||
}
|
||||
$user = Db::name('user')->where(array('id' => $order['user_id'], 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
if(!$user){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '收到回调,无法查询到会员';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log['pay_channel_id'] = 3;
|
||||
$order_log['pay_channel_name'] = 'hipPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到会员信息,会员可能已经删除或者停用,回调内容:".$serializeData;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//用户不存在,回调失败
|
||||
}
|
||||
|
||||
//返回金额
|
||||
if($Total != $order['money']){
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 3;
|
||||
$order_log['pay_channel_name'] = 'hipPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是金额不对,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//金额不对,回调失败
|
||||
}
|
||||
|
||||
//总代理金额
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl || $zdl['money'] < $order['money']){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '无法找到总代理,或者总代理账号余分不足,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 3;
|
||||
$order_log['pay_channel_name'] = 'hipPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "无法找到总代理,或者总代理账号余分不足,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//找不到总代理,回调失败
|
||||
}
|
||||
|
||||
//更新订单表
|
||||
$call_back_data['back_money'] = $Total;
|
||||
$call_back_data['back_sign'] = '';
|
||||
$call_back_data['back_time'] = time();
|
||||
|
||||
$call_back_data['status'] = 3;
|
||||
$call_back_data['agent_parent_id'] = $user['agent_parent_id'];
|
||||
$call_back_data['agent_parent_username'] = $user['agent_parent_username'];
|
||||
$call_back_data['zdl_id'] = $zdl['id'];
|
||||
$call_back_data['zdl_username'] = $zdl['username'];
|
||||
$call_back_data['zdl_money_before'] = $zdl['money'];
|
||||
$call_back_data['zdl_money_after'] = $zdl['money'] - $order['money'];
|
||||
$call_back_data['money_before'] = $user['money'];
|
||||
$call_back_data['money_after'] = $user['money'] + $order['money'];
|
||||
Db::name('order_record')->where(array('id' => $order['id']))->update($call_back_data);
|
||||
|
||||
//记录支付日志
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 3;
|
||||
$order_log['pay_channel_name'] = 'hipPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "回调支付成功";
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
//插入上分表并增加余分
|
||||
$recharge = array();
|
||||
$recharge['type'] = 4;
|
||||
$recharge['amount'] = $order['money'];
|
||||
$recharge['mode'] = 1;
|
||||
$recharge['agent_or_admin'] = 3;
|
||||
$recharge['controller_id'] = $zdl['id'];
|
||||
$recharge['controller_username'] = $zdl['username'];
|
||||
$recharge['controller_nickname'] = $zdl['nickname'];
|
||||
$recharge['controller_type'] = '第三方充值平台充值,扣取总代理余分';
|
||||
$recharge['controller_old_money'] = $zdl['money'];
|
||||
$recharge['controller_new_money'] = $zdl['money'] - $order['money'];
|
||||
$recharge['user_id'] = $order['user_id'];
|
||||
$recharge['user_type'] = $user['agent'];
|
||||
$recharge['user_agent_level'] = 0;
|
||||
$recharge['username_for'] = $user['username'];
|
||||
$recharge['nickname_for'] = $user['nickname'];
|
||||
$recharge['user_parent_id'] = $user['agent_parent_id'];
|
||||
$recharge['create_time'] = time();
|
||||
$recharge['old_money'] = $user['money'];
|
||||
$recharge['new_money'] = $user['money'] + $order['money'];
|
||||
$recharge['controller_system'] = 3;
|
||||
$recharge['remake'] = '第三方充值成功';
|
||||
Db::name('recharge')->insert($recharge);
|
||||
$updateZdl = array();
|
||||
$updateZdl['money'] = $zdl['money'] - $order['money'];
|
||||
$updateZdl['last_recharge_out'] = $order['money'];
|
||||
$updateZdl['last_recharge_out_time'] = time();
|
||||
$updateZdl['recharge_out_count'] = $zdl['recharge_out_count'] + 1;
|
||||
$updateZdl['recharge_out_total_amount'] = $zdl['recharge_out_total_amount'] + $order['money'];
|
||||
$updateUser = array();
|
||||
$updateUser['money'] = $user['money'] + $order['money'];
|
||||
$updateUser['last_recharge'] = $order['money'];
|
||||
$updateUser['last_recharge_time'] = time();
|
||||
$updateUser['recharge_count'] = $user['recharge_count'] + 1;
|
||||
$updateUser['recharge_total_amount'] = $user['recharge_total_amount'] + $order['money'];
|
||||
Db::name('user')->where(array('id' => $zdl['id']))->limit(1)->update($updateZdl);
|
||||
Db::name('user')->where(array('id' => $order['user_id']))->limit(1)->update($updateUser);
|
||||
exit('OK');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller\traits;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
|
||||
trait oneGoPay{
|
||||
|
||||
/**
|
||||
* 创建支付订单和返回支付链接
|
||||
* @return \think\response\Json
|
||||
* DateTime: 2019/12/27 18:42
|
||||
*/
|
||||
public function ogp_online_order(){
|
||||
$user_id = intval(Request::instance()->post('user_id'));
|
||||
$money = intval(Request::instance()->post('price'));
|
||||
$client = intval(Request::instance()->post('client'));
|
||||
$username = trim(Request::instance()->post('username'));
|
||||
$user = Db::name('user')->where(array('id' => $user_id, 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
|
||||
$area_list = config('area_list');
|
||||
//判断是否金流支线,如果不是的话,不允许充值
|
||||
$isAllow = false;
|
||||
foreach($area_list[$user['area_id']]['limit_agent'] as $allowAgentId){
|
||||
if(in_array($allowAgentId,$zdlIdArr)){
|
||||
$isAllow = true;
|
||||
}
|
||||
}
|
||||
if(!$isAllow){
|
||||
return json(array('status' => 0, 'message' => '该账号暂不支持在线充值'));
|
||||
}
|
||||
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl){
|
||||
return json(array('status' => 0, 'message' => '所属代理账号异常,暂不能充值'));
|
||||
}
|
||||
if($zdl['money'] < $money){
|
||||
return json(array('status' => 0, 'message' => '所属代理余额不足,暂不能充值'));
|
||||
}
|
||||
$pay_list = config('pay_list');
|
||||
if($user && $user_id > 0 && $money > 0 && $client > 0){
|
||||
$pay_orderid = 'E'.date("YmdHis").rand(100000,999999); //订单号
|
||||
$pay_amount = $money; //交易金额
|
||||
$pay_notifyurl = $pay_list['oneGoPay']['notify_url']; //服务端返回地址
|
||||
$api_token = '2I8WenxoXshAyDDJsDE1NkBfYjqTKY4ZUGJB0Y6s2lmSueFRxv4pRXfi5909';//api token
|
||||
$tjurl = "https://www.waterpay88.com/api/transaction"; //提交地址
|
||||
$native = [
|
||||
'amount'=>$pay_amount,
|
||||
'out_trade_no'=>$pay_orderid,
|
||||
'notify_url'=>$pay_notifyurl,
|
||||
];
|
||||
$postData = http_build_query($native);
|
||||
$options = array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' =>[
|
||||
'Content-type:application/json',
|
||||
"Authorization:Bearer $api_token",
|
||||
'Accept:application/json'
|
||||
],
|
||||
'content' => json_encode($native),
|
||||
'timeout' => 15 * 60 // 超时时间(单位:s)
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($tjurl, false, $context);
|
||||
$returnArray = json_decode($result,true);
|
||||
if(is_array($returnArray) && isset($returnArray['uri'])){
|
||||
$order_record = array();
|
||||
$order_record['pay_channel_id'] = 2;
|
||||
$order_record['pay_channel_name'] = 'oneGoPay';
|
||||
$order_record['user_id'] = $user_id;
|
||||
$order_record['order_sn'] = $pay_orderid;
|
||||
$order_record['appid'] = 0;//不需要
|
||||
$order_record['api_key'] = '';//不需要
|
||||
$order_record['money'] = $pay_amount;
|
||||
$order_record['sign'] = '';//不需要
|
||||
$order_record['create_time'] = time();
|
||||
$order_record['back_order_sn'] = $returnArray['trade_no'];
|
||||
$order_record['client'] = $client;
|
||||
$order_id = Db::name('order_record')->insertGetId($order_record);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 2;
|
||||
$order_log['pay_channel_name'] = 'oneGoPay';
|
||||
$order_log['money'] = $pay_amount;
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = 'user_id:'.$user_id.',用户名:'.$username.',发起充值:'.$pay_amount.',充值时间:'.date('Y-m-d H:i:s',time());
|
||||
$order_log['order_id'] = $order_id;
|
||||
$order_log['client'] = $client;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
return json(array('status' => 1, 'message' => '发起支付成功,即将跳转...', 'url' => $returnArray['uri']));
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => '支付发起失败,请稍后再试'));
|
||||
}
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => '支付发起失败,请稍后再试'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 充值回调
|
||||
* @throws \think\Exception
|
||||
* DateTime: 2019/12/30 13:49
|
||||
*/
|
||||
public function ogp_call_back(){
|
||||
$post = Request::instance()->post();
|
||||
$serializePost = json_encode($post);
|
||||
Log::record(Request::instance()->post(),'callback');
|
||||
if(!is_array($post) || !isset($post['status']) || $post['status'] != 'success'){
|
||||
Log::record(Request::instance()->post(),'error_pay_callback');
|
||||
exit();
|
||||
}
|
||||
$order = Db::name('order_record')->where('order_sn',$post['out_trade_no'])->find();
|
||||
if(!$order){
|
||||
$order_log['pay_channel_id'] = 2;
|
||||
$order_log['pay_channel_name'] = 'oneGoPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到订单号,回调内容:".$serializePost;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//订单不存在,回调失败
|
||||
}
|
||||
$user = Db::name('user')->where(array('id' => $order['user_id'], 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
if(!$user){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '收到回调,无法查询到会员';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log['pay_channel_id'] = 2;
|
||||
$order_log['pay_channel_name'] = 'oneGoPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到会员信息,会员可能已经删除或者停用,回调内容:".$serializePost;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//用户不存在,回调失败
|
||||
}
|
||||
|
||||
//返回金额
|
||||
if($post['amount'] != $order['money']){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '支付金额小于订单金额,交易停止';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 2;
|
||||
$order_log['pay_channel_name'] = 'oneGoPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是金额不对,回调内容:".$serializePost;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//金额不对,回调失败
|
||||
}
|
||||
|
||||
//总代理金额
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl || $zdl['money'] < $order['money']){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '无法找到总代理,或者总代理账号余分不足,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 2;
|
||||
$order_log['pay_channel_name'] = 'oneGoPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "无法找到总代理,或者总代理账号余分不足,回调内容:".$serializePost;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//找不到总代理,回调失败
|
||||
}
|
||||
|
||||
//更新订单表
|
||||
$call_back_data['back_money'] = $post['amount'];
|
||||
$call_back_data['back_sign'] = '';
|
||||
$call_back_data['back_time'] = time();
|
||||
|
||||
$call_back_data['status'] = 3;
|
||||
$call_back_data['agent_parent_id'] = $user['agent_parent_id'];
|
||||
$call_back_data['agent_parent_username'] = $user['agent_parent_username'];
|
||||
$call_back_data['zdl_id'] = $zdl['id'];
|
||||
$call_back_data['zdl_username'] = $zdl['username'];
|
||||
$call_back_data['zdl_money_before'] = $zdl['money'];
|
||||
$call_back_data['zdl_money_after'] = $zdl['money'] - $order['money'];
|
||||
$call_back_data['money_before'] = $user['money'];
|
||||
$call_back_data['money_after'] = $user['money'] + $order['money'];
|
||||
Db::name('order_record')->where(array('id' => $order['id']))->update($call_back_data);
|
||||
|
||||
//记录支付日志
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 2;
|
||||
$order_log['pay_channel_name'] = 'oneGoPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "回调支付成功";
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
//插入上分表并增加余分
|
||||
$recharge = array();
|
||||
$recharge['type'] = 4;
|
||||
$recharge['amount'] = $order['money'];
|
||||
$recharge['mode'] = 1;
|
||||
$recharge['agent_or_admin'] = 3;
|
||||
$recharge['controller_id'] = $zdl['id'];
|
||||
$recharge['controller_username'] = $zdl['username'];
|
||||
$recharge['controller_nickname'] = $zdl['nickname'];
|
||||
$recharge['controller_type'] = '第三方充值平台充值,扣取总代理余分';
|
||||
$recharge['controller_old_money'] = $zdl['money'];
|
||||
$recharge['controller_new_money'] = $zdl['money'] - $order['money'];
|
||||
$recharge['user_id'] = $order['user_id'];
|
||||
$recharge['user_type'] = $user['agent'];
|
||||
$recharge['user_agent_level'] = 0;
|
||||
$recharge['username_for'] = $user['username'];
|
||||
$recharge['nickname_for'] = $user['nickname'];
|
||||
$recharge['user_parent_id'] = $user['agent_parent_id'];
|
||||
$recharge['create_time'] = time();
|
||||
$recharge['old_money'] = $user['money'];
|
||||
$recharge['new_money'] = $user['money'] + $order['money'];
|
||||
$recharge['controller_system'] = 3;
|
||||
$recharge['remake'] = '第三方充值成功';
|
||||
Db::name('recharge')->insert($recharge);
|
||||
$updateZdl = array();
|
||||
$updateZdl['money'] = $zdl['money'] - $order['money'];
|
||||
$updateZdl['last_recharge_out'] = $order['money'];
|
||||
$updateZdl['last_recharge_out_time'] = time();
|
||||
$updateZdl['recharge_out_count'] = $zdl['recharge_out_count'] + 1;
|
||||
$updateZdl['recharge_out_total_amount'] = $zdl['recharge_out_total_amount'] + $order['money'];
|
||||
$updateUser = array();
|
||||
$updateUser['money'] = $user['money'] + $order['money'];
|
||||
$updateUser['last_recharge'] = $order['money'];
|
||||
$updateUser['last_recharge_time'] = time();
|
||||
$updateUser['recharge_count'] = $user['recharge_count'] + 1;
|
||||
$updateUser['recharge_total_amount'] = $user['recharge_total_amount'] + $order['money'];
|
||||
Db::name('user')->where(array('id' => $zdl['id']))->limit(1)->update($updateZdl);
|
||||
Db::name('user')->where(array('id' => $order['user_id']))->limit(1)->update($updateUser);
|
||||
exit('OK');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller\traits;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
trait tingPay{
|
||||
|
||||
|
||||
public function ting_online_order(){
|
||||
$user_id = intval(Request::instance()->post('user_id'));
|
||||
$money = intval(Request::instance()->post('price'));
|
||||
$client = intval(Request::instance()->post('client'));
|
||||
$username = trim(Request::instance()->post('username'));
|
||||
$pay_type = intval(Request::instance()->post('pay_type'));
|
||||
$user = Db::name('user')->where(array('id' => $user_id, 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$area_list = config('area_list');
|
||||
//判断是否金流支线,如果不是的话,不允许充值
|
||||
$isAllow = false;
|
||||
foreach($area_list[$user['area_id']]['limit_agent'] as $allowAgentId){
|
||||
if(in_array($allowAgentId,$zdlIdArr)){
|
||||
$isAllow = true;
|
||||
}
|
||||
}
|
||||
if(!$isAllow){
|
||||
return json(array('status' => 0, 'message' => '该账号暂不支持在线充值'));
|
||||
}
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl){
|
||||
return json(array('status' => 0, 'message' => '所属代理账号异常,暂不能充值'));
|
||||
}
|
||||
if($zdl['money'] < $money){
|
||||
return json(array('status' => 0, 'message' => '所属代理余额不足,暂不能充值'));
|
||||
}
|
||||
$pay_list = config('pay_list');
|
||||
if($user && $user_id > 0 && $money > 0 && $client > 0){
|
||||
$pay_memberid = "3359"; //商户CID
|
||||
$pay_orderid = 'E'.date("YmdHis").rand(100000,999999); //订单号
|
||||
$pay_amount = $money; //交易金额
|
||||
$pay_notifyurl = $pay_list['tingPay']['notify_url']; //服务端返回地址
|
||||
$pay_callbackurl = $pay_list['tingPay']['callback_url']; //页面跳转返回地址
|
||||
$Md5key = "n7cznODIaFsY75BS1FLidCKaHAoKWtKHn5gSoQqnokNMzLtacFeyZ1Z9elkXHGXy"; //密钥
|
||||
$tjurl = "https://www.istmys.com/tingapi/jump"; //提交地址
|
||||
$native = [
|
||||
'merid' => $pay_memberid,//商户CID
|
||||
'amount' => $pay_amount,//充值金额
|
||||
'orderid' => $pay_orderid,//订单号
|
||||
'userid'=>$user_id,//会员ID
|
||||
'userip' => getIP(),//用户IP
|
||||
//'pay_type'=>$pay_type,//支付方式
|
||||
//'paytype'=> 'qrcode',
|
||||
//'bankflag'=> 'ALIPAY',
|
||||
'notifyurl' => $pay_notifyurl,//回调地址
|
||||
'syncurl' => $pay_callbackurl,//跳转地址
|
||||
];
|
||||
|
||||
ksort($native);
|
||||
$md5str = "";
|
||||
foreach ($native as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
$sign = md5($md5str . "key=" . $Md5key);
|
||||
$native["sign"] = $sign;
|
||||
|
||||
$postData = http_build_query($native);
|
||||
$orderUrl = $tjurl.'?'.$postData;
|
||||
//创建订单
|
||||
$order_record = array();
|
||||
$order_record['pay_channel_id'] = 4;
|
||||
$order_record['pay_channel_name'] = 'tingPay';
|
||||
$order_record['user_id'] = $user_id;
|
||||
$order_record['order_sn'] = $pay_orderid;
|
||||
$order_record['appid'] = $pay_memberid;
|
||||
// $order_record['api_key'] = $Md5key;
|
||||
$order_record['api_key'] = '';//超出超度无法保存sql
|
||||
$order_record['money'] = $pay_amount;
|
||||
// $order_record['sign'] = $sign;
|
||||
$order_record['sign'] = '';//超出超度无法保存sql
|
||||
$order_record['create_time'] = time();
|
||||
$order_record['back_order_sn'] = '';
|
||||
$order_record['client'] = $client;
|
||||
$order_id = Db::name('order_record')->insertGetId($order_record);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 4;
|
||||
$order_log['pay_channel_name'] = 'tingPay';
|
||||
$order_log['money'] = $pay_amount;
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = 'user_id:'.$user_id.',用户名:'.$username.',发起充值:'.$pay_amount.',充值时间:'.date('Y-m-d H:i:s',time());
|
||||
$order_log['order_id'] = $order_id;
|
||||
$order_log['client'] = $client;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
return json(array('status' => 1, 'message' => '发起支付成功,即将跳转...', 'url' => $orderUrl));
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => '支付发起失败,请稍后再试'));
|
||||
}
|
||||
}
|
||||
public function ting_call_back_url(){
|
||||
Log::record(Request::instance()->post(),'callback');
|
||||
exit();
|
||||
}
|
||||
public function ting_call_back(){
|
||||
// $serializeData = Request::instance()->post();
|
||||
// $post = json_decode($serializeData);
|
||||
$post = Request::instance()->post();
|
||||
$serializeData = json_encode($post);
|
||||
if(!is_array($post) || !isset($post['merid']) || !isset($post['userid']) || !isset($post['amount']) || !isset($post['orderid']) || !isset($post['sign']) || !isset($post['status'])){
|
||||
Log::record($post,'error_pay_callback');
|
||||
exit();
|
||||
}
|
||||
|
||||
Log::record($post,'callback');
|
||||
|
||||
if($post['status'] != 'verified'){
|
||||
Log::record($post,'fail_pay_callback');
|
||||
exit();
|
||||
}
|
||||
$order = Db::name('order_record')->where(['order_sn'=>$post['orderid'],'user_id'=>$post['userid']])->find();
|
||||
if(!$order){
|
||||
$order_log['pay_channel_id'] = 4;
|
||||
$order_log['pay_channel_name'] = 'tingPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到订单号,回调内容:".$serializeData;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//订单不存在,回调失败
|
||||
}
|
||||
$user = Db::name('user')->where(array('id' => $order['user_id'], 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
if(!$user){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '收到回调,无法查询到会员';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log['pay_channel_id'] = 4;
|
||||
$order_log['pay_channel_name'] = 'tingPay';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到会员信息,会员可能已经删除或者停用,回调内容:".$serializeData;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//用户不存在,回调失败
|
||||
}
|
||||
//验证签名
|
||||
$Md5key = "n7cznODIaFsY75BS1FLidCKaHAoKWtKHn5gSoQqnokNMzLtacFeyZ1Z9elkXHGXy"; //密钥
|
||||
$postData = $post;
|
||||
unset($postData['sign']);
|
||||
ksort($postData);
|
||||
$md5str = "";
|
||||
foreach ($postData as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
$sign = md5($md5str . "key=" . $Md5key);
|
||||
|
||||
if ($sign != $post['sign']) {
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '签名不对,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 4;
|
||||
$order_log['pay_channel_name'] = 'tingPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是签名不对,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('success');//签名不对,回调失败
|
||||
}
|
||||
|
||||
//返回金额
|
||||
if(round($post['amount'],2) != $order['money']){
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 4;
|
||||
$order_log['pay_channel_name'] = 'tingPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是金额不对,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('success');//金额不对,回调失败
|
||||
}
|
||||
|
||||
//总代理金额
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl || $zdl['money'] < $order['money']){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '无法找到总代理,或者总代理账号余分不足,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 4;
|
||||
$order_log['pay_channel_name'] = 'tingPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "无法找到总代理,或者总代理账号余分不足,回调内容:".$serializeData;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('success');//找不到总代理,回调失败
|
||||
}
|
||||
|
||||
|
||||
|
||||
//更新订单表
|
||||
$call_back_data['back_money'] = $post['amount'];
|
||||
$call_back_data['back_sign'] = '';
|
||||
$call_back_data['back_time'] = time();
|
||||
|
||||
$call_back_data['status'] = 3;
|
||||
$call_back_data['agent_parent_id'] = $user['agent_parent_id'];
|
||||
$call_back_data['agent_parent_username'] = $user['agent_parent_username'];
|
||||
$call_back_data['zdl_id'] = $zdl['id'];
|
||||
$call_back_data['zdl_username'] = $zdl['username'];
|
||||
$call_back_data['zdl_money_before'] = $zdl['money'];
|
||||
$call_back_data['zdl_money_after'] = $zdl['money'] - $order['money'];
|
||||
$call_back_data['money_before'] = $user['money'];
|
||||
$call_back_data['money_after'] = $user['money'] + $order['money'];
|
||||
Db::name('order_record')->where(array('id' => $order['id']))->update($call_back_data);
|
||||
|
||||
//记录支付日志
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 4;
|
||||
$order_log['pay_channel_name'] = 'tingPay';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "回调支付成功";
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
//插入上分表并增加余分
|
||||
$recharge = array();
|
||||
$recharge['type'] = 4;
|
||||
$recharge['amount'] = $order['money'];
|
||||
$recharge['mode'] = 1;
|
||||
$recharge['agent_or_admin'] = 3;
|
||||
$recharge['controller_id'] = $zdl['id'];
|
||||
$recharge['controller_username'] = $zdl['username'];
|
||||
$recharge['controller_nickname'] = $zdl['nickname'];
|
||||
$recharge['controller_type'] = '第三方充值平台充值,扣取总代理余分';
|
||||
$recharge['controller_old_money'] = $zdl['money'];
|
||||
$recharge['controller_new_money'] = $zdl['money'] - $order['money'];
|
||||
$recharge['user_id'] = $order['user_id'];
|
||||
$recharge['user_type'] = $user['agent'];
|
||||
$recharge['user_agent_level'] = 0;
|
||||
$recharge['username_for'] = $user['username'];
|
||||
$recharge['nickname_for'] = $user['nickname'];
|
||||
$recharge['user_parent_id'] = $user['agent_parent_id'];
|
||||
$recharge['create_time'] = time();
|
||||
$recharge['old_money'] = $user['money'];
|
||||
$recharge['new_money'] = $user['money'] + $order['money'];
|
||||
$recharge['controller_system'] = 3;
|
||||
$recharge['remake'] = '第三方充值成功';
|
||||
Db::name('recharge')->insert($recharge);
|
||||
$updateZdl = array();
|
||||
$updateZdl['money'] = $zdl['money'] - $order['money'];
|
||||
$updateZdl['last_recharge_out'] = $order['money'];
|
||||
$updateZdl['last_recharge_out_time'] = time();
|
||||
$updateZdl['recharge_out_count'] = $zdl['recharge_out_count'] + 1;
|
||||
$updateZdl['recharge_out_total_amount'] = $zdl['recharge_out_total_amount'] + $order['money'];
|
||||
$updateUser = array();
|
||||
$updateUser['money'] = $user['money'] + $order['money'];
|
||||
$updateUser['last_recharge'] = $order['money'];
|
||||
$updateUser['last_recharge_time'] = time();
|
||||
$updateUser['recharge_count'] = $user['recharge_count'] + 1;
|
||||
$updateUser['recharge_total_amount'] = $user['recharge_total_amount'] + $order['money'];
|
||||
Db::name('user')->where(array('id' => $zdl['id']))->limit(1)->update($updateZdl);
|
||||
Db::name('user')->where(array('id' => $order['user_id']))->limit(1)->update($updateUser);
|
||||
exit('success');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
namespace app\onlinechip\controller\traits;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
trait yonghengPay{
|
||||
|
||||
|
||||
public function online_order(){
|
||||
$user_id = intval(Request::instance()->post('user_id'));
|
||||
$money = intval(Request::instance()->post('price'));
|
||||
$client = intval(Request::instance()->post('client'));
|
||||
$username = trim(Request::instance()->post('username'));
|
||||
$pay_type = intval(Request::instance()->post('pay_type'));
|
||||
$user = Db::name('user')->where(array('id' => $user_id, 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$area_list = config('area_list');
|
||||
//判断是否金流支线,如果不是的话,不允许充值
|
||||
$isAllow = false;
|
||||
foreach($area_list[$user['area_id']]['limit_agent'] as $allowAgentId){
|
||||
if(in_array($allowAgentId,$zdlIdArr)){
|
||||
$isAllow = true;
|
||||
}
|
||||
}
|
||||
if(!$isAllow){
|
||||
return json(array('status' => 0, 'message' => '该账号暂不支持在线充值'));
|
||||
}
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl){
|
||||
return json(array('status' => 0, 'message' => '所属代理账号异常,暂不能充值'));
|
||||
}
|
||||
if($zdl['money'] < $money){
|
||||
return json(array('status' => 0, 'message' => '所属代理余额不足,暂不能充值'));
|
||||
}
|
||||
$pay_list = config('pay_list');
|
||||
if($user && $user_id > 0 && $money > 0 && $client > 0){
|
||||
$pay_memberid = "11319"; //商户ID
|
||||
$pay_orderid = 'E'.date("YmdHis").rand(100000,999999); //订单号
|
||||
$pay_amount = $money; //交易金额
|
||||
$pay_applydate = date("Y-m-d H:i:s"); //订单时间
|
||||
$pay_notifyurl = $pay_list['yongheng']['notify_url']; //服务端返回地址
|
||||
$pay_callbackurl = $pay_list['yongheng']['callback_url']; //页面跳转返回地址
|
||||
$Md5key = "yfhjiq5rkdmx4xh3egt0f4hkay574wal"; //密钥
|
||||
$tjurl = "https://www.aa168zf.com/Pay_Index.html"; //提交地址
|
||||
$pay_bankcode = $pay_type; //银行编码
|
||||
$native = array(
|
||||
"pay_memberid" => $pay_memberid,
|
||||
"pay_orderid" => $pay_orderid,
|
||||
"pay_amount" => $pay_amount,
|
||||
"pay_applydate" => $pay_applydate,
|
||||
"pay_bankcode" => $pay_bankcode,
|
||||
"pay_notifyurl" => $pay_notifyurl,
|
||||
"pay_callbackurl" => $pay_callbackurl,
|
||||
);
|
||||
ksort($native);
|
||||
$md5str = "";
|
||||
foreach ($native as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
//echo($md5str . "key=" . $Md5key);
|
||||
$sign = strtoupper(md5($md5str . "key=" . $Md5key));
|
||||
$native["pay_md5sign"] = $sign;
|
||||
$native['pay_attach'] = "1234|456";
|
||||
$native['pay_productname'] = 'VIP基础服务';
|
||||
$native['format'] = 'json';
|
||||
$postdata = http_build_query($native);
|
||||
$options = array(
|
||||
'http' => array(
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type:application/x-www-form-urlencoded',
|
||||
'content' => $postdata,
|
||||
'timeout' => 15 * 60 // 超时时间(单位:s)
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($options);
|
||||
$result = file_get_contents($tjurl, false, $context);
|
||||
$returnArray = json_decode($result,true);
|
||||
//echo "<pre>";
|
||||
//print_r($returnArray);
|
||||
//echo "</pre>";
|
||||
//exit();
|
||||
$data = $returnArray['data'];
|
||||
if($returnArray['status'] == 'ok'){
|
||||
$order_record = array();
|
||||
$order_record['pay_channel_id'] = 1;
|
||||
$order_record['pay_channel_name'] = '永恒168';
|
||||
$order_record['user_id'] = $user_id;
|
||||
$order_record['order_sn'] = $data['orderid'];
|
||||
$order_record['appid'] = $pay_memberid;
|
||||
$order_record['api_key'] = $Md5key;
|
||||
$order_record['money'] = $pay_amount;
|
||||
$order_record['sign'] = $sign;
|
||||
$order_record['create_time'] = time();
|
||||
$order_record['back_order_sn'] = $data['transaction_id'];
|
||||
$order_record['client'] = $client;
|
||||
$order_id = Db::name('order_record')->insertGetId($order_record);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['money'] = $pay_amount;
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = 'user_id:'.$user_id.',用户名:'.$username.',发起充值:'.$pay_amount.',充值时间:'.date('Y-m-d H:i:s',time());
|
||||
$order_log['order_id'] = $order_id;
|
||||
$order_log['client'] = $client;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
return json(array('status' => 1, 'message' => '发起支付成功,即将跳转...', 'url' => $returnArray['data']['pay_url']));
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => $returnArray['msg']));
|
||||
}
|
||||
}else{
|
||||
return json(array('status' => 0, 'message' => '支付发起失败,请稍后再试'));
|
||||
}
|
||||
}
|
||||
public function call_back_url(){
|
||||
Log::record(Request::instance()->post(),'callback');
|
||||
exit();
|
||||
}
|
||||
public function call_back(){
|
||||
$post = Request::instance()->post();
|
||||
$serializePost = json_encode($post);
|
||||
Log::record(Request::instance()->post(),'callback');
|
||||
$update = array();
|
||||
$memberid = Request::instance()->post("memberid"); // 商户ID
|
||||
$orderid = Request::instance()->post("orderid"); // 订单号
|
||||
$amount = Request::instance()->post("amount"); // 交易金额
|
||||
$datetime = Request::instance()->post("datetime"); // 交易时间
|
||||
$transaction_id = Request::instance()->post("transaction_id"); // 支付流水号
|
||||
$returncode = Request::instance()->post("returncode"); // 支付成功代码
|
||||
$callBackSign = Request::instance()->post("sign"); // 返回签名
|
||||
$returnArray = array(
|
||||
"memberid" => $memberid,
|
||||
"orderid" => $orderid,
|
||||
"amount" => $amount,
|
||||
"datetime" => $datetime,
|
||||
"transaction_id" => $transaction_id,
|
||||
"returncode" => $returncode,
|
||||
);
|
||||
$md5key = "yfhjiq5rkdmx4xh3egt0f4hkay574wal";
|
||||
ksort($returnArray);
|
||||
reset($returnArray);
|
||||
$md5str = "";
|
||||
foreach ($returnArray as $key => $val) {
|
||||
$md5str = $md5str . $key . "=" . $val . "&";
|
||||
}
|
||||
$sign = strtoupper(md5($md5str . "key=" . $md5key));
|
||||
$order = Db::name('order_record')->where('order_sn',$returnArray['orderid'])->find();
|
||||
if(!$order){
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到订单号,回调内容:".$serializePost;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//订单不存在,回调失败
|
||||
}
|
||||
$user = Db::name('user')->where(array('id' => $order['user_id'], 'status' => 1, 'is_delete' => 0, 'agent' => 0))->find();
|
||||
if(!$user){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '收到回调,无法查询到会员';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是查询不到会员信息,会员可能已经删除或者停用,回调内容:".$serializePost;
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//用户不存在,回调失败
|
||||
}
|
||||
if($order['status'] == 3){
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但订单已经支付完成".$serializePost;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//用户订单已经支付完成
|
||||
}
|
||||
//签名
|
||||
if ($sign != $callBackSign) {
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '签名不对,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是签名不对,回调内容:".$serializePost;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//签名不对,回调失败
|
||||
}
|
||||
//状态
|
||||
if ($returncode != "00") {
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '支付不成功'.$returncode;
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,支付不成功,回调内容:".$serializePost;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//支付状态不对,回调失败
|
||||
}
|
||||
//返回金额
|
||||
if($amount != $order['money']){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '支付金额小于订单金额,交易停止';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "收到回调,但是金额不对,回调内容:".$serializePost;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//金额不对,回调失败
|
||||
}
|
||||
//总代理金额
|
||||
$zdlIdArr = explode(',',$user['agent_parent_id_path']);
|
||||
$zdlId = $zdlIdArr[0];
|
||||
$zdl = Db::name('user')->where(array('id' => $zdlId, 'status' => 1, 'is_delete' => 0, 'agent' => 1))->find();
|
||||
if(!$zdl || $zdl['money'] < $order['money']){
|
||||
$update['status'] = 1;
|
||||
$update['remake'] = '无法找到总代理,或者总代理账号余分不足,交易暂停';
|
||||
Db::name('order_record')->where('id',$order['id'])->update($update);
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "无法找到总代理,或者总代理账号余分不足,回调内容:".$serializePost;
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
exit('OK');//找不到总代理,回调失败
|
||||
}
|
||||
|
||||
$call_back_data = array();
|
||||
//更新订单表
|
||||
$call_back_data['back_money'] = $amount;
|
||||
$call_back_data['back_sign'] = $callBackSign;
|
||||
$call_back_data['back_time'] = time();
|
||||
|
||||
$call_back_data['status'] = 3;
|
||||
$call_back_data['agent_parent_id'] = $user['agent_parent_id'];
|
||||
$call_back_data['agent_parent_username'] = $user['agent_parent_username'];
|
||||
$call_back_data['zdl_id'] = $zdl['id'];
|
||||
$call_back_data['zdl_username'] = $zdl['username'];
|
||||
$call_back_data['zdl_money_before'] = $zdl['money'];
|
||||
$call_back_data['zdl_money_after'] = $zdl['money'] - $order['money'];
|
||||
$call_back_data['money_before'] = $user['money'];
|
||||
$call_back_data['money_after'] = $user['money'] + $order['money'];
|
||||
Db::name('order_record')->where(array('id' => $order['id']))->update($call_back_data);
|
||||
|
||||
//记录支付日志
|
||||
$order_log = array();
|
||||
$order_log['pay_channel_id'] = 1;
|
||||
$order_log['pay_channel_name'] = '永恒168';
|
||||
$order_log['money'] = $order['money'];
|
||||
$order_log['create_time'] = time();
|
||||
$order_log['remake'] = "回调支付成功";
|
||||
$order_log['order_id'] = $order['id'];
|
||||
Db::name('order_log')->insert($order_log);
|
||||
//插入上分表并增加余分
|
||||
$recharge = array();
|
||||
$recharge['type'] = 4;
|
||||
$recharge['amount'] = $order['money'];
|
||||
$recharge['mode'] = 1;
|
||||
$recharge['agent_or_admin'] = 3;
|
||||
$recharge['controller_id'] = $zdl['id'];
|
||||
$recharge['controller_username'] = $zdl['username'];
|
||||
$recharge['controller_nickname'] = $zdl['nickname'];
|
||||
$recharge['controller_type'] = '第三方充值平台充值,扣取总代理余分';
|
||||
$recharge['controller_old_money'] = $zdl['money'];
|
||||
$recharge['controller_new_money'] = $zdl['money'] - $order['money'];
|
||||
$recharge['user_id'] = $order['user_id'];
|
||||
$recharge['user_type'] = $user['agent'];
|
||||
$recharge['user_agent_level'] = 0;
|
||||
$recharge['username_for'] = $user['username'];
|
||||
$recharge['nickname_for'] = $user['nickname'];
|
||||
$recharge['user_parent_id'] = $user['agent_parent_id'];
|
||||
$recharge['create_time'] = time();
|
||||
$recharge['old_money'] = $user['money'];
|
||||
$recharge['new_money'] = $user['money'] + $order['money'];
|
||||
$recharge['controller_system'] = 3;
|
||||
$recharge['remake'] = '第三方充值成功';
|
||||
Db::name('recharge')->insert($recharge);
|
||||
$updateZdl = array();
|
||||
$updateZdl['money'] = $zdl['money'] - $order['money'];
|
||||
$updateZdl['last_recharge_out'] = $order['money'];
|
||||
$updateZdl['last_recharge_out_time'] = time();
|
||||
$updateZdl['recharge_out_count'] = $zdl['recharge_out_count'] + 1;
|
||||
$updateZdl['recharge_out_total_amount'] = $zdl['recharge_out_total_amount'] + $order['money'];
|
||||
$updateUser = array();
|
||||
$updateUser['money'] = $user['money'] + $order['money'];
|
||||
$updateUser['last_recharge'] = $order['money'];
|
||||
$updateUser['last_recharge_time'] = time();
|
||||
$updateUser['recharge_count'] = $user['recharge_count'] + 1;
|
||||
$updateUser['recharge_total_amount'] = $user['recharge_total_amount'] + $order['money'];
|
||||
Db::name('user')->where(array('id' => $zdl['id']))->limit(1)->update($updateZdl);
|
||||
Db::name('user')->where(array('id' => $order['user_id']))->limit(1)->update($updateUser);
|
||||
exit('OK');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user