Browse Source

修改拼团

dongxiaoqin 1 year ago
parent
commit
a3b680431f

+ 9 - 0
app/adminapi/controller/group_activity/GroupActivityCategoryController.php

@@ -111,4 +111,13 @@ class GroupActivityCategoryController extends BaseAdminController
         return $this->success('',['qrcode'=>GroupActivityCategoryLogic::getQRCode($params, $this->request->domain())], 1, 1);
     }
 
+    /**
+     * 分类活动统计
+     */
+    public function total() 
+    {
+        $id = (int)$this->request->param('id');
+        $result = GroupActivityCategoryValidate::total($id);
+        return $this->data($result);
+    }
 }

+ 4 - 3
app/adminapi/lists/group_activity/GroupActivityCategoryLists.php

@@ -38,7 +38,7 @@ class GroupActivityCategoryLists extends BaseAdminDataLists implements ListsSear
     public function setSearch(): array
     {
         return [
-            '=' => ['id', 'status','type', 'is_simulate_form'],
+            '=' => ['id', 'status','type', 'is_simulate_form','property_head_id'],
             '%like%' => ['title','area'],
         ];
     }
@@ -61,8 +61,9 @@ class GroupActivityCategoryLists extends BaseAdminDataLists implements ListsSear
      */
     public function lists(): array
     {
-        $list = GroupActivityCategory::where($this->searchWhere)
-            ->field(['id', 'title', 'start_time', 'end_time', 'service_time', 'participant_num', 'type', 'form_time_limit', 'is_simulate_form', 'simulate_num','area','status','create_time'])
+        $list = GroupActivityCategory::with(['propertyHeadInfo'])
+            ->where($this->searchWhere)
+            ->field(['id', 'property_head_id','title', 'start_time', 'end_time', 'service_time', 'participant_num', 'type', 'form_time_limit', 'is_simulate_form', 'simulate_num','area','status','create_time'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->select()

+ 2 - 4
app/adminapi/logic/group_activity/GroupActivityCategoryLogic.php

@@ -22,7 +22,6 @@ use app\common\logic\BaseLogic;
 use app\common\service\wechat\WeChatMnpService;
 use app\common\model\group_activity\GroupActivity;
 use app\common\model\group_activity\GroupActivityCategory;
-use app\common\model\master_worker\MasterWorker;
 
 /**
  * 拼团活动分类逻辑
@@ -63,7 +62,7 @@ class GroupActivityCategoryLogic extends BaseLogic
                 'start_time' => strtotime($params['start_time']),
                 'end_time' => strtotime($params['end_time']),
                 'service_time' => strtotime($params['service_time']),
-                'master_worker_id' => $params['master_worker_id'],
+                'property_head_id' => $params['property_head_id'],
                 'participant_num' => $params['participant_num'],
                 'type' => $params['type'],
                 'form_time_limit' => $params['form_time_limit'],
@@ -167,7 +166,7 @@ class GroupActivityCategoryLogic extends BaseLogic
                 'start_time' => strtotime($params['start_time']),
                 'end_time' => strtotime($params['end_time']),
                 'service_time' => strtotime($params['service_time']),
-                'master_worker_id' => $params['master_worker_id'],
+                'property_head_id' => $params['property_head_id'],
                 'participant_num' => $params['participant_num'],
                 'type' => $params['type'],
                 'form_time_limit' => $params['form_time_limit'],
@@ -222,7 +221,6 @@ class GroupActivityCategoryLogic extends BaseLogic
         $detail['area'] = explode(",",$detail['area']);
         $detail['images'] = $detail['images'] ? explode(",",$detail['images']) : [];
         $detail['block_data'] = json_decode($detail['block_data'],true);
-        $detail['master_worker_name'] = MasterWorker::where('id',$detail['master_worker_id'])->value('real_name');
         foreach($detail['block_data'] as $key => $item) {
             $detail['block_data'][$key]['activity'] = GroupActivity::where(['block_key' => $item['block_key'],'group_category_id' => $detail['id']])
                     ->field('id,id as data_id,title,image,equity_id,block_key,origin_price,price,work_amount,settlement_amount')

+ 17 - 1
app/adminapi/validate/group_activity/GroupActivityCategoryValidate.php

@@ -14,7 +14,7 @@
 
 namespace app\adminapi\validate\group_activity;
 
-
+use app\common\model\group_activity\GroupActivity;
 use app\common\validate\BaseValidate;
 
 
@@ -111,4 +111,20 @@ class GroupActivityCategoryValidate extends BaseValidate
         return $this->only(['id']);
     }
 
+    /**
+     * 活动分类统计
+     */
+    public static function total($id)
+    {
+        $result = GroupActivity::alias('a')
+        ->leftJoin('group_user_order b', 'a.id = b.group_activity_id')
+        ->leftJoin('group_service_work c', 'b.id = c.group_user_order_id and c.service_status = 3')
+        ->field('a.*, SUM(CASE WHEN c.id IS NOT NULL THEN 1 ELSE 0 END) as order_total')
+        ->where('a.group_category_id', $id)
+        ->group('a.id')
+        ->select()
+        ->toArray();
+        return $result;
+    }
+
 }

+ 18 - 1
app/api/controller/GroupActivityController.php

@@ -1,11 +1,13 @@
 <?php
 namespace app\api\controller;
 
+use think\facade\Log;
 use app\common\logic\PaymentLogic;
 use app\api\logic\GroupActivityLogic;
 use app\api\validate\GroupOrderValidate;
 use app\api\lists\group_activity\UserOrderLists;
-use think\facade\Log;
+use app\api\lists\property\PropertyGroupOrderLists;
+use app\api\lists\property\PropertyServiceWorkLists;
 
 
 /**
@@ -180,4 +182,19 @@ class GroupActivityController extends BaseApiController
         return $this->success('',['qrcode'=>GroupActivityLogic::getQRCode($params, $this->request->domain())], 1, 1);
     }
 
+    /**
+     * 代理人拼团订单列表
+     */
+    public function propertyOrderLists()
+    {
+        return $this->dataLists(new PropertyGroupOrderLists());
+    }
+
+    /**
+     * 代理人完结的工单列表
+     */
+    public function propertyServiceWorkLists()
+    {
+        return $this->dataLists(new PropertyServiceWorkLists());
+    }
 }

+ 82 - 0
app/api/lists/property/PropertyGroupOrderLists.php

@@ -0,0 +1,82 @@
+<?php
+namespace app\api\lists\property;
+
+use app\api\lists\BaseApiDataLists;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\property\PropertyHead;
+use app\common\model\group_activity\GroupUserOrder;
+
+/**
+ * 代理人拼团订单列表
+ * Class PropertyGroupOrderLists
+ * @package app\api\lists\property
+ */
+class PropertyGroupOrderLists extends BaseApiDataLists implements ListsSearchInterface
+{
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/07/07 18:37
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => [],
+        ];
+    }
+    public function queryWhere()
+    {
+        // 指定用户
+        $propertyHeadId = PropertyHead::where('user_id',$this->userId)->value('id');
+        $where[] = ['b.property_head_id', '=', $propertyHeadId];
+
+        if (isset($this->params['status'])) {
+            if ($this->params['status'] == 0) {
+                $where[] = ['a.status', '=', 0];
+            } elseif ($this->params['status'] == 1) {
+                $where[] = ['a.status', '=', 1];
+            } else {
+                $where[] = ['a.status', '>', 1];
+            }
+        }
+        if (isset($this->params['start_time']) && !empty($this->params['start_time'])) {
+            $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time'])));
+            $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time'])));
+            $where[] = ['a.create_time', 'between', [$monthStart, $monthEnd]];
+        }
+        return $where;
+    }
+    
+    /**
+     * @notes 获取列表
+     * @return array
+     */
+    public function lists(): array
+    {
+        $lists = GroupUserOrder::alias('a')
+        ->leftJoin('group_order b','a.group_order_id=b.id')
+        ->leftJoin('group_activity c','a.group_activity_id=c.id')
+        ->field('a.id,a.sn,a.group_activity_id,a.status,a.order_amount,a.paid_amount,a.pay_status,a.refund_status,a.create_time,b.goods_id,b.num,b.origin_price,b.end_time,c.title,c.image')
+            ->where($this->queryWhere())
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order('a.create_time', 'desc')
+            ->select()
+            ->toArray();
+        return $lists;
+    }
+
+    /**
+     * @notes  获取数量
+     * @return int
+     */
+    public function count(): int
+    {
+        return GroupUserOrder::alias('a')
+            ->leftJoin('group_order b','a.group_order_id=b.id')
+            ->leftJoin('group_activity c','a.group_activity_id=c.id')
+            ->where($this->queryWhere())
+            ->count();
+    }
+
+}

