Initial commit
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\service\CommonService;
|
||||
use app\common\service\DemandBiddingService;
|
||||
use app\common\service\EasyWeChatService;
|
||||
use app\common\service\SubscribeMessageService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use app\common\service\DemandService;
|
||||
|
||||
class BiddingDeal extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('bidding:deal')->setDescription('bidding deal command!');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln("bidding:deal:");
|
||||
//超时确定接单处理
|
||||
$this->confirmDemandTimeoutDeal($input, $output);
|
||||
//开标处理
|
||||
$this->openBiddingDeal($input, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开标处理
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return void
|
||||
*/
|
||||
protected function openBiddingDeal(Input $input, Output $output)
|
||||
{
|
||||
|
||||
$open_bidding_time = intval(config('site.general_open_bidding_time') ?? 300);
|
||||
$EasyWeChatService = new EasyWeChatService();
|
||||
DemandService::$Model::hasWhere('demandBiddings', ['bidding_status' => DemandBiddingService::STATUS_BIDDING_ONGOING])->with(['demandBiddings' => function ($query) {
|
||||
$query->order('createtime asc');
|
||||
}])->where(['status' => DemandService::STATUS_BIDDING])->chunk(100, function ($list) use ($open_bidding_time, $EasyWeChatService) {
|
||||
foreach ($list as $item) {
|
||||
$bidList = $item->demandBiddings;
|
||||
foreach ($bidList as $bid) {
|
||||
//排除掉不符合中标状态的
|
||||
if ($bid->bidding_status != CommonService::ONGOING) {
|
||||
continue;
|
||||
}
|
||||
//判断首个投标记录的开始时间距现在是否有配置的时间5分钟
|
||||
if (time() - $bid->createtime >= $open_bidding_time) {
|
||||
//根据匹配度及信誉分获取一个人选,并修改状态为已中标
|
||||
$bid->bidding_status = DemandBiddingService::STATUS_BIDDING_WIN;
|
||||
$bid->process_status = DemandBiddingService::STATUS_PROCESS_ONGOING;
|
||||
$res = $bid->save();
|
||||
//发送接单成功提醒消息
|
||||
$msgData = [
|
||||
'values' => [
|
||||
$item->parent_order_no,
|
||||
mb_substr($item->desc, 0, 8),
|
||||
mb_substr($item->desc, 0, 11),
|
||||
SubscribeMessageService::MSG_MAP[SubscribeMessageService::MSG_TEMP_DEMAND_RECEIVE]['remark'],
|
||||
]
|
||||
];
|
||||
$EasyWeChatService->sendMsg($bid->user_id, SubscribeMessageService::MSG_TEMP_DEMAND_RECEIVE, $msgData);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 'Demands.id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认接单超时处理
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return void
|
||||
*/
|
||||
protected function confirmDemandTimeoutDeal(Input $input, Output $output)
|
||||
{
|
||||
$demand_confirm_timeout = intval(config('site.demand_confirm_timeout_time') ?? 300);
|
||||
$where = [
|
||||
'bidding_status' => DemandBiddingService::STATUS_BIDDING_WIN,
|
||||
'process_status' => DemandBiddingService::STATUS_PROCESS_ONGOING,
|
||||
];
|
||||
DemandBiddingService::where($where)->chunk(100, function ($biddingList) use ($demand_confirm_timeout) {
|
||||
foreach ($biddingList as $bidding) {
|
||||
//如果中标后5分钟未确认接单则弃权
|
||||
if (time() - $bidding->updatetime > $demand_confirm_timeout) {
|
||||
$bidding->bidding_status = DemandBiddingService::STATUS_BIDDING_NO;
|
||||
$bidding->process_status = DemandBiddingService::STATUS_PROCESS_TIMEOUT;
|
||||
$bidding->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\service\AccountLogService;
|
||||
use app\common\service\AccountService;
|
||||
use app\common\service\EasyWeChatService;
|
||||
use app\common\service\OrderService;
|
||||
use app\common\service\SubscribeMessageService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use app\common\service\DemandService;
|
||||
use think\Log;
|
||||
use think\Db;
|
||||
|
||||
class DemandDeal extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('demand:deal')->setDescription('bidding deal command!');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln("bidding:deal:");
|
||||
$this->confirmReceiptTimeoutDeal($input, $output);
|
||||
$this->demandProfitUnfreezeDeal($input, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货超时处理
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return void
|
||||
*/
|
||||
protected function confirmReceiptTimeoutDeal(Input $input, Output $output)
|
||||
{
|
||||
$confirmReceiptTimeoutDay = intval(config('site.confirm_receipt_timeout_day') ?? 7);
|
||||
$where = [
|
||||
'status' => DemandService::STATUS_CONFIRM_RECEIPT,
|
||||
'accept_status' => DemandService::$Common::SUCCESS,
|
||||
];
|
||||
DemandService::where($where)->chunk(100, function ($demandList) use ($confirmReceiptTimeoutDay) {
|
||||
foreach ($demandList as $item) {
|
||||
try {
|
||||
Db::transaction(function () use ($item, $confirmReceiptTimeoutDay) {
|
||||
//如果七天未确认收货,则自动确认收货
|
||||
if (time() > strtotime("+$confirmReceiptTimeoutDay day", $item->accept_time)) {
|
||||
$item->status = DemandService::STATUS_FINISHED;
|
||||
$item->settle_status = DemandService::$Common::ONGOING;
|
||||
$saveRes = $item->save();
|
||||
if (!$saveRes) {
|
||||
exception('更新结算状态失败');
|
||||
}
|
||||
//订单状态改为已完成
|
||||
$upRes = OrderService::where(['parent_order_no' => $item->parent_order_no])->update(['order_status' => OrderService::ORDER_STATUS_FINISHED]);
|
||||
if (!$upRes) {
|
||||
exception('更新订单状态失败');
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
Log::info('确认收货超时处理异常:' . json_encode(['file' => $e->getFile(), 'line' => $e->getLine(), 'error' => $e->getMessage(), 'item' => $item], JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单收益解冻处理
|
||||
* @param Input $input
|
||||
* @param Output $output
|
||||
* @return void
|
||||
*/
|
||||
protected function demandProfitUnfreezeDeal(Input $input, Output $output)
|
||||
{
|
||||
$where = [
|
||||
'status' => DemandService::STATUS_FINISHED,
|
||||
'settle_status' => DemandService::$Common::ONGOING,
|
||||
];
|
||||
DemandService::where($where)->with(['orders', 'winBidding'])->chunk(100, function ($demandList) {
|
||||
foreach ($demandList as $item) {
|
||||
try {
|
||||
Db::transaction(function () use ($item) {
|
||||
//根据订单列表查找冻结金额日志,根据冻结日志解冻冻结金额到余额
|
||||
$userId = $item->winBidding->user_id;
|
||||
$settleTotalAmount = 0;
|
||||
foreach ($item->orders as $order) {
|
||||
$logWhere = [
|
||||
'user_id' => $userId,
|
||||
'account_type' => AccountLogService::ACCOUNT_TYPE_FREEZE,
|
||||
'type' => AccountLogService::TYPE_FREEZE,
|
||||
'inc_or_exp' => AccountLogService::INC_EXP_INCREASE,
|
||||
'refer_id' => $order->id,
|
||||
'status' => AccountLogService::$Common::STATUS_OFF,
|
||||
];
|
||||
$log = AccountLogService::where($logWhere)->find();
|
||||
if ($log) {
|
||||
$amount = $log->amount;
|
||||
$settleTotalAmount += $amount;
|
||||
//写入余额日志
|
||||
$title = OrderService::ORDER_TYPE_MAP[$order->order_type] ?? '需求收益';
|
||||
$log_res = AccountLogService::addLog(AccountLogService::ACCOUNT_TYPE_FREEZE, $userId, $amount, $title . '解冻-冻结金额扣除', AccountLogService::TYPE_UNFREEZE, 0, AccountLogService::INC_EXP_EXPEND, $order->id, $order->total_amount);
|
||||
$log_res2 = AccountLogService::addLog(AccountLogService::ACCOUNT_TYPE_AMOUNT, $userId, $amount, $title . '解冻-余额增加', AccountLogService::TYPE_PROFIT, 0, AccountLogService::INC_EXP_INCREASE, $order->id, $order->total_amount);
|
||||
//减去冻结,加到余额里面
|
||||
AccountService::updateData($userId, $amount, -$amount, 0, 0, $log_res->id);
|
||||
//更新日志状态
|
||||
$log->status = AccountLogService::$Common::STATUS_ON;
|
||||
$saveRes = $log->save();
|
||||
if (!$saveRes) {
|
||||
exception('更新余额日志状态失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
//更新结算状态
|
||||
$item->settle_status = DemandService::$Common::SUCCESS;
|
||||
$saveRes2 = $item->save();
|
||||
if (!$saveRes2) {
|
||||
exception('更新需求结算状态失败');
|
||||
}
|
||||
//发送结算完成通知
|
||||
$msgData = [
|
||||
'values' => [
|
||||
$item->parent_order_no,
|
||||
round($settleTotalAmount, 2),
|
||||
SubscribeMessageService::MSG_MAP[SubscribeMessageService::MSG_TEMP_DEMAND_SETTLE]['remark'],
|
||||
]
|
||||
];
|
||||
(new EasyWeChatService)->sendMsg($userId, SubscribeMessageService::MSG_TEMP_DEMAND_SETTLE, $msgData);
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
Log::info('订单收益解冻处理异常:' . json_encode(['file' => $e->getFile(), 'line' => $e->getLine(), 'error' => $e->getMessage(), 'item' => $item], JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\service\DemandGroupChatService;
|
||||
use app\common\service\WorkWeChatService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
|
||||
class GroupChatFetch extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('groupChat:fetch')->setDescription('groupChat fetch command!');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$output->writeln("groupChat fetch...");
|
||||
DemandGroupChatService::updateQrCode(8);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\command;
|
||||
|
||||
use app\common\job\OrderJob;
|
||||
use think\Console;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Queue;
|
||||
|
||||
class Test extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('test2')->setDescription('Here is the remark ');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
// $output->writeln("TestCommand:");
|
||||
// Queue::push(OrderJob::class, $data = ['order_no' => 888888888], $queue = null); //前者是立即执行
|
||||
// Queue::later(10, OrderJob::class, $data = ['order_no' => 999999999999], $queue = null); //在$delay秒后执行
|
||||
$result = Console::call('bidding:deal', [], $output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user