GameLogic.php 16 KB

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