本文主要是介绍程序员敲代码之Laravel相关,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
https://learnku.com/docs/dcat-admin/2.x
通常php有两种运行模式,
我们最常用的是php-fpm模式,
即nginx,apache通过php-fmp模式访问php文件,
然后把解析后的内容返回给访问者。
另外一种就是php CLI模式,
CLI 是Command Line Interface,
意思是 命令行接口
下面谈谈怎么在php cli模式下运行php命令,
因为有时使用CLI模式更加方便…
PHP cli模式和fpm模式有什么区别、优缺点?
日志
DB::connection()->enableQueryLog(); // 开启QueryLog
# 这里是用laravel模型查询的语句
dump(DB::getQueryLog()); # 打印模型查询执行的sql语句
CURD
SELECT
use Illuminate\Support\Facades\DB;
$result = DB::selectOne($sql); //查一条
$order = DB::table('order')->where('id', '=', 100)->first();
$info = DB::table('order')->where('seller_id',14)->get()->toArray();
多表联查
$information = DB::table('order as so')
->join('order_service_information as sf', 'so.total_order_id', '=', 'sf.total_order_id')
->where('so.id','=',$luation->order_id)
->select('sf.service_title','sf.service_fee_title','sf.service_fee_level')
->get();
get_object_vars()
$faqs=DB::table('seller_apply_for')->where('user_id', '=',170)->first();
$user = get_object_vars($faqs);
dump($user);
第一步,根据分类复制卖家
$sql = "SELECT seller_id from seller_services where first_class_id = 6 and service_status =2 and is_delete =1 and is_prohibit =1 and parent_id <1 GROUP BY seller_id;";$result = DB::select($sql);$resArr = array_column($result, 'seller_id');dump($resArr);$sum = count($resArr);$index = 0;$limit = 5;$pages = ceil($sum / $limit);//总页数for ($i = 1; $i <= $pages; $i++) {$idsArr = array_slice($resArr, $index, $limit);$str = implode(',', $idsArr);dispatch(new \App\Jobs\UserDataCopy($str, 1));$index = $index + $limit;}return 'success';
第二步:根据分类复制服务
$sql = "SELECT service_id from seller_services where first_class_id = 6 and service_status =2 and is_delete =1 and is_prohibit =1 and parent_id <1;";$result = DB::select($sql);$resArr = array_column($result, 'service_id');$sum = count($resArr);$index = 0;$limit = 5;$pages = ceil($sum / $limit);//总页数for ($i = 1; $i <= $pages; $i++) {$idsArr = array_slice($resArr, $index, $limit);$str = implode(',', $idsArr);dispatch(new \App\Jobs\UserDataCopy($str, 2));$index = $index + $limit;}dump('ok');
处理服务卖家id为0的情况
$sql = "SELECT * from seller_services where parent_id > 0 and seller_id = 0;";$result = DB::select($sql);$sql1 = "SELECT seller_id,service_id from seller_services where service_id in (SELECT parent_id from seller_services where parent_id > 0 and seller_id = 0);";$result1 = DB::select($sql1);foreach ($result as $k => $v) {foreach ($result1 as $kk => $vv) {if ($v->parent_id == $vv->service_id) {$user_id = getUserId($vv->seller_id);dump($user_id);if($user_id >0){SellerService::query()->where('service_id',$v->service_id)->update(['seller_id' =>$user_id]);}}}}
分身的服务0-1000之间随机一个数字
$sql = "SELECT * from seller_services where first_class_id = 6 and service_status =2 and is_delete =1 and is_prohibit =1 and parent_id >0;";$result = DB::select($sql);foreach ($result as $kk => $v) {dump($v->service_id);SellerService::query()->where('service_id', $v->service_id)->update(['weight' => mt_rand(0, 1000)]);}dump('ok');die;
处理服务主图重复问题,【注意!不要删除第一张主图】
$sql = "SELECT * from seller_services where first_class_id = 6 and service_status =2 and is_delete =1 and is_prohibit =1 and parent_id >0;";$result = DB::select($sql);$num = 1;foreach ($result as $kk => $v) {if ($num > 93) {$num = 1;}$service_images = json_decode($v->service_images, true);if ($service_images) {if (isset($service_images[0])) {//unset($service_images[0]);shuffle($service_images);array_unshift($service_images, "https://api.manefuwu.com/uploads/images/services/xiezuofanyi/d (" . $num . ").jpg");SellerService::query()->where('service_id', $v->service_id)->update(['service_images' => json_encode($service_images)]);}}$service_shear_images = json_decode($v->service_shear_images, true);if ($service_shear_images) {if (isset($service_shear_images[0])) {//unset($service_shear_images[0]);shuffle($service_shear_images);array_unshift($service_shear_images, "https://api.manefuwu.com/uploads/images/services/xiezuofanyi/d (" . $num . ").jpg");SellerService::query()->where('service_id', $v->service_id)->update(['service_shear_images' => json_encode($service_shear_images)]);}}$num++;}dump('ok');die;
打散服务,将现有的分身服务分散到复制用户
function updSellerServiceUser(){set_time_limit(0);$sql = "SELECT service_id,seller_id,parent_id from seller_services where parent_id >1 and service_id not in (SELECT ss.service_id from seller_services as ss INNER JOIN users as us ON ss.seller_id = us.id where ss.parent_id >1and us.parent_id >1 and us.merchants = 1 and us.examine =1);";$SellerService = DB::select($sql);$num = 1;foreach ($SellerService as $kk => $val) {$user_id = getUserId($val->seller_id);dump($num . '--' . $user_id . '--' . $val->service_id);Log::info("DemoController_index(user_id)", ['service_id' => $val->service_id,'user_id' => $user_id,'num' => $num]);if ($user_id > 0) {SellerService::query()->where('service_id', $val->service_id)->update(['seller_id' => $user_id]);}$num++;}}
大批量处理用户昵称
set_time_limit(0);$nicknameArr = json_decode($this->nickname, true);$UserList = User::query()->where('parent_id', '>', 0)->where('merchants', 1)->where('examine', 1)->get(['id'])->toArray();$i = 0;$num = 1;foreach ($UserList as $kk => $vv) {if ($i > 7580) {$i = 0;}if (isset($nicknameArr[$i])) {$name = $nicknameArr[$i];} else {$name = $nicknameArr[0];}User::query()->where('id', $vv['id'])->update(['nicname' => $name]);Log::info("DemoController_Index(nickname)", ['num' => $num,'user_id' => $vv['id']]);$SellerApplyFor = SellerApplyFor::query()->where('user_id', $vv['id'])->first();if ($SellerApplyFor) {SellerApplyFor::query()->where('id', $SellerApplyFor->id)->update(['nickname' => $name]);}$i++;$num++;}dump('ok');die;
批量修改服务时间
set_time_limit(0);$SellerService = SellerService::query()->where('parent_id', '>', 1)->where('created_at','<','1999-06-18 10:21:25')->get(['service_id'])->toArray();$num = 1;foreach ($SellerService as $kk => $vv) {$date = getRandomDateTime();$res = SellerService::query()->where('service_id', $vv['service_id'])->update(['created_at' => $date,'updated_at' => $date]);Log::info("DemoController_index(created_at)", ['num' => $num,'service_id' => $vv['service_id'],'date' => $date,'res' => $res]);$num++;}dump('ok');die;
批量添加评论
public function index(){set_time_limit(0);$sql = "
SELECT service_id,seller_id from seller_services where first_class_id = 5 and service_status =2 and is_delete =1 and service_shelf =1 and
is_prohibit =1 and parent_id >0 ORDER BY RAND() LIMIT 40;";$sql = "
SELECT service_id,seller_id from seller_services where first_class_id = 6 and service_status =2 and is_delete =1 and service_shelf =1 and
is_prohibit =1 and parent_id >0 ORDER BY RAND() LIMIT 40;";$sql = "
SELECT service_id,seller_id from seller_services where first_class_id = 8 and service_status =2 and is_delete =1 and service_shelf =1 and
is_prohibit =1 and parent_id >0 ORDER BY RAND() LIMIT 30;";$sql = "
SELECT service_id,seller_id from seller_services where first_class_id = 11 and service_status =2 and is_delete =1 and service_shelf =1 and
is_prohibit =1 and parent_id >0 ORDER BY RAND() LIMIT 40;";$num = 1;$SellerServicesList = DB::select($sql);foreach ($SellerServicesList as $kk => $vv) {$default_index = mt_rand(1, 4);// 先创建默认好评for ($i = 1; $i <= $default_index; $i++) {$User = DB::select("SELECT id from users where parent_id >0 and `status` =1 ORDER BY RAND() LIMIT 1;");$ServiceOrder = DB::select("SELECT created_at from service_order where parent_id >0 ORDER BY RAND() LIMIT 1;");ServiceEvaluation::create(['user_id' => $User[0]->id,'seller_id' => $vv->seller_id,'order_id' => 0,'communicate' => 5,'recommend' => 5,'quality' => 5,'content' => '','service_id' => $vv->service_id,'average' => 5,'status' => 0,'parent_id' => $vv->service_id,'audit_status' => 1,'created_at' => $ServiceOrder[0]->created_at,'updated_at' => $ServiceOrder[0]->created_at]);}// 随机评论for ($i = 1; $i <= $default_index; $i++) {$User = DB::select("SELECT id from users where parent_id >0 and `status` =1 ORDER BY RAND() LIMIT 1;");$ServiceOrder = DB::select("SELECT created_at from service_order where parent_id >0 ORDER BY RAND() LIMIT 1;");// 随机一个评论$content = json_decode($this->content, true);$index = array_rand($content, 1);ServiceEvaluation::create(['user_id' => $User[0]->id,'seller_id' => $vv->seller_id,'order_id' => 0,'communicate' => 5,'recommend' => 5,'quality' => 5,'content' => $content[$index],'service_id' => $vv->service_id,'average' => 5,'status' => 0,'parent_id' => $vv->service_id,'audit_status' => 1,'created_at' => $ServiceOrder[0]->created_at,'updated_at' => $ServiceOrder[0]->created_at]);}// 更新,服务评价平均分【evaluation_svg】,评论数量【comment_count】// 更新,用户,seller_score【卖家评分】SellerService::query()->where('service_id', $vv->service_id)->update(['evaluation_svg' => 5,'comment_count' => $default_index * 2]);User::query()->where('id', $vv->seller_id)->update(['seller_score' => 5]);Log::info("DemoController_index(ServiceEvaluation)", ['num' => $num,'service_id' => $vv->service_id,'seller_id' => $vv->seller_id,'default_index' => $default_index]);$num++;}dump("ok");die;}
这篇关于程序员敲代码之Laravel相关的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!