<?php
namespace app\index\logic;

use app\index\model\appointmentmodel;

/**
 * 登记记录表
 *
 * @author wj
 * @date 2022-07-22
 */
class appointmentlogic extends baselogic
{
    /**
     * 设置请求数据规则
     * 20220107
     * wj
     */
    protected function setrules()
    {
        $list = [
            'getuseablelist' => [
                ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
            ],
            'newinfo' => [
                ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
                ['name' => 'sfzid', 'title' => '身份证号', 'require' => true, 'type' => 'string'],
                ['name' => 'name', 'title' => '姓名', 'require' => true, 'type' => 'string'],
                ['name' => 'telno', 'title' => '手机号', 'require' => false, 'type' => 'string'],
                ['name' => 'signurl', 'title' => '签名', 'require' => true, 'type' => 'string'],
                //['name' => 'wid', 'title' => '用户id', 'require' => true, 'type' => 'numeric'],
                //['name' => 'gps_lng', 'title' => '经度', 'require' => false, 'type' => 'numeric', 'default' => ''],
                //['name' => 'gps_lat', 'title' => '纬度', 'require' => false, 'type' => 'numeric', 'default' => ''],

            ],
        ];
        return $list;
    }
    /**
     * 获取用户可用数据
     *
     * @param  [type] $arr
     * @return void
     * @author wj
     * @date 2022-07-25
     */
    public function getuseablelist($arr)
    {
        $result = $this->checkparam(__FUNCTION__, $arr);
        if (1 != $result['status']) {
            return $result;
        }
        $data = $result['data'];
        $openid = $data['openid'];
        $m_a = new appointmentmodel();
        $where = ['openid' => $openid, 'ispay' => '1', 'isuse' => 0];
        $field = ['id', 'openid', 'name', 'telno'];
        $list = $m_a->getList($where, $field, 1, 0);
        if (empty($list)) {
            return backarr(0, "无申请数据");
        }
        return backarr(1, "查询成功", $list);
    }
    /**
     * 新建用户申请数据
     *
     * @param  [type] $arr
     * @return void
     * @author wj
     * @date 2022-07-22
     */
    public function newinfo($arr)
    {
        $result = $this->checkparam(__FUNCTION__, $arr);
        if (1 != $result['status']) {
            return $result;
        }
        $data = $result['data'];
        $m_a = new appointmentmodel();
        $insertData = [
            'openid' => $data['openid'],
            'name' => $data['name'],
            'sfzid' => $data['sfzid'],
            'telno' => $data['telno'],
            'oprdate' => date('Y-m-d H:i:s'),
            'signurl' => $data['signurl'],
        ];
        $id = $m_a->insertData($insertData);
        if (empty($id)) {
            return backarr(0, "添加失败");
        }
        return backarr(1, "添加成功", ['id' => $id]);
    }
}
