make(UserServices::class); $userInfo = $userServices->getUserInfo($uid); } if (!$userInfo) { throw new ValidateException('用户信息不存在'); } if ($userInfo['integral'] < $orderInfo['pay_integral']) { throw new ValidateException('积分不足' . intval($orderInfo['pay_integral'])); } return true; } /** * 使用积分 * @param int $uid * @param array $orderInfo * @param $userInfo * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function integralOrderPay(int $uid, array $orderInfo, $userInfo) { $this->checkIntegralPay($uid, $orderInfo, $userInfo); $priceIntegral = $orderInfo['pay_integral']; $res = true; if ($userInfo['integral'] > 0) { /** @var UserServices $userServices */ $userServices = app()->make(UserServices::class); if ($userInfo['integral'] > $priceIntegral) { $integral = bcsub((string)$userInfo['integral'], (string)$priceIntegral); } else { $integral = 0; } $res = $userServices->update($uid, ['integral' => $integral]); /** @var UserBillServices $userBillServices */ $userBillServices = app()->make(UserBillServices::class); $res = $res && false !== $userBillServices->income('storeIntegral_use_integral', $uid, (int)$priceIntegral, (int)$integral, $orderInfo['id']); } return $res; } }