wang jun 2 年之前
父節點
當前提交
7054cb865c

+ 35 - 0
application/app/controller/Appointment.php

@@ -0,0 +1,35 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 10:57:14
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-19 10:38:56
+ * 微信类
+ */
+namespace app\app\controller;
+
+use app\app\logic\appointmentlogic;
+use think\Controller;
+
+class Appointment extends BaseController
+{
+    /**
+     * 根据id获取信息
+     *
+     * @return void
+     * @author wj
+     * @date 2022-07-25
+     */
+    public function getinfobyid()
+    {
+        $param = request()->param();
+        $this->checktoken($param);
+        $l_a = new appointmentlogic();
+        $result = $l_a->getinfobyid($param);
+        if (!$result['status']) {
+            return backjson2(0, $result['msg']);
+        }
+        return backjson2(1, 'success', $result['data']);
+    }
+
+}

+ 36 - 0
application/app/controller/BaseController.php

@@ -0,0 +1,36 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 10:57:14
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-19 10:38:56
+ * 微信类
+ */
+namespace app\app\controller;
+
+use app\app\logic\webuserlogic;
+use think\Controller;
+
+class BaseController extends Controller
+{
+    /**
+     * 校验用户token
+     *
+     * @param  [type] $token
+     * @return void
+     * @author wj
+     * @date 2022-07-25
+     */
+    public function checktoken($param)
+    {
+        if (!isset($param['token']) || empty($param['token'])) {
+            $this->error("请求错误");
+        }
+        $token = $param['token'];
+        $l_w = new webuserlogic();
+        $result = $l_w->checktoken($token);
+        if (!$result) {
+            $this->error("非合法用户");
+        }
+    }
+}

+ 52 - 0
application/app/controller/Webuser.php

@@ -0,0 +1,52 @@
+<?php
+/*
+ * @Author: wang jun
+ * @Date: 2022-01-18 10:57:14
+ * @Last Modified by: wang jun
+ * @Last Modified time: 2022-01-19 10:38:56
+ * 微信类
+ */
+namespace app\app\controller;
+
+use app\app\logic\webuserlogic;
+use think\Controller;
+
+class Webuser extends BaseController
+{
+    /**
+     * 管理员登陆
+     *
+     * @return void
+     * @author wj
+     * @date 2022-07-25
+     */
+    public function login()
+    {
+        $param = request()->param();
+        $l_w = new webuserlogic();
+        $result = $l_w->login($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, 'success', $result['data']);
+        }
+    }
+    /**
+     * 发送短信
+     *
+     * @return void
+     * @author wj
+     * @date 2022-07-25
+     */
+    public function sendsms()
+    {
+        $param = request()->param();
+        $l_w = new webuserlogic();
+        $result = $l_w->sendsms($param);
+        if (1 != $result['status']) {
+            return backjson2(0, $result['msg']);
+        } else {
+            return backjson2(200, 'success', $result['data']);
+        }
+    }
+}

+ 16 - 16
application/app/logic/appointmentlogic.php

@@ -19,21 +19,9 @@ class appointmentlogic extends baselogic
     protected function setrules()
     {
         $list = [
-            'getlastinfo' => [
-                ['name' => 'code', 'title' => '申请编码', 'require' => true, 'type' => 'string'],
+            'getinfobyid' => [
+                ['name' => 'id', 'title' => '申请id', 'require' => true, 'type' => 'numeric'],
             ],
-            /*'saveinfo' => [
-        ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
-        ['name' => 'union_id', 'title' => 'union_id', 'require' => false, 'type' => 'string'],
-        ['name' => 'nick_name', 'title' => '昵称', 'require' => true, 'type' => 'string'],
-        ['name' => 'avatar_url', 'title' => '头像', 'require' => false, 'type' => 'string'],
-        ['name' => 'gender', 'title' => '性别', 'require' => false, 'type' => 'string'],
-        ['name' => 'province', 'title' => '省', 'require' => false, 'type' => 'string'],
-        ['name' => 'city', 'title' => '市', 'require' => false, 'type' => 'string'],
-        ['name' => 'country', 'title' => '县', 'require' => false, 'type' => 'string'],
-        ['name' => 'tel', 'title' => '手机号', 'require' => false, 'type' => 'string'],
-        ['name' => 'address', 'title' => '地址', 'require' => false, 'type' => 'string'],
-        ],*/
         ];
         return $list;
     }
@@ -45,13 +33,25 @@ class appointmentlogic extends baselogic
      * @author wj
      * @date 2022-07-22
      */
-    public function getlastinfo($arr)
+    public function getinfobyid($arr)
     {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
         $m_a = new appointmentmodel();
-        $info = $m_a->getlastinfo($arr);
+        $where = ['id' => $arr['id']];
+        $field = ['name', 'sfzid', 'telno', 'signurl', 'oprdate', 'ispay', 'isuse', 'payorderno'];
+        $info = $m_a->getInfo($where, $field);
         if (empty($info)) {
             return backarr(0, "无申请数据");
         }
+        if (!$info['ispay']) {
+            return backarr(0, "未支付");
+        }
+        if ($info['isuse']) {
+            return backarr(0, "已使用");
+        }
         return backarr(1, "查询成功", $info);
     }
 }

