|
@@ -10,16 +10,47 @@ use app\common\model\BodyTypeSelection;
|
|
|
use app\common\model\BodyAiReport;
|
|
|
use think\Db;
|
|
|
use think\exception\ValidateException;
|
|
|
+use think\exception\PDOException;
|
|
|
+use think\exception\DbException;
|
|
|
+use Exception;
|
|
|
|
|
|
/**
|
|
|
* 身体档案管理
|
|
|
+ *
|
|
|
+ * @icon fa fa-user
|
|
|
+ * @remark 管理用户身体档案信息,包括基础数据、测量记录、体型选择等
|
|
|
*/
|
|
|
class BodyProfile extends Backend
|
|
|
{
|
|
|
+ /**
|
|
|
+ * BodyProfile模型对象
|
|
|
+ * @var \app\common\model\BodyProfile
|
|
|
+ */
|
|
|
protected $model = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 无需登录的方法,同时也就无需鉴权了
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
protected $noNeedLogin = [];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 无需鉴权的方法,但需要登录
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
protected $noNeedRight = [];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 快速搜索时执行查找的字段
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
protected $searchFields = 'profile_name,relation';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关联查询
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ protected $relationSearch = true;
|
|
|
|
|
|
public function _initialize()
|
|
|
{
|
|
@@ -28,99 +59,97 @@ class BodyProfile extends Backend
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查看列表
|
|
|
+ * 默认生成的控制器所继承的父类中有index方法,在这里重写下
|
|
|
*/
|
|
|
public function index()
|
|
|
{
|
|
|
+ //当前是否为关联查询
|
|
|
+ $this->relationSearch = true;
|
|
|
+ //设置过滤方法
|
|
|
+ $this->request->filter(['strip_tags', 'trim']);
|
|
|
if ($this->request->isAjax()) {
|
|
|
- // 分页参数
|
|
|
- $page = $this->request->get('page/d', 1);
|
|
|
- $limit = $this->request->get('limit/d', 10);
|
|
|
- $search = $this->request->get('search', '');
|
|
|
- $gender = $this->request->get('gender', '');
|
|
|
- $is_own = $this->request->get('is_own', '');
|
|
|
-
|
|
|
- $where = [];
|
|
|
-
|
|
|
- // 搜索条件
|
|
|
- if ($search) {
|
|
|
- $where[] = ['profile_name|relation', 'like', '%' . $search . '%'];
|
|
|
- }
|
|
|
-
|
|
|
- if ($gender !== '') {
|
|
|
- $where[] = ['gender', '=', $gender];
|
|
|
+ //如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
+ if ($this->request->request('keyField')) {
|
|
|
+ return $this->selectpage();
|
|
|
}
|
|
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
|
|
|
- if ($is_own !== '') {
|
|
|
- $where[] = ['is_own', '=', $is_own];
|
|
|
- }
|
|
|
-
|
|
|
- // 查询数据
|
|
|
$list = $this->model
|
|
|
- ->with(['user', 'latestMeasurement'])
|
|
|
+ ->with(['user'])
|
|
|
->where($where)
|
|
|
- ->order('id DESC')
|
|
|
- ->paginate($limit)
|
|
|
- ->each(function($item) {
|
|
|
- // 添加额外信息
|
|
|
- $item['bmi'] = $item->calculateBMI();
|
|
|
- $item['bmi_level'] = $item->getBMILevel();
|
|
|
- return $item;
|
|
|
- });
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->paginate($limit);
|
|
|
+
|
|
|
+ foreach ($list as $row) {
|
|
|
+ $row->visible(['id','profile_name','user_id','gender','is_own','relation','age','height','weight','createtime','updatetime']);
|
|
|
+ $row->visible(['user']);
|
|
|
+ $row->getRelation('user')->visible(['username','nickname']);
|
|
|
+
|
|
|
+ // 计算BMI
|
|
|
+ $row['bmi'] = $row->calculateBMI();
|
|
|
+ $row['bmi_level'] = $row->getBMILevel();
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
|
|
|
- return json(['code' => 0, 'msg' => '', 'count' => $list->total(), 'data' => $list->items()]);
|
|
|
+ return json($result);
|
|
|
}
|
|
|
-
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 添加档案
|
|
|
+ * 添加
|
|
|
*/
|
|
|
public function add()
|
|
|
{
|
|
|
if ($this->request->isPost()) {
|
|
|
- $params = $this->request->post('row/a');
|
|
|
-
|
|
|
- if (empty($params)) {
|
|
|
- $this->error(__('Parameter %s can not be empty', ''));
|
|
|
- }
|
|
|
-
|
|
|
- // 验证必填字段
|
|
|
- if (empty($params['profile_name']) || empty($params['user_id'])) {
|
|
|
- $this->error('档案名称和用户ID不能为空');
|
|
|
- }
|
|
|
-
|
|
|
- // 处理身体照片
|
|
|
- if (isset($params['body_photos']) && is_array($params['body_photos'])) {
|
|
|
- $params['body_photos'] = json_encode($params['body_photos']);
|
|
|
- }
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- $result = $this->model->save($params);
|
|
|
- if ($result === false) {
|
|
|
- throw new \Exception($this->model->getError());
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ if ($params) {
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
+
|
|
|
+ // 处理身体照片
|
|
|
+ if (isset($params['body_photos']) && is_array($params['body_photos'])) {
|
|
|
+ $params['body_photos'] = json_encode($params['body_photos']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = false;
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ //是否采用模型验证
|
|
|
+ if ($this->modelValidate) {
|
|
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
|
|
|
+ $this->model->validateFailException(true)->validate($validate);
|
|
|
+ }
|
|
|
+ $result = $this->model->allowField(true)->save($params);
|
|
|
+ Db::commit();
|
|
|
+ } catch (ValidateException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result !== false) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error(__('No rows were inserted'));
|
|
|
}
|
|
|
-
|
|
|
- Db::commit();
|
|
|
- } catch (\Throwable $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
- $this->success();
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
-
|
|
|
- // 获取用户列表
|
|
|
- $userList = \app\common\model\User::field('id,username,nickname')->select();
|
|
|
- $this->assign('userList', $userList);
|
|
|
+
|
|
|
+ $this->view->assign('genderList', ['1' => __('Male'), '2' => __('Female')]);
|
|
|
+ $this->view->assign('isOwnList', ['1' => __('Own profile'), '0' => __('Others profile')]);
|
|
|
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 编辑档案
|
|
|
+ * 编辑
|
|
|
*/
|
|
|
public function edit($ids = null)
|
|
|
{
|
|
@@ -128,99 +157,116 @@ class BodyProfile extends Backend
|
|
|
if (!$row) {
|
|
|
$this->error(__('No Results were found'));
|
|
|
}
|
|
|
-
|
|
|
- if ($this->request->isPost()) {
|
|
|
- $params = $this->request->post('row/a');
|
|
|
-
|
|
|
- if (empty($params)) {
|
|
|
- $this->error(__('Parameter %s can not be empty', ''));
|
|
|
- }
|
|
|
-
|
|
|
- // 处理身体照片
|
|
|
- if (isset($params['body_photos']) && is_array($params['body_photos'])) {
|
|
|
- $params['body_photos'] = json_encode($params['body_photos']);
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds)) {
|
|
|
+ if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__('You have no permission'));
|
|
|
}
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- $result = $row->save($params);
|
|
|
- if ($result === false) {
|
|
|
- throw new \Exception($row->getError());
|
|
|
+ }
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ if ($params) {
|
|
|
+ $params = $this->preExcludeFields($params);
|
|
|
+
|
|
|
+ // 处理身体照片
|
|
|
+ if (isset($params['body_photos']) && is_array($params['body_photos'])) {
|
|
|
+ $params['body_photos'] = json_encode($params['body_photos']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = false;
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ //是否采用模型验证
|
|
|
+ if ($this->modelValidate) {
|
|
|
+ $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
|
|
|
+ $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
|
|
+ $row->validateFailException(true)->validate($validate);
|
|
|
+ }
|
|
|
+ $result = $row->allowField(true)->save($params);
|
|
|
+ Db::commit();
|
|
|
+ } catch (ValidateException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ if ($result !== false) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error(__('No rows were updated'));
|
|
|
}
|
|
|
-
|
|
|
- Db::commit();
|
|
|
- } catch (\Throwable $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
- $this->success();
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
}
|
|
|
-
|
|
|
- // 获取用户列表
|
|
|
- $userList = \app\common\model\User::field('id,username,nickname')->select();
|
|
|
- $this->assign('userList', $userList);
|
|
|
- $this->assign('row', $row);
|
|
|
+
|
|
|
+ $this->view->assign('row', $row);
|
|
|
+ $this->view->assign('genderList', ['1' => __('Male'), '2' => __('Female')]);
|
|
|
+ $this->view->assign('isOwnList', ['1' => __('Own profile'), '0' => __('Others profile')]);
|
|
|
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除档案
|
|
|
+ * 删除
|
|
|
*/
|
|
|
public function del($ids = null)
|
|
|
{
|
|
|
- if (!$this->request->isPost()) {
|
|
|
+ if (false === $this->request->isPost()) {
|
|
|
$this->error(__("Invalid parameters"));
|
|
|
}
|
|
|
-
|
|
|
- $ids = $ids ? $ids : $this->request->post("ids");
|
|
|
+ $ids = $ids ?: $this->request->post("ids");
|
|
|
if (empty($ids)) {
|
|
|
- $this->error(__('Parameter %s can not be empty', 'ids'));
|
|
|
+ $this->error(__("Parameter %s can not be empty", "ids"));
|
|
|
}
|
|
|
-
|
|
|
$pk = $this->model->getPk();
|
|
|
$adminIds = $this->getDataLimitAdminIds();
|
|
|
if (is_array($adminIds)) {
|
|
|
$this->model->where($this->dataLimitField, 'in', $adminIds);
|
|
|
}
|
|
|
-
|
|
|
$list = $this->model->where($pk, 'in', $ids)->select();
|
|
|
- $count = 0;
|
|
|
|
|
|
+ $count = 0;
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
foreach ($list as $item) {
|
|
|
- // 删除相关数据
|
|
|
- BodyMeasurements::where('profile_id', $item->id)->delete();
|
|
|
- BodyTypeSelection::where('profile_id', $item->id)->delete();
|
|
|
- BodyAiReport::where('profile_id', $item->id)->delete();
|
|
|
+ // 删除相关的测量数据
|
|
|
+ Db::name('body_measurements')->where('profile_id', $item[$pk])->delete();
|
|
|
+ // 删除相关的体型选择数据
|
|
|
+ Db::name('body_type_selections')->where('profile_id', $item[$pk])->delete();
|
|
|
+ // 删除相关的AI报告
|
|
|
+ Db::name('ai_reports')->where('profile_id', $item[$pk])->delete();
|
|
|
|
|
|
$count += $item->delete();
|
|
|
}
|
|
|
Db::commit();
|
|
|
- } catch (\Throwable $e) {
|
|
|
+ } catch (PDOException | Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
- $this->success();
|
|
|
+ if ($count) {
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+ $this->error(__("No rows were deleted"));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查看档案详情
|
|
|
+ * 查看详情
|
|
|
*/
|
|
|
public function detail($ids = null)
|
|
|
{
|
|
|
- $profile = $this->model->with(['user', 'latestMeasurement', 'bodyTypeSelections.typeConfig', 'latestAiReport'])->find($ids);
|
|
|
- if (!$profile) {
|
|
|
- $this->error('档案不存在');
|
|
|
+ $row = $this->model->get($ids);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__("No Results were found"));
|
|
|
}
|
|
|
-
|
|
|
- // 获取完整档案数据
|
|
|
- $profileData = $profile->getFullProfileData();
|
|
|
-
|
|
|
- $this->assign('profile', $profileData);
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__("You have no permission"));
|
|
|
+ }
|
|
|
+ $this->view->assign("row", $row);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
@@ -229,25 +275,15 @@ class BodyProfile extends Backend
|
|
|
*/
|
|
|
public function measurements($profile_id = null)
|
|
|
{
|
|
|
- if (!$profile_id) {
|
|
|
- $this->error('档案ID不能为空');
|
|
|
- }
|
|
|
-
|
|
|
- $profile = $this->model->find($profile_id);
|
|
|
+ $profile = $this->model->get($profile_id);
|
|
|
if (!$profile) {
|
|
|
- $this->error('档案不存在');
|
|
|
+ $this->error(__("No Results were found"));
|
|
|
}
|
|
|
-
|
|
|
- if ($this->request->isAjax()) {
|
|
|
- // 获取测量记录
|
|
|
- $list = BodyMeasurements::where('profile_id', $profile_id)
|
|
|
- ->order('measurement_date DESC')
|
|
|
- ->paginate(10);
|
|
|
-
|
|
|
- return json(['code' => 0, 'msg' => '', 'count' => $list->total(), 'data' => $list->items()]);
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds) && !in_array($profile[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__("You have no permission"));
|
|
|
}
|
|
|
-
|
|
|
- $this->assign('profile', $profile);
|
|
|
+ $this->view->assign("profile", $profile);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
@@ -256,46 +292,25 @@ class BodyProfile extends Backend
|
|
|
*/
|
|
|
public function addMeasurement($profile_id = null)
|
|
|
{
|
|
|
- if (!$profile_id) {
|
|
|
- $this->error('档案ID不能为空');
|
|
|
- }
|
|
|
-
|
|
|
- $profile = $this->model->find($profile_id);
|
|
|
+ $profile = $this->model->get($profile_id);
|
|
|
if (!$profile) {
|
|
|
- $this->error('档案不存在');
|
|
|
+ $this->error(__("No Results were found"));
|
|
|
}
|
|
|
-
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds) && !in_array($profile[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__("You have no permission"));
|
|
|
+ }
|
|
|
+
|
|
|
if ($this->request->isPost()) {
|
|
|
$params = $this->request->post('row/a');
|
|
|
-
|
|
|
if (empty($params)) {
|
|
|
- $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ $this->error(__("Parameter %s can not be empty", ""));
|
|
|
}
|
|
|
-
|
|
|
- $params['profile_id'] = $profile_id;
|
|
|
-
|
|
|
- // 处理测量日期
|
|
|
- if (isset($params['measurement_date']) && $params['measurement_date']) {
|
|
|
- $params['measurement_date'] = strtotime($params['measurement_date']);
|
|
|
- } else {
|
|
|
- $params['measurement_date'] = time();
|
|
|
- }
|
|
|
-
|
|
|
- $measurement = new BodyMeasurements();
|
|
|
- $result = $measurement->save($params);
|
|
|
-
|
|
|
- if ($result === false) {
|
|
|
- $this->error($measurement->getError());
|
|
|
- }
|
|
|
-
|
|
|
+ // TODO: 实现添加测量数据逻辑
|
|
|
$this->success();
|
|
|
}
|
|
|
-
|
|
|
- // 获取测量字段
|
|
|
- $measurementFields = BodyMeasurements::getMeasurementFields($profile->gender);
|
|
|
|
|
|
- $this->assign('profile', $profile);
|
|
|
- $this->assign('measurementFields', $measurementFields);
|
|
|
+ $this->view->assign("profile", $profile);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
@@ -304,40 +319,15 @@ class BodyProfile extends Backend
|
|
|
*/
|
|
|
public function bodyTypes($profile_id = null)
|
|
|
{
|
|
|
- if (!$profile_id) {
|
|
|
- $this->error('档案ID不能为空');
|
|
|
- }
|
|
|
-
|
|
|
- $profile = $this->model->find($profile_id);
|
|
|
+ $profile = $this->model->get($profile_id);
|
|
|
if (!$profile) {
|
|
|
- $this->error('档案不存在');
|
|
|
+ $this->error(__("No Results were found"));
|
|
|
}
|
|
|
-
|
|
|
- if ($this->request->isPost()) {
|
|
|
- $selections = $this->request->post('selections/a');
|
|
|
-
|
|
|
- if (empty($selections)) {
|
|
|
- $this->error('请选择体型');
|
|
|
- }
|
|
|
-
|
|
|
- $result = BodyTypeSelection::saveUserSelections($profile_id, $selections);
|
|
|
-
|
|
|
- if (!$result) {
|
|
|
- $this->error('保存失败');
|
|
|
- }
|
|
|
-
|
|
|
- $this->success();
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds) && !in_array($profile[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__("You have no permission"));
|
|
|
}
|
|
|
-
|
|
|
- // 获取所有体型分类和选项
|
|
|
- $bodyTypeCategories = BodyTypeConfig::getAllCategories($profile->gender);
|
|
|
-
|
|
|
- // 获取用户已选择的体型
|
|
|
- $userSelections = BodyTypeSelection::getUserSelections($profile_id);
|
|
|
-
|
|
|
- $this->assign('profile', $profile);
|
|
|
- $this->assign('bodyTypeCategories', $bodyTypeCategories);
|
|
|
- $this->assign('userSelections', $userSelections);
|
|
|
+ $this->view->assign("profile", $profile);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
@@ -346,22 +336,16 @@ class BodyProfile extends Backend
|
|
|
*/
|
|
|
public function generateReport($profile_id = null)
|
|
|
{
|
|
|
- if (!$profile_id) {
|
|
|
- $this->error('档案ID不能为空');
|
|
|
- }
|
|
|
-
|
|
|
- $profile = $this->model->find($profile_id);
|
|
|
+ $profile = $this->model->get($profile_id);
|
|
|
if (!$profile) {
|
|
|
- $this->error('档案不存在');
|
|
|
+ $this->error(__("No Results were found"));
|
|
|
}
|
|
|
-
|
|
|
- $report = BodyAiReport::generateReport($profile_id);
|
|
|
-
|
|
|
- if (!$report) {
|
|
|
- $this->error('生成报告失败');
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ if (is_array($adminIds) && !in_array($profile[$this->dataLimitField], $adminIds)) {
|
|
|
+ $this->error(__("You have no permission"));
|
|
|
}
|
|
|
-
|
|
|
- $this->success('报告生成成功', null, ['report_id' => $report->id]);
|
|
|
+ // TODO: 实现AI报告生成逻辑
|
|
|
+ $this->success("AI报告生成功能开发中...");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -370,65 +354,62 @@ class BodyProfile extends Backend
|
|
|
public function viewReport($report_id = null)
|
|
|
{
|
|
|
if (!$report_id) {
|
|
|
- $this->error('报告ID不能为空');
|
|
|
- }
|
|
|
-
|
|
|
- $report = BodyAiReport::with(['profile'])->find($report_id);
|
|
|
- if (!$report) {
|
|
|
- $this->error('报告不存在');
|
|
|
+ $this->error(__("Parameter %s can not be empty", "report_id"));
|
|
|
}
|
|
|
-
|
|
|
- $this->assign('report', $report);
|
|
|
+ // TODO: 实现AI报告查看逻辑
|
|
|
+ $this->view->assign("report_id", $report_id);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * AI测量页面
|
|
|
+ * AI测量
|
|
|
*/
|
|
|
public function aiMeasurement($profile_id = null)
|
|
|
{
|
|
|
- if (!$profile_id) {
|
|
|
- $this->error('档案ID不能为空');
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $profile = $this->model->get($profile_id);
|
|
|
+ if (!$profile) {
|
|
|
+ $this->error(__("No Results were found"));
|
|
|
+ }
|
|
|
+ // TODO: 实现AI测量逻辑
|
|
|
+ $this->success("AI测量功能开发中...");
|
|
|
}
|
|
|
-
|
|
|
- $profile = $this->model->with(['user'])->find($profile_id);
|
|
|
+
|
|
|
+ $profile = $this->model->get($profile_id);
|
|
|
if (!$profile) {
|
|
|
- $this->error('档案不存在');
|
|
|
+ $this->error(__("No Results were found"));
|
|
|
}
|
|
|
-
|
|
|
- $this->assign('profile', $profile);
|
|
|
+ $this->view->assign("profile", $profile);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 统计数据
|
|
|
+ * 统计分析
|
|
|
*/
|
|
|
public function statistics()
|
|
|
{
|
|
|
- // 档案统计
|
|
|
- $profileStats = [
|
|
|
- 'total' => $this->model->count(),
|
|
|
- 'male' => $this->model->where('gender', 1)->count(),
|
|
|
- 'female' => $this->model->where('gender', 2)->count(),
|
|
|
- 'own' => $this->model->where('is_own', 1)->count(),
|
|
|
- 'others' => $this->model->where('is_own', 0)->count(),
|
|
|
- ];
|
|
|
-
|
|
|
- // BMI分布统计
|
|
|
- $bmiStats = [];
|
|
|
- $profiles = $this->model->where('height', '>', 0)->where('weight', '>', 0)->select();
|
|
|
- foreach ($profiles as $profile) {
|
|
|
- $bmi = $profile->calculateBMI();
|
|
|
- $level = $profile->getBMILevel();
|
|
|
- $bmiStats[$level] = isset($bmiStats[$level]) ? $bmiStats[$level] + 1 : 1;
|
|
|
+ $adminIds = $this->getDataLimitAdminIds();
|
|
|
+ $where = [];
|
|
|
+ if (is_array($adminIds)) {
|
|
|
+ $where[$this->dataLimitField] = ['in', $adminIds];
|
|
|
}
|
|
|
-
|
|
|
- // 体型选择统计
|
|
|
- $bodyTypeStats = BodyTypeSelection::getSelectionStatistics();
|
|
|
-
|
|
|
- $this->assign('profileStats', $profileStats);
|
|
|
- $this->assign('bmiStats', $bmiStats);
|
|
|
- $this->assign('bodyTypeStats', $bodyTypeStats);
|
|
|
+
|
|
|
+ // 基础统计
|
|
|
+ $totalProfiles = $this->model->where($where)->count();
|
|
|
+ $maleCount = $this->model->where($where)->where('gender', 1)->count();
|
|
|
+ $femaleCount = $this->model->where($where)->where('gender', 2)->count();
|
|
|
+ $ownProfiles = $this->model->where($where)->where('is_own', 1)->count();
|
|
|
+ $otherProfiles = $this->model->where($where)->where('is_own', 0)->count();
|
|
|
+
|
|
|
+ $statistics = [
|
|
|
+ 'total_profiles' => $totalProfiles,
|
|
|
+ 'male_count' => $maleCount,
|
|
|
+ 'female_count' => $femaleCount,
|
|
|
+ 'own_profiles' => $ownProfiles,
|
|
|
+ 'other_profiles' => $otherProfiles,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->view->assign("statistics", $statistics);
|
|
|
return $this->view->fetch();
|
|
|
}
|
|
|
}
|