WithdrawLogic.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LikeShop有特色的全开源社交分销电商系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 商业用途务必购买系统授权,以免引起不必要的法律纠纷
  7. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  8. // | 微信公众号:好象科技
  9. // | 访问官网:http://www.likemarket.net
  10. // | 访问社区:http://bbs.likemarket.net
  11. // | 访问手册:http://doc.likemarket.net
  12. // | 好象科技开发团队 版权所有 拥有最终解释权
  13. // +----------------------------------------------------------------------
  14. // | Author: LikeShopTeam
  15. // +----------------------------------------------------------------------
  16. namespace app\shopapi\logic;
  17. use app\common\enum\AccountLogEnum;
  18. use app\common\enum\UserTerminalEnum;
  19. use app\common\enum\WithdrawEnum;
  20. use app\common\logic\AccountLogLogic;
  21. use app\common\logic\BaseLogic;
  22. use app\common\model\User;
  23. use app\common\model\WithdrawApply;
  24. use app\common\service\ConfigService;
  25. use think\facade\Db;
  26. /**
  27. * 提现逻辑层
  28. * Class WithdrawLogic
  29. * @package app\shopapi\logic
  30. */
  31. class WithdrawLogic extends BaseLogic
  32. {
  33. /**
  34. * @notes 获取提现配置
  35. * @param $userId
  36. * @return array
  37. * @author Tab
  38. * @date 2021/8/6 17:06
  39. */
  40. public static function getConfig($userId,$terminal)
  41. {
  42. $user = User::findOrEmpty($userId)->toArray();
  43. $config = [
  44. 'able_withdraw' => $user['user_earnings'],
  45. 'min_withdraw' => ConfigService::get('config', 'withdraw_min_money', WithdrawEnum::DEFAULT_MIN_MONEY),
  46. 'max_withdraw' => ConfigService::get('config', 'withdraw_max_money', WithdrawEnum::DEFAULT_MAX_MONEY),
  47. 'percentage' => ConfigService::get('config', 'withdraw_service_charge', WithdrawEnum::DEFAULT_PERCENTAGE),
  48. ];
  49. $types = ConfigService::get('config', 'withdraw_way', WithdrawEnum::DEFAULT_TYPE);
  50. foreach($types as $value) {
  51. //h5和头条隐藏微信零钱提现
  52. if(in_array($terminal,[UserTerminalEnum::H5,UserTerminalEnum::TOUTIAO]) && WithdrawEnum::TYPE_WECHAT_CHANGE == $value){
  53. continue;
  54. }
  55. $config['type'][] = [
  56. 'name' => WithdrawEnum::getTypeDesc($value),
  57. 'value' => $value
  58. ];
  59. }
  60. return $config;
  61. }
  62. /**
  63. * @notes 提现申请
  64. * @param $params
  65. * @return bool
  66. * @author Tab
  67. * @date 2021/8/6 17:52
  68. */
  69. public static function apply($params)
  70. {
  71. Db::startTrans();
  72. try {
  73. // 手续费,单位:元
  74. $handlingFee = 0;
  75. if($params['type'] != WithdrawEnum::TYPE_BALANCE) {
  76. // 不是提现至余额,需收手续费
  77. $percentage = ConfigService::get('config', 'withdraw_service_charge', WithdrawEnum::DEFAULT_PERCENTAGE);
  78. $handlingFee = bcadd(($params['money'] * $percentage / 100), 0, 2);
  79. }
  80. $withdrawApply = new WithdrawApply();
  81. $data = [
  82. 'sn' => generate_sn($withdrawApply, 'sn'),
  83. 'batch_no' => generate_sn($withdrawApply, 'batch_no','SJZZ'),
  84. 'user_id' => $params['user_id'],
  85. 'real_name' => $params['real_name'] ?? '',
  86. 'account' => $params['account'] ?? '',
  87. 'type' => $params['type'],
  88. 'money' => $params['money'],
  89. 'left_money' => $params['money'] - $handlingFee,
  90. 'money_qr_code' => $params['money_qr_code'] ?? '',
  91. 'handling_fee' => $handlingFee,
  92. 'apply_remark' => $params['apply_remark'] ?? '',
  93. 'status' => WithdrawEnum::STATUS_WAIT,
  94. 'bank' => $params['bank'] ?? '',
  95. 'subbank' => $params['subbank'] ?? '',
  96. ];
  97. // 新增提现申请记录
  98. $withdrawApply->save($data);
  99. // 扣减用户可提现金额
  100. $user = User::find($params['user_id']);
  101. $user->user_earnings = $user->user_earnings - $params['money'];
  102. $user->save();
  103. // 添加账户流水记录
  104. AccountLogLogic::add($user->id, AccountLogEnum::BW_DEC_WITHDRAWAL, AccountLogEnum::DEC, $params['money'], $withdrawApply->sn, '提现申请');
  105. Db::commit();
  106. return $withdrawApply->id;
  107. } catch (\Exception $e) {
  108. Db::rollback();
  109. self::setError($e->getMessage());
  110. return false;
  111. }
  112. }
  113. /**
  114. * @notes 查看提现申请详情
  115. * @param $params
  116. * @return array
  117. * @author Tab
  118. * @date 2021/8/6 19:06
  119. */
  120. public static function detail($params)
  121. {
  122. $field = 'id,status,status as status_desc,money,sn,create_time,type,type as type_desc,handling_fee,left_money,money_qr_code,apply_remark,audit_remark,transfer_voucher,transfer_remark,account,real_name,bank,subbank,apply_remark';
  123. return WithdrawApply::field($field)->findOrEmpty($params['id'])->toArray();
  124. }
  125. }