소스 검색

commit new home module

superbee 8 년 전
부모
커밋
581d15fff2

+ 0 - 1
application/home/controller/Comment.php

@@ -3,7 +3,6 @@ namespace app\home\controller;
 
 use think\Controller;
 use app\user\model\UserComment;
-use think\Config;
 
 class Comment extends Controller {
 	

+ 21 - 0
application/newhome/config.php

@@ -0,0 +1,21 @@
+<?php
+// +----------------------------------------------------------------------
+// | ThinkPHP [ WE CAN DO IT JUST THINK ]
+// +----------------------------------------------------------------------
+// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
+// +----------------------------------------------------------------------
+// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
+// +----------------------------------------------------------------------
+// | Author: liu21st <liu21st@gmail.com>
+// +----------------------------------------------------------------------
+
+return [
+
+    // +----------------------------------------------------------------------
+    // | 模板设置
+    // +----------------------------------------------------------------------
+    'template' => [
+		'layout_on' => false,
+	],
+
+];

+ 43 - 0
application/newhome/controller/Comment.php

@@ -0,0 +1,43 @@
+<?php
+namespace app\newhome\controller;
+
+use think\Controller;
+use app\user\model\UserComment;
+
+class Comment extends Controller {
+	
+	private $commentModel;
+	
+	public function _initialize(){
+		parent::_initialize();
+		
+		$this->commentModel = new UserComment();
+	}
+	
+	public function index(){
+		$data = decode($this->request->post());
+		
+		$user = $data['u'];
+		$page = $data['p'];
+		$type = $data['t'];
+		
+		$info = $this->commentModel->getInfo($user, $type, $page);
+		
+		return json(["l"=>$info]);
+	}
+	
+	public function comment(){
+		$data = decode($this->request->post());
+		
+		$user = $data['u'];
+		$comment = $data['c'];
+		$content = $data['i'];
+		$type = $data['t'];		
+		
+		$data = ['id'=>getId(), 'user_id'=>$user, 'comment_id'=>$comment, 'content'=>$content, 'type'=>$type];
+		$this->commentModel->add($data);
+		
+		return json(['error'=>0]);
+	}
+	
+}

+ 15 - 0
application/newhome/controller/Index.php

@@ -0,0 +1,15 @@
+<?php
+namespace app\newhome\controller;
+
+use think\Controller;
+use think\Db;
+
+class Index extends Controller {
+	
+	public function index()
+	{
+		$data = Db::name('config')->select();
+		return json(["l"=>$data]);
+	}
+	
+}

+ 85 - 0
application/newhome/controller/Pay.php

@@ -0,0 +1,85 @@
+<?php
+namespace app\newhome\controller;
+
+use think\Controller;
+use think\Db;
+use app\user\model\PayPlugin;
+use app\user\model\User;
+use app\user\model\UserPay;
+
+class Pay extends Controller{
+	private $payPluginModel, $userModel;
+	
+	public function _initialize(){
+		
+		$this->payPluginModel= new PayPlugin();
+		$this->userModel = new User();
+	}
+	
+	public function pay(){
+		$data = decode($this->request->post());
+		
+// 		$data['i'] = 'com.dashgame.garden.packone';
+// 		$data['t'] = 1;
+// 		$data['u'] = 1704251601802555535;
+		
+		$iapInfo = Db::name('iap_config')->where(['item_id'=>$data['i']])->find();
+		if(empty($iapInfo)) return (json(['error'=>1111]));
+		
+		$plugin = $this->payPluginModel->getPayPluginByType($data['t']);
+		if(empty($plugin)) return (json(['error'=>1111]));
+		
+		$biz_content = $this->getAliTradeInfo($iapInfo, $data['u']);
+		$val = $this->getAliPayInfo($plugin, $biz_content);
+		
+		return http_build_query($val);
+	}
+	
+	public function notify(){
+		echo 'success';
+	}
+	
+	private function getAliTradeInfo($ipa, $user){
+		$content = [];
+		
+		$content['subject'] = $ipa['desc'];
+		$content['out_trade_no'] = $tradeNo = 'D'.getId();
+		$content['total_amount'] = $ipa['price'];
+// 		$content['total_amount'] = 0.01;
+		$content['product_code'] = 'QUICK_MSECURITY_PAY';
+		$content['timeout_express'] = '90m';
+		$content['body'] = $ipa['desc'];
+		
+		$userPay = new UserPay();
+		$userPay->add(['user_id'=>$user, 'cost'=>$ipa['price'], 'pay_id'=>$ipa['id'], 'out_trade_no'=>$tradeNo]);
+		
+		return json_encode($content);
+	}
+	
+	private function getAliPayInfo($plugin, $biz_content){
+		$params = [];
+		
+		$params['app_id'] = $plugin['appid'];
+		$params['method'] = 'alipay.trade.app.pay';
+		$params['format'] = "JSON";
+		$params['charset'] = "UTF-8";
+		$params['version'] = "1.0";
+		$params['timestamp'] = getCurrentTime();
+		$params['sign_type'] = "RSA2";
+		$params['notify_url'] = 'http://'.$_SERVER['SERVER_NAME']._PHP_FILE_.'/'.$this->request->module().'/'.$this->request->controller().'/notify';
+		$params['biz_content'] = $biz_content;
+
+		ksort($params);
+
+        $sign = aliSign($plugin['private_key'], getAliSignContent($params));
+        $params['sign'] = $sign;
+		
+		foreach ($params as &$value) {
+            $value = urlencode($value);
+		}
+		
+		return $params;
+	}
+	
+}
+

+ 41 - 0
application/newhome/controller/Praise.php

@@ -0,0 +1,41 @@
+<?php
+namespace app\newhome\controller;
+
+use think\Controller;
+use app\user\model\UserPraise;
+
+class Praise extends Controller{
+	private $praiseModel;
+	
+	public function _initialize(){
+		parent::_initialize();
+		
+		$this->praiseModel = new UserPraise();
+	}
+	
+	public function click(){
+		$data = decode($this->request->post());
+		
+		$user = $data['u'];
+		$target = $data['t'];
+		
+		$info = $this->praiseModel->getTargetInfo($user, $target);
+		if($info) return json(['error'=>1212]);
+		
+		$this->praiseModel->add(['id'=>getId(), "user_id"=>$user, 'target_id'=>$target]);
+		
+		return json(['error'=>0]);
+	}
+	
+	public function target(){
+		$data = decode($this->request->post());
+		
+		$user = $data['u'];
+		$target = $data['t'];
+		
+		$info = $this->praiseModel->getTargetInfo($user, $target);
+		
+		return json(['i'=>($info)?1:0]);
+	}
+	
+}

+ 124 - 0
application/newhome/controller/User.php

@@ -0,0 +1,124 @@
+<?php
+namespace app\newhome\controller;
+
+use think\Controller;
+use app\user\model\UserSkill;
+
+class User extends Controller {
+	
+	private $userModel, $skillModel;
+	
+	public function _initialize(){
+		$this->skillModel = new UserSkill();
+		$this->userModel = new \app\user\model\User(); 
+		
+	}
+	
+	public function login()
+	{
+		$data = decode($this->request->post());
+		
+		$info = $this->userModel->loginByUid($data['u']);
+		$info['s'] = $this->skillModel->getUserSkill($info['i']);
+		$info['time'] = time();
+		
+		return json($info);
+	}
+	
+	public function getskill(){
+		$data = decode($this->request->post());
+		
+		$info = $this->skillModel->getSkillByInfo($data['i']);
+		return json($info);
+	}
+	
+	public function addskill(){
+		$data = decode($this->request->post());
+		
+		$info = $this->skillModel->addUserSkill($data['u'], $data['s']);
+		return json($info);
+	}
+	
+	public function other(){
+		$data = decode($this->request->post());
+		
+		$res = $this->userModel->getUserById($data['u']);
+		$path = "load/".$res['id'].'.txt';
+		
+		$file = fopen($path, "r") or die(json(['error'=>1009]));
+		$info = fread($file, filesize($path));
+		fclose($file);
+		
+		return json(['l'=>$info, 'p'=>$res['praise']]);
+	}
+	
+	public function load(){
+		$data = decode($this->request->post());
+		$id = $data['u'];
+		$path = "load/$id.txt";
+		
+		$res = $this->userModel->getUserById($id);
+		
+		$file = fopen($path, "r") or die(json(['error'=>1009]));
+		$info = fread($file, filesize($path));
+		fclose($file);
+		
+		return json(['l'=>$info, 'p'=>$res['praise']]);
+	}
+	
+	public function save(){
+		$data = decode($this->request->post());
+		$id = $data['u'];
+		$path = "load/$id.txt";
+		
+		$file = fopen($path, 'w') or die(json(['error'=>1009]));
+		fwrite($file, $data['l']);
+		fclose($file);
+		
+		return json(['error'=>0]);
+	}
+	
+	public function rand(){
+		$data = decode($this->request->post());
+		
+		$id = $this->userModel->randOtherId($data['i']);
+		$res = $this->userModel->getUserById($id);
+		
+		$path = "load/$id.txt";
+		$file = fopen($path, "r") or die(json(['error'=>1009]));
+		$info = fread($file, filesize($path));
+		fclose($file);
+		
+		return json(['l'=>$info, 'p'=>$res['praise']]);
+	}
+	
+	public function delete(){
+		$data = decode($this->request->post());
+		
+		$id = $data['s'];
+		
+		$path = "load/$id.txt";
+		$res = unlink($path);
+		
+		return json(['r'=>(($res)?1:0)]);
+	}
+	
+	public function look(){
+		$res = $this->userModel->lookList();
+		
+		return json(['l'=>$res]);
+	}
+	
+	public function nickname(){
+		$data = decode($this->request->post());
+		
+		$nickname = trim($data['n']);
+		$res = $this->userModel->findUserByName($nickname);
+		if($res) return json(['error'=>2020]);
+		
+		$this->userModel->addAndSave(['id'=>$data['u'], 'nickname'=>$nickname]);
+		
+		return json(['error'=>0]);
+	}
+	
+}

+ 17 - 7
application/user/model/User.php

@@ -114,18 +114,28 @@ class User extends Model{
 	 */
 	public function randOtherCode($id){
 		$info = $this->db()->field('short')->where("id", "<>", $id)->select();
-		return $this->getUserJsonFile($info);
+		return $this->getUserJsonFile($info, 'short');
 	}
 	
-	private function getUserJsonFile($info){
+	private function getUserJsonFile($info, $field){
 		$r = rand(0, count($info)-1);
-		$short = $info[$r]['short'];
-		$path = "load/$short.txt";
+		$filename = $info[$r][$field];
+		$path = "load/$filename.txt";
 		if(!file_exists($path)){
 			unset($info[$r]);
-			$short = $this->getUserJsonFile(array_values($info));
+			$short = $this->getUserJsonFile(array_values($info), $field);
 		}
-		return $short;
+		return $filename;
+	}
+	
+	/**
+	 * 随机出非个人的Id
+	 * @param int $id
+	 * @return int
+	 */
+	public function randOtherId($id){
+		$info = $this->db()->field('id')->where("id", "<>", $id)->select();
+		return $this->getUserJsonFile($info, 'id');
 	}
 	
 	/**
@@ -181,7 +191,7 @@ class User extends Model{
 	 * @return array
 	 */
 	public function findUserByName($nickname){
-		return $this->db()->where(['nickname'=>$nickname])->find()->toArray();
+		return $this->db()->where(['nickname'=>$nickname])->find();
 	}
 	
 }