/** * 发送手机验证码 */ function code() { $system = $this->model('system')->fetch('sms'); $system = $this->model('system')->toArray($system, 'sms'); $sms = new sms($system['uid'], $system['key'], $system['sign']); $telephone = $this->post->telephone; if ($telephone === NULL) { return $sms->getNum(); } else { if (validate::telephone($telephone)) { $smslogModel = $this->model('smslog'); if ($smslogModel->check($telephone)) { $code = random::number(6); $template = $system['template']; $template = sprintf($template, $code); $result = $sms->send($telephone, $template); if ($result > 0) { $smslogModel->create($telephone, $code); return json_encode(array('code' => 1, 'result' => 'ok', 'body' => $code)); } } return json_encode(array('code' => 2, 'result' => '短信发送失败')); } else { return json_encode(array('code' => 0, 'result' => '手机号码不合法')); } } }
/** * ajax请求树 * * @return string */ function ajaxtree() { $icon = array("icon-state-warning", "icon-state-success", "icon-state-danger", "icon-state-info"); if ($this->get->parent == '#') { $parent = 0; } else { $parent = $this->get->parent; } if (validate::int($parent)) { $categoryModel = $this->model('category'); $result = $categoryModel->fetchChild($parent); $tree = array(); foreach ($result as $category) { $temp = array(); $temp['id'] = $category['id']; $temp['text'] = $category['name']; $temp['icon'] = "fa fa-folder icon-lg " . $icon[array_rand($icon)]; //$temp['icon'] = 'http://localhost/home/application/assets/gravatar.jpg'; $result = $categoryModel->fetchChild($category['id']); $temp['children'] = !empty($result); if ($parent == 0) { $temp['type'] = 'root'; } $tree[] = $temp; } return new json($tree); } return new json(json::PARAMETER_ERROR, '错误的分类id'); }