围餐的定时任务

Change-Id: Ib449c2b14eed0faf1cdeca89776de889aab6b30a
This commit is contained in:
vguanyiwgd 2024-05-10 09:21:36 +08:00
parent 09a57a68b7
commit 7ace1c206e
1 changed files with 52 additions and 0 deletions

View File

@ -2481,3 +2481,55 @@ select * from
}
}
}
// 定时脚本,当天围餐的菜品都撤掉,然后自动插入餐标菜式,以便实现:当日预定按照人头固定金额203040这三个金额
if($act == 'weican'){
$company_id = '4151';
// 固定餐标的类型
$meal_label_type = "898";
$dining_hall_id = "305";
// 获取今天围餐的所有订单
$today = date('Y-m-d');
$dateInfo = $db->get_all("select a.*, b.name as meal_type_name from tb_date a,tb_meal_type b where a.dc_type=b.id and a.dc_date='{$today}' and a.dining_hall_id='{$dining_hall_id}' and b.mealtype=6 and b.status=1 order by b.idx desc");
if(empty($dateInfo)){
echo "今天没有围餐";
exit;
}
foreach ($dateInfo as $k => $v){
// 把tb_date_dish的菜品数量改为0然后插入餐标菜式
$date_id = $v['id'];
// 获取当前菜谱的所有菜品(不含固定餐标)
$dish_list = $db->get_all("select a.*, b.dish_type from tb_date_dish a, tb_dish b where a.dish_id=b.id and b.dish_type!='{$meal_label_type}' and a.date_id='{$date_id}' and b.enabled=1");
// 获取需要更新的菜品id
$dish_ids = array_column($dish_list, 'dish_id');
$dish_ids = join(',', $dish_ids);
$db->query("update tb_date_dish set total_max_num = book_num where date_id=".$date_id." and dish_id in ({$dish_ids})");
//对于book_num = 0的也更新为不可以订了
$db->query("update tb_date_dish set total_max_num = 1,book_num = 1 where date_id=".$date_id." and book_num = 0 and total_max_num = 0 and dish_id in ({$dish_ids})");
// 然后添加餐标菜式
// 判断是否已经有餐标菜式
$has_meal_label = $db->get_one("select * from tb_date_dish a, tb_dish b where a.dish_id=b.id and b.dish_type='{$meal_label_type}' and a.date_id='{$date_id}' and b.enabled=1");
if(!empty($has_meal_label)){
// 当前菜谱没有餐标菜式,添加
$meal_label_list = $db->get_all("select * from tb_dish where enabled=1 and dish_type='{$meal_label_type}' and dining_hall_id='{$dining_hall_id}' order by id asc");
foreach ($meal_label_list as $mk => $mv){
$insert_data = array(
'date_id' => $date_id,
'dish_id' => $mv['id'],
'max_num'=> 1000,
'is_normal_dish'=>1,
'total_max_num'=> 0,
'idx' => 0,
'book_type' => 1,
'book_num'=> 0,
);
$db->insert("tb_date_dish", $insert_data);
}
}
}
}