OutPushJob.php 4.8 KB

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