+ 93 - 0
app/api/lists/property/PropertyServiceWorkLists.php

@@ -0,0 +1,93 @@
+<?php
+namespace app\api\lists\property;
+
+use app\api\lists\BaseApiDataLists;
+use app\common\lists\ListsExtendInterface;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\property\PropertyHead;
+use app\common\model\works\GroupServiceWork;
+use app\common\model\group_activity\GroupUserOrder;
+
+/**
+ * 代理人完结工单列表
+ * Class PropertyServiceWorkLists
+ * @package app\api\lists\property
+ */
+class PropertyServiceWorkLists extends BaseApiDataLists implements ListsSearchInterface, ListsExtendInterface
+{
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/07/07 18:37
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => [],
+        ];
+    }
+    public function queryWhere()
+    {
+        // 指定用户
+        $propertyHeadId = PropertyHead::where('user_id',$this->userId)->value('id');
+        $where[] = ['b.property_head_id', '=', $propertyHeadId];
+        if (isset($this->params['start_time']) && !empty($this->params['start_time'])) {
+            $monthStart = strtotime(date("Y-m-01",strtotime($this->params['start_time'])));
+            $monthEnd = strtotime(date("Y-m-t 23:59:59",strtotime($this->params['start_time'])));
+            $where[] = ['b.create_time', 'between', [$monthStart, $monthEnd]];
+        }
+       // $where[] = ['a.service_status', '=', 3];
+        return $where;
+    }
+    
+    /**
+     * @notes 获取列表
+     * @return array
+     */
+    public function lists(): array
+    {
+        $lists = GroupServiceWork::alias('a')
+            ->leftJoin('group_order b','a.group_order_id=b.id')
+            ->field('a.id,a.work_total,a.address,a.mobile,a.real_name,b.create_time')
+            ->where($this->queryWhere())
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order('b.create_time', 'desc')
+            ->select()
+            ->toArray();
+        return $lists;
+    }
+
+    /**
+     * @notes  获取数量
+     * @return int
+     */
+    public function count(): int
+    {
+        return GroupServiceWork::alias('a')
+            ->leftJoin('group_order b','a.group_order_id=b.id')
+            ->where($this->queryWhere())
+            ->count();
+    }
+
+    /**
+     * @notes 统计工单总收益
+     * @return float
+     */
+    public function extend(): array
+    {
+        $totalWorkTotal = GroupUserOrder::alias('a')
+            ->leftJoin('group_order b', 'a.group_order_id = b.id')
+            ->leftJoin('group_service_work c', 'a.id = c.group_user_order_id')
+            ->where($this->queryWhere())
+            ->sum('c.work_total');
+
+        $totalWorkAmount = GroupUserOrder::alias('a')
+            ->leftJoin('group_order b', 'a.group_order_id = b.id')
+            ->leftJoin('group_service_work c', 'a.id = c.group_user_order_id')
+            ->where($this->queryWhere())
+            ->sum('c.work_amount');
+        return ["total_amount" => $totalWorkTotal - $totalWorkAmount];
+    }
+
+}

