260 lines
6.8 KiB
PHP
260 lines
6.8 KiB
PHP
<?php
|
|
|
|
namespace app\gateway\controller\v4;
|
|
|
|
use app\channel\service\CardService;
|
|
use app\gateway\controller\v4\Core;
|
|
|
|
/**
|
|
* 接口处理
|
|
* Class Handle
|
|
* @package app\gateway\api
|
|
*/
|
|
class Card extends Core
|
|
{
|
|
# 是否检测数据
|
|
protected $check = true;
|
|
|
|
# 查询接口 一般用于查询数据,同步执行
|
|
public function query(): void
|
|
{
|
|
$settingStatus = sysconf('settingStatus');
|
|
if ($settingStatus == 1) {
|
|
$this->no(-1000);
|
|
}
|
|
$this->checkOpenTime(sysconf('settingOpenTime'));
|
|
|
|
if (isset($this->merchant['opentime']) && $this->merchant['opentime']) {
|
|
$this->checkOpenTime($this->merchant['opentime']);
|
|
}
|
|
$data = $this->channel($this->mid, $this->product, false);
|
|
$this->yes($data);
|
|
}
|
|
|
|
# 提交接口 一般用于提交数据,异步执行
|
|
public function submit(): void
|
|
{
|
|
|
|
$settingStatus = sysconf('settingStatus');
|
|
if ($settingStatus == 1) {
|
|
$this->no(-1000);
|
|
}
|
|
$this->checkOpenTime(sysconf('settingOpenTime'));
|
|
|
|
if (isset($this->merchant['opentime']) && $this->merchant['opentime']) {
|
|
$this->checkOpenTime($this->merchant['opentime']);
|
|
}
|
|
$data = $this->channel($this->mid, $this->product, true);
|
|
$this->yes($data);
|
|
}
|
|
|
|
# 提交接口 一般用于提交数据,异步执行
|
|
public function dc_submit(): void
|
|
{
|
|
$this->submit();
|
|
}
|
|
|
|
# 查询订单接口
|
|
public function order(): void
|
|
{
|
|
$order = input('order_id');
|
|
$merchant_order = input('merchant_order_id');
|
|
if (!$order && !$merchant_order) {
|
|
$this->no(-100);
|
|
}
|
|
$data = $this->getOrder($order, $merchant_order);
|
|
if (!$data) {
|
|
$this->no(-101);
|
|
}
|
|
$result['cash'] = $data['cash'];
|
|
$result['order_id'] = $data['order_id'];
|
|
$result['merchant_order_id'] = $data['merchant_order_id'];
|
|
|
|
|
|
if ($data['status'] < 0) {
|
|
$data['status'] = 1;
|
|
}
|
|
$result['status'] = $data['status'];
|
|
|
|
if (!$data['channel_callback_msg']) {
|
|
$data['channel_callback_msg'] = '{}';
|
|
}
|
|
$request = json_decode($data['channel_callback_msg'], true);
|
|
|
|
$number = '';
|
|
if (isset($request['s_number']) && $request['s_number']) {
|
|
$result['s_number'] = $request['s_number'];
|
|
} elseif (isset($request['s_number']) && $request['s_number']) {
|
|
$result['s_number'] = $request['s_number'];
|
|
}
|
|
|
|
$order_name = sysconf('order_name');
|
|
if ($number && $order_name) {
|
|
$result[$order_name] = $number;
|
|
} elseif ($number) {
|
|
$result['s_number'] = $number;
|
|
}
|
|
|
|
$this->yes($result);
|
|
}
|
|
|
|
# 查询账户接口
|
|
public function account(): void
|
|
{
|
|
$data = $this->merchant;
|
|
$result['name'] = $data['name'];
|
|
$result['account'] = $data['account_surplus'];
|
|
$result['credit'] = $data['credit_surplus'];
|
|
$result['appid'] = $data['appid'];
|
|
$this->yes($result);
|
|
}
|
|
|
|
# 根据日期查询账户数据
|
|
public function accountByDay(): void
|
|
{
|
|
$this->merchantLogService = \app\merchant\service\MerchantLogService::instance();
|
|
$orderService = \app\merchant\service\OrderService::instance();
|
|
$data = $this->merchant;
|
|
|
|
$day = input('day');
|
|
if (!$day) {
|
|
$day = date('Y-m-d', strtotime('-1 day'));
|
|
}
|
|
$begin = $day . ' 00:00:00';
|
|
$after = $day . ' 23:59:59';
|
|
$time = [$begin, $after];
|
|
|
|
# 获取昨天
|
|
$yday = $day . ' 00:00:00';
|
|
$yday = $this->maketime($yday);
|
|
$yday = date('Y-m-d', strtotime('-1 day', $yday));
|
|
|
|
$begin = $yday . ' 00:00:00';
|
|
$after = $yday . ' 23:59:59';
|
|
$stime = [$begin, $after];
|
|
|
|
|
|
$where['mid'] = $data['id'];
|
|
|
|
# 加款
|
|
$where['type'] = 1;
|
|
$chongzhi = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$where['type'] = 2;
|
|
$jianshao = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$add = round($chongzhi - $jianshao, 2);
|
|
|
|
# 冻结
|
|
$dong = $orderService->getDong($where['mid'], $time);
|
|
|
|
$result['name'] = $data['name'];
|
|
$result['account'] = $this->merchant_yue($where['mid'], $time);
|
|
$yaccount = $this->merchant_yue($where['mid'], $stime);
|
|
$result['dong'] = $dong;
|
|
$result['add'] = $add;
|
|
|
|
$where['type'] = 3;
|
|
$kou = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$where['type'] = 4;
|
|
$huifu = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$kou -= $huifu;
|
|
|
|
$result['zhang'] = round($yaccount + $result['add'] - $kou, 2);
|
|
|
|
$this->yes($result);
|
|
}
|
|
|
|
# 计算商户的的一天的余额
|
|
private function merchant_yue($mid, $time): float
|
|
{
|
|
$time[0] = '2020-01-01 00:00:00';
|
|
$where['mid'] = $mid;
|
|
$where['account_type'] = 1;
|
|
$where['oper'] = 1;
|
|
$shouru = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$where['oper'] = 2;
|
|
$zhichu = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$yue = round($shouru - $zhichu, 2);
|
|
|
|
unset($where['oper']);
|
|
$where['account_type'] = 2;
|
|
$where['type'] = 3;
|
|
$kou = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$where['type'] = 4;
|
|
$huifu = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$where['type'] = 1;
|
|
$zonghuikuan = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$where['type'] = 2;
|
|
$zonghuifu = $this->merchantLogService->getDb($where, $time);
|
|
|
|
$zonghuikuan -= $zonghuifu;
|
|
|
|
$hui = round($kou - $huifu - $zonghuikuan, 2);
|
|
|
|
return $yue - $hui;
|
|
}
|
|
|
|
protected function maketime($v): float|false|int|string
|
|
{
|
|
if (!$v) {
|
|
return '';
|
|
}
|
|
|
|
if (is_numeric($v)) {
|
|
return $v;
|
|
}
|
|
|
|
if (is_array($v)) {
|
|
$v = $v[1];
|
|
}
|
|
|
|
if (strstr($v, ' ')) {
|
|
$t = explode(' ', $v);
|
|
$v = $t[0];
|
|
$s = explode(':', $t[1]);
|
|
} else {
|
|
$s = array(0, 0, 0);
|
|
}
|
|
|
|
if (!isset($s[1])) {
|
|
$s[1] = 0;
|
|
}
|
|
|
|
if (!isset($s[2])) {
|
|
$s[2] = 0;
|
|
}
|
|
|
|
if (strstr($v, '-')) {
|
|
$t = explode('-', $v);
|
|
} elseif (strstr($v, '/')) {
|
|
$u = explode('/', $v);
|
|
$t[0] = $u[2];
|
|
$t[1] = $u[0];
|
|
$t[2] = $u[1];
|
|
}
|
|
|
|
if (!isset($t)) {
|
|
$t = array(0, 0, 0);
|
|
}
|
|
|
|
if (!isset($t[1])) {
|
|
$t[1] = 0;
|
|
}
|
|
|
|
if (!isset($t[2])) {
|
|
$t[2] = 0;
|
|
}
|
|
|
|
$v = mktime($s[0], $s[1], $s[2], $t[1], $t[2], $t[0]);
|
|
|
|
return $v;
|
|
}
|
|
} |