diff --git a/application/admin/controller/Site.php b/application/admin/controller/Site.php
index b5505d305..89214d398 100755
--- a/application/admin/controller/Site.php
+++ b/application/admin/controller/Site.php
@@ -180,6 +180,9 @@ class Site extends Common
// 扣除库存规则
$this->assign('common_deduction_inventory_rules_list', lang('common_deduction_inventory_rules_list'));
+ // 增加销量规则
+ $this->assign('common_sales_count_inc_rules_list', lang('common_sales_count_inc_rules_list'));
+
// 首页商品排序规则
$this->assign('goods_order_by_type_list', lang('goods_order_by_type_list'));
$this->assign('goods_order_by_rule_list', lang('goods_order_by_rule_list'));
diff --git a/application/admin/view/default/site/siteset/order.html b/application/admin/view/default/site/siteset/order.html
index 5abce7c86..25a5a24aa 100644
--- a/application/admin/view/default/site/siteset/order.html
+++ b/application/admin/view/default/site/siteset/order.html
@@ -41,6 +41,16 @@
+
+
+
+
+
+
diff --git a/application/lang/zh-cn.php b/application/lang/zh-cn.php
index 9ce54ddad..c489291b4 100755
--- a/application/lang/zh-cn.php
+++ b/application/lang/zh-cn.php
@@ -172,12 +172,18 @@ return [
],
// 扣除库存规则
- 'common_deduction_inventory_rules_list' => [
- 0 => ['id' => 0, 'name' => '订单确认成功', 'checked' => true],
+ 'common_deduction_inventory_rules_list' => [
+ 0 => ['id' => 0, 'name' => '订单确认成功'],
1 => ['id' => 1, 'name' => '订单支付成功'],
2 => ['id' => 2, 'name' => '订单发货'],
],
+ // 商品增加销量规则
+ 'common_sales_count_inc_rules_list' => [
+ 0 => ['id' => 0, 'name' => '订单支付'],
+ 1 => ['id' => 1, 'name' => '订单收货'],
+ ],
+
// 是否已读
'common_is_read_list' => [
0 => ['id' => 0, 'name' => '未读', 'checked' => true],
diff --git a/application/service/OrderAftersaleService.php b/application/service/OrderAftersaleService.php
index 62a5a5d7b..94c58bb85 100644
--- a/application/service/OrderAftersaleService.php
+++ b/application/service/OrderAftersaleService.php
@@ -988,7 +988,9 @@ class OrderAftersaleService
}
// 已完成订单、商品销量释放
- if($order['data']['status'] == 4 && $aftersale['number'] > 0)
+ // 规则 订单支付、订单收货(默认)
+ $order_status = (MyC('common_goods_sales_count_inc_rules', 1) == 1) ? 4 : 2;
+ if($order['data']['status'] == $order_status && $aftersale['number'] > 0)
{
if(!Db::name('Goods')->where(['id'=>intval($aftersale['goods_id'])])->setDec('sales_count', $aftersale['number']))
{
diff --git a/application/service/OrderService.php b/application/service/OrderService.php
index 2d0b3faa6..2a593b596 100755
--- a/application/service/OrderService.php
+++ b/application/service/OrderService.php
@@ -807,7 +807,16 @@ class OrderService
{
// 事务回滚
Db::rollback();
- return DataReturn($ret['msg'], -10);
+ return $ret;
+ }
+
+ // 订单商品销量增加
+ $ret = self::GoodsSalesCountInc(['order_id'=>$order['id'], 'order_status'=>2]);
+ if($ret['code'] != 0)
+ {
+ // 事务回滚
+ Db::rollback();
+ return $ret;
}
// 订单支付成功处理完毕钩子
@@ -1789,16 +1798,16 @@ class OrderService
{
// 事务回滚
Db::rollback();
- return DataReturn($ret['msg'], -10);
+ return $ret;
}
// 订单商品销量增加
- $ret = self::GoodsSalesCountInc(['order_id'=>$order['id']]);
+ $ret = self::GoodsSalesCountInc(['order_id'=>$order['id'], 'order_status'=>4]);
if($ret['code'] != 0)
{
// 事务回滚
Db::rollback();
- return DataReturn($ret['msg'], -10);
+ return $ret;
}
// 用户消息
@@ -2106,6 +2115,11 @@ class OrderService
'checked_type' => 'empty',
'key_name' => 'order_id',
'error_msg' => '订单id有误',
+ ],
+ [
+ 'checked_type' => 'isset',
+ 'key_name' => 'order_status',
+ 'error_msg' => '订单状态有误',
]
];
$ret = ParamsChecked($params, $p);
@@ -2114,21 +2128,41 @@ class OrderService
return DataReturn($ret, -1);
}
- // 获取订单商品
- $order_detail = Db::name('OrderDetail')->field('id,goods_id,title,buy_number')->where(['order_id'=>$params['order_id']])->select();
- if(!empty($order_detail))
+ // 增加销量规则、默认订单收货
+ $status = false;
+ if(MyC('common_goods_sales_count_inc_rules', 1) == 1)
{
- foreach($order_detail as $v)
+ // 订单收货责确认订单状态是收货状态
+ if($params['order_status'] == 4)
{
- if(Db::name('Goods')->where(['id'=>$v['goods_id']])->setInc('sales_count', $v['buy_number']) === false)
- {
- return DataReturn('订单商品销量增加失败['.$v['title'].']', -10);
- }
+ $status = true;
}
- return DataReturn('操作成功', 0);
} else {
- return DataReturn('订单有误,没有找到相关商品', -100);
+ // 订单支付状态
+ if($params['order_status'] == 2)
+ {
+ $status = true;
+ }
}
+ if($status)
+ {
+ // 获取订单商品
+ $order_detail = Db::name('OrderDetail')->field('id,goods_id,title,buy_number')->where(['order_id'=>$params['order_id']])->select();
+ if(!empty($order_detail))
+ {
+ foreach($order_detail as $v)
+ {
+ if(Db::name('Goods')->where(['id'=>$v['goods_id']])->setInc('sales_count', $v['buy_number']) === false)
+ {
+ return DataReturn('订单商品销量增加失败['.$v['title'].']', -10);
+ }
+ }
+ return DataReturn('操作成功', 0);
+ } else {
+ return DataReturn('订单有误,没有找到相关商品', -100);
+ }
+ }
+ return DataReturn('无需处理', 0);
}
/**