pull/1/head
wanghousheng 10 months ago
parent f26a27fec5
commit 6856f5c2cc
  1. 143
      app/api/controller/Server.php
  2. 21
      app/api/model/Server.php
  3. 51
      app/api/model/Server/ServerCategory.php
  4. 70
      app/api/model/Server/ServerOrder.php
  5. 128
      app/api/service/User.php
  6. 22
      app/common/enum/OrderType.php
  7. 10
      app/common/enum/ServerEnum.php
  8. 56
      app/common/enum/user/UserTypeEnum.php
  9. 6
      app/common/model/server/Server.php
  10. 2
      app/common/service/server/Order.php

@ -0,0 +1,143 @@
<?php
/**
* 服务控制器
*/
namespace app\api\controller;
use app\api\model\Server\ServerCategory;
use app\api\model\Server\ServerOrder;
use app\common\enum\ServerEnum;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
class Server extends Controller
{
/**
* @notes:分类列表
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function categoryList(): Json
{
$model = new ServerCategory();
$list = $model->list();
if (!empty($list)) {
foreach ($list as $key => $value) {
unset($list[$key]['image']);
}
}
return $this->renderSuccess(compact('list'));
}
/**
* @notes:服务列表页
* @throws DbException
* @author: wanghousheng
*/
public function list(): Json
{
$server_name = $this->request->post('server_name');
$category_id = intval($this->request->post('category_id'));
$where = [];
if ($server_name) {
$where[] = ['server.server_name', 'like', "%$server_name%"];
}
if ($category_id) {
$where[] = ['server.category_id', '=', $category_id];
}
$model = new \app\api\model\Server($where);
$list = $model->getList();
$data['list'] = $list->items();
$data['total'] = $list->total();
if (!$list->isEmpty()) {
foreach ($data['list'] as $key => $value) {
unset($data['list'][$key]['image']);
unset($data['list'][$key]['category']);
}
}
return $this->renderSuccess($data);
}
/**
* @notes:订单状态
* @return Json
* @author: wanghousheng
*/
public function orderStatus(): Json
{
$list = array_values(ServerEnum::data());
return $this->renderSuccess(compact('list'));
}
/**
* @notes:用户订单列表
* @throws DbException
* @throws BaseException
* @author: wanghousheng
*/
public function userOrderList(): Json
{
$order_no = $this->request->post('order_no');
$order_status = intval($this->request->post('order_status'));
$where = [];
if (!empty($order_no)) {
$where['order_no'] = $order_no;
}
if ($order_status) {
$where['order_status'] = $order_status;
}
$model = new ServerOrder($where);
$list = $model->userOrders($where);
$data['list'] = $list->items();
$data['total'] = $list->total();
if (!$list->isEmpty()) {
if (!$list->isEmpty()) {
foreach ($data['list'] as $key => $value) {
unset($data['list'][$key]['image']);
unset($data['list'][$key]['dealer']);
}
}
}
return $this->renderSuccess($data);
}
/**
* @notes:
* @return Json
* @throws BaseException
* @throws DbException
* @author: wanghousheng
*/
public function dealerOrderList(): Json
{
$order_no = $this->request->post('order_no');
$order_status = intval($this->request->post('order_status'));
$where = [];
if (!empty($order_no)) {
$where['order_no'] = $order_no;
}
if ($order_status) {
$where['order_status'] = $order_status;
}
$model = new ServerOrder($where);
$list = $model->dealerOrders($where);
$data['list'] = $list->items();
$data['total'] = $list->total();
if (!$list->isEmpty()) {
if (!$list->isEmpty()) {
foreach ($data['list'] as $key => $value) {
unset($data['list'][$key]['image']);
unset($data['list'][$key]['dealer']);
}
}
}
return $this->renderSuccess($data);
}
}

@ -0,0 +1,21 @@
<?php
namespace app\api\model;
use app\common\model\server\Server as BaseServer;
class Server extends BaseServer
{
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'store_id',
'create_time',
'update_time',
'status',
'image_id',
'delete_time',
];
}

