type; $type_id = $request->type_id; $merchant_id = $request->account_id; if (!$type || !$type_id || !$merchant_id) { return $this->failure('参数不全'); } switch ($type) { case 'activity': //活动 $database_type = 'App\Models\CommunityActivity'; break; case 'consultation': //咨询 $database_type = 'App\Models\Consultation'; break; case 'shop': //店铺 $database_type = 'App\Models\MerchantShop'; break; case 'merchantInformation': //文章 $database_type = 'App\Models\MerchantInformation'; break; case 'course': $database_type = 'App\Models\Course\Course'; break; case 'evaluate': $database_type = 'App\Models\Server\MerchantEvaluate'; break; default: return $this->failure('不存在的类型'); } $pv_list = Log::with(['merchant_user' => function ($query) { $query->select('id', 'nickname', 'mobile', 'pic'); }]) ->where('log_type', $database_type)->where('log_id', $type_id) ->where('logable_type', 'App\Models\Server\MerchantUser') ->orderBy('id', 'desc')->select('id', 'created_at', 'logable_id') ->paginate(); foreach ($pv_list as $key => $val) { if (!empty($val['merchant_user']) && empty($val['merchant_user']['pic'])) { $pv_list[$key]['merchant_user']['pic'] = User::DefaultAvatar; } } return $this->success('ok', $pv_list); } catch (\Exception $e) { $this->getError($e); return $this->failure('服务器休息中,请稍后再试'); } } }