PHP头条
热点:

Laravel是一套简洁、优雅的PHPWeb开发框架(PHPWebFramework)


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 &#61; "SELECT seller_id from seller_services where first_class_id &#61; 6 and service_status &#61;2 and is_delete &#61;1 and is_prohibit &#61;1 and parent_id <1 GROUP BY seller_id;";$result &#61; DB::select($sql);$resArr &#61; array_column($result, &#39;seller_id&#39;);dump($resArr);$sum &#61; count($resArr);$index &#61; 0;$limit &#61; 5;$pages &#61; ceil($sum / $limit);//总页数for ($i &#61; 1; $i <&#61; $pages; $i&#43;&#43;) {$idsArr &#61; array_slice($resArr, $index, $limit);$str &#61; implode(&#39;,&#39;, $idsArr);dispatch(new \App\Jobs\UserDataCopy($str, 1));$index &#61; $index &#43; $limit;}return &#39;success&#39;;

第二步&#xff1a;根据分类复制服务

$sql &#61; "SELECT service_id from seller_services where first_class_id &#61; 6 and service_status &#61;2 and is_delete &#61;1 and is_prohibit &#61;1 and parent_id <1;";$result &#61; DB::select($sql);$resArr &#61; array_column($result, &#39;service_id&#39;);$sum &#61; count($resArr);$index &#61; 0;$limit &#61; 5;$pages &#61; ceil($sum / $limit);//总页数for ($i &#61; 1; $i <&#61; $pages; $i&#43;&#43;) {$idsArr &#61; array_slice($resArr, $index, $limit);$str &#61; implode(&#39;,&#39;, $idsArr);dispatch(new \App\Jobs\UserDataCopy($str, 2));$index &#61; $index &#43; $limit;}dump(&#39;ok&#39;);

处理服务卖家id为0的情况

$sql &#61; "SELECT * from seller_services where parent_id > 0 and seller_id &#61; 0;";$result &#61; DB::select($sql);$sql1 &#61; "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 &#61; 0);";$result1 &#61; DB::select($sql1);foreach ($result as $k &#61;> $v) {foreach ($result1 as $kk &#61;> $vv) {if ($v->parent_id &#61;&#61; $vv->service_id) {$user_id &#61; getUserId($vv->seller_id);dump($user_id);if($user_id >0){SellerService::query()->where(&#39;service_id&#39;,$v->service_id)->update([&#39;seller_id&#39; &#61;>$user_id]);}}}}

分身的服务0-1000之间随机一个数字

$sql &#61; "SELECT * from seller_services where first_class_id &#61; 6 and service_status &#61;2 and is_delete &#61;1 and is_prohibit &#61;1 and parent_id >0;";$result &#61; DB::select($sql);foreach ($result as $kk &#61;> $v) {dump($v->service_id);SellerService::query()->where(&#39;service_id&#39;, $v->service_id)->update([&#39;weight&#39; &#61;> mt_rand(0, 1000)]);}dump(&#39;ok&#39;);die;

处理服务主图重复问题&#xff0c;【注意&#xff01;不要删除第一张主图】

$sql &#61; "SELECT * from seller_services where first_class_id &#61; 6 and service_status &#61;2 and is_delete &#61;1 and is_prohibit &#61;1 and parent_id >0;";$result &#61; DB::select($sql);$num &#61; 1;foreach ($result as $kk &#61;> $v) {if ($num > 93) {$num &#61; 1;}$service_images &#61; 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(&#39;service_id&#39;, $v->service_id)->update([&#39;service_images&#39; &#61;> json_encode($service_images)]);}}$service_shear_images &#61; 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(&#39;service_id&#39;, $v->service_id)->update([&#39;service_shear_images&#39; &#61;> json_encode($service_shear_images)]);}}$num&#43;&#43;;}dump(&#39;ok&#39;);die;

打散服务&#xff0c;将现有的分身服务分散到复制用户

