| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace addons\Store\common\services;
- use addons\Store\common\enums\BossEnum;
- use addons\Store\common\enums\WithdrawEnum;
- use addons\Store\common\models\StoreWithdrawLog;
- use common\enums\StatusEnum;
- use common\enums\WithdrawWayEnum;
- use common\logic\common\PaymentLogic;
- class FinanceService extends BaseService
- {
- /**
- * 提现列表
- *
- * @param int $type 0审核中 1已完成
- * @param int $limit
- * @param $platform
- * @return array
- */
- public function getWithdrawList(int $type, int $limit, $platform): array
- {
- $where = [
- [
- 'store_id' => $this->store_id,
- 'status' => StatusEnum::ENABLED
- ]
- ];
- $where[] = !$type ? ['withdraw_status' => $type] : ['in', 'withdraw_status', [1, 2]];
- $list = StoreWithdrawLog::listPage([
- 'where' => $where,
- 'order' => 'id desc',
- 'select' => 'id, num, actual_num, poundage_num, type, withdraw_status, created_at, remark',
- 'limit' => $limit
- ]);
- // 提现方式
- $type_map = PaymentLogic::getWithdrawTypeMap($this->mall_id);
- // 因为微信提现需要客户点击确认:所以此处传递微信打款信息给前端
- $storeWithdrawLogIds = array_column($list['list'], 'id');
- // 关联微信打款查询
- $wechatTransferList = \common\models\wechat\WechatTransferLog::find()
- ->select('wechatLog.*')
- ->alias("wechatLog")
- ->innerJoin(\common\models\common\PaymentTransfer::tableName() . ' as payT', 'payT.order_no = wechatLog.out_trade_no')
- ->where(['payT.withdrawal_source_id' => $storeWithdrawLogIds, 'payT.withdrawal_source' => BossEnum::ADDONS_NAME])
- ->indexBy('cash_id')
- ->asArray()
- ->all();
- // 判断需要查询的字段
- $wechatSearch = $platform == 'mp-wx' ? 'mini_program' : 'wechat';
- $wechatProgram = \Yii::$app->services->setting->mall->get($this->mall_id, $wechatSearch, true);
- $appId = $wechatProgram['app_id'] ?? '';
- array_walk($list['list'], function (&$item) use ($type_map, $wechatTransferList, $appId) {
- $item['transfer_result'] = [];
- if (isset($wechatTransferList[$item['id']])) {
- $payment_conf = \Yii::$app->services->setting->mall->get($this->mall_id, 'pay.wechat', true);
- $payment_conf = json_decode($payment_conf, true);
- $mchId = $payment_conf['wechat_mch_id'] ?? '';
- $wechat_transfer = $wechatTransferList[$item['id']];
- $transfer_result = json_decode($wechat_transfer['transfer_result'], true);
- $transfer_result['mchId'] = $mchId;
- $transfer_result['appId'] = $appId;
- $item['transfer_result'] = $transfer_result;
- }
- $item['created_at'] && $item['created_at_text'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['type_text'] = $type_map[$item['type']] ?? WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2)[$item['type']] ?? '-';
- $item['withdraw_status_text'] = WithdrawEnum::WITHDRAW_STATUS_MAP[$item['withdraw_status']] ?? '-';
- });
- return $list;
- }
- }
|