|
|
<?php
|
|
|
/**
|
|
|
* Created by PhpStorm.
|
|
|
* User: DELL
|
|
|
* Date: 2019/5/31
|
|
|
* Time: 9:25
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
* Created by PhpStorm.
|
|
|
* User: DELL
|
|
|
* Date: 2019/4/9
|
|
|
* Time: 10:58
|
|
|
*/
|
|
|
namespace app\command;
|
|
|
|
|
|
use app\api\model\Third;
|
|
|
use app\api\model\UserMoneyLog;
|
|
|
use app\api\model\WithdrawLog;
|
|
|
use think\console\Input;
|
|
|
use think\console\Output;
|
|
|
use think\console\Command;
|
|
|
use addons\epay\library\Service;
|
|
|
use think\Db;
|
|
|
use think\Log;
|
|
|
use Yansongda\Pay\Pay;
|
|
|
|
|
|
class PayToUser extends Command{
|
|
|
|
|
|
protected function configure()
|
|
|
{
|
|
|
$this->setName('PayToUser')->setDescription('企业微信付款到用户,每1分钟执行,执行必须带锁防止同时出现两个脚本');
|
|
|
}
|
|
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
|
{
|
|
|
$config = Service::getConfig('wechat');
|
|
|
$pay = new Pay($config);
|
|
|
$withdrawLog = new WithdrawLog();
|
|
|
$withdrawLogList = $withdrawLog->listNeedPay(30);
|
|
|
$third = new Third();
|
|
|
$userMoneyLog = new UserMoneyLog();
|
|
|
|
|
|
foreach ($withdrawLogList as $v) {
|
|
|
$thirdInfo = $third->getOneByUserId($v['user_id']);
|
|
|
$order = [
|
|
|
'partner_trade_no' => $v['order_id'],
|
|
|
'open_id' => $thirdInfo['openid'],
|
|
|
'check_name' => 'NO_CHECK',
|
|
|
'amount' => $v['money'],
|
|
|
'desc' => '提现到零钱',
|
|
|
];
|
|
|
$res = $pay->driver('wechat')->gateway('transfer')->pay($order);
|
|
|
if(isset($res['return_code']) && ($res['return_code'] == 'SUCCESS') && isset($res['result_code']) && ($res['result_code'] == 'SUCCESS')) {
|
|
|
$withdrawLog->updateOne($v['id'], ['status' => 1, 'updatetime' => time()]);
|
|
|
} else {
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
$insertData = [
|
|
|
'user_id' => $v['user_id'],
|
|
|
'money' => $v['money'],
|
|
|
'memo' => '提现失败,全额返还',
|
|
|
'createtime' => time(),
|
|
|
];
|
|
|
$res = $userMoneyLog->addOne($insertData);
|
|
|
if(!$res) {
|
|
|
Db::rollback();
|
|
|
} else {
|
|
|
$res = $withdrawLog->updateOne($v['id'], ['status' => 2, 'updatetime' => time()]);
|
|
|
if(!$res) {
|
|
|
Db::rollback();
|
|
|
} else {
|
|
|
Db::commit();
|
|
|
}
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
Db::rollback();
|
|
|
Log::write('提现失败,返还到用户账户失败', 'debug');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|