1.提交缺失的东西
This commit is contained in:
@ -29,8 +29,8 @@ use app\common\logic\{
|
||||
PayNotifyLogic
|
||||
};
|
||||
use app\common\model\user\UserLevel;
|
||||
use app\common\model\{AccountLog,
|
||||
AfterSale,
|
||||
use app\common\model\account\AccountLog;
|
||||
use app\common\model\{AfterSale,
|
||||
AfterSale as CommonAfterSale,
|
||||
BargainLaunch,
|
||||
Client_,
|
||||
|
||||
191
app/common/logic/OrderGoodsLogic.php
Normal file
191
app/common/logic/OrderGoodsLogic.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
|
||||
use app\api\logic\SeckillLogic;
|
||||
use app\common\model\AfterSale;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\OrderGoods;
|
||||
use app\common\model\Pay;
|
||||
use app\common\service\ConfigServer;
|
||||
use think\Db;
|
||||
use think\facade\Hook;
|
||||
|
||||
/**
|
||||
* 订单商品逻辑
|
||||
* Class OrderGoodsLogic
|
||||
* @package app\common\logic
|
||||
*/
|
||||
class OrderGoodsLogic
|
||||
{
|
||||
//返回订单库存,销量
|
||||
public static function backStock($order_goods, $pay_status)
|
||||
{
|
||||
$deduct_type = ConfigServer::get('trading', 'deduct_type', 1);
|
||||
//支付后扣减
|
||||
if ($deduct_type == 0 && $pay_status == Pay::UNPAID) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($order_goods as $good) {
|
||||
//回退库存,回退规格库存,减少商品销量
|
||||
Db::name('goods')
|
||||
->where('id', $good['goods_id'])
|
||||
->update([
|
||||
// 'sales_sum' => Db::raw("sales_sum-" . $good['goods_num']),
|
||||
'stock' => Db::raw('stock+' . $good['goods_num'])
|
||||
]);
|
||||
|
||||
//补充规格表库存
|
||||
Db::name('goods_item')
|
||||
->where('id', $good['item_id'])
|
||||
->setInc('stock', $good['goods_num']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//下单扣除订单库存
|
||||
public static function decStock($goods)
|
||||
{
|
||||
$seckill_data = SeckillLogic::getSeckillGoods();
|
||||
$seckill = $seckill_data['seckill'];
|
||||
$seckill_goods = $seckill_data['seckill_goods'];
|
||||
|
||||
$goods_ids = [];
|
||||
|
||||
foreach ($goods as $k1 => $good) {
|
||||
$item_id = $good['item_id'];
|
||||
//扣除库存,扣除规格库存,增加商品销量
|
||||
Db::name('goods')
|
||||
->where('id', $good['goods_id'])
|
||||
->update([
|
||||
'sales_sum' => Db::raw("sales_sum+" . $good['goods_num']),
|
||||
'stock' => Db::raw('stock-' . $good['goods_num'])
|
||||
]);
|
||||
|
||||
//扣除规格表库存
|
||||
Db::name('goods_item')
|
||||
->where('id', $item_id)
|
||||
->setDec('stock', $good['goods_num']);
|
||||
|
||||
//秒杀商品增加销量
|
||||
if (isset($seckill_goods[$item_id])){
|
||||
$seckill_goods_id = $seckill_goods[$item_id]['seckill_goods_id'];
|
||||
Db::name('seckill_goods')
|
||||
->where('id', $seckill_goods_id)
|
||||
->update([
|
||||
'sales_sum' => Db::raw("sales_sum+" . $good['goods_num']),
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
$goods_ids[] = $good['goods_id'];
|
||||
}
|
||||
|
||||
//下架商品总库存为0的商品
|
||||
if (!empty($goods_ids)){
|
||||
self::outGoods($goods_ids);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 下单后下架商品总库存为0的商品
|
||||
* @param $goods_id
|
||||
* @author 段誉(2021/3/19 16:19)
|
||||
* @return bool
|
||||
*/
|
||||
public static function outGoods($goods_ids)
|
||||
{
|
||||
try{
|
||||
$goods = Db::name('goods')
|
||||
->field('id, stock')
|
||||
->where('id', 'in', $goods_ids)
|
||||
->select();
|
||||
|
||||
if (empty($goods)){
|
||||
return true;
|
||||
}
|
||||
|
||||
$need_handle_ids = [];
|
||||
foreach ($goods as $good) {
|
||||
if ($good['stock'] <= 0) {
|
||||
$need_handle_ids[] = $good['id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($need_handle_ids)){
|
||||
return true;
|
||||
}
|
||||
//下架订单商品中 商品总库存已为0的商品
|
||||
Db::name('goods')->where('id', 'in', $need_handle_ids)->update(['status' => 0]);
|
||||
|
||||
// 下架或删除商品,更新商品收藏
|
||||
Hook::listen('update_collect', ['goods_id' => $need_handle_ids]);
|
||||
|
||||
} catch (\Exception $e) {}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取订单商品 退款运费
|
||||
* @return integer|float
|
||||
* @author lbzy
|
||||
* @datetime 2023-06-26 09:20:21
|
||||
*/
|
||||
static function getRefundExpressMoney($id)
|
||||
{
|
||||
$orderGoods = OrderGoods::find($id);
|
||||
$order = Order::find($orderGoods['order_id'] ?? 0);
|
||||
|
||||
// 不是待发货 不退运费
|
||||
if (empty($order['id']) || $order['order_status'] != Order::STATUS_WAIT_DELIVERY) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$after_sales = AfterSale::where('order_id', $order['id'])->select()->toArray();
|
||||
|
||||
$aids = [];
|
||||
|
||||
foreach ($after_sales as $after_sale) {
|
||||
if (! in_array($after_sale['order_goods_id'], $aids)) {
|
||||
$aids[] = $after_sale['order_goods_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$orderGoodsList = OrderGoods::where('order_id', $order['id'])->select()->toArray();
|
||||
|
||||
if (count($aids) != count($orderGoodsList)) {
|
||||
if (in_array($id, $aids)) {
|
||||
return 0;
|
||||
} else {
|
||||
// 没有记录,是否是最后一个订单商品
|
||||
return count($aids) == (count($orderGoodsList) - 1) ? $order['shipping_price'] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 有记录,是否是在最后申请的
|
||||
return $aids[count($aids) - 1] == $id ? $order['shipping_price'] : 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
50
app/common/logic/OrderLogLogic.php
Normal file
50
app/common/logic/OrderLogLogic.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\logic;
|
||||
|
||||
use app\common\model\OrderLog;
|
||||
|
||||
/**
|
||||
* 订单记录日志
|
||||
* Class OrderLogLogic
|
||||
* @package app\common\logic
|
||||
*/
|
||||
class OrderLogLogic
|
||||
{
|
||||
public static function record($type, $channel, $order_id, $handle_id, $content, $desc = '')
|
||||
{
|
||||
if (empty($content)) {
|
||||
return true;
|
||||
}
|
||||
$log = new OrderLog();
|
||||
$log->type = $type;
|
||||
$log->order_id = $order_id;
|
||||
$log->channel = $channel;
|
||||
$log->handle_id = $handle_id;
|
||||
$log->content = OrderLog::getLogDesc($content);
|
||||
$log->create_time = time();
|
||||
|
||||
if ($desc != '') {
|
||||
$log->content = OrderLog::getLogDesc($content) . '(' . $desc . ')';
|
||||
}
|
||||
|
||||
$log->save();
|
||||
}
|
||||
}
|
||||
91
app/common/model/OrderLog.php
Normal file
91
app/common/model/OrderLog.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeshop开源商城系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee
|
||||
// | github下载:https://github.com/likeshop-github
|
||||
// | 访问官网:https://www.likeshop.cn
|
||||
// | 访问社区:https://home.likeshop.cn
|
||||
// | 访问手册:http://doc.likeshop.cn
|
||||
// | 微信公众号:likeshop技术社区
|
||||
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
|
||||
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
|
||||
// | 禁止对系统程序代码以任何目的,任何形式的再发布
|
||||
// | likeshop团队版权所有并拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeshop.cn.team
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
class OrderLog extends Model
|
||||
{
|
||||
//操作人类型
|
||||
const TYPE_USER = 0;//会员
|
||||
const TYPE_SHOP = 1;//门店
|
||||
const TYPE_SYSTEM = 2;//系统
|
||||
|
||||
//订单动作
|
||||
const USER_ADD_ORDER = 101;//提交订单
|
||||
const USER_CANCEL_ORDER = 102;//取消订单
|
||||
const USER_DEL_ORDER = 103;//删除订单
|
||||
const USER_CONFIRM_ORDER = 104;//确认收货
|
||||
const USER_PAID_ORDER = 105;//支付订单
|
||||
const USER_VERIFICATION = 106;//提货核销
|
||||
|
||||
const SHOP_CANCEL_ORDER = 201;//商家取消订单
|
||||
const SHOP_DEL_ORDER = 202;//商家删除订单
|
||||
const SHOP_DELIVERY_ORDER = 203;//商家发货
|
||||
const SHOP_CONFIRM_ORDER = 204;//商家确认收货
|
||||
const SHOP_VERIFICATION = 205;//商家提货核销
|
||||
|
||||
const SYSTEM_CANCEL_ORDER = 301;//系统取消订单
|
||||
const SYSTEM_CONFIRM_ORDER = 302;//系统确认订单
|
||||
|
||||
//订单动作明细
|
||||
public static function getLogDesc($log)
|
||||
{
|
||||
$desc = [
|
||||
self::USER_ADD_ORDER => '会员提交订单',
|
||||
self::USER_CANCEL_ORDER => '会员取消订单',
|
||||
self::USER_DEL_ORDER => '会员删除订单',
|
||||
self::USER_CONFIRM_ORDER => '会员确认收货',
|
||||
self::USER_PAID_ORDER => '会员支付订单',
|
||||
self::USER_VERIFICATION => '会员提货核销',
|
||||
|
||||
self::SHOP_CANCEL_ORDER => '商家取消订单',
|
||||
self::SHOP_DEL_ORDER => '商家删除订单',
|
||||
self::SHOP_DELIVERY_ORDER => '商家发货',
|
||||
self::SHOP_CONFIRM_ORDER => '商家确认收货',
|
||||
self::SHOP_VERIFICATION => '商家提货核销',
|
||||
|
||||
self::SYSTEM_CANCEL_ORDER => '系统取消订单',
|
||||
self::SYSTEM_CONFIRM_ORDER => '系统确认收货',
|
||||
];
|
||||
|
||||
if ($log === true) {
|
||||
return $desc;
|
||||
}
|
||||
|
||||
return isset($desc[$log]) ? $desc[$log] : $log;
|
||||
}
|
||||
|
||||
//订单日志
|
||||
public static function getOrderLog($order_id)
|
||||
{
|
||||
$logs = Db::name('order_log')
|
||||
->where('order_id', $order_id)
|
||||
->select();
|
||||
|
||||
foreach ($logs as &$log){
|
||||
$log['create_time'] = date('Y-m-d H:i:s', $log['create_time']);
|
||||
$log['channel'] = self::getLogDesc($log['channel']);
|
||||
}
|
||||
|
||||
return $logs;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user