@ -0,0 +1,51 @@
<?php
namespace app\api\model\Server;
use app\api\model\UploadFile;
use app\common\model\ServerCategory as BaseServerCategory;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\model\relation\HasOne;
class ServerCategory extends BaseServerCategory
{
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'store_id',
'create_time',
'update_time',
'status',
'image_id',
];
/**
* 分类图片
* @return HasOne
*/
public function image(): HasOne
{
return $this->hasOne(UploadFile::class, 'file_id', 'image_id')
->bind(['image_url' => 'preview_url']);
}
/**
* @notes:获取全部记录
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function list(): array
{
return $this->with(['image'])
->order(['sort', 'create_time'])
->select()
->toArray();
}
}

@ -0,0 +1,70 @@
<?php
namespace app\api\model\Server;
use app\api\service\User as UserService;
use app\common\model\server\Order;
use cores\exception\BaseException;
use think\db\exception\DbException;
use think\Paginator;
class ServerOrder extends Order
{
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'store_id',
'create_time',
'update_time',
'trade_id',
'server_image_id',
'is_delete',
];
/**
* @notes:用户服务订单列表
* @param $where
* @param int $listRows
* @return Paginator
* @throws BaseException
* @throws DbException
* @author: wanghousheng
*/
public function userOrders($where, int $listRows = 15): Paginator
{
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
// 查询列表数据
return $this->with(['image', 'dealer'])
->where($where)
->where('user_id', '=', $userId)
->where('is_delete', '=', 0)
->order(['create_time' => 'desc'])
->paginate($listRows);
}
/**
* @notes:分销员订单列表
* @param $where
* @param int $listRows
* @return Paginator
* @throws BaseException
* @throws DbException
* @author: wanghousheng
*/
public function dealerOrders($where, int $listRows = 15): Paginator
{
// 当前用户ID
$userId = UserService::getCurrentLoginUserId();
// 查询列表数据
return $this->with(['image', 'user'])
->where($where)
->where('dealer_id', '=', $userId)
->where('is_delete', '=', 0)
->order(['create_time' => 'desc'])
->paginate($listRows);
}
}

