初始化仓库
This commit is contained in:
194
service/modules/v1/controllers/StoreController.php
Normal file
194
service/modules/v1/controllers/StoreController.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace service\modules\v1\controllers;
|
||||
|
||||
use common\core\BaseServiceController;
|
||||
use common\models\Department;
|
||||
use common\models\DoctorInfo;
|
||||
use common\models\Store;
|
||||
use common\models\StoreDoctor;
|
||||
use common\modelsgii\DoctorTitle;
|
||||
use yii\db\Exception;
|
||||
use function GuzzleHttp\Promise\all;
|
||||
|
||||
/**
|
||||
* @doc-module 门店
|
||||
*/
|
||||
class StoreController extends BaseServiceController
|
||||
{
|
||||
/**
|
||||
* @doc-name 全部门店列表
|
||||
* @doc-author hyl
|
||||
* @doc-param string keyword 搜索 / optional
|
||||
* @doc-return mixed @Store{*} 门店信息
|
||||
*/
|
||||
public function actionAllList()
|
||||
{
|
||||
$keyword = \Yii::$app->request->post('keyword');
|
||||
$query = Store::find()->where(['is_delete'=> 0])->orderBy(['id'=>SORT_DESC]);
|
||||
//搜索
|
||||
if ($keyword) {
|
||||
$query->andWhere([
|
||||
'or',
|
||||
['like', 'name', $keyword],
|
||||
['like', 'shouzimu', $keyword]
|
||||
]);
|
||||
}
|
||||
|
||||
$list = $query->all();
|
||||
if (!$list) throw new Exception('没搜到任何诊所');
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @doc-name 医生所属门店列表
|
||||
* @doc-author hyl
|
||||
* @doc-param string search 搜索 / optional
|
||||
* @doc-return mixed @Store{*} 门店信息
|
||||
*/
|
||||
public function actionStoreList()
|
||||
{
|
||||
|
||||
$post= \Yii::$app->request->post();
|
||||
$search=$post['search'];
|
||||
$su_id = DoctorInfo::find()->select('su_id')->where([
|
||||
'su_id' => \Yii::$app->user->identity->getId()
|
||||
])->column();
|
||||
$all_store = StoreDoctor::find()->select('store_id')->where([
|
||||
'su_id' => $su_id
|
||||
])->column();
|
||||
|
||||
$store = Store::find()->where(['in', 'id', $all_store])->all();
|
||||
|
||||
if (!$store) throw new Exception('您还不属于任何门店');
|
||||
$query=Store::find()->where(['in', 'id', $all_store])->orderBy(['id'=>SORT_DESC]);
|
||||
//搜索门店
|
||||
if ($search){
|
||||
$query->andWhere(['like','name',$search])->all();
|
||||
}
|
||||
|
||||
|
||||
$this->field=[
|
||||
Store::class=>[
|
||||
'id','name'
|
||||
]
|
||||
];
|
||||
return $this->create($query,$post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 医生当前门店
|
||||
* @doc-author hyl
|
||||
* @doc-param int doctor_id 医生id
|
||||
* @doc-return mixed @StoreDoctor{*,@Store{*}} 门店信息
|
||||
*/
|
||||
public function actionCurrentStore()
|
||||
{
|
||||
$post=\Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
['doctor_id','required']
|
||||
]);
|
||||
|
||||
$store=StoreDoctor::find()->where([
|
||||
'su_id'=>$post['doctor_id'],
|
||||
'is_online'=>1
|
||||
])->with('store')->asArray()->one();
|
||||
|
||||
if (!$store) throw new Exception('没有当前门店');
|
||||
|
||||
return $store;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @doc-name 职称列表
|
||||
* @doc-author hyl
|
||||
* @doc-param int type 1医生2药师
|
||||
* @doc-return mixed @DoctorTitle{*} 职称信息
|
||||
*/
|
||||
public function actionTitleList()
|
||||
{
|
||||
$get=\Yii::$app->request->get();
|
||||
$this->requestValidate($get,[
|
||||
['type','required']
|
||||
]);
|
||||
return DoctorTitle::find()->where(['type'=>$get['type']])->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 科室列表
|
||||
* @doc-author hyl
|
||||
* @doc-param int store_id 门店id
|
||||
* @doc-param string search 搜索内容 / optional
|
||||
* @doc-return mixed @Data{id-int-门店id,name-string-门店,position-string-位置,position-string-位置,contact-string-联系人,start_time-int-开始营业时间,end_time-int-结束营业时间,@Departments{name-string-科室,pid-int-父级id,level-int-level,@Child{name-string-科室,pid-int-父级id,level-int-level}}} 信息
|
||||
*/
|
||||
public function actionDepartList()
|
||||
{
|
||||
$post=\Yii::$app->request->post();
|
||||
|
||||
$this->requestValidate($post,[
|
||||
['store_id','required']
|
||||
]);
|
||||
$store_id=$post['store_id'];
|
||||
$search= $post['search'];
|
||||
|
||||
$Store=Store::find()->where(['id'=>$store_id])->one();
|
||||
|
||||
if (!$Store){
|
||||
throw new Exception('门店不存在');
|
||||
}
|
||||
|
||||
$query=Store::find()->alias('s')->where(['s.id'=>$store_id])->asArray()->one();
|
||||
$query['departments']=Department::find()->with(['child'])->asArray()->all();
|
||||
//搜索
|
||||
if ($search){
|
||||
$query=Store::find()->where(['id'=>$store_id])->with(['child'=>function($m)use($search){
|
||||
$m->andWhere(['like','name',$search]);
|
||||
}])->asArray()->one();
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 门店切换
|
||||
* @doc-param int store 要切换的门店id
|
||||
*/
|
||||
public function actionStoreChange()
|
||||
{
|
||||
$post=\Yii::$app->request->post();
|
||||
|
||||
$this->requestValidate($post,[
|
||||
['store','required']
|
||||
]);
|
||||
|
||||
$t=\Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
StoreDoctor::updateAll(['is_online'=>0],[
|
||||
'and',
|
||||
['su_id'=>\Yii::$app->user->identity->getId()],
|
||||
[ 'is_delete'=>0]
|
||||
]);
|
||||
|
||||
$StoreDoctor=StoreDoctor::find()->where([
|
||||
'su_id'=>\Yii::$app->user->identity->getId(),
|
||||
'store_id'=>$post['store'],
|
||||
'is_delete'=>0,
|
||||
])->one();
|
||||
if (!$StoreDoctor)
|
||||
{
|
||||
throw new Exception('您不属于该门店');
|
||||
}
|
||||
$StoreDoctor->store_id=$post['store'];
|
||||
$StoreDoctor->is_online=1;
|
||||
$StoreDoctor->saveOrFail();
|
||||
|
||||
$t->commit();
|
||||
return ['切换成功'];
|
||||
}catch (\Exception $exception){
|
||||
$t->rollBack();
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user