DefaultController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <?php
  2. namespace addons\JoinPay\backend\controllers;
  3. use addons\JoinPay\common\enums\AddonsJoinPayEnum;
  4. use addons\JoinPay\common\enums\JoinPayTypeEnum;
  5. use addons\JoinPay\common\models\JoinpayFastpayOrder;
  6. use addons\JoinPay\common\models\JoinPayUserBankcard;
  7. use addons\Mch\common\models\MchWithdrawLog;
  8. use addons\Store\common\models\StoreWithdrawLog;
  9. use common\enums\AddonsEnum;
  10. use common\enums\ApiStatusEnum;
  11. use common\enums\DownloadEnum;
  12. use common\enums\PayTypeEnum;
  13. use common\enums\StatusEnum;
  14. use common\enums\WithdrawWayEnum;
  15. use common\helpers\csv\CsvExportHelper;
  16. use common\helpers\StringHelper;
  17. use common\models\common\PaidSinglePayLog;
  18. use common\models\common\PaymentTrade;
  19. use common\models\common\PaymentTradeOrder;
  20. use common\models\mall\MallAddons;
  21. use common\models\user\User;
  22. use common\models\user\UserWithdrawLog;
  23. /**
  24. * 默认控制器
  25. *
  26. * Class DefaultController
  27. * @package addons\JoinPay\backend\controllers
  28. */
  29. class DefaultController extends BaseController
  30. {
  31. /**
  32. * 首页
  33. *
  34. * @return string
  35. */
  36. public function actionIndex()
  37. {
  38. if (\Yii::$app->request->isAjax) {
  39. if (\Yii::$app->request->isGet) {
  40. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
  41. // $wechat = \Yii::$app->services->setting->mall->get($this->mall_id, 'wechat');
  42. if (empty($settings)) $settings = null;
  43. if (!empty($settings['joinpay_channel_alternative'])) $settings['joinpay_channel_alternative'] = json_decode($settings['joinpay_channel_alternative'], true);
  44. if (!empty($settings['joinpay_trade_channel'])) $settings['joinpay_trade_channel'] = json_decode($settings['joinpay_trade_channel'], true);
  45. !empty($settings['price_limit_exceed_trades']) && $settings['price_limit_exceed_trades'] = json_decode($settings['price_limit_exceed_trades'], true);
  46. !empty($settings['price_limit_normal_trades']) && $settings['price_limit_normal_trades'] = json_decode($settings['price_limit_normal_trades'], true);
  47. !empty($settings['joinpay_app_trades']) && $settings['joinpay_app_trades'] = json_decode($settings['joinpay_app_trades'], true);
  48. !empty($settings['joinpay_h5_trades']) && $settings['joinpay_h5_trades'] = json_decode($settings['joinpay_h5_trades'], true);
  49. !empty($settings['joinpay_wechat_trades']) && $settings['joinpay_wechat_trades'] = json_decode($settings['joinpay_wechat_trades'], true);
  50. !empty($settings['joinpay_mp_wx_trades']) && $settings['joinpay_mp_wx_trades'] = json_decode($settings['joinpay_mp_wx_trades'], true);
  51. !empty($settings['joinpay_merchant_wechat']) && $settings['joinpay_merchant_wechat'] = json_decode($settings['joinpay_merchant_wechat'], true);
  52. !empty($settings['joinpay_merchant_alipay']) && $settings['joinpay_merchant_alipay'] = json_decode($settings['joinpay_merchant_alipay'], true);
  53. $platform_setting = JoinPayTypeEnum::getTypeByPlatform(null);
  54. $trade_setting = [];
  55. $trade_tips = [];
  56. foreach ($platform_setting as $platform => $rows) {
  57. $trade_arr_temp = [];
  58. $tips_text = [];
  59. if (is_array($rows)) {
  60. $tips_by_trade = [];
  61. foreach ($rows as $v) {
  62. $trade_key = JoinPayTypeEnum::getJoinpayTradeMap($v);
  63. $trade_arr_temp[] = $trade_key;
  64. empty($tips_by_trade[$trade_key]) && $tips_by_trade[$trade_key] = [];
  65. $tips_by_trade[$trade_key][] = $v;
  66. }
  67. foreach ($tips_by_trade as $k => $trade_arr) {
  68. $tips_text[] = $k . ':' . join('、', $trade_arr);
  69. }
  70. }else{
  71. $trade_key = JoinPayTypeEnum::getJoinpayTradeMap($rows);
  72. $trade_arr_temp[] = $trade_key;
  73. $tips_text[] = $trade_key . ':' . $rows;
  74. }
  75. $tips_text = join(',', $tips_text);
  76. $trade_arr_temp = array_unique($trade_arr_temp);
  77. $trade_setting[$platform] = [];
  78. foreach ($trade_arr_temp as $trade_temp) {
  79. $trade_setting[$platform][] = [
  80. 'label' => JoinPayTypeEnum::getJoinpayTradeNameMap($trade_temp),
  81. 'value' => $trade_temp
  82. ];
  83. }
  84. $trade_setting[$platform][] = [
  85. 'label' => JoinPayTypeEnum::getJoinpayTradeNameMap(JoinPayTypeEnum::JOINPAY_TRADE_FASTPAY),
  86. 'value' => JoinPayTypeEnum::JOINPAY_TRADE_FASTPAY
  87. ];
  88. $trade_name_arr = JoinPayTypeEnum::getJoinpayTradeNameMap();
  89. foreach ($trade_name_arr as $trade_key => $trade_name) {
  90. $tips_text = str_replace($trade_key, $trade_name, $tips_text);
  91. }
  92. !empty($tips_text) && $tips_text = '需开通交易类型:' . $tips_text;
  93. $trade_tips[$platform] = $tips_text;
  94. }
  95. $tactics_pay_setting = [];
  96. if (MallAddons::isInstall($this->mall_id, 'TacticsPay')) {
  97. $tactics_pay_setting = [
  98. 'is_installed' => 1,
  99. 'more_wechat_field' => JoinPayTypeEnum::getMoreMerchantWechatField(),
  100. 'more_alipay_field' => JoinPayTypeEnum::getMoreMerchantAlipayField()
  101. ];
  102. }
  103. return $this->success('success', ['settings' => $settings, 'trade_setting' => $trade_setting, 'trade_tips' => $trade_tips, 'tactics_pay_setting' => $tactics_pay_setting]);
  104. } else {
  105. $post = \Yii::$app->request->post();
  106. $rules = [
  107. [['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'],
  108. [['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'],
  109. [['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],
  110. [['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'],
  111. [['joinpay_wechat_trade_name', 'joinpay_alipay_trade_name', 'joinpay_fastpay_trade_name'], 'string', 'max' => 10],
  112. [['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'],
  113. [['price_limit_exceed_price'], 'number']
  114. ];
  115. if (empty($post['joinpay_trade_channel']) || !is_array($post['joinpay_trade_channel'])) return $this->error('汇聚支付渠道填写错误');
  116. // if (1 == $post['joinpay_alternative_status'] && (empty($post['joinpay_channel_alternative']) || !is_array($post['joinpay_channel_alternative']))) return $this->error('代付支付渠道填写错误');
  117. // if ((empty($post['joinpay_channel_alternative']) || !is_array($post['joinpay_channel_alternative']))) return $this->error('代付支付渠道填写错误');
  118. $res = \Yii::$app->services->validate->validate($post, $rules);
  119. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  120. // 支付配置同时写入商城配置
  121. $joinpay_configs = [
  122. 'status' => $post['joinpay_status'],
  123. 'merchant_no' => $post['joinpay_merchant_no'],
  124. // 'trade_merchant_no' => $post['joinpay_trade_merchant_no'],
  125. 'merchant_secret' => $post['joinpay_merchant_secret'],
  126. 'wechat_app_id' => $post['joinpay_wechat_app_id'] ?? '',
  127. 'wechat_gzh_trade_merchant_no' => $post['joinpay_wechat_gzh_trade_merchant_no'],
  128. 'wechat_gzh_appid' => $post['joinpay_wechat_gzh_appid'],
  129. 'wechat_xcx_trade_merchant_no' => $post['joinpay_wechat_xcx_trade_merchant_no'],
  130. 'wechat_xcx_appid' => $post['joinpay_wechat_xcx_appid'],
  131. 'alipay_trade_merchant_no' => $post['joinpay_alipay_trade_merchant_no'],
  132. 'app3_trade_merchant_no' => $post['joinpay_app3_trade_merchant_no'],
  133. 'unionpay_trade_merchant_no' => $post['joinpay_unionpay_trade_merchant_no']
  134. ];
  135. $fastpay_configs = [
  136. 'status' => $post['joinpay_fast_pay_status'],
  137. 'merchant_no' => $post['joinpay_merchant_no'],
  138. 'fast_pay_private_key' => $post['joinpay_fast_pay_private_key'],
  139. 'fast_pay_public_key' => $post['joinpay_fast_pay_public_key'],
  140. ];
  141. // 组合多商户配置默认信息(微信)
  142. $more_wechat_field = array_column(JoinPayTypeEnum::getMoreMerchantWechatField(), 'key');
  143. $sys_wechat_merchant_id = PayTypeEnum::JOINPAY . str_repeat('0', 11 - strlen(PayTypeEnum::JOINPAY)) . '0';
  144. !isset($post['joinpay_merchant_wechat']) && $post['joinpay_merchant_wechat'] = [];
  145. $temp_merchant_wechat = array_column($post['joinpay_merchant_wechat'], null, 'merchant_id');
  146. if (isset($temp_merchant_wechat[$sys_wechat_merchant_id])) {
  147. foreach ($more_wechat_field as $key) {
  148. $temp_merchant_wechat[$sys_wechat_merchant_id][$key] = $joinpay_configs[$key] ?? '';
  149. }
  150. $temp_merchant_wechat[$sys_wechat_merchant_id]['is_sys'] = true;
  151. $post['joinpay_merchant_wechat'] = array_values($temp_merchant_wechat);
  152. }else {
  153. $field_row = ['merchant_id' => $sys_wechat_merchant_id];
  154. foreach ($more_wechat_field as $key) {
  155. $field_row[$key] = $joinpay_configs[$key] ?? '';
  156. }
  157. $field_row['is_sys'] = true;
  158. array_unshift($post['joinpay_merchant_wechat'], $field_row);
  159. }
  160. // 组合多商户配置默认信息(支付宝)
  161. $more_alipay_field = array_column(JoinPayTypeEnum::getMoreMerchantAlipayField(), 'key');
  162. $sys_alipay_merchant_id = PayTypeEnum::JOINPAY . str_repeat('0', 11 - strlen(PayTypeEnum::JOINPAY)) . '1';
  163. !isset($post['joinpay_merchant_alipay']) && $post['joinpay_merchant_alipay'] = [];
  164. $temp_merchant_alipay = array_column($post['joinpay_merchant_alipay'], null, 'merchant_id');
  165. if (isset($temp_merchant_alipay[$sys_alipay_merchant_id])) {
  166. foreach ($more_alipay_field as $key) {
  167. $temp_merchant_alipay[$sys_alipay_merchant_id][$key] = $joinpay_configs[$key] ?? '';
  168. }
  169. $temp_merchant_alipay[$sys_alipay_merchant_id]['is_sys'] = true;
  170. $post['joinpay_merchant_alipay'] = array_values($temp_merchant_alipay);
  171. }else {
  172. $field_row = ['merchant_id' => $sys_alipay_merchant_id];
  173. foreach ($more_alipay_field as $key) {
  174. $field_row[$key] = $joinpay_configs[$key] ?? '';
  175. }
  176. $field_row['is_sys'] = true;
  177. array_unshift($post['joinpay_merchant_alipay'], $field_row);
  178. }
  179. $configs = [
  180. 'basic' => $post,
  181. ];
  182. \Yii::$app->services->setting->addons->set($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, $configs);
  183. $data = [
  184. 'pay' => [
  185. 'joinpay' => json_encode($joinpay_configs),
  186. 'joinpay_fast' => json_encode($fastpay_configs),
  187. ],
  188. ];
  189. \Yii::$app->services->setting->mall->set($this->mall_id, $data);
  190. }
  191. return $this->success('保存成功', $post);
  192. }
  193. return $this->render('index');
  194. }
  195. public function actionBasicSetting()
  196. {
  197. if (\Yii::$app->request->isAjax) {
  198. if (\Yii::$app->request->isGet) {
  199. $group = \Yii::$app->request->get('group');
  200. if (empty($group) || !in_array($group, ['basic', 'fastpay'])) return $this->error('参数错误');
  201. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, $group);
  202. return $this->success('success', ['settings' => $settings]);
  203. } else {
  204. $post = \Yii::$app->request->post();
  205. $group = $post['group'] ?? '';
  206. if (empty($group) || !in_array($group, ['basic', 'fastpay']) || empty($post[$group])) return $this->error('参数错误');
  207. $rules = [
  208. 'basic' => [
  209. [['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'],
  210. [['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'],
  211. [['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],
  212. [['joinpay_merchant_no', 'joinpay_merchant_secret', 'joinpay_trade_merchant_no', 'joinpay_wechat_app_id'], 'string'],
  213. ],
  214. 'fastpay' => [
  215. [['joinpay_fast_pay_status', 'joinpay_fast_pay_private_key', 'joinpay_fast_pay_public_key'], 'required'],
  216. ['joinpay_fast_pay_status', 'integer'],
  217. ['joinpay_fast_pay_status', 'default', 'value' => 0],
  218. [['joinpay_fast_pay_public_key', 'joinpay_fast_pay_private_key'], 'string']
  219. ],
  220. ];
  221. $res = \Yii::$app->services->validate->validate($post[$group], $rules[$group]);
  222. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  223. // dd($post);
  224. $configs = [
  225. $group => $post[$group],
  226. ];
  227. \Yii::$app->services->setting->addons->set($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, $configs);
  228. // 支付配置同时写入商城配置
  229. if ('basic' == $group) {
  230. // joinpay
  231. $joinpay_configs = [
  232. 'status' => $post['basic']['joinpay_status'],
  233. 'merchant_no' => $post['basic']['joinpay_merchant_no'],
  234. 'trade_merchant_no' => $post['basic']['joinpay_trade_merchant_no'],
  235. 'merchant_secret' => $post['basic']['joinpay_merchant_secret'],
  236. 'wechat_app_id' => $post['basic']['joinpay_wechat_app_id'],
  237. ];
  238. $data = [
  239. 'pay' => [
  240. 'joinpay' => json_encode($joinpay_configs),
  241. ],
  242. ];
  243. \Yii::$app->services->setting->mall->set($this->mall_id, $data);
  244. } else {
  245. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
  246. $fastpay_configs = [
  247. 'status' => $post['fastpay']['joinpay_fast_pay_status'],
  248. 'merchant_no' => $settings['joinpay_merchant_no'],
  249. 'fast_pay_private_key' => $post['fastpay']['joinpay_fast_pay_private_key'],
  250. 'fast_pay_public_key' => $post['fastpay']['joinpay_fast_pay_public_key'],
  251. ];
  252. $data = [
  253. 'pay' => [
  254. 'joinpay_fast' => json_encode($fastpay_configs),
  255. ],
  256. ];
  257. \Yii::$app->services->setting->mall->set($this->mall_id, $data);
  258. }
  259. return $this->success('保存成功');
  260. }
  261. }
  262. return $this->render('/config/basic-setting');
  263. }
  264. public function actionFastpaySetting()
  265. {
  266. return $this->render('/config/fastpay-setting');
  267. }
  268. public function actionPayRecord()
  269. {
  270. if (\Yii::$app->request->isAjax) {
  271. if (\Yii::$app->request->isGet) {
  272. $order_no = \Yii::$app->request->get('order_no');
  273. $start_time = \Yii::$app->request->get('start_time');
  274. $end_time = \Yii::$app->request->get('end_time');
  275. $user_id = \Yii::$app->request->get('user_id');
  276. $user_keyword = \Yii::$app->request->get('user_keyword');
  277. $out_trade_no = \Yii::$app->request->get('out_trade_no');
  278. $pay_type = \Yii::$app->request->get('pay_type');
  279. $page = \Yii::$app->request->get('page', 1);
  280. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  281. $wheres[] = ['mall_id' => $this->mall_id];
  282. if (empty($pay_type)) {
  283. $wheres[] = ['pay_type' => [7, 8]];
  284. } else {
  285. if (!in_array($pay_type, [7, 8])) {
  286. return $this->error('参数错误');
  287. }
  288. $wheres[] = ['pay_type' => $pay_type];
  289. }
  290. if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . '00:00:00')];
  291. if (!empty($end_time)) $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')];
  292. if (!empty($out_trade_no)) $wheres[] = ['like', 'out_trade_no', $out_trade_no];
  293. if (!empty($user_id)) $wheres[] = ['user_id' => $user_id];
  294. if (!empty($user_keyword)) {
  295. $users = User::find()
  296. ->select('id,nickname,mobile,avatar_url')
  297. ->where(['or', ['like', 'nickname', $user_keyword], ['like', 'mobile', $user_keyword]])
  298. ->asArray()
  299. ->indexBy('id')
  300. ->all();
  301. $user_ids = array_column($users, 'id');
  302. $wheres[] = ['user_id' => $user_ids];
  303. }
  304. $trade_ids = [];
  305. if (!empty($order_no)) {
  306. $payment_order_logs = PaymentTradeOrder::find()
  307. ->select('trade_id,order_no')
  308. ->where(['order_no' => $order_no])
  309. ->asArray()
  310. ->indexBy('trade_id')
  311. ->all();
  312. $trade_ids = array_column($payment_order_logs, 'trade_id');
  313. $wheres[] = ['id' => $trade_ids];
  314. }
  315. $params = [
  316. 'select' => 'id,mall_id,user_id,out_trade_no,pay_fee as amount,is_pay,pay_type,created_at,updated_at',
  317. 'where' => $wheres,
  318. 'order' => 'created_at desc,updated_at desc',
  319. 'page' => $page,
  320. 'limit' => $limit
  321. ];
  322. $pay_records = PaymentTrade::listPage($params);
  323. if (empty($pay_records['list'])) {
  324. if (false === $pay_records['list']) {
  325. return $this->error(PaymentTrade::getStaticError());
  326. }
  327. return $this->success('success', $pay_records);
  328. }
  329. if (empty($users)) {
  330. $user_ids = array_column($pay_records['list'], 'user_id');
  331. $users = User::find()
  332. ->select('id,nickname,mobile,avatar_url')
  333. ->where(['id' => $user_ids, 'status' => StatusEnum::ENABLED])
  334. ->asArray()
  335. ->indexBy('id')
  336. ->all();
  337. }
  338. if (empty($payment_order_logs)) {
  339. $trade_ids = array_column($pay_records['list'], 'id');
  340. $payment_order_logs = PaymentTradeOrder::find()
  341. ->select('trade_id,order_no')
  342. ->where(['trade_id' => $trade_ids])
  343. ->asArray()
  344. ->indexBy('trade_id')
  345. ->all();
  346. }
  347. foreach ($pay_records['list'] as &$record) {
  348. $user = $users[$record['user_id']] ?? [];
  349. $payment_order_log = $payment_order_logs[$record['id']] ?? [];
  350. $record['nickname'] = $user['nickname'] ?? '默认会员';
  351. $record['avatar_url'] = $user['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  352. $record['mobile'] = $user['mobile'] ?? '';
  353. $record['order_no'] = $payment_order_log['order_no'] ?? '';
  354. }
  355. $pay_records['export_list'] = JoinpayFastpayOrder::fieldsList();
  356. return $this->success('success', $pay_records);
  357. }
  358. if(\Yii::$app->request->post('flag') == 'EXPORT'){
  359. $post = \Yii::$app->request->post();
  360. $post['mall_id'] = $this->mall_id;
  361. $filename = '支付记录-' . date('YmdHis').'_'.rand(10000,99999);
  362. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ORDERS,JoinpayFastpayOrder::class,'exportHandle',$post);
  363. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  364. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  365. }
  366. }
  367. return $this->render('/pay-record/index');
  368. }
  369. public function actionAlternativePayRecord()
  370. {
  371. if (\Yii::$app->request->isAjax) {
  372. if (\Yii::$app->request->isGet) {
  373. $order_no = \Yii::$app->request->get('order_no');
  374. $start_time = \Yii::$app->request->get('start_time');
  375. $end_time = \Yii::$app->request->get('end_time');
  376. $receive_keyword = \Yii::$app->request->get('receive_keyword');
  377. $account_type = \Yii::$app->request->get('account_type');
  378. $page = \Yii::$app->request->get('page', 1);
  379. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  380. $wheres[] = ['mall_id' => $this->mall_id];
  381. if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . '00:00:00')];
  382. if (!empty($end_time)) $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')];
  383. if (!empty($order_no)) $wheres[] = ['like', 'merchant_order_no', $order_no];
  384. if (!empty($receive_keyword)) {
  385. $wheres[] = ['or', ['like', 'receive_name', $receive_keyword], ['like', 'receive_account', $receive_keyword]];
  386. }
  387. if (!empty($account_type)) $wheres[] = ['account_type' => $account_type];
  388. $params = [
  389. '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',
  390. 'where' => $wheres,
  391. 'order' => 'created_at desc,updated_at desc',
  392. 'page' => $page,
  393. 'limit' => $limit
  394. ];
  395. $alternative_records = PaidSinglePayLog::listPage($params);
  396. if (empty($alternative_records['list'])) {
  397. if (false === $alternative_records['list']) {
  398. return $this->error(PaidSinglePayLog::getStaticError());
  399. }
  400. return $this->success('success', $alternative_records);
  401. }
  402. $order_no_arr = [];
  403. $store_withdraw_order_no_arr = [];
  404. $mch_withdraw_order_no_arr = [];
  405. foreach ($alternative_records['list'] as $item){
  406. switch ($item['source']){
  407. case '2':
  408. $store_withdraw_order_no_arr[]=$item['order_no'];
  409. break;
  410. case '3':
  411. $mch_withdraw_order_no_arr[]=$item['order_no'];
  412. break;
  413. default:
  414. $order_no_arr[]=$item['order_no'];
  415. }
  416. }
  417. $user_ids = [];
  418. if(!empty($order_no_arr)){
  419. $withdraw_logs = UserWithdrawLog::find()
  420. ->select('order_no,user_id')
  421. ->where(['mall_id' => $this->mall_id, 'order_no' => $order_no_arr, 'type' => WithdrawWayEnum::JOINPAY])
  422. ->indexBy('order_no')
  423. ->asArray()
  424. ->all();
  425. $user_ids = array_merge($user_ids,array_column($withdraw_logs, 'user_id'));
  426. }
  427. if(!empty($store_withdraw_order_no_arr)){
  428. if(MallAddons::isInstall($this->mall_id,'Store')){
  429. $store_withdraw_logs = StoreWithdrawLog::lists(['where'=>[['order_no'=>$store_withdraw_order_no_arr]],'index'=>'order_no']);
  430. $user_ids = array_merge($user_ids,array_column($store_withdraw_logs, 'user_id'));
  431. }
  432. }
  433. if(!empty($mch_withdraw_order_no_arr)){
  434. if(MallAddons::isInstall($this->mall_id,'Mch')){
  435. $mch_withdraw_logs = MchWithdrawLog::lists(['where'=>[['order_no'=>$mch_withdraw_order_no_arr]],'index'=>'order_no']);
  436. $user_ids = array_merge($user_ids,array_column($mch_withdraw_logs, 'user_id'));
  437. }
  438. }
  439. $users = User::find()
  440. ->select('id,nickname,mobile,avatar_url')
  441. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
  442. ->indexBy('id')
  443. ->asArray()
  444. ->all();
  445. $handle_status_map = AddonsJoinPayEnum::getHandleStatusMap();
  446. $account_type_map = AddonsJoinPayEnum::getAccountTypeMap();
  447. foreach ($alternative_records['list'] as &$record) {
  448. $record['status_text'] = $handle_status_map[$record['status']];
  449. if (AddonsJoinPayEnum::HANDLE_STATUS2 == $record['status']) $record['status_text'] .= ': ' . $record['error_msg'];
  450. $record['account_type_text'] = $account_type_map[$record['account_type']];
  451. if (AddonsJoinPayEnum::CURRENCY_DOLLAR == $record['currency']) {
  452. $record['amount'] = '$' . floatval($record['amount']);
  453. } elseif (AddonsJoinPayEnum::CURRENCY_RMB == $record['currency']) {
  454. $record['amount'] = '¥' . floatval($record['amount']);
  455. }
  456. switch ($record['source']){
  457. case '2':
  458. $withdraw_log = $store_withdraw_logs[$record['order_no']] ?? [];
  459. break;
  460. case '3':
  461. $withdraw_log = $mch_withdraw_logs[$record['order_no']] ?? [];
  462. break;
  463. default:
  464. $withdraw_log = $withdraw_logs[$record['order_no']] ?? [];
  465. }
  466. $user_id = $withdraw_log['user_id'] ?? 0;
  467. $user = $users[$user_id] ?? [];
  468. $record['user_id'] = $user['id'] ?? 0;
  469. $record['nickname'] = $user['nickname'] ?? '默认会员 ';
  470. $record['avatar_url'] = $user['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  471. }
  472. $alternative_records['export_list'] = JoinpayFastpayOrder::fieldsListPay();
  473. return $this->success('success', $alternative_records);
  474. }
  475. if(\Yii::$app->request->post('flag') == 'EXPORT'){
  476. $post = \Yii::$app->request->post();
  477. $post['mall_id'] = $this->mall_id;
  478. $filename = '代付记录-' . date('YmdHis').'_'.rand(10000,99999);
  479. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id,$filename,DownloadEnum::TYPE_ORDERS,JoinpayFastpayOrder::class,'exportHandlePay',$post);
  480. if ($res === false) return $this->error('加入导出任务失败'.CsvExportHelper::getStaticError());
  481. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  482. }
  483. }
  484. return $this->render('/alternative-pay/index');
  485. }
  486. public function actionSignRecord()
  487. {
  488. if (\Yii::$app->request->isAjax) {
  489. if (\Yii::$app->request->isGet) {
  490. $card_no = \Yii::$app->request->get('card_no');
  491. $start_time = \Yii::$app->request->get('start_time');
  492. $end_time = \Yii::$app->request->get('end_time');
  493. $user_id = \Yii::$app->request->get('user_id');
  494. $user_keyword = \Yii::$app->request->get('user_keyword');
  495. $page = \Yii::$app->request->get('page', 1);
  496. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  497. $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'is_sign' => 1];
  498. if (!empty($card_no)) $wheres[] = ['like', 'bank_card_no', $card_no];
  499. if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . '00:00:00')];
  500. if (!empty($end_time)) $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')];
  501. if (!empty($user_id)) $wheres[] = ['user_id' => $user_id];
  502. if (!empty($user_keyword)) {
  503. $users = User::find()
  504. ->select('id,nickname,mobile,avatar_url')
  505. ->where(['or', ['like', 'nickname', $user_keyword], ['like', 'mobile', $user_keyword]])
  506. ->asArray()
  507. ->indexBy('id')
  508. ->all();
  509. $user_ids = array_column($users, 'id');
  510. $wheres[] = ['user_id' => $user_ids];
  511. }
  512. $params = [
  513. 'select' => 'id,mall_id,user_id,card_id,bank_name,bank_card_no,mobile_no,card_type_name,created_at,updated_at',
  514. 'where' => $wheres,
  515. 'order' => 'created_at desc',
  516. 'page' => $page,
  517. 'limit' => $limit,
  518. ];
  519. $sign_records = JoinPayUserBankcard::listPage($params);
  520. if (empty($sign_records['list'])) {
  521. if (false === $sign_records['list']) {
  522. return $this->error(JoinPayUserBankcard::getStaticError());
  523. }
  524. return $this->success('success', $sign_records);
  525. }
  526. if (empty($users)) {
  527. $user_ids = array_column($sign_records['list'], 'user_id');
  528. $users = User::find()
  529. ->select('id,nickname,mobile,avatar_url')
  530. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
  531. ->asArray()
  532. ->indexBy('id')
  533. ->all();
  534. }
  535. $sign_orders = JoinpayFastpayOrder::find()
  536. ->select('order_no,bank_card_id')
  537. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'user_id' => $user_ids, 'is_sign' => 1])
  538. ->asArray()
  539. ->indexBy('bank_card_id')
  540. ->all();
  541. foreach ($sign_records['list'] as &$record) {
  542. $user = $users[$record['user_id']] ?? [];
  543. $sign_order = $sign_orders[$record['card_id']] ?? [];
  544. $record['nickname'] = $user['nickname'] ?? '默认会员';
  545. $record['avatar_url'] = $user['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  546. $record['mobile'] = $user['mobile'] ?? '';
  547. $record['order_no'] = $sign_order['order_no'] ?? '';
  548. }
  549. return $this->success('success', $sign_records, ApiStatusEnum::CODE_SUCCESS, 0);
  550. }
  551. }
  552. return $this->render('/sign-record/index');
  553. }
  554. public function actionGetMerchantId()
  555. {
  556. $merchant_id = PayTypeEnum::JOINPAY . StringHelper::generateRandCode(10 - strlen(PayTypeEnum::JOINPAY)) . rand(10, 99);
  557. return $this->success('获取成功', $merchant_id);
  558. }
  559. }