This commit is contained in:
2024-11-21 16:40:44 +08:00
commit a5029a2be7
69 changed files with 3160 additions and 0 deletions

View File

@ -0,0 +1,41 @@
{
"type": "think-admin-plugin",
"name": "jerryyan/think-plugs-points-mall",
"license": "WTFPL",
"homepage": "https://thinkadmin.top",
"description": "Points Mall Plugin for ThinkAdmin",
"authors": [
{
"name": "Jerry Yan",
"email": "jerryyan0912@qq.com"
}
],
"require": {
"php": ">7.1"
},
"autoload": {
"psr-4": {
"plugin\\points_mall\\": "src"
}
},
"extra": {
"config": {
"type": "module",
"name": "积分商城",
"document": "https://thinkadmin.top/plugin/think-plugs-wechat.html",
"description": "积分商城"
},
"think": {
"services": [
"plugin\\points_mall\\Service"
]
}
},
"minimum-stability": "dev",
"config": {
"sort-packages": true,
"allow-plugins": {
"zoujingli/think-install": true
}
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace plugin\points_mall;
use think\admin\Plugin;
use think\facade\View;
class Service extends Plugin
{
protected $appName = '积分商城';
protected $appCode = 'points-mall';
protected $package = 'jerryyan/think-plugs-points-mall';
public static function register(): void
{
View::assign("_YES_OR_NO", [
'1' => '是',
'0' => '否'
]);
}
public static function menu(): array
{
$code = app(static::class)->appCode;
return [
[
'name' => '积分商城',
'subs' => [
['name' => '商品管理', 'icon' => 'layui-icon layui-icon-template-1', 'node' => "{$code}/goods/index"],
['name' => '订单管理', 'icon' => 'layui-icon layui-icon-template-1', 'node' => "{$code}/order/index"],
['name' => '用户积分', 'icon' => 'layui-icon layui-icon-template-1', 'node' => "{$code}/point/index"],
]
]
];
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace plugin\points_mall\controller;
use think\admin\Controller;
/**
* 商品管理
*/
class Goods extends Controller
{
/**
* 商品管理
* @auth true
* @menu true
* @return void
*/
public function index()
{
$this->title = '商品管理';
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace plugin\points_mall\controller;
use think\admin\Controller;
/**
* 积分情况
*/
class Point extends Controller
{
/**
* 积分情况
* @auth true
* @menu true
* @return void
*/
public function index()
{
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace plugin\points_mall\controller\api;
use plugin\account\controller\api\Auth as AuthController;
use think\exception\HttpResponseException;
class Auth extends AuthController
{
/**
* 控制器初始化
* @return void
*/
protected function initialize()
{
try {
parent::initialize();
$this->checkUserStatus(false);
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
}
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace plugin\points_mall\controller\api\auth;
use plugin\points_mall\controller\api\Auth;
use plugin\points_mall\model\PointsMallUserPointLog;
use plugin\points_mall\service\UserPointService;
class UserPoint extends Auth
{
public function myPoint() {
$point = UserPointService::getUserPoint($this->usid);
$this->success('获取用户积分', [
'point' => $point
]);
}
public function myPointLog() {
$page = PointsMallUserPointLog::mk()->where('uid', $this->usid)->order('create_at desc')->paginate();
$this->success('获取积分记录', $page);
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace plugin\points_mall\model;
use plugin\account\model\PluginAccountBind;
use think\admin\Model;
class PointsMallUserPoint extends Model
{
protected $pk = 'uid';
public function log()
{
return $this->hasMany(PointsMallUserPointLog::class, 'uid');
}
public function user()
{
return $this->belongsTo(PluginAccountBind::class, 'uid');
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace plugin\points_mall\model;
use think\admin\Model;
class PointsMallUserPointLog extends Model
{
protected $pk = 'uid';
}

View File

@ -0,0 +1,35 @@
<?php
namespace plugin\points_mall\service;
use plugin\points_mall\model\PointsMallUserPoint;
use plugin\points_mall\model\PointsMallUserPointLog;
class UserPointService
{
public static function getUserPoint($uid)
{
$point = PointsMallUserPoint::mk()->where('uid', $uid)->value('point');
if ($point === null) {
$point = 0;
PointsMallUserPoint::mk()->save(['uid' => $uid, 'point' => $point]);
}
return $point;
}
public static function addUserPoint($uid, $point, $reason)
{
$userPoint = PointsMallUserPoint::mk()->where('uid', $uid)->find();
if (empty($userPoint)) {
$userPoint = PointsMallUserPoint::mk()->create(['uid' => $uid, 'point' => 0]);
}
$userPoint->startTrans();
$userPoint->inc('point', $point);
$userPoint->log()->save([
'point' => $point,
'reason' => $reason,
]);
$userPoint->save();
$userPoint->commit();
}
}

View File

@ -0,0 +1,11 @@
<div class="layui-card layui-bg-gray">
{block name='style'}{/block}
{notempty name='title'}
<div class="layui-card-header notselect">
<span class="layui-icon layui-icon-next font-s10 color-desc margin-right-5"></span>{$title|default=''}
<div class="pull-right">{block name='button'}{/block}</div>
</div>
{/notempty}
<div class="layui-card-body">{block name='content'}{/block}</div>
{block name='script'}{/block}
</div>

View File

@ -0,0 +1,23 @@
<div class="layui-card">
{block name='style'}{/block}
{block name='header'}
{notempty name='title'}
<div class="layui-card-header">
<span class="layui-icon font-s10 color-desc ta-mr-5">&#xe65b;</span>{$title|lang}
<div class="pull-right">{block name='button'}{/block}</div>
</div>
{/notempty}
{/block}
<div class="layui-card-line"></div>
<div class="layui-card-body">
<div class="layui-card-table">
{notempty name='showErrorMessage'}
<div class="think-box-notify" type="error">
<b>系统提示:</b><span>{$showErrorMessage|raw}</span>
</div>
{/notempty}
{block name='content'}{/block}
</div>
</div>
{block name='script'}{/block}
</div>