UpdateBonusHistoryShopSeeder.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. use app\common\model\User;
  3. use app\common\model\user\BonusHistory;
  4. use think\migration\Seeder;
  5. class UpdateBonusHistoryShopSeeder extends Seeder
  6. {
  7. /**
  8. * Run Method.
  9. *
  10. * Write your database seeder using this method.
  11. *
  12. * More information on writing seeders is available here:
  13. * http://docs.phinx.org/en/latest/seeding.html
  14. */
  15. public function run()
  16. {
  17. $hs = BonusHistory::where('is_delete',0)->field('id,user_id')->select();
  18. if (count($hs)){
  19. foreach ($hs as $h){
  20. $user = User::where('user_id',$h->user_id)->field('role,shop_id')->find();
  21. if ($user){
  22. if ($user->role == User::NORMAL_USER || $user->role == User::COMMISSION_USER){
  23. $shopId = 0;
  24. }else{
  25. $shopId = $user->shop_id;
  26. }
  27. BonusHistory::where('id',$h->id)->update(['shop_id'=>$shopId,'role'=>$user->role]);
  28. }
  29. }
  30. }
  31. }
  32. }