WokerTask/app/middleapi/controller/RechargeController.php

99 lines
3.4 KiB
PHP
Raw Permalink Normal View History

2023-12-27 14:06:33 +08:00
<?php
namespace app\middleapi\controller;
use app\adminapi\logic\recharge\RechargeLogic;
use app\adminapi\validate\recharge\RechargeRefundValidate;
use app\common\model\recharge\RechargeOrder;
use app\common\service\FileService;
use app\common\controller\BaseLikeAdminController;
/**
* 充值控制器
* Class RechargeController
* @package app\adminapi\controller\recharge
*/
class RechargeController extends BaseLikeAdminController
{
/**
* @notes 充值记录
* @return \think\response\Json
* @author 段誉
* @date 2023/2/24 16:01
*/
public function lists()
{
if(!$this->request->isPost()){
return $this->fail('请求方式错误');
}
$params = $this->request->post(['page_no','page_size', 'user_info', 'start_time', 'end_time', 'sn', 'pay_way', 'pay_status' ]);
$where = [];
if (!empty($params['sn'])) {
$where[] = ['ro.sn', '=', $params['sn']];
}
if (!empty($params['pay_way'])) {
$where[] = ['ro.pay_way', '=', $params['pay_way']];
}
if (!empty($params['pay_status'])) {
$where[] = ['ro.pay_status', '=', $params['pay_status']];
}
if (!empty($params['user_info'])) {
$where[] = ['u.sn|u.nickname|u.mobile', 'like', '%' . $params['user_info'] . '%'];
}
if (!empty($params['start_time']) && !empty($params['end_time'])) {
$where[] = ['ro.create_time', 'between', [strtotime($params['start_time']), strtotime($params['end_time'])]];
}
$pageNo = !empty($params['page_no']) ? $params['page_no'] : 1;
$pageSize = !empty($params['page_size']) ? $params['page_size'] : 20;
$field = 'ro.id,ro.sn,ro.order_amount,ro.pay_way,ro.pay_time,ro.pay_status,ro.create_time,ro.refund_status';
$field .= ',u.avatar,u.nickname,u.company_id';
$data = RechargeOrder::alias('ro')
->join('user u', 'u.id = ro.user_id')
->join('admin a', 'u.admin_id = a.id')
->join('company c', 'u.company_id = c.id')
->field($field)
->where($where)
->order('ro.id', 'desc')
->page($pageNo, $pageSize)
->append(['pay_status_text', 'pay_way_text'])
->select()
->toArray();
foreach ($data as &$item) {
$item['avatar'] = FileService::getFileUrl($item['avatar']);
$item['pay_time'] = empty($item['pay_time']) ? '' : date('Y-m-d H:i:s', $item['pay_time']);
}
$count = RechargeOrder::alias('ro')
->join('user u', 'u.id = ro.user_id')
->join('admin a', 'u.admin_id = a.id')
->join('company c', 'u.company_id = c.id')
->where($where)->count();
$result = [
'lists' => $data,
'count' => $count,
'page_no' => $pageNo,
'page_size' => $pageSize
];
return $this->success('请求成功',$result);
}
/**
* @notes 退款
* @return \think\response\Json
* @author 段誉
* @date 2023/2/28 17:29
*/
public function refund()
{
$params = (new RechargeRefundValidate())->post()->goCheck('refund');
$adminId = 1;
$result = RechargeLogic::refund($params, $adminId);
list($flag, $msg) = $result;
if(false === $flag) {
return $this->fail($msg);
}
return $this->success($msg, [], 1, 1);
}
}