1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
-
- namespace app\admin\model;
-
- use think\Model;
-
- class Doctor extends Model
- {
-
- public function getDoctorSelect()
- {
- $result = $this->field('id as value,name as label')->select();
- return ['rows' => $result];
- }
-
- public function getAll($param, $page, $pageSize)
- {
- unset($param['page']);
- unset($param['pageSize']);
- foreach ($param as $k => $v) {
- if ($param[$k] === '' || $param[$k] === null) {
- unset($param[$k]);
- }
- }
- $where = [];
- if (isset($param['keyword'])) {
- $where[] = ['name', 'like', '%' . $param['keyword'] . '%'];
- unset($param['keyword']);
- }
- $result = $this->where($param)->where($where)->with(['getHospitalOneData', 'getDistrictOneData'])->limit($page, $pageSize)->select();
- $total = $this->where($param)->where($where)->count();
- $host = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_ADDR'] . ':' . $_SERVER['SERVER_PORT'];
- foreach ($result as $k => $v) {
- $result[$k]['demand'] = array_filter(explode(',', $v['demand']));
- $practice_license = json_decode($v['practice_license'], true);
- $poster = json_decode($v['poster'], true);
- $pictures = json_decode($v['pictures'], true);
- $practice_license = (empty($practice_license)) ? [] : $practice_license;
- $poster = (empty($poster)) ? [] : $poster;
- $pictures = (empty($pictures)) ? [] : $pictures;
- foreach ($practice_license as $kk => $vv) {
- $practice_license[$kk]['url'] = $host . $vv['url'];
- }
- foreach ($pictures as $kk => $vv) {
- $pictures[$kk]['url'] = $host . $vv['url'];
- }
- foreach ($poster as $kk => $vv) {
- $poster[$kk]['url'] = $host . $vv['url'];
- }
- $result[$k]['pictures'] = $pictures;
- $result[$k]['poster'] = $poster;
- $result[$k]['practice_license'] = $practice_license;
- }
- return ['rows' => $result, 'total' => $total];
- }
-
- public function getDistrictOneData()
- {
- return $this->hasOne(\app\admin\model\District::class, 'adcode', 'city_id')->bind(['city_name' => 'name']);
- }
-
- public function getHospitalOneData()
- {
- return $this->hasOne(\app\admin\model\Hospital::class, 'id', 'hospital_id')->bind(['hospital_name' => 'name']);
- }
-
- // public function read($param)
- // {
- // $result = $this->where($this->getPk(), $param[$this->getPk()])->find();
- // if (isset($result[$this->getPk()])) {
- // return $result->toArray();
- // } else {
- // return [];
- // }
- // }
-
- }
|