<?php




namespace app\controller\admin\system\merchant;

use app\common\repositories\system\CacheRepository;
use think\App;
use ln\basic\BaseController;
use app\common\repositories\system\merchant\MerchantApplymentsRepository;

class MerchantApplyments extends BaseController
{
    protected $repository;

    /**
     * MerchantApplyments constructor.
     * @param App $app
     * @param MerchantApplymentsRepository $repository
     */
    public function __construct(App $app, MerchantApplymentsRepository $repository)
    {
        parent::__construct($app);
        $this->repository = $repository;
    }

    public function lst()
    {
        [$page, $limit] = $this->getPage();
        $where = $this->request->params(['mer_name','status','date','mer_applyments_id','out_request_no','applyment_id','mer_id']);
        return app('json')->success($this->repository->getList($where, $page, $limit));
    }

    public function detail($id)
    {
        $data = $this->repository->detail($id);
        if(empty($data)) return app('json')->fail('数据不存在');
        return app('json')->success($data);
    }

    public function switchWithStatus($id)
    {
        $data = $this->request->params(['status','message']);

        if(!in_array($data['status'],[0,-1,10])) return app('json')->fail('参数错误');
        if($data['status'] == -1 && !$data['message'] )  return app('json')->fail('驳回理由为空');
        $this->repository->switchWithStatus($id,$data);
        return app('json')->success('审核成功');
    }

    public function getMerchant($id)
    {
        $data = $this->repository->getMerchant($id);
        return app('json')->success($data);
    }

    public function markForm($id)
    {
        return app('json')->success(formToData($this->repository->markForm($id)));
    }

    public function mark($id)
    {
        if(!$this->repository->get($id))
            return app('json')->fail('数据不存在');
        $this->repository->update($id,['mark' => $this->request->param('mark','')]);

        return app('json')->success('备注成功');
    }

}
