| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 | <?phpnamespace App\Console\Commands;use App\Model\AccountInfo;use App\Model\Appeals;use App\Model\BaseArea;use App\Model\WithdrawInfo;use App\Model\DeliverInfo;use App\Model\DeviceInfo;use App\Model\DeviceToUser;use App\Model\RechargeInfo;use App\Model\TransportInfo;use App\Model\UserInfo;use Faker\Generator;use Illuminate\Console\Command;/** * 数据填充器 * Class DataSeeder * @package App\Console\Commands */class DataSeeder extends Command{    /**     * The name and signature of the console command.     *     * @var string     */    protected $signature = 'data:seeder';    /**     * The console command description.     *     * @var string     */    protected $description = 'Command description';    /**     * Create a new command instance.     *     * @return void     */    public function __construct()    {        parent::__construct();    }    /**     * Execute the console command.     *     * @return mixed     */    public function handle()    {        //用户表数据填充300条        $faker_zh = \Faker\Factory::create('zh_CN');        $faker_en = \Faker\Factory::create();        $cities = BaseArea::where('pid','510117')->with(['communities'=>function($query){            $query->select(['area_id','id']);        }])->get(['id'])->toArray();        $area_ids = [];        $communities_ids =[];        $city_max = 0;        $com_max = 0;         foreach ($cities as $city){             $area_ids[]= $city['id'];             $city_max ++;             foreach ($city['communities'] as $community){                 $communities_ids[] = $community['id'];                 $com_max++;             }        }            $us = UserInfo::all(['id','role'])->toArray();            $user_common = [];            $user_agent = [];            $user_agent_user = [];            foreach ($us as $u){                if ($u['role'] == UserInfo::Role_Common)                    $user_common[] = $u['id'];                if ($u['role'] == UserInfo::Role_Agent)                    $user_agent[] = $u['id'];                if ($u['role'] == UserInfo::Role_Agent_User)                    $user_agent_user[] = $u['id'];            }            $us = DeviceInfo::all(['id'])->toArray();            $device_ids =[];            $device_max = 0;            foreach ($us as $u){                $device_max ++;                $device_ids[] = $u['id'];            }        for ($i = 0;$i<2000;$i++){            echo "第{$i}个投放记录开始创建\r\n";            $tempRow = [];            $tempRow['device_id'] = $device_ids[rand(0,$device_max-1)];            $tempRow['user_id'] = $user_common[rand(0,count($user_common)-1)];            $tempRow['no'] = strtoupper(uniqid());            $tempRow['weight'] = rand(1,99999);            $tempRow['money'] = rand(0,1000);            $tempRow['finished_at'] = date('Y-m-d H:i:s');            $tempRow['status'] = rand(1,3);            $tempRow['created_at'] = date('Y-m-d H:i:s',strtotime("-".rand(1,365)." days"));            DeliverInfo::create($tempRow);        }        for ($i = 0;$i<2000;$i++){            echo "第{$i}个收运记录开始创建\r\n";            $tempRow = [];            $tempRow['device_id'] = $device_ids[rand(0,$device_max-1)];            $tempRow['user_id'] = $user_agent_user[rand(0,count($user_agent_user)-1)];            $tempRow['no'] = strtoupper(uniqid());            $tempRow['weight'] = rand(1,999999);            $tempRow['money'] = rand(0,1000);            $tempRow['created_at'] = date('Y-m-d H:i:s',strtotime("-".rand(1,365)." days"));            $tempRow['status'] = rand(1,2);            TransportInfo::create($tempRow);        }        $banks = array(            '渤海银行',            '广发银行',            '国家开发银行',            '恒丰银行',            '华夏银行',            '交通银行',            '平安银行',            '上海浦东发展银行',            '兴业银行',            '招商银行',            '浙商银行',            '中国工商银行',            '中国光大银行',            '中国建设银行',            '中国民生银行',            '中国农业银行',            '中国银行',            '中国邮政储蓄银行',            '中信银行',        );        for ($i = 0;$i<2000;$i++){            echo "第{$i}个提现记录开始创建\r\n";            $tempRow = [];            $tempRow['user_id'] = $user_common[rand(0,count($user_common)-1)];            $tempRow['order_no'] = strtoupper(uniqid());            $tempRow['money'] = rand(0,3000);            $tempRow['poundage'] = rand(0,200);            $tempRow['pay_money'] = $tempRow['money']-$tempRow['poundage'];            $tempRow['paid_at'] = date('Y-m-d H:i:s');            $tempRow['bank_card'] = $faker_zh->phoneNumber;            $tempRow['bank_name'] = $banks[rand(0,count($banks)-1)];            $tempRow['name'] = $faker_zh->name;            $tempRow['mobile'] = $faker_zh->phoneNumber;            $tempRow['ali_account'] = $faker_zh->phoneNumber;            $tempRow['ali_name'] = $faker_zh->name;            $tempRow['status'] = rand(0,1);            $tempRow['type'] = rand(0,2);            $tempRow['created_at'] = date('Y-m-d H:i:s',strtotime("-".rand(1,365)." days"));            $tempRow['reason'] = $faker_en->company;            WithdrawInfo::create($tempRow);        }        for ($i = 0;$i<2000;$i++){            echo "第{$i}个充值记录开始创建\r\n";            $tempRow = [];            $tempRow['user_id'] =  $user_common[rand(0,count($user_common)-1)];            $tempRow['order_no'] = strtoupper(uniqid());            $tempRow['money'] = rand(0,1000);            $tempRow['type'] =rand(0,1);            $tempRow['created_at'] = date('Y-m-d H:i:s',strtotime("-".rand(1,365)." days"));            $tempRow['finished_at'] = date('Y-m-d H:i:s',strtotime("-".rand(1,365)." days"));            $tempRow['status'] = rand(0,1);            RechargeInfo::create($tempRow);        }        for ($i = 0;$i<2000;$i++){            echo "第{$i}个余额记录开始创建\r\n";            $tempRow = [];            $tempRow['user_id'] =  $user_common[rand(0,count($user_common)-1)];            $tempRow['method'] = rand(1,6);            $s = [-1,1];            $tempRow['admin_id'] = $s[rand(0,1)];            $tempRow['balance'] = rand(10,1000);            $tempRow['money'] =rand(10,1000);            $tempRow['detail'] = $faker_en->text;            AccountInfo::create($tempRow);        }    }}
 |