$storeId, 'identification_arr' => ['blessing'], ]; $storePlugStatus = $plugClass->plugStoreStatus($storePlugStatusPost);//获取状态 $verifyRes = $this->paramVerify($param, 1); if ($verifyRes['status']) { return $verifyRes; } else { $where = $verifyRes; } $num = $param['num']; $page = $param['page']; if ($param['line'] == 2) { //线上 小程序订单 $insertRes = $this->conditionInsert($param, 1); $where = array_merge($where, $insertRes); $res['order_count'] = 0; $res['order_money'] = 0; $res['refund_order_count'] = 0; $res['refund_order_money'] = 0; $res['all_money'] = '0'; switch ($param['order_genre']) { case 1: //商城 $modelRes = $BillModel->getOnlineOrder($where, $page, $num); break; case 2: //拼团 $modelRes = $BillModel->getOnlineGroupOrder($where, $page, $num); break; case 3: //秒杀 $modelRes = $BillModel->getOnlineSkillOrder($where, $page, $num); break; case 4: //预售 $modelRes = $BillModel->getAdvanceOrder($where, $page, $num); break; } } else { /* 收银员是否可以查看所有订单 */ $where = $this->cashierAuthCheck($param, 1, $where); $where['type'] = 2; //获取付费插件列表及状态 $PlugApi = new Plug(); $result = $PlugApi->merPlugState([ 'merchant_id' => $param['merchant_id'], 'identification_arr' => ['credit'] ]); if ($result['credit']) { $modelRes = $BillModel->getCreditOutlineOrder($where, $page, $num); } else { $modelRes = $BillModel->getOutlineOrder($where, $page, $num); } } $order = $modelRes['data']; $order_count = $modelRes['count']; if (!empty($order)) { $cashiInfo = []; $cashiIdArr = []; foreach ($order as $key => &$val) { if (!$val['ca_id']) { unset($val['ca_id']); } $val['coupon_money'] = $val['coupon_money'] ? $val['coupon_money'] : '0.00'; $val['pay_coupon_fee'] = $val['pay_coupon_fee'] ? floatval($val['pay_coupon_fee']) : '0.00'; $val['cashier_dis_money'] = $val['cashier_dis_money'] ? $val['cashier_dis_money'] : '0.00'; $val['small_changes_money'] = $val['small_changes_money'] ? $val['small_changes_money'] : '0.00'; $val['integral_dis_money'] = $val['integral_dis_money'] ? $val['integral_dis_money'] : '0.00'; $val['cashier_manual_money'] = $val['cashier_manual_money'] ? $val['cashier_manual_money'] : '0.00'; $val['cashier_dis_money'] = $val['cashier_dis_money'] ? $val['cashier_dis_money'] : '0.00'; $val['user_select_time'] = $val['user_select_time'] ? date('m-d H:i', $val['user_select_time']) : ''; if (!empty($val['vid'])) { $val['vipInfo'] = $VipModel->getFind(["id" => $val['vid']], "nickname,name,balance,mobile_phone,integral"); } //商城订单返回数据 if ($param['line'] == 2) { if ($val['order_genre'] == 4) { if ($val['advance_type'] == 2) { //定金 $val['earnest_pay_time'] = date('Y-m-d H:i:s', $val['earnest_pay_time']); $val['all_earnest_price'] = round($val['all_earnest_price'], 2); $val['all_arrive_price'] = $val['all_arrive_price'] ? round($val['all_arrive_price']) : ''; $val['tail_pay_money'] = round($val['all_money'] - $val['all_earnest_price'], 2); //尾款 $val['advance_type_name'] = "定金 + 尾款"; } else { //全额 $val['tail_pay_money'] = round($val['all_money'], 2); $val['finish_time'] = date('Y-m-d H:i:s', $val['finish_time']); $val['advance_type_name'] = "全额"; } if ($val['state'] == 2) { $tail_time = $PayOrderModel->getFindField(['id' => $val['tail_pay_order_id']], "trade_date"); $val['trade_date'] = date('Y-m-d H:i:s', $tail_time); } } switch ($val['delivery_type']) { case 1: //门店配送 if ($val['status'] == 1 && $value['pickup_type'] = 2) { $val['order_status'] = 0; } break; case 2: //达达配送 $clerkInfo = $DaOrderModel->getOrderFind(['order_no' => strval($val['order_no']), 'id' => $val['delivery_record_id']], '*', 'id desc'); $val['order_status'] = $clerkInfo['order_status']; break; case 3: //Uu配送转成达达订单状态显示 $state_uu = $uuOrderModel->getOrderFindField(['origin_id' => $val['id'], 'id' => $val['delivery_record_id']], 'state', 'id desc'); if ($state_uu == 1) { $val['order_status'] = 1; } else if ($state_uu == 3 || $state_uu == 4) { $val['order_status'] = 2; } else if ($state_uu == 5 || $state_uu == 6) { $val['order_status'] = 3; } else if ($state_uu == -1) { $val['order_status'] = 5; } else { $val['order_status'] = 4; } $val['delivery'] = 2; break; case 5: //码科配送 $MakeOrderModel = new MakeOrderModel(); $status = $MakeOrderModel->getOrderFindField(['bill_id' => $val['id']], "status", "id desc"); switch ($status) { case 'payed': //待接单 $val['order_status'] = 1; break; case 'accepted': //'待取件 $val['order_status'] = 2; break; case 'geted': //待收件 $val['order_status'] = 3; break; case 'gotoed': //待评价 $val['order_status'] = 4; break; case 'completed': //订单已完成 $val['order_status'] = 4; break; case 'cancel': //已取消 $val['order_status'] = 5; break; } break; } if ($val['type'] == 1) { //商城 if ($val['pickup_type'] == 2) { if ($val['user_address']) { $val['address_name'] = $val['user_name']; $val['address_phone'] = $val['user_phone']; $val['address_address'] = $val['user_address']; } } else { $val['address_name'] = $val['user_name']; $val['address_phone'] = $val['user_phone']; } } switch ($val['status']) { case 0: if ($val['order_genre'] == 4 && $val['pay_state'] == 2) { if ($val['cancel_time'] > 0) { $val['state_name'] = '已申请售后'; } else if ($val['tail_end_time'] < time()) { $val['state_name'] = '超出尾款支付时间'; } else if ($val['tail_start_time'] > time()) { $val['state_name'] = '未到尾款支付时间'; } else { $val['state_name'] = '待付尾款'; } } break; case 1: if ($val['refund_status'] == 0) { $val['state_name'] = '待发货'; if ($val["pickup_type"] == 1) { $val['state_name'] = '待自取'; } } else if ($val["refund_status"] == 1) { $val['state_name'] = '已申请售后'; } break; case 2: $val['state_name'] = '待收货'; break; case 3: $val['state_name'] = '交易完成'; if ($val["refund_status"] == 1) { $val['state_name'] = '已申请售后'; } break; } } if (!empty($val['cashier_id'])) { // 防止多次查询同一收银员id if (in_array($val['cashier_id'], $cashiIdArr)) { $val['jobnum'] = $cashiInfo[$val['cashier_id']]['jobnum']; $val['cashier_name'] = $cashiInfo[$val['cashier_id']]['name']; } else { $cashier_info = $CashierModel->getFind(['id' => $val['cashier_id']], "name,jobnum"); $val['jobnum'] = $cashier_info['jobnum']; $val['cashier_name'] = $cashier_info['name']; $cashiIdArr[] = $val['cashier_id']; $cashiInfo[$val['cashier_id']] = $cashier_info; } } $val['key'] = $key + 1; //判断支付人员类型 if (!empty($val['vid']) || !empty($val['third_vip_code'])) { $val['vip_class'] = '会员'; } else { $val['vip_class'] = '散客'; } if (!empty($val['third_vip_code'])) { $val['mec_vip'] = [ 'name' => $val['third_vip_name'], 'code' => $val['third_vip_code'], ]; } if ($val['order_genre'] == 4) { $val['payList'] = $BillAdvanceModel->payMode($val); } else if ($val['settlement_type'] == 2) { $CreditRecord = new \Credit\Business\CreditRecord(); $val['payList'] = $CreditRecord->getCreditPayTypeList($val['id'], $val['all_money']); } else { $val['payList'] = getPayTypeList($val['pay_type'], $val['all_money'], $val['id']); } if (count($val['payList']) > 1) { $val['pay_type_name'] = '组合支付'; } else if ($val['settlement_type'] == 2) { $val['pay_type_name'] = '赊账'; } else { $val['pay_type_name'] = $val['payList'][0]['name']; } $fields = [ 'vip_discount', 'goods_id', 'goods_name', 'num', 'refund_num', 'vip_price', 'price', 'original_price', 'plus_vip_price', 'original_price', 'all_money', 'goods_type', 'attribute_state', 'sku_json_info', 'pricing_method', 'integral_marketing', 'mem_integral', 'use_integral', 'cashier_manual_discount', 'cashier_manual_discount_money', "company", "goods_gifts_id", "goods_gifts_type", 'id', 'serial_number_state', 'code_price_state', ]; $sellList = $SellModel->getSelect(['bill_id' => $val['id']], $fields); $beforeAllMoney = 0; $v_discount = 1; $cashier_manual_discount = 1; $GoodsModel = new RetailGoodsModel(); foreach ($sellList as &$v) { if (($v['goods_type'] == 2 || $v['goods_id'] == 0) && empty($v['goods_name'])) { $v['goods_name'] = '无码商品'; } $v['goods_code'] = ''; if ($v['goods_type'] == 1) { $v['goods_code'] = $GoodsModel->getFindField(['id' => $v['goods_id']], 'goods_code'); } if (!empty($v['sku_json_info'])) { $sku = json_decode($v['sku_json_info'], true); $v['sku_name'] = $sku['name']; if (!$v['sku_name']) { $sku_name = $SkuAttribute->basisSkuIdListSkuNameArr($sku['sku_id_list']); $v['sku_name'] = implode(',', $sku_name); } $v['sku_id'] = $sku['id']; } $v['num'] = round($v['num'], 3); if (floatval($v['vip_discount']) < 1 && floatval($v['vip_discount']) > 0) { $v_discount = floatval($v['vip_discount']); } if (floatval($v['cashier_manual_discount']) < 1 && floatval($v['cashier_manual_discount_money']) > 0) { $cashier_manual_discount = floatval($v['cashier_manual_discount']); } $v['mem_integral'] = intval($v['mem_integral']); $v['price'] = floatval($v['price']); $v['original_price'] = floatval($v['original_price']); $v['plus_vip_price'] = floatval($v['plus_vip_price']); $v['vip_price'] = floatval($v['vip_price']); $v['before_all_money'] = round($v['price'] * $v['num'], 2); $beforeAllMoney += $v['before_all_money']; //串号信息 if ($v['serial_number_state'] == 1) { $serialResult = $SerialClass->sellSerialList([ 'id' => $v['id'] ]); $v['serial_list'] = $serialResult['data']['list']; } } $val['v_discount'] = $v_discount; $val['cashier_manual_discount'] = $cashier_manual_discount; $val['beforeAllMoney'] = $beforeAllMoney; $val['goods_info'] = $sellList; //配送 $val['add_time'] = date('Y-m-d H:i:s', $val['add_time']); $val['cashier_dis_money'] = !empty($val['cashier_dis_money']) ? $val['cashier_dis_money'] : 0; //优惠金额 $val['discount_amount'] = round($val['coupon_money'] + $val['vip_dis_money'] + $val['cashier_dis_money'] + $val['small_changes_money'] + $val['cashier_manual_money'], 2); $guide_name = ''; if (!empty($val['guide_id'])) { $guide_name = $GuideModel->getFindField(['id' => $val['guide_id']], 'guidename'); } $val['guide_name'] = $guide_name; unset($val['vid']); unset($val['store_id']); unset($val['merchant_id']); unset($val['cashier_id']); if ($storePlugStatus === true) { //门店有权限,并开启插件,查询订单是否有祝福码 $extractionCode = new Index(); $val['extraction_code'] = $extractionCode->obtainExtractionCode($val['id']); } else { //门店无权限,或没开启 $val['extraction_code'] = null; } } } else { $order = []; } $res['status'] = 1; $res['order'] = $order; $res['count'] = $order_count; return $res; } /** * 获取商城流水合计 * @param $param * [ * order_number 选填 订单号 * vipCode 选填 会员信息 * judge unaccounted param * line 必填 1线下收银端 2线上小程序 * time 必填 时间段 * status 选填 类型查询条件 当line=2时必填 * order_genre 选填 1.商城订单 2.拼团订单 3.秒杀订单 4预售订单 当line=2时必填 * cashier_id 必填 收银员id * store_id 必填 门店id * ] */ public function orderOfWaterTotal($param) { $BillModel = new RetailBillOrderModel(); $verifyRes = $this->paramVerify($param, 2); $map = $verifyRes['map']; $refund_map = $verifyRes['refund_map']; //$refund_map 退款 $credit_map = $verifyRes['credit_map']; //$credit_map 赊账 $map['pay_state'] = 1; if ($param['line'] == 2) { //线上 小程序订单 $insertRes = $this->conditionInsert($param, 2); $map = array_merge($map, $insertRes); if (!empty($map)) { $map['type'] = 1; switch ($param['order_genre']) { case 1: //商城 $resBack = $BillModel->getOnlineAllData($map); //获取总条数和总金额 break; case 2: //拼团 $resBack = $BillModel->getOnlineGroupAllData($map); //获取总条数和总金额 break; case 3: //秒杀 $resBack = $BillModel->getOnlineSkillAllData($map); //获取总条数和总金额 break; case 4: //预售 $resBack = $BillModel->getAdvanceData($map); //获取总条数和总金额 break; } $order_count = $resBack['num']; $order_money = $resBack['money']; } else { $order_count = 0; $order_money = 0; } if (!empty($refund_map)) { $refund_map['type'] = 1; $refund_map['order_type'] = 2; switch ($param['order_genre']) { case 1: //商城 $resBack = $BillModel->getOnlineAllData($refund_map); //获取总条数和总金额 break; case 2: //拼团 $resBack = $BillModel->getOnlineGroupAllData($refund_map); //获取总条数和总金额 break; case 3: //秒杀 $resBack = $BillModel->getOnlineSkillAllData($refund_map); //获取总条数和总金额 break; } $refund_order_count = $resBack['num']; $refund_order_money = $resBack['money'] ? $resBack['money'] : 0; } else { $refund_order_count = 0; $refund_order_money = 0; } $all_money = $order_money - $refund_order_money; $res['order_count'] = $order_count; $res['order_money'] = $order_money; $res['refund_order_count'] = $refund_order_count; $res['refund_order_money'] = $refund_order_money; $res['all_money'] = $all_money > 0 ? round($all_money, 2) : '0'; } else { /* 收银员是否可以查看所有订单 */ $condition = [ 'map' => $map, 'refund_map' => $refund_map, 'credit_map' => $credit_map, ]; $authRes = $this->cashierAuthCheck($param, 2, $condition); $map = $authRes['condition']['map']; $refund_map = $authRes['condition']['refund_map']; $credit_map = $authRes['condition']['credit_map']; //现金支付 $map['type'] = 2; $SellDataApi = new SellDataController(); $combination = $SellDataApi->combinationPayment($map, 1); $map['pay_type'] = 1; $map['order_type'] = 1; $x_money = $BillModel->getSum($map, 'all_money'); $x_money = round($x_money + $combination['combination_xj'], 2); // 微信支付 $map['pay_type'] = ['in', '3,6']; $w_money = $BillModel->getSum($map, 'all_money'); $w_money = round($w_money + $combination['combination_wxpay'], 2); //支付宝支付 $map['pay_type'] = 4; $z_money = $BillModel->getSum($map, 'all_money'); $z_money = round($z_money + $combination['combination_zfb'], 2); //会员卡余额 $map['pay_type'] = 5; $h_money = $BillModel->getSum($map, 'all_money'); $h_money = round($h_money + $combination['combination_membermoney'], 2); //其他支付 $map['pay_type'] = 7; $other_money = $BillModel->getSum($map, 'all_money'); $other_money = round($other_money + $combination['combination_other_pay'], 2); //德育币支付 $map['pay_type'] = 9; $moralEducationCoin_money = $BillModel->getSum($map, 'all_money'); $moralEducationCoin_money = round($moralEducationCoin_money + $combination['combination_mec_pay'], 2); //赊账 $PlugApi = new Plug(); $plug_result = $PlugApi->merPlugState([ 'merchant_id' => $param['merchant_id'], 'identification_arr' => ['credit'] ]); if ($plug_result['credit']) { $ArrearageModel = new \Credit\Model\CreditArrearageModel(); $credit_map['ca.store_id'] = $param['store_id']; $credit_map['ca.status'] = 1; if ($authRes['condition']['cashier_show_other_sell'] == 2) { $credit_map['rbo.cashier_id'] = $param['cashier_id']; } $res['c_money'] = (float)$ArrearageModel->getPcCreditMoney($credit_map); } //退款金额 $refund_map['order_type'] = 2; $refund_map['pay_state'] = 1; $refund_map['type'] = 2; $refund_money = $BillModel->getSum($refund_map, 'all_money'); $refund_money = $refund_money ? round($refund_money, 2) : 0; $res['x_money'] = $x_money; $res['w_money'] = $w_money; $res['z_money'] = $z_money; $res['h_money'] = $h_money; $res['o_money'] = $other_money; $res['r_money'] = $refund_money; $res['mec_money'] = $moralEducationCoin_money; } return $res; } /** * 参数处理 * @param $param 参数 * @param $type 类型 1流水 2统计 */ private function paramVerify($param, $type) { $VipModel = new RetailVipModel(); $StoreModel = new RetailStoreModel(); $SellSerialModel = new SellSerialModel(); if (!$param['start_time'] || !$param['end_time']) { $start_time = strtotime(date('Y-m-d 0:0:0', time())); $end_time = strtotime(date('Y-m-d 0:0:0', time())) + 86399; } else { $start_time = strtotime($param['start_time']); $end_time = strtotime($param['end_time']); } // 订单号搜索 if ($param['order_num']) { switch ($param['judge']) { case 1: $where['b.order_no'] = ['like', '%' . $param['order_num']]; $map['order_no'] = ['like', '%' . $param['order_num']]; $refund_map['order_no'] = ['like', '%' . $param['order_num']]; $credit_map['rbo.order_no'] = ['like', '%' . $param['order_num']]; break; case 2: $where['o.pick_code'] = $param['order_num']; $map['o.pick_code'] = $param['order_num']; $refund_map['o.pick_code'] = $param['order_num']; break; case 3: //串码 $order_id_arr = $SellSerialModel->basisSerialOrderId($param['order_num'], 1); if (!empty($order_id_arr)) { $where['b.id'] = ['in', $order_id_arr]; $map['id'] = ['in', $order_id_arr]; $refund_map['id'] = ['in', $order_id_arr]; $credit_map['ca.id'] = ['in', $order_id_arr]; } else { $res = [ 'status' => 1, 'order' => [], 'msg' => '串号不存在', 'count' => 0, ]; return $res; } break; } unset($where['b.add_time']); unset($map['add_time']); unset($refund_map['add_time']); unset($credit_map['ca.add_time']); } if ($param['vipCode']) { $merchant_id = $StoreModel->getFindField(['id' => $param['store_id']], 'merchantid'); $vMap = [ 'mobile_phone|cardnum|card_key' => ['like', '%' . $param['vipCode'] . '%'], 'merchantid' => $merchant_id, 'status' => 1 ]; $vip_id = $VipModel->getFindField($vMap, 'id', true); } switch ($type) { case 1: $where['b.store_id'] = $param['store_id']; $where['b.pay_state'] = 1; $where['b.add_time'] = ['between', [$start_time, $end_time]]; if ($param['vipCode']) { if (empty($vip_id)) { $res = [ 'status' => 1, 'order' => [], 'msg' => '会员不存在或已被冻结、挂失', 'count' => 0, ]; return $res; } else { $where['b.vid'] = ['in', $vip_id]; } } break; case 2: $map['store_id'] = $param['store_id']; $refund_map['store_id'] = $param['store_id']; $map['add_time'] = ['between', [$start_time, $end_time]]; $refund_map['add_time'] = ['between', [$start_time, $end_time]]; $credit_map['rbo.add_time'] = ['between', [$start_time, $end_time]]; if ($param['vipCode'] && $vip_id) { $map['vid'] = ['in', $vip_id]; $credit_map['rc.vid'] = ['in', $vip_id]; } break; } if ($type == 1) { return $where; } elseif ($type == 2) { return ['map' => $map, 'credit_map' => $credit_map, 'refund_map' => $refund_map]; } } /** * 参数处理 * @param $param 参数 * @param $type 类型 1流水 2统计 */ private function conditionInsert(&$param, $type) { switch ($param['order_genre']) { case 2: //拼团 $condition['g.state'] = ['in', '2,3']; break; case 3: //秒杀 $condition['s.state'] = ['in', '0,1']; break; case 4: $condition['a.state'] = ['in', '1,2']; break; } switch ($param['status']) { case 0: // 全部订单 $condition['order_type'] = 1; break; case 1: // 待自提订单 $condition['o.pickup_type'] = 1; $condition['order_type'] = 1; $condition['o.status'] = 1; $condition['refund_status'] = 0; break; case 2: // 已自提订单 $condition['o.pickup_type'] = 1; $condition['order_type'] = 1; $condition['o.status'] = 3; $condition['refund_status'] = 0; break; case 3: // 待发货 $condition['o.pickup_type'] = 2; $condition['order_type'] = 1; $condition['o.status'] = 1; $condition['refund_status'] = 0; break; case 4: // 配送中 $condition['o.pickup_type'] = 2; $condition['order_type'] = 1; $condition['o.status'] = 2; $condition['refund_status'] = 0; break; case 5: // 已收货 $condition['o.pickup_type'] = 2; $condition['order_type'] = 1; $condition['o.status'] = 3; $condition['refund_status'] = 0; break; case 6: // 正常购买 $condition['order_type'] = 1; $condition['refund_status'] = 0; break; case 9: // 购买订单 $condition['order_type'] = 1; break; case 10: //待付尾款已过期 $condition['a.state'] = 1; $condition['a.tail_end_time'] = ['lt', time()]; $condition['a.advance_type'] = 2; break; case 11: //待付尾款未过期 $condition['a.state'] = 1; $condition['a.tail_end_time'] = ['gt', time()]; $condition['a.advance_type'] = 2; break; case 12: //已付款 $condition['a.state'] = 2; break; default: $condition['order_type'] = 1; } switch ($type) { case 1: $condition['pay_state'] = ['in', '1,2']; $condition['type'] = 1; $condition['b.order_type'] = 1; break; case 2: $condition['pay_state'] = ['in', '1,2']; $condition['o.order_genre'] = $param['order_genre']; $condition['b.order_type'] = 1; break; } return $condition; } /** * 收银员是否可以查看所有订单 * @param $param 参数 * @param $type 类型 1流水 2统计 */ private function cashierAuthCheck($param, $type, $condition) { $CashierModel = new RetailCashierModel(); $cashier_show_other_sell = $CashierModel->getFindField(['id' => $param['cashier_id']], 'cashier_show_other_sell'); $cashier_show_other_sell = $cashier_show_other_sell ? $cashier_show_other_sell : 2; switch ($type) { case 1: $where = $condition; //选择赊账状态 1未还清 2已还清 if ($param['credit_type']) { $where['ca.state'] = $param['credit_type'] == 1 ? 2 : 1; } //支付方式 1微信 2支付宝 3现金 4余额 5德育币支付 if ($param['pay_type']) { switch ($param['pay_type']) { case 1: $where['b.pay_type'] = 3; break; case 2: $where['b.pay_type'] = 4; break; case 3: $where['b.pay_type'] = 1; break; case 4: $where['b.pay_type'] = 5; break; case 5: $where['b.pay_type'] = 9; break; } } //订单类型 1普通订单 2赊账订单 $PlugApi = new Plug(); $plug_result = $PlugApi->merPlugState([ 'merchant_id' => $param['merchant_id'], 'identification_arr' => ['credit'] ]); if ($param['bill_type'] && $plug_result['credit']) { $where['b.settlement_type'] = $param['bill_type']; } break; case 2: $map = $condition['map']; $refund_map = $condition['refund_map']; $credit_map = $condition['credit_map']; break; } if ($cashier_show_other_sell == 2) { // 收银员查看自己订单 $where['b.cashier_id'] = $param['cashier_id']; $map['cashier_id'] = $param['cashier_id']; $refund_map['cashier_id'] = $param['cashier_id']; $credit_map['ca.cashier_id'] = $param['cashier_id']; } $condition = [ 'map' => $map, 'refund_map' => $refund_map, 'credit_map' => $credit_map, ]; if ($type == 1) { return $where; } else if ($type == 2) { return ['condition' => $condition, 'cashier_show_other_sell' => $cashier_show_other_sell]; } } }