OrderSyncJob.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\order;
  12. use app\services\erp\OrderServices;
  13. use crmeb\basic\BaseJobs;
  14. use crmeb\traits\QueueTrait;
  15. use think\facade\Log;
  16. /**
  17. * Class OrderSyncJob
  18. * @package app\jobs\order
  19. */
  20. class OrderSyncJob extends BaseJobs
  21. {
  22. use QueueTrait;
  23. /**
  24. * @return mixed
  25. */
  26. public static function queueName()
  27. {
  28. return 'CRMEB_PRO_ERP';
  29. }
  30. /**
  31. * 同步订单
  32. * @param int $oid
  33. * @return bool
  34. */
  35. public function syncOrder(int $oid): bool
  36. {
  37. try{
  38. /** @var OrderServices $orderServices */
  39. $orderServices = app()->make(OrderServices::class);
  40. $orderServices->upload($oid);
  41. } catch (\Exception $e) {
  42. Log::error(['msg' => '订单信息同步失败,原因:' . $e->getMessage(), 'data' => ['oid' => $oid]]);
  43. }
  44. return true;
  45. }
  46. /**
  47. * 更新订单信息
  48. * @param string $orderId
  49. * @param string $erpOrderId
  50. * @param int $oid
  51. * @return bool
  52. */
  53. public function reorderOrder(string $orderId, array $erpOrderId = [], int $oid = 0): bool
  54. {
  55. try{
  56. /** @var OrderServices $orderServices */
  57. $orderServices = app()->make(OrderServices::class);
  58. $cancelRes = $orderServices->cancelOrder($orderId, $erpOrderId);
  59. if ($cancelRes && $oid > 0) {
  60. $orderServices->upload($oid);
  61. }
  62. } catch (\Exception $e) {
  63. Log::error(['msg' => '订单信息更新失败,原因:' . $e->getMessage(), 'data' => ['orderId' => $orderId, 'erpOrderId' => $erpOrderId, 'oid' => $oid]]);
  64. }
  65. return true;
  66. }
  67. /**
  68. * 回调取消
  69. * @param array $data
  70. * @return bool
  71. */
  72. public function refundOrder(array $data): bool
  73. {
  74. try{
  75. /** @var OrderServices $orderServices */
  76. $orderServices = app()->make(OrderServices::class);
  77. $orderServices->refundOrder($data);
  78. } catch (\Exception $e) {
  79. Log::error('回调订单取消同步失败,原因:' . $e->getMessage());
  80. }
  81. return true;
  82. }
  83. /**
  84. * 同步退货单
  85. * @param int $refundId
  86. * @return bool
  87. */
  88. public function refundOrderUpload(int $refundId): bool
  89. {
  90. try {
  91. /** @var OrderServices $orderServices */
  92. $orderServices = app()->make(OrderServices::class);
  93. $orderServices->refundOrderUpload([$refundId]);
  94. } catch (\Exception $e) {
  95. Log::error('同步退货单信息失败,原因:' . $e->getMessage());
  96. }
  97. return true;
  98. }
  99. }