初始化项目
This commit is contained in:
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\common\enum\order\ReceiptStatus;
|
||||
use app\common\model\UserOauth as UserOauthModel;
|
||||
use app\console\model\Order as OrderModel;
|
||||
use app\common\service\BaseService;
|
||||
use app\common\service\Order as OrderService;
|
||||
use app\common\service\order\Complete as OrderCompleteService;
|
||||
use app\common\enum\order\OrderStatus as OrderStatusEnum;
|
||||
use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;
|
||||
use app\common\library\helper;
|
||||
use app\console\library\Tools;
|
||||
use app\common\library\wechat\WxPay;
|
||||
use app\common\model\wxapp\Setting as WxappSettingModel;
|
||||
|
||||
/**
|
||||
* 服务类:订单模块
|
||||
* Class Order
|
||||
* @package app\console\service
|
||||
*/
|
||||
class Order extends BaseService
|
||||
{
|
||||
/**
|
||||
* 未支付订单自动关闭
|
||||
* @param int $storeId
|
||||
* @param int $closeHours 自定关闭订单有效期 (小时)
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function closeEvent(int $storeId, int $closeHours)
|
||||
{
|
||||
// 截止时间
|
||||
$deadlineTime = time() - ((int)$closeHours * 60 * 60);
|
||||
// 查询截止时间未支付的订单
|
||||
$model = new OrderModel;
|
||||
$list = $model->getListByClose($storeId, $deadlineTime);
|
||||
// 订单ID集
|
||||
$orderIds = helper::getArrayColumn($list, 'order_id');
|
||||
if (!empty($orderIds)) {
|
||||
// 取消订单事件
|
||||
foreach ($list as $order) {
|
||||
OrderService::cancelEvent($order);
|
||||
}
|
||||
// 批量更新订单状态为已取消
|
||||
$model->onBatchUpdate($orderIds, ['order_status' => OrderStatusEnum::CANCELLED]);
|
||||
}
|
||||
// 记录日志
|
||||
Tools::taskLogs('Order', 'closeEvent', [
|
||||
'storeId' => $storeId,
|
||||
'closeHours' => $closeHours,
|
||||
'deadlineTime' => $deadlineTime,
|
||||
'orderIds' => helper::jsonEncode($orderIds)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 已发货订单自动确认收货
|
||||
* @param int $storeId
|
||||
* @param int $receiveDays 自动收货天数
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function receiveEvent(int $storeId, int $receiveDays)
|
||||
{
|
||||
// 截止时间
|
||||
$deadlineTime = time() - ((int)$receiveDays * 86400);
|
||||
// 查询截止时间未确认收货的订单ID集
|
||||
$model = new OrderModel;
|
||||
$orderIds = $model->getOrderIdsByReceive($storeId, $deadlineTime);
|
||||
// 更新订单收货状态
|
||||
if (!empty($orderIds)) {
|
||||
// 批量更新订单状态为已收货
|
||||
$model->onUpdateReceived($orderIds);
|
||||
// 批量处理已完成的订单
|
||||
$this->onReceiveCompleted($storeId, $orderIds);
|
||||
}
|
||||
// 记录日志
|
||||
Tools::taskLogs('Order', 'receiveEvent', [
|
||||
'storeId' => $storeId,
|
||||
'receiveDays' => $receiveDays,
|
||||
'deadlineTime' => $deadlineTime,
|
||||
'orderIds' => helper::jsonEncode($orderIds)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 已完成订单自动结算
|
||||
* @param int $storeId
|
||||
* @param int $refundDays 售后期限天数
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function settledEvent(int $storeId, int $refundDays)
|
||||
{
|
||||
// 截止时间
|
||||
$deadlineTime = time() - ((int)$refundDays * 86400);
|
||||
// 查询截止时间确认收货的订单ID集
|
||||
$model = new OrderModel;
|
||||
$list = $model->getOrderListBySettled($storeId, $deadlineTime);
|
||||
// 订单ID集
|
||||
$orderIds = helper::getArrayColumn($list, 'order_id');
|
||||
// 订单结算服务
|
||||
if (!empty($orderIds)) {
|
||||
$OrderCompleteService = new OrderCompleteService();
|
||||
$OrderCompleteService->settled($list);
|
||||
}
|
||||
// 记录日志
|
||||
Tools::taskLogs('Order', 'settledEvent', [
|
||||
'storeId' => $storeId,
|
||||
'refundDays' => $refundDays,
|
||||
'deadlineTime' => $deadlineTime,
|
||||
'orderIds' => helper::jsonEncode($orderIds)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量处理已完成的订单
|
||||
* @param int $storeId 商城ID
|
||||
* @param array $orderIds 订单ID集
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function onReceiveCompleted(int $storeId, array $orderIds)
|
||||
{
|
||||
// 获取已完成的订单列表
|
||||
$model = new OrderModel;
|
||||
$list = $model->getListByOrderIds($storeId, $orderIds);
|
||||
// 执行订单完成后的操作
|
||||
if (!$list->isEmpty()) {
|
||||
$OrderCompleteService = new OrderCompleteService();
|
||||
$OrderCompleteService->complete($list, $storeId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动微信支付发货
|
||||
* @param int $storeId
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function deliveryEvent(int $storeId)
|
||||
{
|
||||
// 查询截止时间未支付的订单
|
||||
$model = new OrderModel;
|
||||
$list = $model->getListByDelivery($storeId);
|
||||
// 订单ID集
|
||||
$orderIds = helper::getArrayColumn($list, 'order_id');
|
||||
if (!empty($orderIds)) {
|
||||
// 小程序配置信息
|
||||
$wxConfig = WxappSettingModel::getWxappConfig($storeId);
|
||||
$wxPay = new WxPay(['app_id' => $wxConfig['app_id'], 'app_secret'=> $wxConfig['app_secret']]);
|
||||
// 取消订单事件
|
||||
foreach ($list as $order) {
|
||||
// 请求API数据
|
||||
$name = $order['goods'][0]['goods_name'] ?? '中石油油券';
|
||||
// 获取第三方用户信息(微信)
|
||||
$oauth = UserOauthModel::getOauth($order['user_id'], 'MP-WEIXIN');
|
||||
$wxPay->uploadShipping($order['transaction_id'], $name, $oauth['oauth_id']);
|
||||
}
|
||||
// 批量更新订单状态为已取消
|
||||
$model->onBatchUpdate($orderIds, [
|
||||
'delivery_status' => DeliveryStatusEnum::DELIVERED,
|
||||
'delivery_time' => time(),
|
||||
'receipt_status' => ReceiptStatus::RECEIVED,
|
||||
'receipt_time' => time()
|
||||
]);
|
||||
}
|
||||
// 记录日志
|
||||
Tools::taskLogs('Order', 'deliveryEvent', [
|
||||
'storeId' => $storeId,
|
||||
'orderIds' => helper::jsonEncode($orderIds)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\console\library\Tools;
|
||||
use app\common\service\BaseService;
|
||||
use app\console\model\UserCoupon as UserCouponModel;
|
||||
|
||||
/**
|
||||
* 服务类:用户优惠券
|
||||
* Class Order
|
||||
* @package app\console\service
|
||||
*/
|
||||
class UserCoupon extends BaseService
|
||||
{
|
||||
/**
|
||||
* 设置优惠券过期状态
|
||||
* @param int $storeId
|
||||
* @return bool
|
||||
*/
|
||||
public function setExpired(int $storeId): bool
|
||||
{
|
||||
$model = new UserCouponModel;
|
||||
// 获取已过期的优惠券ID集
|
||||
$couponIds = $model->getExpiredCouponIds($storeId);
|
||||
// 记录日志
|
||||
Tools::taskLogs('UserCoupon', 'setExpired', [
|
||||
'storeId' => $storeId,
|
||||
'couponIds' => helper::jsonEncode($couponIds)
|
||||
]);
|
||||
// 更新已过期状态
|
||||
return $model->setIsExpire($couponIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\console\service;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\console\library\Tools;
|
||||
use app\common\service\BaseService;
|
||||
use app\console\model\User as UserModel;
|
||||
use app\console\model\user\Grade as UserGradeModel;
|
||||
|
||||
|
||||
/**
|
||||
* 服务类:会员等级
|
||||
* Class UserGrade
|
||||
* @package app\console\service
|
||||
*/
|
||||
class UserGrade extends BaseService
|
||||
{
|
||||
/**
|
||||
* 设置用户的会员等级
|
||||
* @param int $storeId
|
||||
* @return array|bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function setUserGrade(int $storeId)
|
||||
{
|
||||
// 获取所有会员等级
|
||||
$list = $this->getUsableList($storeId);
|
||||
// 遍历等级,根据升级条件 查询满足消费金额的用户列表,并且他的等级小于该等级
|
||||
$data = [];
|
||||
foreach ($list as $grade) {
|
||||
// 查询满足会员等级升级条件的用户列表
|
||||
$userList = UserModel::getUpgradeUserList($storeId, $grade, array_keys($data));
|
||||
// 遍历整理数据
|
||||
foreach ($userList as $user) {
|
||||
if (!isset($data[$user['user_id']])) {
|
||||
$data[$user['user_id']] = [
|
||||
'user_id' => $user['user_id'],
|
||||
'old_grade_id' => $user['grade_id'],
|
||||
'new_grade_id' => $grade['grade_id'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
// 记录日志
|
||||
Tools::taskLogs('UserGrade', 'setUserGrade', [
|
||||
'storeId' => $storeId,
|
||||
'data' => $data
|
||||
]);
|
||||
// 批量修改会员的等级
|
||||
return (new UserModel)->setBatchGrade($storeId, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有会员等级
|
||||
* @param int $storeId 商城ID
|
||||
* @return false|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getUsableList(int $storeId)
|
||||
{
|
||||
return UserGradeModel::getUsableList($storeId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user