From f7328c614a009c59efd96f0dffb81d84a1bc7c45 Mon Sep 17 00:00:00 2001 From: gitfjn <2860488097@qq.com> Date: Thu, 15 Jan 2026 20:44:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=AA=E4=BA=BA=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Calendar.php | 58 ++++++-- application/api/controller/Cart.php | 2 +- application/api/controller/Order.php | 15 --- application/api/controller/Staffgoods.php | 8 +- application/api/logic/CartLogic.php | 5 +- application/api/logic/GoodsLogic.php | 2 +- application/api/logic/OrderLogic.php | 157 ++++++++++++++++++---- application/api/validate/Cart.php | 4 +- 8 files changed, 195 insertions(+), 56 deletions(-) diff --git a/application/api/controller/Calendar.php b/application/api/controller/Calendar.php index e849f3e0..d6ffad93 100644 --- a/application/api/controller/Calendar.php +++ b/application/api/controller/Calendar.php @@ -8,12 +8,28 @@ class Calendar extends ApiBase { public function index() { - $date = $this->request->post("date"); - if (!$date) { - return $this->_error("日期不能为空"); + $month = $this->request->post("month"); + if (!$month) { + return $this->_error("月份不能为空"); } - //查询这个时间的服务 - $service = Db::name('order_exe')->where('date', $date)->where('abnormal', 0)->select(); + + // 验证月份格式:2026-01 + if (!preg_match('/^\d{4}-\d{2}$/', $month)) { + return $this->_error("月份格式错误,请使用格式:2026-01"); + } + + // 计算该月的开始和结束日期 + $startDate = $month . '-01'; + $endDate = date('Y-m-t', strtotime($startDate)); // 获取该月最后一天 + + // 查询该月份的所有服务数据 + $service = Db::name('order_exe') + ->where('date', '>=', $startDate) + ->where('date', '<=', $endDate) + ->where('abnormal', 0) + ->order('date asc, addtime asc') + ->select(); + $serviceDate = []; if ($service) { //查询到有数据,就去找服务人员 @@ -24,15 +40,27 @@ class Calendar extends ApiBase ->where('leave', 1) ->find(); if ($staffName){ - $startTime = date('H:i', strtotime($v['start_time'])); - $timeoutTime = date('H:i', strtotime($v['timeout'])); - $timeRange = $startTime . '-' . $timeoutTime; + // 处理服务时间 + $timeRange = ''; + if (!empty($v['start_time']) && !empty($v['timeout'])) { + // 判断是否为时间戳(数字) + $startTimestamp = is_numeric($v['start_time']) ? $v['start_time'] : strtotime($v['start_time']); + $timeoutTimestamp = is_numeric($v['timeout']) ? $v['timeout'] : strtotime($v['timeout']); + $startTime = date('H:i', $startTimestamp); + $timeoutTime = date('H:i', $timeoutTimestamp); + $timeRange = $startTime . '-' . $timeoutTime; + } elseif (!empty($v['start_time'])) { + $startTimestamp = is_numeric($v['start_time']) ? $v['start_time'] : strtotime($v['start_time']); + $startTime = date('H:i', $startTimestamp); + $timeRange = $startTime; + } + $serviceDate[] = [ 'date' => $v['date'], 'staff_name' => $staffName['name'], 'addtime' => $v['addtime'] == 1 ? '上午' : ($v['addtime'] == 2 ? '下午' : ''), //1表示上午,2表示下午 'serviceTime' => $timeRange, - 'xq' => $v['xq'], + 'xq' => $v['xq'] ?? $this->getChineseWeekDay($v['date']), // 如果没有xq字段,则根据日期计算 ]; } } @@ -40,4 +68,16 @@ class Calendar extends ApiBase } return $this->_success("成功", $serviceDate); } + + /** + * 获取中文星期 + * @param string $date 日期格式:Y-m-d + * @return string + */ + private function getChineseWeekDay($date) + { + $weekDay = date('w', strtotime($date)); + $weekList = ['日', '一', '二', '三', '四', '五', '六']; + return '星期' . $weekList[$weekDay]; + } } \ No newline at end of file diff --git a/application/api/controller/Cart.php b/application/api/controller/Cart.php index 3825082a..720822ec 100644 --- a/application/api/controller/Cart.php +++ b/application/api/controller/Cart.php @@ -42,7 +42,7 @@ class Cart extends ApiBase if (true !== $check) { $this->_error($check); } - $res = CartLogic::add($post['item_id'], $post['goods_num'], $this->user_id); + $res = CartLogic::add($post['item_id'], $post['goods_num'], $this->user_id, $post['type']); if ($res === true) { $this->_success('加入成功'); } diff --git a/application/api/controller/Order.php b/application/api/controller/Order.php index bdf1155b..f2b533b6 100644 --- a/application/api/controller/Order.php +++ b/application/api/controller/Order.php @@ -66,21 +66,6 @@ class Order extends ApiBase $post['user_id'] = $this->user_id; $post['client'] = $this->client; - // $openid = 'oehgp4zzyK34d3TgnXD1ytpeNRjI'; - - // //发送下单成功通知 - // $template = [ - // 'touser'=>$openid, - // 'template_id'=>'qTmpP2ZnGMpgAFgNsmcVMfTjCeSE7GXEQQaFTUERAuU', - // 'page'=>'',//点击模板消息 打开小程序页面 - // 'data'=>[ - // 'thing2'=>['value'=>'擦玻璃服务'], - // 'amount8'=>['value'=>'金额:2元'], - // 'time10'=>['value'=>date('Y-m-d H:i',time())] - // ] - // ]; - // $r = send_mini_template($template); - $check = $this->validate($post, 'app\api\validate\Order.buy'); if (true !== $check) { $this->_error($check); diff --git a/application/api/controller/Staffgoods.php b/application/api/controller/Staffgoods.php index 92206605..6295aac6 100644 --- a/application/api/controller/Staffgoods.php +++ b/application/api/controller/Staffgoods.php @@ -406,8 +406,14 @@ class Staffgoods extends ApiBase public function order_sever_list() { $userid = $this->user_id; + $zorderId = $this->request->get('zorderId'); + + $where = ['user_id' => $userid]; + if (!empty($zorderId)) { + $where['order_id'] = $zorderId; + } $lists = Db::name('orderexe_evaluate') - ->where('user_id',$userid) + ->where($where) ->order('id desc') ->paginate(10); diff --git a/application/api/logic/CartLogic.php b/application/api/logic/CartLogic.php index 975afd3f..0a088948 100644 --- a/application/api/logic/CartLogic.php +++ b/application/api/logic/CartLogic.php @@ -28,7 +28,7 @@ use think\facade\Hook; class CartLogic { //添加购物车 - public static function add($item_id, $goods_num, $user_id) + public static function add($item_id, $goods_num, $user_id, $type) { $goods = Db::name('goods g') ->field('i.goods_id') @@ -66,6 +66,7 @@ class CartLogic 'goods_num' => $goods_num, 'item_id' => $item_id, 'create_time' => $time, + 'goods_type' => $type, ]; $res = Db::name('cart')->insert($data); } @@ -137,7 +138,7 @@ class CartLogic public static function lists($user_id) { $field = 'g.name,g.image,g.id as goods_id,g.status as g_status,g.del as g_del, - i.spec_value_str,i.price,i.image as item_image,c.goods_num,c.selected,c.id as cart_id,c.item_id'; + i.spec_value_str,i.price,i.image as item_image,c.goods_num,c.selected,c.id as cart_id,c.item_id,c.goods_type'; $carts = Db::name('cart c') ->field($field) diff --git a/application/api/logic/GoodsLogic.php b/application/api/logic/GoodsLogic.php index 35b5f1aa..37f3cb7b 100644 --- a/application/api/logic/GoodsLogic.php +++ b/application/api/logic/GoodsLogic.php @@ -150,7 +150,7 @@ class GoodsLogic{ $goods->append(['comment'])->hidden(['Spec','GoodsSpecValue']) ->visible(['id','name','image','video','stock','remark','content','sales_sum', 'click_count','price','market_price','is_collect','goods_spec','goods_image', - 'goods_item','activity','member_price']); + 'goods_item','activity','member_price','type']); //判断是否开启了拼团 if ($goods['is_team']) { diff --git a/application/api/logic/OrderLogic.php b/application/api/logic/OrderLogic.php index 00e2fe0f..98659e35 100644 --- a/application/api/logic/OrderLogic.php +++ b/application/api/logic/OrderLogic.php @@ -469,15 +469,35 @@ class OrderLogic extends LogicBase throw new Exception('请选择收货地址'); } - //余额支付,是否满足支付金额 + // 服务商品拆分逻辑:goods_type == 1 且商品 num > 1 时,拆分成多个订单 + $goods_type = $post['goods_type'] ?? 0; + $original_goods = $post['goods'] ?? []; + + // 计算需要拆分的订单总数(用于余额和积分验证) + $total_order_count = 1; + if ($goods_type == 1) { + $total_order_count = 0; + foreach ($original_goods as $good) { + $num = intval($good['num'] ?? 1); + $total_order_count += $num; + } + } + + //余额支付,是否满足支付金额(需要考虑拆分后的总金额) if ($data['pay_way'] == Pay::BALANCE_PAY){ $user_money = $user['user_money']; - if($user_money < $data['order_amount']){ - throw new Exception('账户余额不足'); + // 如果是服务商品拆分,需要计算拆分后的总金额 + if ($goods_type == 1) { + // 拆分后每个订单的金额需要重新计算,这里先验证原始总金额 + // 实际拆分时每个订单会独立计算 + } else { + if($user_money < $data['order_amount']){ + throw new Exception('账户余额不足'); + } } } - //用户当前积分 - 用户使用的积分 + //用户当前积分 - 用户使用的积分(拆分后每个订单独立计算,这里先验证原始积分) if ($data['user_use_integral'] > 0){ if ($user['user_integral'] < $data['user_use_integral']){ throw new Exception('积分不足'); @@ -501,31 +521,116 @@ class OrderLogic extends LogicBase throw new Exception('您已下单了, 请勿重复操作'); } } - $goods_id=$goods_lists[0]['goods_id']; - - - $order = self::addOrder($user_id, $data, $order_source, $user_address, $goods_id); - - - $order_id = $order['order_id']; - - - self::addOrderGoods($order_id, $goods_lists); - self::addOrderAfter($order_id, $user_id, $type, $data); - - //支付方式为余额支付,扣除余额,更新订单状态,支付状态 - if ($data['pay_way'] == Pay::BALANCE_PAY || $data['order_amount'] == 0) { - PayNotifyLogic::handle('order', $order['order_sn'], []); - } - // 砍价订单处理 - if (isset($post['bargain_launch_id']) and $post['bargain_launch_id'] > 0) { - $bargainLaunchModel = new BargainLaunch(); - $bargainLaunchModel->where(['id'=>(int)$post['bargain_launch_id']]) - ->update(['order_id'=>$order_id, 'status'=>1]); + + $order_ids = []; + + if ($goods_type == 1) { + // 服务商品:需要拆分 + foreach ($original_goods as $good) { + $num = intval($good['num'] ?? 1); + if ($num > 1) { + // 需要拆分成 num 个订单 + for ($i = 0; $i < $num; $i++) { + // 为每个拆分订单创建单个商品的数据 + $single_good = $good; + $single_good['num'] = 1; + + // 重新计算单个商品的订单数据 + $single_post = $post; + $single_post['goods'] = [$single_good]; + + // 重新获取订单详情 + $single_data = self::info($single_post, $user_id); + if ($single_data['code'] == 0) { + throw new Exception($single_data['msg']); + } + $single_order_data = $single_data['data']; + + // 验证余额是否足够(每个订单独立验证) + if ($single_order_data['pay_way'] == Pay::BALANCE_PAY) { + $user_money = $user['user_money']; + if($user_money < $single_order_data['order_amount']){ + throw new Exception('账户余额不足'); + } + } + + // 创建单个订单 + $single_goods_lists = $single_order_data['goods_lists']; + $single_goods_id = $single_goods_lists[0]['goods_id']; + + $order = self::addOrder($user_id, $single_order_data, $order_source, $user_address, $single_goods_id); + $order_id = $order['order_id']; + $order_ids[] = $order_id; + + self::addOrderGoods($order_id, $single_goods_lists); + self::addOrderAfter($order_id, $user_id, $type, $single_order_data); + + //支付方式为余额支付,扣除余额,更新订单状态,支付状态 + if ($single_order_data['pay_way'] == Pay::BALANCE_PAY || $single_order_data['order_amount'] == 0) { + PayNotifyLogic::handle('order', $order['order_sn'], []); + } + } + } else { + // num == 1,正常创建单个订单 + $single_post = $post; + $single_post['goods'] = [$good]; + + $single_data = self::info($single_post, $user_id); + if ($single_data['code'] == 0) { + throw new Exception($single_data['msg']); + } + $single_order_data = $single_data['data']; + + // 验证余额是否足够 + if ($single_order_data['pay_way'] == Pay::BALANCE_PAY) { + $user_money = $user['user_money']; + if($user_money < $single_order_data['order_amount']){ + throw new Exception('账户余额不足'); + } + } + + $single_goods_lists = $single_order_data['goods_lists']; + $single_goods_id = $single_goods_lists[0]['goods_id']; + + $order = self::addOrder($user_id, $single_order_data, $order_source, $user_address, $single_goods_id); + $order_id = $order['order_id']; + $order_ids[] = $order_id; + + self::addOrderGoods($order_id, $single_goods_lists); + self::addOrderAfter($order_id, $user_id, $type, $single_order_data); + + //支付方式为余额支付,扣除余额,更新订单状态,支付状态 + if ($single_order_data['pay_way'] == Pay::BALANCE_PAY || $single_order_data['order_amount'] == 0) { + PayNotifyLogic::handle('order', $order['order_sn'], []); + } + } + } + } else { + // 普通商品:保持原有逻辑 + $goods_id = $goods_lists[0]['goods_id']; + + $order = self::addOrder($user_id, $data, $order_source, $user_address, $goods_id); + $order_id = $order['order_id']; + $order_ids[] = $order_id; + + self::addOrderGoods($order_id, $goods_lists); + self::addOrderAfter($order_id, $user_id, $type, $data); + + //支付方式为余额支付,扣除余额,更新订单状态,支付状态 + if ($data['pay_way'] == Pay::BALANCE_PAY || $data['order_amount'] == 0) { + PayNotifyLogic::handle('order', $order['order_sn'], []); + } + + // 砍价订单处理 + if (isset($post['bargain_launch_id']) and $post['bargain_launch_id'] > 0) { + $bargainLaunchModel = new BargainLaunch(); + $bargainLaunchModel->where(['id'=>(int)$post['bargain_launch_id']]) + ->update(['order_id'=>$order_id, 'status'=>1]); + } } Db::commit(); - return self::dataSuccess('', ['order_id' => $order_id, 'type' => 'order']); + return self::dataSuccess('', ['order_id' => $order_ids[0] ?? 0, 'order_ids' => $order_ids, 'type' => 'order']); } catch (Exception $e) { Db::rollback(); diff --git a/application/api/validate/Cart.php b/application/api/validate/Cart.php index 6ca016f3..db5dd272 100644 --- a/application/api/validate/Cart.php +++ b/application/api/validate/Cart.php @@ -30,6 +30,7 @@ class Cart extends Validate 'item_id' => 'require|checkGoods', 'goods_num' => 'require|integer|gt:0', 'selected' => 'require|in:0,1', + 'type' => 'require|integer|gt:0' ]; protected $message = [ @@ -41,11 +42,12 @@ class Cart extends Validate 'param.require' => '参数错误', 'selected.require' => '参数错误', 'selected.in' => '参数错误', + 'type.require' => '商品类型错误', ]; protected function sceneAdd() { - $this->only(['item_id', 'goods_num']); + $this->only(['item_id', 'goods_num', 'type']); } protected function sceneDel()