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

相关文章

sqlite3 相关知识

WAL 模式 VS 回滚模式 特性WAL 模式回滚模式(Rollback Journal)定义使用写前日志来记录变更。使用回滚日志来记录事务的所有修改。特点更高的并发性和性能;支持多读者和单写者。支持安全的事务回滚,但并发性较低。性能写入性能更好,尤其是读多写少的场景。写操作会造成较大的性能开销,尤其是在事务开始时。写入流程数据首先写入 WAL 文件,然后才从 WAL 刷新到主数据库。数据在开始

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

poj 1258 Agri-Net(最小生成树模板代码)

感觉用这题来当模板更适合。 题意就是给你邻接矩阵求最小生成树啦。~ prim代码:效率很高。172k...0ms。 #include<stdio.h>#include<algorithm>using namespace std;const int MaxN = 101;const int INF = 0x3f3f3f3f;int g[MaxN][MaxN];int n

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能

代码随想录冲冲冲 Day39 动态规划Part7

198. 打家劫舍 dp数组的意义是在第i位的时候偷的最大钱数是多少 如果nums的size为0 总价值当然就是0 如果nums的size为1 总价值是nums[0] 遍历顺序就是从小到大遍历 之后是递推公式 对于dp[i]的最大价值来说有两种可能 1.偷第i个 那么最大价值就是dp[i-2]+nums[i] 2.不偷第i个 那么价值就是dp[i-1] 之后取这两个的最大值就是d

pip-tools:打造可重复、可控的 Python 开发环境,解决依赖关系,让代码更稳定

在 Python 开发中,管理依赖关系是一项繁琐且容易出错的任务。手动更新依赖版本、处理冲突、确保一致性等等,都可能让开发者感到头疼。而 pip-tools 为开发者提供了一套稳定可靠的解决方案。 什么是 pip-tools? pip-tools 是一组命令行工具,旨在简化 Python 依赖关系的管理,确保项目环境的稳定性和可重复性。它主要包含两个核心工具:pip-compile 和 pip

D4代码AC集

贪心问题解决的步骤: (局部贪心能导致全局贪心)    1.确定贪心策略    2.验证贪心策略是否正确 排队接水 #include<bits/stdc++.h>using namespace std;int main(){int w,n,a[32000];cin>>w>>n;for(int i=1;i<=n;i++){cin>>a[i];}sort(a+1,a+n+1);int i=1

两个月冲刺软考——访问位与修改位的题型(淘汰哪一页);内聚的类型;关于码制的知识点;地址映射的相关内容

1.访问位与修改位的题型(淘汰哪一页) 访问位:为1时表示在内存期间被访问过,为0时表示未被访问;修改位:为1时表示该页面自从被装入内存后被修改过,为0时表示未修改过。 置换页面时,最先置换访问位和修改位为00的,其次是01(没被访问但被修改过)的,之后是10(被访问了但没被修改过),最后是11。 2.内聚的类型 功能内聚:完成一个单一功能,各个部分协同工作,缺一不可。 顺序内聚:

log4j2相关配置说明以及${sys:catalina.home}应用

${sys:catalina.home} 等价于 System.getProperty("catalina.home") 就是Tomcat的根目录:  C:\apache-tomcat-7.0.77 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" /> 2017-08-10

Node Linux相关安装

下载经编译好的文件cd /optwget https://nodejs.org/dist/v10.15.3/node-v10.15.3-linux-x64.tar.gztar -xvf node-v10.15.3-linux-x64.tar.gzln -s /opt/node-v10.15.3-linux-x64/bin/npm /usr/local/bin/ln -s /opt/nod