162 lines
4.7 KiB
PHP
162 lines
4.7 KiB
PHP
<?php
|
|
namespace member\models\forms;
|
|
|
|
use common\core\BaseModel;
|
|
use common\models\oldDb\PhysicalPackage;
|
|
use common\models\oldDb\PhysicalReserve;
|
|
use common\models\oldDb\PhysicalReserveTotal;
|
|
use yii\base\Exception;
|
|
use yii\data\ActiveDataProvider;
|
|
|
|
class PhysicalForm extends BaseModel
|
|
{
|
|
public $id;
|
|
public $type;
|
|
public $all;
|
|
public $yard_id;
|
|
public $physical_id;
|
|
public $day;
|
|
public $way;
|
|
public $keyword;
|
|
public $page;
|
|
public $page_size;
|
|
public $sort;
|
|
public $sort_type;
|
|
public $reserve_total = 30; #每天体检预约总数
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
[['id','type','all','yard_id','physical_id','way'], 'integer'],
|
|
[['keyword','day'], 'string'],
|
|
[['page','page_size'], 'integer'],
|
|
[['page'], 'default', 'value' => 1],
|
|
[['page_size'], 'default', 'value' => 20],
|
|
[['sort'], 'default', 'value' => 'default'],
|
|
[['sort_type'], 'default', 'value' => 'desc'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 体检套餐列表
|
|
* @throws Exception
|
|
*/
|
|
public function getPhysicalPackageList(): array
|
|
{
|
|
if (!$this->validate()) {
|
|
throw new Exception($this->getErrorMsg($this));
|
|
}
|
|
$package_query = PhysicalPackage::find();
|
|
|
|
//综合排序
|
|
if($this->all){
|
|
$package_query->orderBy([
|
|
'id'=>SORT_ASC
|
|
]);
|
|
}
|
|
|
|
//按照套餐类型排序
|
|
if($this->type){
|
|
$package_query->orderBy([
|
|
'type'=>SORT_ASC
|
|
]);
|
|
}
|
|
|
|
$field = [
|
|
PhysicalPackage::class => [
|
|
'id','name','image','price','intro','content','service','type'
|
|
]
|
|
];
|
|
|
|
$pagination['page'] = (int)$this->page;
|
|
$data = new ActiveDataProvider([
|
|
'query'=>$package_query->asArray(),
|
|
'pagination'=>[
|
|
'defaultPageSize'=>(int)$this->page_size,
|
|
'params'=>$pagination
|
|
]
|
|
]);
|
|
return [
|
|
'data' => $data,
|
|
'field' => $field
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 体检套餐详情
|
|
* @return array
|
|
*/
|
|
public function getPhysicalPackage(): array
|
|
{
|
|
// 套餐详情
|
|
$data['package'] = PhysicalPackage::find()->with(['yardPhysical' => function($query) {
|
|
if(isset($this->yard_id)){
|
|
$query->where(['yard_id'=>$this->yard_id]);
|
|
}
|
|
$query->select('yard_id,physical_id')->with('yard');
|
|
}])->where([
|
|
'id' => $this->id
|
|
])->asArray()->one();
|
|
|
|
// 预约时间 近一月
|
|
$reserve_done = [];//已预约数
|
|
$reserve = PhysicalReserveTotal::find()->where(['>=','day',date('Y-m-d')])->all();
|
|
foreach($reserve as $item){
|
|
$reserve_done[$item->day] = $item->num;
|
|
}
|
|
|
|
$reserve_date = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];
|
|
foreach($reserve_date as $day){
|
|
$date = date('Y-m-d',strtotime('+'.$day.' day'));
|
|
if(isset($reserve_done[$date])){
|
|
//如果有预约是日期 做减法
|
|
$data['reserve'][$date] = $this->reserve_total - $reserve_done[$date];
|
|
}else{
|
|
$data['reserve'][$date] = $this->reserve_total;
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 体检套餐预约
|
|
* @return array
|
|
*/
|
|
public function setPhysicalReserve(): array
|
|
{
|
|
$user_reserve = PhysicalReserve::findone([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
'yard_id' => $this->yard_id,
|
|
'physical_id' => $this->physical_id,
|
|
'day' => $this->day
|
|
]);
|
|
|
|
if(isset($user_reserve) && $user_reserve->status !=2){//已经预约,不可以重复预约
|
|
return ['success' => 0, 'msg'=>'您已经预约过,请误重复预约'];
|
|
}else{
|
|
$user_reserve = new PhysicalReserve();
|
|
$user_reserve->user_id = \Yii::$app->user->id;
|
|
$user_reserve->yard_id = $this->yard_id;
|
|
$user_reserve->physical_id = $this->physical_id;
|
|
$user_reserve->day = $this->day;
|
|
$user_reserve->status = 0;
|
|
$user_reserve->way = isset($this->way) ? $this->way : 0;
|
|
$res = $user_reserve->save();
|
|
}
|
|
|
|
return ['success' => $res, 'msg'=>'您预约成功,请尽快支付'];
|
|
}
|
|
|
|
/**
|
|
* 挂号详情
|
|
* @return array
|
|
*/
|
|
public function getReserveDetail(): array
|
|
{
|
|
return PhysicalReserve::find()->with(['yard','user','package'])->where([
|
|
'id' => $this->id
|
|
])->asArray()->one();
|
|
}
|
|
}
|