1.laravel 路由
//每日蛋白质摄入计算器
Route::get('api/protein/intake', 'FormulaController@proteinIntakeCal');
2.代码
/**
* 每日蛋白质摄入计算器
*/
public function proteinIntakeCal()
{
$number = intval($this->request('number'));
$goalFactor = array(0.8, 1.16, 0.8, 1.16, 1.16, 1.8, 1.16, 2);
$data = [
[
'name' => '正常人',
'min' => sprintf('%.1f', $goalFactor[2 * 0] * $number),
'max' => sprintf('%.1f', $goalFactor[2 * 0 + 1] * $number)
],
[
'name' => '减肥减脂',
'min' => sprintf('%.1f', $goalFactor[2 * 1] * $number),
'max' => sprintf('%.1f', $goalFactor[2 * 1 + 1] * $number)
],
[
'name' => '增肌',
'min' => sprintf('%.1f', $goalFactor[2 * 2] * $number),
'max' => sprintf('%.1f', $goalFactor[2 * 2 + 1] * $number)
],
[
'name' => '健身房健美人士',
'min' => sprintf('%.1f', $goalFactor[2 * 3] * $number),
'max' => sprintf('%.1f', $goalFactor[2 * 3 + 1] * $number)
],
];
return $this->jsonSuc(['result' => $data]);
}