<?php

namespace app\admin\controller\users;

use app\admin\controller\AdminBase;
use app\model\project\Business as BusinessModel;
use think\App;

class Business extends AdminBase
{
    protected $business;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->business = new BusinessModel();
    }

    //会员列表
    public function index(string $do = '')
    {
        $limit = 10;
        if ($do == 'json') {

            $post = input();
            $post['limit'] = isset($post['limit']) ? $post['limit'] : $limit;
            $hasmap[] = ['is_del', '=', 0];
            $map = [];
            if (isset($post['kw']) && !empty($post['kw'])) {
                $hasmap[] = ['username|mobile', 'like', '%' . $post['kw'] . '%'];
            }
            if (isset($post['business']) && !empty($post['business'])) {
                $map[] = ['name', 'like', '%' . $post['business'] . '%'];
            }
            if (isset($post['status']) && $post['status'] > -1) {
                $map[] = ['business.status', '=', $post['status']];
            }

            $list = $this->business->hasWhere('getuserdata', $hasmap)->where($map)->with(['getuserdata'])->append(['addressxx', 'status_text'])->paginate($post['limit']);
            return $this->returnMsg($list);
        }

        $this->assign('limit', $limit);
        $this->assign('get', input());
        return $this->fetch('', '', false);
    }

    //快速编辑
    public function editup()
    {
        $post = input();
        $result = $this->business->update([$post['af'] => $post['av']], [['id', '=', $post['id']]]);
        if ($result) {
            return $this->returnMsg('修改成功', 1);
        } else {
            return $this->returnMsg('修改失败');
        }
    }

    //详情
    public function detail()
    {
        $post = input();
        $info = $this->business->with(['businessQualification', 'businessIndustry', 'businessPorject', 'businessMore', 'businessLogo'])->where('id', $post['id'])->find();

        $this->assign('info', $info);

        return $this->fetch('', '', false);
    }


    public function del()
    {
        $post = input();
        $ids = is_array($post['id']) ? implode(',', $post['id']) : $post['id'];
        if ($this->business->where("id IN(" . $ids . ")")->update(['is_del' => 1])) {
            return $this->returnMsg("删除成功", 1);
        } else {
            return $this->returnMsg("删除失败");
        }
    }

    //审核资料
    public function shenhebusiness()
    {
        $post = input();
        $errordesc = '';
        $shstatus = 1;
        if ($post['shstatus'] == 2) {
            if (empty($post['errordesc'])) {
                return $this->returnMsg("请输入失败原因");
            }
            $errordesc = $post['errordesc'];
            $shstatus = 2;
        }

        $updatedata['status'] = $shstatus;
        $updatedata['process_time'] = time();
        $updatedata['status_desc'] = $errordesc;

        $result = $this->business->where('id', $post['id'])->update($updatedata);
        if ($result) {

            return $this->returnMsg("操作成功", 1);
        } else {
            return $this->returnMsg("操作失败");
        }

    }


}