GameLogic.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/4/12
  6. * Time: 9:32
  7. */
  8. namespace Biz\Game;
  9. use Biz\Account\AccountManager;
  10. use Biz\Game\TranferMoneyLogic;
  11. use App\Commons\Model\Wagent_clientgame_log as Wagent_clientgame_logModel;
  12. use Illuminate\Database\Capsule\Manager as DB;
  13. use Biz\Game\SportbetRecordLogic;
  14. class GameLogic
  15. {
  16. private $paras = [];
  17. private $userKey = '';
  18. private $wagetnModel = null;
  19. public function __construct($paras, $userKey, $wagentModel)
  20. {
  21. $this->paras = $paras;
  22. $this->userKey = $userKey;
  23. $this->wagetnModel = $wagentModel;
  24. }
  25. //返回数据
  26. private function makeret($status = 1, $msg = 'success', $datas = [])
  27. {
  28. return [
  29. 'status' => $status,
  30. 'msg' => $msg,
  31. 'datas' => $datas
  32. ];
  33. }
  34. //CheckAccountIsExist(账户是否存在)
  35. public function CheckAccountIsExist()
  36. {
  37. $username = isset($this->paras['username']) ? trim($this->paras['username']) : '';
  38. if (empty($username)) {
  39. return $this->makeret(0, '请求参数缺失', 'key_error');
  40. }
  41. $username = $this->wagetnModel->agent_pre . $username;
  42. $ac = new AccountManager();
  43. $ret = $ac->getAccount($username);
  44. if ($ret) {
  45. return $this->makeret(1, 'success', 1);
  46. } else {
  47. return $this->makeret(1, 'success', 0);
  48. }
  49. }
  50. //CheckAndCreateAccount(检测并创建游戏帐户)
  51. public function CheckAndCreateAccount()
  52. {
  53. $username = isset($this->paras['username']) ? trim($this->paras['username']) : '';
  54. $password = isset($this->paras['password']) ? trim($this->paras['password']) : '';
  55. $remark = [
  56. 'moneysort' => '',
  57. 'limitvideo' => 0,
  58. 'limitroulette' => 0,
  59. ];
  60. $remark['moneysort'] = isset($this->paras['moneysort']) ? trim($this->paras['moneysort']) : '';
  61. $remark['limitvideo'] = isset($this->paras['limitvideo']) ? intval($this->paras['limitvideo']) : 0;
  62. $remark['limitroulette'] = isset($this->paras['limitroulette']) ? intval($this->paras['limitroulette']) : 0;
  63. $remark = json_encode($remark);
  64. if (empty($username) || empty($password)) {
  65. return $this->makeret(0, '请求参数缺失', 'key_error');
  66. }
  67. $username = $this->wagetnModel->agent_pre . $username;
  68. $ac = new AccountManager();
  69. $userInfo = $ac->getAccount($username);
  70. if ($userInfo) {
  71. return $this->makeret(1, 'success', '1');
  72. }
  73. if (!$this->nameCheck($username)) {
  74. return $this->makeret(0, 'false', 3);
  75. }
  76. if (!$this->passCheck($password)) {
  77. return $this->makeret(0, 'false', 2);
  78. }
  79. $wagent_name = isset($this->paras['agent']) ? $this->paras['agent'] : '';
  80. $postdatas = [
  81. 'account' => $username,
  82. 'password' => $password,
  83. 'again_password' => $password,
  84. 'name' => $username,
  85. 'phone' => uniqid('agent_'),
  86. 'remark' => $remark,
  87. 'wagent_name' => $wagent_name,
  88. ];
  89. $ac = new AccountManager();
  90. $ret = $ac->register($postdatas);
  91. if (isset($ret['status']) && $ret['status'] == 1) {
  92. return $this->makeret(1, 'success', '1');
  93. } else {
  94. $errormsg = isset($ret['msg']) ? $ret['msg'] : 'false';
  95. return $this->makeret(0, $errormsg, '0');
  96. }
  97. }
  98. private function nameCheck($name)
  99. {
  100. if (mb_strlen($name) >= 32) {
  101. return false;
  102. }
  103. return true;
  104. }
  105. private function passCheck($pass)
  106. {
  107. $skip = ['\'', '"', '\\', '/', '>', '<', '&', '#', '--', '%', '?', '$', ' '];
  108. foreach ($skip as $val) {
  109. if (stripos($pass, $val) !== false) {
  110. return false;
  111. }
  112. }
  113. return true;
  114. }
  115. //GetBalance(查询余额)
  116. public function GetBalance()
  117. {
  118. $accountModel = $this->accountAndPassCheck();
  119. $account_identity = $accountModel->identity;
  120. $parentinfo = lm('account_detailed', 'commons')->where('account_identity', $account_identity)->first();
  121. if (empty($parentinfo)) {
  122. return $this->makeret(1, '账号记录不存在', '0');
  123. }
  124. return $this->makeret(1, 'success', $parentinfo->cash);
  125. }
  126. public function accountAndPassCheck()
  127. {
  128. $username = isset($this->paras['username']) ? trim($this->paras['username']) : '';
  129. $password = isset($this->paras['password']) ? trim($this->paras['password']) : '';
  130. if (empty($username) || empty($password)) {
  131. $ret = $this->makeret(0, '请求参数缺失', 'key_error');
  132. Render($ret['datas'], $ret['status'], $ret['msg']);
  133. }
  134. $username = $this->wagetnModel->agent_pre . $username;
  135. $ac = new AccountManager();
  136. $account = $ac->getAccount($username);
  137. if (!$account) {
  138. $ret = $this->makeret(0, '账号不存在', 'account_no_exist');
  139. Render($ret['datas'], $ret['status'], $ret['msg']);
  140. }
  141. $account_identity = $account->identity;
  142. $passCheckret = VerPassword($account_identity, $password);
  143. if (!$passCheckret) {
  144. $ret = $this->makeret(0, '密码有误', 'key_error');
  145. Render($ret['datas'], $ret['status'], $ret['msg']);
  146. }
  147. return $account;
  148. }
  149. //TransferCredit(转帐)
  150. public function TransferCredit()
  151. {
  152. $accountModel = $this->accountAndPassCheck();
  153. if ($accountModel->status != 1) {
  154. $ret = $this->makeret(0, 'false', 'userStatus false!');
  155. return $ret;
  156. }
  157. $tlogc = new TranferMoneyLogic($accountModel, $this->paras, $this->wagetnModel);
  158. $ret = $tlogc->dorun();
  159. return $ret;
  160. }
  161. //ConfirmTransferCredit(查询转帐)
  162. public function ConfirmTransferCredit()
  163. {
  164. $accountModel = $this->accountAndPassCheck();
  165. $billno = isset($this->paras['billno']) ? trim($this->paras['billno']) : '';
  166. if (empty($billno)) {
  167. $ret = $this->makeret(0, 'billno error', '0');
  168. return $ret;
  169. }
  170. $type = isset($this->paras['type']) ? strtoupper(trim($this->paras['type'])) : '';
  171. if (empty($type) || !in_array($type, ['IN', 'OUT'])) {
  172. $ret = $this->makeret(0, 'type error', '0');
  173. return $ret;
  174. }
  175. $where = [
  176. 'account_indent' => $accountModel->identity,
  177. 'agent_name' => $this->wagetnModel->agent_name,
  178. 'type' => $type,
  179. 'billno' => $billno
  180. ];
  181. $model = lm('Money_transfer', 'Commons')->where($where)->first();
  182. if ($model) {
  183. $ret = $this->makeret(1, 'success', 1);
  184. return $ret;
  185. } else {
  186. $ret = $this->makeret(0, 'false', 0);
  187. return $ret;
  188. }
  189. }
  190. //TransferGame(进入游戏)(记录登陆日志,并自动登陆一次,返回用户登陆信息)
  191. public function TransferGame()
  192. {
  193. $this->accountAndPassCheck();
  194. $datas = [
  195. 'agent_name' => $this->paras['agent'],
  196. 'domain' => isset($this->paras['domain']) ? trim($this->paras['domain']) : '',
  197. 'userame' => $this->wagetnModel->agent_pre . $this->paras['username'],
  198. 'gametype' => isset($this->paras['gametype']) ? trim($this->paras['gametype']) : '',
  199. 'gamekind' => isset($this->paras['gamekind']) ? trim($this->paras['gamekind']) : '',
  200. 'iframe' => isset($this->paras['iframe']) ? intval(trim($this->paras['iframe'])) : -1,
  201. 'platformname' => isset($this->paras['platformname']) ? trim($this->paras['platformname']) : '',
  202. 'lang' => isset($this->paras['lang']) ? trim($this->paras['lang']) : '',
  203. 'ip' => GETIP(),
  204. ];
  205. $model = new Wagent_clientgame_logModel();
  206. $ret = $model->insert($datas);
  207. if ($ret) {
  208. $username = $this->wagetnModel->agent_pre . $this->paras['username'];
  209. $ac = new AccountManager();
  210. $ret2 = $ac->login($username, $this->paras['password']);
  211. if (isset($ret2['status']) && $ret2['status'] == 1 && isset($ret2['data']['0']['token'])) {
  212. $t_d = $ret2['data']['0'];
  213. $token = urlencode(json_encode(['img_url' => $t_d['img_url'], 'name' => $t_d['name'], 'token' => $t_d['token'], 'cash' => $t_d['cash']], 256));
  214. return $this->makeret(1, $ret2['msg'], ['ret' => 0, 'tokenold' => $t_d['token'], 'token' => $token, 'url' => 'http://' . $_SERVER['HTTP_HOST'] . '/m/jump.html?token=' . $token]);
  215. } else {
  216. return $this->makeret(0, 'false', 0);
  217. }
  218. } else {
  219. return $this->makeret(0, 'false', 0);
  220. }
  221. }
  222. //GetReport(获取报表数据)
  223. public function GetReport()
  224. {
  225. $this->accountAndPassCheck();
  226. $datetart = isset($this->paras['datestart']) ? trim($this->paras['datestart']) : '';
  227. $dateends = isset($this->paras['dateend']) ? trim($this->paras['dateend']) : '';
  228. if (empty($datetart) || empty($dateends)) {
  229. return $this->makeret(0, 'begin or endtime is empty', 0);
  230. }
  231. $retstr = '/^(\d{4}-\d{2}-\d{2})$/';
  232. if (!preg_match($retstr, $datetart) || !preg_match($retstr, $dateends)) {
  233. return $this->makeret(0, 'date fromat error', 0);
  234. }
  235. $username = $this->wagetnModel->agent_pre . $this->paras['username'];
  236. $ret = $this->getMoneyBuyData($username, $datetart, $dateends);
  237. $retlast['sports']['UserName'] = $this->paras['username'];
  238. $retlast['sports']['BettingTime'] = intval($ret['counts']);
  239. $retlast['sports']['BettingAmount'] = intval($ret['money']);
  240. $retlast['sports']['BettingEffectiveAmount'] = intval($ret['prize_money']);
  241. $retlast['sports']['BettingLoseWin'] = intval($ret['money'] - $ret['prize_money']);
  242. return $this->makeret(1, 'success', $retlast);
  243. }
  244. //获取某人体育游戏的统计数据
  245. public function getMoneyBuyData($account, $databegin, $dataend)
  246. {
  247. $db = $GLOBALS['DB'];
  248. $ret1 = $db->select("select count(id) as counts,sum(money) as money, sum(prize_money) as money_buy from money_buy_simplex where account_name=:account and status in (1,2) and money_time>=:timebegin and money_time<=:timeend group by account_name ;", ['account' => $account, 'timebegin' => $databegin, 'timeend' => $dataend]);
  249. $ret2 = $db->select("select count(id) as counts,sum(money) as money, sum(prize_money) as money_buy from money_buy_str where account_name=:account and status in (1,2) and money_time>=:timebegin and money_time<=:timeend group by account_name ;", ['account' => $account, 'timebegin' => $databegin, 'timeend' => $dataend]);
  250. $ret = ['counts' => 0, 'money' => 0, 'prize_money' => 0];
  251. if ($ret1) {
  252. $ret['counts'] += $ret1['0']['count'];
  253. $ret['money'] += $ret1['0']['money'];
  254. $ret['prize_money'] += $ret1['0']['prize_money'];
  255. }
  256. if ($ret2) {
  257. $ret['counts'] += $ret2['0']['count'];
  258. $ret['money'] += $ret2['0']['money'];
  259. $ret['prize_money'] += $ret2['0']['prize_money'];
  260. }
  261. return $ret;
  262. }
  263. // GetCashTrade(转帐记录)
  264. public function GetCashTrade()
  265. {
  266. $billno = isset($this->paras['billno']) ? $this->paras['billno'] : '';
  267. if (empty($billno)) {
  268. $ret = $this->makeret(0, 'billno empty', 0);
  269. return $ret;
  270. }
  271. $moneyTransferModel = lm('Money_transfer', 'Commons')->where(['agent_name' => $this->wagetnModel->agent_name, 'billno' => $billno])->first();
  272. if (empty($moneyTransferModel)) {
  273. $ret = $this->makeret(0, 'no data', 0);
  274. return $ret;
  275. }
  276. $AccountArray = lm('Account', 'Commons')->getinfo($moneyTransferModel->account_indent, 2);
  277. if (empty($AccountArray) || !is_array($AccountArray)) {
  278. $ret = $this->makeret(0, 'account error', 0);
  279. return $ret;
  280. }
  281. $datas = [
  282. 'Billno' => $moneyTransferModel->billno,
  283. 'UserName' => substr($AccountArray['account'], strlen($this->wagetnModel->agent_pre)),
  284. 'OrderNumber' => $moneyTransferModel->billno,
  285. 'TradeAmount' => $moneyTransferModel->tradeamount,
  286. 'Balance' => $moneyTransferModel->blance,
  287. 'TradeType' => trim($moneyTransferModel->type),
  288. 'From' => $moneyTransferModel->tfrom,
  289. 'To' => $moneyTransferModel->tto,
  290. 'AddTime' => $moneyTransferModel->addtime,
  291. ];
  292. $ret = $this->makeret(1, 'success', $datas);
  293. return $ret;
  294. }
  295. //GetBettingRecordByVendor(真人游戏记录)
  296. public function GetBettingRecordByVendor()
  297. {
  298. $ret = $this->makeret();
  299. return $ret;
  300. }
  301. //GetSportsBettingRecordByVendor(体育投注记录)
  302. public function GetSportsBettingRecordByVendor()
  303. {
  304. $vendorid = isset($this->paras['vendorid']) ? trim($this->paras['vendorid']) : 0;
  305. $isjs = isset($this->paras['isjs']) ? intval($this->paras['isjs']) : 0;
  306. if (empty($vendorid)) {
  307. $ret = $this->makeret(0, 'paretn error', 0);
  308. return $ret;
  309. }
  310. $logic = new SportbetRecordLogic($this->wagetnModel, $vendorid, $isjs);
  311. $ret = $logic->dorun();
  312. if (!$ret) {
  313. return $this->makeret(0, 'false', 0);
  314. } else {
  315. return $this->makeret(1, 'success', $ret);
  316. }
  317. return $ret;
  318. }
  319. //GetEleBettingRecord(电子投注记录)
  320. public function GetEleBettingRecord()
  321. {
  322. $ret = $this->makeret();
  323. return $ret;
  324. }
  325. //GetFishBettingRecord(捕鱼王投注记录)
  326. public function GetFishBettingRecord()
  327. {
  328. $ret = $this->makeret();
  329. return $ret;
  330. }
  331. //GetLotteryBettingRecord(彩票投注记录)
  332. public function GetLotteryBettingRecord()
  333. {
  334. $ret = $this->makeret();
  335. return $ret;
  336. }
  337. //GetGameResult(游戏结果记录)
  338. public function GetGameResult()
  339. {
  340. $ret = $this->makeret();
  341. return $ret;
  342. }
  343. //UpdateAccount(帐户密码更改)
  344. public function UpdateAccount()
  345. {
  346. $username = isset($this->paras['username']) ? trim($this->paras['username']) : '';
  347. $password = isset($this->paras['password']) ? trim($this->paras['password']) : '';
  348. if (empty($username) || empty($password)) {
  349. return $this->makeret(0, '请求参数缺失', 'key_error');
  350. }
  351. $username = $this->wagetnModel->agent_pre . $username;
  352. $ac = new AccountManager();
  353. $userInfo = $ac->getAccount($username);
  354. if (!$userInfo) {
  355. return $this->makeret(0, 'false', 'key_error');
  356. }
  357. if ($userInfo->status != 1) {
  358. return $this->makeret(0, '用户状态不正确', 'key_error');
  359. }
  360. $pwdData = GenPassword($password);
  361. $passdatas = [
  362. 'account_password' => $pwdData['password'],
  363. "encryption" => $pwdData['encryption'],
  364. ];
  365. $ret = lm('account_password', 'Commons')->where('account_identity', $userInfo->identity)->update($passdatas);
  366. if ($ret) {
  367. $ret = $this->makeret(1, 'success', 1);
  368. } else {
  369. $ret = $this->makeret(0, 'false', 0);
  370. }
  371. return $ret;
  372. }
  373. //GetSportVendorId(获取体育VendorId)
  374. public function GetSportVendorId()
  375. {
  376. $ret = $this->makeret();
  377. return $ret;
  378. }
  379. //代理帮用户请求一次登陆操作,如果成功有用户有效token值
  380. public function AutoLogin()
  381. {
  382. $this->accountAndPassCheck();
  383. $username = $this->wagetnModel->agent_pre . $this->paras['username'];
  384. $ac = new AccountManager();
  385. $ret2 = $ac->login($username, $this->paras['password']);
  386. if (isset($ret2['status']) && $ret2['status'] == 1 && isset($ret2['data']['0']['token'])) {
  387. $t_d = $ret2['data']['0'];
  388. $token = urlencode(json_encode(['img_url' => $t_d['img_url'], 'name' => $t_d['name'], 'token' => $t_d['token'], 'cash' => $t_d['cash']], 256));
  389. return $this->makeret(1, $ret2['msg'], ['ret' => 0, 'token' => $token, 'url' => 'http://' . $_SERVER['HTTP_HOST'] . '/m/jump.html?token=' . $token]);
  390. } else {
  391. return $this->makeret(0, 'false', 0);
  392. }
  393. }
  394. }