119 lines
3.6 KiB
PHP
119 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace admin\controllers\drug;
|
|
|
|
use admin\components\BaseAdminController;
|
|
use admin\controllers\AuthController;
|
|
use admin\models\forms\drug\GranularForm;
|
|
use admin\models\forms\drug\ImportForm;
|
|
use moonland\phpexcel\Excel;
|
|
use yii\web\UploadedFile;
|
|
|
|
/**
|
|
* @doc-module 配方颗粒库
|
|
*/
|
|
class GranularController extends BaseAdminController
|
|
{
|
|
/**
|
|
* @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();
|
|
$GranularForm=new GranularForm();
|
|
$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 ['请求方式错误'];
|
|
}
|
|
}
|
|
} |