CardGenerateCommand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\command;
  3. use app\model\Card;
  4. use app\model\CardIssue;
  5. use app\model\Member;
  6. use app\model\MemberAccount;
  7. use app\model\Order;
  8. use app\model\PayDetail;
  9. use support\Db;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Output\OutputInterface;
  14. class CardGenerateCommand extends Command
  15. {
  16. protected static $defaultName = 'CardGenerateCommand';
  17. protected static $defaultDescription = 'CardGenerateCommand';
  18. /**
  19. * @return void
  20. */
  21. protected function configure()
  22. {
  23. $this->addArgument('name', InputArgument::OPTIONAL, '生成卡号');
  24. }
  25. protected function execute(InputInterface $input, OutputInterface $output): int
  26. {
  27. try {
  28. $issue = CardIssue::where('card_issue_id', 5)->first();
  29. $cards = [];
  30. for ($i = 0; $i < $issue->card_issue_num; $i++) {
  31. $cardId = $issue->card_issue_serial_prefix . str_pad($issue->card_issue_serial_begin + $i, $issue->card_issue_serial_length - strlen($issue->card_issue_serial_prefix), '0', STR_PAD_LEFT);
  32. $cards[] = [
  33. 'card_id' => $cardId,
  34. 'join_card_main_id' => $issue->join_issue_card_main_id,
  35. 'join_card_issue_id' => $issue->card_issue_id,
  36. 'card_status' => 'INIT',
  37. 'card_cdkey' => random_string(8, 'number'),
  38. 'card_addtimes' => time()
  39. ];
  40. }
  41. Card::insert($cards);
  42. return self::SUCCESS;
  43. } catch (\Exception $e) {
  44. dump($e->getMessage());
  45. return self::SUCCESS;
  46. }
  47. }
  48. }