GameLogic.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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 App\Commons\Model\Money_transfer;
  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. $type = isset($this->paras['type']) ? strtoupper(trim($this->paras['type'])) : '';
  147. if (!in_array( $type , ['IN','OUT'])){ return $this->makeret(0,'type error!','type error'); }
  148. $credit = isset($this->paras['credit']) ? floatval(trim($this->paras['credit'])) : 0;
  149. if ( $credit <=0 ){ return $this->makeret(0,'credit error','credit error'); }
  150. $billno = isset($this->paras['billno']) ? strtoupper(trim($this->paras['billno'])) : '';
  151. if (empty($billno)){ return $this->makeret(0,'billno empty','billno empty'); }
  152. $transferModel = new Money_transfer();
  153. $hasexit = $transferModel->findOneByAttr('billno',$billno);
  154. if ( $hasexit ){ return $this->makeret(0,'billno exists','billno exists'); }
  155. $parentinfo = lm('account_detailed', 'commons')->where('account_identity', $accountModel->account_identity)->first();
  156. if (empty($parentinfo)) { return $this->makeret(1,'account_detailed not exists','0'); }
  157. $cash = $parentinfo->cash ;
  158. if ( $type == 'OUT' && $cash<$credit ){
  159. return $this->makeret(0,'no_enough_credit','no_enough_credit');
  160. }
  161. $transferModel->account_indent = $accountModel->identity;
  162. $transferModel->ordernumber = OrderID('transfer_') ;
  163. $transferModel->billno = $billno;
  164. $transferModel->tradeamount = $credit ;
  165. $transferModel->blance = ($type == 'IN') ? $cash + $credit : $cash - $credit ;
  166. $transferModel->type = $type ;
  167. $transferModel->tradtype = ($type == 'IN') ? 8 : 9 ;
  168. $transferModel->tfrom = 0 ;
  169. $transferModel->tto = 0 ;
  170. $transferModel->agent_name = $this->wagetnModel->agent_name ;
  171. $ret = $transferModel->save();
  172. if ($ret){
  173. $ret = $this->makeret(1,'success',1) ;
  174. return $ret;
  175. }else{
  176. $ret = $this->makeret(0,'false',0) ;
  177. return $ret;
  178. }
  179. }
  180. //ConfirmTransferCredit(查询转帐)
  181. public function ConfirmTransferCredit(){
  182. $ret = $this->makeret() ;
  183. return $ret;
  184. }
  185. //TransferGame(进入游戏)
  186. public function TransferGame(){
  187. $ret = $this->makeret() ;
  188. return $ret;
  189. }
  190. //GetReport(获取报表数据)
  191. public function GetReport(){
  192. $ret = $this->makeret() ;
  193. return $ret;
  194. }
  195. // GetCashTrade(转帐记录)
  196. public function GetCashTrade(){
  197. $ret = $this->makeret() ;
  198. return $ret;
  199. }
  200. //GetBettingRecordByVendor(真人游戏记录)
  201. public function GetBettingRecordByVendor(){
  202. $ret = $this->makeret() ;
  203. return $ret;
  204. }
  205. //GetSportsBettingRecordByVendor(体育投注记录)
  206. public function GetSportsBettingRecordByVendor(){
  207. $ret = $this->makeret() ;
  208. return $ret;
  209. }
  210. //GetEleBettingRecord(电子投注记录)
  211. public function GetEleBettingRecord(){
  212. $ret = $this->makeret() ;
  213. return $ret;
  214. }
  215. //GetFishBettingRecord(捕鱼王投注记录)
  216. public function GetFishBettingRecord(){
  217. $ret = $this->makeret() ;
  218. return $ret;
  219. }
  220. //GetLotteryBettingRecord(彩票投注记录)
  221. public function GetLotteryBettingRecord(){
  222. $ret = $this->makeret() ;
  223. return $ret;
  224. }
  225. //GetGameResult(游戏结果记录)
  226. public function GetGameResult(){
  227. $ret = $this->makeret() ;
  228. return $ret;
  229. }
  230. //UpdateAccount(帐户密码更改)
  231. public function UpdateAccount(){
  232. $username = isset($this->paras['username']) ? trim($this->paras['username']) : '';
  233. $password = isset($this->paras['password']) ? trim($this->paras['password']) : '' ;
  234. if (empty($username) || empty($password) ){
  235. return $this->makeret(0,'请求参数缺失','key_error');
  236. }
  237. $username = $this->wagetnModel->agent_pre.$username;
  238. $ac = new AccountManager();
  239. $userInfo = $ac->getAccount($username);
  240. if (!$userInfo){
  241. return $this->makeret(0,'false','key_error');
  242. }
  243. if ($userInfo->status != 1){
  244. return $this->makeret(0,'用户状态不正确','key_error');
  245. }
  246. $pwdData = GenPassword($password);
  247. $passdatas = [
  248. 'account_password'=>$pwdData['password'],
  249. "encryption" => $pwdData['encryption'],
  250. ];
  251. $ret = lm('account_password', 'Commons')->where('account_identity',$userInfo->identity)->update($passdatas);
  252. if ($ret ){
  253. $ret = $this->makeret(1,'success',1) ;
  254. }else{
  255. $ret = $this->makeret(0,'false',0) ;
  256. }
  257. return $ret;
  258. }
  259. //GetSportVendorId(获取体育VendorId)
  260. public function GetSportVendorId(){
  261. $ret = $this->makeret() ;
  262. return $ret;
  263. }
  264. }