1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- use app\common\model\User;
- use app\common\model\user\BonusHistory;
- use think\migration\Seeder;
- class UpdateBonusHistoryShopSeeder extends Seeder
- {
- /**
- * Run Method.
- *
- * Write your database seeder using this method.
- *
- * More information on writing seeders is available here:
- * http://docs.phinx.org/en/latest/seeding.html
- */
- public function run()
- {
- $hs = BonusHistory::where('is_delete',0)->field('id,user_id')->select();
- if (count($hs)){
- foreach ($hs as $h){
- $user = User::where('user_id',$h->user_id)->field('role,shop_id')->find();
- if ($user){
- if ($user->role == User::NORMAL_USER || $user->role == User::COMMISSION_USER){
- $shopId = 0;
- }else{
- $shopId = $user->shop_id;
- }
- BonusHistory::where('id',$h->id)->update(['shop_id'=>$shopId,'role'=>$user->role]);
- }
- }
- }
- }
- }
|