1589 lines
53 KiB
PHP
1589 lines
53 KiB
PHP
<?php
|
||
|
||
// +----------------------------------------------------------------------
|
||
// | ThinkAdmin
|
||
// +----------------------------------------------------------------------
|
||
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||
// +----------------------------------------------------------------------
|
||
// | 官方网站: https://thinkadmin.top
|
||
// +----------------------------------------------------------------------
|
||
// | 开源协议 ( https://mit-license.org )
|
||
// +----------------------------------------------------------------------
|
||
// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
|
||
// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\order\controller;
|
||
|
||
use app\channel\service\ChannelService;
|
||
use app\kami\service\LockCardService;
|
||
use app\merchant\service\OrderAutoService;
|
||
use app\merchant\service\OrderLastHistoryService;
|
||
use app\merchant\service\OrderLastweekHistoryService;
|
||
use app\merchant\service\OrderTwoHistoryService;
|
||
use app\openapi\controller\Coretb;
|
||
use app\setting\service\BlackCardService;
|
||
use think\admin\Controller;
|
||
use app\order\service\OrderService;
|
||
use app\merchant\service\MerchantService;
|
||
use app\merchant\service\MerchantLogService;
|
||
use app\merchant\service\PercentService;
|
||
use app\merchant\service\OrderService as OrderBase;
|
||
use app\merchant\service\OrderHistoryService;
|
||
use app\channel\service\CardService;
|
||
use app\merchant\service\CardService as CardLogService;
|
||
use \PhpOffice\PhpSpreadsheet\IOFactory;
|
||
use dever\Log;
|
||
|
||
/**
|
||
* 订单列表
|
||
* Class Order
|
||
* @package app\order\controller
|
||
*/
|
||
class Order extends Controller
|
||
{
|
||
/**
|
||
* cell
|
||
*
|
||
* @var array
|
||
*/
|
||
private $cell = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');
|
||
/**
|
||
* 绑定数据表
|
||
* @var string
|
||
*/
|
||
public $table = 'merchant_order';
|
||
|
||
private function getConfig(): array
|
||
{
|
||
$config['cash'] = [5,10,20,30,50,100,200,300,500,1000,2000];
|
||
$config['status'] = [''=>'-- 全部 --','1'=>'下单','2'=>'成功', '3'=> '失败', '4' => '处理中', '5' => '存疑', '7' => '提卡成功待处理','-1' => '队列中', '-2' => '失败待处理', '-3' => '排队中', '-4' => '复充排队中', '-5' => '已暂停', '-6' => '已冻结'];
|
||
$config['time'] = ['1'=>'小于1分钟','2'=>'1分钟-10分钟', '3' => '10分钟-20分钟','4' => '20分钟-30分钟','5' => '30分钟-40分钟','6' => '40分钟-50分钟','7' => '50分钟-60分钟','8' => '1小时-24小时','9' => '24小时-36小时','10' => '36小时-48小时','11' => '大于48小时'];
|
||
$config['data_type'] = ['1'=>'今日','7'=>'最近一周','5'=>'最近一个月','6'=>'最近二到三个月','2'=>'历史'];
|
||
$config['is_number'] = [''=>'-- 全部 --','1'=>'有流水号','2'=>'无流水号'];
|
||
$config['buy_back'] = [''=>'-- 全部 --','1'=>'返销订单','0'=>'正常订单'];
|
||
$config['kami_hinged'] = [''=>'-- 全部 --','1'=>'卡密二销返销订单','2'=>'正常订单'];
|
||
$config['apply_refund'] = [''=>'-- 全部 --','0'=>'未申请','1'=>'登记申请退单','2'=>'退单成功','3'=>'退单失败已成功','4'=>'退单处理中'];
|
||
|
||
return $config;
|
||
}
|
||
|
||
private function getDb()
|
||
{
|
||
$data_type = input('data_type', 1);
|
||
if ($data_type == 5 ){
|
||
$this->table = 'merchant_order_last_history';
|
||
} else if ($data_type == 6) {
|
||
$this->table = 'merchant_order_two_history';
|
||
}else if ($data_type == 2) {
|
||
$this->table = 'merchant_order_history';
|
||
}else if ($data_type == 7) {
|
||
$this->table = 'merchant_order_lastweek_history';
|
||
}
|
||
$this->data_type = $data_type;
|
||
$this->isp = PercentService::instance()->getIsp();
|
||
$query = $this->_query($this->table);
|
||
|
||
$time = input('time');
|
||
if ($time > 0) {
|
||
$start = $end = 0;
|
||
switch ($time) {
|
||
case 1:
|
||
$start = 0;
|
||
$end = 60;
|
||
break;
|
||
|
||
case 2:
|
||
$start = 60;
|
||
$end = 600;
|
||
break;
|
||
|
||
|
||
case 3:
|
||
$start = 600;
|
||
$end = 1200;
|
||
break;
|
||
|
||
case 4:
|
||
$start = 1200;
|
||
$end = 1800;
|
||
break;
|
||
|
||
case 5:
|
||
$start = 1800;
|
||
|
||
$end = 2400;
|
||
break;
|
||
|
||
case 6:
|
||
$start = 2400;
|
||
$end = 3000;
|
||
break;
|
||
|
||
case 7:
|
||
$start = 3000;
|
||
$end = 3600;
|
||
break;
|
||
|
||
case 8:
|
||
$start = 3600;
|
||
$end = 86400;
|
||
break;
|
||
|
||
case 9:
|
||
$start = 86400;
|
||
$end = 129600;
|
||
break;
|
||
|
||
case 10:
|
||
$start = 129600;
|
||
$end = 172800;
|
||
break;
|
||
|
||
case 11:
|
||
$start = 172800;
|
||
$end = 8640000;
|
||
break;
|
||
|
||
default:
|
||
# code...
|
||
break;
|
||
}
|
||
$cur = time();
|
||
$sql = '(status in(2,3) and unix_timestamp(channel_callback_at) - unix_timestamp(create_at) > ' . $start . ' and unix_timestamp(channel_callback_at) - unix_timestamp(create_at) <= ' . $end .')';
|
||
$sql .= ' or ';
|
||
$sql .= '(status not in(2,3) and '.$cur.' - unix_timestamp(create_at) > ' . $start . ' and '.$cur.' - unix_timestamp(create_at) <= ' . $end .')';
|
||
//$query->whereRaw(' channel_callback_at > 0 and timestampdiff(second,create_at, channel_callback_at) > ' . $start . ' and timestampdiff(second,create_at, channel_callback_at) <= ' . $end);
|
||
$query->whereRaw($sql);
|
||
}
|
||
|
||
$status = input('status');
|
||
if ($status) {
|
||
if ($status == 4) {
|
||
$query->whereRaw('status in(4,6)');
|
||
} elseif ($status == -7) {
|
||
$query->whereRaw('status in(-3,-4,-5)');
|
||
} else {
|
||
$query->whereRaw('status = ' . $status);
|
||
}
|
||
}
|
||
|
||
$buy_back = input('buy_back');
|
||
if (($buy_back == 0 || $buy_back == 1) && !empty($buy_back)) {
|
||
// 如果变量等于0或1,并且不为空,执行这里的代码
|
||
$query->whereRaw('buy_back = '.$buy_back);
|
||
}
|
||
|
||
$kami_hinged = input('kami_hinged');
|
||
if (($kami_hinged == 1 ) && !empty($kami_hinged)) {
|
||
// 如果变量等于0或1,并且不为空,执行这里的代码
|
||
$query->whereRaw(' response like("%is_kami%")');
|
||
}elseif ($kami_hinged == 2) {
|
||
# 无流水号的
|
||
$query->whereRaw(' response not like("%is_kami%")');
|
||
}
|
||
// if ($buy_back == 1) {
|
||
// # 有流水号的
|
||
// $query->whereRaw('buy_back = '.$buy_back);
|
||
// } elseif ($buy_back == 0) {
|
||
// # 无流水号的
|
||
// $query->whereRaw('buy_back = '.$buy_back);
|
||
// }
|
||
|
||
$is_number = input('is_number');
|
||
|
||
|
||
|
||
if ($is_number == 1) {
|
||
# 有流水号的
|
||
$query->whereRaw(' channel_callback_msg like("%s_number%")');
|
||
} elseif ($is_number == 2) {
|
||
# 无流水号的
|
||
$query->whereRaw(' channel_callback_msg not like("%s_number%")');
|
||
}
|
||
|
||
return $query;
|
||
}
|
||
|
||
|
||
/**
|
||
* 订单列表
|
||
* @auth true
|
||
* @menu true
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
*/
|
||
public function index()
|
||
{
|
||
|
||
|
||
$this->title = '订单列表';
|
||
$query = $this->getDb();
|
||
// var_dump($query);
|
||
$query->equal('mid,cid,pid,account,cash,product_key,isp')->like('order_id,channel_order_id,merchant_order_id,parent_order_id')->dateBetween('create_at,channel_callback_at');
|
||
// try{
|
||
// $query->order('create_at desc')->page();
|
||
// }catch(\Exception $e){
|
||
// var_dump($e);exit;
|
||
// }
|
||
if (input('output') === 'json') {
|
||
$result = $query->order('create_at desc')->page(true, false);
|
||
|
||
$this->success('获取数据列表成功', $result);
|
||
} else {
|
||
|
||
$res= $query->order('create_at desc')->page();
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 数据列表处理
|
||
* @param array $data
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
*/
|
||
protected function _page_filter(&$data)
|
||
{
|
||
$this->clist = OrderService::instance()->getChannelList(true);
|
||
$this->mlist = OrderService::instance()->getMerchantList(true);
|
||
$this->plist = OrderService::instance()->getProductList(true);
|
||
$this->pkeylist = OrderService::instance()->getProductKeyList(true);
|
||
|
||
$this->search = $this->getConfig();
|
||
|
||
//
|
||
// product_key == cardbuy response
|
||
|
||
$page = input('page', 1);
|
||
$limit = input('limit', 20);
|
||
foreach ($data as $k => &$vo) {
|
||
$k = $k + 1;
|
||
$vo['index'] = $k;
|
||
if ($page > 1) {
|
||
$vo['index'] = $k + ($limit * ($page - 1));
|
||
}
|
||
$vo['cinfo'] = $this->clist[$vo['cid']] ?? false;
|
||
$vo['minfo'] = $this->mlist[$vo['mid']] ?? false;
|
||
$vo['pinfo'] = $this->plist[$vo['pid']] ?? false;
|
||
|
||
$vo['other'] = OrderService::instance()->getOtherList($vo['order_id']);
|
||
if ($vo['other']) {
|
||
foreach ($vo['other'] as $k1 => $v1) {
|
||
$vo['other'][$k1]['cinfo'] = $this->clist[$v1['cid']] ?? false;
|
||
}
|
||
}
|
||
$vo['s_number'] = '';
|
||
$vo['time'] = '';
|
||
if ($vo['channel_callback_msg']) {
|
||
$vo['channel_callback_msg'] = json_decode($vo['channel_callback_msg'], true);
|
||
if (isset($vo['channel_callback_msg']['trade_no']) && $vo['channel_callback_msg']['trade_no']) {
|
||
$vo['channel_order_id'] = $vo['channel_callback_msg']['trade_no'];
|
||
}
|
||
|
||
if (isset($vo['channel_callback_msg']['s_number']) && $vo['channel_callback_msg']['s_number'] && $vo['cid'] != 10031) {
|
||
$vo['s_number'] = $vo['channel_callback_msg']['s_number'];
|
||
}
|
||
|
||
if (isset($vo['channel_callback_msg']['message']) && $vo['channel_callback_msg']['message']) {
|
||
$vo['msg'] = $vo['channel_callback_msg']['message'];
|
||
} elseif (isset($vo['channel_callback_msg']['msg']) && $vo['channel_callback_msg']['msg']) {
|
||
$vo['msg'] = $vo['channel_callback_msg']['msg'];
|
||
}
|
||
}
|
||
|
||
if (isset($vo['msg']) && is_array($vo['msg'])) {
|
||
$msg = $vo['msg'];
|
||
$vo['msg'] = array();
|
||
foreach ($msg as $k => $v) {
|
||
$k = $k+1;
|
||
$vo['msg'][] = '卡密'.$k.':' . $v['card'] . ',' . $v['pwd'] . ',' . $v['time'];
|
||
}
|
||
$vo['msg'] = implode(',', $vo['msg']);
|
||
}
|
||
|
||
$vo['buy_num'] = 1;
|
||
if ($vo['param']) {
|
||
$vo['param'] = json_decode($vo['param'], true);
|
||
if (isset($vo['param']['num']) && $vo['param']['num']) {
|
||
$vo['buy_num'] = $vo['param']['num'];
|
||
}
|
||
}
|
||
|
||
$vo['one_cash'] = round($vo['cash'] / $vo['buy_num'], 3);
|
||
|
||
$vo['show_set'] = 2;
|
||
|
||
#添加锁卡功能
|
||
if(isset($vo['cinfo']['suoka_status']) && $vo['cinfo']['suoka_status'] > 0){
|
||
if(isset($vo['lockcard_id']) && $vo['lockcard_id']){
|
||
$lockCardInfo = LockCardService::instance()->getInfo($vo['order_id']);
|
||
if($lockCardInfo && isset($lockCardInfo['lock_type'])){
|
||
if($lockCardInfo['lock_type'] == 1){
|
||
$vo['suoka_status'] = 2;
|
||
}else{
|
||
$vo['suoka_status'] = 1;
|
||
}
|
||
|
||
}else{
|
||
$vo['suoka_status'] = 1;
|
||
}
|
||
|
||
}else{
|
||
$vo['suoka_status'] = 1;
|
||
}
|
||
|
||
}else{
|
||
$vo['suoka_status'] = 0;
|
||
}
|
||
#添加黑名单设置功能
|
||
if(isset($vo['minfo']['merchant_type']) && $vo['minfo']['merchant_type'] == 8 || $vo['minfo']['merchant_type'] == 9){
|
||
|
||
$check = BlackCardService::instance()->checkorderid($vo['order_id'],$vo['minfo']['merchant_type']);
|
||
|
||
if(!$check){
|
||
$vo['set_black_status'] = 2;
|
||
}else{
|
||
$vo['set_black_status'] = 1;
|
||
}
|
||
// var_dump(1);die;
|
||
|
||
|
||
}else{
|
||
$vo['set_black_status'] = 0;
|
||
}
|
||
|
||
if ($vo['channel_callback_at']) {
|
||
|
||
$start = $this->maketime($vo['create_at']);
|
||
$end = $this->maketime($vo['channel_callback_at']);
|
||
|
||
$time = ($end - $start);
|
||
$vo['time'] = $this->secToTime($time);
|
||
} elseif ($vo['status'] == 3 && !$vo['channel_callback_at']) {
|
||
$vo['time'] = '0秒';
|
||
} else {
|
||
$start = $this->maketime($vo['create_at']);
|
||
$end = time();
|
||
$time = ($end - $start);
|
||
$vo['time'] = $this->secToTime($time);
|
||
}
|
||
|
||
$set_callback = input('set_callback', 2);
|
||
if ($set_callback == 1) {
|
||
$vo['show_set'] = 1;
|
||
}
|
||
|
||
if ($vo['project_id']) {
|
||
$vo['project'] = $this->app->db->name('merchant_project')->where(['id' => $vo['project_id']])->find();
|
||
}
|
||
|
||
$vo['card'] = array();
|
||
$vo['card_error'] = 0;
|
||
if ($vo['card_id'] && $vo['card_id'] > 0) {
|
||
$vo['card'] = CardService::instance()->db()->where(array('id' => $vo['card_id']))->find();
|
||
$vo['card_error'] = CardLogService::instance()->getNum($vo['card_id'], 7);
|
||
}
|
||
|
||
if (str_contains($vo['product_key'], '_cardbuy')) {
|
||
$vo['card_status'] = 3;
|
||
}elseif (str_contains($vo['product_key'], '_card')) {
|
||
$vo['card_status'] = 1;
|
||
} else {
|
||
$vo['card_status'] = 2;
|
||
}
|
||
|
||
#添加撤单功能
|
||
if(isset($vo['cinfo']['cancel_status']) && $vo['cinfo']['cancel_status'] && isset($vo['minfo']['cancel_support']) && $vo['minfo']['cancel_support'] ){
|
||
if($vo['apply_refund'] == 1){
|
||
$vo['show_refund'] = 2;
|
||
}elseif(!$vo['apply_refund'] ){
|
||
$vo['show_refund'] = 1;
|
||
}
|
||
|
||
|
||
}else{
|
||
$vo['show_refund'] = 0;
|
||
}
|
||
|
||
#虚拟商品卡密数据channel_callback_msg
|
||
// $vo['kami'] = array();
|
||
// if($vo['product_key'] =='cardbuy' && isset($vo['channel_callback_msg'])){
|
||
//// $tempMsg=json_decode($vo['channel_callback_msg']);
|
||
//// if($tempMsg[''])
|
||
// }
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 实时统计
|
||
* @login true
|
||
* @auth true
|
||
* @param integer $id
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
*/
|
||
public function stat()
|
||
{
|
||
$query = $this->getDb();
|
||
|
||
$config = $this->getConfig();
|
||
|
||
$this->total = OrderService::instance()->total();
|
||
|
||
$this->_form($this->table, 'stat');
|
||
}
|
||
|
||
#异步实时统计
|
||
public function stats()
|
||
{
|
||
$query = $this->getDb();
|
||
|
||
$config = $this->getConfig();
|
||
|
||
$this->total = OrderService::instance()->total();
|
||
$this->success('ok',$this->total);
|
||
|
||
// $this->_form($this->table, 'stat');
|
||
}
|
||
|
||
|
||
/**
|
||
* 查看详细数据
|
||
* @login true
|
||
* @auth true
|
||
* @param integer $id
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
*/
|
||
public function info($id = 0)
|
||
{
|
||
$data_type = input('data_type', 1);
|
||
if ($data_type == 5) {
|
||
$this->table = 'merchant_order_last_history';
|
||
} elseif ($data_type == 3) {
|
||
$this->table = 'merchant_order_auto_error';
|
||
}elseif ($data_type == 6) {
|
||
$this->table = 'merchant_order_two_history';
|
||
}elseif ($data_type == 2) {
|
||
$this->table = 'merchant_order_history';
|
||
}elseif ($data_type == 7) {
|
||
$this->table = 'merchant_order_lastweek_history';
|
||
}
|
||
$this->_applyFormToken();
|
||
$this->verify = false;
|
||
$this->_form($this->table, 'info');
|
||
}
|
||
|
||
/**
|
||
* 手动充值
|
||
* @login true
|
||
* @auth true
|
||
* @param integer $id
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
*/
|
||
public function pay()
|
||
{
|
||
if ($this->request->isGet()) {
|
||
$this->_applyFormToken();
|
||
$this->verify = false;
|
||
$this->pkeylist = OrderService::instance()->getProductKeyList(true);
|
||
|
||
$this->search = $this->getConfig();
|
||
|
||
$this->_form($this->table, 'pay');
|
||
} else {
|
||
|
||
$mid = 1;
|
||
$data = input('data');
|
||
$cash = input('cash');
|
||
$product = input('product');
|
||
|
||
if (!$product) {
|
||
$this->error('请选择产品');
|
||
}
|
||
if (!$cash) {
|
||
$this->error('请选择面值');
|
||
}
|
||
|
||
$data = explode("\r\n", $data);
|
||
|
||
$log = array();
|
||
$log['data'] = $data;
|
||
$log['cash'] = $cash;
|
||
$log['product'] = $product;
|
||
Log::write('gateway', 'oper', $log);
|
||
|
||
if ($data) {
|
||
$service = \app\channel\service\ChannelService::instance();
|
||
foreach ($data as $k => $v) {
|
||
if (!$v) {
|
||
continue;
|
||
}
|
||
$temp = explode(',', $v);
|
||
$param = array();
|
||
$param['cash'] = $cash;
|
||
|
||
if ($product == 'dxdc') {
|
||
if (isset($temp[1])) {
|
||
$param['cnum'] = $temp[1];
|
||
}
|
||
if (isset($temp[2])) {
|
||
$param['cpwd'] = $temp[2];
|
||
}
|
||
} elseif ($product == 'dhcz') {
|
||
$param['mobile'] = $temp[0];
|
||
} elseif ($product == 'ltcz' || $product == 'ydcz' || $product == 'dxcz') {
|
||
$param['mobile'] = $temp[0];
|
||
} else {
|
||
$param['card'] = $temp[0];
|
||
if (isset($temp[1]) && $temp[1]) {
|
||
$param['idCard'] = $temp[1];
|
||
}
|
||
if (isset($temp[2]) && $temp[2]) {
|
||
$param['realName'] = $temp[2];
|
||
}
|
||
if (isset($temp[3]) && $temp[3]) {
|
||
$param['mobile'] = $temp[3];
|
||
}
|
||
}
|
||
|
||
$param['order'] = $this->createOrderId($k);
|
||
$service->use($mid, $product, $param, true);
|
||
}
|
||
}
|
||
|
||
$this->success('操作成功', '');
|
||
}
|
||
}
|
||
|
||
protected function createOrderId($i = 0)
|
||
{
|
||
return 'CR' . date('Ymd').substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(100000, 999999)) . '_' . $i;
|
||
}
|
||
|
||
/**
|
||
* 表单数据处理
|
||
* @param array $data
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
*/
|
||
protected function _info_form_filter(&$data)
|
||
{
|
||
$data['info'] = OrderService::instance()->getOrderInfo($data['cid'],$data['mid'],$data['pid']);
|
||
$data['card'] = array();
|
||
|
||
if ($data['card_id'] && $data['card_id'] > 0) {
|
||
$data['card'] = CardService::instance()->db()->where(array('id' => $data['card_id']))->find();
|
||
|
||
$data['card']['log'] = CardLogService::instance()->getData($data['card_id']);
|
||
}
|
||
|
||
#虚拟商品卡密数据channel_callback_msg
|
||
|
||
$data['kami'] = array();
|
||
|
||
if((str_contains($data['product_key'], '_cardbuy') || $data['product_key'] =='cardbuy') && isset($data['channel_callback_msg'])){
|
||
$tempMsg=json_decode($data['channel_callback_msg'] ,true);
|
||
if(isset($tempMsg['kami']) && $tempMsg['kami']){
|
||
$data['kami'] ['cardno'] = $tempMsg['kami']['cardno'];
|
||
$data['kami'] ['cardpwd'] = $tempMsg['kami']['cardpwd'];
|
||
$data['kami'] ['expired'] = $tempMsg['kami']['expired'];
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
# 手动扣款
|
||
public function kou()
|
||
{
|
||
$order_id = input('order_id');
|
||
if (!$order_id) {
|
||
$this->error('请选择订单');
|
||
}
|
||
$status = input('status');
|
||
$data_type = input('data_type', 1);
|
||
|
||
if ($data_type == 5) {
|
||
$order = OrderLastHistoryService::instance();
|
||
} else if ($data_type == 6) {
|
||
$order = OrderTwoHistoryService::instance();
|
||
}else if ($data_type == 2) {
|
||
$order = OrderHistoryService::instance();
|
||
}else if ($data_type == 7) {
|
||
$order = OrderLastweekHistoryService::instance();
|
||
}else {
|
||
$order = OrderBase::instance();
|
||
}
|
||
|
||
$info = $order->get($order_id);
|
||
|
||
if ($info) {
|
||
$log = MerchantLogService::instance()->getOrderId($info['mid'], $info['order_id']);
|
||
|
||
if (!$log) {
|
||
$state = MerchantService::instance()->setFrozenAccount($info['id'], $info['order_id'], $info['mid'], $info['pid'], $info['product_key'], $info['cash'], $info['project_id'], $info['account'], $info['isp'], $info['create_at']);
|
||
|
||
if ($state) {
|
||
$update = array();
|
||
$update['actual_cash'] = $state[0];
|
||
$update['product_cash'] = $state[1];
|
||
if (isset($state[2])) {
|
||
$update['account_type'] = $state[2];
|
||
}
|
||
|
||
$order->db()->where(array('id' => $info['id']))->update($update);
|
||
|
||
$this->success('扣款成功', '');
|
||
} else {
|
||
$this->success('扣款失败', '');
|
||
}
|
||
} else {
|
||
$this->success('扣款失败', '');
|
||
}
|
||
|
||
} else {
|
||
$this->success('扣款失败', '');
|
||
}
|
||
}
|
||
# 取消订单
|
||
public function cancel()
|
||
{
|
||
$order_id = input('order_id');
|
||
$status = input('status');
|
||
|
||
$data_type = input('data_type', 1);
|
||
$order = OrderBase::instance();
|
||
|
||
if ($data_type == 5) {
|
||
$order = OrderLastHistoryService::instance();
|
||
} else if ($data_type == 6) {
|
||
$order = OrderTwoHistoryService::instance();
|
||
}else if ($data_type == 2) {
|
||
$order = OrderHistoryService::instance();
|
||
}else if ($data_type == 7) {
|
||
$order = OrderLastweekHistoryService::instance();
|
||
} else {
|
||
$order = OrderBase::instance();
|
||
}
|
||
|
||
$info = $order->get($order_id);
|
||
|
||
if ($info) {
|
||
$info['order']=$info['order_id'];
|
||
|
||
$result=MerchantService::instance()->qxdd($info);
|
||
if($result['code']==1){
|
||
$order->db()->where(array('id' => $info['id']))->update(array('status'=>5));
|
||
}
|
||
// $order->cancelOrder($info);
|
||
}
|
||
|
||
$this->success('操作成功', '');
|
||
}
|
||
# 设置卡密
|
||
public function setCard()
|
||
{
|
||
$data['order_id'] = input('order_id');
|
||
if (!$data['order_id']) {
|
||
$this->error('请选择订单');
|
||
}
|
||
$data['status'] = input('status');
|
||
$data['data_type'] = input('data_type', 1);
|
||
|
||
$order = OrderService::instance();
|
||
if ($this->request->isPost()) {
|
||
$card = input('card');
|
||
if (!$card) {
|
||
$this->error('错误的卡密信息');
|
||
}
|
||
$msg = array();
|
||
foreach ($card as $k => $v) {
|
||
|
||
if (strstr($v, ',')) {
|
||
$t = explode(',', $v);
|
||
} else {
|
||
$t = explode(',', $v);
|
||
}
|
||
$msg[$k]['card'] = $t[0];
|
||
$msg[$k]['pwd'] = $t[1];
|
||
$msg[$k]['time'] = $t[2];
|
||
}
|
||
$order->setCallback($data['data_type'], $data['order_id'], $data['status'], $msg);
|
||
|
||
$this->success('设置成功,商户回调结果要等系统统一推送才会同步,请关注同步结果!也可以手动发起回调!', '');
|
||
|
||
} else {
|
||
|
||
$data['card'] = array();
|
||
|
||
$buy_num = 1;
|
||
$info = $order->getOrder($data['data_type'], $data['order_id']);
|
||
if ($info && $info['param']) {
|
||
$info['param'] = json_decode($info['param'], true);
|
||
if (isset($info['param']['num']) && $info['param']['num']) {
|
||
$buy_num = $info['param']['num'];
|
||
}
|
||
}
|
||
if ($info && $info['channel_callback_msg']) {
|
||
$info['channel_callback_msg'] = json_decode($info['channel_callback_msg'], true);
|
||
if (isset($info['channel_callback_msg']['message']) && $info['channel_callback_msg']['message']) {
|
||
$msg = $info['channel_callback_msg']['message'];
|
||
} elseif (isset($info['channel_callback_msg']['msg']) && $info['channel_callback_msg']['msg']) {
|
||
$msg = $info['channel_callback_msg']['msg'];
|
||
}
|
||
}
|
||
|
||
$data['card'] = array();
|
||
for($i = 1; $i <= $buy_num; $i++) {
|
||
$card = '';
|
||
$pwd = '';
|
||
$time = '';
|
||
$k = $i-1;
|
||
if (isset($msg) && isset($msg[$k])) {
|
||
$card = $msg[$k]['card'];
|
||
$pwd = $msg[$k]['pwd'];
|
||
$time = $msg[$k]['time'];
|
||
}
|
||
$s = $card;
|
||
if ($card && $pwd && $time) {
|
||
$s = $card . ',' . $pwd . ',' . $time;
|
||
}
|
||
$data['card'][$i] = $s;
|
||
}
|
||
$this->fetch('setCard', $data);
|
||
}
|
||
}
|
||
|
||
# 手动设置成功,设置官方流水号
|
||
public function setYes()
|
||
{
|
||
$data['order_id'] = input('order_id');
|
||
if (!$data['order_id']) {
|
||
$this->error('请选择订单');
|
||
}
|
||
$data['status'] = input('status');
|
||
$data['data_type'] = input('data_type', 1);
|
||
|
||
$order = OrderService::instance();
|
||
if ($this->request->isPost()) {
|
||
$s_number = input('s_number');
|
||
$order->setCallback($data['data_type'], $data['order_id'], $data['status'], '', $s_number);
|
||
$this->success('设置成功,商户回调结果要等系统统一推送才会同步,请关注同步结果!也可以手动发起回调!', '');
|
||
|
||
} else {
|
||
$info = $order->getOrder($data['data_type'], $data['order_id']);
|
||
$data['s_number'] = '';
|
||
if ($info && $info['channel_callback_msg']) {
|
||
$info['channel_callback_msg'] = json_decode($info['channel_callback_msg'], true);
|
||
if (isset($info['channel_callback_msg']['s_number']) && $info['channel_callback_msg']['s_number']) {
|
||
$data['s_number'] = $info['channel_callback_msg']['s_number'];
|
||
}
|
||
}
|
||
$this->fetch('setYes', $data);
|
||
}
|
||
}
|
||
|
||
public function setBlack(){
|
||
|
||
// $data = array();
|
||
// $data['name'] = $name;
|
||
$data['order_id'] = input('order_id');
|
||
if (!$data['order_id']) {
|
||
$this->error('请选择订单');
|
||
}
|
||
$data['black_status'] = input('black_status');
|
||
$data['data_type'] = input('data_type', 1);
|
||
if ($data['data_type'] == 2) {
|
||
$order = OrderHistoryService::instance();
|
||
} else if($data['data_type'] == 5){
|
||
$order = OrderLastHistoryService::instance();
|
||
} else if($data['data_type'] == 6){
|
||
$order = OrderTwoHistoryService::instance();
|
||
} else if($data['data_type'] == 7){
|
||
$order = OrderLastweekHistoryService::instance();
|
||
} else {
|
||
$order = OrderBase::instance();
|
||
}
|
||
|
||
|
||
|
||
$info = $order->db()->field('merchant_order_id,mid,param,order_id')->where(['id' => $data['order_id']])->find();
|
||
// var_dump($data);die;
|
||
|
||
$param = json_decode($info['param'],true);
|
||
if(isset($param['By_OpenUid']) && $param['By_OpenUid'] != 'error'){
|
||
$value = $param['By_OpenUid'];;
|
||
}elseif(isset($param['buyerId']) && $param['buyerId'] != 'error'){
|
||
$value = $param['buyerId'];;
|
||
|
||
}else{
|
||
$value = $this->get_nick($info['merchant_order_id'], $info['mid']);
|
||
if(!isset($value) || $value == 'error'){
|
||
$this->error('暂未关联买家openuid,请联系技术处理');
|
||
}else{
|
||
if(isset($info['param'])){
|
||
|
||
$array = json_decode($info['param'],true);
|
||
if(is_array($array)){
|
||
$array['By_OpenUid'] = $value;
|
||
$json = json_encode($array,JSON_UNESCAPED_UNICODE);
|
||
// var_dump($json);die;
|
||
|
||
$order->db()->where(['order_id'=>$info['order_id']])->update(['param'=>$json]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if($data['black_status'] == 2){
|
||
$desc = '淘宝店铺于'.date('Y-m-d H-i-s').'加入黑名单,关联订单号:'.$info['order_id'];
|
||
|
||
$info = BlackCardService::instance()->up(1, $value, $desc);
|
||
$this->success('加入黑名单成功', '');
|
||
|
||
}else{
|
||
BlackCardService::instance()->db()->where(['value'=>$value] )->delete();
|
||
$this->success('删除黑名单成功', '');
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
public function get_nick($merchant_order_id,$mid)
|
||
{
|
||
|
||
|
||
$merchant = MerchantService::instance()->get($mid);
|
||
|
||
$Seesionkey = $merchant['refresh_token'];#淘宝此token为直充系统授权token
|
||
$request = [];
|
||
$request['agentId'] = $merchant['agentId'];
|
||
$request['agentkey'] = $merchant['agentkey'];
|
||
if(isset($merchant['other_param']) && $merchant['other_param'] && str_contains($this->merchant['other_param'], "reapi_appkey"))
|
||
{
|
||
$other_param = json_decode($this->merchant['other_param'], true);
|
||
$request['agentId'] = $other_param['reapi_appkey'];
|
||
$request['agentkey'] = $other_param['reapi_appsecret'];
|
||
$Seesionkey = $this->merchant['access_token'];
|
||
|
||
}
|
||
$request['tid'] = $merchant_order_id;
|
||
$request['access_token'] = $Seesionkey;
|
||
$response = Coretb::taobaosdk('getByTrade',$request);
|
||
$json = json_encode($response);
|
||
$array = json_decode($json,true);
|
||
if(is_array($array)){
|
||
if(isset($array['open_uid']) && $array['open_uid']){
|
||
|
||
return $array['open_uid'];
|
||
}
|
||
}
|
||
Log::write('openapi', 'taobao_getnick', $json);#写入到日志里
|
||
|
||
return 'error';
|
||
|
||
|
||
}
|
||
|
||
#手动设置卡密
|
||
public function setKami()
|
||
{
|
||
$data['order_id'] = input('order_id');
|
||
if (!$data['order_id']) {
|
||
$this->error('请选择订单');
|
||
}
|
||
$data['status'] = input('status');
|
||
$data['data_type'] = input('data_type', 1);
|
||
|
||
$order = OrderService::instance();
|
||
if ($this->request->isPost()) {
|
||
$s_nubmer = input('s_nubmer');
|
||
$order->setCallback($data['data_type'], $data['order_id'], $data['status'], '', $s_nubmer);
|
||
$this->success('设置成功,商户回调结果要等系统统一推送才会同步,请关注同步结果!也可以手动发起回调!', '');
|
||
|
||
} else {
|
||
$info = $order->getOrder($data['data_type'], $data['order_id']);
|
||
$data['s_nubmer'] = '';
|
||
if ($info && $info['channel_callback_msg']) {
|
||
$info['channel_callback_msg'] = json_decode($info['channel_callback_msg'], true);
|
||
if (isset($info['channel_callback_msg']['s_nubmer']) && $info['channel_callback_msg']['s_nubmer']) {
|
||
$data['s_nubmer'] = $info['channel_callback_msg']['s_nubmer'];
|
||
}
|
||
}
|
||
$this->fetch('setKami', $data);
|
||
}
|
||
}
|
||
|
||
# 锁卡功能优化
|
||
public function suoka()
|
||
{
|
||
$order_id = input('orOrderder_id');
|
||
if (!$order_id) {
|
||
$this->error('请选择订单');
|
||
}
|
||
$type = input('type');
|
||
$msg = input('msg');
|
||
$data_type = input('data_type', 1);
|
||
|
||
$channelService = ChannelService::instance();
|
||
$LockCardService = LockCardService::instance();
|
||
|
||
$order = OrderService::instance();
|
||
|
||
|
||
$orderInfo = $order->getOrder($data_type,$order_id);
|
||
|
||
$response = json_decode($orderInfo['response'],true);
|
||
|
||
$channelInfo = $channelService->get($orderInfo['cid']);
|
||
|
||
if ($data_type == 5) {
|
||
$order = OrderLastHistoryService::instance();
|
||
}else if ($data_type == 6) {
|
||
$order = OrderTwoHistoryService::instance();
|
||
}else if ($data_type == 7) {
|
||
$order = OrderLastweekHistoryService::instance();
|
||
}elseif ($data_type == 2) {
|
||
$order = OrderHistoryService::instance();
|
||
}elseif ($data_type == 3) {
|
||
$order = OrderAutoService::instance();
|
||
}
|
||
|
||
$where = ['order_id' => $order_id];
|
||
|
||
|
||
if($channelInfo['suoka_status'] == 1){
|
||
|
||
if (isset($response['kami'])) {
|
||
if($type == 1){
|
||
$suoka = $channelService->call('lockCard', $orderInfo['cid'], $orderInfo);
|
||
if($suoka == 'ok' || $suoka == 'old_ok'){
|
||
$lockcard_id = $LockCardService->lockcard_log(1,$orderInfo,$response['kami'],'锁卡');
|
||
if($lockcard_id){
|
||
$order->db()->where($where)->update(['lockcard_id'=>$lockcard_id]);
|
||
$this->success('锁卡成功!', '');
|
||
}else{
|
||
$this->error('锁卡成功!登记失败', '');
|
||
}
|
||
|
||
|
||
}else{
|
||
Log::write('kami', 'lockCard', $orderInfo['order_id'].'锁卡失败');#写入到日志里
|
||
$this->error('锁卡失败!请自行核对', '');
|
||
}
|
||
}else{
|
||
$this->error('暂不支持解锁', '');
|
||
}
|
||
|
||
}
|
||
}elseif($channelInfo['suoka_status'] == 2){
|
||
if (isset($response['kami'])) {
|
||
if($type == 1) {
|
||
$suoka = $LockCardService->call('suoka', $orderInfo['cid'], $response['kami']['cardno'], $response['kami']['cardpwd'], $orderInfo['pid'], $orderInfo['cash']);
|
||
if ($suoka == 'ok' || $suoka == 'old_ok') {
|
||
$lockcard_id = $LockCardService->lockcard_log(1,$orderInfo,$response['kami'],'锁卡');
|
||
if($lockcard_id){
|
||
$order->db()->where($where)->update(['lockcard_id'=>$lockcard_id]);
|
||
$this->success('锁卡成功!', '');
|
||
}else{
|
||
$this->error('锁卡成功!登记失败', '');
|
||
}
|
||
|
||
|
||
} elseif ($suoka == 'use_error') {
|
||
$lockcard_id = $LockCardService->lockcard_log(2,$orderInfo,$response['kami'],'锁卡');
|
||
Log::write('kami', 'lockCard', $orderInfo['order_id'].'锁卡失败,已经被使用');#写入到日志里
|
||
if($lockcard_id){
|
||
$order->db()->where($where)->update(['lockcard_id'=>$lockcard_id]);
|
||
$this->error('已经被使用!', '');
|
||
}else{
|
||
$this->error('锁卡失败!已经被使用', '');
|
||
}
|
||
|
||
} else {
|
||
Log::write('kami', 'lockCard', $orderInfo['order_id'].'锁卡失败');#写入到日志里
|
||
$this->error('锁卡失败!请自行核对', '');
|
||
|
||
}
|
||
}else{
|
||
$this->error('暂不支持解锁', '');
|
||
}
|
||
//
|
||
|
||
}
|
||
|
||
|
||
} else{
|
||
$this->error('锁卡', '');
|
||
}
|
||
|
||
}
|
||
|
||
#
|
||
# 设置订单状态
|
||
/**
|
||
* 设置订单状态
|
||
* @login true
|
||
* @auth true
|
||
*/
|
||
public function set()
|
||
{
|
||
$order_id = input('order_id');
|
||
if (!$order_id) {
|
||
$this->error('请选择订单');
|
||
}
|
||
$status = input('status');
|
||
$msg = input('msg');
|
||
$data_type = input('data_type', 1);
|
||
$order = OrderService::instance();
|
||
$order->setCallback($data_type, $order_id, $status, $msg);
|
||
$this->success('设置成功,商户回调结果要等系统统一推送才会同步,请关注同步结果!也可以手动发起回调!', '');
|
||
}
|
||
|
||
# 单一重新送入
|
||
public function set_restart()
|
||
{
|
||
$order_id = input('order_id');
|
||
if (!$order_id) {
|
||
$this->error('请选择订单');
|
||
}
|
||
|
||
$order = OrderBase::instance();
|
||
$data = $order->db()->where(array('status' => -5 ,'id' =>$order_id))->order('id asc')->findOrEmpty();
|
||
|
||
$service = \app\channel\service\ChannelService::instance();
|
||
|
||
if(!$data){
|
||
$this->error('该订单未暂停无法重新推送');
|
||
}
|
||
|
||
$num = $data['num'];
|
||
|
||
$order_id = $data['order_id'] . '_' . $num;
|
||
|
||
$data['param'] = json_decode($data['param'], true);
|
||
if ($data['param']) {
|
||
$param = $data['param'];
|
||
$service->use($data['mid'], $data['pid'], $param, true, $order_id);
|
||
}
|
||
|
||
$this->success('重新下单成功', '');
|
||
|
||
}
|
||
|
||
#淘宝设置黑名单
|
||
|
||
|
||
# 发起回调
|
||
public function call()
|
||
{
|
||
$order_id = input('order_id');
|
||
$status = input('status');
|
||
$data_type = input('data_type', 1);
|
||
$order = OrderBase::instance();
|
||
|
||
if ($data_type == 2) {
|
||
$order = OrderHistoryService::instance();
|
||
} else if($data_type == 5){
|
||
$order = OrderLastHistoryService::instance();
|
||
}else if($data_type == 6){
|
||
$order = OrderTwoHistoryService::instance();
|
||
}else if($data_type == 7){
|
||
$order = OrderLastweekHistoryService::instance();
|
||
}else {
|
||
$order = OrderBase::instance();
|
||
}
|
||
|
||
$info = $order->get($order_id);
|
||
|
||
if ($info) {
|
||
$order->callSend($info, $data_type, false);
|
||
}
|
||
|
||
$this->success('推送成功', '');
|
||
}
|
||
|
||
# 发起拦截
|
||
public function apply_refund()
|
||
{
|
||
$order_id = input('order_id');
|
||
if (!$order_id) {
|
||
$this->error('请选择订单');
|
||
}
|
||
|
||
$apply_refund_type = input('apply_refund_type');
|
||
$data_type = input('data_type', 1);
|
||
if ($data_type != 1) {
|
||
$this->error('无法退单');
|
||
}
|
||
$order = OrderBase::instance();
|
||
|
||
$info = $order->get($order_id);
|
||
if (!$info) {
|
||
$this->error('未找到订单');
|
||
}
|
||
|
||
|
||
|
||
if ($info) {
|
||
if($info['status'] == 2 || $info['status'] == 3){
|
||
$this->error('该订单不支持退单,已有新的状态');
|
||
}
|
||
if($info['status'] == 1 || $info['status'] == -4 || $info['status'] == -5){
|
||
$order = OrderService::instance();
|
||
$order->setCallback($data_type, $order_id, 3, '{申请退单且状态为未退送}');
|
||
$this->success('拦截成功','');
|
||
}
|
||
$msg = $order->apply_refund($info, $apply_refund_type);
|
||
if($msg == 'success'){
|
||
$this->success('拦截成功','');
|
||
}elseif ($msg == 'fail'){
|
||
$this->error('拦截失败,不支持或者已经处理');
|
||
}elseif($msg == 'ok') {
|
||
$this->success('拦截申请成功,请等待它自动处理,若充值成功会继续充值','');
|
||
}
|
||
|
||
}
|
||
|
||
|
||
$this->success('推送成功', '');
|
||
}
|
||
|
||
# 对暂停的数据进行重新下单
|
||
public function restart()
|
||
{
|
||
$order = OrderBase::instance();
|
||
$data = $order->getStopOrder();
|
||
|
||
$service = \app\channel\service\ChannelService::instance();
|
||
|
||
foreach ($data as $key => $info) {
|
||
|
||
$num = $info['num'];
|
||
|
||
$order_id = $info['order_id'] . '_' . $num;
|
||
|
||
$info['param'] = json_decode($info['param'], true);
|
||
if ($info['param']) {
|
||
$param = $info['param'];
|
||
$service->use($info['mid'], $info['pid'], $param, true, $order_id);
|
||
}
|
||
}
|
||
|
||
$this->success('重新下单成功', '');
|
||
}
|
||
|
||
# 再次下单
|
||
public function order()
|
||
{
|
||
$order_id = input('order_id');
|
||
$status = input('status');
|
||
$data_type = input('data_type', 1);
|
||
$order = OrderBase::instance();
|
||
|
||
if ($data_type == 2) {
|
||
$order = OrderHistoryService::instance();
|
||
} else if ($data_type == 5) {
|
||
$order = OrderLastHistoryService::instance();
|
||
} else if ($data_type == 6) {
|
||
$order = OrderTwoHistoryService::instance();
|
||
} else if ($data_type == 7) {
|
||
$order = OrderLastweekHistoryService::instance();
|
||
} else {
|
||
$order = OrderBase::instance();
|
||
}
|
||
|
||
$info = $order->get($order_id);
|
||
|
||
if ($info) {
|
||
|
||
if ($info['status'] != 5) {
|
||
$this->error('只有疑似订单才能复冲');
|
||
}
|
||
|
||
$info['card'] = array();
|
||
if ($info['card_id'] && $info['card_id'] > 0) {
|
||
$info['card'] = CardService::instance()->db()->where(array('id' => $info['card_id'], 'use' => 1))->find();
|
||
if (!$info['card']) {
|
||
$this->error('当前卡密已不可用');
|
||
}
|
||
}
|
||
|
||
$num = $info['num'] + 1;
|
||
|
||
$order_id = $info['order_id'] . '_' . $num;
|
||
|
||
$service = \app\channel\service\ChannelService::instance();
|
||
|
||
$param['card'] = $info['account'];
|
||
$param['cash'] = $info['cash'];
|
||
if ($info['card']) {
|
||
$param['cnum'] = $info['card']['cnum'];
|
||
$param['cpwd'] = $info['card']['cpwd'];
|
||
}
|
||
|
||
$param['order'] = $info['merchant_order_id'];
|
||
|
||
if (isset($info['param']) && $info['param']) {
|
||
$info['param'] = json_decode($info['param'], true);
|
||
} else {
|
||
$info['param'] = false;
|
||
}
|
||
if ($info['param'] && isset($info['param']['notify']) && $info['param']['notify']) {
|
||
$param['notify'] = $info['param']['notify'];
|
||
}
|
||
|
||
$state = $service->use($info['mid'], $info['pid'], $param, false, $order_id);
|
||
|
||
if ($state == 'ok') {
|
||
$this->success('重新下单成功', '');
|
||
} else {
|
||
$this->error('重新下单失败:' . $state);
|
||
}
|
||
}
|
||
|
||
$this->error('复冲失败,请重新复冲');
|
||
}
|
||
|
||
# 上传充值文件
|
||
public function upload()
|
||
{
|
||
if ($_FILES) {
|
||
$data = $_FILES;
|
||
} else {
|
||
$this->error('请上传文件');
|
||
}
|
||
|
||
if (str_contains($data['file']['name'], '.xls')) {
|
||
$file = 'card/order_card.xlsx';
|
||
} else {
|
||
$file = 'card/order_card.txt';
|
||
}
|
||
|
||
if (is_file($file)) {
|
||
@unlink($file);
|
||
}
|
||
copy($data['file']['tmp_name'], $file);
|
||
|
||
if (is_file($file)) {
|
||
|
||
$data = $this->read($file);
|
||
|
||
$yes = 0;
|
||
$no = 0;
|
||
if ($data) {
|
||
$card = array();
|
||
foreach ($data as $k => $v) {
|
||
if ($k >= 0) {
|
||
$state = $this->up($v['A'], $v['B']);
|
||
if ($state && $state > 0) {
|
||
$yes++;
|
||
$card[] = $state;
|
||
} elseif (!$state) {
|
||
$no++;
|
||
}
|
||
}
|
||
}
|
||
|
||
$card = implode("\r\n", $card);
|
||
$this->success('已上传,其中' . $yes . '条上传成功,' . $no . '条上传失败', $card);
|
||
|
||
} else {
|
||
$this->error('上传失败');
|
||
}
|
||
} else {
|
||
$this->error('上传失败');
|
||
}
|
||
}
|
||
|
||
private function up($card, $cash = 0)
|
||
{
|
||
if (is_numeric($card) && $card) {
|
||
return $card;
|
||
} else {
|
||
return -1;
|
||
}
|
||
}
|
||
|
||
private function read($file)
|
||
{
|
||
if (!strstr($file, '.xls')) {
|
||
$content = file_get_contents($file);
|
||
|
||
$data = explode("\r\n", $content);
|
||
$result = array();
|
||
if (preg_match("/\s/", $data[0])) {
|
||
$i = 0;
|
||
foreach ($data as $k => $v) {
|
||
if ($v) {
|
||
$v = preg_replace('/\s(?=\S)/', ' ', $v);
|
||
$temp = explode(' ', $v);
|
||
$result[$i]['A'] = $temp[0];
|
||
if (isset($temp[1])) {
|
||
$result[$i]['B'] = $temp[1];
|
||
} else {
|
||
$result[$i]['B'] = '';
|
||
}
|
||
$i++;
|
||
}
|
||
}
|
||
} else {
|
||
if (isset($data[1]) && strlen($data[1]) <= 5) {
|
||
# 面值
|
||
$value = true;
|
||
$total = count($data)/2;
|
||
} else {
|
||
$value = false;
|
||
$total = count($data);
|
||
}
|
||
|
||
for ($i = 0; $i< $total; $i++) {
|
||
|
||
$index = $i;
|
||
if (isset($data[$index]) && $data[$index]) {
|
||
$result[$i]['A'] = $data[$index];
|
||
if ($value) {
|
||
$result[$i]['B'] = $data[$index + 1] ?? '';
|
||
} else {
|
||
$result[$i]['B'] = '';
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
include('../excel/PHPExcel.php');
|
||
|
||
$objRead = new \PHPExcel_Reader_Excel2007();
|
||
if (!$objRead->canRead($file)) {
|
||
$objRead = new \PHPExcel_Reader_Excel5();
|
||
if (!$objRead->canRead($file)) {
|
||
Export::alert('file not exists!');
|
||
}
|
||
}
|
||
$sheet = 0;
|
||
$offset = 0;
|
||
|
||
$obj = $objRead->load($file);
|
||
$currSheet = $obj->getSheet($sheet);
|
||
$columnH = $currSheet->getHighestColumn();
|
||
$columnCnt = array_search($columnH, $this->cell);
|
||
$rowCnt = $currSheet->getHighestRow();
|
||
|
||
$data = array();
|
||
for ($_row = 1; $_row <= $rowCnt; $_row++) {
|
||
for ($_column = 0; $_column <= $columnCnt; $_column++) {
|
||
$cellId = $this->cell[$_column].$_row;
|
||
//$cellValue = $currSheet->getCell($cellId)->getValue();
|
||
$cellValue = $currSheet->getCell($cellId)->getCalculatedValue();
|
||
if ($cellValue instanceof \PHPExcel_RichText) {
|
||
$cellValue = $cellValue->__toString();
|
||
}
|
||
$data[$_row][$this->cell[$_column]] = $cellValue;
|
||
}
|
||
}
|
||
|
||
return $data;
|
||
}
|
||
|
||
# 批量上传充值文件
|
||
public function uploadMul()
|
||
{
|
||
if ($_FILES) {
|
||
$data = $_FILES;
|
||
} else {
|
||
$this->error('请上传文件');
|
||
}
|
||
|
||
if (str_contains($data['file']['name'], '.xls')) {
|
||
$file = 'card/order_mul_card.xlsx';
|
||
} else {
|
||
$file = 'card/order_mul_card.txt';
|
||
}
|
||
|
||
if (is_file($file)) {
|
||
@unlink($file);
|
||
}
|
||
copy($data['file']['tmp_name'], $file);
|
||
|
||
if (is_file($file)) {
|
||
|
||
$data = $this->readMul($file);
|
||
|
||
$yes = 0;
|
||
$no = 0;
|
||
if ($data) {
|
||
$card = array();
|
||
foreach ($data as $k => $v) {
|
||
if ($k > 1) {
|
||
$state = $this->upMul($v['A'], $v['B'], $v['C']);
|
||
if ($state) {
|
||
$yes++;
|
||
} else {
|
||
$no++;
|
||
$card[] = $v['A'];
|
||
}
|
||
}
|
||
}
|
||
|
||
$card = implode("\r\n", $card);
|
||
$msg = '已上传,其中' . $yes . '条上传成功,' . $no . '条上传失败';
|
||
if ($card) {
|
||
$msg .= ':<br />' . $card;
|
||
}
|
||
$this->success($msg);
|
||
|
||
} else {
|
||
$this->error('上传失败');
|
||
}
|
||
} else {
|
||
$this->error('上传失败');
|
||
}
|
||
}
|
||
|
||
private function upMul($order_id, $s_nubmer, $status)
|
||
{
|
||
if ($status != 2 && $status != 3) {
|
||
return false;
|
||
}
|
||
$order = OrderService::instance();
|
||
$data_type = 1;
|
||
return $order->setCallback($data_type, $order_id, $status, '', $s_nubmer);
|
||
}
|
||
|
||
private function readMul($file)
|
||
{
|
||
include('../excel/PHPExcel.php');
|
||
|
||
$objRead = new \PHPExcel_Reader_Excel2007();
|
||
if (!$objRead->canRead($file)) {
|
||
$objRead = new \PHPExcel_Reader_Excel5();
|
||
if (!$objRead->canRead($file)) {
|
||
Export::alert('file not exists!');
|
||
}
|
||
}
|
||
$sheet = 0;
|
||
$offset = 0;
|
||
|
||
$obj = $objRead->load($file);
|
||
$currSheet = $obj->getSheet($sheet);
|
||
$columnH = $currSheet->getHighestColumn();
|
||
$columnCnt = array_search($columnH, $this->cell);
|
||
$rowCnt = $currSheet->getHighestRow();
|
||
|
||
$data = array();
|
||
for ($_row = 1; $_row <= $rowCnt; $_row++) {
|
||
for ($_column = 0; $_column <= $columnCnt; $_column++) {
|
||
$cellId = $this->cell[$_column].$_row;
|
||
//$cellValue = $currSheet->getCell($cellId)->getValue();
|
||
$cellValue = $currSheet->getCell($cellId)->getCalculatedValue();
|
||
if ($cellValue instanceof \PHPExcel_RichText) {
|
||
$cellValue = $cellValue->__toString();
|
||
}
|
||
$data[$_row][$this->cell[$_column]] = $cellValue;
|
||
}
|
||
}
|
||
|
||
return $data;
|
||
}
|
||
|
||
public function maketime($v)
|
||
{
|
||
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;
|
||
}
|
||
|
||
public function secToTime($times)
|
||
{
|
||
|
||
$result = '0秒';
|
||
|
||
if ($times>0) {
|
||
|
||
$hour = floor($times/3600);
|
||
|
||
$minute = floor(($times-3600 * $hour)/60);
|
||
|
||
$second = floor((($times-3600 * $hour) - 60 * $minute) % 60);
|
||
|
||
$result = '';
|
||
if ($hour > 0) {
|
||
$result = $hour . '时';
|
||
}
|
||
if ($minute > 0) {
|
||
$result .= $minute . '分';
|
||
}
|
||
if ($second > 0) {
|
||
$result .= $second . '秒';
|
||
}
|
||
|
||
}
|
||
|
||
return $result;
|
||
|
||
}
|
||
|
||
}
|