You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hainan_2024/Laravel/app/Services/ComboItemGroupService.php

188 lines
7.2 KiB
PHP

<?php
namespace App\Services;
use App\Http\Controllers\API\PEISApiController;
use Illuminate\Support\Facades\DB;
class ComboItemGroupService
{
public function Save($res){
if(isset($res['变更套餐'])){
$combos=$res['变更套餐'];
$successCount = 0;//成功的数量
foreach ($combos as $combo){
if($combo['变更类别']=='改价'){
DB::table('combos')->where(['combo_id' => $combo['Id']])->update([
'original_price'=> $combo['原价'],
'price'=> $combo['价格'],
]);
foreach ($combo['包含项目'] as $key => $v) {
DB::table('combo_items')->where(['combo_id' => $combo['Id'],'item_id'=>$v['Id']])->update([
'price'=> $v['价格']
]);
}
}
if($combo['变更类别']=='删除'){
DB::table('combos')->where(['combo_id' => $combo['Id']])->delete();
DB::table('combo_items')->where(['combo_id' => $combo['Id']])->delete();
}
$sixin_combo_item_ids=[];//思信套餐内项目ids
if($combo['变更类别']=='修改' || $combo['变更类别']=='新增'){
if($combo['可选']===false){//如果可选为false,则删除
DB::table('combos')->where(['combo_id' => $combo['Id']])->delete();
DB::table('combo_items')->where(['combo_id' => $combo['Id']])->delete();
return \Yz::echoError1('删除成功');
}
$item = [];
foreach ($combo['包含项目'] as $key => $v) {
$sixin_combo_item_ids[]=$v['Id'];
//在独立表中缓存一份套餐对应的项目信息
$item_sex = null;
if (isset($v['性别限制'])) {
$item_sex_array = ['全部' => 0, '男' => 1, '女' => 2];
$item_sex = $item_sex_array[$combo['性别限制']] >= 0 ? $item_sex_array[$combo['性别限制']] : null;
}
$item_date = [
'combo_id'=>$combo['Id'],
'item_id'=>$v['Id'],
'name'=>$v['名称'],
'desc' => $v['简介'],
'keshi_id' => $v['科室Id'],
'keshi_name' => $v['科室名称'],
'price'=> $v['价格'],
'sex'=>$item_sex,
'can_qian_hou'=>$v['餐前餐后'],
'status'=>1
];
$db_combo_item = DB::table('combo_items')->where(['item_id' => $v['Id'], 'combo_id' => $combo['Id']])->first();
if (!!$db_combo_item) {
//如果存在项目
$u = DB::table('combo_items')->where(['id' => $db_combo_item->id])->update($item_date);
} else {
//如果不在项目
$u = DB::table('combo_items')->insert($item_date);
}
$item[] = [
'id' => $v['Id'],
'name' => $v['名称'],
'desc' => $v['备注'],
'keshi_name' => $v['科室名称'],
];
}
//查询当前套餐缓存的套餐项目ids
$db_combo_item_ids=DB::table('combo_items')
->where(['combo_id' => $combo['Id']])->pluck('item_id')->toArray();
// 查询在库里缓存但思信已经没有的项目ids,标注为弃用0
$k_ids = array_diff($db_combo_item_ids, $sixin_combo_item_ids);
if(count($k_ids)>0){
DB::table('combo_items')->where(['combo_id'=>$combo['Id']])->whereIn('item_id',$k_ids)->delete();
}
$item = json_encode($item, JSON_UNESCAPED_UNICODE);
$sex = null;
if (isset($combo['性别限制'])) {
$sex_array = ['全部' => 0, '男' => 1, '女' => 2];
$sex = $sex_array[$combo['性别限制']] >= 0 ? $sex_array[$combo['性别限制']] : null;
}
$db_combo = DB::table('combos')->where(['combo_id' => $combo['Id']])->first();
$comboData = [
'combo_id' => $combo['Id'],
'sex' => $sex,
'name' => $combo['名称'],
'pinyin' => $combo['拼音'],
'original_price' => $combo['原价'],
'price' => $combo['价格'],
'items' => $item,
'item_count' => $combo['项目数量'],
'duo_xuan_yi'=>json_encode($combo['包含多选一组'], JSON_UNESCAPED_UNICODE),
'keyue_start_time' => $combo['可约开始时间'],
'keyue_end_time' => $combo['可约截止时间'],
'status' => 1,
'updated_at' => date('Y-m-d H:i:s'),
];
if (!!$db_combo) {
//如果存在套餐
$u = DB::table('combos')->where([ 'combo_id' => $combo['Id']])->update($comboData);
} else {
//如果不存在套餐
$comboData['tags'] = json_encode([]);
$comboData['tags2'] = json_encode([]);
$u = DB::table('combos')->insert($comboData);
}
if ($u) {
$successCount++;
} else {
return \Yz::echoError1('更新失败');
}
}
}
}
if(isset($res['变更收费项目'])){
$items=$res['变更收费项目'];
foreach ($items as $item){
if($item['变更类别']=='改价'){
DB::table('items')->where(['item_id'=>$item['Id']])->update(['price'=>$item['价格']]);
}
if($item['变更类别']=='删除'){
DB::table('items')->where(['item_id'=>$item['Id']])->delete();
}
if($item['变更类别']=='修改' || $item['变更类别']=='新增'){
$item_sex=null;
if (isset($v['性别限制'])) {
$item_sex_array = ['全部' => 0, '男' => 1, '女' => 2];
$item_sex = $item_sex_array[$item['性别限制']] >= 0 ? $item_sex_array[$item['性别限制']] : null;
}
$ItemData=[
'item_id'=>$item['Id'],
'sex'=>$item_sex,
'can_qian_hou'=>$item['餐前餐后'],
'name'=>$item['名称'],
'pinyin'=>$item['拼音'],
'price'=>$item['价格'],
'is_choose'=>$item['可选']===false ? "0" : "1",
'keshi_id'=>$item['科室Id'],
'keshi_name'=>$item['科室名称'],
'beizhu'=>$item['备注'],
'jianjie'=>$item['简介'],
'tishi'=>$item['提示信息'],
'status'=>1,
'updated_at'=>date('Y-m-d H:i:s'),
];
$cha= DB::table('items')->where(['item_id'=>$item['Id']])->get();
if(count($cha)>0){
DB::table('items')->where(['item_id'=>$item['Id']])->update($ItemData);
}else{
DB::table('items')->insert($ItemData);
}
}
}
}
return \Yz::Return(true, '操作完成', []);
}
//弃检
public function QiJian($tj_num,$username,$ids)
{
$peis = new PEISApiController();
$data=[
'体检号'=>$tj_num,
"操作医生姓名"=>$username,
"取消弃检"=>false,
"收费项目Id列表"=>$ids
];
$url=$peis::Api("弃检接口","460107000001");
$res_str=$peis::Post2("弃检接口",$url,1,$data);
$res = json_decode($res_str, true);
if($res['Success']===true){
return ['status'=>true,'msg'=>$res['Message']];
}else{
return ['status'=>false,'msg'=>$res['Message']];
}
}
}