dongxiaoqin 1 год назад
Родитель
Сommit
c21f27dc34

+ 18 - 4
app/adminapi/controller/works/GroupServiceWorkController.php

@@ -97,9 +97,9 @@ class GroupServiceWorkController extends BaseAdminController
         $params = (new GroupServiceWorkValidate())->post()->goCheck('delete');
         $result = GroupServiceWorkLogic::edit($params);
         if (true === $result) {
-            return $this->success('编辑成功', [], 1, 1);
+            return $this->success('删除成功', [], 1, 1);
         }
-        return $this->success('分配成功', [], 1, 1);
+        return $this->fail(GroupServiceWorkLogic::getError());
     }
 
 
@@ -157,6 +157,20 @@ class GroupServiceWorkController extends BaseAdminController
         }
         return $this->fail(GroupServiceWorkLogic::getError());
     }
-
-
+    
+    /**
+     * @notes 退款
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/07/10 15:06
+     */
+    public function refund()
+    {
+        $params = (new GroupServiceWorkValidate())->post()->goCheck('detail');
+        $result = GroupServiceWorkLogic::refund($params,$this->adminInfo);
+        if (true === $result) {
+            return $this->success('退款成功', [], 1, 1);
+        }
+        return $this->fail(GroupServiceWorkLogic::getError());
+    }
 }

+ 1 - 1
app/adminapi/lists/works/GroupServiceWorkLists.php

@@ -103,7 +103,7 @@ class GroupServiceWorkLists extends BaseAdminDataLists implements ListsSearchInt
         ])
             ->where($this->searchWhere)
             ->where($this->queryWhere())
