OutPushJob.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\jobs;
  3. use app\services\order\OutStoreOrderRefundServices;
  4. use app\services\order\OutStoreOrderServices;
  5. use crmeb\basic\BaseJobs;
  6. use crmeb\traits\QueueTrait;
  7. use think\facade\Log;
  8. class OutPushJob extends BaseJobs
  9. {
  10. use QueueTrait;
  11. /**
  12. * 订单推送
  13. * @param int $oid
  14. * @param string $pushUrl
  15. * @param int $step
  16. * @return bool
  17. */
  18. public function orderCreate(int $oid, string $pushUrl, int $step = 0): bool
  19. {
  20. if ($step > 2) {
  21. Log::error('订单' . $oid . '推送失败');
  22. return true;
  23. }
  24. try {
  25. /** @var OutStoreOrderServices $services */
  26. $services = app()->make(OutStoreOrderServices::class);
  27. if (!$services->orderCreatePush($oid, $pushUrl)) {
  28. OutPushJob::dispatchSece(($step + 1) * 5, 'orderCreate', [$oid, $pushUrl, $step + 1]);
  29. }
  30. } catch (\Exception $e) {
  31. Log::error('订单' . $oid . '推送失败,失败原因:' . $e->getMessage());
  32. OutPushJob::dispatchSece(($step + 1) * 5, 'orderCreate', [$oid, $pushUrl, $step + 1]);
  33. }
  34. return true;
  35. }
  36. /**
  37. * 订单支付推送
  38. * @param int $oid
  39. * @param string $pushUrl
  40. * @param int $step
  41. * @return bool
  42. */
  43. public function paySuccess(int $oid, string $pushUrl, int $step = 0): bool
  44. {
  45. if ($step > 2) {
  46. Log::error('订单支付' . $oid . '推送失败');
  47. return true;
  48. }
  49. try {
  50. /** @var OutStoreOrderServices $services */
  51. $services = app()->make(OutStoreOrderServices::class);
  52. if (!$services->paySuccessPush($oid, $pushUrl)) {
  53. OutPushJob::dispatchSece(($step + 1) * 5, 'paySuccess', [$oid, $pushUrl, $step + 1]);
  54. }
  55. } catch (\Exception $e) {
  56. Log::error('订单支付' . $oid . '推送失败,失败原因:' . $e->getMessage());
  57. OutPushJob::dispatchSece(($step + 1) * 5, 'paySuccess', [$oid, $pushUrl, $step + 1]);
  58. }
  59. return true;
  60. }
  61. /**
  62. * 售后单生成
  63. * @param int $oid
  64. * @param string $pushUrl
  65. * @param int $step
  66. * @return bool
  67. */
  68. public function refundCreate(int $oid, string $pushUrl, int $step = 0): bool
  69. {
  70. if ($step > 2) {
  71. Log::error('售后单' . $oid . '推送失败');
  72. return true;
  73. }
  74. try {
  75. /** @var OutStoreOrderRefundServices $services */
  76. $services = app()->make(OutStoreOrderRefundServices::class);
  77. if (!$services->refundCreatePush($oid, $pushUrl)) {
  78. OutPushJob::dispatchSece(($step + 1) * 5, 'refundCreate', [$oid, $pushUrl, $step + 1]);
  79. }
  80. } catch (\Exception $e) {
  81. Log::error('售后单' . $oid . '推送失败,失败原因:' . $e->getMessage());
  82. OutPushJob::dispatchSece(($step + 1) * 5, 'refundCreate', [$oid, $pushUrl, $step + 1]);
  83. }
  84. return true;
  85. }
  86. /**
  87. * 取消申请
  88. * @param int $oid
  89. * @param string $pushUrl
  90. * @param int $step
  91. * @return bool
  92. */
  93. public function refundCancel(int $oid, string $pushUrl, int $step = 0): bool
  94. {
  95. if ($step > 2) {
  96. Log::error('取消售后单' . $oid . '推送失败');
  97. return true;
  98. }
  99. try {
  100. /** @var OutStoreOrderRefundServices $services */
  101. $services = app()->make(OutStoreOrderRefundServices::class);
  102. if (!$services->cancelApplyPush($oid, $pushUrl)) {
  103. OutPushJob::dispatchSece(($step + 1) * 5, 'refundCancel', [$oid, $pushUrl, $step + 1]);
  104. }
  105. } catch (\Exception $e) {
  106. Log::error('取消售后单' . $oid . '推送失败,失败原因:' . $e->getMessage());
  107. OutPushJob::dispatchSece(($step + 1) * 5, 'refundCancel', [$oid, $pushUrl, $step + 1]);
  108. }
  109. return true;
  110. }
  111. }