123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace app\admin\controller\notify;
- use app\admin\service\notify\RechargeService;
- use app\model\Member;
- use app\model\MemberAccount;
- use app\model\Order;
- use app\model\PayDetail;
- use support\Db;
- use support\exception\BusinessException;
- use support\Request;
- class RechargeController
- {
- /**
- * @Desc 计划任务
- * @Author Gorden
- * @Date 2024/5/29 11:31
- *
- * @return void
- */
- // public function disposePaySuccess()
- // {
- //// $unix = strtotime(date("Y-m-d H:i",strtotime("-1 minute")).':00');
- // $payDetails = PayDetail::where('pay_category', 'RECHARGE')
- // ->where('pay_status', 'SUCCESS')
- // ->where(function ($query) {
- // $query->whereRaw("JSON_EXTRACT(`pay_extend_json`, '$.notify') IS NULL")
- // ->orWhereJsonDoesntContain('pay_extend_json->notify', 'success');
- // })
- // ->get()
- // ->toArray();
- // if (!$payDetails) {
- // return;
- // }
- //
- // foreach ($payDetails as $payDetail) {
- // $this->paySuccess($payDetail['pay_id']);
- // }
- // }
- public function paySuccess(Request $request)
- {
- $data = $request->post();
- if (is_json($data)) {
- $data = json_decode($data, true);
- }
- if (!$data['pay_id']) {
- return json_fail('参数异常');
- }
- try {
- _syslog("APP充值","APP充值成功");
- return $this->disposePaySuccess($data['pay_id']);
- }catch (\Exception $e){
- _syslog("APP充值","APP充值失败");
- return json_fail("处理失败");
- }
- // public function paySuccess($id)
- // {
- // if (!$id) {
- // return json_fail('参数异常');
- // }
- //
- // $payDetail = PayDetail::find($id);
- // if ($payDetail->pay_status != 'SUCCESS') {
- // return json_fail("支付状态异常");
- // }
- }
- /**
- * @param $payId
- * @return \support\Response
- * @throws BusinessException
- */
- public function disposePaySuccess($payId){
- $payDetail = PayDetail::find($payId);
- if (!$payDetail || $payDetail->pay_status != 'SUCCESS') {
- throw new BusinessException("支付状态异常");
- // return json_fail("支付状态异常");
- }
- $extendJson = [];
- if (!empty($payDetail->pay_extend_json)) {
- $extendJson = json_decode($payDetail->pay_extend_json, true);
- if (isset($extendJson['notify']) && $extendJson['notify'] == 'success') {
- return json_success('处理完成');
- }
- }
- try {
- Db::beginTransaction();
- $extendJson['notify'] = 'success';
- $payDetail->pay_extend_json = json_encode($extendJson);
- $payDetail->save();
- // 赠送比例
- $objectJson = json_decode($payDetail->join_pay_object_json, true);
- $addedNbr = 0;
- if (isset($objectJson['order_id'])) {
- // 对应订单设置已完成
- Order::where('order_groupby',$payDetail->join_pay_order_id)->update(['order_status_system'=>'DONE','order_is_complete'=>'Y']);
- $addedNbr = RechargeService::disposeOrder($objectJson['order_id']);
-
- // throw new BusinessException("支付数据异常");
- // return json_fail("");
- }
- // 赠送金额累加到 账户表 member_account_added
- $memberAccount = MemberAccount::where('join_account_member_id', $payDetail->join_pay_member_id)
- ->where('member_account_classify', 'CASH')
- ->first();
- $payAmount = floatval($payDetail->pay_amount);
- $added = $memberAccount->member_account_added + $payAmount * $addedNbr;
- $income = $memberAccount->member_account_income + $payAmount;
- $memberAccount->member_account_added = $added;
- $memberAccount->member_account_income = $income;
- $memberAccount->member_account_surplus = $income - $memberAccount->member_account_expend;
- $memberAccount->save();
-
- // 根据最新的数据,更新用户等级
- $member = Member::find($payDetail->join_pay_member_id);
- $roleId = RechargeService::disposeRole($payDetail->join_pay_member_id, $payDetail->pay_amount);
- if ($roleId && $member->join_member_role_id != $roleId) {
- $member->join_member_role_id = $roleId;
- $member->save();
- // 处理增值套包、组件
- RechargeService::disposeAdded($roleId, $payDetail->join_pay_member_id);
- }
- Db::commit();
- return json_success('success');
- } catch (BusinessException $e) {
- dump($e->getMessage());
- Db::rollBack();
- throw new BusinessException("处理失败");
- // return json_fail('处理失败');
- } catch (\Exception $e) {
- dump($e->getMessage());
- Db::rollBack();
- throw new BusinessException("处理失败");
- // return json_fail('处理失败');
- }
- }
- }
|