| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592 |
- <?php
- namespace addons\JoinPay\backend\controllers;
- use addons\JoinPay\common\enums\AddonsJoinPayEnum;
- use addons\JoinPay\common\enums\JoinPayTypeEnum;
- use addons\JoinPay\common\models\JoinpayFastpayOrder;
- use addons\JoinPay\common\models\JoinPayUserBankcard;
- use addons\Mch\common\models\MchWithdrawLog;
- use addons\Store\common\models\StoreWithdrawLog;
- use common\enums\AddonsEnum;
- use common\enums\ApiStatusEnum;
- use common\enums\DownloadEnum;
- use common\enums\PayTypeEnum;
- use common\enums\StatusEnum;
- use common\enums\WithdrawWayEnum;
- use common\helpers\csv\CsvExportHelper;
- use common\helpers\StringHelper;
- use common\models\common\PaidSinglePayLog;
- use common\models\common\PaymentTrade;
- use common\models\common\PaymentTradeOrder;
- use common\models\mall\MallAddons;
- use common\models\user\User;
- use common\models\user\UserWithdrawLog;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\JoinPay\backend\controllers
- */
- class DefaultController extends BaseController
- {
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
- // $wechat = \Yii::$app->services->setting->mall->get($this->mall_id, 'wechat');
- if (empty($settings)) $settings = null;
- if (!empty($settings['joinpay_channel_alternative'])) $settings['joinpay_channel_alternative'] = json_decode($settings['joinpay_channel_alternative'], true);
- if (!empty($settings['joinpay_trade_channel'])) $settings['joinpay_trade_channel'] = json_decode($settings['joinpay_trade_channel'], true);
- !empty($settings['price_limit_exceed_trades']) && $settings['price_limit_exceed_trades'] = json_decode($settings['price_limit_exceed_trades'], true);
- !empty($settings['price_limit_normal_trades']) && $settings['price_limit_normal_trades'] = json_decode($settings['price_limit_normal_trades'], true);
- !empty($settings['joinpay_app_trades']) && $settings['joinpay_app_trades'] = json_decode($settings['joinpay_app_trades'], true);
- !empty($settings['joinpay_h5_trades']) && $settings['joinpay_h5_trades'] = json_decode($settings['joinpay_h5_trades'], true);
- !empty($settings['joinpay_wechat_trades']) && $settings['joinpay_wechat_trades'] = json_decode($settings['joinpay_wechat_trades'], true);
- !empty($settings['joinpay_mp_wx_trades']) && $settings['joinpay_mp_wx_trades'] = json_decode($settings['joinpay_mp_wx_trades'], true);
- !empty($settings['joinpay_merchant_wechat']) && $settings['joinpay_merchant_wechat'] = json_decode($settings['joinpay_merchant_wechat'], true);
- !empty($settings['joinpay_merchant_alipay']) && $settings['joinpay_merchant_alipay'] = json_decode($settings['joinpay_merchant_alipay'], true);
- $platform_setting = JoinPayTypeEnum::getTypeByPlatform(null);
- $trade_setting = [];
- $trade_tips = [];
- foreach ($platform_setting as $platform => $rows) {
- $trade_arr_temp = [];
- $tips_text = [];
- if (is_array($rows)) {
- $tips_by_trade = [];
- foreach ($rows as $v) {
- $trade_key = JoinPayTypeEnum::getJoinpayTradeMap($v);
- $trade_arr_temp[] = $trade_key;
- empty($tips_by_trade[$trade_key]) && $tips_by_trade[$trade_key] = [];
- $tips_by_trade[$trade_key][] = $v;
- }
- foreach ($tips_by_trade as $k => $trade_arr) {
- $tips_text[] = $k . ':' . join('、', $trade_arr);
- }
- }else{
- $trade_key = JoinPayTypeEnum::getJoinpayTradeMap($rows);
- $trade_arr_temp[] = $trade_key;
- $tips_text[] = $trade_key . ':' . $rows;
- }
- $tips_text = join(',', $tips_text);
- $trade_arr_temp = array_unique($trade_arr_temp);
- $trade_setting[$platform] = [];
- foreach ($trade_arr_temp as $trade_temp) {
- $trade_setting[$platform][] = [
- 'label' => JoinPayTypeEnum::getJoinpayTradeNameMap($trade_temp),
- 'value' => $trade_temp
- ];
- }
- $trade_setting[$platform][] = [
- 'label' => JoinPayTypeEnum::getJoinpayTradeNameMap(JoinPayTypeEnum::JOINPAY_TRADE_FASTPAY),
- 'value' => JoinPayTypeEnum::JOINPAY_TRADE_FASTPAY
- ];
- $trade_name_arr = JoinPayTypeEnum::getJoinpayTradeNameMap();
- foreach ($trade_name_arr as $trade_key => $trade_name) {
- $tips_text = str_replace($trade_key, $trade_name, $tips_text);
- }
- !empty($tips_text) && $tips_text = '需开通交易类型:' . $tips_text;
- $trade_tips[$platform] = $tips_text;
- }
- $tactics_pay_setting = [];
- if (MallAddons::isInstall($this->mall_id, 'TacticsPay')) {
- $tactics_pay_setting = [
- 'is_installed' => 1,
- 'more_wechat_field' => JoinPayTypeEnum::getMoreMerchantWechatField(),
- 'more_alipay_field' => JoinPayTypeEnum::getMoreMerchantAlipayField()
- ];
- }
- return $this->success('success', ['settings' => $settings, 'trade_setting' => $trade_setting, 'trade_tips' => $trade_tips, 'tactics_pay_setting' => $tactics_pay_setting]);
- } else {
- $post = \Yii::$app->request->post();
- $rules = [
- [['joinpay_status', 'joinpay_merchant_no', 'joinpay_merchant_secret', 'joinpay_fast_pay_status', 'joinpay_fast_pay_private_key', 'joinpay_fast_pay_public_key', 'joinpay_trade_channel', 'joinpay_wechat_trade_name', 'joinpay_alipay_trade_name', 'joinpay_unionpay_trade_name', 'joinpay_alternative_status', 'joinpay_fastpay_trade_name', 'joinpay_wechat_xcx_trade_merchant_no', 'joinpay_wechat_xcx_appid', 'joinpay_wechat_gzh_trade_merchant_no', 'joinpay_wechat_gzh_appid', 'joinpay_alipay_trade_merchant_no', 'price_limit_open', 'joinpay_platform_app_open', 'joinpay_platform_h5_open', 'joinpay_platform_wechat_open', 'joinpay_platform_mp_wx_open'], 'required'],
- [['joinpay_status', 'joinpay_alternative_status', 'joinpay_fast_pay_status', 'joinpay_wechat_gzh_trade_merchant_no', 'joinpay_wechat_xcx_trade_merchant_no', 'joinpay_alipay_trade_merchant_no', 'joinpay_app3_trade_merchant_no', 'joinpay_unionpay_trade_merchant_no', 'price_limit_open', 'joinpay_platform_app_open', 'joinpay_platform_h5_open', 'joinpay_platform_wechat_open', 'joinpay_platform_mp_wx_open', 'joinpay_more_merchant_enable', 'not_to_examine'], 'integer'],
- [['joinpay_status', 'joinpay_alternative_status', 'joinpay_fast_pay_status', 'price_limit_open', 'joinpay_platform_app_open', 'joinpay_platform_h5_open', 'joinpay_platform_wechat_open', 'joinpay_platform_mp_wx_open'], 'default', 'value' => 0],
- [['joinpay_merchant_no', 'joinpay_merchant_secret', 'joinpay_fast_pay_public_key', 'joinpay_fast_pay_private_key', 'joinpay_wechat_trade_name', 'joinpay_alipay_trade_name', 'joinpay_unionpay_trade_name', 'joinpay_fastpay_trade_name', 'joinpay_wechat_gzh_appid', 'joinpay_wechat_xcx_appid'], 'string'],
- [['joinpay_wechat_trade_name', 'joinpay_alipay_trade_name', 'joinpay_fastpay_trade_name'], 'string', 'max' => 10],
- [['joinpay_channel_alternative', 'price_limit_exceed_trades', 'price_limit_normal_trades', 'joinpay_app_trades', 'joinpay_h5_trades', 'joinpay_wechat_trades', 'joinpay_mp_wx_trades', 'joinpay_merchant_wechat', 'joinpay_merchant_alipay'], 'safe'],
- [['price_limit_exceed_price'], 'number']
- ];
- if (empty($post['joinpay_trade_channel']) || !is_array($post['joinpay_trade_channel'])) return $this->error('汇聚支付渠道填写错误');
- // if (1 == $post['joinpay_alternative_status'] && (empty($post['joinpay_channel_alternative']) || !is_array($post['joinpay_channel_alternative']))) return $this->error('代付支付渠道填写错误');
- // if ((empty($post['joinpay_channel_alternative']) || !is_array($post['joinpay_channel_alternative']))) return $this->error('代付支付渠道填写错误');
- $res = \Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // 支付配置同时写入商城配置
- $joinpay_configs = [
- 'status' => $post['joinpay_status'],
- 'merchant_no' => $post['joinpay_merchant_no'],
- // 'trade_merchant_no' => $post['joinpay_trade_merchant_no'],
- 'merchant_secret' => $post['joinpay_merchant_secret'],
- 'wechat_app_id' => $post['joinpay_wechat_app_id'] ?? '',
- 'wechat_gzh_trade_merchant_no' => $post['joinpay_wechat_gzh_trade_merchant_no'],
- 'wechat_gzh_appid' => $post['joinpay_wechat_gzh_appid'],
- 'wechat_xcx_trade_merchant_no' => $post['joinpay_wechat_xcx_trade_merchant_no'],
- 'wechat_xcx_appid' => $post['joinpay_wechat_xcx_appid'],
- 'alipay_trade_merchant_no' => $post['joinpay_alipay_trade_merchant_no'],
- 'app3_trade_merchant_no' => $post['joinpay_app3_trade_merchant_no'],
- 'unionpay_trade_merchant_no' => $post['joinpay_unionpay_trade_merchant_no']
- ];
- $fastpay_configs = [
- 'status' => $post['joinpay_fast_pay_status'],
- 'merchant_no' => $post['joinpay_merchant_no'],
- 'fast_pay_private_key' => $post['joinpay_fast_pay_private_key'],
- 'fast_pay_public_key' => $post['joinpay_fast_pay_public_key'],
- ];
- // 组合多商户配置默认信息(微信)
- $more_wechat_field = array_column(JoinPayTypeEnum::getMoreMerchantWechatField(), 'key');
- $sys_wechat_merchant_id = PayTypeEnum::JOINPAY . str_repeat('0', 11 - strlen(PayTypeEnum::JOINPAY)) . '0';
- !isset($post['joinpay_merchant_wechat']) && $post['joinpay_merchant_wechat'] = [];
- $temp_merchant_wechat = array_column($post['joinpay_merchant_wechat'], null, 'merchant_id');
- if (isset($temp_merchant_wechat[$sys_wechat_merchant_id])) {
- foreach ($more_wechat_field as $key) {
- $temp_merchant_wechat[$sys_wechat_merchant_id][$key] = $joinpay_configs[$key] ?? '';
- }
- $temp_merchant_wechat[$sys_wechat_merchant_id]['is_sys'] = true;
- $post['joinpay_merchant_wechat'] = array_values($temp_merchant_wechat);
- }else {
- $field_row = ['merchant_id' => $sys_wechat_merchant_id];
- foreach ($more_wechat_field as $key) {
- $field_row[$key] = $joinpay_configs[$key] ?? '';
- }
- $field_row['is_sys'] = true;
- array_unshift($post['joinpay_merchant_wechat'], $field_row);
- }
- // 组合多商户配置默认信息(支付宝)
- $more_alipay_field = array_column(JoinPayTypeEnum::getMoreMerchantAlipayField(), 'key');
- $sys_alipay_merchant_id = PayTypeEnum::JOINPAY . str_repeat('0', 11 - strlen(PayTypeEnum::JOINPAY)) . '1';
- !isset($post['joinpay_merchant_alipay']) && $post['joinpay_merchant_alipay'] = [];
- $temp_merchant_alipay = array_column($post['joinpay_merchant_alipay'], null, 'merchant_id');
- if (isset($temp_merchant_alipay[$sys_alipay_merchant_id])) {
- foreach ($more_alipay_field as $key) {
- $temp_merchant_alipay[$sys_alipay_merchant_id][$key] = $joinpay_configs[$key] ?? '';
- }
- $temp_merchant_alipay[$sys_alipay_merchant_id]['is_sys'] = true;
- $post['joinpay_merchant_alipay'] = array_values($temp_merchant_alipay);
- }else {
- $field_row = ['merchant_id' => $sys_alipay_merchant_id];
- foreach ($more_alipay_field as $key) {
- $field_row[$key] = $joinpay_configs[$key] ?? '';
- }
- $field_row['is_sys'] = true;
- array_unshift($post['joinpay_merchant_alipay'], $field_row);
- }
- $configs = [
- 'basic' => $post,
- ];
- \Yii::$app->services->setting->addons->set($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, $configs);
- $data = [
- 'pay' => [
- 'joinpay' => json_encode($joinpay_configs),
- 'joinpay_fast' => json_encode($fastpay_configs),
- ],
- ];
- \Yii::$app->services->setting->mall->set($this->mall_id, $data);
- }
- return $this->success('保存成功', $post);
- }
- return $this->render('index');
- }
- public function actionBasicSetting()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $group = \Yii::$app->request->get('group');
- if (empty($group) || !in_array($group, ['basic', 'fastpay'])) return $this->error('参数错误');
- $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, $group);
- return $this->success('success', ['settings' => $settings]);
- } else {
- $post = \Yii::$app->request->post();
- $group = $post['group'] ?? '';
- if (empty($group) || !in_array($group, ['basic', 'fastpay']) || empty($post[$group])) return $this->error('参数错误');
- $rules = [
- 'basic' => [
- [['joinpay_status', 'joinpay_merchant_no', 'joinpay_merchant_secret', 'joinpay_trade_merchant_no', 'joinpay_wechat_app_id', 'joinpay_mp_wx_open', 'joinpay_wechat_open', 'joinpay_wechat_h5_open', 'joinpay_alipay_h5_open', 'joinpay_wechat_app_open', 'joinpay_alipay_app_open'], 'required'],
- [['joinpay_status', 'joinpay_mp_wx_open', 'joinpay_wechat_open', 'joinpay_wechat_h5_open', 'joinpay_alipay_h5_open', 'joinpay_alipay_app_open', 'joinpay_wechat_app_open'], 'integer'],
- [['joinpay_status', 'joinpay_mp_wx_open', 'joinpay_wechat_open', 'joinpay_wechat_h5_open', 'joinpay_alipay_h5_open', 'joinpay_alipay_app_open', 'joinpay_wechat_app_open'], 'default', 'value' => 0],
- [['joinpay_merchant_no', 'joinpay_merchant_secret', 'joinpay_trade_merchant_no', 'joinpay_wechat_app_id'], 'string'],
- ],
- 'fastpay' => [
- [['joinpay_fast_pay_status', 'joinpay_fast_pay_private_key', 'joinpay_fast_pay_public_key'], 'required'],
- ['joinpay_fast_pay_status', 'integer'],
- ['joinpay_fast_pay_status', 'default', 'value' => 0],
- [['joinpay_fast_pay_public_key', 'joinpay_fast_pay_private_key'], 'string']
- ],
- ];
- $res = \Yii::$app->services->validate->validate($post[$group], $rules[$group]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // dd($post);
- $configs = [
- $group => $post[$group],
- ];
- \Yii::$app->services->setting->addons->set($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, $configs);
- // 支付配置同时写入商城配置
- if ('basic' == $group) {
- // joinpay
- $joinpay_configs = [
- 'status' => $post['basic']['joinpay_status'],
- 'merchant_no' => $post['basic']['joinpay_merchant_no'],
- 'trade_merchant_no' => $post['basic']['joinpay_trade_merchant_no'],
- 'merchant_secret' => $post['basic']['joinpay_merchant_secret'],
- 'wechat_app_id' => $post['basic']['joinpay_wechat_app_id'],
- ];
- $data = [
- 'pay' => [
- 'joinpay' => json_encode($joinpay_configs),
- ],
- ];
- \Yii::$app->services->setting->mall->set($this->mall_id, $data);
- } else {
- $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
- $fastpay_configs = [
- 'status' => $post['fastpay']['joinpay_fast_pay_status'],
- 'merchant_no' => $settings['joinpay_merchant_no'],
- 'fast_pay_private_key' => $post['fastpay']['joinpay_fast_pay_private_key'],
- 'fast_pay_public_key' => $post['fastpay']['joinpay_fast_pay_public_key'],
- ];
- $data = [
- 'pay' => [
- 'joinpay_fast' => json_encode($fastpay_configs),
- ],
- ];
- \Yii::$app->services->setting->mall->set($this->mall_id, $data);
- }
- return $this->success('保存成功');
- }
- }
- return $this->render('/config/basic-setting');
- }
- public function actionFastpaySetting()
- {
- return $this->render('/config/fastpay-setting');
- }
- public function actionPayRecord()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $order_no = \Yii::$app->request->get('order_no');
- $start_time = \Yii::$app->request->get('start_time');
- $end_time = \Yii::$app->request->get('end_time');
- $user_id = \Yii::$app->request->get('user_id');
- $user_keyword = \Yii::$app->request->get('user_keyword');
- $out_trade_no = \Yii::$app->request->get('out_trade_no');
- $pay_type = \Yii::$app->request->get('pay_type');
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $wheres[] = ['mall_id' => $this->mall_id];
- if (empty($pay_type)) {
- $wheres[] = ['pay_type' => [7, 8]];
- } else {
- if (!in_array($pay_type, [7, 8])) {
- return $this->error('参数错误');
- }
- $wheres[] = ['pay_type' => $pay_type];
- }
- if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . '00:00:00')];
- if (!empty($end_time)) $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')];
- if (!empty($out_trade_no)) $wheres[] = ['like', 'out_trade_no', $out_trade_no];
- if (!empty($user_id)) $wheres[] = ['user_id' => $user_id];
- if (!empty($user_keyword)) {
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['or', ['like', 'nickname', $user_keyword], ['like', 'mobile', $user_keyword]])
- ->asArray()
- ->indexBy('id')
- ->all();
- $user_ids = array_column($users, 'id');
- $wheres[] = ['user_id' => $user_ids];
- }
- $trade_ids = [];
- if (!empty($order_no)) {
- $payment_order_logs = PaymentTradeOrder::find()
- ->select('trade_id,order_no')
- ->where(['order_no' => $order_no])
- ->asArray()
- ->indexBy('trade_id')
- ->all();
- $trade_ids = array_column($payment_order_logs, 'trade_id');
- $wheres[] = ['id' => $trade_ids];
- }
- $params = [
- 'select' => 'id,mall_id,user_id,out_trade_no,pay_fee as amount,is_pay,pay_type,created_at,updated_at',
- 'where' => $wheres,
- 'order' => 'created_at desc,updated_at desc',
- 'page' => $page,
- 'limit' => $limit
- ];
- $pay_records = PaymentTrade::listPage($params);
- if (empty($pay_records['list'])) {
- if (false === $pay_records['list']) {
- return $this->error(PaymentTrade::getStaticError());
- }
- return $this->success('success', $pay_records);
- }
- if (empty($users)) {
- $user_ids = array_column($pay_records['list'], 'user_id');
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['id' => $user_ids, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- if (empty($payment_order_logs)) {
- $trade_ids = array_column($pay_records['list'], 'id');
- $payment_order_logs = PaymentTradeOrder::find()
- ->select('trade_id,order_no')
- ->where(['trade_id' => $trade_ids])
- ->asArray()
- ->indexBy('trade_id')
- ->all();
- }
- foreach ($pay_records['list'] as &$record) {
- $user = $users[$record['user_id']] ?? [];
- $payment_order_log = $payment_order_logs[$record['id']] ?? [];
- $record['nickname'] = $user['nickname'] ?? '默认会员';
- $record['avatar_url'] = $user['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- $record['mobile'] = $user['mobile'] ?? '';
- $record['order_no'] = $payment_order_log['order_no'] ?? '';
- }
- $pay_records['export_list'] = JoinpayFastpayOrder::fieldsList();
- return $this->success('success', $pay_records);
- }
- if(\Yii::$app->request->post('flag') == 'EXPORT'){
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $filename = '支付记录-' . date('YmdHis').'_'.rand(10000,99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ORDERS,JoinpayFastpayOrder::class,'exportHandle',$post);
- if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- return $this->render('/pay-record/index');
- }
- public function actionAlternativePayRecord()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $order_no = \Yii::$app->request->get('order_no');
- $start_time = \Yii::$app->request->get('start_time');
- $end_time = \Yii::$app->request->get('end_time');
- $receive_keyword = \Yii::$app->request->get('receive_keyword');
- $account_type = \Yii::$app->request->get('account_type');
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $wheres[] = ['mall_id' => $this->mall_id];
- if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . '00:00:00')];
- if (!empty($end_time)) $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')];
- if (!empty($order_no)) $wheres[] = ['like', 'merchant_order_no', $order_no];
- if (!empty($receive_keyword)) {
- $wheres[] = ['or', ['like', 'receive_name', $receive_keyword], ['like', 'receive_account', $receive_keyword]];
- }
- if (!empty($account_type)) $wheres[] = ['account_type' => $account_type];
- $params = [
- 'select' => 'id,mall_id,order_no,receive_account,receive_name,account_type,amount,currency,paid_desc,status,error_msg,merchant_order_no,created_at,updated_at,source',
- 'where' => $wheres,
- 'order' => 'created_at desc,updated_at desc',
- 'page' => $page,
- 'limit' => $limit
- ];
- $alternative_records = PaidSinglePayLog::listPage($params);
- if (empty($alternative_records['list'])) {
- if (false === $alternative_records['list']) {
- return $this->error(PaidSinglePayLog::getStaticError());
- }
- return $this->success('success', $alternative_records);
- }
- $order_no_arr = [];
- $store_withdraw_order_no_arr = [];
- $mch_withdraw_order_no_arr = [];
- foreach ($alternative_records['list'] as $item){
- switch ($item['source']){
- case '2':
- $store_withdraw_order_no_arr[]=$item['order_no'];
- break;
- case '3':
- $mch_withdraw_order_no_arr[]=$item['order_no'];
- break;
- default:
- $order_no_arr[]=$item['order_no'];
- }
- }
- $user_ids = [];
- if(!empty($order_no_arr)){
- $withdraw_logs = UserWithdrawLog::find()
- ->select('order_no,user_id')
- ->where(['mall_id' => $this->mall_id, 'order_no' => $order_no_arr, 'type' => WithdrawWayEnum::JOINPAY])
- ->indexBy('order_no')
- ->asArray()
- ->all();
- $user_ids = array_merge($user_ids,array_column($withdraw_logs, 'user_id'));
- }
- if(!empty($store_withdraw_order_no_arr)){
- if(MallAddons::isInstall($this->mall_id,'Store')){
- $store_withdraw_logs = StoreWithdrawLog::lists(['where'=>[['order_no'=>$store_withdraw_order_no_arr]],'index'=>'order_no']);
- $user_ids = array_merge($user_ids,array_column($store_withdraw_logs, 'user_id'));
- }
- }
- if(!empty($mch_withdraw_order_no_arr)){
- if(MallAddons::isInstall($this->mall_id,'Mch')){
- $mch_withdraw_logs = MchWithdrawLog::lists(['where'=>[['order_no'=>$mch_withdraw_order_no_arr]],'index'=>'order_no']);
- $user_ids = array_merge($user_ids,array_column($mch_withdraw_logs, 'user_id'));
- }
- }
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
- ->indexBy('id')
- ->asArray()
- ->all();
- $handle_status_map = AddonsJoinPayEnum::getHandleStatusMap();
- $account_type_map = AddonsJoinPayEnum::getAccountTypeMap();
- foreach ($alternative_records['list'] as &$record) {
- $record['status_text'] = $handle_status_map[$record['status']];
- if (AddonsJoinPayEnum::HANDLE_STATUS2 == $record['status']) $record['status_text'] .= ': ' . $record['error_msg'];
- $record['account_type_text'] = $account_type_map[$record['account_type']];
- if (AddonsJoinPayEnum::CURRENCY_DOLLAR == $record['currency']) {
- $record['amount'] = '$' . floatval($record['amount']);
- } elseif (AddonsJoinPayEnum::CURRENCY_RMB == $record['currency']) {
- $record['amount'] = '¥' . floatval($record['amount']);
- }
- switch ($record['source']){
- case '2':
- $withdraw_log = $store_withdraw_logs[$record['order_no']] ?? [];
- break;
- case '3':
- $withdraw_log = $mch_withdraw_logs[$record['order_no']] ?? [];
- break;
- default:
- $withdraw_log = $withdraw_logs[$record['order_no']] ?? [];
- }
- $user_id = $withdraw_log['user_id'] ?? 0;
- $user = $users[$user_id] ?? [];
- $record['user_id'] = $user['id'] ?? 0;
- $record['nickname'] = $user['nickname'] ?? '默认会员 ';
- $record['avatar_url'] = $user['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- }
- $alternative_records['export_list'] = JoinpayFastpayOrder::fieldsListPay();
- return $this->success('success', $alternative_records);
- }
- if(\Yii::$app->request->post('flag') == 'EXPORT'){
- $post = \Yii::$app->request->post();
- $post['mall_id'] = $this->mall_id;
- $filename = '代付记录-' . date('YmdHis').'_'.rand(10000,99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ORDERS,JoinpayFastpayOrder::class,'exportHandlePay',$post);
- if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- return $this->render('/alternative-pay/index');
- }
- public function actionSignRecord()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $card_no = \Yii::$app->request->get('card_no');
- $start_time = \Yii::$app->request->get('start_time');
- $end_time = \Yii::$app->request->get('end_time');
- $user_id = \Yii::$app->request->get('user_id');
- $user_keyword = \Yii::$app->request->get('user_keyword');
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'is_sign' => 1];
- if (!empty($card_no)) $wheres[] = ['like', 'bank_card_no', $card_no];
- if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . '00:00:00')];
- if (!empty($end_time)) $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')];
- if (!empty($user_id)) $wheres[] = ['user_id' => $user_id];
- if (!empty($user_keyword)) {
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['or', ['like', 'nickname', $user_keyword], ['like', 'mobile', $user_keyword]])
- ->asArray()
- ->indexBy('id')
- ->all();
- $user_ids = array_column($users, 'id');
- $wheres[] = ['user_id' => $user_ids];
- }
- $params = [
- 'select' => 'id,mall_id,user_id,card_id,bank_name,bank_card_no,mobile_no,card_type_name,created_at,updated_at',
- 'where' => $wheres,
- 'order' => 'created_at desc',
- 'page' => $page,
- 'limit' => $limit,
- ];
- $sign_records = JoinPayUserBankcard::listPage($params);
- if (empty($sign_records['list'])) {
- if (false === $sign_records['list']) {
- return $this->error(JoinPayUserBankcard::getStaticError());
- }
- return $this->success('success', $sign_records);
- }
- if (empty($users)) {
- $user_ids = array_column($sign_records['list'], 'user_id');
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- $sign_orders = JoinpayFastpayOrder::find()
- ->select('order_no,bank_card_id')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'user_id' => $user_ids, 'is_sign' => 1])
- ->asArray()
- ->indexBy('bank_card_id')
- ->all();
- foreach ($sign_records['list'] as &$record) {
- $user = $users[$record['user_id']] ?? [];
- $sign_order = $sign_orders[$record['card_id']] ?? [];
- $record['nickname'] = $user['nickname'] ?? '默认会员';
- $record['avatar_url'] = $user['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- $record['mobile'] = $user['mobile'] ?? '';
- $record['order_no'] = $sign_order['order_no'] ?? '';
- }
- return $this->success('success', $sign_records, ApiStatusEnum::CODE_SUCCESS, 0);
- }
- }
- return $this->render('/sign-record/index');
- }
- public function actionGetMerchantId()
- {
- $merchant_id = PayTypeEnum::JOINPAY . StringHelper::generateRandCode(10 - strlen(PayTypeEnum::JOINPAY)) . rand(10, 99);
- return $this->success('获取成功', $merchant_id);
- }
- }
|