MoneyHandle.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  1. <?php
  2. namespace Biz\Money;
  3. /**
  4. * 资金操作相关类
  5. */
  6. class MoneyHandle
  7. {
  8. /**
  9. * 资金明细表
  10. * @var string
  11. */
  12. private $money_table = 'fund_detailed';
  13. /**
  14. * 用户详情表
  15. * @var string
  16. */
  17. private $account_detailed = 'account_detailed';
  18. /**
  19. * 用户银行绑定记录表
  20. * @var string
  21. */
  22. private $bank_table = 'account_bank';
  23. /**
  24. * 用户表
  25. * @var string
  26. */
  27. private $account_table = 'account';
  28. /**
  29. * 交易密码表
  30. * @var string
  31. */
  32. private $pay_password = 'pay_password';
  33. /**
  34. * 代理信息表
  35. * @var string
  36. */
  37. private $agent = 'agent_detailed';
  38. /**
  39. * 代理资金表
  40. * @var string
  41. */
  42. private $agent_money = 'agent_money';
  43. /**
  44. * 佣金记录表
  45. * @var string
  46. */
  47. private $money_reward = 'money_reward';
  48. /**
  49. * 资金明细表
  50. * @var string
  51. */
  52. private $money_details = 'money_details';
  53. /**
  54. * 中奖记录表
  55. * @var string
  56. */
  57. private $prize_table = 'money_prize';
  58. /**
  59. * 提现记录表
  60. * @var string
  61. */
  62. private $money_take = 'money_take';
  63. /**
  64. * 充值记录
  65. * @var string
  66. */
  67. private $money_recharge = 'money_recharge';
  68. /**
  69. * 反水记录表
  70. * @var string
  71. */
  72. private $money_back = 'money_back';
  73. /**
  74. * 回水记录表
  75. * @var string
  76. */
  77. private $money_return = 'money_return';
  78. /**
  79. * 投注记录影子表
  80. * @var string
  81. */
  82. private $money_buy = 'money_buy';
  83. private $account_list = 'AccountList';
  84. private $sixMoney_buy='SixMoney_buy';
  85. private $sixPrize_table='sixMoney_prize';
  86. //private $game;
  87. public function init()
  88. {
  89. }
  90. /**
  91. * 绑定银行卡
  92. * @param [type] $account_identity 用户id
  93. * @param [type] $bank_address 开户银行地址
  94. * @param [type] $bank_name 银行名称
  95. * @param [type] $bank_no 银行卡号
  96. * @param [type] $bank_user 银行卡用户
  97. * @param [type] $pay_pwd 支付密码
  98. * @param [type] $sure_pwd 确认密码
  99. * @return [type] [description]
  100. */
  101. public function bind_bank($account_identity, $bank_address, $bank_name, $bank_no, $bank_user, $pay_pwd, $sure_pwd,$bank_code)
  102. {
  103. //判断重要参数是否为空
  104. //var_dump($account_identity,$bank_address,$bank_name,$bank_no,$bank_user,$pay_pwd,$sure_pwd);
  105. //return $bank_address;
  106. if (empty($account_identity)) {
  107. //Render('null','-2001',lang()->get('user not login'));
  108. return '-2001';
  109. }
  110. if (empty($bank_address)) {
  111. //Render('null','-2002',lang()->get('bank_address missing'));
  112. // return $bank_address;
  113. return '-2002';
  114. }
  115. if (empty($bank_name)) {
  116. //Render('null','-2003',lang()->get('bank_name missing'));
  117. return '-2003';
  118. }
  119. /*if(empty($bank_code)){
  120. return '-2003';
  121. }*/
  122. if (empty($bank_no)) {
  123. //Render('null','-2004',lang()->get('bank_number missing'));
  124. return '-2004';
  125. }
  126. if (empty($bank_user)) {
  127. //Render('null','-2005',lang()->get('bank_user missing'));
  128. return '-2005';
  129. }
  130. if (empty($pay_pwd) || empty($sure_pwd)) {
  131. //Render('null','-2006',lang()->get('password missing'));
  132. return '-2006';
  133. }
  134. //判断两次交易密码是否一致
  135. if ($pay_pwd != $sure_pwd) {
  136. //Render('null','-2007',lang()->get('two password not equal'));
  137. return '-2007';
  138. }
  139. $this->setPayPwd($account_identity, $pay_pwd, $sure_pwd);
  140. //验证用户是否已经绑定了该银行卡
  141. $res = lm($this->bank_table, 'commons')->where(['account_identity' => $account_identity])->first();
  142. //return $res;
  143. if ($res) {
  144. return '-2033';
  145. }
  146. //检测该银行卡是否已经绑定
  147. $res2 = lm($this->bank_table, 'commons')->where('bank_number', $bank_no)->first();
  148. if ($res2) {
  149. return '-2136';
  150. }
  151. //检测开户人姓名是否与用户真实姓名相同
  152. $userName = lm($this->account_detailed, 'commons')->select('name')->where('account_identity', $account_identity)->first();
  153. if ($userName) {
  154. if (!empty($userName->name) && $userName->name != $bank_user) {
  155. return '-3311';
  156. }
  157. } else {
  158. return '-4001';
  159. }
  160. //为用户绑定银行卡
  161. $data = array(
  162. 'identity' => UUID(),
  163. 'account_identity' => $account_identity,
  164. 'bank_address' => $bank_address,
  165. 'bank_name' => $bank_name,
  166. 'account_name' => $bank_user,
  167. 'bank_number' => $bank_no,
  168. 'band_time' => date('Y-m-d H:i:s', time()),
  169. 'bank_code' => $bank_code
  170. );
  171. $res = lm($this->bank_table, 'commons')->insert($data);
  172. $resd = lm($this->account_detailed, 'commons')->select('name')->where('account_identity', $account_identity)->first();
  173. if (empty($resd->name)) {
  174. lm($this->account_detailed, 'commons')->where('account_identity', $account_identity)->update(['name' => $bank_user]);
  175. }
  176. if ($res) {
  177. //Render('null','1',lang()->get('success'));
  178. return 1;
  179. } else {
  180. //Render('null','-2009',lang()->get('fail'));
  181. return '-2009';
  182. }
  183. }
  184. /**
  185. * 设置默认银行卡或者解绑银行卡
  186. * @param [type] $account_identity 用户id
  187. * @param [type] $bank_no 银行卡号
  188. * @param [type] $pay_pwd 交易密码
  189. * @param [type] $type 类型 1.设置默认银行卡,-1,解除该银行卡绑定
  190. * @return [type] [description]
  191. */
  192. public function bankStatus($account_identity, $bank_no, $pay_pwd, $type)
  193. {
  194. if ($type == 1) {
  195. $type = 2;
  196. }
  197. if (!$this->verifyPayPwd($account_identity, $pay_pwd)) {
  198. return '-2020';
  199. }
  200. $res = lm($this->bank_table, 'commons')->where(['account_identity' => $account_identity, 'bank_number' => $bank_no])->update(['status' => $type]);
  201. if ($res) {
  202. return '1';
  203. } else {
  204. return '-2016';
  205. }
  206. }
  207. /**
  208. * 设置交易密码
  209. * @param [type] $account_identity 用户id
  210. * @param [type] $pay_pwd 密码
  211. * @param [type] $sure_pwd 确认密码
  212. */
  213. public function setPayPwd($account_identity, $pay_pwd, $sure_pwd)
  214. {
  215. //判断重要参数是否为空
  216. if (empty($account_identity)) {
  217. //Render('null','-2010',lang()->get('user not login'));
  218. return '-2001';
  219. }
  220. if (empty($pay_pwd) || empty($sure_pwd)) {
  221. //Render('null','-2011',lang()->get('password missing'));
  222. return '-2006';
  223. }
  224. //判断两次交易密码是否一致
  225. if ($pay_pwd != $sure_pwd) {
  226. //Render('null','-2012',lang()->get('two password not equal'));
  227. return '-2007';
  228. }
  229. //检查用户是否已经设置密码
  230. $judge = lm($this->pay_password, 'commons')->where(['account_identity' => $account_identity])->first();
  231. //为用户设置交易密码
  232. $pwd = GenPassword($pay_pwd);
  233. $data = array(
  234. 'identity' => UUID(),
  235. 'pay_password' => $pwd['password'],
  236. 'encryption' => $pwd['encryption'],
  237. 'account_identity' => $account_identity,
  238. );
  239. if ($judge) {
  240. $res = lm($this->pay_password, 'commons')->where(['account_identity' => $account_identity])->update($data);
  241. } else {
  242. $res = lm($this->pay_password, 'commons')->insert($data);
  243. }
  244. if ($res) {
  245. //Render('null','1',lang()->get('success'));
  246. return '1';
  247. } else {
  248. //Render('null','-2013',lang()->get('fail'));
  249. return '-2013';
  250. }
  251. }
  252. /**
  253. * 检测是否设置交易密码
  254. * @param [type] $account_identity 用户id
  255. */
  256. public function checkPayPwd($account_identity='')
  257. {
  258. //$account_identity = isset($_SESSION['uinfo']['account_identity']) ? $_SESSION['uinfo']['account_identity'] : '';
  259. if (empty($account_identity)) {
  260. Render('', '-2001', lang()->get('user not login'));
  261. }
  262. //检查用户是否已经设置密码
  263. $judge = lm($this->pay_password, 'commons')->where(['account_identity' => $account_identity])->first();
  264. if ($judge) {
  265. return '1';
  266. } else {
  267. return '-1024';
  268. }
  269. }
  270. /**
  271. * 投注追号
  272. * @param [type] $user_id 用户id
  273. * @param [type] $money 投注追号金额
  274. * @param array $extra 其他数据
  275. * @return [type] [description]
  276. */
  277. public function betting($user_id, $money, $extra = array())
  278. {
  279. if($money<=0)return -3311;
  280. //检测用户资金
  281. $check = $this->check($user_id, $money);
  282. if ($check < 0) {
  283. return $check;
  284. }
  285. //订单号
  286. $order_id = isset($extra['order_id']) ? $extra['order_id'] : '';
  287. if (empty($order_id)) {
  288. return -2116;
  289. }
  290. //投注了类型
  291. $type = isset($extra['money_type']) ? $extra['money_type'] : '';
  292. if (empty($type)) {
  293. return -2117;
  294. }
  295. //游戏期号
  296. $game_no = isset($extra['game_no']) ? $extra['game_no'] : '';
  297. if (empty($game_no)) {
  298. return -2119;
  299. }
  300. //游戏名
  301. $game_name = isset($extra['type_name']) ? $extra['type_name'] : '';
  302. if (empty($game_name)) {
  303. return -2118;
  304. }
  305. //投注号码
  306. $codes = isset($extra['codes']) ? $extra['codes'] : '';
  307. if (empty($codes)) {
  308. return -2122;
  309. }
  310. //反水金额
  311. $back_money = isset($extra['back_money']) ? $extra['back_money'] : '';
  312. //反水比例
  313. $back = isset($extra['back']) ? $extra['back'] : '';
  314. /*//获取购买号码
  315. $codes = $this->getCodes($order_id, $game_name);*/
  316. _beginTransaction();
  317. //获取用户信息
  318. $account = $this->getAccount($user_id);
  319. //投注影子表数据加入
  320. $data = array(
  321. 'info_identity' => $extra['identity'],
  322. 'account_name' => $account['account_name'],
  323. 'account_identity' => $user_id,
  324. 'order_id' => $order_id,
  325. 'game_name' => $game_name,
  326. 'game_no' => $game_no,
  327. 'codes' => $codes,
  328. 'money' => $money,
  329. 'get_money' => -$money,
  330. 'status' => $type,
  331. 'money_time' => date('Y-m-d H:i:s', time()),
  332. 'member_type' => $account['status'],
  333. );
  334. $this->money_buy = ($game_name=='sixlottery' || $game_name=='sfsixlottery')?'SixMoney_buy':$this->money_buy;
  335. ($game_name=='sixlottery' || $game_name=='sfsixlottery')?($data['game_identity'] = $extra['gameid']):null;
  336. $res = lm($this->money_buy, 'Commons')->insert($data);
  337. if (!$res) {
  338. _rollBack();
  339. return -2120;
  340. }
  341. //反水
  342. if ($back_money != 0) {
  343. $judge = $this->back_money($user_id, $back_money, $game_name, $order_id, $back,$extra['identity']);
  344. if ($judge < 0) {
  345. return $judge;
  346. }
  347. }
  348. $game = new \Biz\Game\GameQuery;
  349. //获取游戏信息
  350. $gameName = $game->getGameInfo($extra['type_name']);
  351. if (!is_array($gameName)) {
  352. return $gameName;
  353. }
  354. //$gameName = isset($extra['type_name']) ? $extra['type_name'] : '';
  355. $res = $this->insertMoney($user_id, $money, $order_id, $type, $gameName['name'], $game_no);
  356. if ($res < 0) {
  357. _rollBack();
  358. }
  359. _commit();
  360. return $res;
  361. }
  362. /**
  363. * 六合投注追号
  364. * @param [type] $user_id 用户id
  365. * @param [type] $money 投注追号金额
  366. * @param array $extra 其他数据
  367. * @return [type] [description]
  368. */
  369. public function sixBetting($user_id, $money, $extra = array())
  370. {
  371. //检测用户资金
  372. $check = $this->check($user_id, $money);
  373. if ($check < 0) {
  374. return $check;
  375. }
  376. //订单号
  377. $order_id = isset($extra['order_id']) ? $extra['order_id'] : '';
  378. if (empty($order_id)) {
  379. return -2116;
  380. }
  381. //投注了类型
  382. $type = isset($extra['money_type']) ? $extra['money_type'] : '';
  383. if (empty($type)) {
  384. return -2117;
  385. }
  386. //游戏期号
  387. $game_no = isset($extra['game_no']) ? $extra['game_no'] : '';
  388. if (empty($game_no)) {
  389. return -2119;
  390. }
  391. //游戏名
  392. $game_name = isset($extra['type_name']) ? $extra['type_name'] : '';
  393. if (empty($game_name)) {
  394. return -2118;
  395. }
  396. //投注号码
  397. $codes = isset($extra['codes']) ? $extra['codes'] : '';
  398. if (empty($codes)) {
  399. return -2122;
  400. }
  401. //反水金额
  402. $back_money = isset($extra['back_money']) ? $extra['back_money'] : '';
  403. //反水比例
  404. $back = isset($extra['back']) ? $extra['back'] : '';
  405. /*//获取购买号码
  406. $codes = $this->getCodes($order_id, $game_name);*/
  407. _beginTransaction();
  408. //获取用户信息
  409. $account = $this->getAccount($user_id);
  410. //投注影子表数据加入
  411. $data = array(
  412. 'info_identity' => $extra['identity'],
  413. 'account_name' => $account['account_name'],
  414. 'account_identity' => $user_id,
  415. 'order_id' => $order_id,
  416. 'game_name' => $game_name,
  417. 'game_no' => $game_no,
  418. 'codes' => $codes,
  419. 'money' => $money,
  420. 'get_money' => -$money,
  421. 'status' => $type,
  422. 'money_time' => date('Y-m-d H:i:s', time()),
  423. 'member_type' => $account['status'],
  424. );
  425. $res = lm($this->sixMoney_buy, 'Commons')->insert($data);
  426. if (!$res) {
  427. _rollBack();
  428. return -2120;
  429. }
  430. //反水
  431. if ($back_money != 0) {
  432. $judge = $this->back_money($user_id, $back_money, $game_name, $order_id, $back,$extra['identity']);
  433. if ($judge < 0) {
  434. return $judge;
  435. }
  436. }
  437. $game = new \Biz\Game\GameQuery;
  438. //获取游戏信息
  439. $gameName = $game->getGameInfo($extra['type_name']);
  440. if (!is_array($gameName)) {
  441. return $gameName;
  442. }
  443. //$gameName = isset($extra['type_name']) ? $extra['type_name'] : '';
  444. $res = $this->insertMoney($user_id, $money, $order_id, $type, $gameName['name'], $game_no);
  445. if ($res < 0) {
  446. _rollBack();
  447. }
  448. _commit();
  449. return $res;
  450. }
  451. /**
  452. * 中奖
  453. */
  454. public function prize($user_id, $money, $game, $buy_id, $prize)
  455. {
  456. //生成订单id
  457. $order_id = OrderID();
  458. //生成信息id
  459. $info_id = UUID();
  460. //更新投注影子表
  461. //获取投注金额
  462. $buy_money = lm($this->money_buy, 'Commons')->where('order_id', $buy_id)->first();
  463. if ($buy_money) {
  464. $game_no = $buy_money->game_no;
  465. //阻止重新开奖的派彩
  466. /*if ($buy_money->prize_money > 0) {
  467. return 1;
  468. }*/
  469. $accountname = $buy_money->account_name;
  470. $buy_money = $buy_money->money;
  471. } else {
  472. return -2121;
  473. }
  474. //获取真实投注金额(除去反水金额的消费金额)
  475. //$rel_money = $this->getMoney($buy_id);
  476. //更新投注影子表
  477. $get_money = $money - $buy_money;
  478. $rest = lm($this->money_buy, 'Commons')
  479. ->where('order_id', $buy_id)
  480. ->update(['get_money' => $get_money, 'prize_money' => $money, 'game_status' => 1, 'prize' => $prize]);
  481. if (!$rest) {
  482. return -2120;
  483. }
  484. if (lm($this->prize_table, 'Commons')->where('buy_identity', $buy_id)->first()) {
  485. return 1;
  486. }
  487. //将中奖插入中奖记录
  488. $data = array(
  489. 'game_name' => $game['table_name'],
  490. 'buy_identity' => $buy_id,
  491. 'account_name' => $accountname,
  492. 'account_identity' => $user_id,
  493. 'order_id' => $order_id,
  494. 'info_identity' => $info_id,
  495. 'money' => $money,
  496. 'money_time' => date('Y-m-d H:i:s', time()),
  497. );
  498. $res = lm($this->prize_table, 'Commons')->insert($data);
  499. if ($res) {
  500. $type = 4;
  501. /* lm("message",'commons')->updateMessage('admin',$accountname,'中奖提示','恭喜中奖,您在'.lang()->get($game['table_name']).'中的第'.$game_no.'期中,中奖:'.$money.'元',2);*/
  502. return $this->insertMoney($user_id, $money, $order_id, $type, $game['name'], $game_no);
  503. } else {
  504. return '-2113';
  505. }
  506. }
  507. /***六合派奖
  508. * @param $user_id 用户id
  509. * @param $accountName 用户名
  510. * @param $buy_money 投注金额
  511. * @param $prize_money 派奖金额
  512. * * @param $buy_id 购买id
  513. * @param $gameInfo 游戏信息的数组 包含游戏名,游戏期号
  514. * @param $prize_code 中奖号码
  515. *
  516. */
  517. public function sixPrize($user_id, $prize_money, $game, $buy_id, $prize_code,$buy_money,$gameInfo,$userInfo)
  518. {
  519. //生成订单id
  520. $order_id = OrderID();
  521. //生成信息id
  522. $info_id = UUID();
  523. $game_no = $gameInfo['no'];
  524. //更新投注影子表
  525. //更新投注影子表
  526. //computeTime('更新影子表');
  527. $get_money = $prize_money - $buy_money;
  528. $rest = lm($this->sixMoney_buy, 'Commons')
  529. ->where('order_id', $buy_id)
  530. ->update(['get_money' => $get_money, 'prize_money' => $prize_money, 'game_status' => 1, 'prize' => $prize_code]);
  531. if (!$rest) {
  532. return -2120;
  533. }
  534. // computeTime('更新money_buy');
  535. //将中奖插入中奖记录
  536. $data = array(
  537. 'game_name' => $gameInfo['en_name'],
  538. 'buy_identity' => $buy_id,
  539. 'account_name' => $userInfo['account'],
  540. 'account_identity' => $user_id,
  541. 'order_id' => $order_id,
  542. 'info_identity' => $info_id,
  543. 'money' => $prize_money,
  544. 'money_time' => date('Y-m-d H:i:s', time()),
  545. );
  546. $res = lm($this->sixPrize_table, 'Commons')->insert($data);
  547. //computeTime('添加money_prize');
  548. if ($res) {
  549. $type = 4;
  550. $userInfo['account_name']=$userInfo['account'];
  551. return $this->insertMoney($userInfo['identity'], $prize_money, $order_id, $type, lang()->get($gameInfo['en_name']), $game_no,$userInfo,$gameInfo['en_name']);
  552. } else {
  553. return '-2113';
  554. }
  555. }
  556. /**
  557. * 重新开奖撤销中奖记录
  558. * @param [type] $buy_id 购买id
  559. * @return [type] [description]
  560. */
  561. public function reprize($buy_id, $user_id, $nowMoney)
  562. {
  563. $res = lm($this->money_buy, 'commons')->where('order_id', $buy_id)->first();
  564. if ($res) {
  565. $data = [
  566. 'game_status' => 0,
  567. 'prize_money' => 0,
  568. 'get_money' => -$res->money,
  569. 'prize' => '{}',
  570. ];
  571. } else {
  572. return -2051;
  573. }
  574. // $account = $this->getAccount($res->account_identity);
  575. $res1 = lm($this->money_buy, 'commons')->where('order_id', $buy_id)->update($data);
  576. //成功则更新中奖记录表的状态
  577. if ($res1) {
  578. $prize = lm($this->prize_table, 'commons')->where('buy_identity', $buy_id)->first();
  579. $res2 = lm($this->prize_table, 'commons')->where('buy_identity', $buy_id)->delete();
  580. //更新成功修改资金详情记录
  581. if ($res2) {
  582. $trade_id = OrderID();
  583. return $this->insertDetail($user_id, $trade_id, $res->prize_money, $nowMoney, 9, $buy_id, lang()->get($res->game_name), $res->game_no);
  584. }
  585. }
  586. return -2049;
  587. }
  588. /**
  589. * 重新开奖中奖用户退还中奖金额,扣除余额到0
  590. * @param [type] $gameNo 游戏期号
  591. * @param [type] $gameName 游戏名
  592. * @return [type] [description]
  593. */
  594. public function returnPrizeMoney($gameNo, $gameName)
  595. {
  596. $gameName = strtolower($gameName);
  597. if($gameName=='sixlottery' || $gameName=='sfsixlottery'){
  598. $this->money_buy = 'SixMoney_buy';
  599. $this->prize_table = 'SixMoney_prize';
  600. }
  601. $isPrize = $this->isPrize($gameNo, $gameName);
  602. if ($isPrize < 0) {
  603. return $isPrize;
  604. }
  605. $res = lm($this->money_buy, 'commons')->select('account_identity', 'prize_money', 'order_id')->where('game_name', $gameName)->where('game_no', $gameNo)->where('prize_money', '>', '0')->get();
  606. if ($res) {
  607. _beginTransaction();
  608. $res = $res->toArray();
  609. try {
  610. foreach ($res as $key => $value) {
  611. $userCash = lm($this->account_detailed, 'commons')->select('cash', 'available_cash')->where('account_identity', $value['account_identity'])->first();
  612. /*if ($value['prize_money'] > $userCash->available_cash) {
  613. $available_cash = 0;
  614. $cash = $userCash->cash - $userCash->available_cash;
  615. } else {*/
  616. $available_cash = $userCash->available_cash - $value['prize_money'];
  617. $cash = $userCash->cash - $value['prize_money'];
  618. //}
  619. $result = $this->updateAccountMoney($value['account_identity'], $value['prize_money'], 2, $available_cash);
  620. if ($result < 0) {
  621. _rollBack();
  622. }
  623. $this->reprize($value['order_id'], $value['account_identity'], $available_cash);
  624. }
  625. lm($gameName . '_buy', 'commons')->where('no', $gameNo)->update(array('status' => 0));
  626. //_commit();
  627. } catch (PDOException $e) {
  628. _rollBack();
  629. }
  630. }
  631. return 1;
  632. }
  633. public function updateStatus($gameno, $gamename)
  634. {
  635. lm('money_buy', 'commons')->where('game_no', $gameno)->where('game_name', $gamename)->where('game_status', 0)->update(array('game_status' => 2));
  636. lm($gamename . '_buy', 'commons')->where('no', $gameno)->where('status', 0)->update(array('status' => 2));
  637. return 1;
  638. }
  639. /**
  640. * 重新开奖中奖用户退还中奖金额,扣除余额到0
  641. * @param [type] $gameno 游戏期号
  642. * @param [type] $gamename 游戏名
  643. * @return [type] [description]
  644. */
  645. public function isPrize($gameno, $gamename)
  646. {
  647. $status = lm($gamename, 'commons')->select('status')->where('info_no', $gameno)->first();
  648. if ($status) {
  649. if ($status['status'] == 2) {
  650. return 1;
  651. }
  652. return -3307;
  653. }
  654. return -3221;
  655. }
  656. /**
  657. * 充值
  658. * @param $user_id 用户id
  659. * @param $money 充值金额
  660. * @param array $extra 其他参数数组
  661. */
  662. public function addMoney($user_id, $money, $type)
  663. {
  664. $type = '在线充值';
  665. //获取用户信息
  666. $account = $this->getAccount($user_id);
  667. //生成订单id
  668. $order_id = OrderID();
  669. //充值后金额
  670. $nowMoney = $account['available_cash'] + $money;
  671. //充值记录
  672. $data = array(
  673. 'info_identity' => UUID(),
  674. 'order_id' => $order_id,
  675. 'apply_time' => date('Y-m-d H:i:s', time()),
  676. 'money' => $money,
  677. 'account_name' => $account['account_name'],
  678. 'account_identity' => $user_id,
  679. 'status' => 3,
  680. 'recharge_type' => $type,
  681. 'money_cash' => $nowMoney,
  682. );
  683. $res = lm($this->money_recharge, 'Commons')->insert($data);
  684. if ($res) {
  685. return $order_id;
  686. }
  687. }
  688. /**
  689. * 确认充值
  690. * @param [type] $order_id 充值订单
  691. * @return [type] [description]
  692. */
  693. public function suerAddMoney($order_id, $status = 3)
  694. {
  695. $charge = lm($this->money_recharge, 'commons')->where('order_id', $order_id)->where('status', 3)->first();
  696. if (!$charge) {
  697. return -2047;
  698. }
  699. if ($status < 0) {
  700. $res = lm($this->money_recharge, 'commons')->where('order_id', $order_id)->update(['status' => 2]);
  701. return 1;
  702. }
  703. $res = lm($this->money_recharge, 'commons')->where('order_id', $order_id)
  704. ->update(['status' => 1, 'complete_time' => date('Y-m-d H:i:s', time())]);
  705. if ($res) {
  706. return $this->insertMoney($charge->account_identity, $charge->money, $order_id, 6);
  707. }
  708. return -2048;
  709. }
  710. /**
  711. * 提现
  712. * @param array $user_id 用户id
  713. * @param array $money 提现金额
  714. * @param array $pay_pwd 交易密码
  715. * @return [type] [description]
  716. */
  717. public function takeMoney($user_id, $money, $pwd, $bank_no)
  718. {
  719. if ($money < 100) {
  720. return -2112;
  721. }
  722. $account = $this->getAccount($user_id);
  723. //检测用户资金
  724. $check = $this->check($user_id, $money);
  725. if ($check < 0) {
  726. return $check;
  727. }
  728. //验证交易密码
  729. if (!$this->verifyPayPwd($user_id, $pwd)) {
  730. return -2020;
  731. }
  732. //获取用户银行卡信息
  733. $bank_info = $this->getBankInfo($user_id, $bank_no);
  734. //生成订单id
  735. $order_id = OrderID();
  736. //提现后金额
  737. $nowMoney = $account['available_cash'] - $money;
  738. $nowCash = $account['cash'] - $money;
  739. //插入提现申请记录
  740. $data = array(
  741. 'info_identity' => UUID(),
  742. 'order_id' => $order_id,
  743. 'account_identity' => $user_id,
  744. 'account_name' => $account['account_name'],
  745. 'money' => $money,
  746. 'apply_time' => date('Y-m-d H:i:s', time()),
  747. 'apply_date' => date('Y-m-d', time()),
  748. 'bank_info' => $bank_info['bank_name'],
  749. 'bank_no' => $bank_no,
  750. 'bank_address' => $bank_info['bank_address'],
  751. 'bank_user' => $bank_info['account_name'],
  752. 'money_cash' => $nowMoney,
  753. );
  754. //验证三分钟内不能重复提交提现申请
  755. $txTime = lm($this->money_take, 'commons')->select('apply_time')->where('account_identity', $user_id)->orderBy('apply_time', 'desc')->first();
  756. $applyTime = date('Y-m-d H:i:s', time() - 300);
  757. if ($txTime) {
  758. if (!empty($txTime->apply_time) && $txTime->apply_time >= $applyTime) {
  759. return '-2051';
  760. }
  761. }
  762. _beginTransaction();
  763. try {
  764. $res = lm($this->money_take, 'Commons')->insert($data);
  765. if ($res) {
  766. $res1 = $this->updateAccountMoney($user_id, $money, 2, $nowMoney, $account['available_cash']);
  767. if ($res1 < 0) {
  768. throw new PDOException($res1);
  769. //return $res1;
  770. }
  771. $resdetail = $this->insertDetail($user_id, '', $money, $nowMoney, 15);
  772. //return $this->insertMoney($user_id, $money, $order_id, 5);
  773. //return 1;
  774. if ($resdetail < 0) {
  775. throw new PDOException($resdetail);
  776. }
  777. } else {
  778. throw new PDOException(-2113);
  779. //return -2113;
  780. }
  781. _commit();
  782. return 1;
  783. } catch (PDOException $e) {
  784. _rollBack();
  785. return $e->getMessage();
  786. }
  787. }
  788. /**
  789. * 撤单
  790. * @param [type] $user_id 用户id
  791. * @param [type] $order_id 订单id
  792. * @param [type] $money 操作金额
  793. * @return [type] [description]
  794. */
  795. public function cancel($user_id, $order_id)
  796. {
  797. //获取订单信息
  798. $orderInfo = lm($this->money_buy, 'commons')->where('order_id', $order_id)->where('status', '<', 4)->first();
  799. if (!$orderInfo) {
  800. $this->money_buy = 'sixMoney_buy';
  801. $orderInfo = lm($this->money_buy, 'commons')->where('order_id', $order_id)->where('status', '<', 4)->first();
  802. if (!$orderInfo)return -2125;
  803. }
  804. $money = $this->getMoney($order_id);
  805. $account = $this->getAccount($user_id);
  806. $nowMoney = $account['available_cash'] + $money;
  807. // $now_allMoney = $account['cash'] + $money;
  808. //修改状态
  809. $desc = sprintf(lang()->get('user cancel'), lang()->get($orderInfo->game_name), $orderInfo->game_no, $account['account_name'], $order_id);
  810. // $desc = lang()->get($orderInfo->game_name) . '期号为:' . $orderInfo->game_no . ',' . $account['account_name'] . '撤销了订单,单号:' . $order_id;
  811. $res1 = lm($this->money_buy, 'Commons')->where('order_id', $order_id)->update(['status' => 4, 'get_money' => 0]);
  812. //更新用户金额
  813. $res = $this->updateAccountMoney($user_id, $money, 1, $nowMoney, $account['available_cash']);
  814. if (!$res) {
  815. return '-2034';
  816. }
  817. if (!$res1) {
  818. return -2034;
  819. }
  820. // //更新反水表
  821. $res2 = lm($this->money_back, 'Commons')->where('buy_identity', $order_id)->update(['status' => 3]);
  822. $res = $this->insertCancelData($account, $desc, $money, $nowMoney, 3, $order_id);
  823. if (!$res) {
  824. return '-2034';
  825. }
  826. return '1';
  827. }
  828. /**
  829. * 验证账户金额是否足够
  830. * @param [type] $money 操作所需金额
  831. * @param [type] $available_cash 账户可用金额
  832. * @return [type] [description]
  833. */
  834. public function verifyMoney($money, $available_cash)
  835. {
  836. if ($available_cash >= $money) {
  837. return true;
  838. } else {
  839. return false;
  840. }
  841. }
  842. /**
  843. * 验证账户金额是否异常
  844. * @param [type] $available_cash 账户可用金额
  845. * @param [type] $cash 账户总金额
  846. * @param [type] $frozen_cash 冻结金额
  847. * @return [type] true or FALSE
  848. */
  849. public function verifyAccount($available_cash, $cash, $frozen_cash)
  850. {
  851. if ($cash == $available_cash + $frozen_cash) {
  852. return true;
  853. } else {
  854. return false;
  855. }
  856. }
  857. /**
  858. * 检测用户账户情况
  859. * @param [type] $account_identity 用户id
  860. * @param [type] $money 操作金额
  861. * @return [type] [description]
  862. */
  863. public function check($account_identity, $money)
  864. {
  865. //获取用户信息;
  866. $account = $this->getAccount($account_identity);
  867. //检测用户信息
  868. if (!$this->verifyAccount($account['available_cash'], $account['cash'], $account['frozen_cash'])) {
  869. return -2021;
  870. }
  871. //检测用户资金
  872. if (!$this->verifyMoney($money, $account['available_cash'])) {
  873. return -2022;
  874. }
  875. return 1;
  876. }
  877. /**
  878. * 验证交易密码
  879. * @param [type] $account_identity 用户唯一id
  880. * @param [type] $pwd 密码
  881. * @return [type] true or false
  882. */
  883. public function verifyPayPwd($account_identity, $pwd)
  884. {
  885. $enc = lm($this->pay_password, 'commons')->select('encryption')->where('account_identity', $account_identity)->first();
  886. if ($enc) {
  887. $enc = $enc->toArray();
  888. } else {
  889. return false;
  890. }
  891. $VerPwd = md5(md5($enc["encryption"] . $pwd));
  892. //dump($VerPwd);
  893. $res = lm($this->pay_password, 'commons')->where(['account_identity' => $account_identity, 'pay_password' => $VerPwd])->first();
  894. if ($res) {
  895. return true;
  896. } else {
  897. return false;
  898. }
  899. }
  900. /**
  901. * 获取用户信息
  902. * @param [type] $account_identity 用户唯一id
  903. * @return [type] 用户资金相关数组
  904. */
  905. public function getAccount($account_identity)
  906. {
  907. // $data = array();
  908. /*$res = lm($this->account_detailed, 'Commons')
  909. ->select('available_cash', 'cash', 'frozen_cash', 'account_identity')
  910. ->where('account_identity', $account_identity)
  911. ->sharedLock()
  912. ->first();
  913. if ($res) {
  914. $res = $res->toArray();
  915. } else {
  916. return -4001;
  917. }
  918. $res2 = lm($this->account_table, 'commons')->select('account', 'status')->where('identity', $account_identity)->first()->toArray();
  919. $data = $res;
  920. $data['account_name'] = $res2['account'];
  921. $data['status'] = $res2['status'];*/
  922. $res = lm($this->account_list, 'Commons')
  923. ->select('account as account_name', 'account_status as status', 'available_cash', 'cash', 'frozen_cash', 'account_identity')
  924. ->where('identity', $account_identity)->first();
  925. // print_r(lm($this->account_list, 'Commons')->getsql());
  926. if ($res) {
  927. return $res->toArray();
  928. } else {
  929. return -4001;
  930. }
  931. }
  932. /**
  933. * 根据代理id获取代理信息
  934. * @param [string] $agent_id 代理id
  935. * @return [array] 代理相关信息
  936. */
  937. public function getAgent($agent_id)
  938. {
  939. $res = lm($this->agent, 'Commons')
  940. ->select('agent_user', 'agent_identity', 'take_money')
  941. ->where('agent_identity', $agent_id)
  942. ->first();
  943. if ($res) {
  944. $agent = $res->toArray();
  945. } else {
  946. return '-2001';
  947. }
  948. return $agent;
  949. }
  950. /**
  951. * 通过审核
  952. * @param [type] $identity 信息id
  953. * @return [type] [description]
  954. */
  955. public function pass_take($identity)
  956. {
  957. # code...
  958. }
  959. /**
  960. * 完成提现
  961. * @param [type] $identity 信息id
  962. * @return [type] [description]
  963. */
  964. public function give_take($identity)
  965. {
  966. }
  967. /**
  968. * 更新数据
  969. * @param [type] $gameName [description]
  970. * @param [type] $moeny [description]
  971. * @param [type] $code [description]
  972. * @return [type] [description]
  973. */
  974. public function codeMoneyBack($gameName, $order_id, $code)
  975. {
  976. $res1 = lm("money_buy", 'commons')->where('order_id', $order_id)->update(['codes' => json_encode($code)]);
  977. if ($res1) {
  978. $res2 = lm($gameName . "_buy", 'commons')->where('order_id', $order_id)->update(['codes' => json_encode($code)]);
  979. if ($res2) {
  980. return 1;
  981. }
  982. }
  983. return -2016;
  984. }
  985. /**
  986. * 反水记录增加
  987. * @param string $account_identity 用户id
  988. * @param [type] $money 金额
  989. * @param string $game_name 游戏名
  990. * @param string $buy_id 购买记录id
  991. * @param [type] $ratio 反水比例
  992. * @return [type] [description]
  993. */
  994. public function back_money($account_identity, $money, $game_name, $buy_id, $ratio,$buy_identity='')
  995. {
  996. if(empty($buy_identity)){
  997. $buy_identity=UUID();
  998. }
  999. //获取用户信息
  1000. $account = $this->getAccount($account_identity);
  1001. //获取游戏信息
  1002. $game = new \Biz\Game\GameQuery;
  1003. $game_info = $game->getGameInfo($game_name);
  1004. //查询是否反水
  1005. $check = lm($this->money_back, 'Commons')->where('buy_identity', $buy_id)->first();
  1006. if ($check) {
  1007. return -2113;
  1008. }
  1009. //生成订单id
  1010. $order_id = OrderID();
  1011. //插入反水信息
  1012. $data = array(
  1013. 'info_identity' => $buy_identity,
  1014. 'order_id' => $order_id,
  1015. 'account_name' => $account['account_name'],
  1016. 'account_identity' => $account_identity,
  1017. 'game_name' => $game_info['table_name'],
  1018. 'game_id' => $game_info['identity'],
  1019. 'buy_identity' => $buy_id,
  1020. 'money' => $money,
  1021. 'ratio' => $ratio,
  1022. 'processing_time' => date('Y-m-d H:i:s', time()),
  1023. );
  1024. $res = lm($this->money_back, 'Commons')->insert($data);
  1025. if ($res) {
  1026. return 1;
  1027. } else {
  1028. return -2113;
  1029. }
  1030. }
  1031. /**
  1032. * 确认反水
  1033. * @param [type] $order_id 购买订单
  1034. * @return [type] [description]
  1035. */
  1036. public function suer_back($order_id)
  1037. {
  1038. $info = lm($this->money_back, 'Commons')->where('buy_identity', $order_id)->where('status', '<>', 3)->first();
  1039. if (!$info) {
  1040. return -2113;
  1041. }
  1042. //$account=$this->getAccount($info->account_identity);
  1043. $res = lm($this->money_back, 'Commons')->where('buy_identity', $order_id)->update(['status' => 3]);
  1044. if ($res) {
  1045. return $this->insertMoney($info->account_identity, $info->money, $info->order_id, 7);
  1046. }
  1047. return -2113;
  1048. }
  1049. /**
  1050. * 回水操作
  1051. * @param string $account_identity 用户id
  1052. * @param string $money 金额
  1053. * @param string $ratio 回水比例
  1054. * @param string $total_money 亏损总金额
  1055. * @return [type] [description]
  1056. */
  1057. public function return_money($account_identity, $money, $ratio, $total_money)
  1058. {
  1059. //获取用户信息
  1060. $account = $this->getAccount($account_identity);
  1061. //生成订单id
  1062. $order_id = OrderID();
  1063. //加入回水记录
  1064. $data = array(
  1065. 'info_identity' => UUID(),
  1066. 'order_id' => $order_id,
  1067. 'account_name' => $account['account_name'],
  1068. 'account_identity' => $account_identity,
  1069. 'money' => $money,
  1070. 'ratio' => $ratio,
  1071. 'total_money' => $total_money,
  1072. 'processing_time' => date('Y-m-d H:i:s', time()),
  1073. );
  1074. $res = lm($this->money_return, 'Commons')->insert($data);
  1075. if ($res) {
  1076. return $this->insertMoney($account_identity, $money, $order_id, 8);
  1077. } else {
  1078. return -2113;
  1079. }
  1080. }
  1081. /**
  1082. * 管理员扣款
  1083. * @param [type] $account_identity 用户id
  1084. * @param [type] $money 金额
  1085. * @return [type] [description]
  1086. */
  1087. public function cut_money($account_identity, $money)
  1088. {
  1089. //检测用户资金
  1090. $check = $this->check($account_identity, $money);
  1091. if ($check < 0) {
  1092. return $check;
  1093. }
  1094. //生成订单id
  1095. $order_id = OrderID();
  1096. return $this->insertMoney($account_identity, $money, $order_id, 9);
  1097. }
  1098. /**
  1099. * 资金记录修改
  1100. * @param string $account_identity 用户id
  1101. * @param string $money 金额
  1102. * @param 订单号 $order_id 订单号
  1103. * @param int $type 交易类型
  1104. * @return [type] [description]
  1105. */
  1106. public function insertMoney($account_identity, $money, $order_id, $type, $game_name = '', $game_no = '',$account=array(),$game_eName='')
  1107. {
  1108. // lm($this->account_detailed, 'Commons')->beginTransaction();
  1109. //_beginTransaction();
  1110. //获取用户信息
  1111. if(!is_array($account)){
  1112. return -3219;
  1113. }
  1114. if(is_array($account)&&count($account)<1){
  1115. $account = $this->getAccount($account_identity);
  1116. }
  1117. //computeTime('获取用户信息');
  1118. if ($type == 4) {
  1119. lm("message", 'commons')->updateMessage('admin', $account['account_name'], '中奖提示', '恭喜你中奖,您在' . $game_name . '中的第' . $game_no . '期中,中奖:' . $money . '元', 2);
  1120. }
  1121. //获取money_type
  1122. $m_type = $this->getMtype($type);
  1123. //computeTime('获取money_type');
  1124. //总资金记录表
  1125. if ($m_type == 1) {
  1126. $nowMoney = $account['available_cash'] + $money;
  1127. // $nowCash = $account['cash'] + $money;
  1128. } else {
  1129. $nowMoney = $account['available_cash'] - $money;
  1130. // $nowCash = $account['cash'] - $money;
  1131. }
  1132. //更新用户余额
  1133. if($game_eName='sixlottery' || $gameName=='sfsixlottery'){
  1134. $res2 = $this->updateAccountSixMoney($account_identity, $money, $m_type, $nowMoney, $account['available_cash']);
  1135. }else{
  1136. $res2 = $this->updateAccountMoney($account_identity, $money, $m_type, $nowMoney, $account['available_cash']);
  1137. }
  1138. // computeTime('更新用户余额结束' . var_export($res2, 1));
  1139. if ($res2 > 0) {
  1140. if (empty($game_name)) {
  1141. $res3 = $this->insertDetail($account_identity, $order_id, $money, $nowMoney, $type);
  1142. } else {
  1143. $res3 = $this->insertDetail($account_identity, $order_id, $money, $nowMoney, $type, $order_id, $game_name, $game_no,$account);
  1144. }
  1145. //computeTime('添加详细' . $res3);
  1146. if ($res3 > 0) {
  1147. //_commit();
  1148. return 1;
  1149. } else {
  1150. //_rollBack();
  1151. return $res3;
  1152. }
  1153. } else {
  1154. //_rollBack();
  1155. return $res2;
  1156. }
  1157. //computeTime('插入资金详情结束');
  1158. }
  1159. /**
  1160. * 获取描述信息
  1161. * @param string $account_name 用户名
  1162. * @param string $money 金额
  1163. * @param string $order_id 订单号
  1164. * @param int $type 操作类型
  1165. * @return [type] [description]
  1166. */
  1167. public function getDesc($account_name, $money, $order_id, $type, $game_name = '', $game_no = '')
  1168. {
  1169. // return ;
  1170. switch ($type) {
  1171. case 1:
  1172. return sprintf(lang()->get('user betting'), $game_name, $game_no, $account_name, $money, $order_id);
  1173. break;
  1174. case 2:
  1175. return sprintf(lang()->get('user append'), $game_name, $game_no, $account_name, $money, $order_id);
  1176. break;
  1177. case 3:
  1178. return sprintf(lang()->get('user cancel'), $game_name, $game_no, $account_name, $order_id);
  1179. break;
  1180. case 4:
  1181. return sprintf(lang()->get('user prize'), $game_name, $game_no, $account_name, $money, $order_id);
  1182. break;
  1183. case 5:
  1184. return sprintf(lang()->get('user take money'), $account_name, $money, $order_id);
  1185. break;
  1186. case 6:
  1187. return sprintf(lang()->get('user charge money'), $account_name, $money, $order_id);
  1188. break;
  1189. case 7:
  1190. return sprintf(lang()->get('user back money'), $account_name, $money, $order_id);
  1191. break;
  1192. case 8:
  1193. return sprintf(lang()->get('user return money'), $account_name, $money, $order_id);
  1194. break;
  1195. case 9:
  1196. return sprintf(lang()->get('cancel prize'), $game_name, $game_no, $account_name, $money, $order_id);
  1197. break;
  1198. case 10:
  1199. return sprintf(lang()->get('user empty money'), $account_name, $money, $order_id);
  1200. break;
  1201. case 11:
  1202. return sprintf(lang()->get('user cut money'), $account_name, $money, $order_id);
  1203. break;
  1204. case 15:
  1205. return sprintf(lang()->get('frozen money'), $account_name, $money, $order_id);
  1206. break;
  1207. default:
  1208. return '';
  1209. break;
  1210. }
  1211. }
  1212. /**
  1213. * 获取状态
  1214. * @param [type] $type 操作类型
  1215. * @return [type] [description]
  1216. */
  1217. public function getStatus($type)
  1218. {
  1219. $arr = array(
  1220. '1' => '投注',
  1221. '2' => '追号',
  1222. '3' => '撤单',
  1223. '4' => '派奖',
  1224. '5' => '审核中',
  1225. '6' => '待支付',
  1226. '7' => '成功',
  1227. '8' => '成功',
  1228. '9' => '扣款',
  1229. '10' => '佣金提成',
  1230. );
  1231. return $arr[$type];
  1232. }
  1233. /**
  1234. * 返回money_type
  1235. * @param [type] $type 类型
  1236. * @return [type] [description]
  1237. */
  1238. public function getMtype($type)
  1239. {
  1240. $arr = array(
  1241. '1' => 2,
  1242. '2' => 2,
  1243. '3' => 1,
  1244. '4' => 1,
  1245. '5' => 2,
  1246. '6' => 1,
  1247. '7' => 1,
  1248. '8' => 1,
  1249. '9' => 2,
  1250. '10' => 1,
  1251. '11' => 2,
  1252. '15' => 2,
  1253. );
  1254. return $arr[$type];
  1255. }
  1256. /**
  1257. * 获取用户绑定银行卡信息
  1258. * @param [type] $account_identity 用户唯一id
  1259. * @param [type] $bank_no 银行卡号
  1260. * @return [type] [description]
  1261. */
  1262. public function getBankInfo($account_identity, $bank_no)
  1263. {
  1264. $res = lm($this->bank_table, 'Commons')
  1265. ->select('bank_number', 'account_name', 'bank_address', 'bank_name')
  1266. ->where(['account_identity' => $account_identity, 'bank_number' => $bank_no])
  1267. ->first();
  1268. if ($res) {
  1269. $data = $res->toArray();
  1270. } else {
  1271. return -2114;
  1272. }
  1273. return $data;
  1274. }
  1275. /**
  1276. * 根据英文游戏名及订单号获取用户投注号码
  1277. * @param [type] $order_id 订单号
  1278. * @param [type] $game_name 游戏英文名
  1279. * @return [type] 购买号码
  1280. */
  1281. public function getCodes($order_id, $game_name)
  1282. {
  1283. $table = $game_name . '_buy';
  1284. $res = lm($table, 'Commons')->select('codes')->where('order_id', $order_id)->first();
  1285. return $res->codes;
  1286. }
  1287. /**
  1288. * 根据投注订单查询实际消费金额
  1289. * @param [type] $order_id 投注订单
  1290. * @return string 实际消费金额
  1291. */
  1292. public function getMoney($order_id)
  1293. {
  1294. //获取投注金额
  1295. $money = lm($this->money_details, 'Commons')->where('trade_id', $order_id)->first();
  1296. if ($money) {
  1297. $money = $money->money;
  1298. } else {
  1299. return -2115;
  1300. }
  1301. return $money;
  1302. }
  1303. /**
  1304. * 更新用户金额
  1305. * @param [type] $money 操作金额
  1306. * @param [type] $nowCash 做类型
  1307. * @param [type] $last_money 操作后金额
  1308. * @param [type] $Cash 当前余额
  1309. * @return [type] [description]
  1310. */
  1311. public function updateAccountMoney($account_identity, $money, $type, $last_money, $cash = '')
  1312. {
  1313. //更新用户余额
  1314. /* // computeTime('更新用户余额开始');
  1315. if (!empty($cash)) {
  1316. $res=$this->checkWater($account_identity,$cash);
  1317. if($res<0){
  1318. return $res;
  1319. }
  1320. }*/
  1321. // computeTime('验证用户资金结束');
  1322. $res=S('DB')->select("select update_money('".$account_identity."',".$money.",".$type.")");
  1323. return 1;
  1324. /*if ($type == 1) {
  1325. $res3 = lm($this->account_detailed, 'Commons')->where('account_identity', $account_identity)->where('available_cash', '<', $last_money)->increment('available_cash', $money);
  1326. $res4 = lm($this->account_detailed, 'Commons')->where('account_identity', $account_identity)->where('cash', '<', $last_money)->increment('cash', $money);
  1327. } else {
  1328. $res3 = lm($this->account_detailed, 'Commons')->where('account_identity', $account_identity)->where('available_cash', '>', $last_money)->decrement('available_cash', $money);
  1329. $res4 = lm($this->account_detailed, 'Commons')->where('account_identity', $account_identity)->where('cash', '>', $last_money)->decrement('cash', $money);
  1330. }*/
  1331. //print_r(array($type,$account_identity,$money,$last_money,$cash));
  1332. /*if ($res) {
  1333. return 1;
  1334. } else {
  1335. return -2113;
  1336. }*/
  1337. }
  1338. function updateAccountSixMoney($account_identity, $money, $type, $last_money='', $cash = ''){
  1339. //更新用户余额
  1340. /*if (!empty($cash)) {
  1341. $res=$this->checkWater($account_identity,$cash);
  1342. if($res<0){
  1343. return $res;
  1344. }
  1345. }*/
  1346. $res=S('DB')->select("select update_money('".$account_identity."',".$money.",".$type.")");
  1347. return 1;
  1348. }
  1349. //
  1350. /**
  1351. * 检测资金流水情况
  1352. * @param $account_identity
  1353. * @param $cash
  1354. */
  1355. public function checkWater($account_identity, $NowCash)
  1356. {
  1357. //查询最后一条资金余额
  1358. $last_data = lm($this->money_details, 'commons')->where('account_identity', $account_identity)->orderBy('id', 'desc')->first();
  1359. if (!$last_data) {
  1360. return -2113;
  1361. }
  1362. $last_data = $last_data->toArray();
  1363. if ($last_data['money_cash'] != $NowCash) {
  1364. return -2255;
  1365. }
  1366. return 1;
  1367. }
  1368. /**
  1369. * 插入资金详情
  1370. * @param [type] $user_id 用户id
  1371. * @param [type] $trade_id 交易id
  1372. * @param [type] $money 交易金额
  1373. * @param [type] $nowMoney 剩余金额
  1374. * @param [type] $type 交易类型的数字表示
  1375. * @return [type] [description]
  1376. */
  1377. public function insertDetail($user_id, $trade_id, $money, $nowMoney, $type, $buy_id = '', $gamename = '', $gameNo = '',$account=array())
  1378. {
  1379. if(!is_array($account)){
  1380. return -3219;
  1381. }
  1382. if(is_array($account)&&count($account)<1){
  1383. //computeTime('getAccount');
  1384. $account = $this->getAccount($user_id);
  1385. }
  1386. //computeTime('getMtype');
  1387. //获取money_type
  1388. $m_type = $this->getMtype($type);
  1389. if (empty($trade_id)) {
  1390. $trade_id = OrderID();
  1391. }
  1392. if (empty($buy_id)) {
  1393. $trade_desc = $this->getDesc($account['account_name'], $money, $trade_id, $type);
  1394. } else {
  1395. $trade_desc = $this->getDesc($account['account_name'], $money, $buy_id, $type, $gamename, $gameNo);
  1396. }
  1397. $data2 = array(
  1398. 'info_identity' => UUID(),
  1399. 'trade_id' => $trade_id,
  1400. 'account_name' => $account['account_name'],
  1401. 'account_identity' => $user_id,
  1402. 'money' => $money,
  1403. 'money_time' => date('Y-m-d H:i:s', time()),
  1404. 'money_type' => $m_type,
  1405. 'money_cash' => $nowMoney,
  1406. //'status' => $status,
  1407. 'trade_type' => $type,
  1408. 'trade_desc' => $trade_desc,
  1409. );
  1410. $res3 = lm($this->money_details, 'commons')->insert($data2);
  1411. if ($res3) {
  1412. return 1;
  1413. }
  1414. return -2049;
  1415. }
  1416. //测单记录插入
  1417. public function insertCancelData($account, $desc, $money, $nowMoney, $type, $out_id)
  1418. {
  1419. $insert_Data = array(
  1420. 'info_identity' => UUID(),
  1421. 'trade_id' => OrderID(),
  1422. 'account_name' => $account['account_name'],
  1423. 'account_identity' => $account['account_identity'],
  1424. 'money' => $money,
  1425. 'money_time' => date('Y-m-d H:i:s'),
  1426. 'money_type' => 1,
  1427. 'money_cash' => $nowMoney,
  1428. 'trade_type' => $type,
  1429. 'trade_desc' => $desc,
  1430. 'out_order_id' => $out_id,
  1431. );
  1432. $res3 = lm($this->money_details, 'commons')->insert($insert_Data);
  1433. if ($res3) {
  1434. return 1;
  1435. }
  1436. return -2049;
  1437. }
  1438. /**
  1439. * 绑定银行卡,新增2018-10-26,绑定银行卡时不需要交易密码
  1440. * @param [type] $account_identity 用户id
  1441. * @param [type] $bank_address 开户银行地址
  1442. * @param [type] $bank_name 银行名称
  1443. * @param [type] $bank_no 银行卡号
  1444. * @param [type] $bank_user 银行卡用户
  1445. * @return [type] [description]
  1446. */
  1447. public function bindBank($account_identity, $bank_address, $bank_name, $bank_no, $bank_user)
  1448. {
  1449. //判断重要参数是否为空
  1450. if (empty($account_identity)) {
  1451. return '-2001';
  1452. }
  1453. /*if (empty($bank_address)) {
  1454. return '-2002';
  1455. }*/
  1456. if (empty($bank_name)) {
  1457. return '-2003';
  1458. }
  1459. if (empty($bank_no)) {
  1460. return '-2004';
  1461. }
  1462. if (empty($bank_user)) {
  1463. return '-2005';
  1464. }
  1465. //验证用户是否已经绑定了该银行卡
  1466. $res = lm($this->bank_table, 'commons')->where(['account_identity' => $account_identity])->first();
  1467. if ($res) {
  1468. return '-2033';
  1469. }
  1470. //检测该银行卡是否已经绑定
  1471. $res2 = lm($this->bank_table, 'commons')->where('bank_number', $bank_no)->first();
  1472. if ($res2) {
  1473. return '-2136';
  1474. }
  1475. //检测开户人姓名是否与用户真实姓名相同
  1476. $userName = lm($this->account_detailed, 'commons')->select('name')->where('account_identity', $account_identity)->first();
  1477. if ($userName) {
  1478. if (!empty($userName->name) && $userName->name != $bank_user) {
  1479. return '-3311';
  1480. }
  1481. } else {
  1482. return '-4001';
  1483. }
  1484. //为用户绑定银行卡
  1485. $data = array(
  1486. 'identity' => UUID(),
  1487. 'account_identity' => $account_identity,
  1488. 'bank_address' => $bank_address,
  1489. 'bank_name' => $bank_name,
  1490. 'account_name' => $bank_user,
  1491. 'bank_number' => $bank_no,
  1492. 'band_time' => date('Y-m-d H:i:s', time()),
  1493. );
  1494. $res = lm($this->bank_table, 'commons')->insert($data);
  1495. $resd = lm($this->account_detailed, 'commons')->select('name')->where('account_identity', $account_identity)->first();
  1496. if (empty($resd->name)) {
  1497. lm($this->account_detailed, 'commons')->where('account_identity', $account_identity)->update(['name' => $bank_user]);
  1498. }
  1499. if ($res) {
  1500. return 1;
  1501. } else {
  1502. return '-2009';
  1503. }
  1504. }
  1505. }