refactor(channel): 新增 Template通道类
- 新增 Template通道类,实现了一些通用的充值和查询功能 - 修改 Mykjapi 类,增加了一些注释和调试代码 - 更新 Order 控制器,增加了订单号的处理逻辑 - 调整 merchantApi/Order 控制器,优化了参数处理 - 修改 OrderCancel命令,增加了条件判断和日志记录
This commit is contained in:
parent
ce2f6cfc62
commit
b97c1ffe94
@ -34,6 +34,7 @@ class Mykjapi extends Core
|
|||||||
$response = $this->curl('post', $url, $request ,true);
|
$response = $this->curl('post', $url, $request ,true);
|
||||||
|
|
||||||
$response = $this->response($response);
|
$response = $this->response($response);
|
||||||
|
// var_dump($response);die;
|
||||||
|
|
||||||
//$response['data'] = '{}';
|
//$response['data'] = '{}';
|
||||||
//$response['msg'] = 'ok';
|
//$response['msg'] = 'ok';
|
||||||
@ -42,6 +43,7 @@ class Mykjapi extends Core
|
|||||||
if($response['array']['mobileresult']['res'] == '1'){
|
if($response['array']['mobileresult']['res'] == '1'){
|
||||||
return ['mobile'=>$response['array']['mobileresult']['mobile'],'old_isp'=>$response['array']['mobileresult']['initIsp'],'new_isp'=>$response['array']['mobileresult']['isp'] ];
|
return ['mobile'=>$response['array']['mobileresult']['mobile'],'old_isp'=>$response['array']['mobileresult']['initIsp'],'new_isp'=>$response['array']['mobileresult']['isp'] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
286
app/channel/service/system/Template.php
Normal file
286
app/channel/service/system/Template.php
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\channel\service\system;
|
||||||
|
|
||||||
|
#模板
|
||||||
|
class Template extends Core
|
||||||
|
{
|
||||||
|
protected $host = ''; // 主机,不设置,后台
|
||||||
|
protected $mid = ''; // 商户id
|
||||||
|
protected $token = ''; // 密钥
|
||||||
|
protected $api = '';
|
||||||
|
//话费直充
|
||||||
|
public function dhcz($param){
|
||||||
|
// $check 前面为我们系统参宿,后面为文档中上游对应参数
|
||||||
|
# card(油卡账户),mobile(手机号,只在话费充值有),account(账户,除话费充值均为这个),以上三个基本上都是单独存在,不会同时存在,所以选择好判断.
|
||||||
|
# cash(充值金额),num(充值数量,非必须存在)
|
||||||
|
$check = array
|
||||||
|
(
|
||||||
|
'mobile' => 'recharge_account',
|
||||||
|
'cash'=>'quantity',
|
||||||
|
'Operator'=>'Operator'
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$this->api='api/buy';
|
||||||
|
# 判断运营商的方法
|
||||||
|
$this->isp('手机号');
|
||||||
|
#写法:
|
||||||
|
if (isset($param['isp']) && $param['isp']) {
|
||||||
|
if ($param['isp'] == 1) {
|
||||||
|
$param['Operator'] = 3;
|
||||||
|
} elseif ($param['isp'] == 2) {
|
||||||
|
$param['Operator'] = 2;
|
||||||
|
} elseif ($param['isp'] == 3) {
|
||||||
|
$param['Operator'] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#isp 1移动,2联通,3电信
|
||||||
|
|
||||||
|
return $this->submit($param, $check);
|
||||||
|
}
|
||||||
|
#dhcz 三网他,ydcz/dxcz/ltcz各个运营商类目,不识别
|
||||||
|
|
||||||
|
public function ydcz($param)
|
||||||
|
{
|
||||||
|
#需呀定义运营商
|
||||||
|
$param['Operator'] = '移动';
|
||||||
|
|
||||||
|
return $this->dhcz($param);
|
||||||
|
}
|
||||||
|
public function dxcz($param)
|
||||||
|
{
|
||||||
|
return $this->dhcz($param);
|
||||||
|
}
|
||||||
|
public function ltcz($param)
|
||||||
|
{
|
||||||
|
return $this->dhcz($param);
|
||||||
|
}
|
||||||
|
# 通用卡密购买,命名规范 渠道加卡的首字母_cardbuy 骏卡xxka jkxxk_cardbuy
|
||||||
|
# cardbuy为通用写法
|
||||||
|
public function cardbuy($param)
|
||||||
|
{
|
||||||
|
$check = array
|
||||||
|
(
|
||||||
|
'account' => 'recharge_account',
|
||||||
|
'cash'=>'quantity'
|
||||||
|
);
|
||||||
|
$this->api='api/buy';
|
||||||
|
return $this->submit($param, $check);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jdhy_cardbuy($param){
|
||||||
|
$check = array
|
||||||
|
(
|
||||||
|
'account' => 'recharge_account',
|
||||||
|
'cash'=>'cash'
|
||||||
|
);
|
||||||
|
$this->api='api/buy';
|
||||||
|
return $this->submit($param, $check);
|
||||||
|
}
|
||||||
|
|
||||||
|
# 通知处理 主要返回状态 2是成功 3是失败
|
||||||
|
public function notify($data)
|
||||||
|
{
|
||||||
|
$result = array();
|
||||||
|
$result['cash'] = 1;
|
||||||
|
$result['status'] = 4;
|
||||||
|
#以上基本不要变
|
||||||
|
|
||||||
|
if(isset($data['query_status'])){
|
||||||
|
if ($data['query_status'] == 200) {
|
||||||
|
$result['status'] = 2;
|
||||||
|
} else if($data['query_status'] == 500) {
|
||||||
|
$result['status'] = 3;
|
||||||
|
}else {
|
||||||
|
$result['status'] = 4;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if ($data['state'] == 200) {
|
||||||
|
$result['status'] = 2;
|
||||||
|
} else if($data['state'] == 500) {
|
||||||
|
$result['status'] = 3;
|
||||||
|
}else {
|
||||||
|
$result['status'] = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#以下处理逻辑可以自由
|
||||||
|
// if(isset($data['cards'])&&$data['cards']&&is_array($data['cards'])){
|
||||||
|
//
|
||||||
|
// $result['kami'] = array
|
||||||
|
// (
|
||||||
|
// 'cardno' => isset($data['cards'][0]['card_no'])?$data['cards'][0]['card_no']:'',
|
||||||
|
// 'cardpwd' => $data['cards'][0]['card_password'],
|
||||||
|
// 'expired' => isset($data['cards'][0]['expired_at'])?$data['cards'][0]['expired_at']:'',
|
||||||
|
//// 'value' => $array['data']['count_money'],
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
if(isset($data['kami'])&&$data['kami']){
|
||||||
|
$result['kami']=$data['kami'];
|
||||||
|
}
|
||||||
|
$result['yes'] = 'ok'; //响应给上游的数据
|
||||||
|
|
||||||
|
$result['data'] = $data;
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
public function query($order){
|
||||||
|
$request['customer_id'] = $this->mid;
|
||||||
|
$request['order_id'] = $order['merchant_order_id'];
|
||||||
|
$request['timestamp'] = time();
|
||||||
|
$request['sign'] = $this->_sign($request);
|
||||||
|
$url = $this->host . 'api/order';
|
||||||
|
$response = $this->curl('post', $url, $request);
|
||||||
|
|
||||||
|
#记录日志
|
||||||
|
$log['type'] = 'query_response';
|
||||||
|
$log['data'] = $response;
|
||||||
|
$log['config'] = $this->data;
|
||||||
|
$this->log($log);
|
||||||
|
#记录借宿
|
||||||
|
|
||||||
|
$array = $this->json_decode($response,true);
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
$result['status'] = 4;
|
||||||
|
if ($array['code']=='ok' ) {
|
||||||
|
if($array['state'] ==200){
|
||||||
|
$result['query_status'] = 200;
|
||||||
|
|
||||||
|
$result['status'] = 2;
|
||||||
|
}elseif ($array['state'] == 500){
|
||||||
|
$result['query_status'] = 500;
|
||||||
|
$result['status'] = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(isset($array['data']['cards'])){
|
||||||
|
$result['kami']=array(
|
||||||
|
'cardno' => isset($array['data']['cards'][0]['card_no'])?$array['data']['cards'][0]['card_no']:'',
|
||||||
|
'cardpwd' => $array['data']['cards'][0]['card_password'],
|
||||||
|
'expired' => $array['data']['cards'][0]['expired_at'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
# 数据响应格式处理
|
||||||
|
public function response($data)
|
||||||
|
{
|
||||||
|
$log['type'] = 'response';
|
||||||
|
$log['data'] = $data;
|
||||||
|
$log['config'] = $this->data;
|
||||||
|
$this->log($log);
|
||||||
|
|
||||||
|
#以上不要做任何变动
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$array = $this->json_decode($data); //响应数据为json
|
||||||
|
#如果响应为XML格式
|
||||||
|
// $array = (array) simplexml_load_string($data);
|
||||||
|
|
||||||
|
if (!$array) {
|
||||||
|
$msg = 'error';
|
||||||
|
} elseif (isset($array['code']) && $array['code']=='ok') { //修改判断逻辑为确定提交成功即可
|
||||||
|
# 正确
|
||||||
|
$msg = 'ok';
|
||||||
|
#如有其他判断以下
|
||||||
|
// if(isset($array['cards'])){
|
||||||
|
// $array['kami'] = array
|
||||||
|
// (
|
||||||
|
// 'cardno' => $array['cards'][0]['card_no'],
|
||||||
|
// 'cardpwd' => $array['cards'][0]['card_password'],
|
||||||
|
// 'expired' => $array['cards'][0]['expired_at'],
|
||||||
|
//// 'value' => $array['data']['count_money'],
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
} else {
|
||||||
|
# 错误
|
||||||
|
$msg = $array['message'] ?? 'error'; //前面message根据响应内容改成对应的错误提示
|
||||||
|
}
|
||||||
|
|
||||||
|
return array
|
||||||
|
(
|
||||||
|
'msg' => $msg,
|
||||||
|
'data' => $data,
|
||||||
|
'array' => $array,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
# 查询余额接口
|
||||||
|
public function account($day)
|
||||||
|
{
|
||||||
|
$request['customer_id'] = $this->mid;
|
||||||
|
$request['timestamp']=time();
|
||||||
|
$request['sign'] = $this->_sign($request);
|
||||||
|
$url = $this->host . 'api/customer';
|
||||||
|
$response = $this->curl('post', $url, $request);
|
||||||
|
$response = $this->response($response);
|
||||||
|
|
||||||
|
$datas = $response['array']['data'];
|
||||||
|
if(is_array($datas) && isset($datas['balance']) && $datas['balance'] ){
|
||||||
|
$datas['account'] = $datas['balance']; //此处为余额
|
||||||
|
}
|
||||||
|
|
||||||
|
return $datas;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 提交数据
|
||||||
|
private function submit($param, $check)
|
||||||
|
{
|
||||||
|
#提交处理
|
||||||
|
$param = $this->param($param, $check);
|
||||||
|
if (is_string($param) || (is_array($param) && $param['status'] == 1)) {
|
||||||
|
return $param;
|
||||||
|
}
|
||||||
|
$request = $param['detail']; //上面替换剩下的
|
||||||
|
#结束初步
|
||||||
|
|
||||||
|
$request['customer_id']=$this->mid;
|
||||||
|
if(!isset($request['quantity'])){
|
||||||
|
$request['quantity']=$param['cash'] ?? 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$request['notify_url']=$this->getNotify($param['order'], 1); //回调方法默认不用改
|
||||||
|
$request['outer_order_id']=$param['order']; //我方系统订单号
|
||||||
|
$request['product_id']=$this->getGid($param['cash']); //此方法为根据面值获取产品id,如无需可注释
|
||||||
|
$request['timestamp']=time();
|
||||||
|
// unset($request['cash']);
|
||||||
|
$request['sign'] = $this->_sign($request);
|
||||||
|
$url = $this->host . $this->api; //组装地址
|
||||||
|
|
||||||
|
#该系统提交写法:
|
||||||
|
$this->curl('post', $url, $request);//为post请求,表格提交
|
||||||
|
$this->curl('post', $url, $request,true); //为post请求,json提交
|
||||||
|
http_post($url,$request); //如果上面不可用,可以用这个方法, thinkadmin自带方法
|
||||||
|
http_get($url,$request); // get请求
|
||||||
|
$this->http_send('POST',$url,$request);//额外封,实在不行可以用.
|
||||||
|
#只需保留一个方法
|
||||||
|
|
||||||
|
|
||||||
|
$response = $this->curl('post', $url, $request);
|
||||||
|
$response = $this->response($response);
|
||||||
|
$channel_order_id = '';
|
||||||
|
|
||||||
|
#如果出现响应有上游订单号,可以如下
|
||||||
|
if (isset($response["array"]['data']['order_id'])) {
|
||||||
|
$channel_order_id = $response["array"]['data']['order_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->create($param['order'], $channel_order_id, $param['merchant_order'], $param['cash'], $url, $request, $response, 1, $param['account']);
|
||||||
|
return $response['msg'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _sign($request)
|
||||||
|
{
|
||||||
|
// unset($request['cash']);
|
||||||
|
ksort($request);
|
||||||
|
$str=$this->token;
|
||||||
|
foreach($request as $k=>$v){
|
||||||
|
$str.=$k.$v;
|
||||||
|
}
|
||||||
|
$str=strtolower(md5($str));
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
}
|
@ -1147,6 +1147,7 @@ class Order extends Controller
|
|||||||
$order = OrderBase::instance();
|
$order = OrderBase::instance();
|
||||||
|
|
||||||
$info = $order->get($order_id);
|
$info = $order->get($order_id);
|
||||||
|
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
$this->error('未找到订单');
|
$this->error('未找到订单');
|
||||||
}
|
}
|
||||||
@ -1162,6 +1163,9 @@ class Order extends Controller
|
|||||||
$order->setCallback($data_type, $order_id, 3, '{申请退单且状态为未推送}');
|
$order->setCallback($data_type, $order_id, 3, '{申请退单且状态为未推送}');
|
||||||
$this->success('拦截成功','');
|
$this->success('拦截成功','');
|
||||||
}
|
}
|
||||||
|
if(isset($info['num']) && $info['num']>0) {
|
||||||
|
$info['order_id'] = $info['order_id'].'_'.$info['num'];
|
||||||
|
}
|
||||||
$msg = $order->apply_refund($info, $apply_refund_type);
|
$msg = $order->apply_refund($info, $apply_refund_type);
|
||||||
if($msg == 'success'){
|
if($msg == 'success'){
|
||||||
$this->success('拦截成功','');
|
$this->success('拦截成功','');
|
||||||
|
@ -42,7 +42,6 @@ class Order extends Core
|
|||||||
$param['mnp_isp_array'] = $this->input['mnp_isp_array'];
|
$param['mnp_isp_array'] = $this->input['mnp_isp_array'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
$param['product'] =$this->product;
|
$param['product'] =$this->product;
|
||||||
|
|
||||||
@ -65,6 +64,7 @@ class Order extends Core
|
|||||||
$mnp_cid = sysconf('PhoneMnp_cid');
|
$mnp_cid = sysconf('PhoneMnp_cid');
|
||||||
if($mnp_cid){
|
if($mnp_cid){
|
||||||
$mnp_array = ChannelService::instance()->call('phone_mnp', $mnp_cid, $param);
|
$mnp_array = ChannelService::instance()->call('phone_mnp', $mnp_cid, $param);
|
||||||
|
|
||||||
if(is_array($mnp_array) && isset($mnp_array['new_isp'])){
|
if(is_array($mnp_array) && isset($mnp_array['new_isp'])){
|
||||||
$mnp_isp = $mnp_array['new_isp'];
|
$mnp_isp = $mnp_array['new_isp'];
|
||||||
if($mnp_isp == 1){
|
if($mnp_isp == 1){
|
||||||
@ -89,9 +89,10 @@ class Order extends Core
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// die;
|
||||||
|
|
||||||
|
|
||||||
$isp = Service::instance()->isp($this->input['mobile']);
|
$isp = Service::instance()->isp($mobile);
|
||||||
if ($isp == 1) {
|
if ($isp == 1) {
|
||||||
$this->product = 'ydcz';
|
$this->product = 'ydcz';
|
||||||
} elseif ($isp == 2) {
|
} elseif ($isp == 2) {
|
||||||
|
@ -58,10 +58,20 @@ class OrderCancel extends Command
|
|||||||
if(isset($array['timeout_cancel'])){
|
if(isset($array['timeout_cancel'])){
|
||||||
$timeout_cancel = $array['timeout_cancel'];
|
$timeout_cancel = $array['timeout_cancel'];
|
||||||
}
|
}
|
||||||
|
// if(isset($array['timeout_cancel_form'])){
|
||||||
|
// $timeout_cancel = $array['timeout_cancel_form'];
|
||||||
|
// }
|
||||||
|
|
||||||
foreach($channelList as $channel) {
|
foreach($channelList as $channel) {
|
||||||
|
if(isset($array['timeout_cancel_form'])){
|
||||||
|
$timeout_cancel = $array['timeout_cancel_form'];
|
||||||
|
$where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['create_at','>=',date('Y-m-d H:i:s',time()-$timeout_cancel)]];
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['expire_time','<=',date('Y-m-d H:i:s',time()+$timeout_cancel)]];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['expire_time','<=',date('Y-m-d H:i:s',time()+$timeout_cancel)]];
|
|
||||||
|
|
||||||
|
|
||||||
list($count, $total) = [0, $class->db()->where($where)->order('id asc')->count()];
|
list($count, $total) = [0, $class->db()->where($where)->order('id asc')->count()];
|
||||||
@ -69,22 +79,25 @@ class OrderCancel extends Command
|
|||||||
// $data = $class->db()->where($where)->limit(100)->select()->toArray();
|
// $data = $class->db()->where($where)->limit(100)->select()->toArray();
|
||||||
$class->db()->where($where)->order('id asc')->chunk(100, function (Collection $data) use (&$count, $total,$channel,$channelService,&$count_sum,$class) {
|
$class->db()->where($where)->order('id asc')->chunk(100, function (Collection $data) use (&$count, $total,$channel,$channelService,&$count_sum,$class) {
|
||||||
$array = $data->toArray();
|
$array = $data->toArray();
|
||||||
|
if($array){
|
||||||
|
|
||||||
|
foreach ($array as $k => $vo) {
|
||||||
|
$class->db()->where(['order_id','=',$vo['order_id']] )->update(['apply_refund'=>1]);
|
||||||
|
if(isset($vo['num']) && $vo['num']>0) {
|
||||||
|
$vo['order_id'] = $vo['order_id'].'_'.$vo['num'];
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($array as $k => $vo) {
|
$result = $channelService->call('cancel', $vo['cid'], $vo);
|
||||||
$class->db()->where(['order_id','=',$vo['order_id']] )->update(['apply_refund'=>1]);
|
if ($result) {
|
||||||
if(isset($vo['num']) && $vo['num']>0) {
|
$count_sum++;
|
||||||
$vo['order_id'] = $vo['order_id'].'_'.$vo['num'];
|
$count++;
|
||||||
}
|
$this->setQueueProgress("拦截 {$vo['order_id']} 订单成功", $count / $total * 100);
|
||||||
|
}
|
||||||
$result = $channelService->call('cancel', $vo['cid'], $vo);
|
|
||||||
if ($result) {
|
|
||||||
$count_sum++;
|
|
||||||
$count++;
|
|
||||||
$this->setQueueProgress("拦截 {$vo['order_id']} 订单成功", $count / $total * 100);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user