FinanceService.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace addons\Store\common\services;
  3. use addons\Store\common\enums\BossEnum;
  4. use addons\Store\common\enums\WithdrawEnum;
  5. use addons\Store\common\models\StoreWithdrawLog;
  6. use common\enums\StatusEnum;
  7. use common\enums\WithdrawWayEnum;
  8. use common\logic\common\PaymentLogic;
  9. class FinanceService extends BaseService
  10. {
  11. /**
  12. * 提现列表
  13. *
  14. * @param int $type 0审核中 1已完成
  15. * @param int $limit
  16. * @param $platform
  17. * @return array
  18. */
  19. public function getWithdrawList(int $type, int $limit, $platform): array
  20. {
  21. $where = [
  22. [
  23. 'store_id' => $this->store_id,
  24. 'status' => StatusEnum::ENABLED
  25. ]
  26. ];
  27. $where[] = !$type ? ['withdraw_status' => $type] : ['in', 'withdraw_status', [1, 2]];
  28. $list = StoreWithdrawLog::listPage([
  29. 'where' => $where,
  30. 'order' => 'id desc',
  31. 'select' => 'id, num, actual_num, poundage_num, type, withdraw_status, created_at, remark',
  32. 'limit' => $limit
  33. ]);
  34. // 提现方式
  35. $type_map = PaymentLogic::getWithdrawTypeMap($this->mall_id);
  36. // 因为微信提现需要客户点击确认:所以此处传递微信打款信息给前端
  37. $storeWithdrawLogIds = array_column($list['list'], 'id');
  38. // 关联微信打款查询
  39. $wechatTransferList = \common\models\wechat\WechatTransferLog::find()
  40. ->select('wechatLog.*')
  41. ->alias("wechatLog")
  42. ->innerJoin(\common\models\common\PaymentTransfer::tableName() . ' as payT', 'payT.order_no = wechatLog.out_trade_no')
  43. ->where(['payT.withdrawal_source_id' => $storeWithdrawLogIds, 'payT.withdrawal_source' => BossEnum::ADDONS_NAME])
  44. ->indexBy('cash_id')
  45. ->asArray()
  46. ->all();
  47. // 判断需要查询的字段
  48. $wechatSearch = $platform == 'mp-wx' ? 'mini_program' : 'wechat';
  49. $wechatProgram = \Yii::$app->services->setting->mall->get($this->mall_id, $wechatSearch, true);
  50. $appId = $wechatProgram['app_id'] ?? '';
  51. array_walk($list['list'], function (&$item) use ($type_map, $wechatTransferList, $appId) {
  52. $item['transfer_result'] = [];
  53. if (isset($wechatTransferList[$item['id']])) {
  54. $payment_conf = \Yii::$app->services->setting->mall->get($this->mall_id, 'pay.wechat', true);
  55. $payment_conf = json_decode($payment_conf, true);
  56. $mchId = $payment_conf['wechat_mch_id'] ?? '';
  57. $wechat_transfer = $wechatTransferList[$item['id']];
  58. $transfer_result = json_decode($wechat_transfer['transfer_result'], true);
  59. $transfer_result['mchId'] = $mchId;
  60. $transfer_result['appId'] = $appId;
  61. $item['transfer_result'] = $transfer_result;
  62. }
  63. $item['created_at'] && $item['created_at_text'] = date('Y-m-d H:i:s', $item['created_at']);
  64. $item['type_text'] = $type_map[$item['type']] ?? WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2)[$item['type']] ?? '-';
  65. $item['withdraw_status_text'] = WithdrawEnum::WITHDRAW_STATUS_MAP[$item['withdraw_status']] ?? '-';
  66. });
  67. return $list;
  68. }
  69. }