|
@@ -858,6 +858,14 @@ class WholeController extends Curd
|
|
|
public function insert(Request $request): Response
|
|
|
{
|
|
|
$params = $request->post();
|
|
|
+ // 判断餐品是否连带着服务或实体
|
|
|
+ $goodsClassifys = array_unique(array_column($params['goodsContentList'],'goods_classify'));
|
|
|
+ if (in_array('MEALS',$goodsClassifys) && count($goodsClassifys) > 1){
|
|
|
+ return json_fail('餐饮餐品不支持和其他类型的产品一起下单');
|
|
|
+ }
|
|
|
+ if (in_array('MEALS',$goodsClassifys)){
|
|
|
+ $params['submit_goods_classify'] = 'MEALS';
|
|
|
+ }
|
|
|
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
@@ -904,6 +912,7 @@ class WholeController extends Curd
|
|
|
$systemStatus = 'SENDING'; // 待发货
|
|
|
// 立即结算
|
|
|
if($params['settlement_now'] == 'Y'){
|
|
|
+ $params['order_is_complete'] = 'Y';
|
|
|
if(in_array($params['goods_classify'],['SERVICE','CHNMED','CHNNCD'])){
|
|
|
$systemStatus = 'DONE';
|
|
|
}
|
|
@@ -918,22 +927,22 @@ class WholeController extends Curd
|
|
|
return json_fail('账户异常');
|
|
|
}
|
|
|
$amount = $account->member_account_surplus + $account->member_account_added;
|
|
|
- if ($params['pay_constitute'] == 'N' && (!$account || $params['order_sheet_pay'] > $amount)) {
|
|
|
+ if ($params['pay_constitute'] == 'N' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
Db::rollBack();
|
|
|
return json_fail('账户余额不足');
|
|
|
}
|
|
|
- if ($params['pay_constitute'] == 'Y' && (!$account || $params['order_sheet_pay'] > $amount)) {
|
|
|
- $qrcodePayAmount = $params['order_sheet_pay'] - $amount;
|
|
|
- $params['order_sheet_pay'] = $amount;
|
|
|
+ if ($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
+ $qrcodePayAmount = $params['order_amount_pay'] - $amount;
|
|
|
+ $params['order_amount_pay'] = $amount;
|
|
|
}
|
|
|
- if ($params['order_sheet_pay'] > $account->member_account_surplus) {
|
|
|
- $cut = $account->member_account_added - ($params['order_sheet_pay'] - $account->member_account_surplus);
|
|
|
+ if ($params['order_amount_pay'] > $account->member_account_surplus) {
|
|
|
+ $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
|
|
|
$account->member_account_surplus = 0;
|
|
|
$account->member_account_added = $cut;
|
|
|
} else {
|
|
|
- $account->member_account_surplus = $account->member_account_surplus - $params['order_sheet_pay'];
|
|
|
+ $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
}
|
|
|
- $account->member_account_expend = $account->member_account_expend + $params['order_sheet_pay'];
|
|
|
+ $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
$account->save();
|
|
|
if ($params['pay_constitute'] == 'N') {
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
@@ -949,13 +958,13 @@ class WholeController extends Curd
|
|
|
return json_fail('账户异常');
|
|
|
}
|
|
|
$account->member_account_surplus = floatval($account->member_account_surplus);
|
|
|
- if ($params['pay_constitute'] == 'N' && ($params['order_sheet_pay'] > $account->member_account_surplus)) {
|
|
|
+ if ($params['pay_constitute'] == 'N' && ($params['order_amount_pay'] > $account->member_account_surplus)) {
|
|
|
Db::rollBack();
|
|
|
return json_fail('账户余额不足');
|
|
|
}
|
|
|
- if($params['pay_constitute'] == 'Y' && ($params['order_sheet_pay'] > $account->member_account_surplus)){
|
|
|
- $qrcodePayAmount = $params['order_sheet_pay'] - $account->member_account_surplus;
|
|
|
- $params['order_sheet_pay'] = $account->member_account_surplus;
|
|
|
+ if($params['pay_constitute'] == 'Y' && ($params['order_amount_pay'] > $account->member_account_surplus)){
|
|
|
+ $qrcodePayAmount = $params['order_amount_pay'] - $account->member_account_surplus;
|
|
|
+ $params['order_amount_pay'] = $account->member_account_surplus;
|
|
|
}
|
|
|
|
|
|
if ($params['pay_constitute'] == 'N') {
|
|
@@ -963,8 +972,8 @@ class WholeController extends Curd
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
}
|
|
|
|
|
|
- $account->member_account_surplus = $account->member_account_surplus - $params['order_sheet_pay'];
|
|
|
- $account->member_account_expend = $account->member_account_expend + $params['order_sheet_pay'];
|
|
|
+ $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
+ $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
$account->save();
|
|
|
} else if ($params['settlement_now'] == 'Y' && $params['pay_category'] == 'CARD') { // 储值卡账户
|
|
|
$cardNbr = $params['card_nbr'];
|
|
@@ -981,23 +990,23 @@ class WholeController extends Curd
|
|
|
return json_fail('账户异常');
|
|
|
}
|
|
|
$amount = $account->member_account_surplus + $account->member_account_added;
|
|
|
- if ($params['pay_constitute'] == 'N' && (!$account || $params['order_sheet_pay'] > $amount)) {
|
|
|
+ if ($params['pay_constitute'] == 'N' && (!$account || $params['order_amount_pay'] > $amount)) {
|
|
|
Db::rollBack();
|
|
|
return json_fail('账户余额不足');
|
|
|
}
|
|
|
- if($params['pay_constitute'] == 'Y' && (!$account || $params['order_sheet_pay'] > $amount)){
|
|
|
- $qrcodePayAmount = $params['order_sheet_pay'] - $amount;
|
|
|
- $params['order_sheet_pay'] = $amount;
|
|
|
+ if($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)){
|
|
|
+ $qrcodePayAmount = $params['order_amount_pay'] - $amount;
|
|
|
+ $params['order_amount_pay'] = $amount;
|
|
|
}
|
|
|
|
|
|
- if ($params['order_sheet_pay'] > $account->member_account_surplus) {
|
|
|
- $cut = $account->member_account_added - ($params['order_sheet_pay'] - $account->member_account_surplus);
|
|
|
+ if ($params['order_amount_pay'] > $account->member_account_surplus) {
|
|
|
+ $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
|
|
|
$account->member_account_surplus = 0;
|
|
|
$account->member_account_added = $cut;
|
|
|
} else {
|
|
|
- $account->member_account_surplus = $account->member_account_surplus - $params['order_sheet_pay'];
|
|
|
+ $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
|
|
|
}
|
|
|
- $account->member_account_expend = $account->member_account_expend + $params['order_sheet_pay'];
|
|
|
+ $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
|
|
|
$account->save();
|
|
|
|
|
|
if ($params['pay_constitute'] == 'N') {
|
|
@@ -1009,10 +1018,10 @@ class WholeController extends Curd
|
|
|
// 提交过来的支付分类
|
|
|
$submitPayCategory = $params['pay_category'];
|
|
|
// 账户支付的金额
|
|
|
- $accountAmount = $params['order_sheet_pay'];
|
|
|
+ $accountAmount = $params['order_amount_pay'];
|
|
|
if ($params['pay_constitute'] == 'Y' && $qrcodePayAmount > 0){
|
|
|
// 组合支付,支付金额改成需要付款码需要支付的金额
|
|
|
- $params['order_sheet_pay'] = $qrcodePayAmount;
|
|
|
+ $params['order_amount_pay'] = $qrcodePayAmount;
|
|
|
}
|
|
|
if($params['pay_constitute'] == 'Y' && $qrcodePayAmount <= 0){
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
@@ -1051,7 +1060,7 @@ class WholeController extends Curd
|
|
|
'join_pay_order_id'=>$params['orderGroupId'],
|
|
|
'pay_status'=>'SUCCESS',
|
|
|
'pay_category' => $params['goods_classify'],
|
|
|
- 'pay_amount'=> $params['order_sheet_pay'],
|
|
|
+ 'pay_amount'=> $params['order_amount_pay'],
|
|
|
'pay_paytimes'=>date('Y-m-d H:i:s'),
|
|
|
'pay_prepayid'=>$params['pay_category'],
|
|
|
'pay_json_request' => json_encode($params),
|
|
@@ -1068,7 +1077,7 @@ class WholeController extends Curd
|
|
|
$params['order_status_system'] = $systemStatus;
|
|
|
$params['order_status_payment'] = 'SUCCESS';
|
|
|
// 账户支付的金额
|
|
|
- $params['order_sheet_pay'] = $accountAmount;
|
|
|
+ $params['order_amount_pay'] = $accountAmount;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1086,14 +1095,31 @@ class WholeController extends Curd
|
|
|
// 'express' => 'Y',
|
|
|
// ]);
|
|
|
}
|
|
|
+ $params['order_amount_pay'] = $params['order_amount_pay'] + $qrcodePayAmount;
|
|
|
+
|
|
|
+ if (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS'){
|
|
|
+ $premises = SysDept::where('dept_name',$params['dept_premises_id'])->where('dept_category','营业场所')->first();
|
|
|
+ if (!$premises){
|
|
|
+ Db::rollBack();
|
|
|
+
|
|
|
+ return json_fail('门店不存在,请重新选择');
|
|
|
+ }
|
|
|
+ $params['submit_premises_id'] = $premises->dept_id;
|
|
|
+ $orderConfigJson['premises'] = $params['dept_premises_id'];
|
|
|
+ $orderConfigJson['dept'] = $premises->dept_id;
|
|
|
+ $orderConfigJson['reach'] = "00:00";
|
|
|
+ $orderConfigJson['table'] = null;
|
|
|
+ $orderConfigJson['express'] = "到店吃";
|
|
|
+ $orderConfigJson['tableid'] = null;
|
|
|
+ }
|
|
|
+
|
|
|
$params['order_config_json'] = json_encode($orderConfigJson);
|
|
|
- $params['order_sheet_pay'] = $params['order_sheet_pay'] + $qrcodePayAmount;
|
|
|
// 写入主订单
|
|
|
$this->insertMain($params);
|
|
|
// 订单详情
|
|
|
$sheetId = $this->insertSheet($params);
|
|
|
// 支付记录
|
|
|
- $params['order_sheet_pay'] = $params['order_sheet_pay'] - $qrcodePayAmount;
|
|
|
+ $params['order_amount_pay'] = $params['order_amount_pay'] - $qrcodePayAmount;
|
|
|
$this->insertPayDetail($params);
|
|
|
|
|
|
$params['order_express_goods'] = json_encode(['sheet' => [$sheetId]]);
|
|
@@ -1213,10 +1239,10 @@ class WholeController extends Curd
|
|
|
'order_groupby' => $params['orderGroupId'],
|
|
|
'join_order_member_id' => $params['join_order_member_id'],
|
|
|
'order_name' => date('Y-m-d H:i:s') . '-订单',
|
|
|
- 'order_amount_total' => $params['order_sheet_amount'],
|
|
|
- 'order_amount_pay' => $params['order_sheet_pay'],
|
|
|
- 'order_category' => 'SYSTEM',
|
|
|
- 'order_is_complete' => 'N',
|
|
|
+ 'order_amount_total' => $params['order_amount_total'],
|
|
|
+ 'order_amount_pay' => $params['order_amount_pay'],
|
|
|
+ 'order_category' => (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') ? 'DISHES' :'NORMAL',
|
|
|
+ 'order_is_complete' => $params['order_is_complete'] ?? 'N',
|
|
|
'order_status_system' => $params['order_status_system'],
|
|
|
'order_status_payment' => $params['order_status_payment'],
|
|
|
'order_status_storage' => $params['order_status_storage'],
|
|
@@ -1248,20 +1274,28 @@ class WholeController extends Curd
|
|
|
{
|
|
|
try {
|
|
|
foreach($params['goodsContentList'] as $goods){
|
|
|
+ //{"unit": "份", "table": null, "premises": "15"}
|
|
|
$price = floatval($goods['goods_sales_price']);
|
|
|
+ $extendJson['unit'] = $goods['sku_name'];
|
|
|
+ if (isset($params['submit_premises_id'])){
|
|
|
+ $extendJson['table'] = null;
|
|
|
+ $extendJson['premises'] = $params['submit_premises_id'];
|
|
|
+ }
|
|
|
$data = [
|
|
|
'join_sheet_member_id' => $params['join_order_member_id'],
|
|
|
'join_sheet_order_id' => $params['orderId'],
|
|
|
'join_sheet_goods_id' => $goods['goods_id'],
|
|
|
'join_sheet_goods_sku_id' => $goods['sku_id'],
|
|
|
'order_sheet_status' => $params['settlement_now'] == 'Y' ? 'DONE' : 'PAYING',
|
|
|
- 'order_sheet_category' => 'NORMAL',
|
|
|
+ 'order_sheet_category' => (isset($params['submit_goods_classify']) && $params['submit_goods_classify'] == 'MEALS') ? 'DISHES' :'NORMAL',
|
|
|
'order_sheet_num' => $goods['nbr'],
|
|
|
'order_sheet_price' => $goods['goods_sales_price'],
|
|
|
'order_sheet_amount' => $price * $goods['nbr'],
|
|
|
'order_sheet_pay' => $price * $goods['nbr'],
|
|
|
+ 'order_sheet_task_status' => 'NONE',
|
|
|
'order_sheet_remark' => $params['order_remark'] ?? '',
|
|
|
- 'order_sheet_addtimes' => time()
|
|
|
+ 'order_sheet_addtimes' => time(),
|
|
|
+ 'order_sheet_extend_json'=>json_encode($extendJson)
|
|
|
];
|
|
|
|
|
|
OrderSheet::insertGetId($data);
|
|
@@ -1294,7 +1328,7 @@ class WholeController extends Curd
|
|
|
'join_pay_order_id' => $params['orderGroupId'],
|
|
|
'pay_status' => 'SUCCESS',
|
|
|
'pay_category' => $params['goods_classify'],
|
|
|
- 'pay_amount' => $params['order_sheet_pay'],
|
|
|
+ 'pay_amount' => $params['order_amount_pay'],
|
|
|
'pay_prepayid' => $payPrepayid,
|
|
|
'pay_paytimes' => date('Y-m-d H:i:s'),
|
|
|
'pay_json_request' => json_encode($params),
|
|
@@ -1383,6 +1417,59 @@ class WholeController extends Curd
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function addDishes(Request $request)
|
|
|
+ {
|
|
|
+ $params = $request->post();
|
|
|
+ $goodsClassifys = array_unique(array_column($params['goodsContentList'],'goods_classify'));
|
|
|
+ if (!in_array('MEALS',$goodsClassifys) || count($goodsClassifys) > 1){
|
|
|
+ return json_fail('餐饮餐品不支持和其他类型的产品一起下单');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::beginTransaction();
|
|
|
+ try{
|
|
|
+ $order = Order::where('order_id',$params['order_id'])->first();
|
|
|
+ $payDetail = PayDetail::where('join_pay_order_id',$order->order_groupby)->first();
|
|
|
+ $sheet = OrderSheet::where('join_sheet_order_id',$params['order_id'])->first();
|
|
|
+ foreach($params['goodsContentList'] as $goods){
|
|
|
+ //{"unit": "份", "table": null, "premises": "15"}
|
|
|
+ $price = floatval($goods['goods_sales_price']);
|
|
|
+ $data = [
|
|
|
+ 'join_sheet_member_id' => $order->join_order_member_id,
|
|
|
+ 'join_sheet_order_id' => $params['order_id'],
|
|
|
+ 'join_sheet_goods_id' => $goods['goods_id'],
|
|
|
+ 'join_sheet_goods_sku_id' => $goods['sku_id'],
|
|
|
+ 'order_sheet_status' => 'PAYING',
|
|
|
+ 'order_sheet_category' => 'DISHES',
|
|
|
+ 'order_sheet_num' => $goods['nbr'],
|
|
|
+ 'order_sheet_price' => $goods['goods_sales_price'],
|
|
|
+ 'order_sheet_amount' => $price * $goods['nbr'],
|
|
|
+ 'order_sheet_pay' => $price * $goods['nbr'],
|
|
|
+ 'order_sheet_task_status' => 'NONE',
|
|
|
+ 'order_sheet_remark' => $params['order_remark'] ?? '',
|
|
|
+ 'order_sheet_addtimes' => time(),
|
|
|
+ 'order_sheet_extend_json'=>$sheet->order_sheet_extend_json ?? '[]'
|
|
|
+ ];
|
|
|
+
|
|
|
+ $order->order_amount_total = $order->order_amount_total + $data['order_sheet_amount'];
|
|
|
+ $order->order_amount_pay = $order->order_amount_pay + $data['order_sheet_pay'];
|
|
|
+
|
|
|
+ $payDetail->pay_amount = $payDetail->pay_amount + $data['order_sheet_pay'];
|
|
|
+
|
|
|
+ OrderSheet::insertGetId($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ $order->save();
|
|
|
+ $payDetail->save();
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ return json_success('加菜成功');
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Db::rollBack();
|
|
|
+
|
|
|
+ return json_success('加菜失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改主订单
|
|
|
*/
|