1
This commit is contained in:
99
application/master/controller/Medicament.php
Normal file
99
application/master/controller/Medicament.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
namespace app\master\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
|
||||
class Medicament extends Controller
|
||||
{
|
||||
|
||||
protected $article_obj = '';
|
||||
protected $medicament_obj = '';
|
||||
protected $article_to_medicament_obj = '';
|
||||
|
||||
public function __construct(\think\Request $request = null)
|
||||
{
|
||||
parent::__construct($request);
|
||||
$this->article_obj = Db::name('article');
|
||||
$this->medicament_obj = Db::name('medicament');
|
||||
$this->article_to_medicament_obj = Db::name('ArticleToMedicament');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加文章药剂项
|
||||
*/
|
||||
public function addMedicament()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
// 验证规则
|
||||
$rule = new Validate([
|
||||
'article_id' => 'require|number',
|
||||
'med_title' => 'require',
|
||||
'med_ename' => 'require'
|
||||
]);
|
||||
if (!$rule->check($data)) {
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
|
||||
$article_info = $this->article_obj->where('article_id', $data['article_id'])->find();
|
||||
|
||||
//检测当前药剂是否存在
|
||||
$med_check = $this->medicament_obj->where('med_title', trim($data['med_title']))->whereOr('med_ename',trim($data['med_ename']))->where('med_state',0)->find();
|
||||
if($med_check){
|
||||
return json(['code'=>2,'data'=>$med_check]);
|
||||
}
|
||||
|
||||
//添加药剂信息
|
||||
$insert_med['med_title'] = trim($data['med_title']);
|
||||
$insert_med['med_ename'] = trim($data['med_ename']);
|
||||
$insert_med['med_ctime'] = time();
|
||||
$med_id = $this->medicament_obj->insertGetId($insert_med);
|
||||
|
||||
//添加文章对应关系
|
||||
$insert_atm['article_id'] = $data['article_id'];
|
||||
$insert_atm['med_id'] = $med_id;
|
||||
$this->article_to_medicament_obj->insert($insert_atm);
|
||||
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加已存在药剂的归属对应关系
|
||||
*/
|
||||
public function addMedicamentHas(){
|
||||
$data = $this->request->post();
|
||||
// 验证规则
|
||||
$rule = new Validate([
|
||||
'article_id' => 'require|number',
|
||||
'med_id' => 'require'
|
||||
]);
|
||||
if (!$rule->check($data)) {
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
|
||||
$insert_atm['article_id'] = $data['article_id'];
|
||||
$insert_atm['med_id'] = $data['med_id'];
|
||||
$this->article_to_medicament_obj->insert($insert_atm);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除药剂话题与文章对应关系
|
||||
*/
|
||||
public function delMedicament(){
|
||||
$data = $this->request->post();
|
||||
$rule = new Validate([
|
||||
'article_id'=>'require',
|
||||
'med_id'=>'require'
|
||||
]);
|
||||
if(!$rule->check($data)){
|
||||
return jsonError($rule->getError());
|
||||
}
|
||||
$this->article_to_medicament_obj->where('article_id',$data['article_id'])->where('med_id',$data['med_id'])->update(['med_state'=>1]);
|
||||
return jsonSuccess([]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user