init
- 框架初始化 - 安装插件 - 修复PHP8.4报错
This commit is contained in:
33
application/admin/controller/shopro/user/Coupon.php
Normal file
33
application/admin/controller/shopro/user/Coupon.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\user;
|
||||
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\order\Order;
|
||||
use app\admin\model\shopro\user\Coupon as UserCouponModel;
|
||||
|
||||
class Coupon extends Common
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new UserCouponModel;
|
||||
}
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
$coupon_id = $this->request->param('coupon_id');
|
||||
|
||||
$coupons = $this->model->sheepFilter()->with(['user', 'order'])
|
||||
->where('coupon_id', $coupon_id)
|
||||
->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$this->success('获取成功', null, $coupons);
|
||||
}
|
||||
}
|
||||
27
application/admin/controller/shopro/user/Group.php
Normal file
27
application/admin/controller/shopro/user/Group.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\user;
|
||||
|
||||
use think\Db;
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\UserGroup as GroupModel;
|
||||
|
||||
class Group extends Common
|
||||
{
|
||||
protected $noNeedRight = ['select'];
|
||||
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new GroupModel;
|
||||
}
|
||||
|
||||
|
||||
public function select()
|
||||
{
|
||||
$list = \app\admin\model\UserGroup::field('id,name,status')->select();
|
||||
$this->success('', null, $list);
|
||||
}
|
||||
}
|
||||
152
application/admin/controller/shopro/user/User.php
Normal file
152
application/admin/controller/shopro/user/User.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\user;
|
||||
|
||||
use think\Db;
|
||||
use app\admin\controller\shopro\Common;
|
||||
use addons\shopro\service\Wallet as WalletService;
|
||||
use app\admin\model\shopro\user\User as UserModel;
|
||||
use app\admin\model\shopro\user\Coupon as UserCouponModel;
|
||||
|
||||
class User extends Common
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
protected $noNeedRight = ['select'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new UserModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$data = $this->model->sheepFilter()->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$this->success('获取成功', null, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$user = $this->model->with(['third_oauth', 'parent_user'])->where('id', $id)->find();
|
||||
if (!$user) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
$this->success('获取成功', null, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户
|
||||
*
|
||||
* @param $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id = null)
|
||||
{
|
||||
$params = $this->request->only(['username', 'nickname', 'mobile', 'password', 'avatar', 'gender', 'email', 'status']);
|
||||
|
||||
if (empty($params['password'])) unset($params['password']);
|
||||
if (empty($params['username'])) unset($params['username']);
|
||||
|
||||
$params['id'] = $id;
|
||||
$this->svalidate($params, '.edit');
|
||||
unset($params['id']);
|
||||
|
||||
$user = $this->model->where('id', $id)->find();
|
||||
$user->save($params);
|
||||
|
||||
$this->success('更新成功', null, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户(支持批量)
|
||||
*
|
||||
* @param $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if (empty($id)) {
|
||||
$this->error(__('Parameter %s can not be empty', 'id'));
|
||||
}
|
||||
|
||||
$id = explode(',', $id);
|
||||
$list = $this->model->where('id', 'in', $id)->select();
|
||||
$result = Db::transaction(function () use ($list) {
|
||||
$count = 0;
|
||||
foreach ($list as $item) {
|
||||
$count += $item->delete();
|
||||
}
|
||||
|
||||
return $count;
|
||||
});
|
||||
|
||||
if ($result) {
|
||||
$this->success('删除成功', null, $result);
|
||||
} else {
|
||||
$this->error(__('No rows were deleted'));
|
||||
}
|
||||
}
|
||||
|
||||
public function recharge()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$params = $this->request->only(['id', 'type', 'amount', 'memo']);
|
||||
if (!in_array($params['type'], ['money', 'score'])) {
|
||||
error_stop('参数错误');
|
||||
}
|
||||
|
||||
$result = Db::transaction(function () use ($params) {
|
||||
return WalletService::change($params['id'], $params['type'], $params['amount'], 'admin_recharge', [], $params['memo']);
|
||||
});
|
||||
if ($result) {
|
||||
$this->success('充值成功');
|
||||
}
|
||||
$this->error('充值失败');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户优惠券列表
|
||||
*/
|
||||
public function coupon($id)
|
||||
{
|
||||
$userCoupons = UserCouponModel::sheepFilter()->with('coupon')->where('user_id', $id)
|
||||
->order('id', 'desc')->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$this->success('获取成功', null, $userCoupons);
|
||||
}
|
||||
|
||||
|
||||
public function select()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$data = $this->model->sheepFilter()->paginate($this->request->param('list_rows', 10));
|
||||
|
||||
$this->success('获取成功', null, $data);
|
||||
}
|
||||
}
|
||||
90
application/admin/controller/shopro/user/WalletLog.php
Normal file
90
application/admin/controller/shopro/user/WalletLog.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\shopro\user;
|
||||
|
||||
use app\admin\controller\shopro\Common;
|
||||
use app\admin\model\shopro\user\WalletLog as WalletLogModel;
|
||||
use addons\shopro\library\Operator;
|
||||
|
||||
class WalletLog extends Common
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new WalletLogModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 余额记录
|
||||
*/
|
||||
public function money($id)
|
||||
{
|
||||
$list_rows = $this->request->param('list_rows', 10);
|
||||
$walletLogs = WalletLogModel::where('user_id', $id)->money()->order('id', 'desc')->paginate($list_rows);
|
||||
|
||||
// 多态关联 oper
|
||||
$morphs = [
|
||||
'user' => \app\admin\model\shopro\user\User::class,
|
||||
'admin' => \app\admin\model\Admin::class,
|
||||
'system' => \app\admin\model\Admin::class,
|
||||
];
|
||||
$walletLogs = morph_to($walletLogs, $morphs, ['oper_type', 'oper_id']);
|
||||
$walletLogs = $walletLogs->toArray();
|
||||
|
||||
// 解析操作人信息
|
||||
foreach ($walletLogs['data'] as &$log) {
|
||||
$log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
|
||||
}
|
||||
$this->success('', null, $walletLogs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分记录
|
||||
*/
|
||||
public function score($id)
|
||||
{
|
||||
$list_rows = $this->request->param('list_rows', 10);
|
||||
$walletLogs = WalletLogModel::where('user_id', $id)->score()->order('id', 'desc')->paginate($list_rows);
|
||||
|
||||
// 多态关联 oper
|
||||
$morphs = [
|
||||
'user' => \app\admin\model\shopro\user\User::class,
|
||||
'admin' => \app\admin\model\Admin::class,
|
||||
'system' => \app\admin\model\Admin::class,
|
||||
];
|
||||
$walletLogs = morph_to($walletLogs, $morphs, ['oper_type', 'oper_id']);
|
||||
$walletLogs = $walletLogs->toArray();
|
||||
|
||||
// 解析操作人信息
|
||||
foreach ($walletLogs['data'] as &$log) {
|
||||
$log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
|
||||
}
|
||||
$this->success('', null, $walletLogs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 佣金记录
|
||||
*/
|
||||
public function commission($id)
|
||||
{
|
||||
$list_rows = $this->request->param('list_rows', 10);
|
||||
$walletLogs = WalletLogModel::where('user_id', $id)->commission()->order('id', 'desc')->paginate($list_rows);
|
||||
|
||||
// 多态关联 oper
|
||||
$morphs = [
|
||||
'user' => \app\admin\model\shopro\user\User::class,
|
||||
'admin' => \app\admin\model\Admin::class,
|
||||
'system' => \app\admin\model\Admin::class,
|
||||
];
|
||||
$walletLogs = morph_to($walletLogs, $morphs, ['oper_type', 'oper_id']);
|
||||
$walletLogs = $walletLogs->toArray();
|
||||
|
||||
// 解析操作人信息
|
||||
foreach ($walletLogs['data'] as &$log) {
|
||||
$log['oper'] = Operator::info($log['oper_type'], $log['oper'] ?? null);
|
||||
}
|
||||
$this->success('', null, $walletLogs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user