'支付成功', 'REFUND' => '退款成功', 'REVOKED' => '撤销支付', 'WAIT_BUYER_PAY' => '待支付', 'WAIT_REFUND' => '待退款', ]; } /** * 订单场景类型列表 * @return array */ public function orderType() { return [ '1' => '购买商品', '2' => '会员充值', '4' => '购买礼品卡', '5' => '购买PLUS会员', '6' => '快捷收银', '7' => '购买次卡', '8' => '积分商城订单', '9' => '赊账还款', ]; } /** * 订单类型列表 * @return array */ public function sceneType() { return array( '1' => '付款订单', '2' => '退款订单', ); } /** * 支付类型列表 * @param $other_pay_id 其他支付ID * @return array */ public function payType($other_pay_id) { if ($other_pay_id) { $OtherPayModel = new RetailOtherPayModel(); return array( '5' => $OtherPayModel->getFindField(['id' => $other_pay_id], 'name'), ); } return array( '1' => '微信', '2' => '支付宝', '3' => '现金', '4' => '小程序微信', '5' => '其他支付', '6' => '会员余额', '8' => '德育币', ); } /** * 订单支付模式 * @return array */ public function merPayType() { return array( '1' => '普通商户模式', '2' => '服务商模式', '3' => '新大陆模式', '4' => '云闪付模式', '5' => '乐返模式', '6' => '拉卡拉模式', '7' => '钱客云模式', ); } /** * 获取订单状态 * @param $order_state * @return mixed */ public function getOrderState($order_state) { if ($res = $this->orderState()[$order_state]) { return $res; } else { return ''; } } /** * 获取订单场景类型描述 * @param $order_type 场景类型值 * @return mixed */ public function getOrderType($order_type) { if ($res = $this->orderType()[$order_type]) { return $res; } else { return ''; } } /** * 获取订单类型描述 * @param $scene_type 订单类型值 * @return mixed */ public function getSceneType($scene_type) { if ($res = $this->sceneType()[$scene_type]) { return $res; } else { return ''; } } /** * 获取订单支付类型描述 * @param $pay_type 支付类型值 * @param $other_pay_id 其他支付ID * @return mixed */ public function getPayType($pay_type, $other_pay_id = null) { if ($res = $this->payType($other_pay_id)[$pay_type]) { return $res; } else { return ''; } } /** * 获取订单支付模式 * @param $m_pay_type 支付模式值 * @return mixed */ public function getMerPayType($m_pay_type) { if ($res = $this->merPayType()[$m_pay_type]) { return $res; } else { return ''; } } /** * 根据购买/退款商品订单ID对应的支付列表名称及金额 * @param $bill_pay_type 商品订单表的支付类型 * @param $all_money 商品订单表的总金额 * @param $bill_id 商品订单表ID * @return array */ public function getFindPayList($bill_pay_type= '', $all_money = '', $bill_id = '') { $payList = []; switch ($bill_pay_type) { case 7: case 8: case '': //7其他支付 8组合支付 $PayOrderModel = new RetailPayOrderModel(); $list = $PayOrderModel->getSelect([ 'bill_id' => $bill_id, 'order_state' => ['in', 'SUCCESS,REFUND'], ], 'pay_type,other_pay_id,trade_amount', 'id desc'); foreach ($list as $val) { $payList[] = [ 'name' => $this->getPayType($val['pay_type'], $val['other_pay_id']), 'money' => $val['trade_amount'], 'type' => $val['pay_type'], ]; } break; default: $BillOrder = new BillOrder(); $payList[] = [ 'name' => $this->getPayType($BillOrder->getPayOrderPayType($bill_pay_type), 0), 'money' => $all_money, 'type' => $BillOrder->getPayOrderPayType($bill_pay_type), ]; } return $payList; } /** * 处理支付异常订单 * @param $order * @return mixed * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function handleWaitPayOrder($order) { if ($order['pay_type'] == 4) { //小程序微信支付 $WxMiniPay = new WxMiniPayController(); $response = $WxMiniPay->queryOrderAndUpdate($order); if ($response['status'] == 1) { $res = R($order['notify_url'], array($order)); } } else { $PaySetModel = new RetailPaySetModel(); $PayOrderModel = new RetailPayOrderModel(); $paySet = $PaySetModel->getFindMerchantConfig($order['merchant_id'], 1); //店内、公众号 第三方微信、支付宝 switch ($order['m_pay_type']) { case 1: case 2: //直连 if ($order['pay_type'] == 1) { //微信 $WxPay = new NewWxPayController(); $response = $WxPay->queryOrderAndUpdate($order); } else { //支付宝 $AliPay = new NewAliPayController(); $response = $AliPay->queryOrderAndUpdate($order); } break; case 3: //新大陆支付 $PayContinent = new PayContinentController(); $response = $PayContinent->searchAndUpdateOrder_v3($order); break; case 4: //云闪付 $CloudPay = new CloudPayController(); $response = $CloudPay->queryOrderAndUpdate($order); break; case 5: //乐返 $happyPay = new \HappyPay\Business\HappyPay(); $response = $happyPay->happyPayQueryOrder([ 'pay_order' => $order, 'config' => $paySet['config'] ]); $response['status'] = $response['result_code'] == 1 ? 1 : 0; if ($response['status'] == 1) { $save = array( 'trade_no' => $response['payInfo']['data']['batch'], 'order_state' => 'SUCCESS', 'trade_date' => strtotime(time()), 'extend_content' => json_encode($response['payInfo']), ); $PayOrderModel->updateOrder(['id' => $order['id']], $save);//更新订单信息 } break; case 6: //拉卡拉 $laKaLaPay = new \LaKaLaPay\Business\LaKaLaMis(); $response = $laKaLaPay->laKaLaPayQueryOrder([ 'pay_order' => $order, 'config' => $paySet['config'] ]); $response['status'] = $response['result_code'] == 1 ? 1 : 0; if ($response['status'] == 1) { $save = array( 'trade_no' => $response['payInfo']['respData']['tradeNo'], 'order_state' => 'SUCCESS', 'trade_date' => strtotime(time()), 'extend_content' => json_encode($response['payInfo']), ); $PayOrderModel->updateOrder(['id' => $order['id']], $save);//更新订单信息 } break; case 7: //钱客云 $moneyGuest = new \MoneyGuestPay\Business\MoneyGuest(); $response = $moneyGuest->moneyGuestQueryOrder([ 'pay_order' => $order, 'config' => $paySet['config'] ]); $response['status'] = $response['result_code'] == 1 ? 1 : 0; if ($response['status'] == 1) { $save = array( 'trade_no' => $response['payInfo']['obj']['orderNumber'], 'order_state' => 'SUCCESS', 'trade_date' => strtotime(time()), 'extend_content' => json_encode($response['payInfo']), ); $PayOrderModel->updateOrder(['id' => $order['id']], $save);//更新订单信息 } break; default: $response['status'] = 0; $response['mag'] = '查询失败'; } if ($response['status'] == 1) { switch ($order['order_type']) { case '1': //购买商品订单 $BillModel = new RetailBillOrderModel(); $bill = $BillModel->getFind(array('id' => $order['bill_id'])); $item = array( 'pay_money' => bcadd($bill['pay_money'], $order['trade_amount']), 'amount_received' => bcadd($bill['amount_received'], $order['trade_amount']), ); $BillModel->updateOrder(array('id' => $order['bill_id']), $item); $OrderApi = new OrderController(); if ($bill['type'] == 2) { if (bcsub($item['pay_money'], $bill['all_money']) == 0) { //订单已经支付完成 //开始更新商品 $res = $OrderApi->paySuccess_v1($bill['id']); } else { $res['status'] = 1; } } else { $res = $OrderApi->paySuccess_v1($bill['id']); } break; case '2': //充值订单 $RechargeApi = new RechargeController(); $res = $RechargeApi->updateOrder($order); break; case '6': //快捷收银 $res = array('status' => 1, 'msg' => '支付成功'); break; case '7': //购买次卡 $SubCardApi = new \Api\Controller\SubCardController(); $res = $SubCardApi->updataCardOrder($order); break; case '8': //积分商城 $ScoreMallApi = new ScoreMallController(); $res = $ScoreMallApi->buyNotify($order); break; } } } if ($res['status'] == 1) { $result['status'] = 1; $result['msg'] = '订单支付成功,并修复异常数据'; } else { $result['status'] = 0; $result['msg'] = $response['status'] == 1 ? '订单支付成功,但修复异常数据失败,请联系系统服务商进行处理' : '订单未支付'; } return $result; } /** * 获取购买/退款商品订单的支付流水列表 * @param $param * $param['merchant_id'] 商户ID * $param['store_id'] 商户ID * $param['order_no'] 购买商品的订单号 * @return mixed */ public function getBillPayList($param) { if (empty($param['order_no'])) { return callBack(statusCode()['error'], '缺少订单号'); } //1.查询bill订单 $BillOrderViewModel = new BillOrderViewModel(); $bMap = [ 'merchant_id' => $param['merchant_id'], 'store_id' => $param['store_id'], 'order_no' => strval($param['order_no']), ]; $order = $BillOrderViewModel->getFind($bMap, 'id,order_genre'); if (empty($order)) { return callBack(statusCode()['error'], '订单号不存在'); } //2.获取该订单的所有支付成功/退款的支付流水列表 $pay_list = $this->getBillPayOrderList($order['id']); //3.是预售订单则做额外处理 if ($order['order_genre'] == 4) { $BillAdvanceModel = new RetailBillAdvanceModel(); $advance_order = $BillAdvanceModel->getFind(['bill_id' => $order['id']]); foreach ($pay_list as &$val) { if ($advance_order['advance_type'] == 2) { if ($val['id'] == $advance_order['earnest_pay_order_id']) { $val['advance_name'] = '定金'; } else if ($val['id'] == $advance_order['tail_pay_order_id']) { $val['advance_name'] = '尾款'; } } else { $val['advance_name'] = '全额'; } } } return callBack(statusCode()['success'], '获取成功', $pay_list); } /** * 根据购买/退款商品订单ID获取支付流水列表 * @param $bill_id * @return array * @throws \think\db\exception\DbException * @throws \think\exception\DbException */ public function getBillPayOrderList($bill_id) { $list = M('retail_pay_order as p') ->join('ls_retail_other_pay as o on o.id=p.other_pay_id', 'LEFT') ->field('p.id,p.pay_type,p.other_pay_id,p.trade_amount,p.trade_no,p.out_trade_no,p.scene_type' . ',o.name') ->where(['bill_id' => $bill_id, 'order_state' => ['in', 'SUCCESS,REFUND']]) ->select(); $payList = []; foreach ($list as $val) { $payList[] = [ 'id' => $val['id'],//支付流水表ID 'pay_name' => $val['name'] ? $val['name'] : $this->getPayType($val['pay_type']),//支付类型 'trade_amount' => $val['trade_amount'], 'trade_no' => $val['trade_no'],//外部订单号 'out_trade_no' => $val['out_trade_no'],//内部订单号 'type' => intval($val['pay_type']),//支付类型的编号 'scene_type' => $this->getSceneType($val['scene_type']), ]; } return $payList; } }