限时折扣相关
This commit is contained in:
@@ -783,6 +783,10 @@ class Base extends Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$res = Db::execute($sql);
|
$res = Db::execute($sql);
|
||||||
|
// 顺便修改限时折扣
|
||||||
|
(new static())->delTimeInfo($message);
|
||||||
|
$message['table_code'] = $message['new_table_code'];
|
||||||
|
(new static())->setTimeInfo($message);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return $res;
|
return $res;
|
||||||
}catch (Exception $e) {
|
}catch (Exception $e) {
|
||||||
@@ -918,6 +922,63 @@ class Base extends Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取限时折扣
|
||||||
|
public function getTimeInfo($message)
|
||||||
|
{
|
||||||
|
$redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount';
|
||||||
|
$time_dis_info = Redis::get($redis_str);
|
||||||
|
if($time_dis_info) {
|
||||||
|
$time_dis_info = json_decode($time_dis_info, true);
|
||||||
|
}else {
|
||||||
|
if(!empty($message['time_dis_info'])) {
|
||||||
|
$time_dis_info = !is_array($message['time_dis_info'])?json_decode($message['time_dis_info'], true):$message['time_dis_info'];
|
||||||
|
}else {
|
||||||
|
$time_dis_info = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $time_dis_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 限时折扣修改
|
||||||
|
public function setTimeInfo($message)
|
||||||
|
{
|
||||||
|
$redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount';
|
||||||
|
if(empty($message['data'])) {
|
||||||
|
$res = Redis::del($redis_str);
|
||||||
|
}else {
|
||||||
|
$res = Redis::setEx($redis_str, '86400', json_encode($message['data']));
|
||||||
|
// 将桌号存入redis 以便及时删除
|
||||||
|
$time_discount_info = Redis::get('time_discount:info');
|
||||||
|
if($time_discount_info) {
|
||||||
|
$arr_time_discount_info = explode(',', $time_discount_info);
|
||||||
|
if(!in_array($redis_str, $arr_time_discount_info)) {
|
||||||
|
$time_discount_info = array_merge($arr_time_discount_info, [$redis_str]);
|
||||||
|
Redis::set('time_discount:info', implode(',', $time_discount_info));
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
Redis::set('time_discount:info', $redis_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 限时折扣删除
|
||||||
|
public function delTimeInfo($message)
|
||||||
|
{
|
||||||
|
$redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount';
|
||||||
|
Redis::del($redis_str);
|
||||||
|
$time_discount_info = Redis::get('time_discount:info');
|
||||||
|
if($time_discount_info) {
|
||||||
|
$arr_time_discount_info = explode(',', $time_discount_info);
|
||||||
|
$result = array_search($redis_str, $arr_time_discount_info);
|
||||||
|
if($result !== false) {
|
||||||
|
unset($time_discount_info[$result]);
|
||||||
|
Redis::set('time_discount:info', implode(',', $time_discount_info));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -61,17 +61,18 @@ class Shopping extends Base
|
|||||||
// 绑定桌码和 client_id
|
// 绑定桌码和 client_id
|
||||||
Gateway::bindUid($client_id, $table_code);
|
Gateway::bindUid($client_id, $table_code);
|
||||||
// 限时折扣
|
// 限时折扣
|
||||||
$redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount';
|
// $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount';
|
||||||
$time_dis_info = Redis::get($redis_str);
|
// $time_dis_info = Redis::get($redis_str);
|
||||||
if($time_dis_info) {
|
// if($time_dis_info) {
|
||||||
$time_dis_info = json_decode($time_dis_info, true);
|
// $time_dis_info = json_decode($time_dis_info, true);
|
||||||
}else {
|
// }else {
|
||||||
if(!empty($message['time_dis_info'])) {
|
// if(!empty($message['time_dis_info'])) {
|
||||||
$time_dis_info = !is_array($message['time_dis_info'])?json_decode($message['time_dis_info'], true):$message['time_dis_info'];
|
// $time_dis_info = !is_array($message['time_dis_info'])?json_decode($message['time_dis_info'], true):$message['time_dis_info'];
|
||||||
}else {
|
// }else {
|
||||||
$time_dis_info = null;
|
// $time_dis_info = null;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
$time_dis_info = (new Base())->getTimeInfo($message);
|
||||||
if(!empty($message['one_more_order'])) {
|
if(!empty($message['one_more_order'])) {
|
||||||
// 再来一单
|
// 再来一单
|
||||||
if(empty($message['order_id']) || empty($message['user_id'])) {
|
if(empty($message['order_id']) || empty($message['user_id'])) {
|
||||||
@@ -361,6 +362,23 @@ class Shopping extends Base
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
self::gateway_query('sendToClient', [$client_id, json_encode($snd_data)]);
|
self::gateway_query('sendToClient', [$client_id, json_encode($snd_data)]);
|
||||||
|
|
||||||
|
// 直接回馈初始化后的内容
|
||||||
|
$car = Db::query("
|
||||||
|
SELECT * FROM `tb_cashier_cart` WHERE
|
||||||
|
`shop_id`={$message['shop_id']} AND
|
||||||
|
`table_code`='{$message['new_table_code']}'
|
||||||
|
");
|
||||||
|
$snd_data = [
|
||||||
|
'msg' => '购物车初始化',
|
||||||
|
'operate_type' => 'init',
|
||||||
|
'msg_id' => $rand,
|
||||||
|
'type' => 'shopping',
|
||||||
|
'table_code' => $message['table_code'],
|
||||||
|
'data' => $car,
|
||||||
|
'time_dis_info' => (new Base())->getTimeInfo($message)
|
||||||
|
];
|
||||||
|
self::gateway_query('sendToClient', [$client_id, json_encode($snd_data)]);
|
||||||
}catch (\ba\Exception $e) {
|
}catch (\ba\Exception $e) {
|
||||||
Log::info('修改购物车时转桌[error]->>>>>' . $e->getMessage());
|
Log::info('修改购物车时转桌[error]->>>>>' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,29 +135,29 @@ class Events
|
|||||||
Gateway::sendToClient($client_id, json_encode(['msg' => '桌码或shop_id不能为空']));
|
Gateway::sendToClient($client_id, json_encode(['msg' => '桌码或shop_id不能为空']));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount';
|
// $redis_str = Base::get_shopping_save_uid($message['shop_id'], $message['table_code']) . ':time_discount';
|
||||||
if(empty($message['data'])) {
|
// if(empty($message['data'])) {
|
||||||
$res = Redis::del($redis_str);
|
// $res = Redis::del($redis_str);
|
||||||
}else {
|
// }else {
|
||||||
$res = Redis::set($redis_str, json_encode($message['data']));
|
// $res = Redis::set($redis_str, json_encode($message['data']));
|
||||||
// 将桌号存入redis 以便及时删除
|
// // 将桌号存入redis 以便及时删除
|
||||||
$time_discount_info = Redis::get('time_discount:info');
|
// $time_discount_info = Redis::get('time_discount:info');
|
||||||
if($time_discount_info) {
|
// if($time_discount_info) {
|
||||||
$arr_time_discount_info = explode(',', $time_discount_info);
|
// $arr_time_discount_info = explode(',', $time_discount_info);
|
||||||
if(!in_array($redis_str, $arr_time_discount_info)) {
|
// if(!in_array($redis_str, $arr_time_discount_info)) {
|
||||||
$time_discount_info = array_merge($arr_time_discount_info, [$redis_str]);
|
// $time_discount_info = array_merge($arr_time_discount_info, [$redis_str]);
|
||||||
Redis::set('time_discount:info', implode(',', $time_discount_info));
|
// Redis::set('time_discount:info', implode(',', $time_discount_info));
|
||||||
}
|
// }
|
||||||
}else {
|
// }else {
|
||||||
Redis::set('time_discount:info', $redis_str);
|
// Redis::set('time_discount:info', $redis_str);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
$snd_data = [
|
$snd_data = [
|
||||||
'msg' => '折扣修改',
|
'msg' => '折扣修改',
|
||||||
'operate_type' => $message['operate_type'],
|
'operate_type' => $message['operate_type'],
|
||||||
'msg_id' => '',
|
'msg_id' => '',
|
||||||
'type' => 'time_discount',
|
'type' => 'time_discount',
|
||||||
'status' => $res,
|
'status' => (new Base())->setTimeInfo($message),
|
||||||
'data' => $message['data'],
|
'data' => $message['data'],
|
||||||
];
|
];
|
||||||
Gateway::sendToClient($client_id, json_encode($snd_data));
|
Gateway::sendToClient($client_id, json_encode($snd_data));
|
||||||
|
|||||||
Reference in New Issue
Block a user