+ 3 - 2
app/api/logic/GroupActivityLogic.php

@@ -70,7 +70,7 @@ class GroupActivityLogic extends BaseLogic
         $detail = GroupOrder::where(['id'=>$order_id])->findOrEmpty()->toArray();
         if(!empty($detail)){
             $detail['activity'] = GroupActivity::getDetail($detail['group_activity_id']);
-            $detail['activity']['goods'] = self::getEquityGoods($detail['activity']['equity_id']); 
+            $detail['activity']['goods'] = self::getEquityGoods($detail['equity_id']); 
             $detail['is_paid'] = 0;
             $detail['order_id'] = 0;
 
@@ -136,7 +136,7 @@ class GroupActivityLogic extends BaseLogic
                 }
             }
             $detail['activity'] = GroupActivity::getDetail($detail['group_activity_id']);
-            $detail['activity']['goods'] = self::getEquityGoods($detail['activity']['equity_id']); 
+            $detail['activity']['goods'] = self::getEquityGoods($detail['groupOrder']['equity_id']); 
             $detail['timestamp'] = time();
         }
         return $detail;
@@ -177,6 +177,7 @@ class GroupActivityLogic extends BaseLogic
                     'sn' => generate_sn(GroupOrder::class, 'sn'),
                     'group_category_id' => $activity['group_category_id'],
                     'group_activity_id' => $params['group_activity_id'],
