Browse Source

酒店商家控制台

Panda 1 week ago
parent
commit
943fce2d46
1 changed files with 61 additions and 0 deletions
  1. 61 0
      application/api/controller/shop/ShopHotel.php

+ 61 - 0
application/api/controller/shop/ShopHotel.php

@@ -48,4 +48,65 @@ class ShopHotel extends Api
             'statistics' => $statistics
         ]);
     }
+
+    // 交易统计
+    public function statistics()
+    {
+        $params = $this->request->param();
+        $user_id = $this->auth->id;
+
+        if (empty($params['type'])){
+            $params['type'] = 1;
+        }
+
+        $model = new HotelModel();
+        $info = $model->getDetail(
+            params: ['user_id' => $user_id],
+            select: ['id','invite_id','user_id','name','image','images','back_rate','address']
+        );
+        if (!$info){
+            return $this->success('未开通门店');
+        }
+        switch ($params['type']){
+            case 1:
+                // 今天
+                $createtimeBetween = [
+                    strtotime(date('Y-m-d 00:00:00')),
+                    strtotime(date('Y-m-d 23:59:59')),
+                ];
+                break;
+            case 2:
+                // 昨天
+                $createtimeBetween = [
+                    strtotime(date('Y-m-d 00:00:00', strtotime('-1 day'))),
+                    strtotime(date('Y-m-d 23:59:59', strtotime('-1 day'))),
+                ];
+                break;
+            case 3:
+                // 本月
+                $createtimeBetween = [
+                    strtotime(date('Y-m-01 00:00:00')),
+                    strtotime(date('Y-m-d 23:59:59')),
+                ];
+                break;
+            default:
+                $createtimeBetween = [
+                    strtotime(date('Y-m-d 00:00:00'),strtotime($params['date'])),
+                    strtotime(date('Y-m-d 23:59:59'),strtotime($params['date'])),
+                ];
+                break;
+        }
+
+        $wait_use = Db::name('bill')
+            ->where(['shop_id'=>$info['id'],'table_name'=>'hotel_order'])
+            ->whereIn('status',[1,2,3])
+            ->whereBetween('createtime',$createtimeBetween)
+            ->field('sum(total_amount - back_amount) as money,count(id) as num')
+            ->find();
+
+        return $this->success('success',[
+            'money' => $wait_use['money'] ?? 0,
+            'num' => $used['num'] ?? 0,
+        ]);
+    }
 }