194 lines
7.5 KiB
PHP
194 lines
7.5 KiB
PHP
<?php
|
||
|
||
namespace admin\controllers\drug;
|
||
|
||
use admin\components\BaseAdminController;
|
||
use admin\models\forms\drug\GranularForm;
|
||
use admin\models\forms\drug\ImportForm;
|
||
use admin\models\forms\drug\ServerForm;
|
||
use common\enums\UserRoleEnum;
|
||
use common\helpers\FuncHelper;
|
||
use common\models\oldDb\Drug;
|
||
use moonland\phpexcel\Excel;
|
||
use yii\web\UploadedFile;
|
||
|
||
/**
|
||
* @doc-module 产品服务包库
|
||
*/
|
||
class ServerController extends BaseAdminController
|
||
{
|
||
|
||
/**
|
||
* @doc-name 药品基本信息列表
|
||
* @doc-param int status 状态类型1中药2西药3颗粒配方5全部列表
|
||
* @doc-param string name 搜素药名、编号、条形码、厂家、中西药标签、拼音首拼、别名
|
||
* @doc-return mixed @List{id,drug_name-string-药名,drug_number-string-编号,drug_alias-string-别名,bar_code-string-条形码,guozi_no-string-国字准号,category_first-int-一级分类,category_second-int-二级分类,source-string-货源(厂家),function-string-功能主治,decotion-string-煎法,is_otc-int-是否处方药,usage-string-用法,specification-string-规格,instruction-string-说明书图片,image-string-药品图片,time-string-使用时间,use_type-string-使用方法,frequency-string-频率,unit-string-单位,small_info-string-简介,info-string-基础信息,content-string-详情信息,status-int-状态1草稿2下架3上架,is_shalving-int-状态1下架2上架,stock-int-库存,store-int-门店,type-int-类别1中药2西药3颗粒配方4中成药} 药品列表
|
||
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
||
*/
|
||
public function actionList()
|
||
{
|
||
$get = \Yii::$app->request->get();
|
||
|
||
if (!empty($get['start_time']) && !empty($get['end_time'])) {
|
||
$start_time = strtotime($get['start_time'] . ' ' . '00:00:00');
|
||
$end_time = strtotime($get['end_time'] . ' ' . '23:59:59');
|
||
}
|
||
|
||
$query = Drug::find()->alias('d')->orderBy(['id' => SORT_DESC]);
|
||
|
||
$user = \Yii::$app->user->identity;
|
||
|
||
if ($user->role == UserRoleEnum::STORE_ADMIN) { //门店
|
||
$query->joinWith(['drugStoreRelationes' => function ($drug) use ($user) {
|
||
$drug->alias('ds');
|
||
$drug->andWhere(['ds.store_id' => $user->store_id,'ds.is_forbid'=>0,'ds.status'=>2]);
|
||
}]);
|
||
}
|
||
|
||
|
||
$query->andWhere(['d.type' => 5]);
|
||
if (!empty($get['name'])) {
|
||
$query->andWhere([
|
||
'or',
|
||
['like', 'drug_name', $get['name']],
|
||
['like', 'drug_number', $get['name']],
|
||
['like', 'bar_code', $get['name']],
|
||
['like', 'source', $get['name'] ],
|
||
['like', 'pinyin_simple', $get['name'] ],
|
||
['like', 'drug_alias', $get['name'] ],
|
||
]);
|
||
}
|
||
|
||
if (!empty($start_time) && !empty($end_time)) {
|
||
if ($start_time==$end_time){//筛选当天
|
||
$time=FuncHelper::getDayBE($get['start_time']);
|
||
|
||
$end_time=$time;
|
||
}
|
||
|
||
$query->andWhere(['between', 'd.created_at', $start_time,$end_time]);
|
||
}
|
||
if (!empty($get['type'])) {
|
||
$query->andWhere(['type' => $get['type']]);
|
||
}
|
||
|
||
$this->field = [
|
||
Drug::class => [
|
||
'id', 'pinyin_simple', 'drug_name', 'source', 'type', 'is_otc', 'category_first', 'category_second', 'small_info', 'info', 'content', 'usage', 'specification', 'image', 'status', 'drug_number', 'drug_alias', 'bar_code', 'guozi_no', 'place', 'function', 'instruction', 'decotion_id' => 'decotion', 'decotion' => 'drugUseWay.name', 'unit' => 'unit.name',
|
||
'store' => 'drugStoreRelationes.store_id',
|
||
'price' => 'drugStoreRelationes.price',
|
||
'buy_price' => 'drugStoreRelationes.buy_price',
|
||
'stock' => 'drugStoreRelationes.drugStoreDrug.stock',
|
||
'is_shalving' => 'drugStoreRelationes.status',
|
||
'type_id', 'frequency_id', 'unit_id', 'time_id',
|
||
'use_frequency' => 'drugUseFrequency.name', 'use_type' => 'drugUseType.name',
|
||
'use_time' => 'drugUseTime.name',
|
||
'is_forbid'=>'drugStoreRelationes.is_forbid',
|
||
],
|
||
];
|
||
return $this->create($query, $get);
|
||
}
|
||
/**
|
||
* @doc-name 新增产品服务包库
|
||
* @doc-param string drug_name 药名
|
||
* @doc-param string pinyin_simple 拼音首拼
|
||
* @doc-param string drug_number 编号
|
||
* @doc-param string drug_alias 别名
|
||
* @doc-param int unit_id 单位
|
||
* @doc-param int status 状态1草稿2下架3上架
|
||
* @doc-param string place 产地 / optional
|
||
* @doc-param string instruction 说明书图片 / optional
|
||
* @doc-param json drugstore[{"drugstore_id":1,"price":100,"type":1,"stock":100},{"drugstore_id":2,"price":100,"type":1,"stock":200}] 仓库
|
||
*/
|
||
public function actionSave()
|
||
{
|
||
$post=\Yii::$app->request->post();
|
||
$post['type']=5;
|
||
$GranularForm=new ServerForm();
|
||
$GranularForm->attributes=$post;
|
||
return $GranularForm->save();
|
||
}
|
||
/**
|
||
* @doc-name 删除产品服务包库
|
||
* @doc-param int id 药品ID
|
||
*/
|
||
public function actionDelete()
|
||
{
|
||
$post=\Yii::$app->request->post();
|
||
$this->requestValidate($post,[
|
||
['id','required']
|
||
]);
|
||
$GranularForm=new GranularForm();
|
||
$GranularForm->attributes=$post;
|
||
return $GranularForm->del();
|
||
}
|
||
|
||
/**
|
||
* @doc-name 修改产品服务包库
|
||
* @doc-param int id 药品ID
|
||
* @doc-param string drug_name 药名
|
||
* @doc-param string pinyin_simple 拼音首拼
|
||
* @doc-param string drug_number 编号
|
||
* @doc-param string drug_alias 别名
|
||
* @doc-param int unit_id 单位
|
||
* @doc-param string place 产地 / optional
|
||
* @doc-param string instruction 说明书图片 / optional
|
||
*/
|
||
public function actionUpdate()
|
||
{
|
||
$post=\Yii::$app->request->post();
|
||
$this->requestValidate($post,[
|
||
['id','required']
|
||
]);
|
||
$GranularForm=new GranularForm();
|
||
$GranularForm->attributes=$post;
|
||
return $GranularForm->update();
|
||
|
||
}
|
||
/**
|
||
* @doc-name 查看产品服务包库
|
||
* @doc-param int id 药品ID
|
||
*/
|
||
public function actionInfo()
|
||
{
|
||
$get=\Yii::$app->request->get();
|
||
$this->requestValidate($get,[
|
||
['id','required']
|
||
]);
|
||
$GranularForm=new GranularForm();
|
||
$GranularForm->attributes=$get;
|
||
return $GranularForm->info();
|
||
}
|
||
|
||
/**
|
||
* @doc-name 导入产品服务包库
|
||
* @doc-param file file 文件
|
||
*/
|
||
public function actionGranularImport()
|
||
{
|
||
$request = \Yii::$app->request;
|
||
if ($request->isPost) {
|
||
//设置最大执行时间
|
||
ini_set("max_execution_time", "360");
|
||
$file = UploadedFile::getInstanceByName('file');
|
||
if ($file->size > 5 * 1024 * 1024) {
|
||
return ['excel文件不能超过5M!'];
|
||
}
|
||
|
||
//文件名
|
||
$filename = date('His') . md5($file->getBaseName()) . mt_rand(1000, 9999) . '.' . $file->getExtension();
|
||
//保存文件
|
||
$file->saveAs($filename);
|
||
|
||
$data = Excel::import($filename, [
|
||
'setFirstRecordAsKeys' => true,
|
||
'getOnlySheet' => 'Sheet1',
|
||
]);
|
||
|
||
$ImportForm=new ImportForm();
|
||
return $ImportForm->GranularImport($data);
|
||
} else {
|
||
return ['请求方式错误'];
|
||
}
|
||
}
|
||
} |