| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | <?phpnamespace app\admin\controller;use app\common\controller\Backend;use app\common\model\BodyProfile as BodyProfileModel;use app\common\model\BodyMeasurements;use app\common\model\BodyTypeConfig;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;use app\common\Service\BodyProfileService;/** * 身体档案管理 * * @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()    {        parent::_initialize();        $this->model = new BodyProfileModel;    }    /**     * 默认生成的控制器所继承的父类中有index方法,在这里重写下     */    public function index()    {        //当前是否为关联查询        $this->relationSearch = true;        //设置过滤方法        $this->request->filter(['strip_tags', 'trim']);        if ($this->request->isAjax()) {            //如果发送的来源是Selectpage,则转发到Selectpage            if ($this->request->request('keyField')) {                return $this->selectpage();            }            list($where, $sort, $order, $offset, $limit) = $this->buildparams();                        $list = $this->model                ->with(['user'])                ->where($where)                ->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($result);        }        return $this->view->fetch();    }    /**     * 查看详情     */    public function detail($ids = null)    {        $row = $this->model->get($ids);        if (!$row) {            $this->error(__("No Results were found"));        }        $adminIds = $this->getDataLimitAdminIds();        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {            $this->error(__("You have no permission"));        }        // 使用方法查询        $profileData = BodyProfileService::getProfileDetail($row->id, $row->user_id);        $this->view->assign("profileData", $profileData);        $this->view->assign("row", $row);        return $this->view->fetch();    }}
 |