function updSellerServiceUser(){set_time_limit(0);$sql &#61; "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 &#61; us.id where ss.parent_id >1and us.parent_id >1 and us.merchants &#61; 1 and us.examine &#61;1);";$SellerService &#61; DB::select($sql);$num &#61; 1;foreach ($SellerService as $kk &#61;> $val) {$user_id &#61; getUserId($val->seller_id);dump($num . &#39;--&#39; . $user_id . &#39;--&#39; . $val->service_id);Log::info("DemoController_index(user_id)", [&#39;service_id&#39; &#61;> $val->service_id,&#39;user_id&#39; &#61;> $user_id,&#39;num&#39; &#61;> $num]);if ($user_id > 0) {SellerService::query()->where(&#39;service_id&#39;, $val->service_id)->update([&#39;seller_id&#39; &#61;> $user_id]);}$num&#43;&#43;;}}

大批量处理用户昵称

set_time_limit(0);$nicknameArr &#61; json_decode($this->nickname, true);$UserList &#61; User::query()->where(&#39;parent_id&#39;, &#39;>&#39;, 0)->where(&#39;merchants&#39;, 1)->where(&#39;examine&#39;, 1)->get([&#39;id&#39;])->toArray();$i &#61; 0;$num &#61; 1;foreach ($UserList as $kk &#61;> $vv) {if ($i > 7580) {$i &#61; 0;}if (isset($nicknameArr[$i])) {$name &#61; $nicknameArr[$i];} else {$name &#61; $nicknameArr[0];}User::query()->where(&#39;id&#39;, $vv[&#39;id&#39;])->update([&#39;nicname&#39; &#61;> $name]);Log::info("DemoController_Index(nickname)", [&#39;num&#39; &#61;> $num,&#39;user_id&#39; &#61;> $vv[&#39;id&#39;]]);$SellerApplyFor &#61; SellerApplyFor::query()->where(&#39;user_id&#39;, $vv[&#39;id&#39;])->first();if ($SellerApplyFor) {SellerApplyFor::query()->where(&#39;id&#39;, $SellerApplyFor->id)->update([&#39;nickname&#39; &#61;> $name]);}$i&#43;&#43;;$num&#43;&#43;;}dump(&#39;ok&#39;);die;

批量修改服务时间

set_time_limit(0);$SellerService &#61; SellerService::query()->where(&#39;parent_id&#39;, &#39;>&#39;, 1)->where(&#39;created_at&#39;,&#39;<&#39;,&#39;1999-06-18 10:21:25&#39;)->get([&#39;service_id&#39;])->toArray();$num &#61; 1;foreach ($SellerService as $kk &#61;> $vv) {$date &#61; getRandomDateTime();$res &#61; SellerService::query()->where(&#39;service_id&#39;, $vv[&#39;service_id&#39;])->update([&#39;created_at&#39; &#61;> $date,&#39;updated_at&#39; &#61;> $date]);Log::info("DemoController_index(created_at)", [&#39;num&#39; &#61;> $num,&#39;service_id&#39; &#61;> $vv[&#39;service_id&#39;],&#39;date&#39; &#61;> $date,&#39;res&#39; &#61;> $res]);$num&#43;&#43;;}dump(&#39;ok&#39;);die;

批量添加评论

public function index(){set_time_limit(0);$sql &#61; "
SELECT service_id,seller_id from seller_services where first_class_id &#61; 5 and service_status &#61;2 and is_delete &#61;1 and service_shelf &#61;1 and
is_prohibit &#61;1 and parent_id >0 ORDER BY RAND() LIMIT 40;"
;$sql &#61; "
SELECT service_id,seller_id from seller_services where first_class_id &#61; 6 and service_status &#61;2 and is_delete &#61;1 and service_shelf &#61;1 and
is_prohibit &#61;1 and parent_id >0 ORDER BY RAND() LIMIT 40;"
;$sql &#61; "
SELECT service_id,seller_id from seller_services where first_class_id &#61; 8 and service_status &#61;2 and is_delete &#61;1 and service_shelf &#61;1 and
is_prohibit &#61;1 and parent_id >0 ORDER BY RAND() LIMIT 30;"
;$sql &#61; "
SELECT service_id,seller_id from seller_services where first_class_id &#61; 11 and service_status &#61;2 and is_delete &#61;1 and service_shelf &#61;1 and
is_prohibit &#61;1 and parent_id >0 ORDER BY RAND() LIMIT 40;"
;$num &#61; 1;$SellerServicesList &#61; DB::select($sql);foreach ($SellerServicesList as $kk &#61;> $vv) {$default_index &#61; mt_rand(1, 4);// 先创建默认好评for ($i &#61; 1; $i <&#61; $default_index; $i&#43;&#43;) {$User &#61; DB::select("SELECT id from users where parent_id >0 and &#96;status&#96; &#61;1 ORDER BY RAND() LIMIT 1;");$ServiceOrder &#61; DB::select("SELECT created_at from service_order where parent_id >0 ORDER BY RAND() LIMIT 1;");ServiceEvaluation::create([&#39;user_id&#39; &#61;> $User[0]->id,&#39;seller_id&#39; &#61;> $vv->seller_id,&#39;order_id&#39; &#61;> 0,&#39;communicate&#39; &#61;> 5,&#39;recommend&#39; &#61;> 5,&#39;quality&#39; &#61;> 5,&#39;content&#39; &#61;> &#39;&#39;,&#39;service_id&#39; &#61;> $vv->service_id,&#39;average&#39; &#61;> 5,&#39;status&#39; &#61;> 0,&#39;parent_id&#39; &#61;> $vv->service_id,&#39;audit_status&#39; &#61;> 1,&#39;created_at&#39; &#61;> $ServiceOrder[0]->created_at,&#39;updated_at&#39; &#61;> $ServiceOrder[0]->created_at]);}// 随机评论for ($i &#61; 1; $i <&#61; $default_index; $i&#43;&#43;) {$User &#61; DB::select("SELECT id from users where parent_id >0 and &#96;status&#96; &#61;1 ORDER BY RAND() LIMIT 1;");$ServiceOrder &#61; DB::select("SELECT created_at from service_order where parent_id >0 ORDER BY RAND() LIMIT 1;");// 随机一个评论$content &#61; json_decode($this->content, true);$index &#61; array_rand($content, 1);ServiceEvaluation::create([&#39;user_id&#39; &#61;> $User[0]->id,&#39;seller_id&#39; &#61;> $vv->seller_id,&#39;order_id&#39; &#61;> 0,&#39;communicate&#39; &#61;> 5,&#39;recommend&#39; &#61;> 5,&#39;quality&#39; &#61;> 5,&#39;content&#39; &#61;> $content[$index],&#39;service_id&#39; &#61;> $vv->service_id,&#39;average&#39; &#61;> 5,&#39;status&#39; &#61;> 0,&#39;parent_id&#39; &#61;> $vv->service_id,&#39;audit_status&#39; &#61;> 1,&#39;created_at&#39; &#61;> $ServiceOrder[0]->created_at,&#39;updated_at&#39; &#61;> $ServiceOrder[0]->created_at]);}// 更新&#xff0c;服务评价平均分【evaluation_svg】&#xff0c;评论数量【comment_count】// 更新&#xff0c;用户&#xff0c;seller_score【卖家评分】SellerService::query()->where(&#39;service_id&#39;, $vv->service_id)->update([&#39;evaluation_svg&#39; &#61;> 5,&#39;comment_count&#39; &#61;> $default_index * 2]);User::query()->where(&#39;id&#39;, $vv->seller_id)->update([&#39;seller_score&#39; &#61;> 5]);Log::info("DemoController_index(ServiceEvaluation)", [&#39;num&#39; &#61;> $num,&#39;service_id&#39; &#61;> $vv->service_id,&#39;seller_id&#39; &#61;> $vv->seller_id,&#39;default_index&#39; &#61;> $default_index]);$num&#43;&#43;;}dump("ok");die;}

www.phpzy.comtrue/phpzx/49691.htmlTechArticleLaravel是一套简洁、优雅的PHPWeb开发框架(PHPWebFramework) https://learnku.com/docs/dcat-admin/2.x 通常php有两种运行模式 我们最常用的是php-fpm模式 即nginxapache通过php-fmp模式访问php文件 然后把解析后...

相关文章

PHP之友评论

今天推荐