服务回收

pull/1/head
wanghousheng 1 year ago
parent 9c43fe42bd
commit b89c162045
  1. 47
      app/common/enum/ServerEnum.php
  2. 31
      app/common/enum/dealer/DealerUserEnum.php
  3. 23
      app/common/model/dealer/User.php
  4. 103
      app/common/model/server/Order.php
  5. 91
      app/common/service/server/Order.php
  6. 83
      app/store/controller/Server.php
  7. 29
      app/store/controller/dealer/User.php
  8. 10
      app/store/model/server/Server.php

@ -0,0 +1,47 @@
<?php
namespace app\common\enum;
class ServerEnum extends EnumBasics
{
// 待付款
const APPLYPAY = 10;
// 待派单
const APPLYDISPATCH = 20;
// 待服务
const APPLYSERVER = 30;
// 已完成
const COMPLETED = 40;
// 已取消
const CANCELLED = 50;
/**
* 获取枚举数据
* @return array
*/
public static function data(): array
{
return [
self::APPLYPAY => [
'name' => '待付款',
'value' => self::APPLYPAY,
],
self::CANCELLED => [
'name' => '已取消',
'value' => self::CANCELLED,
],
self::APPLYDISPATCH => [
'name' => '待派单',
'value' => self::APPLYDISPATCH,
],
self::APPLYSERVER => [
'name' => '待服务',
'value' => self::APPLYSERVER,
],
self::COMPLETED => [
'name' => '已完成',
'value' => self::COMPLETED,
]
];
}
}

@ -0,0 +1,31 @@
<?php
namespace app\common\enum\dealer;
use app\common\enum\EnumBasics;
class DealerUserEnum extends EnumBasics
{
//工程师
const ENGINEER = 20;
//普通
const NORMAL = 10;
/**
* 获取枚举数据
* @return array
*/
public static function data(): array
{
return [
self::ENGINEER => [
'name' => '工程师',
'value' => self::ENGINEER,
],
self::NORMAL => [
'name' => '普通',
'value' => self::NORMAL,
],
];
}
}

@ -12,8 +12,13 @@ declare (strict_types=1);
namespace app\common\model\dealer;
use cores\BaseModel;
use app\common\enum\dealer\DealerUserEnum;
use app\common\library\helper;
use cores\BaseModel;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\model\relation\BelongsTo;
/**
@ -167,4 +172,20 @@ class User extends BaseModel
]);
return true;
}
/**
* @notes:获取工程师分销商
* @return array|Collection|User[]
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public static function getEngineer()
{
return (new static())
->where(['type' => DealerUserEnum::ENGINEER])
->order(['create_time'])
->select();
}
}

@ -0,0 +1,103 @@
<?php
declare (strict_types=1);
namespace app\common\model\server;
use app\common\enum\ServerEnum;
use app\common\model\UploadFile;
use cores\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasOne;
use think\Paginator;
class Order extends BaseModel
{
// 定义表名
protected $name = 'server_order';
// 定义主键
protected $pk = 'order_id';
/**
* 追加字段
* @var array
*/
protected $append = [
'order_status_text', // 订单状态文字描述
];
public function serve(): BelongsTo
{
return $this->belongsTo(Server::class, 'id', 'server_id');
}
/**
* 获取器:订单状态文字描述
* @return string
*/
public function getOrderStatusTextAttr($value, $data): string
{
// 订单状态
return ServerEnum::data()[$data['order_status']]['name'];
}
/**
* 图片
* @return HasOne
*/
public function image(): HasOne
{
return $this->hasOne(UploadFile::class, 'file_id', 'server_image_id')
->bind(['server_image' => 'preview_url']);
}
/**
* 关联用户表
* @return BelongsTo
*/
public function user(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\$module\\model\\User")
->bind(['user_name' => 'nick_name', 'user_mobile' => 'mobile']);
}
public function dealer(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\$module\\model\\User", 'dealer_id', 'user_id')
->bind(['dealer_name' => 'nick_name', 'dealer_mobile' => 'mobile']);
}
/**
* @notes:服务订单列表
* @param array $where
* @param int $listRows
* @return Paginator
* @author: wanghousheng
*/
public function getList(array $where, int $listRows = 15): Paginator
{
$where = $this->setQueryDefaultValue($where);
return $this->with(['image', 'dealer'])
->alias('a')
->join('user b', 'b.user_id = a.user_id')
->where($where)
->order(['create_time'])
->field('a.*,b.mobile as user_mobile,b.nick_name as user_nick_name')
->paginate($listRows);
}
/**
* @notes:订单详情
* @param $where
* @param array $with
* @return Order|array|null
* @author: wanghousheng
*/
public static function detail($where, array $with = [])
{
return static::get($where, $with);
}
}

