<?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\platform_api;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\validate\works\ServiceWorkValidate;
use app\common\logic\ThirdOrderLogic;
use app\common\model\third\ThirdOrders;


/**
 * MeiTuanApiController
 * Class MeiTuanApiController
 * @package app\adminapi\controller\platform_api
 */
class MeiTuanApiController extends BaseAdminController
{

    /**
     * @notes 获取详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/01/17 13:50
     */
    public function bookresult()
    {
        $params = (new ServiceWorkValidate())->goCheck('detail');
        $order = ThirdOrders::where('work_id',$params['id'])->order('create_time desc')->findOrEmpty();
        if($order->isEmpty()){
            return $this->fail('美团订单不存在');
        }
        if($order['bookStatus']!=1){
            return $this->fail('订单状态异常，无法接单');
        }
        $result = ThirdOrderLogic::bookresultcallback(json_decode($order['request_msg'],true)['opBizCode'],$order['orderId'],2);
        if(!empty($result['code']) && $result['code']==200){
            $order->bookStatus = 2;
            $order->save();
            return $this->success('接单成功');
        }else{
            return $this->fail($result['msg']);
        }
    }


}