Quellcode durchsuchen

add - 退款流程接口、后台管理

liugc vor 11 Monaten
Ursprung
Commit
81d36c9bca

+ 108 - 0
app/adminapi/controller/external/DouyinOrderController.php

@@ -0,0 +1,108 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+
+namespace app\adminapi\controller\external;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\external\DouyinOrderLists;
+use app\adminapi\logic\external\DouyinOrderLogic;
+use app\adminapi\validate\external\DouyinOrderValidate;
+
+
+/**
+ * DouyinOrder控制器
+ * Class DouyinOrderController
+ * @package app\adminapi\controller
+ */
+class DouyinOrderController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function lists()
+    {
+        return $this->dataLists(new DouyinOrderLists());
+    }
+
+
+    /**
+     * @notes 添加
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function add()
+    {
+        $params = (new DouyinOrderValidate())->post()->goCheck('add');
+        $result = DouyinOrderLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(DouyinOrderLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function edit()
+    {
+        $params = (new DouyinOrderValidate())->post()->goCheck('edit');
+        $result = DouyinOrderLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(DouyinOrderLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function delete()
+    {
+        $params = (new DouyinOrderValidate())->post()->goCheck('delete');
+        DouyinOrderLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function detail()
+    {
+        $params = (new DouyinOrderValidate())->goCheck('detail');
+        $result = DouyinOrderLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}

+ 89 - 0
app/adminapi/lists/external/DouyinOrderLists.php

@@ -0,0 +1,89 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\external;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\external\DouyinOrder;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * DouyinOrder列表
+ * Class DouyinOrderLists
+ * @package app\adminapi\lists
+ */
+class DouyinOrderLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['user_id', 'order_number', 'order_status', 'transaction_id', 'pay_status', 'consultation_id', 'work_id'],
+            '%like%' => ['mobile', 'remark'],
+        ];
+    }
+
+    public function queryWhere(): array
+    {
+        $where = [];
+        if(isset($this->params['refund_pay_status']) && !empty($this->params['refund_pay_status'])){
+            $where[] = ['pay_status', 'in', [3,4,5,6]];
+        }
+        /*if(isset($this->params['create_time_range']) && !empty($this->params['create_time_range'][0]) && !empty($this->params['create_time_range'][1])){
+            $time = [strtotime($this->params['create_time_range'][0]), strtotime($this->params['create_time_range'][1])+86400-1];
+            $where[] = ['create_time', 'between', $time];
+        }*/
+        return  $where;
+    }
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function lists(): array
+    {
+        return DouyinOrder::where($this->searchWhere)->where($this->queryWhere())
+            ->field(['*'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function count(): int
+    {
+        return DouyinOrder::where($this->searchWhere)->where($this->queryWhere())->count();
+    }
+
+}

+ 85 - 0
app/adminapi/lists/external/DouyinRefundOrderLists.php

@@ -0,0 +1,85 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\external;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\lists\ListsSearchInterface;
+use app\common\model\external\DouyinRefundOrder;
+
+
+/**
+ * DouyinRefundOrder列表
+ * Class DouyinRefundOrderLists
+ * @package app\adminapi\lists
+ */
+class DouyinRefundOrderLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['user_id','refund_number', 'refund_status'],
+        ];
+    }
+
+    public function queryWhere(): array
+    {
+        $where = [];
+        /*if(isset($this->params['create_time_range']) && !empty($this->params['create_time_range'][0]) && !empty($this->params['create_time_range'][1])){
+            $time = [strtotime($this->params['create_time_range'][0]), strtotime($this->params['create_time_range'][1])+86400-1];
+            $where[] = ['create_time', 'between', $time];
+        }*/
+        return  $where;
+    }
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function lists(): array
+    {
+        return DouyinRefundOrder::where($this->searchWhere)->where($this->queryWhere())
+            ->field(['*'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function count(): int
+    {
+        return DouyinRefundOrder::where($this->searchWhere)->where($this->queryWhere())->count();
+    }
+
+}

+ 140 - 0
app/adminapi/logic/external/DouyinOrderLogic.php

@@ -0,0 +1,140 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic\external;
+
+
+use app\common\model\external\DouyinOrder;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * DouyinOrder逻辑
+ * Class DouyinOrderLogic
+ * @package app\adminapi\logic
+ */
+class DouyinOrderLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            DouyinOrder::create([
+                'user_id' => $params['user_id'],
+                'mobile' => $params['mobile'],
+                'address_id' => $params['address_id'],
+                'address' => $params['address'],
+                'goods_id' => $params['goods_id'],
+                'unit_price' => $params['unit_price'],
+                'quantity' => $params['quantity'],
+                'total_amount' => $params['total_amount'],
+                'title' => $params['title'],
+                'order_number' => $params['order_number'],
+                'order_status' => $params['order_status'],
+                'transaction_id' => $params['transaction_id'],
+                'pay_time' => $params['pay_time'],
+                'paid_amount' => $params['paid_amount'],
+                'pay_status' => $params['pay_status'],
+                'consultation_id' => $params['consultation_id'],
+                'work_id' => $params['work_id'],
+                'remark' => $params['remark']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            DouyinOrder::where('id', $params['id'])->update([
+                'user_id' => $params['user_id'],
+                'mobile' => $params['mobile'],
+                'address_id' => $params['address_id'],
+                'address' => $params['address'],
+                'goods_id' => $params['goods_id'],
+                'unit_price' => $params['unit_price'],
+                'quantity' => $params['quantity'],
+                'total_amount' => $params['total_amount'],
+                'title' => $params['title'],
+                'order_number' => $params['order_number'],
+                'order_status' => $params['order_status'],
+                'transaction_id' => $params['transaction_id'],
+                'pay_time' => $params['pay_time'],
+                'paid_amount' => $params['paid_amount'],
+                'pay_status' => $params['pay_status'],
+                'consultation_id' => $params['consultation_id'],
+                'work_id' => $params['work_id'],
+                'remark' => $params['remark']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 删除
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public static function delete(array $params): bool
+    {
+        return DouyinOrder::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public static function detail($params): array
+    {
+        return DouyinOrder::findOrEmpty($params['id'])->toArray();
+    }
+}

+ 118 - 0
app/adminapi/validate/external/DouyinOrderValidate.php

@@ -0,0 +1,118 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate\external;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * DouyinOrder验证器
+ * Class DouyinOrderValidate
+ * @package app\adminapi\validate
+ */
+class DouyinOrderValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+        'mobile' => 'require',
+        'address_id' => 'require',
+        'address' => 'require',
+        'goods_id' => 'require',
+        'unit_price' => 'require',
+        'quantity' => 'require',
+        'total_amount' => 'require',
+        'title' => 'require',
+        'order_number' => 'require',
+        'paid_amount' => 'require',
+        'pay_status' => 'require',
+        'work_id' => 'require',
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+        'mobile' => '手机号',
+        'address_id' => '用户地址Id',
+        'address' => '用户地址',
+        'goods_id' => '预约商品',
+        'unit_price' => '商品单价',
+        'quantity' => '商品数量',
+        'total_amount' => '总金额',
+        'title' => '订单名称',
+        'order_number' => '订单单号',
+        'paid_amount' => '实付金额',
+        'pay_status' => '支付状态:0-待支付;1-已支付; 2-已取消即超时未付;	3-退款申请中;4-退款申请不通过;5-退款申请通过-退款中;6-已退款',
+        'work_id' => '工单Id',
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return DouyinOrderValidate
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['mobile','address_id','address','goods_id','unit_price','quantity','total_amount','title','order_number','paid_amount','pay_status','work_id']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return DouyinOrderValidate
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id','mobile','address_id','address','goods_id','unit_price','quantity','total_amount','title','order_number','paid_amount','pay_status','work_id']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return DouyinOrderValidate
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return DouyinOrderValidate
+     * @author likeadmin
+     * @date 2025/05/23 13:40
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 83 - 1
app/api/controller/DouYinController.php

@@ -14,6 +14,8 @@
 
 namespace app\api\controller;
 
+use app\adminapi\lists\external\DouyinOrderLists;
+use app\adminapi\lists\external\DouyinRefundOrderLists;
 use app\api\lists\GoodsLists;
 use app\api\logic\GoodsLogic;
 use app\api\service\DouYinService;
@@ -196,6 +198,86 @@ class DouYinController extends BaseApiController
         }
     }
 
+    /**
+     * 修改预约
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/22 14:35
+     */
+    public function upReservation()
+    {
+        try {
+            $params = $this->request->post(); // order_number appointment_time
+            DouYinService::upReservation($params);
+            return $this->success();
+        } catch (\Exception $e) {
+            return $this->fail($e->getMessage());
+        }
+    }
+    /**
+     * 订单列表
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/22 14:35
+     */
+    public function getOrderLists()
+    {
+        $params = $this->request->get();
+        $params['user_id'] = $this->userId;
+        return $this->dataLists((new DouyinOrderLists())->setParams($params));
+    }
 
-
+    public function getOrderDetail()
+    {
+        $params = $this->request->get();
+        $params['user_id'] = $this->userId;
+        $result = DouYinService::getOrderDetail($params);
+        return $this->data($result);
+    }
+    /**
+     * 退款
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/22 14:35
+     */
+    public function refund()
+    {
+        try {
+            $params = $this->request->post(); // order_number appointment_time
+            $params['user_id'] = $this->userId;
+            DouYinService::refund($params);
+            return $this->success();
+        } catch (\Exception $e) {
+            return $this->fail($e->getMessage());
+        }
+    }
+    /**
+     * 退款订单列表
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/22 14:35
+     */
+    public function getRefundLists()
+    {
+        $params = $this->request->get();
+        $params['user_id'] = $this->userId;
+        return $this->dataLists((new DouyinRefundOrderLists())->setParams($params));
+    }
+    /**
+     * 退款回调
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/22 14:35
+     */
+    public function refundNotify()
+    {
+        try {
+            $params = $this->request->post();
+            $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
+            if(DouYinService::refundNotify($msg)){
+                return json(["err_no"=>0,"err_tips"=>"success"], 200);
+            }
+        } catch (\Exception $e) {
+            return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
+        }
+    }
 }

+ 177 - 0
app/api/service/DouYinService.php

@@ -3,11 +3,14 @@
 namespace app\api\service;
 
 use app\adminapi\logic\external\ExternalConsultationLogic;
+use app\api\logic\ServiceOrderLogic;
 use app\common\model\Config;
 use app\common\model\external\DouyinOrder;
+use app\common\model\external\DouyinRefundOrder;
 use app\common\model\external\ExternalConsultation;
 use app\common\model\external\ExternalConsultationOrder;
 use app\common\model\goods\Goods;
+use app\common\model\recharge\RechargeOrder;
 use app\common\model\user\User;
 use app\common\model\user\UserAuth;
 use app\common\model\works\ServiceWork;
@@ -189,5 +192,179 @@ class DouYinService
             throw new \Exception($e->getMessage());
         }
     }
+    public static function upReservation($params)
+    {
+        // $params['order_number']
+        Db::startTrans();
+        try {
+            $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
+            if(!$order->isEmpty()){
+                // sn appointment_time
+                $result = ServiceOrderLogic::approvalChangeAppointment(['sn'=>RechargeOrder::where('work_id', $order->work_id)->value('sn'),'appointment_time'=>$params['appointment_time']]);
+                if (false === $result) {
+                    throw new \Exception(ServiceOrderLogic::getError());
+                }
+                $order->fulfillment_status = ServiceWork::where('id', $order->work_id)->value('work_status');
+                $order->save();
+            }
+            Db::commit();
+            return $order['id'];
+        } catch (\Exception $e) {
+            Db::rollback();
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+    public static function getOrderDetail($params)
+    {
+        //抖音订单信息/商品信息/预约信息(地址、时间、履约状态与信息)
+        // $params['order_number']  user_id
+        $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
+        if($order->isEmpty()){
+            return [];
+        }
+        $orderInfo = $order->toArray();
+        empty($orderInfo['goods']) && $orderInfo['goods'] = [];
+        empty($orderInfo['serviceWork']) && $orderInfo['serviceWork'] = [];
+
+        $work_status = $orderInfo['serviceWork']['work_status']??0;
+        $performance = [];
+        // tmp
+        switch ($work_status){
+            case 0:
+                $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
+                break;
+            case 1:
+            case 2:
+            case 3:
+                $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
+                $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
+                break;
+            case 4:
+            case 5:
+            case 6:
+                $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
+                $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
+                $performance[] = ['status' => '服务中','title' => '服务中','time' => date('Y-m-d H:i:s',time())];
+                break;
+            case 7:
+            case 8:
+                $performance[] = ['status' => '待派单','title' => '待派单','time' => date('Y-m-d H:i:s',time())];
+                $performance[] = ['status' => '已派单','title' => '已派单','time' => date('Y-m-d H:i:s',time())];
+                $performance[] = ['status' => '服务中','title' => '服务中','time' => date('Y-m-d H:i:s',time())];
+                $performance[] = ['status' => '已完结','title' => '已完结','time' => date('Y-m-d H:i:s',time())];
+                break;
+        }
+        $orderInfo['performance'] = $performance;
+
+        return $orderInfo;
+    }
+
+    public static function refund($params)
+    {
+        Db::startTrans();
+        try {
+            // $params['order_number']  user_id
+            $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
+            if($order->isEmpty()){
+                throw new \Exception('订单不存在');
+            }
+            $orderInfo = $order->toArray();
+            $work_status = $orderInfo['serviceWork']['work_status']??0;
+            if(3 < $work_status){
+                throw new \Exception('该订单禁止退款');
+            }
+
+            DouyinRefundOrder::create([
+                'refund_number' => generate_sn(DouyinRefundOrder::class, 'refund_number'),
+                'order_number' => $orderInfo['order_number'],
+                'transaction_id' => $orderInfo['transaction_id'],
+                'reason' => $params['reason']??'',
+                'refund_status' => 0,
+                'user_id' => $orderInfo['user_id'],
+                'refund_amount' => $orderInfo['paid_amount'],
+            ]);
+
+            Db::commit();
+
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+    public static function refundExamine($params)
+    {
+        Db::startTrans();
+        try {
+            // $params['order_number']  user_id
+            $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->where('user_id', $params['user_id'])->findOrEmpty();
+            if($order->isEmpty()){
+                throw new \Exception('订单不存在');
+            }
+            $orderInfo = $order->toArray();
+            $douyinRefundOrder = DouyinRefundOrder::where('refund_number', $params['refund_number'])->findOrEmpty();
+            if($params['is_examine_ok'] === 'pass'){
+                $douyinRefundOrder->refund_status = 2;
+                RechargeOrder::where('work_id', $orderInfo['work_id'])->update([
+                    'pay_status' => 2,
+                    'pay_time' => 0,
+                    'paid_amount' => 0,
+                ]);
+                ServiceWork::where('id', $orderInfo['work_id'])->update([
+                    'work_status' => 0,
+                    'user_confirm_status' => 0,
+                    'service_status' => 4,
+                    'work_pay_status' => 0
+                ]);
+            }else{
+                $douyinRefundOrder->refund_status = 1;
+            }
+            $douyinRefundOrder->save();
+
+            Db::commit();
+
+            // TODO 需接抖音支付接口
+            /*if($params['is_examine_ok'] === 'pass'){
+                //通过后向抖音申请退款
+                //https://open.douyin.com/api/trade_basic/v1/developer/refund_create/
+            }*/
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+    public static function refundNotify($params)
+    {
+        Db::startTrans();
+        try {
+            $douyinRefundOrder = DouyinRefundOrder::where('refund_number', $params['out_refund_no'])->findOrEmpty();
+            if($douyinRefundOrder->isEmpty()){
+                throw new \Exception('退款订单不存在');
+            }
+            if($douyinRefundOrder->refund_status == 0){
+                if($params['status'] === 'SUCCESS'){
+                    $douyinRefundOrder->refund_status = 3;
+                    DouyinOrder::where('order_number', $douyinRefundOrder->order_number)->update([
+                        'order_status' => 4,
+                        'pay_status' => 3,
+                    ]);
+                }elseif($params['status'] === 'FAIL'){
+                    $douyinRefundOrder->refund_status = 4;
+                }else{
+                    throw new \Exception('退款状态未知');
+                }
+                $douyinRefundOrder->save();
+            }
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            throw new \Exception($e->getMessage());
+        }
+    }
 
 }

+ 14 - 0
app/common/model/external/DouyinOrder.php

@@ -3,8 +3,22 @@
 namespace app\common\model\external;
 
 use app\common\model\BaseModel;
+use app\common\model\goods\Goods;
+use app\common\model\works\ServiceWork;
 
 class DouyinOrder extends BaseModel
 {
     protected $name = 'douyin_order';
+
+    public function goods()
+    {
+        return $this->hasOne(Goods::class, 'id', 'goods_id')
+            ->field('id,goods_name');
+    }
+    public function serviceWork()
+    {
+        return $this->hasOne(ServiceWork::class, 'id', 'work_id')
+            ->field('work_sn,mobile,address,appointment_time,work_status,user_confirm_status,service_status,work_pay_status,
+            lon,lat,province,city,area_name');
+    }
 }

+ 10 - 0
app/common/model/external/DouyinRefundOrder.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace app\common\model\external;
+
+use app\common\model\BaseModel;
+
+class DouyinRefundOrder extends BaseModel
+{
+    protected $name = 'douyin_refund_order';
+}