-            ->field(['id', 'code','work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'goods_category_ids', 'goods_category_id', 'work_total','settlement_amount','work_status', 'service_status', 'dispatch_time', 'receive_time', 'appointment_time', 'work_images','finished_images', 'finished_time', 'master_worker_id', 'work_amount',  'create_time', 'finally_door_time','third_type'])
+            ->field(['id', 'code','work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'goods_category_ids', 'goods_category_id', 'work_total','settlement_amount','work_status', 'service_status', 'dispatch_time', 'receive_time', 'appointment_time', 'work_images','finished_images', 'finished_time', 'master_worker_id', 'work_amount',  'create_time', 'finally_door_time','third_type','group_user_order_id'])
             ->append(['service_status_text','category_type_text','third_type_text'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])

+ 0 - 5
app/adminapi/logic/master_worker/MasterWorkerTemporaryLogic.php

@@ -14,14 +14,9 @@
 
 namespace app\adminapi\logic\master_worker;
 
-
-use Excel;
-use think\db\Query;
 use think\facade\Db;
-use think\facade\Config;
 use app\common\logic\BaseLogic;
 use PhpOffice\PhpSpreadsheet\IOFactory;
-use app\common\model\master_worker\MasterWorker;
 use app\common\model\master_worker\MasterWorkerTemporary;
 
 

+ 85 - 1
app/adminapi/logic/works/GroupServiceWorkLogic.php

@@ -17,10 +17,15 @@ namespace app\adminapi\logic\works;
 use think\db\Query;
 use think\Exception;
 use think\facade\Db;
+use app\common\enum\RefundEnum;
 use app\common\logic\BaseLogic;
+use app\common\logic\RefundLogic;
 use PhpOffice\PhpSpreadsheet\IOFactory;
+use app\common\model\refund\RefundRecord;
 use app\common\model\works\GroupServiceWork;
+use app\common\model\group_activity\GroupOrder;
 use app\workerapi\logic\GroupServiceWorkLogLogic;
+use app\common\model\group_activity\GroupUserOrder;
 use app\common\model\master_worker\MasterWorkerTemporary;
 
 /**
@@ -44,6 +49,7 @@ class GroupServiceWorkLogic extends BaseLogic
             GroupServiceWork::where('id', $params['id'])->update([
                 'address' => $params['address'],
                 'appointment_time' => strtotime($params['appointment_time']),
+                'remark' => $params['remark'],
             ]);
             Db::commit();
             return true;
@@ -358,7 +364,6 @@ class GroupServiceWorkLogic extends BaseLogic
                         continue;
                     }
                     $data['third_type'] = 2;
-                    $data['work_status'] = 3;
                     $data['work_pay_status'] = 2;
                     $data['category_type'] = 2;
                     $data['appointment_time'] = $data['appointment_time'] ? strtotime($data['appointment_time']) : 0;
@@ -376,4 +381,83 @@ class GroupServiceWorkLogic extends BaseLogic
         }
     }
 
+    /**
+     * 退款
+     */
+    public static function refund($params,$userInfo){
+        Db::startTrans();
+        try {
+
+            $work = GroupServiceWork::findOrEmpty($params['id']);
+            if($work->isEmpty()){
+                throw new Exception('工单不存在');
+            }
+            if($work->work_status >=7 ){
+                throw new \Exception('工单已完结,不支持退款');
+            }
+            if(!$work->group_user_order_id ){
+                throw new \Exception('临时工单,不支持退款');
+            }
+            $order = GroupUserOrder::where(['id'=>$work->group_user_order_id])->findOrEmpty()->toArray();
+            if (empty($order)){
+                throw new \Exception('用户拼团订单不存在');
+            }
+            if ($order['refund_status'] != 0) {
+                throw new \Exception('用户拼团订单已退款');
+            }
+            
+            //添加变更日志
+            $work_log = [
+                'type' => 5,
+                'work_id'=>$work->id,
+                'master_worker_id'=>$work->master_worker_id,
+                'opera_log'=>'后台用户['.$userInfo['admin_id'].']'.$userInfo['name'].'于'.date('Y-m-d H:i:s',time()).'执行退款'
+            ];
+            GroupServiceWorkLogLogic::add($work_log);
+
+            //退款
+            $work->work_status = 9;
+            $work->service_status = 5;
+            $work->save();
+
+            // 生成退款记录
+            $recordSn = generate_sn(RefundRecord::class, 'sn');
+            $record = RefundRecord::create([
+                'sn' => $recordSn,
+                'user_id' => $order['user_id'],
+                'order_id' => $order['id'],
+                'order_sn' => $order['sn'],
+                'order_type' => RefundEnum::ORDER_TYPE_GROUP,
+                'order_amount' => $order['order_amount'],
+                'refund_amount' => $order['order_amount'],
+                'refund_type' => RefundEnum::TYPE_ADMIN,
+                'transaction_id' => $order['transaction_id'] ?? '',
+                'refund_way' => RefundEnum::getRefundWayByPayWay($order['pay_way']),
+            ]);
+            
+            //更新用户拼团订单
+            GroupUserOrder::where('id',$order['id'])->update(['status' => 2,'refund_status' => 1]);
+
+            //更新拼团订单
+            GroupOrder::where('id',$order['id'])->update([
+                'num' => Db::raw('num-1')
+            ]);
+
+            // 退款
+            $result = RefundLogic::refund($order, $record['id'], $order['order_amount'], $userInfo['admin_id']);
+
+            if ($result !== true) {
+                throw new Exception(RefundLogic::getError());
+                Db::rollback();
+                return false;
+            } else {
+                Db::commit();
+                return true;
+            }
+        }catch(\Exception $e){
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }

+ 1 - 1
app/workerapi/http/middleware/LoginMiddleware.php

@@ -65,7 +65,7 @@ class LoginMiddleware
 
             //临时工程师校验一下权限
             $controller = $request->controller();
-            if (isset($userInfo['type']) && $userInfo['type'] == 2 && !in_array(strtolower($controller), ['groupworks','sms','login','upload'])) {
+            if (isset($userInfo['type']) && $userInfo['type'] == 2 && !in_array(strtolower($controller), ['groupworks','sms','login','upload','masterworkeragree'])) {
                 return JsonService::fail('暂无权限', [], 401);
             }
         }