yunPayService)) { return $this->yunPayService = new YunPayService(['mall_id' => $this->mall_id]); } return $this->yunPayService; } /** * 获取分页列表 * * @param array $params * @return array */ public function getPageList(array $params = []) { $limit = $params['limit'] ?? 20; $page = $params['page'] ?? 1; $model = AgentOrder::find(); $model->with(['user' => function ($query) { $query->select(['id', 'mall_id', 'nickname', 'mobile', 'avatar_url']); }]); $model->with(['store' => function ($query) { $query->select(['id', 'mall_id', 'store_name']); }]); $model->andWhere(['mall_id' => $this->mall_id]); if (!empty($params['user_id'])) { $model->andWhere(['user_id' => $params['user_id']]); } if (!empty($params['user_keyword'])) { $model->andWhere([ 'user_id' => User::getUserIdsByKeyword($this->mall_id, $params['user_keyword']) ]); } if (!empty($params['acct_keyword'])) { $model->andWhere([ 'or', ['=', 'acct_name', $params['acct_keyword']], ['=', 'acct_number', $params['acct_keyword']], ]); } if (!empty($params['order_no'])) { $model->andWhere([ 'trade_id' => PaymentTrade::getIdsByNo($this->mall_id, $params['order_no']) ]); } if (!empty($params['time'])) { $model->andFilterWhere([ 'between', 'created_at', strtotime($params['time'][0]), strtotime($params['time'][1]) ]); } $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]); $model->limit($pagination->limit)->offset($pagination->offset); $list = $model->orderBy('id desc') ->asArray() ->all(); foreach ($list as $k => $v) { $list[$k]['res_data'] = Json::decode($v['res_data']); } $data['list'] = $list; $data['page_count'] = $pagination->pageCount; $data['current_page'] = $page + 1; return $data; } /** * 代付 * * @param WithdrawLog $log * @return int */ public function agentPay(WithdrawLog $log) { $service = $this->getYunPayService(); // 提现信息 $info = Json::decode($log->extra); if (!empty($info['name']) && !empty($info['bank_account'])) { // 代付类 $trans = new AgentTrans( $log->order_no . mt_rand(1000, 9999), $log->actual_num, $info['bank_account'], $info['name'], sprintf('订单%s提现', $log->order_no) ); // 如果设置账户类型 if (!empty($info['bank_account_type'])) { $trans->setAcctType($info['bank_account_type']); } // 执行代付 $res = $service->sendPayRq($trans); // 添加代付记录 $reqData = $service->getReqData(); /** * @var AgentOrder */ $model = AgentOrder::addLog([ 'mall_id' => $this->mall_id, 'user_id' => $log->user_id, 'withdraw_id' => $log->id, 'trans_amount' => $reqData['transAmt'], 'order_no' => $reqData['outOrderId'], 'acct_number' => $reqData['settleAcct'], 'acct_name' => $reqData['settleAcctNm'], 'acct_type' => $trans->getAcctType(), 'req_data' => $reqData, 'res_data' => $res, 'status' => $res['transStatus'] ?? '', ]); // 申请失败 if ($res['respCode'] != '0000') { $msg = $res['respMsg']; $model->agree($log, $msg); return $this->error($msg); } else { // 打款失败 if ($res['transStatus'] == '102') { $msg = $res['respMsg']; $model->agree($log, $msg); return $this->error($msg); } // 打款成功 if ($res['transStatus'] == '100') { $model->success($log); return $log->id; } } } else { $msg = '账户信息有误'; WithdrawLog::remit_fail($log, $msg); return $this->error($msg); } return $log->id; } /** * 回调处理 * * @param array $respData * @return boolean */ public function notify(array $respData) { /** * @var AgentOrder */ $order = AgentOrder::getOrderByNo($this->mall_id, $respData['outOrderId']); // 订单完成不处理 if ($order->status == '100') return true; if ($order->type == 1) { /** * 提现订单 * @var WithdrawLog */ $log = $order->withdrawLog; if ('100' == $respData['transStatus']) { // 对比金额 if ($log->actual_num == $respData['transAmt']) { $order->success($log, '100', $respData); return true; } } else if ('102' == $respData['transStatus']) { // 交易失败 $msg = $respData['respMsg'] ?? $respData['resDesc']; $order->agree($log, $msg, '102', $respData); return $this->error($msg); } else { $msg = $respData['respMsg'] ?? $respData['resDesc']; $order->agree($log, $msg, $respData['transStatus'], $respData); // 未知结果,这种情况不会有。 return $this->error('未知情况'); } } if ($order->type == 2) { /** * 分账订单 * @var SplitbillItem */ $log = $order->splitbillLog; if ('100' == $respData['transStatus']) { // 对比金额 if ($log->amount == $respData['transAmt']) { $order->successByStore('100', $respData); return true; } } else if ('102' == $respData['transStatus']) { // 交易失败 $msg = $respData['respMsg']; $order->failByStore('102', $respData); return $this->error($msg); } else { // 未知结果,这种情况不会有。 return $this->error('未知情况'); } } } }