Sfoglia il codice sorgente

直播间三个数据统计,订单之后后更新冗余到表

lizhen_gitee 2 mesi fa
parent
commit
294c24518f

+ 12 - 3
addons/shopro/controller/goods/Liveroom.php

@@ -70,10 +70,19 @@ class Liveroom extends Common
     //直播间商品列表顶部三个统计
     public function liveroom_index_tongji()
     {
+        //鉴权
+        $room_no = input('room_no','','trim');
+        $user = auth_user();
+        $this->check_auth($room_no,$user['id']);
+
+        $session = input('session','','trim');
+
+        $room_log = Db::name('live_room_log')->where('session',$session)->where('room_no',$room_no)->find();
+
         $rs = [
-            'sales_total_price' => 1,
-            'paid_ordernum'     => 2,
-            'uv'                => 3,
+            'sales_total_price' => $room_log['order_total_amount'], //销售额
+            'paid_ordernum'     => $room_log['order_paidnum'],      //支付订单量
+            'uv'                => $room_log['uv'],                 //访客数
         ];
         $this->success('获取成功', $rs);
 

+ 13 - 2
addons/shopro/job/OrderPaid.php

@@ -35,7 +35,7 @@ class OrderPaid extends BaseJob
                 Db::transaction(function () use ($order, $user, $data) {
                     // 订单减库存
                     $stockSale = new StockSale();
-                    $stockSale->forwardStockSale($order);
+                    $stock_rs = $stockSale->forwardStockSale($order);
 
                     // 处理发票审核改为等待开具
                     if ($order->invoice_status == 1) {
@@ -52,7 +52,18 @@ class OrderPaid extends BaseJob
                     // 将订单参与活动信息改为已支付
                     $orderOper = new OrderOper();
                     $orderOper->activityOrderPaid($order);
-                    
+
+                    //直播间增加销量等数据
+                    if($order['room_log_id'])
+                    {
+                        $room_data = [
+                            'order_paidnum'      => ['inc',1],
+                            'order_total_amount' => ['inc',$order->pay_fee],
+                            'goods_sales'        => ['inc',$stock_rs['goods_num_sum']],
+                        ];
+                        Db::name('live_room_log')->where('id',$order['room_log_id'])->update($room_data);
+                    }
+
                     // 触发订单支付完成事件
                     $data = ['order' => $order, 'user' => $user];
                     \think\Hook::listen('order_paid_after', $data);//orderPaidAfter

+ 6 - 0
addons/shopro/service/StockSale.php

@@ -148,9 +148,13 @@ class StockSale
     public function forwardStockSale($order) {
         $items = OrderItem::where('order_id', $order['id'])->select();
 
+        $result = [
+            'goods_num_sum' => 0,
+        ];
         foreach ($items as $key => $item) {
             // 增加商品销量
             Goods::where('id', $item->goods_id)->setInc('sales', $item->goods_num);
+            $result['goods_num_sum'] += $item->goods_num;
 
             $skuPrice = SkuPrice::where('id', $item->goods_sku_price_id)->find();
             if ($skuPrice) {
@@ -177,6 +181,8 @@ class StockSale
                 $this->stockUnLockItem($order, $item);
             }
         }
+
+        return $result;
     }
 
 

+ 9 - 3
application/api/controller/Demo.php

@@ -3,7 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-
+use think\Db;
 /**
  * 示例接口
  */
@@ -15,7 +15,7 @@ class Demo extends Api
     //如果接口已经设置无需登录,那也就无需鉴权了
     //
     // 无需登录的接口,*表示全部
-    protected $noNeedLogin = ['test', 'test1'];
+    protected $noNeedLogin = ['*'];
     // 无需鉴权的接口,*表示全部
     protected $noNeedRight = ['test2'];
 
@@ -96,7 +96,13 @@ class Demo extends Api
      */
     public function test3()
     {
-        $this->success('返回成功', ['action' => 'test3']);
+        //$this->success('返回成功', ['action' => 'test3']);
+        $data = [
+            'order_paidnum'      => ['inc',1],
+            'order_total_amount' => ['inc',11.25],
+            'goods_sales'        => ['inc',5],
+        ];
+        Db::name('live_room_log')->where('id',23)->update($data);
     }
 
 }