程序员敲代码之Laravel相关

2024-08-29 00:48

本文主要是介绍程序员敲代码之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相关的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1116370

相关文章

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

MySQL数据库的内嵌函数和联合查询实例代码

《MySQL数据库的内嵌函数和联合查询实例代码》联合查询是一种将多个查询结果组合在一起的方法,通常使用UNION、UNIONALL、INTERSECT和EXCEPT关键字,下面:本文主要介绍MyS... 目录一.数据库的内嵌函数1.1聚合函数COUNT([DISTINCT] expr)SUM([DISTIN

Java实现自定义table宽高的示例代码

《Java实现自定义table宽高的示例代码》在桌面应用、管理系统乃至报表工具中,表格(JTable)作为最常用的数据展示组件,不仅承载对数据的增删改查,还需要配合布局与视觉需求,而JavaSwing... 目录一、项目背景详细介绍二、项目需求详细介绍三、相关技术详细介绍四、实现思路详细介绍五、完整实现代码

Go语言代码格式化的技巧分享

《Go语言代码格式化的技巧分享》在Go语言的开发过程中,代码格式化是一个看似细微却至关重要的环节,良好的代码格式化不仅能提升代码的可读性,还能促进团队协作,减少因代码风格差异引发的问题,Go在代码格式... 目录一、Go 语言代码格式化的重要性二、Go 语言代码格式化工具:gofmt 与 go fmt(一)

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

Python如何去除图片干扰代码示例

《Python如何去除图片干扰代码示例》图片降噪是一个广泛应用于图像处理的技术,可以提高图像质量和相关应用的效果,:本文主要介绍Python如何去除图片干扰的相关资料,文中通过代码介绍的非常详细,... 目录一、噪声去除1. 高斯噪声(像素值正态分布扰动)2. 椒盐噪声(随机黑白像素点)3. 复杂噪声(如伪

Java Spring ApplicationEvent 代码示例解析

《JavaSpringApplicationEvent代码示例解析》本文解析了Spring事件机制,涵盖核心概念(发布-订阅/观察者模式)、代码实现(事件定义、发布、监听)及高级应用(异步处理、... 目录一、Spring 事件机制核心概念1. 事件驱动架构模型2. 核心组件二、代码示例解析1. 事件定义

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部