140 lines
4.0 KiB
PHP
140 lines
4.0 KiB
PHP
![]() |
<?php
|
||
|
|
||
|
namespace app\queue\command\kuaishou;
|
||
|
|
||
|
|
||
|
use app\gateway\service\RedisService;
|
||
|
use app\merchant\service\MerchantService;
|
||
|
use app\merchant\service\OrderService;
|
||
|
//use app\order\service\Kami91OrderService;
|
||
|
use think\admin\Command;
|
||
|
use think\console\Input;
|
||
|
use think\console\Output;
|
||
|
use think\Collection;
|
||
|
|
||
|
/**
|
||
|
* 快手超时订单渠道连接诶
|
||
|
* Class KsOrderChanelTimeoutInt
|
||
|
* @package app\data\command
|
||
|
*/
|
||
|
class KsOrderChanelTimeoutInt extends Command
|
||
|
{
|
||
|
protected $redis = false;
|
||
|
protected function configure()
|
||
|
{
|
||
|
$this->setName('xQueue:KsOrderChanelTimeoutInt')->setDescription('[ 快手商家-订单列表 ] 渠道超时订单拦截');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param Input $input
|
||
|
* @param Output $output
|
||
|
* @throws \think\admin\Exception
|
||
|
*/
|
||
|
protected function execute(Input $input, Output $output)
|
||
|
{
|
||
|
ini_set('memory_limit', '1024M');
|
||
|
|
||
|
#定义查询快手店铺
|
||
|
|
||
|
$merchatlist = MerchantService::instance()->getTypeInfo('5');
|
||
|
|
||
|
if (empty($merchatlist)) {
|
||
|
$this->setQueueError("无快手店铺商户,任务未执行"); // 设置失败的消息并结束执行
|
||
|
}
|
||
|
|
||
|
$orderService = OrderService::instance();
|
||
|
|
||
|
$midsum = 0;
|
||
|
|
||
|
foreach ($merchatlist as $key => $v) {
|
||
|
$time = '6'; #定义超时拦截时间
|
||
|
$midsum++;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
$cur = time();
|
||
|
$time = 60 * '2';
|
||
|
$whereRaw = $cur . '-unix_timestamp(create_at) >=' . $time;
|
||
|
|
||
|
|
||
|
list($count, $total) = [0, $orderService->db()->whereRaw('status = 1 and ' . $whereRaw)->count()];
|
||
|
|
||
|
$orderService->db()->whereRaw('status = 1 and ' . $whereRaw)->chunk(100, function (Collection $data) use (&$count, $total, $orderService) {
|
||
|
// var_dump($orderlist);die;
|
||
|
foreach ($data->toArray() as $vo) {
|
||
|
|
||
|
if ($vo['request'] && $vo['status'] == 1) {
|
||
|
$count++;
|
||
|
$vo['request'] = json_decode($vo['request'], true);
|
||
|
\app\order\service\OrderService::instance()->setCallback(1, $vo['order_id'], 3);
|
||
|
}
|
||
|
|
||
|
$this->setQueueProgress("超时订单退款 {$vo['order_id']} ", $count / $total * 100);
|
||
|
}
|
||
|
|
||
|
});
|
||
|
$this->setQueueSuccess("完成 {$count} 个超时订单退款!");
|
||
|
}
|
||
|
|
||
|
protected function redis()
|
||
|
{
|
||
|
if (!$this->redis) {
|
||
|
$this->redis = RedisService::getInstance();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function transOrder($time){
|
||
|
$this->redis();
|
||
|
$where=[['status','=',4],['cid','=','2'],['expire_time','<=',date('Y-m-d H:i:s',time()+$time*60*60)]];
|
||
|
|
||
|
|
||
|
$field = "order_id,account";//需要数据库返回的字段
|
||
|
|
||
|
|
||
|
$orders = $this->getNeedOrder($where, $field);
|
||
|
|
||
|
$redisData=[];
|
||
|
if($orders){
|
||
|
foreach($orders as $key=>$value){
|
||
|
if(!$this->redis->get('rediskey-'.$orders[$key]['order_id'])){
|
||
|
array_push($redisData,$orders[$key]['account']);
|
||
|
$this->redis->set('rediskey-'.$orders[$key]['order_id'],'1',30*60);
|
||
|
}
|
||
|
if(!$this->redis->get('rediskey-1H-'.$orders[$key]['order_id']) && $time == '1'){
|
||
|
array_push($redisData,$orders[$key]['account']);
|
||
|
$this->redis->set('rediskey-1H-'.$orders[$key]['order_id'],'1',30*60);
|
||
|
}
|
||
|
if(!$this->redis->get('rediskey-TOP-'.$orders[$key]['order_id']) && $time == '0.5'){
|
||
|
array_push($redisData,$orders[$key]['order_id']);
|
||
|
$this->redis->set('rediskey-TOP-'.$orders[$key]['order_id'],'1',30*60);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return $redisData ? implode("\n", $redisData) : '';
|
||
|
}
|
||
|
|
||
|
public function getNeedOrder($where,$field)
|
||
|
{
|
||
|
$orderService = OrderService::instance();
|
||
|
|
||
|
$data = $orderService->db()->field($field)->where($where)->select()->toArray();
|
||
|
return $data;
|
||
|
}
|
||
|
|
||
|
protected function handle()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|