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

相关文章

C++使用栈实现括号匹配的代码详解

《C++使用栈实现括号匹配的代码详解》在编程中,括号匹配是一个常见问题,尤其是在处理数学表达式、编译器解析等任务时,栈是一种非常适合处理此类问题的数据结构,能够精确地管理括号的匹配问题,本文将通过C+... 目录引言问题描述代码讲解代码解析栈的状态表示测试总结引言在编程中,括号匹配是一个常见问题,尤其是在

Java调用DeepSeek API的最佳实践及详细代码示例

《Java调用DeepSeekAPI的最佳实践及详细代码示例》:本文主要介绍如何使用Java调用DeepSeekAPI,包括获取API密钥、添加HTTP客户端依赖、创建HTTP请求、处理响应、... 目录1. 获取API密钥2. 添加HTTP客户端依赖3. 创建HTTP请求4. 处理响应5. 错误处理6.

使用 sql-research-assistant进行 SQL 数据库研究的实战指南(代码实现演示)

《使用sql-research-assistant进行SQL数据库研究的实战指南(代码实现演示)》本文介绍了sql-research-assistant工具,该工具基于LangChain框架,集... 目录技术背景介绍核心原理解析代码实现演示安装和配置项目集成LangSmith 配置(可选)启动服务应用场景

Python中顺序结构和循环结构示例代码

《Python中顺序结构和循环结构示例代码》:本文主要介绍Python中的条件语句和循环语句,条件语句用于根据条件执行不同的代码块,循环语句用于重复执行一段代码,文章还详细说明了range函数的使... 目录一、条件语句(1)条件语句的定义(2)条件语句的语法(a)单分支 if(b)双分支 if-else(

MySQL数据库函数之JSON_EXTRACT示例代码

《MySQL数据库函数之JSON_EXTRACT示例代码》:本文主要介绍MySQL数据库函数之JSON_EXTRACT的相关资料,JSON_EXTRACT()函数用于从JSON文档中提取值,支持对... 目录前言基本语法路径表达式示例示例 1: 提取简单值示例 2: 提取嵌套值示例 3: 提取数组中的值注意

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

JAVA调用Deepseek的api完成基本对话简单代码示例

《JAVA调用Deepseek的api完成基本对话简单代码示例》:本文主要介绍JAVA调用Deepseek的api完成基本对话的相关资料,文中详细讲解了如何获取DeepSeekAPI密钥、添加H... 获取API密钥首先,从DeepSeek平台获取API密钥,用于身份验证。添加HTTP客户端依赖使用Jav

Java实现状态模式的示例代码

《Java实现状态模式的示例代码》状态模式是一种行为型设计模式,允许对象根据其内部状态改变行为,本文主要介绍了Java实现状态模式的示例代码,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来... 目录一、简介1、定义2、状态模式的结构二、Java实现案例1、电灯开关状态案例2、番茄工作法状态案例

nginx-rtmp-module模块实现视频点播的示例代码

《nginx-rtmp-module模块实现视频点播的示例代码》本文主要介绍了nginx-rtmp-module模块实现视频点播,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习... 目录预置条件Nginx点播基本配置点播远程文件指定多个播放位置参考预置条件配置点播服务器 192.

CSS自定义浏览器滚动条样式完整代码

《CSS自定义浏览器滚动条样式完整代码》:本文主要介绍了如何使用CSS自定义浏览器滚动条的样式,包括隐藏滚动条的角落、设置滚动条的基本样式、轨道样式和滑块样式,并提供了完整的CSS代码示例,通过这些技巧,你可以为你的网站添加个性化的滚动条样式,从而提升用户体验,详细内容请阅读本文,希望能对你有所帮助...