WechatMerchantTransfer.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\common\command;
  20. use app\adminapi\logic\withdraw\WechatMerchantTransferLogic;
  21. use app\adminapi\logic\withdraw\WithdrawLogic;
  22. use app\common\enum\AccountLogEnum;
  23. use app\common\enum\UserTerminalEnum;
  24. use app\common\enum\WithdrawEnum;
  25. use app\common\logic\AccountLogLogic;
  26. use app\common\model\WithdrawApply;
  27. use app\common\service\ConfigService;
  28. use app\common\service\WeChatConfigService;
  29. use think\console\Command;
  30. use think\console\Output;
  31. use think\console\Input;
  32. use think\facade\Log;
  33. class WechatMerchantTransfer extends Command
  34. {
  35. protected function configure()
  36. {
  37. $this->setName('wechat_merchant_transfer')
  38. ->setDescription('商家转账到零钱查询');
  39. }
  40. protected function execute(Input $input, Output $output)
  41. {
  42. $transfer_way = ConfigService::get('config', 'transfer_way',1);
  43. //选择了商家转账到零钱再进行查询
  44. if ($transfer_way == WithdrawEnum::ENTERPRISE) {
  45. return false;
  46. }
  47. //默认使用小程序配置
  48. $config = WeChatConfigService::getWechatConfigByTerminal(UserTerminalEnum::WECHAT_MMP);
  49. $lists = WithdrawApply::where(['type'=>WithdrawEnum::TYPE_WECHAT_CHANGE,'status'=>WithdrawEnum::STATUS_ING])
  50. ->field('id,sn,batch_no,user_id,money')
  51. ->select();
  52. foreach ($lists as $list) {
  53. $result = WechatMerchantTransferLogic::details($list,$config);
  54. if(isset($result['detail_status'])) {
  55. if ($result['detail_status'] == 'SUCCESS') {
  56. //提现成功,更新提现申请单
  57. WithdrawApply::update([
  58. 'status' => WithdrawEnum::STATUS_SUCCESS,
  59. 'pay_search_result' => json_encode($result, JSON_UNESCAPED_UNICODE),
  60. 'payment_no'=>$result['detail_id'],
  61. 'payment_time' => strtotime($result['update_time']),
  62. ],['id'=>$list['id']]);
  63. }
  64. if ($result['detail_status'] == 'FAIL') {
  65. //提现成功,更新提现申请单
  66. WithdrawApply::update([
  67. 'status' => WithdrawEnum::STATUS_FAIL,
  68. 'pay_search_result' => json_encode($result, JSON_UNESCAPED_UNICODE),
  69. ],['id'=>$list['id']]);
  70. // 回退提现金额
  71. WithdrawLogic::fallbackMoney($list);
  72. // 记录账户流水
  73. AccountLogLogic::add($list['user_id'], AccountLogEnum::BW_INC_PAYMENT_FAIL, AccountLogEnum::INC, $list['money'], $list['sn'], '付款失败回退金额');
  74. }
  75. continue;
  76. }else {
  77. Log::write($result['message'] ?? '商家转账到零钱查询失败');
  78. return null;
  79. }
  80. }
  81. return true;
  82. }
  83. }