Bladeren bron

提交技能修改。

superbee 8 jaren geleden
bovenliggende
commit
f422f40d72
2 gewijzigde bestanden met toevoegingen van 65 en 63 verwijderingen
  1. 1 2
      Application/Home/Controller/UserController.class.php
  2. 64 61
      Application/User/Model/SkillModel.class.php

+ 1 - 2
Application/Home/Controller/UserController.class.php

@@ -16,7 +16,6 @@ class UserController extends Controller{
 	
 	public function login(){
 		$data = decode($_POST);
-		$data['u'] = 'fuck';
 
 		$info = $this->userModel->loginByUid($data['u']);
 		$info['skill'] = $this->skillModel->getUserSkill($info['i']);
@@ -34,7 +33,7 @@ class UserController extends Controller{
 	public function addskill(){
 		$data = decode($_POST);
 		
-		$info = $this->skillModel->addUserSkill($data['u'], $data['i']);
+		$info = $this->skillModel->addUserSkill($data['u'], $data['s']);
 		return $this->ajaxReturn($info);
 	}
 	

+ 64 - 61
Application/User/Model/SkillModel.class.php

@@ -1,61 +1,64 @@
-<?php
-namespace User\Model;
-use Think\Model;
-
-/**
- * 用户模型
- * @author Superbee
- *
- */
-class SkillModel extends Model {
-	
-    protected $fields = array('id', 'user_id', 'skill_id', 'time', '_pk' => 'id', '_autoinc' => false);
-    
-    public function __construct(){
-    	$this->dbName = "user_skill";
-    	$this->db = M($this->dbName);
-    }
-
-    /**
-     * 添加技能
-     * @param int $user
-     * @param int $skill
-     */
-    public function addUserSkill($user, $skill){
-    	$data = $this->db->where(['user_id'=>$user, 'skill_id'=>$skill])->find();
-    	$time = time();
-    	
-    	if($data){
-    		$data['time'] = $time;
-    		$this->db->save($data);
-    	}else{
-	    	$data = ['user_id'=>$user, 'skill_id'=>$skill, 'id'=>getId(), 'time'=>$time];
-    		$this->db->add($data);
-    	}
-    	
-    	return ['i'=>$data['id'], 's'=>$skill, 't'=>$time];
-    }
-    
-    /**
-     * 获取单个技能
-     * @param int $id
-     * @return array skill_id, time
-     */
-    public function getSkillById($id){
-    	$res = $this->db->field('skill_id s, time t')->where(['id'=>$id])->find();
-    	
-    	return $res;
-    }
-    
-    /**
-     * 获取所有技能
-     * @param int $user
-     */
-    public function getUserSkill($user){
-    	$res = $this->db->field('id i, skill_id s, time t')->where(['user_id'=>$user])->select();
-    	return ($res)?$res:'';
-    }
-    
-}
-
-
+<?php
+namespace User\Model;
+use Think\Model;
+
+/**
+ * 用户模型
+ * @author Superbee
+ *
+ */
+class SkillModel extends Model {
+	
+    protected $fields = array('id', 'user_id', 'skill_id', 'time', '_pk' => 'id', '_autoinc' => false);
+    
+    public function __construct(){
+    	$this->dbName = "user_skill";
+    	$this->db = M($this->dbName);
+    }
+
+    /**
+     * 添加技能
+     * @param int $user
+     * @param int $skill
+     */
+    public function addUserSkill($user, $skill){
+    	$data = $this->db->where(['user_id'=>$user, 'skill_id'=>$skill])->find();
+    	$time = time();
+    	$id = 0;
+    	
+    	if($data){
+    		$id = $data['id'];
+    		$data['time'] = $time;
+    		$this->db->save($data);
+    	}else{
+    		$id = getId();
+	    	$data = ['user_id'=>$user, 'skill_id'=>$skill, 'id'=>$id, 'time'=>$time];
+    		$this->db->add($data);
+    	}
+    	
+    	return ['i'=>$id, 's'=>$skill, 't'=>$time];
+    }
+    
+    /**
+     * 获取单个技能
+     * @param int $id
+     * @return array skill_id, time
+     */
+    public function getSkillById($id){
+    	$res = $this->db->field('skill_id s, time t')->where(['id'=>$id])->find();
+    	
+    	return $res;
+    }
+    
+    /**
+     * 获取所有技能
+     * @param int $user
+     */
+    public function getUserSkill($user){
+    	$res = $this->db->field('id i, skill_id s, time t')->where(['user_id'=>$user])->select();
+    	return ($res)?$res:'';
+    }
+    
+}
+
+