123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace app\api\controller\user;
- use app\models\system\SystemGroupData;
- use app\models\user\UserMobileRecharge;
- use app\Request;
- use crmeb\services\UtilService;
- use think\facade\Log;
- /**
- * 充值类
- * Class UserRechargeController
- * @package app\api\controller\user
- */
- class MobileRechargeController
- {
- /**
- * 小程序充值
- *
- * @param Request $request
- * @return mixed
- */
- public function routine(Request $request)
- {
- list($recharId, $mobile) = UtilService::postMore([['rechar_id', 0], ['mobile', '']], $request, true);
- if (!$recharId) return app('json')->fail('请选择充值金额!');
- if (!not_empty_check($mobile) || !mobile_check($mobile)) return app('json')->fail('请输入正确的手机号码!');
- if ($recharId) {
- $data = SystemGroupData::getDateValue($recharId);
- if ($data === false) {
- return app('json')->fail('您选择的充值方式已下架!');
- } else {
- $get_money = $data['get_money'] ?? 0;
- }
- }
- $price = $data['price'];
- $rechargeOrder = UserMobileRecharge::addRecharge($request->uid(), $mobile, $price, 'weixin', $get_money);
- if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
- try {
- return app('json')->successful(UserMobileRecharge::jsPay($rechargeOrder));
- } catch (\Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- }
- /**
- * 支付宝充值
- *
- * @param Request $request
- * @return mixed
- */
- public function ali(Request $request)
- {
- list($recharId, $mobile) = UtilService::postMore([['rechar_id', 0], ['mobile', '']], $request, true);
- if (!$recharId) return app('json')->fail('请选择充值金额!');
- if (!not_empty_check($mobile) || !mobile_check($mobile)) return app('json')->fail('请输入正确的手机号码!');
- if ($recharId) {
- $data = SystemGroupData::getDateValue($recharId);
- if ($data === false) {
- return app('json')->fail('您选择的充值方式已下架!');
- } else {
- $get_money = $data['get_money'] ?? 0;
- }
- }
- $price = $data['price'];
- $rechargeOrder = UserMobileRecharge::addRecharge($request->uid(), $mobile, $price, 'ali', $get_money);
- if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
- try {
- return app('json')->successful(UserMobileRecharge::aliPay($rechargeOrder));
- } catch (\Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- }
- /**
- * 支付宝充值
- *
- * @param Request $request
- * @return mixed
- */
- public function app(Request $request)
- {
- list($recharId, $mobile) = UtilService::postMore([['rechar_id', 0], ['mobile', '']], $request, true);
- if (!$recharId) return app('json')->fail('请选择充值金额!');
- if (!not_empty_check($mobile) || !mobile_check($mobile)) return app('json')->fail('请输入正确的手机号码!');
- if ($recharId) {
- $data = SystemGroupData::getDateValue($recharId);
- if ($data === false) {
- return app('json')->fail('您选择的充值方式已下架!');
- } else {
- $get_money = $data['get_money'] ?? 0;
- }
- }
- $price = $data['price'];
- $rechargeOrder = UserMobileRecharge::addRecharge($request->uid(), $mobile, $price, 'app', $get_money);
- if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
- try {
- return app('json')->successful(UserMobileRecharge::appPay($rechargeOrder));
- } catch (\Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- }
- /**
- * 公众号充值
- *
- * @param Request $request
- * @return mixed
- */
- public function wechat(Request $request)
- {
- list($recharId, $mobile, $from) = UtilService::postMore([['rechar_id', 0], ['mobile', ''], ['from', 'weixin']], $request, true);
- if (!$recharId) return app('json')->fail('请选择充值金额!');
- if (!not_empty_check($mobile) || !mobile_check($mobile)) return app('json')->fail('请输入正确的手机号码!');
- if ($recharId) {
- $data = SystemGroupData::getDateValue($recharId);
- if ($data === false) {
- return app('json')->fail('您选择的充值方式已下架!');
- } else {
- $get_money = $data['get_money'] ?? 0;
- }
- }
- $price = $data['price'];
- $rechargeOrder = UserMobileRecharge::addRecharge($request->uid(), $mobile, $price, 'weixin', $get_money);
- if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
- try {
- if ($from == 'weixinh5') {
- $recharge = UserMobileRecharge::wxH5Pay($rechargeOrder);
- } else {
- $recharge = UserMobileRecharge::wxPay($rechargeOrder);
- }
- } catch (\Exception $e) {
- return app('json')->fail($e->getMessage());
- }
- return app('json')->successful(['type' => $from, 'data' => $recharge]);
- }
- /**
- * 充值额度选择
- * @return mixed
- */
- public function index()
- {
- $rechargeQuota = sys_data('user_mobile_recharge_quota') ?? [];
- $data['recharge_quota'] = $rechargeQuota;
- $recharge_attention = sys_config('mobile_recharge__attention');
- $recharge_attention = explode("\n", $recharge_attention);
- $data['recharge_attention'] = $recharge_attention;
- return app('json')->successful($data);
- }
- public function notify(Request $request)
- {
- $date = $request->post();
- if ($date['status'] == 'SUCCESS') {
- UserMobileRecharge::where('order_id', $date['orderId'])->update(['status', 1]);
- return 'SUCCESS';
- } else {
- UserMobileRecharge::where('order_id', $date['orderId'])->update(['status', 2]);
- Log::error($date['orderId'] . '充值失败');
- return 'SUCCESS';
- }
- }
- }
|