fetchAll(); //不应该存在的时间点 $not_exit_time = ['23','00','01','02','03','04','05','06','07']; $user_manager = []; $user_product = []; $user_vip_price = []; $user_contact = []; $export_info = []; foreach ($list as $info) { switch ($info['operation']) { case '点击客户管理': $user_manager[] = $info; break; case '点击客户信息产品账号': $user_product[] = $info; break; case '点击客户信息会员价': $user_vip_price[] = $info; break; case '点击客户更多联系方式': $user_contact[] = $info; break; case '点击导出所有客户信息': $export_info[] = $info; break; } } $recore_num = 1; $start_time = "2020-5-13 15:42:27"; $user_click_time = []; //点击用户管理 foreach ($user_manager as $v) { // $userlist = $user->field('`LoginCode`')->where(['CreateTime'=>['<',$start_time]])->order('id')->limit('50')->fetchAll(); // $user_click_time[] = $start_time; // $data['info'] = json_encode($userlist); $data['create_time'] = $start_time; $test->where(['id' => $v['id']])->update($data); $start_time = formatTime($start_time,10000,30000); echo '更新第'.$recore_num++.'条数据'."\r"; } // 点击导出所有客户信息 $start_time = "2020-5-13 15:45:37"; foreach($export_info as $v){ // $data['info'] = '本次点击时间之前所有客户数据'; $data['create_time'] = $start_time; $test->where(['id' => $v['id']])->update($data); $start_time = formatTime($start_time,20000,43200); echo '更新第'.$recore_num++.'条数据'."\r"; } //点击客户信息产品账号 $k = 0; $start_time = "2020-5-13 15:42:35"; //给出客户信息列表 foreach ($user_product as $v) { // $data['info'] = $user_click_list[$k++]['LoginCode']; $data['create_time'] = $start_time; $test->where(['id' => $v['id']])->update($data); $start_time = formatTime($start_time,100,180); echo '更新第'.$recore_num++.'条数据'."\r"; } //点击客户信息会员价 $k = 0; $start_time = "2020-5-13 15:42:57"; foreach ($user_vip_price as $v) { // $data['info'] = $user_click_list[$k++]['LoginCode']; $data['create_time'] = $start_time; $test->where(['id' => $v['id']])->update($data); $start_time = formatTime($start_time,100,180); echo '更新第'.$recore_num++.'条数据'."\r"; } //点击客户更多联系方式 $k = 0; $start_time = "2020-5-13 15:43:08"; foreach ($user_contact as $v) { // $data['info'] = $user_click_list[$k++]['LoginCode']; $data['create_time'] = $start_time; $test->where(['id' => $v['id']])->update($data); $start_time = formatTime($start_time,100,180); echo '更新第'.$recore_num++.'条数据'."\r"; } function formatTime($time,$rand1,$rand2) { global $not_exit_time; $c_time = date('Y-m-d H:i:s',strtotime($time) + rand($rand1,$rand2)); $start_time = explode(':',explode(' ',$c_time)[1])[0]; if(!in_array($start_time,$not_exit_time)){ return $c_time; } else { return formatTime($c_time,$rand1,$rand2); } }