MigrateMemberDistributor.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /****************************************************************
  3. * Author: king -- LiBaoJia
  4. * Date: 2020/4/1 4:59 PM
  5. * Email: livsyitian@163.com
  6. * QQ: 995265288
  7. * IDE: PhpStorm
  8. * User: 芸众商城 www.yunzshop.com
  9. ****************************************************************/
  10. namespace app\Console\Commands;
  11. use app\common\models\Member;
  12. use Illuminate\Console\Command;
  13. use Yunshop\Commission\models\Agents;
  14. use Yunshop\Commission\admin\model\MemberShopInfo;
  15. class MigrateMemberDistributor extends Command
  16. {
  17. /**
  18. * The name and signature of the console command.
  19. *
  20. * @var string
  21. */
  22. protected $signature = 'migrate:member_distributor';
  23. /**
  24. * The console command description.
  25. *
  26. * @var string
  27. */
  28. protected $description = '将会员更新成为推广员';
  29. /**
  30. * Execution entrance
  31. */
  32. public function handle()
  33. {
  34. \YunShop::app()->uniacid = 2;
  35. //查询没有成为分销商的会员总数
  36. $values = MemberShopInfo::getAgentMembers();
  37. $values = empty($values) ? [] : $values->toArray();
  38. $count = count($values);
  39. if ($count <= 0) {
  40. return;
  41. }
  42. $barOne = $this->output->createProgressBar($count);
  43. foreach ($values as $value) {
  44. $this->memberDistributor($value);
  45. $barOne->advance();
  46. }
  47. $barOne->finish();
  48. $this->comment('member distributor data migration completed!');
  49. }
  50. public function memberDistributor($arrMember)
  51. {
  52. $arrAgent['uniacid'] = $arrMember['uniacid'];
  53. $arrAgent['parent_id'] = $arrMember['parent_id'];
  54. $arrAgent['member_id'] = $arrMember['member_id'];
  55. $arrAgent['parent'] = $arrMember['relation'];
  56. $arrAgent['created_at'] = $arrMember['agent_time'];
  57. $arrAgent['updated_at'] = $arrMember['agent_time'];
  58. $agent = new Agents();
  59. $agent->fill($arrAgent);
  60. $agent->save();
  61. }
  62. }