Initial commit: queue workspace
Made-with: Cursor
This commit is contained in:
306
pro_v3.5.1/app/controller/api/admin/user/User.php
Normal file
306
pro_v3.5.1/app/controller/api/admin/user/User.php
Normal file
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\admin\user;
|
||||
|
||||
use app\jobs\BatchHandleJob;
|
||||
use app\Request;
|
||||
use app\services\activity\coupon\StoreCouponIssueServices;
|
||||
use app\services\activity\coupon\StoreCouponUserServices;
|
||||
use app\services\other\queue\QueueServices;
|
||||
use app\services\user\channel\ChannelMerchantServices;
|
||||
use app\services\user\group\UserGroupServices;
|
||||
use app\services\user\label\UserLabelCateServices;
|
||||
use app\services\user\label\UserLabelRelationServices;
|
||||
use app\services\user\level\SystemUserLevelServices;
|
||||
use app\services\user\level\UserLevelServices;
|
||||
use app\services\user\UserBatchProcessServices;
|
||||
use app\services\user\UserServices;
|
||||
use think\annotation\Inject;
|
||||
use think\Response;
|
||||
|
||||
/**
|
||||
* 用户类
|
||||
* Class StoreProduct
|
||||
* @package app\api\controller\store
|
||||
*/
|
||||
class User
|
||||
{
|
||||
/**
|
||||
* 用户services
|
||||
* @var UserServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserServices $services;
|
||||
|
||||
public function list(Request $request): Response
|
||||
{
|
||||
$where = $request->getMore([
|
||||
['page', 1],
|
||||
['limit', 20],
|
||||
['nickname', ''],
|
||||
['status', ''],
|
||||
['pay_count', ''],
|
||||
['is_promoter', ''],
|
||||
['order', ''],
|
||||
['data', ''],
|
||||
['user_type', ''],
|
||||
['country', ''],
|
||||
['province', ''],
|
||||
['city', ''],
|
||||
['user_time_type', ''],
|
||||
['user_time', ''],
|
||||
['sex', ''],
|
||||
[['level', 0], 0],
|
||||
[['group_id', 'd'], 0],
|
||||
[['label_id', 'd'], 0],
|
||||
['now_money', 'normal'],
|
||||
['field_key', ''],
|
||||
['isMember', ''],
|
||||
['label_ids', '']
|
||||
]);
|
||||
if ($where['label_ids']) {
|
||||
$where['label_id'] = stringToIntArray($where['label_ids']);
|
||||
unset($where['label_ids']);
|
||||
}
|
||||
$where['user_time_type'] = $where['user_time_type'] == 'all' ? '' : $where['user_time_type'];
|
||||
return app('json')->success($this->services->index($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
* @param $id
|
||||
* @return Response
|
||||
* User: liusl
|
||||
* DateTime: 2024/1/26 11:38
|
||||
*/
|
||||
public function info($id)
|
||||
{
|
||||
if (!$id) {
|
||||
return app('json')->fail('用户id不能为空');
|
||||
}
|
||||
return app('json')->success($this->services->manageRead($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户标签
|
||||
* @param $uid
|
||||
* @param UserLabelCateServices $services
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* User: liusl
|
||||
* DateTime: 2024/1/26 11:50
|
||||
*/
|
||||
public function userLabel($uid, UserLabelCateServices $services)
|
||||
{
|
||||
return app('json')->success($services->getUserLabel((int)$uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组
|
||||
* @param UserGroupServices $services
|
||||
* @return Response
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* User: liusl
|
||||
* DateTime: 2024/1/29 10:24
|
||||
*/
|
||||
public function userGroup(UserGroupServices $services)
|
||||
{
|
||||
return app('json')->success($services->getGroupList('*'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 等级
|
||||
* @param SystemUserLevelServices $services
|
||||
* @return Response
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* User: liusl
|
||||
* DateTime: 2024/1/29 11:00
|
||||
*/
|
||||
public function userLevel(SystemUserLevelServices $services)
|
||||
{
|
||||
return app('json')->success($services->getLevelList(['is_show' => 1, 'is_del' => 0], 'id,name,grade,image,icon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 优惠券列表
|
||||
* @param Request $request
|
||||
* @param StoreCouponIssueServices $services
|
||||
* @return Response
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* User: liusl
|
||||
* DateTime: 2024/1/29 15:51
|
||||
*/
|
||||
public function couponGrant(Request $request, StoreCouponIssueServices $services, StoreCouponUserServices $storeCouponUserServices)
|
||||
{
|
||||
[$coupon_title, $uid] = $request->getMore([
|
||||
['coupon_title', ''],
|
||||
['uid', 0],
|
||||
], true);
|
||||
if ($uid == 0) {
|
||||
$where['receive'] = 'send';
|
||||
$where['coupon_title'] = $coupon_title;
|
||||
$data = $services->getCouponIssueList($where);
|
||||
} else {
|
||||
$data = $storeCouponUserServices->getUserCouponList($uid, 0);
|
||||
}
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改余额积分
|
||||
* @param Request $request
|
||||
* @param $uid
|
||||
* @return Response
|
||||
* User: liusl
|
||||
* DateTime: 2024/1/29 15:10
|
||||
*/
|
||||
public function updateOther(Request $request, $uid)
|
||||
{
|
||||
$data = $request->postMore([
|
||||
['status', 0],
|
||||
['number', 0],
|
||||
['type', 1]//1余额 2积分
|
||||
]);
|
||||
if (!$uid) return app('json')->fail('数据不存在');
|
||||
$data['adminId'] = (int)$request->uid();
|
||||
$data['is_other'] = true;
|
||||
$type = $data['type'];
|
||||
unset($data['type']);
|
||||
|
||||
$data['money'] = $data['integration'] = $data['money_status'] = $data['integration_status'] = 0;
|
||||
if ($type == 1) {
|
||||
$data['money'] = (string)$data['number'];
|
||||
$data['money_status'] = $data['status'];
|
||||
} else {
|
||||
$data['integration'] = (string)$data['number'];
|
||||
$data['integration_status'] = $data['status'];
|
||||
}
|
||||
return app('json')->success($this->services->updateInfo($uid, $data) ? '修改成功' : '修改失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑用户
|
||||
* @param Request $request
|
||||
* @param UserBatchProcessServices $batchProcessServices
|
||||
* @return Response
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* User: liusl
|
||||
* DateTime: 2024/1/29 17:34
|
||||
*/
|
||||
public function update(Request $request, UserBatchProcessServices $batchProcessServices)
|
||||
{
|
||||
[$uid, $type, $level, $days_status, $days, $coupon_id, $group_id, $label_id] = $request->postMore([
|
||||
['uid', 0],
|
||||
['type', 1],//类型
|
||||
['level', 0],//等级
|
||||
['days_status', 0],//付费会员赠加/减少
|
||||
['days', 0],//赠送天数
|
||||
['coupon_id', 0],//优惠券id
|
||||
['group_id', 0],//分组
|
||||
['label_id', []],//标签
|
||||
], true);
|
||||
if (!$uid) return app('json')->fail('缺少参数');
|
||||
$res = true;
|
||||
$updateData = [];
|
||||
if (!is_array($uid)) {
|
||||
$info = $this->services->get((int)$uid);
|
||||
if (!$info) return app('json')->fail('用户不存在');
|
||||
}
|
||||
switch ($type) {
|
||||
case 1://等级
|
||||
if ($level == 0) return app('json')->fail('请选择等级');
|
||||
if ($level == $info['level']) return app('json')->fail('当前等级无需修改');
|
||||
/** @var UserLevelServices $userLevelService */
|
||||
$userLevelService = app()->make(UserLevelServices::class);
|
||||
$res = $userLevelService->setUserLevel((int)$uid, (int)$level);
|
||||
$msg = $res ? '修改成功' : '修改失败';
|
||||
break;
|
||||
case 2://付费会员
|
||||
$res = $this->services->saveGiveLevelTime((int)$uid, (int)$days, (int)$days_status);
|
||||
$msg = $res ? '赠送成功' : '赠送失败';
|
||||
break;
|
||||
case 3://赠送优惠券
|
||||
/** @var StoreCouponIssueServices $issueService */
|
||||
$issueService = app()->make(StoreCouponIssueServices::class);
|
||||
$coupon = $issueService->get($coupon_id);
|
||||
if (!$coupon) {
|
||||
return app('json')->fail('数据不存在!');
|
||||
} else {
|
||||
$coupon = $coupon->toArray();
|
||||
}
|
||||
if (is_array($uid)) {
|
||||
/** @var QueueServices $queueService */
|
||||
$queueService = app()->make(QueueServices::class);
|
||||
$queueService->setQueueData([], 'uid', $uid);
|
||||
//加入队列
|
||||
BatchHandleJob::dispatch([$coupon, 1]);
|
||||
$msg = '赠送成功';
|
||||
} else {
|
||||
/** @var StoreCouponIssueServices $storeCouponIssueServices */
|
||||
$storeCouponIssueServices = app()->make(StoreCouponIssueServices::class);
|
||||
$res = $storeCouponIssueServices->setCoupon($coupon, [$uid], '', '', true);
|
||||
$msg = $res ? '赠送成功' : '赠送失败';
|
||||
}
|
||||
break;
|
||||
case 4://分组
|
||||
if (is_array($uid)) {
|
||||
$batchProcessServices->batchProcess(1, $uid, ['group_id' => $group_id]);
|
||||
} else {
|
||||
if ($group_id == $info['group_id']) return app('json')->fail('当前分组无需修改');
|
||||
$updateData['group_id'] = $group_id;
|
||||
}
|
||||
$msg = '修改成功';
|
||||
break;
|
||||
case 5://标签
|
||||
$label_id = array_filter($label_id);
|
||||
if (is_array($uid)) {
|
||||
$batchProcessServices->batchProcess(2, $uid, ['label_id' => $label_id]);
|
||||
$msg = '修改成功';
|
||||
} else {
|
||||
/** @var UserLabelRelationServices $userLabel */
|
||||
$userLabel = app()->make(UserLabelRelationServices::class);
|
||||
$res = $userLabel->setUserLable([$uid], $label_id, 0, 0, true);
|
||||
$msg = $res ? '修改成功' : '修改失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return app('json')->fail('参数错误');
|
||||
}
|
||||
if ($res && count($updateData) > 0) {
|
||||
$this->services->update((int)$uid, $updateData);
|
||||
}
|
||||
return app('json')->success($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购商列表
|
||||
* @return void
|
||||
* User: liusl
|
||||
* DateTime: 2025/4/12 上午10:04
|
||||
*/
|
||||
public function channelList(Request $request, ChannelMerchantServices $channelMerchantServices)
|
||||
{
|
||||
$where = $request->postMore([
|
||||
['keyword', ''],
|
||||
]);
|
||||
return app('json')->success($channelMerchantServices->getChannelList($where));
|
||||
}
|
||||
|
||||
}
|
||||
67
pro_v3.5.1/app/controller/api/admin/user/UserAddress.php
Normal file
67
pro_v3.5.1/app/controller/api/admin/user/UserAddress.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\admin\user;
|
||||
|
||||
use app\Request;
|
||||
use app\services\user\UserAddressServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
|
||||
/**
|
||||
* 用户地址类
|
||||
* Class UserAddress
|
||||
* @package app\api\controller\store
|
||||
*/
|
||||
class UserAddress
|
||||
{
|
||||
|
||||
/**
|
||||
* @var UserAddressServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserAddressServices $services;
|
||||
|
||||
|
||||
/**
|
||||
* 地址列表
|
||||
* @param Request $request
|
||||
* @param $uid
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function address_list(Request $request, $uid)
|
||||
{
|
||||
$uid = (int)$uid;
|
||||
$list = [];
|
||||
if ($uid) {
|
||||
$list = $this->services->getUserAddressList($uid);
|
||||
}
|
||||
return app('json')->successful($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认地址
|
||||
* @param Request $request
|
||||
* @param $uid
|
||||
* @return \think\Response
|
||||
* @throws \throwable
|
||||
*/
|
||||
public function address_default(Request $request, $uid)
|
||||
{
|
||||
$uid = (int)$uid;
|
||||
$defaultAddress = [];
|
||||
if ($uid) $defaultAddress = $this->services->getUserDefaultAddressCache($uid);
|
||||
if ($defaultAddress) {
|
||||
return app('json')->successful('ok', $defaultAddress);
|
||||
}
|
||||
return app('json')->successful('empty', []);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user