From 76c305d8c33b69fffb0ead4d09365fca31058f23 Mon Sep 17 00:00:00 2001 From: printempw Date: Sat, 13 Aug 2016 23:25:10 +0800 Subject: [PATCH] add option for setting score of private textures --- app/Controllers/SkinlibController.php | 15 ++++---- assets/src/js/skinlib.js | 6 ++- resources/views/admin/score.tpl | 20 ++++++++-- resources/views/skinlib/upload.tpl | 5 +++ setup/options.php | 53 ++++++++++++++------------- 5 files changed, 61 insertions(+), 38 deletions(-) diff --git a/app/Controllers/SkinlibController.php b/app/Controllers/SkinlibController.php index ba9b9593..a4c7429b 100644 --- a/app/Controllers/SkinlibController.php +++ b/app/Controllers/SkinlibController.php @@ -123,18 +123,21 @@ class SkinlibController extends BaseController $t = new Texture(); $t->name = $_POST['name']; $t->type = $_POST['type']; + $t->like = 1; $t->hash = \Storage::upload($_FILES['file']); $t->size = ceil($_FILES['file']['size'] / 1024); $t->public = ($_POST['public'] == 'true') ? "1" : "0"; $t->uploader = $this->user->uid; $t->upload_at = Utils::getTimeFormatted(); - if ($this->user->getScore() / Option::get('score_per_storage') < $t->size) + $cost = $t->size * (($t->public == "1") ? Option::get('score_per_storage') : Option::get('private_score_per_storage')); + + if ($this->user->getScore() < $cost) View::json('积分不够啦', 7); $results = Texture::where('hash', $t->hash)->get(); - if (!$results->isEmpty()) - { + + if (!$results->isEmpty()) { foreach ($results as $result) { if ($result->type == $t->type) { View::json([ @@ -148,13 +151,9 @@ class SkinlibController extends BaseController $t->save(); - $this->user->setScore($t->size, 'minus'); + $this->user->setScore($cost, 'minus'); if ($this->user->closet->add($t->tid, $t->name)) { - $t = Texture::find($t->tid); - $t->likes += 1; - $t->save(); - View::json([ 'errno' => 0, 'msg' => '材质 '.$_POST['name'].' 上传成功', diff --git a/assets/src/js/skinlib.js b/assets/src/js/skinlib.js index 7b83b9ab..0950c29f 100644 --- a/assets/src/js/skinlib.js +++ b/assets/src/js/skinlib.js @@ -2,7 +2,7 @@ * @Author: printempw * @Date: 2016-07-19 10:46:38 * @Last Modified by: printempw - * @Last Modified time: 2016-08-06 18:51:20 + * @Last Modified time: 2016-08-13 23:23:14 */ 'use strict'; @@ -20,6 +20,10 @@ $('#page-select').on('change', function() { }); +$('#private').on('ifToggled', function() { + $(this).prop('checked') ? $('#msg').show() : $('#msg').hide(); +}); + function addToCloset(tid) { $.getJSON('../skinlib/info/'+tid, function(json) { var dom = '
'+ diff --git a/resources/views/admin/score.tpl b/resources/views/admin/score.tpl index 5ddd5583..c9a30a0a 100644 --- a/resources/views/admin/score.tpl +++ b/resources/views/admin/score.tpl @@ -27,9 +27,10 @@
$value) { + if ($key != "option" && $key != "submit") + Option::set($key, $value); + } echo '
设置已保存。
'; } ?> @@ -45,6 +46,19 @@ + + + + +
私密材质存储 + + +
+ + 积分 = 1 KB +
+ +
角色 diff --git a/resources/views/skinlib/upload.tpl b/resources/views/skinlib/upload.tpl index ee1f49b7..fdfbe86f 100644 --- a/resources/views/skinlib/upload.tpl +++ b/resources/views/skinlib/upload.tpl @@ -41,7 +41,12 @@ + + +