StoredProcedure.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. namespace App\Services;
  3. use App\Facade\TableName;
  4. use App\Http\helper\NumConfig;
  5. use App\Models\AccountsInfo;
  6. use App\Notification\TelegramBot;
  7. use App\Util;
  8. use Carbon\Carbon;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Facades\Log;
  11. use PHPUnit\Util\RegularExpressionTest;
  12. // 执行存储过程
  13. class StoredProcedure
  14. {
  15. /**
  16. * 用户单控标签
  17. * @param int $UserID
  18. * @param int $type -- 1,充值 2.提现 3.单控 4.无 5.单控结束 6.进其他1 7.进其他2 8.出
  19. * @param $value
  20. *
  21. */
  22. public static function user_label($UserID, $type, $value = 0)
  23. {
  24. if ($type == 2) { // 提现和充值 统一 元
  25. $value = $value / NumConfig::NUM_VALUE;
  26. }
  27. // DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec CheckAccountsLabel $UserID,$type,$value,1");
  28. }
  29. /**
  30. * 受限用户获取标签
  31. * @param int $UserID 用户ID
  32. * @return array
  33. */
  34. public static function GetUserTabTypeEx($UserID)
  35. {
  36. $result = DB::connection('write')->select("SET NOCOUNT ON use QPTreasureDB exec GSP_GP_GetUserTabTypeEx $UserID");
  37. return $result;
  38. }
  39. // 执行存储过程,-- 防刷处理机制
  40. public static function SetUserTabType($UserID)
  41. {
  42. $result = DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec GSP_GP_SetUserTabState $UserID,13");
  43. return $result;
  44. }
  45. // 查询用户标签
  46. public static function getUserTab($UserID)
  47. {
  48. $result = DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec GSP_GP_GetUserTabAllType $UserID");
  49. return $result;
  50. }
  51. // 周卡
  52. public static function BuyMonthCard($UserID, $CardID, $orderSN)
  53. {
  54. $result = DB::connection('write')->select("SET NOCOUNT ON use QPPlatformDB exec GSP_GP_BuyMonthCard $UserID,$CardID,$orderSN");
  55. return $result;
  56. }
  57. /**
  58. * 首充10元存储
  59. * @param $UserID // 用户ID
  60. * @param $RechargeNum // 充值金额 分
  61. * @param int $type // 1、购买验证[能不能充10元首充] 2、购买完成[首充成功后调用]
  62. * @return array
  63. */
  64. public static function FirstCharge($UserID, $RechargeNum = 0, $type = 1)
  65. {
  66. if ($type == 1) { // 购买时的判断
  67. $result = DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec GSP_GR_RechargeActiveCheck $UserID");
  68. } else {
  69. $result = DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec GSP_GR_RechargeActiveInit $UserID,$RechargeNum");
  70. }
  71. return $result;
  72. }
  73. /**
  74. * 网页注册-- 裂变
  75. * @param string $Accounts 用户帐号
  76. * @param string $NickName 用户昵称
  77. * @param string $Spreader 推荐帐号
  78. * @param string $LogonPass 登录密码
  79. * @param string $InsurePass 银行密码
  80. * @param int $FaceI 头像标识
  81. * @param int $Gender 用户性别
  82. * @param string $PassPortID 身份证号
  83. * @param string $Compellation 真实名字
  84. * @param string $ClientIP 连接地址
  85. * @param string $MachineID 机器标识
  86. * @param int $Type 注册类型,0:facebook(微信),1:游客,2:手机号
  87. * @param int $Channel 渠道 0、100 官方渠道
  88. * @param string $PackageName 包名
  89. * @return mixed
  90. */
  91. public static function ALLRegisterAccounts($Accounts, $NickName, $Spreader, $LogonPass, $InsurePass, $FaceI, $Gender, $PassPortID, $Compellation, $ClientIP, $MachineID, $Type, $Channel, $PackageName)
  92. {
  93. $sql = "DECLARE @return_value int
  94. set nocount on
  95. EXEC @return_value =QPAccountsDB.dbo.GSP_GP_ALLRegisterAccountsN '$Accounts',$NickName,$Spreader, '$LogonPass','$InsurePass', $FaceI, $Gender, $PassPortID, '$Compellation', '$ClientIP', '$MachineID', $Type, $Channel, '$PackageName', 0,1
  96. SELECT 'ReturnValue' = @return_value";
  97. $maxRetries = 2;
  98. $retryCount = 0;
  99. $success = false;
  100. while ($retryCount < $maxRetries && !$success) {
  101. try {
  102. $dbh = DB::connection()->getPdo();
  103. $dbh->exec("USE QPAccountsDB");
  104. $stmt = $dbh->prepare($sql);
  105. $stmt->execute();
  106. $retval = $stmt->fetch(\PDO::FETCH_ASSOC);
  107. return $retval;
  108. } catch (\Exception $e) {
  109. //已经有数据立马返回
  110. $retval = AccountsInfo::where('Accounts', $Accounts . $Channel)->first();
  111. if ($retval) {
  112. $retval = $retval->toArray();
  113. return $retval;
  114. }
  115. if ($e->getCode() == '40001') { // Deadlock error code
  116. $retryCount++;
  117. sleep(1); // Wait for a second before retrying
  118. continue;
  119. }
  120. Log::error("Reg Error :" . $e->getMessage() . "|||" . $sql . "|||" . json_encode($retval));
  121. }
  122. }
  123. return $retval;
  124. }
  125. /**
  126. * 绑定手机号
  127. * @param string $phone 手机号
  128. * @param string $LogonPass 登录密码
  129. * @param int $UserID 登录密码
  130. * @return mixed
  131. */
  132. public static function bindSms($phone, $LogonPass, $UserID)
  133. {
  134. $dbh = DB::connection()->getPdo();
  135. $stmt = $dbh->prepare("DECLARE @return_value int
  136. set nocount on use QPAccountsDB
  137. EXEC @return_value = GSP_GP_BindSmsDirect '$phone', '$LogonPass',$UserID
  138. SELECT 'ReturnValue' = @return_value");
  139. $stmt->execute();
  140. $retval = $stmt->fetch(\PDO::FETCH_ASSOC);
  141. return $retval;
  142. }
  143. /**
  144. * 裂变 -- 充值返利 获取可领额度
  145. * @param $UserID
  146. * @param $Type -- 1下级,2下下级
  147. * @return array
  148. */
  149. public static function recharge($UserID, $Type)
  150. {
  151. $result = DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec AgentQueryUserList $UserID,$Type");
  152. return $result;
  153. }
  154. /**
  155. * 裂变 -- 领取充值额度
  156. * @param $UserID
  157. * @param $Type
  158. * @return array
  159. */
  160. public static function receiveRecharge($UserID, $Type)
  161. {
  162. $result = DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec AgentRebateWithDraw $UserID,$Type");
  163. return $result;
  164. }
  165. /**
  166. * 获取登陆IP
  167. * @param $PackageName
  168. * @return array
  169. */
  170. public static function getLoginIPMap($PackageName)
  171. {
  172. $result = DB::connection('write')->select("SET NOCOUNT ON use QPPlatformDB exec GSP_GR_GetLoginIPMap '{$PackageName}'");
  173. return $result;
  174. }
  175. public static function addPlatformData($UserID, $Type, $Money)
  176. {
  177. Log::info('addPlatformData执行:'.$Type,compact("Type","Money"));
  178. $isFirst = $Extra = $Channel = 0;
  179. if ($Type == 3) {
  180. $isFirst = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew')
  181. ->where('UserID', $UserID)
  182. ->where('DateID', date('Ymd'))
  183. ->value('Recharge');
  184. } elseif ($Type == 4) {
  185. $isFirst = DB::table(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew')
  186. ->where('UserID', $UserID)
  187. ->where('DateID', date('Ymd'))
  188. ->value('Withdraw');
  189. Util::WriteLog('addPlatformData_with',$isFirst);
  190. }
  191. // 查找用户渠道
  192. $Channel = DB::connection('write')->table(TableName::QPAccountsDB() . 'AccountsInfo')
  193. ->where('UserID', $UserID)->select('Channel', 'RegisterDate')->first();
  194. $RegisterDate = $Channel->RegisterDate ?? '';
  195. $Channel = $Channel->Channel ?? 0;
  196. if (empty((int)$isFirst)) $Extra = 1;
  197. if($UserID == 4293017 && $Type == 3){
  198. // $Channel = 101;
  199. }
  200. $result = DB::connection('write')->select("DECLARE @return_value int
  201. SET NOCOUNT ON use QPRecordDB exec GSP_GP_AddPlatformData $Type,$Channel,$Money,$Extra
  202. SELECT 'ReturnValue' = @return_value
  203. ");
  204. if ($Type == 3 || $Type == 4) {
  205. (new \App\Models\RecordPlatformData())->OldUser($UserID, $Channel, $Money, $Extra,$Type);
  206. (new \App\Models\RecordPlatformData())->Today($Channel, $Money, $RegisterDate, $Extra,$Type);
  207. if($Type == 3){
  208. // 广告来源充值统计
  209. (new AdRecharge())->attribute($UserID, $RegisterDate, $Money,$Extra);
  210. }
  211. $callback = DB::table(TableName::agent() . 'UserCallBack')->where('UserID', $UserID)->first();
  212. if($callback){
  213. $update = [];
  214. if($Type == 3){
  215. $update = [
  216. 'recharge' => $callback->recharge+$Money,
  217. //'CallbackDate' => date('Y-m-d H:i:s')
  218. ];
  219. }
  220. if($Type == 4){
  221. $update = [
  222. 'withdraw' => $callback->withdraw+$Money,
  223. //'CallbackDate' => date('Y-m-d H:i:s')
  224. ];
  225. }
  226. if($update)
  227. DB::table(TableName::agent() . 'UserCallBack')->where('UserID', $UserID)->update($update);
  228. }
  229. }
  230. return $result;
  231. }
  232. /**
  233. * 用户可提现余额
  234. * @param $UserID
  235. * @return mixed
  236. */
  237. public static function GetWithDrawLimit($UserID)
  238. {
  239. $dbh = DB::connection()->getPdo();
  240. $stmt = $dbh->prepare("DECLARE @return_value int
  241. set nocount on use QPAccountsDB
  242. EXEC @return_value = GSP_GR_GetWithDrawLimit $UserID
  243. SELECT 'ReturnValue' = @return_value");
  244. $stmt->execute();
  245. $retval = $stmt->fetch(\PDO::FETCH_ASSOC);
  246. return $retval;
  247. }
  248. public static function QueryVersionNew($CurVersion, $UserID, $Channel, $ChannelIdx, $VersionCode, $UserVPN, $LocalIP, $LocalTime, $PackageName)
  249. {
  250. $result = DB::connection('write')->select("SET NOCOUNT ON use QPAccountsDB exec GSP_GP_QueryVersionNew $CurVersion,$UserID,$Channel,$ChannelIdx,$VersionCode,$UserVPN,$LocalIP,$LocalTime,'$PackageName'");
  251. return $result;
  252. }
  253. }