223 lines
8.4 KiB
PHP
223 lines
8.4 KiB
PHP
<?php
|
||
|
||
namespace admin\controllers\base;
|
||
|
||
use admin\components\BaseAdminController;
|
||
use admin\models\forms\drug\DepartForm;
|
||
use common\enums\UserRoleEnum;
|
||
use common\helpers\ArrayHelper;
|
||
use common\models\oldDb\Department;
|
||
use common\models\oldDb\Platform;
|
||
use common\models\oldDb\Store;
|
||
|
||
/**
|
||
* @doc-module 科室与门店
|
||
*/
|
||
class DepartController extends BaseAdminController
|
||
{
|
||
/**
|
||
* @doc-name 科室列表(处理成二维数组)
|
||
* @doc-param int name 科室名字 / optional
|
||
* @doc-return mixed @List{id,name-string-名字,pid-int-父级id,level-int-等级,child_depart-string-子级科室} 科室信息
|
||
*/
|
||
public function actionDeptList()
|
||
{
|
||
$get = \Yii::$app->request->get();
|
||
$query = Department::find();
|
||
if (!empty($get['name'])) {
|
||
$query->andWhere([
|
||
'like', 'name', $get['name']
|
||
]);
|
||
}
|
||
|
||
$this->field = [
|
||
Department::class => [
|
||
'id', 'name', 'pid', 'level',
|
||
'child_depart' => 'child'
|
||
]
|
||
];
|
||
return $this->create($query, $get);
|
||
}
|
||
|
||
/**
|
||
* @doc-name 科室列表
|
||
* @doc-param int name 科室名字 / optional
|
||
* @doc-return mixed @List{id,name-string-名字,pid-int-父级id,level-int-等级} 科室信息
|
||
*/
|
||
public function actionList()
|
||
{
|
||
$get = \Yii::$app->request->get();
|
||
$query = Department::find();
|
||
if (!empty($get['name'])) {
|
||
$query->andWhere([
|
||
'like', 'name', $get['name']
|
||
]);
|
||
}
|
||
|
||
return $query->select(['id', 'name', 'level'])->all();
|
||
}
|
||
|
||
/**
|
||
* @doc-name 新增科室
|
||
* @doc-param string name 科室
|
||
* @doc-param int level 科室级别
|
||
* @doc-param int pid 父级id / optional
|
||
* @doc-param string is_recommend 是否推荐 / optional
|
||
* @doc-param int feature 是否是重点特色专科0不是1是 / optional
|
||
*/
|
||
public function actionSaveDept()
|
||
{
|
||
$post = \Yii::$app->request->post();
|
||
$DepartForm = new DepartForm();
|
||
$DepartForm->attributes = $post;
|
||
return $DepartForm->SaveDepart();
|
||
}
|
||
|
||
/**
|
||
* @doc-name 门店列表
|
||
* @doc-param int name 名字 / optional
|
||
* @doc-param string region 省 / optional
|
||
* @doc-param string city 市 / optional
|
||
* @doc-param int limit 每页条数 / optional
|
||
* @doc-return mixed @List{id,name-string-名字,drugstore_id-int-仓库id,drugstore-string-仓库,plate_id-int-平台id,position-string-位置,pic-string-图片,contact-string-联系人,mobile-string-联系电话,qr_code-string-门店二维码,start_time-string-开始营业时间,end_time-string-结束营业时间,see_rate-int-是否查看毛利率0否1是} 门店信息
|
||
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
||
*/
|
||
public function actionStoreList()
|
||
{
|
||
$get = \Yii::$app->request->get();
|
||
$query = Store::find()->alias('s');
|
||
$name = \Yii::$app->request->get('name');
|
||
$region = \Yii::$app->request->get('region');
|
||
$city = \Yii::$app->request->get('city');
|
||
$admin = \Yii::$app->user->identity;
|
||
|
||
if ($admin->role==UserRoleEnum::STORE_ADMIN){
|
||
$query->andWhere(['s.id'=>$admin->store_id])->orderBy(['s.id'=>SORT_DESC]);
|
||
}elseif ($admin->role==UserRoleEnum::PROVINCE_DAI){
|
||
$query->andWhere(['s.province_id'=>$admin->province_id])->orderBy(['s.id'=>SORT_DESC]);
|
||
}elseif ($admin->role==UserRoleEnum::CITY_DAI){
|
||
$query->andWhere(['s.city_id'=>$admin->city_id])->orderBy(['s.id'=>SORT_DESC]);
|
||
}elseif ($admin->role==UserRoleEnum::SUPPLY){
|
||
$query->andWhere(['s.code'=>$admin->code])->orderBy(['s.id'=>SORT_DESC]);
|
||
}else{
|
||
$query->orderBy(['s.id'=>SORT_DESC]);
|
||
}
|
||
if (!empty($name) ) {
|
||
$query->andWhere([
|
||
'or',
|
||
['like', 's.name', $name],
|
||
['like', 's.shouzimu', $name],
|
||
]);
|
||
}
|
||
if ( !empty($region)) {
|
||
$query->joinWith(['province'=>function($p)use($region){
|
||
$p->alias('p');
|
||
$p->where(['like','p.name',$region]);
|
||
}]);
|
||
}
|
||
if ( !empty($city)) {
|
||
$query->joinWith(['city'=>function($p)use($city){
|
||
$p->alias('c');
|
||
$p->where(['like','c.name',$city]);
|
||
}]);
|
||
}
|
||
if (empty(\Yii::$app->request->get('page'))) {
|
||
$this->field = [
|
||
Store::class => [
|
||
'id', 'name'
|
||
]
|
||
];
|
||
} else {
|
||
$this->field = [
|
||
Store::class => [
|
||
'id', 'plate_id', 'name', 'position', 'offical_seal', 'pic', 'contact', 'mobile', 'qr_code',
|
||
'start_time', 'end_time',
|
||
'drugstore_id', 'see_rate',
|
||
'drugstore' => 'drugStore.name',
|
||
'code','uid','supply'=>'admin.username',
|
||
'province'=>'province.name',
|
||
'city'=>'city.name',
|
||
'province_id',
|
||
'city_id','erp_id'
|
||
]
|
||
];
|
||
}
|
||
return $this->create($query, $get);
|
||
}
|
||
|
||
|
||
/**
|
||
* @doc-name 新增或编辑门店
|
||
* @doc-desc 传id则修改
|
||
* @doc-param int id 门店id / optional
|
||
* @doc-param int plate_id 平台ID
|
||
* @doc-param int erp_id erp_id / optional
|
||
* @doc-param int drugstore_id 仓库ID
|
||
* @doc-param string name 名字
|
||
* @doc-param string contact 联系人
|
||
* @doc-param string position 位置
|
||
* @doc-param string mobile 电话
|
||
* @doc-param int province_id 省
|
||
* @doc-param int city_id 市
|
||
* @doc-param string code 推广码
|
||
* @doc-param string offical_seal 公章
|
||
* @doc-param string start_time 开始营业时间
|
||
* @doc-param string end_time 结束营业时间
|
||
* @doc-param string pic 图片 / optional
|
||
* @doc-param string bank_user_name 开户人姓名 / optional
|
||
* @doc-param string bank_card 银行卡号 / optional
|
||
* @doc-param string bank_name 开户行 / optional
|
||
* @doc-param int bank_account_type 银行账户类型 1:对公,2:对私,5:存折 / optional
|
||
* @doc-param string bank_no 银行联行号bank_account_type=1或5或非62开头的对私银行账户时必选 / optional
|
||
*/
|
||
public function actionSaveStore()
|
||
{
|
||
$post = \Yii::$app->request->post();
|
||
$this->requestValidate($post, [
|
||
['code','required','message'=>'推广码不能为空'],
|
||
['plate_id','required','message'=>'平台ID不能为空'],
|
||
['drugstore_id','required','message'=>'仓库ID不能为空'],
|
||
['name','required','message'=>'名字不能为空'],
|
||
['contact','required','message'=>'联系人不能为空'],
|
||
['position','required','message'=>'联系人不能为空'],
|
||
['mobile','required','message'=>'电话不能为空'],
|
||
// ['offical_seal','required','message'=>'公章不能为空'],
|
||
['start_time','required','message'=>'开始营业时间不能为空'],
|
||
['end_time','required','message'=>'结束营业时间不能为空'],
|
||
['province_id','required','message'=>'省份不能为空'],
|
||
['city_id','required','message'=>'城市不能为空'],
|
||
]);
|
||
|
||
$post['store_name'] = $post['name'];
|
||
$post['shouzimu']=ArrayHelper::shouzimu($post['name']);
|
||
|
||
$DepartForm = new DepartForm();
|
||
$DepartForm->attributes = $post;
|
||
return $DepartForm->SaveStore();
|
||
}
|
||
|
||
/**
|
||
* @doc-name 平台列表
|
||
* @doc-param int name 名字 / optional
|
||
* @doc-return mixed @List{id,name-string-平台名称,token-string-平台密钥(后期使用),url-string-通讯地址,callbackurl-string-位置,status-int-1使用0不使用} 平台信息
|
||
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
||
*/
|
||
public function actionPlatformList()
|
||
{
|
||
$get = \Yii::$app->request->get();
|
||
$query = Platform::find();
|
||
|
||
if (!empty($get['name'])) {
|
||
$query->andWhere([
|
||
'like', 'name', $get['name']
|
||
]);
|
||
}
|
||
|
||
$this->field = [
|
||
Platform::class => [
|
||
'id', 'name', 'token', 'callbackurl', 'url', 'status'
|
||
]
|
||
];
|
||
return $this->create($query, $get);
|
||
}
|
||
} |