| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 | <?phpnamespace app\admin\controller;use app\admin\controller\base\Permissions;use think\Db;class AppointmentApplication extends Permissions{    private function getModel()    {        return new \app\common\model\AppointmentApplication();    }    public function index()    {        if ($this->request->isAjax()) {            $post = $this->request->param();            $where = [];            if (isset($post['ids']) and !empty($post['ids'])) {                $where['id'] = ['in', $post['ids']];            }            if (!empty($post["name"])) {                $where["name"] = ['like', '%' . $post["name"] . '%'];            }            if (isset($post["sex"]) and "" != $post["sex"]) {                $where["sex"] = $post["sex"];            }            if (!empty($post["phone"])) {                $where["phone"] = ['like', '%' . $post["phone"] . '%'];            }            if (!empty($post["id_card"])) {                $where["id_card"] = ['like', '%' . $post["id_card"] . '%'];            }            if (isset($post["status"]) and "" != $post["status"]) {                $where["status"] = $post["status"];            }            if (!empty($post["remark"])) {                $where["remark"] = ['like', '%' . $post["remark"] . '%'];            }            if (isset($post["create_time"]) and !empty($post["create_time"])) {                $timerang = explode(' - ', $post["create_time"]);                $min_time = strtotime($timerang[0]);                $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');                $where["create_time"] = [['>=', $min_time], ['<=', $max_time]];            }            if (isset($post["finish_time"]) and !empty($post["finish_time"])) {                $timerang = explode(' - ', $post["finish_time"]);                $min_time = strtotime($timerang[0]);                $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');                $where["finish_time"] = [['>=', $min_time], ['<=', $max_time]];            }            $model = $this->getModel();            $count = $model->where($where)->count();            $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();            foreach ($data as $key => $value) {                $value['childs_text'] = $value->childs_text;                $value['sex_text'] = $value->sex_text;                $value['status_text'] = $value->status_text;                $value['problem_type_text'] = $value->problem_type_text;                $value['marriage_text'] = $value->marriage_text;                $value['education_level_text'] = $value->education_level_text;                $value['appointment_date'] = $value->appointment_date;                $data[$key] = $value;            }            return array('code' => 0, 'count' => $count, 'data' => $data);        } else {            return $this->fetch();        }    }    public function publish()    {        $id = $this->request->param('id', 0, 'intval');        $model = $this->getModel();        $post = $this->request->post();        if ($this->request->isPost()) {            //验证            $validate = new \think\Validate([                ['status|订单状态', 'number'],                ['remark|备注', 'max:200'],            ]);            if (!$validate->check($post)) {                $this->error('提交失败:' . $validate->getError());            }        }        if ($id > 0) {            //修改            $data = $model->where('id', $id)->find();            if (empty($data)) {                $this->error('id不正确');            }            if ($this->request->isPost()) {                if (false == $model->allowField(true)->save($post, ['id' => $id])) {                    $this->error('修改失败');                } else {                    $this->success('修改成功');                }            } else {                $this->assign('data', $data);                return $this->fetch();            }        } else {        }    }    public function status()    {        if ($this->request->isPost()) {            $post = $this->request->post();            if (false == Db::name('appointment_application')->where('id', $post['id'])->update(['status' => $post['status'], 'finish_time' => time()])) {                $this->error('设置失败');            } else {                $this->success('设置成功', 'index');            }        }    }}
 |