@ -0,0 +1,91 @@
<?php
declare (strict_types=1);
namespace app\common\service\server;
use app\api\model\dealer\User as DealerUserModel;
use app\common\enum\dealer\DealerUserEnum;
use app\common\enum\order\PayStatus;
use app\common\enum\ServerEnum;
use app\common\model\UserCoupon as UserCouponModel;
use app\common\service\BaseService;
use app\common\service\order\Refund as RefundService;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class Order extends BaseService
{
/**
* 生成订单号
* @return string
*/
public static function createOrderNo(): string
{
return date('Ymd') . substr(implode('', array_map('ord', str_split(substr(uniqid(), 7, 13)))), 0, 8);
}
/**
* @notes:用户取消订单
* @param array $order
* @return bool
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public static function cancelOrder(array $order): bool
{
//未完成 未取消
if (!empty($order['order_status']) && $order['order_status'] != ServerEnum::COMPLETED || $order['order_status'] != ServerEnum::CANCELLED) {
if (!empty($order['coupon_id'])) {
// 回退用户优惠券
$order['coupon_id'] > 0 && UserCouponModel::setIsUse($order['coupon_id'], false);
}
//判断是否已支付
if ($order['pay_status'] == PayStatus::SUCCESS) {
if (!(new RefundService)->handle($order)) {
try {
throwError('执行订单退款失败');
} catch (BaseException $e) {
return false;
}
}
}
//更新订单状态
$model = new \app\common\model\server\Order;
$model->where(['order_id' => $order['order_id']])->save(['order_status' => ServerEnum::CANCELLED]);
return true;
}
return false;
}
/**
* @notes:派单
* @param array $order
* @param int $dealerId
* @return bool
* @author: wanghousheng
*/
public static function dispatchOrders(array $order, int $dealerId): bool
{
//判断该订单是否可以指派
if (!empty($order) && $order['order_status'] == ServerEnum::APPLYDISPATCH) {
//判断指派人员是否是分销工程师
$dealerInfo = DealerUserModel::detail($dealerId, []);
if (!empty($dealerInfo)) {
$dealerInfo = $dealerInfo->toArray();
if ($dealerInfo['type'] == DealerUserEnum::ENGINEER) {
$model = new \app\common\model\server\Order;
$up['dealer_id'] = $dealerId;
$up['order_status'] = ServerEnum::APPLYSERVER;
$model->where(['order_id' => $order['order_id']])->save($up);
return true;
}
}
}
return false;
}
}

@ -1,9 +1,11 @@
<?php
declare (strict_types=1);
namespace app\store\controller;
use app\store\model\server\Server as ServerModel;
use app\store\model\ServerCategory;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -182,4 +184,85 @@ class Server extends Controller
}
return $this->renderSuccess('操作成功');
}
/**
* @notes:服务订单列表
* @return Json
* @author: wanghousheng
*/
public function orderList(): Json
{
$model = new \app\common\model\server\Order;
$server_name = $this->request->post('server_name');
$order_no = $this->request->post('order_no');
$order_status = intval($this->request->post('order_status'));
$where = [];
if (!empty($server_name)) {
$where[] = ['a.server_name', 'like', `%$server_name%`];
}
if (!empty($order_no)) {
$where[] = ['a.order_no', '=', $order_no];
}
if ($order_status) {
$where[] = ['a.order_status', '=', $order_status];
}
$user_mobile = $this->request->post('user_mobile');
if ($user_mobile) {
$where[] = ['b.mobile', '=', $user_mobile];
}
$user_nickname = $this->request->post('user_nickname');
if ($user_nickname) {
$where[] = ['b.nick_name', 'like', "%$server_name%"];
}
$list = $model->getList($where);
return $this->renderSuccess(compact('list'));
}
/**
* @notes:取消服务订单
* @param int $orderId
* @return Json
* @author: wanghousheng
*/
public function cancelOrder(int $orderId): Json
{
$order = \app\common\model\server\Order::detail($orderId);
if (empty($order)) {
return $this->renderError('订单信息不存在');
}
try {
$result = \app\common\service\server\Order::cancelOrder($order->toArray());
if ($result) {
return $this->renderSuccess('操作成功');
}
} catch (BaseException|DataNotFoundException|ModelNotFoundException|DbException $e) {
return $this->renderError($e->getMessage() ?: '取消失败');
}
return $this->renderError('取消失败');
}
/**
* @notes:派单
* @return Json
* @author: wanghousheng
*/
public function dispatchOrders(): Json
{
$data = $this->postForm();
if (empty($data['dealer_id'])) {
return $this->renderError('指派人员不能为空');
}
if (empty($data['order_id'])) {
return $this->renderError('缺少必要参数');
}
$order = \app\common\model\server\Order::detail($data['order_id']);
if (empty($order)) {
return $this->renderError('订单信息不存在');
}
$result = \app\common\service\server\Order::dispatchOrders($order->toArray(), $data['dealer_id']);
if ($result) {
return $this->renderSuccess('操作成功');
}
return $this->renderError('操作失败');
}
}

@ -12,12 +12,15 @@ declare (strict_types=1);
namespace app\store\controller\dealer;
use think\response\Json;
use app\common\service\qrcode\Poster;
use app\store\controller\Controller;
use app\store\model\dealer\User as UserModel;
use app\store\model\dealer\Referee as RefereeModel;
use app\common\service\qrcode\Poster;
use app\store\model\dealer\User as UserModel;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
/**
* 分销商管理
@ -84,9 +87,9 @@ class User extends Controller
* @param string $channel 渠道
* @return Json
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function poster(int $dealerId, string $channel = 'H5'): Json
{
@ -94,4 +97,18 @@ class User extends Controller
$Qrcode = new Poster($model, $channel);
return $this->renderSuccess(['imageUrl' => $Qrcode->getImage()]);
}
/**
* @notes:工程师分销商
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function getEngineer(): Json
{
$list = UserModel::getEngineer();
return $this->renderSuccess(compact('list'));
}
}

@ -1,11 +1,9 @@
<?php
declare (strict_types=1);
namespace app\store\model\server;
use app\common\model\server\Server as ServerModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class Server extends ServerModel
{
@ -43,11 +41,7 @@ class Server extends ServerModel
*/
public function remove(array $serverId): bool
{
try {
return static::whereIn('server_id', $serverId)->select()->delete();
} catch (DataNotFoundException|ModelNotFoundException|DbException $e) {
return false;
}
return static::whereIn('server_id', $serverId)->delete();
}
/**

Loading…
Cancel
Save