UpdateSellerGradeSeeder.php 1012 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. use app\common\model\User;
  3. use think\migration\Seeder;
  4. class UpdateSellerGradeSeeder extends Seeder
  5. {
  6. /**
  7. * Run Method.
  8. *
  9. * Write your database seeder using this method.
  10. *
  11. * More information on writing seeders is available here:
  12. * http://docs.phinx.org/en/latest/seeding.html
  13. */
  14. public function run()
  15. {
  16. $users = User::where('role',99)->select();
  17. if (count($users)){
  18. foreach ($users as $user){
  19. $applyRec = \app\common\model\ApplySeller::where('user_id',$user->user_id)
  20. ->where('state',1)->find();
  21. if ($applyRec){
  22. $expire = intval(strtotime('+1 year',strtotime($applyRec->update_time)));
  23. }else{
  24. $expire = intval(strtotime('+1 year',strtotime($user->create_time)));
  25. }
  26. User::where('user_id',$user->user_id)->update(['seller_grade'=>1,'seller_expire'=>$expire]);
  27. }
  28. }
  29. }
  30. }