CRMEB/crmeb/app/jobs/PinkJob.php
2024-11-29 10:23:24 +08:00

57 lines
2.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\jobs;
use app\services\activity\combination\StorePinkServices;
use app\services\order\StoreOrderRefundServices;
use app\services\order\StoreOrderServices;
use crmeb\basic\BaseJobs;
use crmeb\traits\QueueTrait;
class PinkJob extends BaseJobs
{
use QueueTrait;
public function doJob($pinkId)
{
/** @var StorePinkServices $pinkService */
$pinkService = app()->make(StorePinkServices::class);
$people = $pinkService->value(['id' => $pinkId], 'people');
$count = $pinkService->count(['k_id' => $pinkId, 'is_refund' => 0]) + 1;
$orderIds = $pinkService->getColumn([['id|k_id', '=', $pinkId]], 'order_id_key', 'uid');
if ($people > $count) {
$virtual = $pinkService->virtualCombination($pinkId);
if ($virtual) return true;
$refundData = [
'refund_reason' => '拼团时间超时',
'refund_explain' => '拼团时间超时',
'refund_img' => json_encode([]),
];
foreach ($orderIds as $key => $item) {
/** @var StoreOrderServices $orderService */
$orderService = app()->make(StoreOrderServices::class);
$order = $orderService->get($item);
/** @var StoreOrderRefundServices $orderRefundService */
$orderRefundService = app()->make(StoreOrderRefundServices::class);
$orderRefundService->applyRefund((int)$order['id'], (int)$order['uid'], $order, [], 1, (float)$order['pay_price'], $refundData, 1);
$pinkService->update([['id|k_id', '=', $pinkId]], ['status' => 3]);
$pinkService->orderPinkAfterNo($key, $pinkId, false, $order->is_channel);
}
return true;
}
return true;
}
}