model = new Pay(); } /** * 待审核支付记录 * @param array $where * @return mixed */ public function getAuditPage(array $where) { $field = 'id, out_trade_no, type, money, body, voucher, create_time, trade_id, trade_type, status'; $search_model = $this->model->where([['type', '=', PayDict::OFFLINEPAY]])->withSearch(['create_time', 'out_trade_no', 'status'], $where)->field($field)->append(['type_name'])->order('create_time desc'); return $this->pageQuery($search_model); } /** * 获取交易详情 * @param int $id * @return void */ public function getDetail(int $id) { $field = 'id,out_trade_no,trade_type,trade_id,trade_no,body,money,voucher,status,create_time,pay_time,cancel_time,type,channel,fail_reason'; return $this->model->where([['id', '=', $id]]) ->field($field) ->append(['type_name', 'channel_name', 'status_name']) ->findOrEmpty() ->toArray(); } /** * 支付审核通过 * @param string $out_trade_no * @return null */ public function pass(string $out_trade_no) { return (new CoreOfflineService())->pass($out_trade_no); } /** * 支付审核未通过 * @param string $out_trade_no * @param string $reason */ public function refuse(string $out_trade_no, string $reason) { return (new CoreOfflineService())->refuse($out_trade_no, $reason); } /** * 统计支付数据 * @param $where * @return int * @throws \think\db\exception\DbException */ public function payCount($where) { return $this->model->where($where)->count(); } /** * 去支付 * @param string $type * @param string $trade_type * @param int $trade_id * @param string $return_url * @param string $quit_url * @param string $buyer_id * @return mixed * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function pay(string $type, string $trade_type, int $trade_id, string $return_url = '', string $quit_url = '', string $buyer_id = '', string $voucher = '', string $openid = '') { return (new CorePayService())->pay($trade_type, $trade_id, $type, ChannelDict::PC, $openid, $return_url, $quit_url, $buyer_id, $voucher); } /** * 获取支付信息 * @param string $trade_type * @param int $trade_id * @return array */ public function getInfoByTrade(string $trade_type, int $trade_id) { return (new CorePayService())->getInfoByTrade($trade_type, $trade_id, ChannelDict::H5); } /** * 获取找朋友帮忙付支付信息 * @param string $trade_type * @param int $trade_id * @return array */ public function getFriendspayInfoByTrade(string $trade_type, int $trade_id, string $channel) { $pay_info = (new CorePayService())->getInfoByTrade($trade_type, $trade_id, ChannelDict::H5, PaySceneDict::FRIENDSPAY); if (!empty($pay_info)) { //海报 $poster = (new Poster())->field('id')->where([ ['type', '=', 'friendspay'], ['status', '=', 1], ['is_default', '=', 1] ])->findOrEmpty()->toArray(); if (!empty($poster)) { $pay_info['poster_id'] = $poster['id']; } //发起帮付会员信息 $member = (new Member())->field('member_id,nickname,headimg')->where([ ['member_id', '=', $pay_info['from_main_id']] ])->findOrEmpty()->toArray(); $pay_info['member'] = $member; //二维码 $qrcode = $this->getQrcode($trade_type, $trade_id, $channel); $pay_info['link'] = $qrcode['url']; $pay_info['qrcode'] = $qrcode['path']; } return $pay_info; } /** * 获取找朋友帮忙付二维码 * @param string $trade_type * @param int $trade_id * @return array */ public function getQrcode(string $trade_type, int $trade_id, string $channel) { $url = (new CoreSysConfigService())->getSceneDomain()['wap_url']; $page = 'app/pages/friendspay/money'; $data = [ [ 'key' => 'id', 'value' => $trade_id ], [ 'key' => 'type', 'value' => $trade_type ] ]; $dir = 'upload/friendspay_qrcode'; $path = ''; try { $path = qrcode($url, $page, $data, $dir, $channel); } catch (\Exception $e) { Log::write('找朋友帮忙付二维码生成error' . $e->getMessage() . $e->getFile() . $e->getLine()); } $url = $url . '/' . $page; $scene = []; foreach ($data as $v) { $scene[] = $v['key'] . '=' . $v['value']; } $url .= '?' . implode('&', $scene); return [ 'url' => $url, 'path' => $path ]; } /** * 获取支付方式列表 * @return array|array[] * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function getPayTypeList() { $pay_type_list = (new CorePayService())->getPayTypeByTrade('', ChannelDict::H5); if (!empty($pay_type_list)) { foreach ($pay_type_list as $k => $v) { if (!in_array($v['key'], [PayDict::BALANCEPAY, PayDict::FRIENDSPAY])) { unset($pay_type_list[$k]); } } $pay_type_list = array_values($pay_type_list); } return $pay_type_list; } public function order_pay($data) { $out_trade_no = 'sm' . date("YmdHis") . time(); $order = new OrderTable(); $order_info = $order->where(['id' => $data['order_id']])->find(); $cr = new CustomerResources(); $resource_info = $cr->where(['id' => $order_info['resource_id']])->find(); $config = return_pay_config($resource_info['campus'], $data['order_id']); $params = [ 'out_trade_no' => $out_trade_no, 'body' => '订单扫码支付:' . $out_trade_no, 'money' => $order_info['order_amount'] * 100, ]; $pay = new PayLoader('Wechatpay', $config); $url = $pay->scan($params); $path = qrcode($url['code_url'], '', [], 'upload/qrcode/pay/'); $order->where(['id' => $data['order_id']])->update(['payment_id' => $out_trade_no,'ipv3' => $config['mch_secret_key']]); $payModel = new Pay(); $campus_pay = new CampusPay(); $campus_pay_info = $campus_pay->where(['campus_id' => $order_info['campus_id']])->findOrEmpty()->toArray(); $payModel->insert([ 'main_id' => $resource_info['member_id'], 'from_main_id' => $resource_info['member_id'], 'out_trade_no' => $out_trade_no, 'trade_type' => '', 'trade_id' => $data['order_id'], 'trade_no' => $out_trade_no, 'body' => '扫码支付', 'money' => $order_info['order_amount'], 'status' => 0, 'create_time' => time(), 'type' => $order_info['payment_type'], 'mch_id' => $campus_pay_info['mchid'], 'main_type' => $order_info['payment_type'], 'channel' => '微信扫码支付' ]); return ['qrcode_url' => getCurrentDomain().$path,'out_trade_no'=>$out_trade_no]; } public function check_payment_status($data) { $order = new OrderTable(); $order_status = $order->where(['payment_id' => $data['out_trade_no']])->value("order_status"); return ['order_status' => $order_status]; } }