<?php
public function localSearch($city, $name){
$sou = ['wmember.headimgurl', 'activity.id', 'activity.tr_id', 'activity.wid',
'activity.title', 'activity.img', 'activity.price',
'activity.start', 'activity.forming', 'activity.day_number'];
$homeSearch = Activity::where('tr_id', 1)->where('end', '>=', date("Y-m-d"))
->where('activity.city', $city)
->Join('wmember', 'activity.wid', '=', 'wmember.wid')
->where('activity.type', 'like', '%' . $name . '%')
->select($sou)->get();
if ($homeSearch->isEmpty())
$homeSearch = Activity::where('tr_id', 1)->where('end', '>=', date("Y-m-d"))
->where('activity.city', $city)
->Join('wmember', 'activity.wid', '=', 'wmember.wid')
->where('activity.title', 'like', '%' . $name . '%')
->select($sou)->get();
if ($homeSearch->isEmpty())
$this->homeSearch($city, $name);
foreach ($homeSearch as $k => $v) {
$v->img = asset($v->img);
$ord_people = DB::table('order')->where('sub_id', $v->id)->where('status', 2)->sum('people_num');
if ($ord_people >= $v->forming) {
$v->become = "已成行";
} else {
$v->become = "報名中";
}
}
if ($homeSearch->first()) {
return ['status' => '0', 'msg' => "載入成功!", 'search' => $homeSearch];
} else {
return ['status' => '1', 'msg' => "暫時沒有資料!"];
}
}
本作品採用《CC 協議》,轉載必須註明作者和本文連結