RepairWithdraw.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\Console\Commands;
  3. use app\common\models\Income;
  4. use app\common\models\Withdraw;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Artisan;
  7. use Illuminate\Support\Facades\Log;
  8. class RepairWithdraw extends Command
  9. {
  10. protected $signature = 'fix:income';
  11. /**
  12. * The console command description.
  13. *
  14. * @var string
  15. */
  16. protected $description = '修复收入';
  17. /**
  18. * Create a new command instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. }
  26. /**
  27. * Execute the console command.
  28. *
  29. * @return mixed
  30. */
  31. public function handle()
  32. {
  33. /* $bar = $this->output->createProgressBar(100);
  34. for($i = 0; $i<100;$i++) {
  35. $this->info('test success'.$i.'!');
  36. sleep(1);
  37. $bar->advance();
  38. }
  39. $bar->finish();
  40. $this->error('test fail!');
  41. $this->comment('test comment!');*/
  42. $member_ids = Income::select('member_id')->groupBy('member_id')->get();
  43. $i = 0;
  44. $ids = [];
  45. foreach ($member_ids as $member) {
  46. //dd($member_id['member_id']);
  47. $result = $this->withdrawCheck($member['member_id']);
  48. if (!$result) {
  49. $ids[] = $member['member_id'];
  50. $i ++;
  51. }
  52. }
  53. //dump($ids);
  54. //dd('一共' .$i. '个会员数据存在问题');
  55. Log::info('一共' .$i. '个会员数据存在问题');
  56. }
  57. public function withdrawCheck($member_id)
  58. {
  59. //$member_id = 2450;
  60. $withdraws = Withdraw::select('type_id')->where('member_id',$member_id)->get();
  61. $withdraw_ids = '';
  62. foreach ($withdraws as $key => $item) {
  63. $withdraw_ids = $item['type_id'] . ',' . $withdraw_ids;
  64. }
  65. $withdraw_ids = explode(',', $withdraw_ids, -1);
  66. $incomes = Income::select('id')->where('member_id',$member_id)->where('status',1)->get();
  67. $income_ids = [];
  68. foreach ($incomes as $key => $item) {
  69. $income_ids[] =$item['id'];
  70. }
  71. /*dump($withdraw_ids);
  72. dump($income_ids);
  73. dump(array_diff($withdraw_ids,$income_ids));
  74. dd(array_diff($income_ids,$withdraw_ids));*/
  75. $array = array_diff($income_ids,$withdraw_ids);
  76. if (empty($array)) {
  77. return true;
  78. }
  79. Income::where('member_id',$member_id)->whereIn('id',$array)->update(['status' => 0, 'pay_status' => 0]);
  80. Log::info('会员ID:' .$member_id. '收入提现数据错误修复成功');
  81. //dump('会员ID:' .$member_id. '收入提现数据错误修复成功');
  82. return false;
  83. }
  84. }