+ 1 - 1
application/app/logic/baselogic.php

@@ -38,7 +38,7 @@ class baselogic
                     $title = $value['title'];
                     //必填
                     if (isset($value['require']) && $value['require']) {
-                        if (!isset($param[$name])) {
+                        if (!isset($param[$name]) || empty($param[$name])) {
                             throw new \Exception($title . '未填');
                         }
                     }

+ 123 - 0
application/app/logic/webuserlogic.php

@@ -0,0 +1,123 @@
+<?php
+namespace app\app\logic;
+
+use app\app\model\smscoderecordmodel;
+use app\app\model\webusermodel;
+
+/**
+ * 登记记录表
+ *
+ * @author wj
+ * @date 2022-07-22
+ */
+class webuserlogic extends baselogic
+{
+    /**
+     * 设置请求数据规则
+     * 20220107
+     * wj
+     */
+    protected function setrules()
+    {
+        $list = [
+            'login' => [
+                ['name' => 'telno', 'title' => '手机号', 'require' => true, 'type' => 'numeric'],
+                ['name' => 'code', 'title' => '验证码', 'require' => true, 'type' => 'numeric'],
+            ],
+            'sendsms' => [
+                ['name' => 'telno', 'title' => '手机号', 'require' => true, 'type' => 'numeric'],
+            ],
+        ];
+        return $list;
+    }
+
+    //后台或数据库直接添加数据
+    public function login($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $data = $result['data'];
+        $telno = $data['telno'];
+        $code = $data['code'];
+        //验证用户
+        $m_w = new webusermodel();
+        $winfo = $m_w->getinfobytelno($telno);
+        if (empty($winfo)) {
+            return backarr(0, "无用户数据");
+        }
+        $wid = $winfo['id'];
+        //验证code
+        $m_s = new smscoderecordmodel();
+        $result = $m_s->checkcode($telno, $code);
+        if (!$result['status']) {
+            return $result;
+        }
+        $row = $m_w->settoken($wid, $telno);
+        if (empty($row)) {
+            return backarr(0, "用户token修改失败");
+        }
+        $winfo = $m_w->getinfobyid($wid, ['token']);
+        return backarr(1, "用户登录成功", $winfo);
+    }
+    /**
+     * 校验token
+     *
+     * @param  [type] $token
+     * @return void
+     * @author wj
+     * @date 2022-07-25
+     */
+    public function checktoken($token)
+    {
+        $m_w = new webusermodel();
+        $info = $m_w->getinfobytoken($token);
+        return $info ? true : false;
+    }
+    /**
+     * 发送短信
+     *
+     * @return void
+     * @author wj
+     * @date 2022-07-25
+     */
+    public function sendsms($arr)
+    {
+        $result = $this->checkparam(__FUNCTION__, $arr);
+        if (1 != $result['status']) {
+            return $result;
+        }
+        $data = $result['data'];
+        $telno = $data['telno'];
+        if (!isMoblid($telno)) {
+            return backarr(0, "手机号格式错误");
+        }
+        //查未使用的验证码
+        $m_s = new smscoderecordmodel();
+        $where = ['telno' => $telno];
+        $list = $m_s->getList($where, 'smscode', 1, 0)->toArray();
+        if (empty($list)) {
+            //发送短信
+            //$code = randomStr();
+            $code = "8888";
+            $smsData = [
+                'telno' => $telno,
+                'smscode' => $code,
+            ];
+            $row = $m_s->insertData($smsData);
+            if (empty($row)) {
+                return backarr(0, "验证码添加失败");
+            }
+        } else {
+            $code = $list[0]['smscode'];
+        }
+        //发送验证码
+        $sendresult = true;
+        if (!$sendresult) {
+            return backarr(0, "验证码发送失败");
+        }
+        return backarr(1, "验证码发送成功");
+    }
+
+}

+ 3 - 1
application/app/model/appointmentmodel.php

@@ -1,5 +1,5 @@
 <?php
-namespace app\index\model;
+namespace app\app\model;
 
 use think\Model;
 
@@ -11,6 +11,8 @@ use think\Model;
  */
 class appointmentmodel extends Model
 {
+    protected $table = "t_appointment";
+
     public function insertData($data)
     {
         if (!isset($data['oprdate']) || empty($data['oprdate']) || !is_string($data['oprdate'])) {

+ 117 - 0
application/app/model/smscoderecordmodel.php

@@ -0,0 +1,117 @@
+<?php
+namespace app\app\model;
+
+use think\Model;
+
+/**
+ * 短信表
+ *
+ * @author wj
+ * @date 2022-07-25
+ */
+class smscoderecordmodel extends Model
+{
+    protected $table = "t_smscoderecord";
+    public function insertData($data)
+    {
+        if (!isset($data['create_date']) || empty($data['create_date']) || !is_string($data['create_date'])) {
+            $data['create_date'] = date("Y-m-d H:i:s");
+        }
+        if (isset($data['id'])) {
+            unset($data['id']);
+        }
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+
+    /**
+     * 校验入库数据
+     * 20220119
+     */
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+
+    public function deleteinfo($where)
+    {
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj = $sqlObj->count();
+        }
+        return $data;
+    }
+    /**
+     * 校验验证码
+     *
+     * @param  [type] $telno
+     * @param  [type] $code
+     * @return void
+     * @author wj
+     * @date 2022-07-25
+     */
+    public function checkcode($telno, $code)
+    {
+        $where = ['telno' => $telno];
+        $field = ['smscode', 'id'];
+        $id = 0;
+        $list = $this->where($where)->field($field)->select()->toArray();
+        if (empty($list)) {
+            return backarr(0, "无对应验证码");
+        }
+        foreach ($list as $key => $value) {
+            if ($code == $value['smscode']) {
+                $id = $value['id'];
+                break;
+            }
+        }
+        if (empty($id)) {
+            return backarr(0, "验证码错误");
+        }
+        $row = $this->where($where)->delete();
+        if (empty($row)) {
+            return backarr(0, "验证码删除失败");
+        }
+        return backarr(1, "校验成功");
+    }
+}

+ 84 - 0
application/app/model/tubemodel.php

@@ -0,0 +1,84 @@
+<?php
+namespace app\app\model;
+
+use think\Model;
+
+/**
+ * 管理员用户
+ *
+ * @author wj
+ * @date 2022-07-25
+ */
+class tubemodel extends Model
+{
+    protected $table = "t_tube";
+    public function insertData($data)
+    {
+        if (!isset($data['oprtime']) || empty($data['oprtime']) || !is_string($data['oprtime'])) {
+            $data['oprtime'] = date("Y-m-d H:i:s");
+        }
+        if (isset($data['id'])) {
+            unset($data['id']);
+        }
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+
+    /**
+     * 校验入库数据
+     * 20220119
+     */
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+
+    public function deleteinfo($where)
+    {
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj = $sqlObj->count();
+        }
+        return $data;
+    }
+}

+ 135 - 0
application/app/model/webusermodel.php

@@ -0,0 +1,135 @@
+<?php
+namespace app\app\model;
+
+use think\Model;
+
+/**
+ * 管理员用户
+ *
+ * @author wj
+ * @date 2022-07-25
+ */
+class webusermodel extends Model
+{
+    protected $table = "t_webuser";
+    public function insertData($data)
+    {
+        if (!isset($data['oprdate']) || empty($data['oprdate']) || !is_string($data['oprdate'])) {
+            $data['oprdate'] = date("Y-m-d H:i:s");
+        }
+        if (isset($data['id'])) {
+            unset($data['id']);
+        }
+        $data = $this->formatData($data);
+        if (empty($data)) {
+            return false;
+        }
+        $id = $this->insertGetId($data);
+        return $id ? $id : false;
+    }
+
+    /**
+     * 校验入库数据
+     * 20220119
+     */
+    private function formatData($data)
+    {
+        $useData = [];
+        $fields = $this->getTableFields();
+        foreach ($data as $key => $value) {
+            if (in_array($key, $fields)) {
+                $useData[$key] = $value;
+            }
+        }
+        return $useData;
+    }
+    public function getInfo($where, $field = "*", $row = true)
+    {
+        $info = $this->field($field)->where($where);
+        if ($row) {
+            $info = $info->find();
+        } else {
+            $info = $info->select();
+        }
+        return empty($info) ? false : $info;
+    }
+
+    public function updateinfo($where, $updateData)
+    {
+        $row = $this->where($where)->update($updateData);
+        return empty($row) ? false : $row;
+    }
+
+    public function deleteinfo($where)
+    {
+        $row = $this->where($where)->delete();
+        return empty($row) ? false : $row;
+    }
+
+    public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
+    {
+        $sqlObj = $this->where($where);
+        if ("count" != $field) {
+            $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
+            if ($row) {
+                $data = $sqlObj->find();
+            } else {
+                $data = $sqlObj->select();
+            }
+        } else {
+            $data = $sqlObj = $sqlObj->count();
+        }
+        return $data;
+    }
+
+    /**
+     * 根据id获取信息
+     * wj
+     * 20220118
+     */
+    public function getinfobyid($id, $field = "*")
+    {
+        $where = ['id' => $id];
+        $info = $this->where($where)->field($field)->find();
+        return $info;
+    }
+    /**
+     * 根据telno获取信息
+     * wj
+     * 20220118
+     */
+    public function getinfobytelno($telno)
+    {
+        $where = ['telno' => $telno, 'type' => 0];
+        $info = $this->where($where)->find();
+        return $info ? $info : false;
+    }
+    /**
+     * 根据telno获取信息
+     * wj
+     * 20220118
+     */
+    public function getinfobytoken($token)
+    {
+        $where = ['token' => $token];
+        $info = $this->where($where)->find();
+        return $info ? $info : false;
+    }
+    /**
+     * 重置用户token
+     *
+     * @param  [type] $wid
+     * @param  [type] $telno
+     * @return void
+     * @author wj
+     * @date 2022-07-25
+     */
+    public function settoken($wid, $telno)
+    {
+        $token = md5(md5($telno) . time());
+        $where = ['id' => $wid];
+        $updateData = ['token' => $token];
+        $row = $this->where($where)->update($updateData);
+        return $row ? $row : false;
+    }
+}

+ 27 - 0
application/common.php

@@ -231,3 +231,30 @@ function getselfurl($name = null)
     }
     return isset($urllist[$name]) ? $urllist[$name] : $urllist[$defaultname];
 }
+/**
+ * 随机验证码
+ *
+ * @param  integer $type
+ * @param  integer $len
+ * @return void
+ * @author wj
+ * @date 2022-07-25
+ */
+function randomStr($type = 1, $len = 6)
+{
+    $number = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
+    $strArray = [];
+    switch ($type) {
+        case 1:
+            $strArray = $number;
+            break;
+    }
+    $len = $len <= 0 ? 6 : $len;
+    $len = $len > 10 ? 6 : $len;
+    $str = '';
+    for ($i = 0; $i < $len; $i++) {
+        $num = $strArray[mt_rand(0, count($strArray) - 1)];
+        $str .= $num;
+    }
+    return $str;
+}