AutoWithdrawCash.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  5. use App\Modules\Finance\Services\WithdrawCashService;
  6. use App\Modules\OfficialAccount\Models\DistributionSelfDefineConfig;
  7. use App\Modules\Finance\Services\FinancialStatService;
  8. class AutoWithdrawCash extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'AutoWithdrawCash';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '自动申请提现';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $this->start();
  39. }
  40. public function start(){
  41. \Log::info('auto_withdraw_cash_start');
  42. // 获取自动提现的渠道列表
  43. $distributionSelfDefineConfigs = DistributionSelfDefineConfig::getDistributionsByType('auto_withdraw_cash');
  44. foreach($distributionSelfDefineConfigs as $distributionSelfDefineConfig){
  45. try{
  46. $distribution_channel_id = $distributionSelfDefineConfig->distribution_channel_id;
  47. \Log::info('auto_withdraw_start:'.$distribution_channel_id);
  48. $financialStat = FinancialStatService::getFinancialStatSingle($distribution_channel_id);
  49. \Log::info($financialStat);
  50. if($financialStat['enable_withdrawal_amount'] >= 100){
  51. $amount = intval(($financialStat['enable_withdrawal_amount']*100))/100;
  52. \Log::info('real_amount:'.$amount.' orgin_amount:'.$financialStat['enable_withdrawal_amount']);
  53. $res = WithdrawCashService::auto_add_withdrawCash($distribution_channel_id,$amount,'系统自动申请提现');
  54. \Log::info('auto_withdraw:'.json_encode($res,JSON_UNESCAPED_UNICODE));
  55. }else{
  56. \Log::info('auto_withdraw_not_enough:'.$distribution_channel_id.' amount:'.$financialStat['enable_withdrawal_amount']);
  57. }
  58. }catch(Exception $e){
  59. \Log::info('auto_withdraw_cash_ept:'.$e->getMessage());
  60. }
  61. }
  62. \Log::info('auto_withdraw_cash_end');
  63. }
  64. }