You've already forked guangan
1
This commit is contained in:
36
plugs/think-plugs-points-mall/src/Service.php
Normal file
36
plugs/think-plugs-points-mall/src/Service.php
Normal 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"],
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
22
plugs/think-plugs-points-mall/src/controller/Goods.php
Normal file
22
plugs/think-plugs-points-mall/src/controller/Goods.php
Normal 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 = '商品管理';
|
||||
}
|
||||
}
|
22
plugs/think-plugs-points-mall/src/controller/Point.php
Normal file
22
plugs/think-plugs-points-mall/src/controller/Point.php
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
25
plugs/think-plugs-points-mall/src/controller/api/Auth.php
Normal file
25
plugs/think-plugs-points-mall/src/controller/api/Auth.php
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\points_mall\model;
|
||||
|
||||
use think\admin\Model;
|
||||
|
||||
class PointsMallUserPointLog extends Model
|
||||
{
|
||||
protected $pk = 'uid';
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
11
plugs/think-plugs-points-mall/src/view/main.html
Normal file
11
plugs/think-plugs-points-mall/src/view/main.html
Normal 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>
|
23
plugs/think-plugs-points-mall/src/view/table.html
Normal file
23
plugs/think-plugs-points-mall/src/view/table.html
Normal 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"></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>
|
Reference in New Issue
Block a user