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.
144 lines
5.5 KiB
PHP
144 lines
5.5 KiB
PHP
<?php
|
|
namespace App\Services;
|
|
|
|
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']])->delete();
|
|
DB::table('combo_items')->where(['combo_id' => $combo['Id']])->delete();
|
|
}
|
|
$sixin_combo_item_ids=[];//思信套餐内项目ids
|
|
if($combo['变更类别']=='修改' || $combo['变更类别']=='新增'){
|
|
$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),
|
|
'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']])->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['简介'],
|
|
'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, '操作完成', []);
|
|
}
|
|
}
|