CapitalFlowJob.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\jobs\system;
  3. use app\services\system\CapitalFlowServices;
  4. use app\services\user\UserServices;
  5. use crmeb\basic\BaseJobs;
  6. use crmeb\traits\QueueTrait;
  7. use think\facade\Log;
  8. /**
  9. * 平台资金流水记录
  10. * Class CapitalFlowJob
  11. * @package app\jobs\system
  12. */
  13. class CapitalFlowJob extends BaseJobs
  14. {
  15. use QueueTrait;
  16. /**
  17. * @param $order
  18. * @param $type
  19. * @return bool
  20. */
  21. public function doJob($order, $type)
  22. {
  23. if (!$order || !$type) {
  24. return true;
  25. }
  26. $data = [];
  27. try {
  28. switch ($type) {
  29. case 'order'://订单
  30. if (in_array($order['pay_type'], ['weixin', 'alipay', 'offline'])) {
  31. $userServices = app()->make(UserServices::class);
  32. $userInfo = $userServices->get($order['uid'], ['uid', 'nickname']);
  33. $data = [
  34. 'order_id' => $order['order_id'],
  35. 'store_id' => $order['store_id'] ?? 0,
  36. 'uid' => $order['uid'] ?? 0,
  37. 'nickname' => $userInfo['nickname'] ?? '游客' . time(),
  38. 'phone' => $order['phone'] ?? '',
  39. 'price' => $order['pay_price'],
  40. 'pay_type' => $order['pay_type'],
  41. ];
  42. }
  43. break;
  44. case 'refund'://退款
  45. //退款写入资金流水
  46. if (in_array($order['pay_type'], ['weixin', 'alipay', 'offline'])) {
  47. $userServices = app()->make(UserServices::class);
  48. $userInfo = $userServices->get($order['uid'], ['uid', 'nickname', 'phone']);
  49. //记录资金流水队列
  50. $data = [
  51. 'order_id' => $order['order_id'],
  52. 'store_id' => $order['store_id'],
  53. 'uid' => $order['uid'],
  54. 'nickname' => $userInfo['nickname'],
  55. 'phone' => $userInfo['phone'],
  56. 'price' => $order['refund_price'],
  57. 'pay_type' => $order['pay_type'],
  58. ];
  59. }
  60. break;
  61. case 'pay_member'://购买付费会员
  62. if ($order['pay_type'] != 'yue') {
  63. $userServices = app()->make(UserServices::class);
  64. $userInfo = $userServices->get($order['uid'], ['uid', 'nickname', 'phone']);
  65. $data = [
  66. 'order_id' => $order['order_id'],
  67. 'store_id' => 0,
  68. 'uid' => $order['uid'],
  69. 'nickname' => $userInfo['nickname'],
  70. 'phone' => $userInfo['phone'],
  71. 'price' => $order['pay_price'],
  72. 'pay_type' => $order['pay_type'],
  73. ];
  74. }
  75. break;
  76. case 'recharge'://充值
  77. $data = [
  78. 'order_id' => $order['order_id'],
  79. 'store_id' => $order['store_id'] ?? 0,
  80. 'uid' => $order['uid'],
  81. 'nickname' => $order['nickname'],
  82. 'phone' => $order['phone'],
  83. 'price' => $order['price'],
  84. 'pay_type' => $order['recharge_type'] ?? 'weixin',
  85. 'add_time' => time(),
  86. ];
  87. break;
  88. case 'refund_recharge'://充值退款
  89. $data = [
  90. 'order_id' => $order['order_id'],
  91. 'store_id' => $order['store_id'] ?? 0,
  92. 'uid' => $order['uid'],
  93. 'nickname' => $order['nickname'],
  94. 'phone' => $order['phone'],
  95. 'price' => $order['price'],
  96. 'pay_type' => $order['recharge_type'] ?? 'weixin',
  97. ];
  98. break;
  99. case 'extract'://提现
  100. $data = $order;
  101. break;
  102. case 'luck'://抽奖
  103. $data = $order;
  104. break;
  105. }
  106. if ($data) {
  107. /** @var CapitalFlowServices $capitalFlowServices */
  108. $capitalFlowServices = app()->make(CapitalFlowServices::class);
  109. $capitalFlowServices->setFlow($data, $type);
  110. }
  111. } catch (\Throwable $e) {
  112. Log::error('写入资金流水错误:[' . class_basename($this) . ']' . $e->getMessage());
  113. }
  114. return true;
  115. }
  116. }