Ver código fonte

Merge branch 'master' of e.coding.net:zdap/weixiu/weixiu_api into m--accessory_settlement

liugc 11 meses atrás
pai
commit
fec1740212

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

@@ -0,0 +1,114 @@
+<?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;
+use app\api\service\DouYinService;
+
+
+/**
+ * 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);
+    }
+    public function refundExamine()
+    {
+        $params = $this->request->post();
+        $result = DouyinOrderLogic::refundExamine($params);
+        return $this->success('操作成功', [], 1, 1);
+    }
+
+}

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

@@ -0,0 +1,90 @@
+<?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::with(['goods', 'serviceWork','douyinRefundOrder'])->where($this->searchWhere)->where($this->queryWhere())
+            ->field(['*'])
+            ->append(['order_status_text','pay_status_text'])
+            ->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();
+    }
+
+}

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

@@ -0,0 +1,86 @@
+<?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(['*'])
+            ->append(['refund_status_text'])
+            ->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();
+    }
+
+}

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

@@ -0,0 +1,159 @@
+<?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\api\service\DouYinService;
+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();
+    }
+
+    public static function refundExamine($params)
+    {
+        try {
+            $params['is_examine_ok'] = 'pass';
+            DouYinService::refundExamine($params);
+            return true;
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+
+    }
+
+
+
+
+
+}

+ 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']);
+    }
+
+}

+ 316 - 0
app/api/controller/DouYinController.php

@@ -0,0 +1,316 @@
+<?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\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;
+use app\common\enum\LoginEnum;
+use app\common\enum\user\UserTerminalEnum;
+use app\common\model\user\User;
+use app\api\validate\{LoginAccountValidate, RegisterValidate, WebScanLoginValidate, WechatLoginValidate};
+use app\api\logic\LoginLogic;
+use think\facade\Log;
+
+/**
+ * 抖音 - tmp
+ * Class DouYinController
+ * @package app\api\controller
+ */
+class DouYinController extends BaseApiController
+{
+
+    public array $notNeedLogin = ['testNotify','getClientToken','register','account','getAllGoods','getGoodsDetail','payNotify'];
+    public function testNotify()
+    {
+        // https://weixiudev.kyjlkj.com/api/dou_yin/testNotify
+        $params = $this->request->post();
+        Log::info('dy_testNotify:'.json_encode($params));
+    }
+
+    public function getClientToken()
+    {
+        $access_token = DouYinService::getClientToken();
+        return $this->success('',['access_token'=>$access_token]);
+    }
+    /**
+     * 手机号注册
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/20 13:39
+     */
+    public function register()
+    {
+        try {
+            $params = $this->request->post();
+            $this->validate($params,[
+                "code" => "require",
+                "mobile" => "require|mobile",
+            ]);
+            // 验证码验证
+            $res = \app\workerapi\logic\LoginLogic::confirmMobile($params);
+            if(!$res){
+                throw new \Exception('验证码错误');
+            }
+            // 注册并登录
+            $result = DouYinService::phoneLogin($params);
+            return $this->data($result);
+        } catch (\Exception $e) {
+            return $this->fail($e->getMessage());
+        }
+    }
+
+    /**
+     * @notes 账号密码/手机号密码/手机号验证码登录
+     * @return \think\response\Json
+     * @author 段誉
+     * @date 2022/9/16 10:42
+     */
+    public function account()
+    {
+        try {
+            $params = (new LoginAccountValidate())->post()->goCheck();
+            $result = LoginLogic::login($params);
+            if (false === $result) {
+                return $this->fail(LoginLogic::getError());
+            }
+            return $this->data($result);
+        } catch (\Exception $e) {
+            return $this->fail($e->getMessage());
+        }
+    }
+
+
+    /**
+     * @notes 退出登录
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author 段誉
+     * @date 2022/9/16 10:42
+     */
+    public function logout()
+    {
+        LoginLogic::logout($this->userInfo);
+        return $this->success();
+    }
+
+
+    /**
+     * 所有商品
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/20 14:35
+     */
+    public function getAllGoods()
+    {
+        $params = $this->request->get();
+        $params['platform_value'] = 6;
+        return $this->dataLists((new GoodsLists())->setParams($params));
+    }
+
+
+    /**
+     * 商品详情
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/20 14:35
+     */
+    public function getGoodsDetail()
+    {
+        $params = $this->request->get();
+        $params['platform_value'] = 6;
+        $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId,$params);
+        return $this->data($result);
+    }
+
+
+    /**
+     * 下单
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/22 14:35
+     */
+    public function submitOrder()
+    {
+        try {
+            $params = $this->request->post();
+            $params['user_id'] = $this->userId;
+            $params['user_info'] = $this->userInfo;
+            $order_number = DouYinService::submitOrder($params);
+            $requestOrderData = DouYinService::getByteAuthorization($order_number);
+            $requestOrderData['order_number'] = $order_number;
+            return $this->success('',$requestOrderData);
+        } 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 requestOrderData()
+    {
+        try {
+            $params = $this->request->post();
+            $params['user_id'] = $this->userId;
+            $params['user_info'] = $this->userInfo;
+            $requestOrderData = DouYinService::getByteAuthorization($params['order_number']);
+            $requestOrderData['order_number'] = $params['order_number'];
+            return $this->success('',$requestOrderData);
+        } 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 cancelOrder()
+    {
+        try {
+            $params = $this->request->post(); // order_number
+            DouYinService::cancelOrder($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 payNotify()
+    {
+        try {
+            $params = $this->request->post();
+            $msg = is_array($params['msg'])?$params['msg']:json_decode($params['msg'],true);
+            if(DouYinService::payNotify($msg)){
+                return json(["err_no"=>0,"err_tips"=>"success"], 200);
+            }
+        } catch (\Exception $e) {
+            return json(["err_no"=>1001,"err_tips"=>$e->getMessage()], 200);
+        }
+    }
+
+    /**
+     * 预约
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/22 14:35
+     */
+    public function reservation()
+    {
+        try {
+            $params = $this->request->post(); // order_number
+            DouYinService::reservation($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 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);
+        }
+    }
+}

+ 4 - 2
app/api/lists/GoodsLists.php

@@ -51,6 +51,9 @@ class GoodsLists  extends BaseApiDataLists implements ListsSearchInterface
         $where['user_id'] = 0;//常规商品
         $where['is_agent'] = 0;//常规商品
         $where['platform_value'] = 0;//自平台商品
+        if (isset($this->params['platform_value']) && !empty($this->params['platform_value'])) {
+            $where['platform_value'] = $this->params['platform_value'];//外部平台商品
+        }
         if (!empty($this->params['goods_category_id'])) {
             $goodsCategoryId = end($this->params['goods_category_id']);
             $goodsCategoryData = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
@@ -76,14 +79,13 @@ class GoodsLists  extends BaseApiDataLists implements ListsSearchInterface
         $lists = Goods::order(['id' => 'desc'])
             ->where($this->searchWhere)
             ->where($this->queryWhere())
-            ->visible(['id','goods_name','goods_image'])
+            ->visible(['id','goods_name','goods_image','service_fee','category_type','goods_category_ids','goods_category_id','goods_payment_type','base_service_fee','service_total'])
             ->limit($this->limitOffset, $this->limitLength)
             ->select()
             ->toArray();
         return $lists;
     }
 
-
     /**
      * @notes 获取数量
      * @return int

+ 2 - 2
app/api/logic/GoodsLogic.php

@@ -30,7 +30,7 @@ class GoodsLogic extends BaseLogic
         $where = [];
         $service_work_id = $params['service_work_id']??0;
         $platform_appid = $params['platform_appid']??0;
-        $platform_value = 0;
+        $platform_value = $params['platform_value']??0;
         if($type == 'category'){
             $where[] = ['goods_status','=',1];
             $where[] = ['goods_category_id','=',$id];
@@ -44,7 +44,7 @@ class GoodsLogic extends BaseLogic
                 $platform_value = ExternalPlatform::where('appid',$platform_appid)->value('id');
                 $where[] = ['platform_value','=',$platform_value];
             }else{
-                $where[] = ['platform_value','=',0];
+                $where[] = ['platform_value','=',$platform_value];
             }
             $goods = Goods::where($where)->visible([
                 'id','goods_image','goods_name','goods_banners','good_unit','sell_num','base_service_fee',

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

@@ -0,0 +1,551 @@
+<?php
+
+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;
+use app\common\service\ConfigService;
+use app\common\service\FileService;
+use think\facade\Db;
+use think\facade\Log;
+
+class DouYinService
+{
+    protected static int $terminal = \app\common\enum\user\UserTerminalEnum::DOUYIN;
+    protected static int $external_platform_id = 6;
+    public static function register(array $params)
+    {
+        $userSn = User::createUserSn();
+        $params['password'] = !empty($params['password'])?$params['password']:rand(100000,999999);
+        $passwordSalt = \think\facade\Config::get('project.unique_identification');
+        $password = create_password($params['password'], $passwordSalt);
+        $avatar = ConfigService::get('default_image', 'user_avatar');
+        $user = User::create([
+            'sn' => $userSn,
+            'avatar' => $avatar,
+            'nickname' => '用户' . $userSn,
+            'account' => $params['account'],
+            'mobile' => !empty($params['mobile'])?$params['mobile']:'',
+            'password' => $password,
+            'channel' => self::$terminal,
+            'user_type' => $params['user_type']??0,
+        ]);
+
+        return $user;
+    }
+    public static function phoneLogin(array $params)
+    {
+        try {
+            $where = ['mobile' => $params['mobile']];
+            $params['account'] = $params['mobile'];
+            $user = User::where($where)->findOrEmpty();
+            if ($user->isEmpty()) {
+                //直接注册用户
+                $params['channel'] = self::$terminal;
+                $user = self::register($params);
+            }
+            //更新登录信息
+            $user->login_time = time();
+            $user->login_ip = request()->ip();
+            $user->save();
+
+            $userInfo = UserTokenService::setToken($user->id, self::$terminal);
+
+            //返回登录信息
+            $avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
+            $avatar = FileService::getFileUrl($avatar);
+
+            return [
+                'nickname' => $userInfo['nickname'],
+                'sn' => $userInfo['sn'],
+                'mobile' => $userInfo['mobile'],
+                'avatar' => $avatar,
+                'token' => $userInfo['token'],
+            ];
+        } catch (\Exception $e) {
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+    /**
+     * 提交订单
+     * @param array $params
+     * @return array|false
+     */
+    public static function submitOrder($params)
+    {
+        Db::startTrans();
+        try {
+
+            $goods = Goods::findOrEmpty($params['goods_id']);
+            if($goods->isEmpty()){
+                throw new \Exception('产品不存在!');
+            }
+            if(empty($params['user_info']['mobile'])){
+                throw new \Exception('请先补充您的联系方式后在提交订单');
+            }
+            // TODO tmp防抖1m
+            $isExist = DouyinOrder::where(['user_id'=>$params['user_id'],'goods_id'=>$goods['id']])->where('create_time','>',(time() - 60))->findOrEmpty();
+            if(!$isExist->isEmpty()){
+                throw new \Exception('请勿重复下单!');
+            }
+            $quantity = $params['quantity']??1;
+            //生成订单
+            $create_data = [
+                'user_id' => $params['user_id'],
+                'mobile' => $params['user_info']['mobile'],
+                'title' => $goods['goods_name'],
+
+                'goods_id'=>$goods['id'],
+                'unit_price' => $goods['service_fee'],
+                'quantity' => $quantity,
+                'total_amount' => $goods['service_fee'] * $quantity,
+                'order_number' => generate_sn(DouyinOrder::class, 'order_number'),
+            ];
+            $order = DouyinOrder::create($create_data);
+            Db::commit();
+            return $create_data['order_number'];
+        } catch (\Exception $e) {
+            Db::rollback();
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+    public static function getByteAuthorization($order_number)
+    {
+        /*{
+            "skuList": [{
+                "skuId": "商品ID",
+                "price": 100,//单价-分
+                "quantity": 1,
+                "title": "商品标题",
+                "imageList": ["https://cdn.weixiu.kyjlkj.com/uploads/images/20240914/202409141528015aeaa2357.png"],
+                "type": 701,
+                "tagGroupId": "tag_group_7272625659887960076"
+            }],
+            "outOrderNo": "202411121413333930",
+            "totalAmount": 100,//分
+            "orderEntrySchema": {
+                    "path": "page/path/index",
+                "params": '{"id":1234, "name":"hello"}'
+            },
+            "payNotifyUrl": "https://weixiudev.kyjlkj.com/api/dou_yin/payNotify"
+        }*/
+        try {
+            $douyinOrder = DouyinOrder::where('order_number',$order_number)->findOrEmpty();
+            if($douyinOrder->isEmpty()){
+                throw new \Exception('订单不存在!');
+            }
+            $order = $douyinOrder->toArray();
+            $goods_image = Goods::where('id',$order['goods_id'])->value('goods_image')??'';
+
+            $data = [
+                "skuList" => [
+                    [
+                        "skuId" => (string)$order['goods_id'],
+                        "price" => $order['unit_price'] * 100,
+                        "quantity" => $order['quantity'],
+                        "title" => $order['title'],
+                        "imageList" => [$goods_image],
+                        "type" => 701,
+                        "tagGroupId" => "tag_group_7272625659887960076"
+                    ]
+                ],
+                "outOrderNo" => $order['order_number'],
+                "totalAmount" => $order['total_amount'] * 100,
+                "orderEntrySchema" => [
+                    "path" => "page/index/index",
+                    "params" => json_encode(['order_number' => $order['order_number']])
+                ],
+                "payNotifyUrl" => config('douyin.payNotifyUrl'),
+            ];
+            $byteAuthorization = self::byteAuthorization(config('douyin.privateKeyStr'), json_encode($data), config('douyin.appId'), self::randStr(10), time(), 1);
+            return ['byteAuthorization'=>$byteAuthorization,'data'=>json_encode($data)];
+        } catch (\Exception $e) {
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+    public static function cancelOrder($params)
+    {
+        // $params['order_number']
+        Db::startTrans();
+        try {
+            $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
+            if(!$order->isEmpty()){
+                if($order->order_status == 1 && $order->pay_status == 0){
+                    $order->order_status = 4;
+                    $order->save();
+                }else{
+                    throw new \Exception('订单状态不可取消!');
+                }
+            }
+            Db::commit();
+            return $order['id'];
+        } catch (\Exception $e) {
+            Db::rollback();
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+    public static function payNotify($params)
+    {
+            Log::write(json_encode($params));
+            // 查询抖音订单是否完成支付
+            if ($params['status'] === 'SUCCESS') {
+                $transaction_id = $params['order_id']??'';
+                $paid_amount = bcdiv(bcsub($params['total_amount'] ,$params['discount_amount']), '100', 2)??0;
+                $out_order_no = $params['out_order_no'];
+                $pay_time = $params['event_time']??time();
+                $order = DouyinOrder::where('order_number', $out_order_no)->findOrEmpty();
+                if(!$order->isEmpty()){
+                    // 更新充值订单状态
+                    $order->transaction_id = $transaction_id;
+                    $order->order_status = 2;
+                    $order->pay_time = $pay_time;
+                    $order->paid_amount = $paid_amount;
+
+                    $user = User::where('id',$order->user_id)->findOrEmpty()->toArray();
+                    $form_detail = [
+                        'user_name' => $user['real_name']??'',
+                        'mobile' => $user['mobile'],
+                        'transaction_id' => $transaction_id,
+                        'out_trade_no' => $out_order_no,
+                        'paid_amount' => $paid_amount,
+                        'params' => $params,
+                    ];
+                    $consultation = ExternalConsultation::create([
+                        'external_platform_id' => self::$external_platform_id,
+                        'form_detail' => json_encode($form_detail),
+                        'user_name' => $user['real_name']??'',
+                        'mobile' => $user['mobile'],
+                        'goods_id' => $order->goods_id,
+                        'amount' => $paid_amount
+                    ]);
+                    $order->consultation_id = $consultation->id;
+                    $order->save();
+                    return true;
+                }
+            }
+            return false;
+    }
+    public static function reservation($params)
+    {
+        /*$lon_lat = get_address_lat_lng($params['user_address']);
+        $params['lon'] = $lon_lat['lon'];
+        $params['lat'] = $lon_lat['lat'];*/
+
+        // $params['order_number']
+        Db::startTrans();
+        try {
+            $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
+            if(!$order->isEmpty()){
+                $consultation = ExternalConsultation::where('id', $order->consultation_id)->findOrEmpty()->toArray();
+                $consultation['user_name'] = $params['user_name']??$consultation['user_name'];
+                $consultation['mobile'] = $params['mobile']??$consultation['mobile'];
+                $consultation['user_address'] = $params['user_address'];
+                $consultation['lon'] = $params['lon'];
+                $consultation['lat'] = $params['lat'];
+                $consultation['appointment_time'] = $params['appointment_time'];
+                $result = ExternalConsultationLogic::order($consultation);
+                if (false === $result) {
+                    throw new \Exception('预约失败');
+                }
+                $consultationOrder = ExternalConsultationOrder::where('consultation_id', $order->consultation_id)->where('goods_id', $order->goods_id)->where('amount', $order->paid_amount)
+                    ->findOrEmpty()->toArray();
+                $work_status = ServiceWork::where('id', $consultationOrder['work_id'])->value('work_status');
+                $order->work_id = $consultationOrder['work_id'];
+                $order->fulfillment_status = $work_status;
+                $order->save();
+            }
+            Db::commit();
+            return $order['id'];
+        } catch (\Exception $e) {
+            Db::rollback();
+            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','douyinRefundOrder'])->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'] = [];
+        empty($orderInfo['douyinRefundOrder']) && $orderInfo['douyinRefundOrder'] = [];
+
+        $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']
+            $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $params['order_number'])->findOrEmpty();
+            if($order->isEmpty()){
+                throw new \Exception('订单不存在');
+            }
+            $orderInfo = $order->toArray();
+            //$refund_number = $params['refund_number']??'';
+            $douyinRefundOrder = DouyinRefundOrder::where('order_number', $params['order_number'])->order('id', 'desc')->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();
+
+            if($params['is_examine_ok'] === 'pass'){
+                //通过后向抖音申请退款
+                self::sendRefundCreate($params['order_number']);
+            }
+            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());
+        }
+    }
+
+
+    public static function byteAuthorization($privateKeyStr, $data, $appId, $nonceStr, $timestamp, $keyVersion) {
+        $byteAuthorization = '';
+        // 读取私钥
+        $privateKey = openssl_pkey_get_private($privateKeyStr);
+        if (!$privateKey) {
+            throw new \Exception("Invalid private key");
+        }
+        // 生成签名
+        $signature = self::getSignature("POST", "/requestOrder", $timestamp, $nonceStr, $data, $privateKey);
+        if ($signature === false) {
+            return null;
+        }
+        // 构造 byteAuthorization
+        $byteAuthorization = sprintf("SHA256-RSA2048 appid=%s,nonce_str=%s,timestamp=%s,key_version=%s,signature=%s", $appId, $nonceStr, $timestamp, $keyVersion, $signature);
+        return $byteAuthorization;
+    }
+
+    public static function getSignature($method, $url, $timestamp, $nonce, $data, $privateKey) {
+        Log::info("method:{$method}\n url:{$url}\n timestamp:{$timestamp}\n nonce:{$nonce}\n data:{$data}");
+        $targetStr = $method. "\n" . $url. "\n" . $timestamp. "\n" . $nonce. "\n" . $data. "\n";
+        openssl_sign($targetStr, $sign, $privateKey, OPENSSL_ALGO_SHA256);
+        $sign = base64_encode($sign);
+        return $sign;
+    }
+
+    public static function randStr($length = 8) {
+        $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+        $str = '';
+        for ($i = 0; $i < $length; $i++) {
+            $str .= $chars[mt_rand(0, strlen($chars) - 1)];
+        }
+        return $str;
+    }
+    public static function getClientToken() {
+        $url = 'https://open.douyin.com/oauth/client_token/';
+        $cache_name = 'dy_client_token';
+        $cache_data = cache($cache_name);
+        if(empty($cache_data) || $cache_data == null){
+            $data = [
+                'client_key'=> config('douyin.appId'),
+                'client_secret'=> config('douyin.appSecret'),
+                'grant_type'=> "client_credential"
+            ];
+            $res = http_request($url,$data,['Content-Type' => 'application/json;charset=utf-8']);
+            if($res['message'] === 'success'){
+                cache($cache_name, json_encode($res['data']), (time()+$res['data']['expires_in']-1));
+                $cache_data = $res['data'];
+            }
+        }
+        return json_decode($cache_data, true)['access_token'];
+    }
+
+    public static function sendRefundCreate($order_number)
+    {
+        try {
+            // $params['order_number']
+            $order = DouyinOrder::with(['goods','serviceWork'])->where('order_number', $order_number)->findOrEmpty();
+            if($order->isEmpty()){
+                throw new \Exception('订单不存在');
+            }
+            $orderInfo = $order->toArray();
+            $douyinRefundOrder = DouyinRefundOrder::where('order_number', $order_number)->order('id', 'desc')->findOrEmpty();
+
+                //通过后向抖音申请退款
+                //getClientToken()
+                $url = 'https://open.douyin.com/api/trade_basic/v1/developer/refund_create/';
+                $data = [
+                    "order_id" => $orderInfo['transaction_id'],
+                    "out_refund_no" => $douyinRefundOrder->refund_number,
+                    "cp_extra" => $orderInfo['id'].'|'.$douyinRefundOrder->id,
+                    "order_entry_schema" => [
+                        "path" => "page/index/index",
+                        "params" => json_encode(['refund_number'=>$douyinRefundOrder->refund_number])
+                    ],
+                    "refund_total_amount " => $douyinRefundOrder->refund_amount * 100,
+                    //"notify_url" => "https://xxx",
+                    "refund_reason" => [
+                        [
+                            "code" => 101,
+                            "text" => "不想要了"
+                        ]
+                    ]
+                ];
+                $res = http_request($url,json_encode($data));
+                if(isset($res['err_msg']) && $res['err_msg'] === 'success'){
+                    $douyinRefundOrder->transaction_id = $res['data']['refund_id'];
+                    $douyinRefundOrder->save();
+                }
+            return true;
+        } catch (\Exception $e) {
+            Log::info($e->getMessage());
+            return false;
+        }
+    }
+
+
+}

+ 2 - 1
app/api/validate/LoginAccountValidate.php

@@ -36,7 +36,8 @@ class LoginAccountValidate extends BaseValidate
     protected $rule = [
         'terminal' => 'require|in:' . UserTerminalEnum::WECHAT_MMP . ',' . UserTerminalEnum::WECHAT_OA . ','
             . UserTerminalEnum::H5 . ',' . UserTerminalEnum::PC . ',' . UserTerminalEnum::IOS .
-            ',' . UserTerminalEnum::ANDROID,
+            ',' . UserTerminalEnum::ANDROID.
+            ',' . UserTerminalEnum::DOUYIN,
         'scene' => 'require|in:' . LoginEnum::ACCOUNT_PASSWORD . ',' . LoginEnum::MOBILE_CAPTCHA . '|checkConfig',
         'account' => 'require',
     ];

+ 3 - 0
app/common/enum/user/UserTerminalEnum.php

@@ -28,6 +28,7 @@ class UserTerminalEnum
     const PC         = 4;//电脑PC
     const IOS        = 5;//苹果app
     const ANDROID    = 6;//安卓app
+    const DOUYIN    = 7;//抖音小程序
 
 
     const ALL_TERMINAL = [
@@ -37,6 +38,7 @@ class UserTerminalEnum
         self::PC,
         self::IOS,
         self::ANDROID,
+        self::DOUYIN,
     ];
 
     /**
@@ -55,6 +57,7 @@ class UserTerminalEnum
             self::PC            => '电脑PC',
             self::IOS           => '苹果APP',
             self::ANDROID       => '安卓APP',
+            self::DOUYIN       => '抖音小程序',
         ];
         if(true === $from){
             return $desc;

+ 11 - 2
app/common/lists/BaseDataLists.php

@@ -70,6 +70,12 @@ abstract class BaseDataLists implements ListsInterface
 
         $this->params = $this->request->param();
 
+        $this->initController();
+    }
+
+
+    public function initController()
+    {
         //初始化租户
         $this->initTenant();
 
@@ -86,7 +92,6 @@ abstract class BaseDataLists implements ListsInterface
         $this->initExport();
     }
 
-
     public function initTenant()
     {
         if(!empty($this->request->adminInfo['tenant_id'])){
@@ -232,9 +237,13 @@ abstract class BaseDataLists implements ListsInterface
     public function setParams($params): self
     {
         $this->params = $params;
+        $this->initController();
         return $this;
     }
-
+    public function getParams(): array
+    {
+        return $this->params;
+    }
     public function setExcelComplexFields(): array
     {
         return [];

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

@@ -0,0 +1,40 @@
+<?php
+
+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,goods_image,service_fee,goods_category_id');
+    }
+    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');
+    }
+
+    public function douyinRefundOrder()
+    {
+        return $this->hasOne(DouyinRefundOrder::class, 'order_number', 'order_number');
+    }
+
+    public function getOrderStatusTextAttr($value,$data)
+    {
+        $status = [1=>'已下单',2=>'服务中',3=>'服务完成',4=>'服务取消'];
+        return $status[$data['order_status']??1];
+    }
+    public function getPayStatusTextAttr($value,$data)
+    {
+        $status = [0=>'待支付',1=>'已支付',2=>'已取消',3=>'已退款'];
+        return $status[$data['pay_status']??0];
+    }
+}

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

@@ -0,0 +1,18 @@
+<?php
+
+namespace app\common\model\external;
+
+use app\common\model\BaseModel;
+
+class DouyinRefundOrder extends BaseModel
+{
+    protected $name = 'douyin_refund_order';
+
+    public function getRefundStatusTextAttr($value,$data)
+    {
+        $status = [0=>'申请中',1=>'申请不通过',2=>'退款中',3=>'退款失败'];
+        return $status[$data['refund_status']??0];
+    }
+
+
+}

+ 38 - 0
config/douyin.php

@@ -0,0 +1,38 @@
+<?php
+
+return [
+    'appId' => 'tt4dc83b75d2c06f6301',
+    'appSecret' => '4a043ceb98f9c05607c6ed39cdbdcb33c6f23a75',
+    'payNotifyUrl' => env('PAY_NOTIFY_URL')?:'https://weixiudev.kyjlkj.com/api/dou_yin/payNotify',
+
+    'privateKeyStr' => "-----BEGIN RSA PRIVATE KEY-----
+MIIEpQIBAAKCAQEA3QB2NX+vsNbn1RSFd7LLI7zXkUDpVo1kFHntQ5rlPie3fEtd
+Y6/i5gNqBE0VlRG0AIgC1ApoVRa5kTmWAxByTQm6BryaIsmSEyyQ514loSpL9sJt
+5wJiuYnY6IepyZPCNdxohF7nVqx8tBIHlV9ePnctua/amNjocNd4Fv9eNFX0y5IC
+S3ZU62cBZpZXWzSdMhhvbGQzMVVx0SUtDRspU+juN/0asfT1uQ7Kko+WnI6hutgl
+abEJLje6VcOfHNWuMfyESOYlLuI4sMBqcoDYRsKLr7xjdFWUiPwHIKI4Udapcmwi
+4Y6dtbJccA/3ZF/Axowuovvel/+2500HUaopIQIDAQABAoIBAHi6HNki1H4dF+4d
+1L9Ly47NRVFTDWS7vnU1Gfi5cAuhNKnQncasOZ3/NXX+ChEx54v2wNzGhrIcxOhh
+deJcpKQS8S1m8CiaxpJ04P+TPakp6u90zQbKFdZXSEfWfFjiv9AehHXzRhriBQl1
+Y/EkdN5YyoDKYPboXynteuvNOtAJNDlFUCJGv6tOl2v+WhBRnI3wuH5BKh7wr+i7
+dmv49L5UjGG32pA9UzjoNgg7VEucYUm5CYKVWwPKYT6HsK/8pYLQh0Scp09iAZqx
+c6h5ygLsD2MsdVIc8V0b0g7y3vpC+S/DMAi9SUrW8KPvM5rVCcq32I2IsRgyTGGH
++8/VQ3UCgYEA3bI1OBJC5/jFF7xaf7EzLensvQDUQ0Qbq0fRcSESQ85lKFi7neqx
+MVQWwE60Js7Y78rPk4Wberbqg8tx5IiR2RP13PLMN7wB03aDNm2RaQEG4rpTfdtn
+39/lgk3mH2AlBBuea/ey0DzlmC4zSmLiF+5h9MeHiKcxA7MJpQ1JQrsCgYEA/zLA
+I1SaXAHtArzy11ZnFPj5tChvPBK0HBdAE2vXse9ObJDclwNuVOSRpooCbrs8HQ2v
+UjPzXXKFrJrqliJ5d0MJk+K2RQeM4+6KwaqyvI79pqle997NfRmEITk9WlfIsGyp
+D9FjBzK1KLBa1KYSj1qnAoXcC0gZf6u0coHsa9MCgYEA0CQyZxRuEJC1qtVCOkTK
+Aj9v7vtKTmUxfRwOfaJJHbQ3sSut6lOgTOnf+mlqJk1py6ikPqLgGNSHVXm60o+O
+LzrYSLsEFQfExx6rjnxMW0OFjXTWUoGeAsiZGD++4JJJ7pNnp4KFNZEXFku6CArS
+rxk2irSSgTBHimubkITq1WUCgYEA6niAnHWBFYQXdWqRXFRghZ50HpkACpvMq/qY
+vr9ZAH00+v7mDkHyv0D6qZ8nuQGCq9cE/GwK8BLmyr3TR3oJTBBl3mBww1+6jTmA
+d4wUiLaASv5W6TrmZkhpY/Upb7Y0CBTuCECD0fs/A1F1QugLKXdK90Bx+lOWSf1C
+3+qLhE0CgYEAwVIzwZ5MeDYh8myVRc/DQySvR9zJyFvEa5PzQEhVS93ATDS8kLzm
+IjjN61pxQeEWLGpsn/oA/TrGl4uEA8ARA1BtSGF9PWn94BUqESKoxBjcFtz20qXD
+lgekFOv4ZBwrOkuhpHfPGYlx3nlNBfxy15IwpGb71zfhgKXgopbfadI=
+-----END RSA PRIVATE KEY-----
+",
+
+
+];

+ 1 - 0
public/yOHzCfSDiY.txt

@@ -0,0 +1 @@
+4df18feaa91ea15703e689c6479603f0