GameLogic.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. class GameLogic
  12. {
  13. private $paras = [] ;
  14. private $userKey = '' ;
  15. private $wagetnModel = null ;
  16. public function __construct($paras,$userKey,$wagentModel)
  17. {
  18. $this->paras = $paras;
  19. $this->userKey = $userKey;
  20. $this->wagetnModel = $wagentModel ;
  21. }
  22. //返回数据
  23. private function makeret($status=1,$msg='success',$datas=[]){
  24. return [
  25. 'status'=>$status,
  26. 'msg'=>$msg,
  27. 'datas'=>$datas
  28. ];
  29. }
  30. //CheckAccountIsExist(账户是否存在)
  31. public function CheckAccountIsExist(){
  32. $username= isset($this->paras['username']) ? trim($this->paras['username']) : '';
  33. if (empty($username)){
  34. return $this->makeret(0,'请求参数缺失','key_error');
  35. }
  36. $username = $this->wagetnModel->agent_pre.$username;
  37. $ac = new AccountManager();
  38. $ret = $ac->getAccount($username);
  39. if ($ret){
  40. return $this->makeret(1,'success',1);
  41. }else{
  42. return $this->makeret(1,'success',0);
  43. }
  44. }
  45. //CheckAndCreateAccount(检测并创建游戏帐户)
  46. public function CheckAndCreateAccount(){
  47. $username = isset($this->paras['username']) ? trim($this->paras['username']) : '';
  48. $password = isset($this->paras['password']) ? trim($this->paras['password']) : '' ;
  49. $remark = [
  50. 'moneysort'=>'',
  51. 'limitvideo'=>0,
  52. 'limitroulette'=>0,
  53. ];
  54. $remark['moneysort'] = isset($this->paras['moneysort']) ? trim($this->paras['moneysort']) : '' ;
  55. $remark['limitvideo'] = isset($this->paras['limitvideo']) ? intval($this->paras['limitvideo']) : 0;
  56. $remark['limitroulette'] = isset($this->paras['limitroulette']) ? intval($this->paras['limitroulette']) : 0 ;
  57. $remark = json_encode($remark);
  58. if (empty($username) || empty($password) ){
  59. return $this->makeret(0,'请求参数缺失','key_error');
  60. }
  61. $username = $this->wagetnModel->agent_pre.$username;
  62. $ac = new AccountManager();
  63. $userInfo = $ac->getAccount($username);
  64. if ($userInfo){
  65. return $this->makeret(1,'success','1');
  66. }
  67. if (!$this->nameCheck($username)){
  68. return $this->makeret(0,'false',3);
  69. }
  70. if (!$this->passCheck($password)){
  71. return $this->makeret(0,'false',2);
  72. }
  73. $wagent_name = isset($this->paras['agent']) ? $this->paras['agent'] : '';
  74. $postdatas = [
  75. 'account' => $username,
  76. 'password' => $password,
  77. 'again_password' => $password,
  78. 'name' => $username,
  79. 'phone' => uniqid('agent_'),
  80. 'remark' => $remark,
  81. 'wagent_name' => $wagent_name,
  82. ];
  83. $ac = new AccountManager();
  84. $ret = $ac->register($postdatas);
  85. if (isset($ret['status']) && $ret['status']==1){
  86. return $this->makeret(1,'success','1');
  87. }else{
  88. $errormsg = isset($ret['msg']) ? $ret['msg'] : 'false' ;
  89. return $this->makeret(0,$errormsg,'0');
  90. }
  91. }
  92. private function nameCheck($name){
  93. if (mb_strlen($name) >= 32){
  94. return false;
  95. }
  96. return true;
  97. }
  98. private function passCheck($pass){
  99. $skip = ['\'','"','\\','/','>','<','&','#','--','%','?','$',' '] ;
  100. foreach ($skip as $val){
  101. if ( stripos($pass,$val) !== false ){
  102. return false;
  103. }
  104. }
  105. return true;
  106. }
  107. //GetBalance(查询余额)
  108. public function GetBalance(){
  109. $accountModel= $this->accountAndPassCheck();
  110. $account_identity = $accountModel->account_indentity;
  111. $parentinfo = lm('account_detailed', 'commons')->where('account_identity', $account_identity)->first();
  112. if (empty($parentinfo)) {
  113. return $this->makeret(1,'账号记录不存在','0');
  114. }
  115. return $this->makeret(1,'success',$parentinfo->cash) ;
  116. }
  117. public function accountAndPassCheck(){
  118. $username= isset($this->paras['username']) ? trim($this->paras['username']) : '';
  119. $password = isset($this->paras['password']) ? trim($this->paras['password']) : '';
  120. if (empty($username) || empty($password) ){
  121. $ret = $this->makeret(0,'请求参数缺失','key_error');
  122. Render($ret['datas'],$ret['status'],$ret['msg']);
  123. }
  124. $username = $this->wagetnModel->agent_pre.$username;
  125. $ac = new AccountManager();
  126. $account = $ac->getAccount($username);
  127. if (!$account){
  128. $ret = $this->makeret(0,'账号不存在','account_no_exist');
  129. Render($ret['datas'],$ret['status'],$ret['msg']);
  130. }
  131. $account_identity = $account->identity;
  132. $passCheckret = VerPassword($account_identity,$password);
  133. if (!$passCheckret){
  134. $ret = $this->makeret(0,'密码有误','key_error');
  135. Render($ret['datas'],$ret['status'],$ret['msg']);
  136. }
  137. return $account ;
  138. }
  139. //TransferCredit(转帐)
  140. public function TransferCredit(){
  141. $accountModel = $this->accountAndPassCheck();
  142. if ($accountModel->status !=1){
  143. $ret = $this->makeret(0,'false','userStatus false!') ;
  144. return $ret;
  145. }
  146. $tlogc = new TranferMoneyLogic( $accountModel,$this->paras,$this->wagetnModel );
  147. $ret = $tlogc->dorun();
  148. return $ret;
  149. }
  150. //ConfirmTransferCredit(查询转帐)
  151. public function ConfirmTransferCredit(){
  152. $accountModel = $this->accountAndPassCheck();
  153. $billno = isset($this->paras['billno']) ? trim($this->paras['billno']) : '';
  154. if (empty($billno)){
  155. $ret = $this->makeret(0,'billno error','0') ;
  156. return $ret;
  157. }
  158. $type = isset($this->paras['type']) ? strtoupper(trim($this->paras['type'])) : '';
  159. if (empty($type) || !in_array($type,['IN','OUT']) ){
  160. $ret = $this->makeret(0,'type error','0') ;
  161. return $ret;
  162. }
  163. $where = [
  164. 'account_indent' => $accountModel->identity,
  165. 'agent_name' => $this->wagetnModel->agent_name,
  166. 'type' => $type,
  167. 'billno' => $billno
  168. ];
  169. $model = lm('Money_transfer','Commons')->where( $where )->first();
  170. if ($model){
  171. $ret = $this->makeret(1,'success',1);
  172. return $ret;
  173. }else{
  174. $ret = $this->makeret(0,'false',0);
  175. return $ret;
  176. }
  177. }
  178. //TransferGame(进入游戏)
  179. public function TransferGame(){
  180. $ret = $this->makeret() ;
  181. return $ret;
  182. }
  183. //GetReport(获取报表数据)
  184. public function GetReport(){
  185. $ret = $this->makeret() ;
  186. return $ret;
  187. }
  188. // GetCashTrade(转帐记录)
  189. public function GetCashTrade(){
  190. $billno = isset($this->paras['billno']) ? $this->paras['billno'] : '' ;
  191. if (empty($billno)){
  192. $ret = $this->makeret(0,'billno empty',0) ;
  193. return $ret;
  194. }
  195. $moneyTransferModel = lm('Money_transfer','Commons')->where(['agent_name'=>$this->wagetnModel->agent_name,'billno'=>$billno])->first();
  196. if (empty( $moneyTransferModel )){
  197. $ret = $this->makeret(0,'no data',0) ;
  198. return $ret;
  199. }
  200. $AccountArray= lm('Account','Commons')->getinfo($moneyTransferModel->account_indent,2);
  201. if (empty($AccountArray) || !is_array( $AccountArray )){
  202. $ret = $this->makeret(0,'account error',0) ;
  203. return $ret;
  204. }
  205. $datas = [
  206. 'Billno'=>$moneyTransferModel->billno,
  207. 'UserName'=>substr($AccountArray['account'],strlen($this->wagetnModel->agent_pre)),
  208. 'OrderNumber'=>$moneyTransferModel->billno,
  209. 'TradeAmount'=>$moneyTransferModel->tradeamount,
  210. 'Balance'=>$moneyTransferModel->blance,
  211. 'TradeType'=> trim($moneyTransferModel->type),
  212. 'From'=>$moneyTransferModel->tfrom,
  213. 'To'=>$moneyTransferModel->tto,
  214. 'AddTime'=>$moneyTransferModel->addtime,
  215. ];
  216. $ret = $this->makeret(1,'success',$datas) ;
  217. return $ret;
  218. }
  219. //GetBettingRecordByVendor(真人游戏记录)
  220. public function GetBettingRecordByVendor(){
  221. $ret = $this->makeret() ;
  222. return $ret;
  223. }
  224. //GetSportsBettingRecordByVendor(体育投注记录)
  225. public function GetSportsBettingRecordByVendor(){
  226. $ret = $this->makeret() ;
  227. return $ret;
  228. }
  229. //GetEleBettingRecord(电子投注记录)
  230. public function GetEleBettingRecord(){
  231. $ret = $this->makeret() ;
  232. return $ret;
  233. }
  234. //GetFishBettingRecord(捕鱼王投注记录)
  235. public function GetFishBettingRecord(){
  236. $ret = $this->makeret() ;
  237. return $ret;
  238. }
  239. //GetLotteryBettingRecord(彩票投注记录)
  240. public function GetLotteryBettingRecord(){
  241. $ret = $this->makeret() ;
  242. return $ret;
  243. }
  244. //GetGameResult(游戏结果记录)
  245. public function GetGameResult(){
  246. $ret = $this->makeret() ;
  247. return $ret;
  248. }
  249. //UpdateAccount(帐户密码更改)
  250. public function UpdateAccount(){
  251. $username = isset($this->paras['username']) ? trim($this->paras['username']) : '';
  252. $password = isset($this->paras['password']) ? trim($this->paras['password']) : '' ;
  253. if (empty($username) || empty($password) ){
  254. return $this->makeret(0,'请求参数缺失','key_error');
  255. }
  256. $username = $this->wagetnModel->agent_pre.$username;
  257. $ac = new AccountManager();
  258. $userInfo = $ac->getAccount($username);
  259. if (!$userInfo){
  260. return $this->makeret(0,'false','key_error');
  261. }
  262. if ($userInfo->status != 1){
  263. return $this->makeret(0,'用户状态不正确','key_error');
  264. }
  265. $pwdData = GenPassword($password);
  266. $passdatas = [
  267. 'account_password'=>$pwdData['password'],
  268. "encryption" => $pwdData['encryption'],
  269. ];
  270. $ret = lm('account_password', 'Commons')->where('account_identity',$userInfo->identity)->update($passdatas);
  271. if ($ret ){
  272. $ret = $this->makeret(1,'success',1) ;
  273. }else{
  274. $ret = $this->makeret(0,'false',0) ;
  275. }
  276. return $ret;
  277. }
  278. //GetSportVendorId(获取体育VendorId)
  279. public function GetSportVendorId(){
  280. $ret = $this->makeret() ;
  281. return $ret;
  282. }
  283. }