@ -12,12 +12,14 @@ declare (strict_types=1);
namespace app\api\service;
use think\facade\Cache;
use app\api\model\User as UserModel;
use app\api\model\UserOauth as UserOauthModel;
use app\common\enum\Client as ClientEnum;
use app\common\enum\dealer\DealerUserEnum;
use app\common\enum\user\UserTypeEnum;
use app\common\service\User as UserService;
use cores\exception\BaseException;
use app\common\enum\Client as ClientEnum;
use think\facade\Cache;
/**
* 用户服务类
@ -63,6 +65,128 @@ class User extends UserService
return $userInfo ? $userInfo['user_id'] : false;
}
/**
* @notes:是否PLUS会员
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public static function isPlusMember(): bool
{
$userType = static::getCurrentLoginUserType();
if ($userType && $userType == UserTypeEnum::MEMBER && self::checkEffectiveTime()) {
return true;
}
return false;
}
/**
* @notes:是否分销商
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public function isDealerMember(): bool
{
$userType = static::getCurrentLoginUserType();
if ($userType && $userType == UserTypeEnum::DEALER) {
$userId = self::getCurrentLoginUserId();
//分销表里有没有
$dealerInfo = \app\api\model\dealer\User::detail($userId, []);
if (!$dealerInfo->isEmpty() && self::checkEffectiveTime()) {
return true;
}
}
return false;
}
/**
* @notes:是否分销商-工程师
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public function isDealerEngineer(): bool
{
$userType = static::getCurrentLoginUserType();
if ($userType && $userType == UserTypeEnum::DEALER) {
$userId = self::getCurrentLoginUserId();
//分销表里有没有
$dealerInfo = \app\api\model\dealer\User::detail($userId, []);
if (!$dealerInfo->isEmpty() && self::checkEffectiveTime() && $dealerInfo['type'] == DealerUserEnum::ENGINEER) {
return true;
}
}
return false;
}
/**
* @notes:是否店主
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public function isStore(): bool
{
$userType = static::getCurrentLoginUserType();
if ($userType && $userType == UserTypeEnum::STORE) {
$userId = self::getCurrentLoginUserId();
//商家表里有没有
$model = new \app\api\model\Store();
$store_id = $model->where(['user_id' => $userId])->value('store_id');
if ($store_id && $store_id == $this->getStoreId()) {
return $userId;
}
}
return false;
}
/**
* @notes:是否普通会员
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public function isNormalMember(): bool
{
$userType = static::getCurrentLoginUserType();
if ($userType && $userType == UserTypeEnum::NORMAL) {
return true;
}
return false;
}
/**
* @notes:检测plus会员 分销商是否到期
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
private function checkEffectiveTime(): bool
{
$userInfo = static::getCurrentLoginUser();
if (!empty($userInfo) && !empty($userInfo['effective_time'])) {
$effective_time = strtotime($userInfo['effective_time'] . ' 23:59:59');
if (time() < $effective_time) {
return true;
}
}
return false;
}
/**
* 获取当前登录的用户身份
* getCurrentLoginUser方法的二次封装
* @param bool $isForce 是否强制验证登录, 如果未登录将抛错
* @return int|false
* @throws BaseException
*/
public static function getCurrentLoginUserType(bool $isForce = true)
{
$userInfo = static::getCurrentLoginUser($isForce);
return $userInfo ? $userInfo['user_type'] : 10;
}
/**
* 获取第三方用户信息
* @param int $userId 用户ID

@ -22,9 +22,19 @@ class OrderType extends EnumBasics
// 商城订单
const ORDER = 10;
// 服务订单
const SERVER = 20;
// 开通会员订单
const MEMBER = 30;
// 开通分销订单
const DEALER = 40;
// 余额充值订单
const RECHARGE = 100;
/**
* 获取订单类型值
* @return array
@ -39,6 +49,18 @@ class OrderType extends EnumBasics
self::RECHARGE => [
'name' => '余额充值订单',
'value' => self::RECHARGE,
],
self::SERVER => [
'name' => '服务订单',
'value' => self::SERVER,
],
self::MEMBER => [
'name' => '开通会员订单',
'value' => self::MEMBER,
],
self::DEALER => [
'name' => '开通分销订单',
'value' => self::DEALER,
]
];
}

@ -26,10 +26,6 @@ class ServerEnum extends EnumBasics
'name' => '待付款',
'value' => self::APPLYPAY,
],
self::CANCELLED => [
'name' => '已取消',
'value' => self::CANCELLED,
],
self::APPLYDISPATCH => [
'name' => '待派单',
'value' => self::APPLYDISPATCH,
@ -41,7 +37,11 @@ class ServerEnum extends EnumBasics
self::COMPLETED => [
'name' => '已完成',
'value' => self::COMPLETED,
]
],
self::CANCELLED => [
'name' => '已取消',
'value' => self::CANCELLED,
],
];
}
}

@ -0,0 +1,56 @@
<?php
namespace app\common\enum\user;
use app\common\enum\EnumBasics;
class UserTypeEnum extends EnumBasics
{
// 普通用户
const NORMAL = 10;
// 会员用户
const MEMBER = 20;
// 分销商用户
const DEALER = 30;
// 店长用户
const STORE = 40;
/**
* 获取用户类型值
* @return array
*/
public static function data(): array
{
return [
self::NORMAL => [
'name' => '普通会员',
'value' => self::NORMAL,
],
self::MEMBER => [
'name' => 'PLUS会员',
'value' => self::MEMBER,
],
self::DEALER => [
'name' => '分销商',
'value' => self::DEALER,
],
self::STORE => [
'name' => '店长',
'value' => self::STORE,
]
];
}
/**
* 根据值获取名称
* @param string $value
* @return string
*/
public static function getName(string $value): string
{
return self::data()[$value]['name'];
}
}

@ -30,12 +30,14 @@ class Server extends BaseModel
*/
public function image(): HasOne
{
return $this->hasOne(UploadFile::class, 'file_id', 'image_id');
return $this->hasOne(UploadFile::class, 'file_id', 'image_id')
->bind(['server_image' => 'preview_url']);
}
public function category(): HasOne
{
return $this->hasOne(ServerCategory::class, 'category_id', 'category_id');
return $this->hasOne(ServerCategory::class, 'category_id', 'category_id')
->bind(['server_category' => 'name']);
}
/**

@ -23,7 +23,7 @@ class Order extends BaseService
*/
public static function createOrderNo(): string
{
return date('Ymd') . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13)))), 0, 8);
return 'SE' . date('Ymd') . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13)))), 0, 8);
}
/**

Loading…
Cancel
Save