PinkJob.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. use think\db\exception\DataNotFoundException;
  18. use think\db\exception\DbException;
  19. use think\db\exception\ModelNotFoundException;
  20. class PinkJob extends BaseJobs
  21. {
  22. use QueueTrait;
  23. public function doJob($pinkId)
  24. {
  25. /** @var StorePinkServices $pinkService */
  26. $pinkService = app()->make(StorePinkServices::class);
  27. $people = $pinkService->value(['id' => $pinkId], 'people');
  28. $count = $pinkService->count(['k_id' => $pinkId, 'is_refund' => 0]) + 1;
  29. $orderIds = $pinkService->getColumn([['id|k_id', '=', $pinkId]], 'order_id_key', 'uid');
  30. if ($people > $count) {
  31. $virtual = $pinkService->virtualCombination($pinkId);
  32. if ($virtual) return true;
  33. $refundData = [
  34. 'refund_reason' => '拼团时间超时',
  35. 'refund_explain' => '拼团时间超时',
  36. 'refund_img' => json_encode([]),
  37. ];
  38. foreach ($orderIds as $key => $item) {
  39. /** @var StoreOrderServices $orderService */
  40. $orderService = app()->make(StoreOrderServices::class);
  41. $order = $orderService->get($item);
  42. /** @var StoreOrderRefundServices $orderRefundService */
  43. $orderRefundService = app()->make(StoreOrderRefundServices::class);
  44. $orderRefundService->applyRefund((int)$order['id'], (int)$order['uid'], $order, [], 1, (float)$order['pay_price'], $refundData, 1);
  45. $pinkService->update([['id|k_id', '=', $pinkId]], ['status' => 3]);
  46. $pinkService->orderPinkAfterNo($key, $pinkId, false, $order->is_channel);
  47. }
  48. return true;
  49. }
  50. return true;
  51. }
  52. }