PinkJob.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs;
  12. use app\services\activity\combination\StorePinkServices;
  13. use app\services\order\StoreOrderRefundServices;
  14. use app\services\order\StoreOrderServices;
  15. use crmeb\basic\BaseJobs;
  16. use crmeb\traits\QueueTrait;
  17. class PinkJob extends BaseJobs
  18. {
  19. use QueueTrait;
  20. public function doJob($pinkId)
  21. {
  22. /** @var StorePinkServices $pinkService */
  23. $pinkService = app()->make(StorePinkServices::class);
  24. $people = $pinkService->value(['id' => $pinkId], 'people');
  25. $count = $pinkService->count(['k_id' => $pinkId, 'is_refund' => 0]) + 1;
  26. $orderIds = $pinkService->getColumn([['id|k_id', '=', $pinkId]], 'order_id_key', 'uid');
  27. if ($people > $count) {
  28. $refundData = [
  29. 'refund_reason' => '拼团时间超时',
  30. 'refund_explain' => '拼团时间超时',
  31. 'refund_img' => json_encode([]),
  32. ];
  33. foreach ($orderIds as $key => $item) {
  34. /** @var StoreOrderServices $orderService */
  35. $orderService = app()->make(StoreOrderServices::class);
  36. $order = $orderService->get($item);
  37. /** @var StoreOrderRefundServices $orderRefundService */
  38. $orderRefundService = app()->make(StoreOrderRefundServices::class);
  39. $orderRefundService->applyRefund((int)$order['id'], (int)$order['uid'], $order, [], 1, (float)$order['pay_price'], $refundData, 1);
  40. $pinkService->update([['id|k_id', '=', $pinkId]], ['status' => 3]);
  41. $pinkService->orderPinkAfterNo($key, $pinkId, false, $order->is_channel);
  42. }
  43. return true;
  44. }
  45. return true;
  46. }
  47. }