123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的saas管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\service\admin\pay;
- use app\dict\common\ChannelDict;
- use app\dict\pay\PayDict;
- use app\model\pay\Pay;
- use app\service\core\paytype\CoreOfflineService;
- use core\base\BaseAdminService;
- /**
- * 支付服务层
- */
- class PayService extends BaseAdminService
- {
- public function __construct()
- {
- parent::__construct();
- $this->model = new Pay();
- }
- /**
- * 支付记录表
- * @param array $where
- * @return array
- */
- public function getPage(array $where)
- {
- $field = 'id, site_id, main_id, out_trade_no, trade_type, trade_id, trade_no, body, money, voucher, status, json, create_time, pay_time, cancel_time, type, mch_id, main_type, channel, fail_reason';
- $search_model = $this->model->where([ [ 'status', 'in', '2,3' ] ])->withSearch([ 'create_time', 'out_trade_no', 'type', 'channel' ], $where)
- ->with([
- 'member' => function($query) {
- $query->field('member_id, nickname, headimg, mobile');
- }
- ])
- ->field($field)->append([ 'type_name', 'channel_name', 'status_name' ])->order('create_time desc');
- return $this->pageQuery($search_model);
- }
- /**
- * 待审核支付记录
- * @param array $where
- * @return array
- */
- 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 array
- */
- 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);
- }
- /**
- * 按支付方式统计支付金额
- * @return array
- */
- public function getPayTypeStat()
- {
- $data = [];
- $list = array_filter(PayDict::getPayType(), function($value){
- return $value['key'] !== PayDict::FRIENDSPAY;
- });
- $pay_type_list = array_keys($list);
- foreach ($pay_type_list as $type) {
- $sum = $this->model->where([ [ 'type', '=', $type ], [ 'status', '=', PayDict::STATUS_FINISH ] ])->sum('money');
- $data[ $type ] = $sum;
- }
- return $data;
- }
- /**
- * 按支付渠道统计支付金额
- * @return array
- */
- public function getChannelStat()
- {
- $data = [];
- $channel_list = array_keys(ChannelDict::getType());
- foreach ($channel_list as $channel) {
- $sum = $this->model->where([ [ 'channel', '=', $channel ], [ 'status', '=', PayDict::STATUS_FINISH ] ])->sum('money');
- $data[ $channel ] = $sum;
- }
- return $data;
- }
- }
|