<?php


namespace app\admin\controller\bbfxshop\tongue_diagnosis;

use app\admin\controller\bbfxshop\Base;
use think\Db;


class Diagnose extends Base
{
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\TongueDiagnosis;
    }
    
    public function getList(){
        $params = $this->param();
        
        $pindex = max(1, intval($params["page"]));
        $psize = intval($params["limit"])?intval($params["limit"]):10;
        $where = array("a.uniacid"=>UNIACID);
        
        $list = Db::name("bbfx_tongue_diagnosis_record")->alias("a")->join("bbfx_user b","a.user_id=b.id","LEFT")->where($where)->field("a.*,b.nickname,b.avatar")->order('id desc')->limit(($pindex - 1) * $psize,$psize)->select();
        $total = Db::name("bbfx_tongue_diagnosis_record")->alias("a")->join("bbfx_user b","a.user_id=b.id","LEFT")->where($where)->count();
        
        foreach ($list as $key => &$val){
            $val['avatar'] = cdnurl($val['avatar']);
            $val['tf_image'] = cdnurl($val['tf_image']);
            $val['ff_image'] = cdnurl($val['ff_image']);
            $val['tb_image'] = cdnurl($val['tb_image']);
            $val['createtime'] = date("Y-m-d H:i:s",$val['createtime']);
        }
        unset($val);
        
        __success("操作成功",['total'=>$total,'list'=>$list]);
    }

    public function detail(){
        $id = $this->param("id/d");

        $item = Db::name("bbfx_tongue_diagnosis_record")->where(['uniacid'=>UNIACID,'id'=>$id])->find();
        if(empty($item)){
            __error("数据不存在");
        }

        $item['tf_image'] = cdnurl($item['tf_image']);
        $item['ff_image'] = cdnurl($item['ff_image']);
        $item['tb_image'] = cdnurl($item['tb_image']);
        $item['createtime'] = date("Y-m-d H:i:s",$item['createtime']);
        if(!empty($item['result'])) $item['result'] = iunserializer($item['result']);
        if(!empty($item['report'])) $item['report'] = iunserializer($item['report']);

        __success("操作成功",$item);
    }
    
    public function delete(){
        $this->commonDelete("bbfx_tongue_diagnosis_record");
    }
}