Prechádzať zdrojové kódy

commit user comment and praise model and controller

superbee 8 rokov pred
rodič
commit
0915ef717a

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

@@ -0,0 +1,44 @@
+<?php
+namespace app\home\controller;
+
+use think\Controller;
+use app\user\model\UserComment;
+use think\Config;
+
+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]);
+	}
+	
+}

+ 2 - 2
application/home/controller/Pay.php

@@ -24,10 +24,10 @@ class Pay extends Controller{
 // 		$data['u'] = 1704251601802555535;
 		
 		$iapInfo = Db::name('iap_config')->where(['item_id'=>$data['i']])->find();
-		if(empty($iapInfo)) exit(json(['error'=>1111]));
+		if(empty($iapInfo)) return (json(['error'=>1111]));
 		
 		$plugin = $this->payPluginModel->getPayPluginByType($data['t']);
-		if(empty($plugin)) exit(json(['error'=>1111]));
+		if(empty($plugin)) return (json(['error'=>1111]));
 		
 		$biz_content = $this->getAliTradeInfo($iapInfo, $data['u']);
 		$val = $this->getAliPayInfo($plugin, $biz_content);

+ 30 - 0
application/home/controller/Praise.php

@@ -0,0 +1,30 @@
+<?php
+namespace app\home\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]);
+	}
+	
+}

+ 30 - 0
application/user/model/UserComment.php

@@ -0,0 +1,30 @@
+<?php
+namespace app\user\model;
+
+use think\Model;
+
+class UserComment extends Model{
+	protected $createTime = "inputtime";
+	protected $updateTime = '';
+	protected $autoWriteTimestamp = 'datetime';		// 开启自动写入时间戳字段
+	
+	public function initialize(){
+		parent::initialize();
+	}
+	
+	public function getInfo($user, $type, $page = 0){
+		$this->db()
+		->alias("c")
+		->field("u.short s, c.inputtime t, c.content c")
+		->where(['c.user_id'=>$user, "c.type"=>$type])
+		->join("gd_user u", "c.comment_id = u.id", "left")
+		->page($page, config('paginate.list_rows'))
+		->order("inputtime DESC")
+		->select();
+	}
+	
+	public function add($data){
+		return $this->save($data);
+	}
+	
+}

+ 1 - 1
application/user/model/UserPay.php

@@ -5,7 +5,7 @@ use think\Model;
 
 class UserPay extends Model{
 	
-	protected $createTime = 'create_time';			// 每次更新时间
+	protected $createTime = 'create_time';			// 每次创建时间
 	protected $autoWriteTimestamp = 'datetime';		// 开启自动写入时间戳字段
 	
 	public function initialize(){

+ 36 - 0
application/user/model/UserPraise.php

@@ -0,0 +1,36 @@
+<?php
+namespace app\user\model;
+
+use think\Model;
+use think\Db;
+
+class UserPraise extends Model{
+	
+	protected $createTime = "inputtime";
+	protected $updateTime = '';
+	protected $autoWriteTimestamp = 'datetime';		// 开启自动写入时间戳字段
+	
+	public function initialize(){
+		parent::initialize();
+	}
+	
+	/**
+	 * 添加数据
+	 * @param array $data
+	 * @return number|string
+	 */
+	public function add($data){
+		Db::name("user")->where(['id'=>$data['target_id']])->setInc('praise');
+		return $this->save($data);
+	}
+	
+	/**
+	 * 查找制定目标数据
+	 * @param int $target
+	 * @return array|\think\db\false|PDOStatement|string|\think\Model
+	 */
+	public function getTargetInfo($user, $target){
+		return $this->db()->where(['user_id'=>$user, 'target_id'=>$target])->find();
+	}
+	
+}