get(); $couponData = DB::table($newCouponName)->get(); $bar = $this->output->createProgressBar(count($oldData)); $bar->start(); $newData = []; foreach ($oldData as $key => $value) { $newData[] = [ 'id' => $value->id, 'coupon_id' => $value->system_coupon_user_id ?? 0, 'user_id' => $value->user_id ?? 0, 'order_main_id' => $value->order_main_id ?? 0, 'receive_time' => $value->receive_time ?? 0, 'number' => $value->number ?? 0, 'number_remain' => $value->number_remain ?? 0, 'status' => $value->status ?? 0, 'update_time' => $value->update_time ?? 0, 'receive_type' => $value->receive_type ?? 0, 'rebate_type' => $value->rebate_type ?? 0, 'send_user_id' => $value->send_user_id ?? 0, 'phone' => $value->phone ?? '', 'created_at' => $value->created_at ?? 0, 'updated_at' => time(), ]; $bar->advance(); } // insert new data to new table DB::table($newTableName)->insert($newData); // 优惠券添加的字段设置默认值 foreach($couponData as $k => $v){ $upData = [ 'category' => empty($v->category)? 1 : $v->category, 'category_ids' => empty($v->category_ids)? '[]' : $v->category_ids, 'market_ids' => empty($v->market_ids)? '[]' : $v->market_ids, 'is_new_user' => empty($v->is_new_user)? 2 : $v->is_new_user, 'type' => empty($v->type)? 1 : $v->type, 'activity_available' => empty($v->activity_available)? '[]' : $v->activity_available, 'tags' => empty($v->tags)? '[]' : $v->tags, 'remark' => empty($v->remark)? '' : $v->remark, 'created_at' => empty($v->created_at)? time() : $v->created_at, 'updated_at' => time(), ]; DB::table($newCouponName)->where('id',$v->id)->update($upData); } $bar->finish(); return 0; } }