+                    'property_head_id' => $activity['property_head_id'],
                     'equity_id' => $activity['equity_id'],
                     'goods_id' => EquityConfig::where('id', $activity['equity_id'])->value('goods_id'),
                     'user_id' => $params['user_id'],

+ 5 - 1
app/common/model/group_activity/GroupActivityCategory.php

@@ -16,6 +16,7 @@ namespace app\common\model\group_activity;
 
 use app\common\model\BaseModel;
 use think\model\concern\SoftDelete;
+use app\common\model\property\PropertyHead;
 
 
 /**
@@ -41,5 +42,8 @@ class GroupActivityCategory extends BaseModel
     {
         return !empty($data['service_time'])?date('Y-m-d H:i:s',$data['service_time']):'';
     }
-    
+    public function propertyHeadInfo()
+    {
+        return $this->hasOne(PropertyHead::class, 'id', 'property_head_id');
+    }
 }

+ 8 - 30
app/workerapi/lists/GroupServiceWorkLists.php

@@ -36,42 +36,20 @@ class GroupServiceWorkLists  extends BaseWorkerDataLists implements ListsSearchI
         $status = $this->params['status'] ?? 0;
         switch ($status){
             case 0:
-                $where[] = ['work_status','<>',1];
-                $where[] = ['service_status','in','0,1,2'];
+                //今日上门
+                $startOfDayTimestamp = strtotime(date("Y-m-d"));
+                $endOfDayTimestamp = strtotime(date("Y-m-d 23:59:59"));
+                $where[] = ['work_status','=',3];
+                $where[] = ['appointment_time','between',[$startOfDayTimestamp, $endOfDayTimestamp]];
                 break;
             case 1:
+                //待完成
                 $where[] = ['work_status','<>',1];
                 $where[] = ['service_status','in','0,1,2'];
-                // 创建 DateTime 对象并设置为今天午夜
-                $startOfDay = new DateTime('today midnight');
-                // 设置为今天最后一秒
-                $endOfDay = new DateTime('today midnight');
-                $endOfDay->modify('+1 day -1 second');
-                // 转换为时间戳
-                $startOfDayTimestamp = $startOfDay->getTimestamp();
-                $endOfDayTimestamp = $endOfDay->getTimestamp();
-                $where[] = ['appointment_time','between',[$startOfDayTimestamp, $endOfDayTimestamp]];
                 break;
             case 2:
-                $where[] = ['work_status','<>',1];
-                $where[] = ['service_status','in','0,1,2'];
-                // 创建一个 DateTime 对象表示当前时间
-                $dateNow = new DateTime();
-                // 修改这个对象以表示明天的午夜
-                $midnightTomorrow = clone $dateNow;
-                $midnightTomorrow->modify('+1 day midnight');
-                // 修改这个对象以表示明天的最后一秒
-                $lastSecondTomorrow = clone $dateNow;
-                $lastSecondTomorrow->modify('+1 day 23:59:59');
-                $midnightTimestamp = $midnightTomorrow->getTimestamp();
-                $lastSecondTimestamp = $lastSecondTomorrow->getTimestamp();
-                $where[] = ['appointment_time','between',[$midnightTimestamp, $lastSecondTimestamp]];
-                break;
-            case 3:
-                $where[] = ['work_status','<>',1];
-                break;
-            case 4:
-                $where['work_status'] = 7;
+                //已完成
+                $where[] = ['service_status','=','3'];
                 break;
         }
         $list = GroupServiceWork::where($where)