OutPushJob.php 5.4 KB

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