UserPraise.php 791 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. use think\Db;
  5. class UserPraise extends Model{
  6. protected $createTime = "inputtime";
  7. protected $updateTime = '';
  8. protected $autoWriteTimestamp = 'datetime'; // 开启自动写入时间戳字段
  9. public function initialize(){
  10. parent::initialize();
  11. }
  12. /**
  13. * 添加数据
  14. * @param array $data
  15. * @return number|string
  16. */
  17. public function add($data){
  18. Db::name("user")->where(['id'=>$data['target_id']])->setInc('praise');
  19. return $this->save($data);
  20. }
  21. /**
  22. * 查找制定目标数据
  23. * @param int $target
  24. * @return array|string|\think\Model
  25. */
  26. public function getTargetInfo($user, $target){
  27. return $this->db()->where(['user_id'=>$user, 'target_id'=>$target])->find();
  28. }
  29. }