<?php
namespace app\api\controller;

use app\adminapi\validate\property\PropertyOrderValidate;
use app\api\lists\property\PropertyCommissionLists;
use app\api\lists\property\PropertyOrderLists;
use app\api\lists\property\PropertySurplusLogLists;
use app\api\logic\PropertyCommissionLogic;
use app\api\logic\PropertyOrderLogic;
use app\api\logic\ServiceOrderLogic;
use app\api\validate\PropertyValidate;
use app\api\validate\ServiceOrderValidate;
use app\common\model\orders\RechargeOrder;
use think\facade\Log;

/**
 * 物业模块类
 */
class PropertyController extends BaseApiController
{
    public array $notNeedLogin = ['orderByQrcode'];

    /**
     * @notes 用户绑定物业信息
     * @return \think\response\Json
     */
    public function bindProperty()
    {
        $params = (new PropertyOrderValidate())->post()->goCheck('bind', [
            'householder_name'=>'',
            'householder_mobile'=>$this->userInfo['mobile']
        ]);
        Log::info('物业ID-11');
        $result = PropertyOrderLogic::bind($params);
        if (true === $result) {
            return $this->success('下单成功', [], 1, 1);
        }
        return $this->fail(PropertyOrderLogic::getError());
    }

    /**
     * @notes 二维码扫码下物业单
     * @return \think\response\Json
     */
    public function orderByQrcode()
    {
        $params = (new PropertyOrderValidate())->post()->goCheck('add');
        $result = PropertyOrderLogic::add($params);
        if (true === $result) {
            return $this->success('下单成功', [], 1, 1);
        }
        return $this->fail(PropertyOrderLogic::getError());
    }

    /**
     * 提现申请
     * @return \think\response\Json
     */
    public function withdrawCash()
    {
        $params = (new PropertyValidate())->post()->goCheck('withdrawCash', [
            'user_id' => $this->userId,
            'user_info' => $this->userInfo
        ]);
        $result = PropertyCommissionLogic::withdrawCash($params);
        if (false === $result) {
            return $this->fail(PropertyCommissionLogic::getError());
        }
        return $this->success('申请成功，等待审核', [], 1, 1);
    }
    /**
     * 物业负责人资金账户信息
     * @return \think\response\Json
     */
    public function assetAccount()
    {
        $params = [
            'user_id' => $this->userId,
            'user_info' => $this->userInfo
        ];
        return $this->success('资金账户', PropertyCommissionLogic::assetAccount($params), 1, 1);
    }
    /**
     * 下单列表
     * @return \think\response\Json
     */
    public function orderLists()
    {
        return $this->dataLists(new PropertyOrderLists());
    }

    /**
     * 进出记录列表
     * @return \think\response\Json
     */
    public function surplusLists()
    {
        return $this->dataLists(new PropertySurplusLogLists());
    }

    /**
     * 分成列表
     * @return \think\response\Json
     */
    public function commissionLists()
    {
        return $this->dataLists(new PropertyCommissionLists());
    }

    /**
     * 订单支付详情
     * @return \think\response\Json
     */
    public function commissionOrderDetail()
    {
        $params = (new ServiceOrderValidate())->goCheck('detail');
        //获取订单用户信息
        $params['user_id'] = RechargeOrder::where('sn',$params['sn'])->value('user_id');
        $result = ServiceOrderLogic::orderPayInfo($params);
        if (false === $result) {
            return $this->fail(ServiceOrderLogic::getError());
        }
        return $this->data($result);
    }


}