public function delAction() { $p = $_REQUEST; $pType = empty($p['type']) ? Tool_Fnc::ajaxMsg('类型不为空') : trim($p['type']); $pDate = empty($p['date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : trim($p['date']); $pDid = empty($p['did']) ? Tool_Fnc::ajaxMsg('DID不能为空') : trim($p['did']); if (!Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } if (!Tool_Validate::az09($pDid)) { Tool_Fnc::ajaxMsg('did格式不正确'); } $tIWMO = new I_WeightModel(); $tSql = 'delete from ' . $tIWMO->table . ' where type = ' . $pType . ' and date = \'' . $pDate . '\' and did = \'' . $pDid . '\''; if (!$tIWMO->exec($tSql)) { Tool_Fnc::ajaxMsg('删除失败'); } Tool_Fnc::ajaxMsg('删除成功', 1); }
public function diethomeAction() { $p = $_REQUEST; $pDate = empty($p['date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : trim($p['date']); if (!Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } $tFAMO = new R_FoodaddModel(); $tFMO = new FoodModel(); $tDWLMO = new DryweightlogModel(); $tDatas = array(); $tDWLRow['weight'] = $tDWLMO->is_dryweight($this->tUid, $pDate); $tArr = $tFMO->diet('protein', $tDWLRow['weight']); $tDatas['protein']['total'] = $tArr['start']; $tSql = 'select * from (select fid,unit,amount,weight from ' . $tFAMO->table . ' where uid = ' . $this->tUid . ' and created >=' . strtotime($pDate) . ' and created <=' . strtotime($pDate . ' 23:59:59') . ') fa, ' . $tFMO->table . ' f where fa.fid = f.id'; $tList = $tFMO->query($tSql); $tDatas['protein']['surplus'] = 0; $tDatas['protein']['number'] = 0; if (!count($tList)) { Tool_Fnc::ajaxMsg('', 1, $tDatas); } #已经摄取 foreach ($tList as $tRow) { $tDatas['protein']['number'] += $tRow['protein'] / 100 * $tRow['weight']; #蛋白质 } unset($tList); #应摄取 #蛋白质 $tSurplus = $tArr['end'] - $tDatas['protein']['number']; $tDatas['protein']['surplus'] = $tSurplus <= 0 ? 0 : $tSurplus; Tool_Fnc::ajaxMsg('', 1, $tDatas); exit; }
public function delAction() { $p = $_REQUEST; $pType = empty($p['type']) ? Tool_Fnc::ajaxMsg('删除类型不能为空') : intval($p['type']); $pDate = empty($p['date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : trim($p['date']); if (!Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } $tMO = new R_BloodpressureModel(); $tSql = 'delete from ' . $tMO->table . ' where type = ' . $pType . ' and date = \'' . $pDate . '\' and uid = ' . $this->tUid; if (!$tMO->exec($tSql)) { Tool_Fnc::ajaxMsg('删除失败'); } Tool_Fnc::ajaxMsg('删除成功', 1); }
public function regAction() { $p = $_REQUEST; $pPhone = empty($p['phone']) ? '' : trim($p['phone']); $pPassword = empty($p['ptxt']) ? '' : trim($p['ptxt']); #客户端发送的必须是md5的 密码 $pCode = empty($p['code']) ? '0' : trim($p['code']); $pDid = empty($p['did']) ? '' : trim($p['did']); $tTime = time(); if (empty($pPassword)) { Tool_Fnc::ajaxMsg('密码不能为空'); } if (empty($pCode)) { Tool_Fnc::ajaxMsg('验证码不能为空'); } if (!Tool_Validate::integer($pCode)) { Tool_Fnc::ajaxMsg('验证码格式错误'); } if (strlen($pPassword) != 32) { Tool_Fnc::ajaxMsg('接口发送的必须是密文密码'); } if (empty($pDid) || !Tool_Validate::az09($pDid)) { Tool_Fnc::ajaxMsg('did error'); } $tUMO = new UserModel(); $tRow = $tUMO->field('count(0) c')->where('phone = \'' . $pPhone . '\'')->fRow(); if (!empty($tRow['c'])) { Tool_Fnc::ajaxMsg('该手机已被他人使用,请重新输入'); } $tUMO = new UserModel(); $tKey = Tool_Fnc::newrand(4); $tMd5str = Tool_Fnc::markmd5($pPassword, $tKey); $tCodeMO = new PhonecodeModel(); $tCodeCRow = $tCodeMO->check($pPhone, 1, $pCode); if ($tCodeCRow['status'] == 0) { Tool_Fnc::ajaxMsg($tCodeCRow['msg']); } $pSex = !isset($p['sex']) ? Tool_Fnc::ajaxMsg('请填写性别') : intval($p['sex']); $pDryWeight = !isset($p['dry_weight']) ? Tool_Fnc::ajaxMsg('请填写干体重') : floatval($p['dry_weight']); $pDateOfBirth = empty($p['date_of_birth']) ? Tool_Fnc::ajaxMsg('请填写出生日期') : trim($p['date_of_birth']); if (!empty($pDateOfBirth) && !Tool_Validate::is_date($pDateOfBirth)) { Tool_Fnc::ajaxMsg('日期格式不正确'); } $tData = array('phone' => $pPhone, 'reg_ip' => Tool_Fnc::realip(), "passwd" => $tMd5str, "reg_time" => $tTime, 'private_key' => $tKey, 'reg_did' => $pDid, 'user_type' => 0, 'sex' => $pSex, 'dry_weight' => $pDryWeight, 'date_of_birth' => $pDateOfBirth, 'reg_did' => $pDid); if (!($tID = $tUMO->insert($tData))) { Tool_Fnc::ajaxMsg('注册失败'); } //did入库 $tUDMO = new UserdidModel(); $tUDRow = $tUDMO->field('count(0) c')->where('uid = ' . $tID . ' and did = \'' . $pDid . '\'')->fRow(); if (empty($tUDRow['c'])) { $tData = array('uid' => $tID, 'did' => $pDid, 'created' => $tTime, 'ip' => Tool_Fnc::realip()); $tUDMO->insert($tData); } $tTokenarr = $this->creattoken($tID); //干重记录表数据更新 $tDWMO = new DryweightlogModel(); $tDryWeightLog = array('uid' => $tID, 'weight' => $pDryWeight, 'date' => date('Y-m-d'), 'month' => date('Y-m'), 'year' => date('Y'), 'created' => $tTime); $tDWMO->insert($tDryWeightLog); //匿名转实名 $tUMO->incognito_real($pDid, $tID); $tTokenarr = array_merge($tTokenarr, array('user_type' => 0)); Tool_Fnc::ajaxMsg('注册成功', 1, $tTokenarr); }
public function yearAction() { $p = $_REQUEST; $pDate = empty($p['date']) ? '' : trim($p['date']); $pOpt = empty($p['opt']) ? 'left' : Tool_Fnc::safe_string($p['opt']); if (!empty($pDate) && !Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } $tWhere = ''; $tTime = strtotime($pDate); if ($pOpt == 'left') { if (!empty($pDate)) { $tEnd = date('Y-m-d', $tTime - 86400); } else { $tTime = time(); $tEnd = date('Y-m-d'); } $tStart = date('Y-m-d', $tTime - 86400 * 364); } else { if (!empty($pDate)) { $tStart = date('Y-m-d', $tTime + 86400); } else { $tTime = time(); $tStart = date('Y-m-d'); } $tEnd = date('Y-m-d', $tTime + 86400 * 364); } $tTRMO = new BqetreatmentrecordModel(); $tTRDatas = $tTRMO->field('bodyweight_bef,bodyweight_after,treate_date')->where('uid = ' . $this->tUid . ' and treate_date between \'' . $tStart . '\' and \'' . $tEnd . '\'')->order('treate_date asc')->fList(); $tDWLMO = new DryweightlogModel(); $tDWLDatas = $tDWLMO->field('weight,date')->where('uid = ' . $this->tUid . ' and date between \'' . $tStart . '\' and \'' . $tEnd . '\'')->fList(); //最开始日期 $tSql = 'select treate_date from ' . $tTRMO->table . ' where uid = ' . $this->tUid . ' order by treate_date asc limit 1'; $tTRMOList = $tTRMO->query($tSql); #用户最新干体重 $tUMO = new UserModel(); $tURow = $tUMO->field('dry_weight')->where('id = ' . $this->tUid)->fRow(); //如果没有干体重 初始化 $tDatearr = array(); for ($i = 0; $i < 364; $i++) { $tDatearr[] = date('Y-m-d', strtotime($tStart) + 86400 * $i); } $tDWLDate = array(); foreach ($tDWLDatas as $tRow) { $tDWLDate[] = $tRow['date']; } $tDatediff = array_diff($tDatearr, $tDWLDate); $tDiffarr = array(); foreach ($tDatediff as $tDate) { break; #判断该日期之前的干体重 $tDWLRow = $tDWLMO->field('weight')->where('uid = ' . $this->tUid . ' and date < ' . $tDate)->order('date desc')->limit('1')->fRow(); if (count($tDWLRow)) { $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tDWLRow['weight']); continue; } #判断该日期之后临近的干体重 $tDWLRow = $tDWLMO->field('weight')->where('uid = ' . $this->tUid . ' and date > ' . $tDate)->order('date desc')->limit('1')->fRow(); if (count($tDWLRow)) { $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tDWLRow['weight']); continue; } #当前用户干体重 $tDWLDatas[] = $tDiffarr[] = array('date' => $tDate, 'weight' => $tURow['dry_weight']); } #将没有干体重的天入库 foreach ($tDiffarr as $tRow) { break; if ($tDWLMO->in_weight($this->tUid, $tRow['date'])) { continue; } $tData = array('weight' => $tRow['weight'], 'uid' => $this->tUid, 'created' => $tTime, 'date' => $tRow['date'], 'month' => date('Y-m', strtotime($tRow['date'])), 'year' => date('Y-m', strtotime($tRow['date']))); $tDWLMO->insert($tData); } #排除 只要有体重的 干体重╮(╯▽╰)╭ $tTRDate = array(); foreach ($tTRDatas as $tRow) { $tTRDate[] = $tRow['treate_date']; } foreach ($tDWLDatas as $tKey => $tRow) { if (!in_array($tRow['date'], $tTRDate)) { unset($tDWLDatas[$tKey]); } } $tDWLDatas = Tool_Fnc::arraySort($tDWLDatas, 'date', 'asc'); Tool_Fnc::ajaxMsg('', 1, array('dry_weight' => $tDWLDatas, 'weight' => $tTRDatas, 'start_treate_date' => $tTRMOList[0]['treate_date'])); }
public function diethomeAction() { $p = $_REQUEST; $pDate = empty($p['date']) ? Tool_Fnc::ajaxMsg('日期不能为空') : trim($p['date']); $pDid = empty($p['did']) ? Tool_Fnc::ajaxMsg('DID不能为空') : trim($p['did']); if (!Tool_Validate::az09($pDid)) { Tool_Fnc::ajaxMsg('did格式不正确'); } if (!Tool_Validate::is_date($pDate)) { Tool_Fnc::ajaxMsg('日期不正确'); } $tFAMO = new I_FoodaddModel(); $tFMO = new FoodModel(); $tDatas = array(); $tSql = 'select * from (select fid,unit,amount,weight from ' . $tFAMO->table . ' where did = \'' . $pDid . '\' and created >=' . strtotime($pDate) . ' and created <=' . strtotime($pDate . ' 23:59:59') . ') fa, ' . $tFMO->table . ' f where fa.fid = f.id'; $tList = $tFMO->query($tSql); $tDatas['protein'] = array('total' => 90, 'surplus' => 0, 'number' => 0); if (!count($tList)) { Tool_Fnc::ajaxMsg('', 1, $tDatas); } #已经摄取 foreach ($tList as $tRow) { $tDatas['protein']['number'] += $tRow['protein'] / 100 * $tRow['weight']; #蛋白质 } unset($tList); $tDatas['protein']['total'] = 90; $tDatas['protein']['surplus'] = 90 - $tDatas['protein']['number']; Tool_Fnc::ajaxMsg('', 1, $tDatas); exit; }