程序员敲代码之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

相关文章

Redis实现高效内存管理的示例代码

《Redis实现高效内存管理的示例代码》Redis内存管理是其核心功能之一,为了高效地利用内存,Redis采用了多种技术和策略,如优化的数据结构、内存分配策略、内存回收、数据压缩等,下面就来详细的介绍... 目录1. 内存分配策略jemalloc 的使用2. 数据压缩和编码ziplist示例代码3. 优化的

Python 基于http.server模块实现简单http服务的代码举例

《Python基于http.server模块实现简单http服务的代码举例》Pythonhttp.server模块通过继承BaseHTTPRequestHandler处理HTTP请求,使用Threa... 目录测试环境代码实现相关介绍模块简介类及相关函数简介参考链接测试环境win11专业版python

Python从Word文档中提取图片并生成PPT的操作代码

《Python从Word文档中提取图片并生成PPT的操作代码》在日常办公场景中,我们经常需要从Word文档中提取图片,并将这些图片整理到PowerPoint幻灯片中,手动完成这一任务既耗时又容易出错,... 目录引言背景与需求解决方案概述代码解析代码核心逻辑说明总结引言在日常办公场景中,我们经常需要从 W

使用Spring Cache本地缓存示例代码

《使用SpringCache本地缓存示例代码》缓存是提高应用程序性能的重要手段,通过将频繁访问的数据存储在内存中,可以减少数据库访问次数,从而加速数据读取,:本文主要介绍使用SpringCac... 目录一、Spring Cache简介核心特点:二、基础配置1. 添加依赖2. 启用缓存3. 缓存配置方案方案

MySQL的配置文件详解及实例代码

《MySQL的配置文件详解及实例代码》MySQL的配置文件是服务器运行的重要组成部分,用于设置服务器操作的各种参数,下面:本文主要介绍MySQL配置文件的相关资料,文中通过代码介绍的非常详细,需要... 目录前言一、配置文件结构1.[mysqld]2.[client]3.[mysql]4.[mysqldum

Python多线程实现大文件快速下载的代码实现

《Python多线程实现大文件快速下载的代码实现》在互联网时代,文件下载是日常操作之一,尤其是大文件,然而,网络条件不稳定或带宽有限时,下载速度会变得很慢,本文将介绍如何使用Python实现多线程下载... 目录引言一、多线程下载原理二、python实现多线程下载代码说明:三、实战案例四、注意事项五、总结引

IDEA与MyEclipse代码量统计方式

《IDEA与MyEclipse代码量统计方式》文章介绍在项目中不安装第三方工具统计代码行数的方法,分别说明MyEclipse通过正则搜索(排除空行和注释)及IDEA使用Statistic插件或调整搜索... 目录项目场景MyEclipse代码量统计IDEA代码量统计总结项目场景在项目中,有时候我们需要统计

MySQL设置密码复杂度策略的完整步骤(附代码示例)

《MySQL设置密码复杂度策略的完整步骤(附代码示例)》MySQL密码策略还可能包括密码复杂度的检查,如是否要求密码包含大写字母、小写字母、数字和特殊字符等,:本文主要介绍MySQL设置密码复杂度... 目录前言1. 使用 validate_password 插件1.1 启用 validate_passwo

MySQL实现多源复制的示例代码

《MySQL实现多源复制的示例代码》MySQL的多源复制允许一个从服务器从多个主服务器复制数据,这在需要将多个数据源汇聚到一个数据库实例时非常有用,下面就来详细的介绍一下,感兴趣的可以了解一下... 目录一、多源复制原理二、多源复制配置步骤2.1 主服务器配置Master1配置Master2配置2.2 从服

Go语言使用net/http构建一个RESTful API的示例代码

《Go语言使用net/http构建一个RESTfulAPI的示例代码》Go的标准库net/http提供了构建Web服务所需的强大功能,虽然众多第三方框架(如Gin、Echo)已经封装了很多功能,但... 目录引言一、什么是 RESTful API?二、实战目标:用户信息管理 API三、代码实现1. 用户数据