love_php/app/Http/Controllers/Server/Admin/HomeController.php

354 lines
16 KiB
PHP
Raw Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Http\Controllers\Server\Admin;
use App\Http\Response\ResponseJson;
use App\Models\Configs;
use App\Models\ConsultAccount;
use App\Models\Consultation;
use App\Models\Course\Course;
use App\Models\MerchantShop;
use App\Models\QATest;
use App\Models\SaasBanner;
use App\Models\Server\CommunityActivity;
use App\Models\Server\MerchantAccount;
use App\Models\Server\MerchantEvaluate;
use App\Models\Server\MerchantRecommendArea;
use App\Models\Server\MerchantServiceStatus;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Log;
class HomeController extends Controller
{
use ResponseJson;
public function carouselRecommend(Request $request)
{
try {
$merchant_id = $request->account_id;
$saas_banner = SaasBanner::where('merchant_id',$merchant_id)
->select('id','pic','path','path_type')
->get();
return $this->success('ok', $saas_banner);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function updateCarouselRecommend(Request $request)
{
try {
$input = is_array($request->value) ? $request->value : json_decode($request->value,true);
$merchant_id = $request->account_id;
foreach ($input as $key => $val) {
if (!$val || empty($val['pic'])) {
return $this->failure('轮播图片为必传参数');
}
if (!empty($val['id'])) {
$banner = SaasBanner::where('merchant_id', $merchant_id)
->where('id', $val['id'])->first();
if ($banner) {
$banner->pic = $val['pic'];
$banner->merchant_id = $merchant_id;
$banner->path = $val['path'] ?? null;
$banner->path_type = $val['path_type'] ?? 'h5';
$banner->save();
}
} else {
$banner = new SaasBanner();
$banner->pic = $val['pic'];
$banner->path = $val['path'] ?? null;
$banner->merchant_id = $merchant_id;
$banner->path_type = $val['path_type'] ?? 'h5';
$banner->save();
}
}
$key = 'carousel_photot_m_user_id';
$this->forgetBykey($key);
return $this->success('ok');
}catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function deleteCarouselRecommend(Request $request)
{
try {
$merchant_id = $request->account_id;
$id = $request->id;
if(!$id){
return $this->failure('id为必传参数');
}
SaasBanner::where('merchant_id',$merchant_id)
->where('id',$id)
->delete();
return $this->success('ok');
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function serviceStatus(Request $request)
{
try {
$merchant_id = $request->account_id;;
$merchant = MerchantAccount::find($merchant_id);
$statuses = $merchant->servicesStatus();
return $this->success('ok', $statuses);
}catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function orderServiceStatus(Request $request)
{
try {
$merchant_id = $request->account_id;
$merchant = MerchantAccount::find($merchant_id);
if (empty($merchant)) throw new \Exception("商户不存在");
$config = $request->input('config');
foreach ($config as $key => $conf) {
$type = substr($key, 8);
MerchantServiceStatus::where(['m_id'=>$merchant_id, 'type'=>$type])->update(['sort'=>$conf]);
}
return $this->success('ok');
}catch (\Exception $e) {
$this->getError($e);
return $this->failure();
}
}
public function updateServiceStatus(Request $request)
{
try {
$merchant_id = $request->account_id;
$values = $request->input('values');
$values[0]['is_show'] = $request->input('is_show_activity', 0);
$values[0]['type'] = 'activity';
$values[1]['is_show'] = $request->input('is_show_consult', 0);
$values[1]['type'] = 'consult';
$values[2]['is_show'] = $request->input('is_show_course', 0);
$values[2]['type'] = 'course';
$values[3]['is_show'] = $request->input('is_show_evaluate', 0);
$values[3]['type'] = 'evaluate';
$values[4]['is_show'] = $request->input('is_show_service', 0);
$values[4]['type'] = 'service';
$values[5]['is_show'] = $request->input('is_show_shop', 0);
$values[5]['type'] = 'shop';
$values[6]['is_show'] = $request->input('is_show_test', 0);
$values[6]['type'] = 'test';
foreach ($values as $value) {
MerchantServiceStatus::updateOrCreate(['m_id'=> $merchant_id, 'type'=> $value['type']], ['is_show'=>$value['is_show']]);
}
return $this->success('ok');
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function areaRecommend(Request $request)
{
try {
$merchant_id = $request->account_id;
$top_areas = MerchantRecommendArea::where('m_id',$merchant_id)->where('area_type', 'top')->orderBY('id', 'desc')->first();
if ($top_areas) {
$this->areaRecommendDetail($top_areas);
}
$middle_areas = MerchantRecommendArea::where('m_id',$merchant_id)->where('area_type', 'middle')->orderBY('id', 'asc')->get();
foreach ($middle_areas as &$area) {
$this->areaRecommendDetail($area);
}
$below_left_areas = MerchantRecommendArea::where('m_id',$merchant_id)->where('area_type', 'below_left')->orderBY('id', 'asc')->get();
foreach ($below_left_areas as &$area) {
$this->areaRecommendDetail($area);
}
$below_right_areas = MerchantRecommendArea::where('m_id',$merchant_id)->where('area_type', 'below_right')->orderBY('id', 'asc')->get();
foreach ($below_right_areas as &$area) {
$this->areaRecommendDetail($area);
}
$merchant = MerchantAccount::find($merchant_id);
if ($merchant->share_qr_code) {
$share_qrcode = $merchant->share_qr_code;
}else {
$jump_url = urlencode(env('APP_URL') . '/pu/#/');
$share_url = env('APP_URL') . '/api/official/live/wechat/FamilyAuth?merchant_id=' . $merchant_id. '&url=' . $jump_url;
$share_qrcode = $this->getPreviewQrcode($share_url);
$merchant->save();
}
return $this->success('ok', compact('top_areas', 'middle_areas', 'below_left_areas', 'below_right_areas','share_qrcode'));
}catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function areaRecommendDetail($service){
if ($service->type == 'activity' || $service->type == 'service') {
$obj = \DB::table('community_activities as a')->where('id', $service->type_id)->selectRaw('id, title, pic')->first();
}elseif($service->type == 'consult') {
$obj = \DB::table('consultations as c')->where('id', $service->type_id)->selectRaw('id, title, pic')->first();
}elseif ($service->type == 'course') {
$obj = \DB::table('courses as c')->where('id', $service->type_id)->selectRaw('id, title,thumb as pic')->first();
}elseif ($service->type == 'evaluate') {
$obj = \DB::table('merchant_evaluates as me')->where('id', $service->type_id)->selectRaw('id, title,image as pic')->first();
}elseif ($service->type == 'shop') {
$obj = \DB::table('merchant_shops as ms')->where('id', $service->type_id)->selectRaw('id, title,icon as pic')->first();
}elseif ($service->type == 'test') {
$obj = \DB::table('q_a_tests as qat')->where('id', $service->type_id)->selectRaw('id, title, pic')->first();
}
$service->detail = $obj;
return $service;
}
public function updateAreaRecommend(Request $request, $id)
{
try {
$merchant_id = $request->account_id;
$area_type = $request->area_type;
$type_id = $request->type_id;
$type = $request->type;
if (empty($type) || empty($type_id)) return $this->failure('请选择推荐服务类型');
$area = MerchantRecommendArea::find($id);
$other_area = MerchantRecommendArea::where('id','<>', $area->id)->where('m_id', $merchant_id)
->where('area_type', $area_type)->where('type', $type)->where('type_id', $type_id)
->first();
if ($other_area) return $this->failure("该服务已经存在");
if ($type != $area->type || $type_id != $area->type_id) {
$area->type = $type;
$area->type_id = $type_id;
$area->save();
}
$this->areaRecommendDetail($area);
return $this->success('ok', $area);
}catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function storeAreaRecommend(Request $request)
{
try {
$merchant_id = $request->account_id;
$area_type = $request->area_type;
$type_id = $request->type_id;
$type = $request->type;
if (empty($type) || empty($type_id)) return $this->failure('请选择推荐服务类型');
$other_area = MerchantRecommendArea::where('m_id', $merchant_id)->where('area_type', $area_type)
->where('type', $type)->where('type_id', $type_id)
->first();
if ($other_area) return $this->failure("该服务已经存在");
if ($area_type == 'top') {
$area = MerchantRecommendArea::where('m_id', $merchant_id)->where('area_type', $area_type)->first();
if ($area) {
$area->type_id = $type_id;
$area->type = $type;
$area->save();
}else {
$area = MerchantRecommendArea::create([
'm_id'=>$merchant_id,'area_type'=>$area_type,'type'=>$type,'type_id'=>$type_id,'is_show'=>1
]);
}
}else {
$area = MerchantRecommendArea::create([
'm_id'=>$merchant_id,'area_type'=>$area_type,'type'=>$type,'type_id'=>$type_id,'is_show'=>1
]);
}
$this->areaRecommendDetail($area);
return $this->success('ok',$area);
}catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function deleteAreaRecommend(Request $request, $id)
{
try {
$merchant_id = $request->account_id;
MerchantRecommendArea::where('id', $id)->where('m_id', $merchant_id)->delete();
return $this->success('ok');
}catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
public function allServices(Request $request)
{
try {
$merchant_id = $request->account_id;
$type = $request->input('type');
$keyword = $request->input('keyword');
if ($type == 'activity') {
$services = CommunityActivity::join('merchant_services', function ($join) use($merchant_id) {
$join->on('community_activities.id', '=', 'merchant_services.type_id')
->where('merchant_services.merchant_id', $merchant_id)
->where('merchant_services.type', 'community')
->where('merchant_services.status', 1)
->whereNull('merchant_services.deleted_at');
}, null, null, 'right')
->where('community_activities.class', 'one')->whereNull('community_activities.deleted_at')
->selectRaw('ufutx_community_activities.id, ufutx_community_activities.title, ufutx_community_activities.pic');
}elseif($type == 'service') {
$services = CommunityActivity::join('merchant_services', function ($join) use($merchant_id) {
$join->on('community_activities.id', '=', 'merchant_services.type_id')
->where('merchant_services.merchant_id', $merchant_id)
->where('merchant_services.type', 'community')
->where('merchant_services.status', 1)
->whereNull('merchant_services.deleted_at');
}, null, null, 'right')
->where('community_activities.class', 'many')->whereNull('community_activities.deleted_at')
->selectRaw('ufutx_community_activities.id, ufutx_community_activities.title, ufutx_community_activities.pic');
}elseif($type == 'consult') {
$services = \DB::table('consultations as c')->whereExists(function($sql) use($merchant_id){
$sql->from('consult_accounts as ca')->whereRaw('ufutx_ca.id = ufutx_c.consult_account_id ')->where('ca.merchant_id',$merchant_id);
})
->whereNull('deleted_at')->selectRaw('id, title, pic');
}elseif ($type == 'course') {
$services = Course::join('merchant_services', function ($join) use($merchant_id) {
$join->on('courses.id', '=', 'merchant_services.type_id')
->where('merchant_services.merchant_id', $merchant_id)
->where('merchant_services.type', 'course')
->where('merchant_services.status', 1)
->whereNull('merchant_services.deleted_at');
}, null, null, 'right')
->where('courses.is_show',1)
->whereNull('courses.deleted_at')->selectRaw('ufutx_courses.id, ufutx_courses.title,ufutx_courses.thumb as pic');
}elseif ($type == 'evaluate') {
$services = \DB::table('merchant_evaluates as me')->where('merchant_id', $merchant_id)
->whereNull('deleted_at')->selectRaw('id, title,image as pic');
}elseif ($type == 'shop') {
$services = \DB::table('merchant_shops as ms')->where('merchant_id', $merchant_id)
->whereNull('deleted_at')->selectRaw('id, title,icon as pic');
}elseif ($type == 'test') {
$services = \DB::table('q_a_tests as qat')->where('merchant_id', $merchant_id)
->whereNull('deleted_at')->selectRaw('id, title, pic');
}else {
return $this->failure("暂不支持该类型");
}
if ($keyword) {
$services = $services->where('title', 'like', '%'.trim($keyword).'%');
}else {
$services = $services->limit(25);
}
$services = $services /* ->orderBy('id', 'desc') */->get();
return $this->success('ok', $services);
} catch (\Exception $e) {
$this->getError($e);
return $this->failure('服务器休息,请稍后再试');
}
}
}