Moneycopy.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. <?php
  2. namespace Biz\Money;
  3. /**
  4. * 资金操作相关类
  5. */
  6. class Moneycopy {
  7. /**
  8. * 资金明细表
  9. * @var string
  10. */
  11. private $money_table = 'fund_detailed';
  12. /**
  13. * 用户详情表
  14. * @var string
  15. */
  16. private $account_detailed = 'account_detailed';
  17. /**
  18. * 用户银行绑定记录表
  19. * @var string
  20. */
  21. private $bank_table = 'account_bank';
  22. /**
  23. * 用户表
  24. * @var string
  25. */
  26. private $account_table = 'account';
  27. /**
  28. * 交易密码表
  29. * @var string
  30. */
  31. private $pay_password = 'pay_password';
  32. /**
  33. * 代理信息表
  34. * @var string
  35. */
  36. private $agent = 'agent_detailed';
  37. /**
  38. * 代理资金表
  39. * @var string
  40. */
  41. private $agent_money = 'agent_money';
  42. /**
  43. * 佣金记录表
  44. * @var string
  45. */
  46. private $money_reward = 'money_reward';
  47. /**
  48. * 资金明细表
  49. * @var string
  50. */
  51. private $money_details = 'money_details';
  52. /**
  53. * 中奖记录表
  54. * @var string
  55. */
  56. private $prize_table = 'money_prize';
  57. /**
  58. * 提现记录表
  59. * @var string
  60. */
  61. private $money_take = 'money_take';
  62. /**
  63. * 充值记录
  64. * @var string
  65. */
  66. private $money_recharge = 'money_recharge';
  67. /**
  68. * 反水记录表
  69. * @var string
  70. */
  71. private $money_back = 'money_back';
  72. /**
  73. * 回水记录表
  74. * @var string
  75. */
  76. private $money_return = 'money_return';
  77. //private $game;
  78. public function init() {
  79. }
  80. /**
  81. * 绑定银行卡
  82. * @param [type] $account_identity 用户id
  83. * @param [type] $bank_address 开户银行地址
  84. * @param [type] $bank_name 银行名称
  85. * @param [type] $bank_no 银行卡号
  86. * @param [type] $bank_user 银行卡用户
  87. * @param [type] $pay_pwd 支付密码
  88. * @param [type] $sure_pwd 确认密码
  89. * @return [type] [description]
  90. */
  91. public function bind_bank($account_identity, $bank_address, $bank_name, $bank_no, $bank_user, $pay_pwd, $sure_pwd) {
  92. //判断重要参数是否为空
  93. if (empty($account_identity)) {
  94. //Render('null','-2001',lang()->get('user not login'));
  95. return '-2001';
  96. }
  97. if (empty($bank_address)) {
  98. //Render('null','-2002',lang()->get('bank_address missing'));
  99. return '-2002';
  100. }
  101. if (empty($bank_name)) {
  102. //Render('null','-2003',lang()->get('bank_name missing'));
  103. return '-2003';
  104. }
  105. if (empty($bank_no)) {
  106. //Render('null','-2004',lang()->get('bank_number missing'));
  107. return '-2004';
  108. }
  109. if (empty($bank_user)) {
  110. //Render('null','-2005',lang()->get('bank_user missing'));
  111. return '-2005';
  112. }
  113. if (empty($pay_pwd) || empty($sure_pwd)) {
  114. //Render('null','-2006',lang()->get('password missing'));
  115. return '-2006';
  116. }
  117. //判断两次交易密码是否一致
  118. if ($pay_pwd != $sure_pwd) {
  119. //Render('null','-2007',lang()->get('two password not equal'));
  120. return '-2007';
  121. }
  122. //验证用户是否已设置交易密码
  123. $enc = lm($this->pay_password, 'commons')->select('encryption')->where('account_identity', $account_identity)->first()->toArray();
  124. $VerPwd = md5(md5($enc["encryption"] . $pay_pwd));
  125. $judge = lm($this->pay_password, 'commons')->where(['account_identity' => $account_identity, 'pay_password' => $VerPwd])->first();
  126. if (empty($judge)) {
  127. //Render('null','-2008',lang()->get('pay_pwd not set'));
  128. return '-2008';
  129. }
  130. //验证交易密码
  131. if (!$this->verifyPayPwd($account_identity, $pay_pwd)) {
  132. return '-2020';
  133. }
  134. //验证用户是否已经绑定了该银行卡
  135. $res = lm($this->bank_table, 'commons')->where(['account_identity' => $account_identity, 'bank_number' => $bank_no])->first();
  136. if ($res) {
  137. return '-2033';
  138. }
  139. //为用户绑定银行卡
  140. $data = array(
  141. 'identity' => UUID(),
  142. 'account_identity' => $account_identity,
  143. 'bank_address' => $bank_address,
  144. 'bank_name' => $bank_name,
  145. 'account_name' => $bank_user,
  146. 'bank_number' => $bank_no,
  147. 'band_time' => date('Y-m-d H:i:s', time()),
  148. );
  149. $res = lm($this->bank_table, 'commons')->insert($data);
  150. if ($res) {
  151. //Render('null','1',lang()->get('success'));
  152. return 1;
  153. } else {
  154. //Render('null','-2009',lang()->get('fail'));
  155. return '-2009';
  156. }
  157. }
  158. /**
  159. * 设置默认银行卡或者解绑银行卡
  160. * @param [type] $account_identity 用户id
  161. * @param [type] $bank_no 银行卡号
  162. * @param [type] $pay_pwd 交易密码
  163. * @param [type] $type 类型 1.设置默认银行卡,-1,解除该银行卡绑定
  164. * @return [type] [description]
  165. */
  166. public function bankStatus($account_identity, $bank_no, $pay_pwd, $type) {
  167. if ($type == 1) {
  168. $type = 2;
  169. }
  170. if (!$this->verifyPayPwd($account_identity, $pay_pwd)) {
  171. return '-2020';
  172. }
  173. $res = lm($this->bank_table, 'commons')->where(['account_identity' => $account_identity, 'bank_number' => $bank_no])->update(['status' => $type]);
  174. if ($res) {
  175. return '1';
  176. } else {
  177. return '-2016';
  178. }
  179. }
  180. /**
  181. * 设置交易密码
  182. * @param [type] $account_identity 用户id
  183. * @param [type] $pay_pwd 密码
  184. * @param [type] $sure_pwd 确认密码
  185. */
  186. public function setPayPwd($account_identity, $pay_pwd, $sure_pwd) {
  187. //判断重要参数是否为空
  188. if (empty($account_identity)) {
  189. //Render('null','-2010',lang()->get('user not login'));
  190. return '-2010';
  191. }
  192. if (empty($pay_pwd) || empty($sure_pwd)) {
  193. //Render('null','-2011',lang()->get('password missing'));
  194. return '-2006';
  195. }
  196. //判断两次交易密码是否一致
  197. if ($pay_pwd != $sure_pwd) {
  198. //Render('null','-2012',lang()->get('two password not equal'));
  199. return '-2007';
  200. }
  201. //检查用户是否已经设置密码
  202. $judge = lm($this->pay_password, 'commons')->where(['account_identity' => $account_identity])->first();
  203. if ($judge) {
  204. return '-2017';
  205. }
  206. //为用户设置交易密码
  207. $pwd = GenPassword($pay_pwd);
  208. $data = array(
  209. 'identity' => UUID(),
  210. 'pay_password' => $pwd['password'],
  211. 'encryption' => $pwd['encryption'],
  212. 'account_identity' => $account_identity,
  213. );
  214. $res = lm($this->pay_password, 'commons')->insert($data);
  215. if ($res) {
  216. //Render('null','1',lang()->get('success'));
  217. return '1';
  218. } else {
  219. //Render('null','-2013',lang()->get('fail'));
  220. return '-2013';
  221. }
  222. }
  223. /**
  224. * 投注追号
  225. * @param [type] $user_id 用户id
  226. * @param [type] $money 投注追号金额
  227. * @param array $extra 其他数据
  228. * @return [type] [description]
  229. */
  230. public function betting($user_id, $money, $extra = array()) {
  231. $type = 1;
  232. //处理数据
  233. if (isset($extra['type_name']) && !empty($extra['type_name'])) {
  234. $game = new \Biz\Game\GameQuery;
  235. $res = $game->getGameInfo($extra['type_name']);
  236. $extra['game_type'] = $res['identity'];
  237. unset($extra['type_name']);
  238. }
  239. $data = $extra;
  240. return $this->updateMoney($user_id, $money, $type, $data);
  241. }
  242. /**
  243. * 中奖
  244. */
  245. public function prize($user_id, $money, $game_type, $buy_identity) {
  246. $type = 0;
  247. $data['money_type'] = 7;
  248. $data['identity'] = UUID();
  249. $data['order_id'] = OrderID();
  250. $data['game_type'] = $game_type;
  251. $data['buy_identity'] = $buy_identity;
  252. return $this->updateMoney($user_id, $money, $type, $data);
  253. }
  254. /**
  255. * 充值
  256. * @param $user_id 用户id
  257. * @param $money 充值金额
  258. * @param array $extra 其他参数数组
  259. */
  260. public function addMoney($user_id, $money, $extra = array()) {
  261. $type = 0;
  262. $data = $extra;
  263. $data['money_type'] = 3;
  264. //$data['identity']= UUID();
  265. $data['order_id'] = OrderID();
  266. return $this->updateMoney($user_id, $money, $type, $data);
  267. }
  268. /**
  269. * 提现
  270. * @param array $user_id 用户id
  271. * @param array $money 提现金额
  272. * @param array $pay_pwd 交易密码
  273. * @return [type] [description]
  274. */
  275. public function takeMoney($user_id, $money, $pay_pwd, $bank_no) {
  276. if ($money < 100) {
  277. return '-2112';
  278. }
  279. $account = $this->getAccount($user_id);
  280. if (!$this->verifyAccount($account['available_cash'], $account['cash'], $account['frozen_cash'])) {
  281. return '-2021';
  282. }
  283. if (!$this->verifyMoney($money, $account['available_cash'])) {
  284. return '-2022';
  285. }
  286. //验证交易密码
  287. if (!$this->verifyPayPwd($user_id, $pay_pwd)) {
  288. return '-2020';
  289. }
  290. $data['account_identity'] = $user_id;
  291. $data['account_name'] = $account['account_name'];
  292. $data['identity'] = UUID();
  293. $data['order_id'] = OrderID();
  294. $data['money_time'] = date('Y-m-d H:i:s', time());
  295. $data['money_date'] = date('Y-m-d', time());
  296. $data['money_type'] = 4;
  297. $data['remarks'] = $bank_no;
  298. $data['money'] = $money;
  299. $res = lm($this->money_table, 'commons')->insert($data);
  300. if ($res) {
  301. //Render('null','1',lang()->get('success'));
  302. return '1';
  303. } else {
  304. // Render('null','-2014',lang()->get('cash fail'));
  305. return '-2014';
  306. }
  307. }
  308. /**
  309. * 更新资金
  310. * @param [type] $user_id 用户id
  311. * @param [type] $money 操作金额
  312. * @param integer $type 变化资金类型
  313. * @param array $extra 扩展数组
  314. * @return [type] [description]
  315. */
  316. public function updateMoney($user_id, $money, $type = 0, $extra = array()) {
  317. if (empty($extra['game_type'])) {
  318. $extra['game_type'] = 1;
  319. }
  320. $extra['buy_identity'] = isset($extra['buy_identity']) ? $extra['buy_identity'] : '';
  321. $account = $this->getAccount($user_id); //获取用户信息
  322. //验证账户异常
  323. if (!$this->verifyAccount($account['available_cash'], $account['cash'], $account['frozen_cash'])) {
  324. return 'error-2021';
  325. }
  326. //验证用户金额
  327. if (!$this->verifyMoney($money, $account['available_cash'])) {
  328. return 'error-2022';
  329. }
  330. //判断是那种更新
  331. if ($type == 0) {
  332. //增加资金
  333. $nowMoney = $account['available_cash'] + $money;
  334. $now_allMoney = $account['cash'] + $money;
  335. } else {
  336. //资金减少
  337. $nowMoney = $account['available_cash'] - $money;
  338. $now_allMoney = $account['cash'] - $money;
  339. }
  340. //更新用户余额
  341. $res = lm($this->account_detailed, 'Commons')
  342. ->where('account_identity', $user_id)
  343. ->update(
  344. ['cash' => $now_allMoney, 'available_cash' => $nowMoney]
  345. );
  346. if (!$res) {
  347. // Render('null','-2015',lang()->get('change fail'));
  348. return 'error-2016';
  349. }
  350. //查询剩余金额
  351. $extra['money_cash'] = lm($this->account_detailed, 'Commons')->where('account_identity', $user_id)->value('cash');
  352. // $data = array(
  353. // 'identity' => UUID(),
  354. // 'account_identity' => $user_id,
  355. // 'account_name' => $account['account_name'],
  356. // 'money_type' => $extra['money_type'],
  357. // 'money' => $money,
  358. // 'remarks' => $extra['buy_identity'],
  359. // 'order_id' => $extra['order_id'],
  360. // 'money_time' => date('Y-m-d H:i:s', time()),
  361. // 'money_date' => date('Y-m-d', time()),
  362. // 'game_type' => $extra['game_type'],
  363. // 'cur_cash' => $nowMoney,
  364. // 'status' => 1,
  365. // );
  366. // $result = lm($this->money_table, 'commons')->insert($data);
  367. $data = array(
  368. 'info_identity' => UUID(),
  369. 'trade_id' => $extra['order_number'],
  370. 'account_name' => $account['account_name'],
  371. 'account_identity'=> account_identity,
  372. 'money_type' => $extra['money_type'],//1.增加 2.减少
  373. 'money' => $money,
  374. 'money_time'=>$extra['money_time'],
  375. 'money_cash' => $extra['money_cash'],//剩余金额
  376. 'trade_type' => $extra['trade_type'],//交易类型
  377. 'trade_desc' => $extra['trade_desc'],//交易描述
  378. 'reason' => $extra['reason'],//理由
  379. // 'status' => $extra['status'], //1.成功,2失败
  380. );
  381. $result = lm('Money_details', 'commons')->insert($data);
  382. if (!$result) {
  383. // Render('null','2014',lang()->get('change fail'));
  384. return 'error-2016';
  385. }
  386. //Render('null','1',lang()->get('success'));
  387. return '1';
  388. }
  389. /**
  390. * 撤单
  391. * @param [type] $user_id 用户id
  392. * @param [type] $order_id 订单id
  393. * @param [type] $money 操作金额
  394. * @return [type] [description]
  395. */
  396. public function cancel($user_id, $order_id) {
  397. $money = lm($this->money_table, 'commons')->where('order_id', $order_id)->first()->money;
  398. $account = $this->getAccount($user_id);
  399. $nowMoney = $account['available_cash'] + $money;
  400. $now_allMoney = $account['cash'] + $money;
  401. //更新用户金额
  402. $res = lm($this->account_detailed, 'Commons')
  403. ->where('account_identity', $user_id)
  404. ->update(
  405. ['cash' => $now_allMoney, 'available_cash' => $nowMoney]
  406. );
  407. if ($res) {
  408. return '-2034';
  409. }
  410. //修改状态
  411. $res = lm($this->money_table, 'commons')->where('order_id', $order_id)->update(['state' => '0']);
  412. if ($res) {
  413. return '-2034';
  414. }
  415. return '1';
  416. }
  417. /**
  418. * 验证账户金额是否足够
  419. * @param [type] $money 操作所需金额
  420. * @param [type] $available_cash 账户可用金额
  421. * @return [type] [description]
  422. */
  423. public function verifyMoney($money, $available_cash) {
  424. if ($available_cash > $money) {
  425. return true;
  426. } else {
  427. return false;
  428. }
  429. }
  430. /**
  431. * 验证账户金额是否异常
  432. * @param [type] $available_cash 账户可用金额
  433. * @param [type] $cash 账户总金额
  434. * @param [type] $frozen_cash 冻结金额
  435. * @return [type] true or FALSE
  436. */
  437. public function verifyAccount($available_cash, $cash, $frozen_cash) {
  438. if ($cash == $available_cash + $frozen_cash) {
  439. return true;
  440. } else {
  441. return false;
  442. }
  443. }
  444. /**
  445. * 验证交易密码
  446. * @param [type] $account_identity 用户唯一id
  447. * @param [type] $pwd 密码
  448. * @return [type] true or false
  449. */
  450. public function verifyPayPwd($account_identity,$pwd) {
  451. $enc = lm($this->pay_password,'commons')->select('encryption')->where('account_identity', $account_identity)->first();
  452. dump($enc);die;
  453. // ->toArray()
  454. $VerPwd = md5(md5($enc["encryption"] . $pwd));
  455. $res = lm($this->pay_password,'commons')->where(['account_identity' => $account_identity, 'pay_password' => $VerPwd])->first();
  456. if ($res) {
  457. return true;
  458. } else {
  459. return false;
  460. }
  461. }
  462. /**
  463. * 获取用户信息
  464. * @param [type] $account_identity 用户唯一id
  465. * @return [type] 用户资金相关数组
  466. */
  467. public function getAccount($account_identity) {
  468. $data = array();
  469. $res = lm($this->account_detailed, 'Commons')
  470. ->select('available_cash', 'cash', 'frozen_cash', 'account_identity')
  471. ->where('account_identity', $account_identity)
  472. ->first()
  473. ->toArray();
  474. $res2 = lm($this->account_table, 'commons')->select('account')->where('identity', $account_identity)->first()->toArray();
  475. $data = $res;
  476. $data['account_name'] = $res2['account'];
  477. return $data;
  478. }
  479. /**
  480. * 根据代理id获取代理信息
  481. * @param [string] $agent_id 代理id
  482. * @return [array] 代理相关信息
  483. */
  484. public function getAgent($agent_id) {
  485. $res = lm($this->agent, 'Commons')
  486. ->select('agent_user', 'agent_identity', 'take_money')
  487. ->where('agent_identity', $agent_id)
  488. ->first();
  489. if ($res) {
  490. $agent = $res->toArray();
  491. } else {
  492. return '-2001';
  493. }
  494. return $agent;
  495. }
  496. /**
  497. * 新中奖信息
  498. * @param [type] $account_identity 用户id
  499. * @param [type] $money 金额
  500. * @param [type] $game_name 游戏英文名
  501. * @return [type] [description]
  502. */
  503. public function newPrize($account_identity, $money, $game_name, $buy_id) {
  504. $game = new \Biz\Game\GameQuery;
  505. //获取游戏信息
  506. $game = $game->getGameInfo($game_name);
  507. //获取用户信息
  508. $account = $this->getAccount($account_identity);
  509. //生成订单id
  510. $order_id = OrderID();
  511. //生成信息id
  512. $info_id = UUID();
  513. //将中奖插入中奖记录
  514. $data = array(
  515. 'game_name' => $game['name'],
  516. 'buy_id' => $buy_id,
  517. 'account_name' => $account['account_name'],
  518. 'account_identity' => $account_identity,
  519. 'order_id' => $order_id,
  520. 'info_identity' => $info_id,
  521. 'money' => $money,
  522. 'money_time' => date('Y-m-d H:i:s', time()),
  523. );
  524. $res = lm($this->prize_table, 'Commons')->insert($data);
  525. if ($res) {
  526. $type = 4;
  527. return $this->insertMoney($account_identity, $money, $order_id, $type);
  528. } else {
  529. return '-2113';
  530. }
  531. }
  532. /**
  533. * 申请提现接口
  534. * @param [type] $account_identity 用户id
  535. * @param [type] $money 金额
  536. * @param [type] $bank_no 银行卡号
  537. * @param [type] $pwd 支付密码
  538. * @return [type] [description]
  539. */
  540. public function apply_money($account_identity, $money, $bank_no, $pwd) {
  541. //验证交易密码
  542. /*if (!$this->verifyPayPwd($account_identity, $pwd)) {
  543. return -2020;
  544. }*/
  545. //获取用户信息
  546. $account = $this->getAccount($account_identity);
  547. //获取用户银行卡信息
  548. $bank_info = $this->getBankInfo($account_identity, $bank_no);
  549. //生成订单id
  550. $order_id = OrderID();
  551. //插入提现申请记录
  552. $data = array(
  553. 'info_identity' => UUID(),
  554. 'order_id' => $order_id,
  555. 'account_identity' => $account_identity,
  556. 'account_name' => $account['account_name'],
  557. 'money' => $money,
  558. 'apply_time' => date('Y-m-d H:i:s', time()),
  559. 'bank_no' => $bank_no,
  560. 'bank_address' => $bank_info['bank_address'],
  561. 'bank_user' => $bank_info['account_name'],
  562. 'status' => 1,
  563. );
  564. $res = lm($this->money_take, 'Commons')->insert($data);
  565. if ($res) {
  566. return $this->insertMoney($account_identity, $money, $order_id, 5);
  567. } else {
  568. return -2113;
  569. }
  570. }
  571. /**
  572. * 通过审核
  573. * @param [type] $identity 信息id
  574. * @return [type] [description]
  575. */
  576. public function pass_take($identity) {
  577. # code...
  578. }
  579. /**
  580. * 完成提现
  581. * @param [type] $identity 信息id
  582. * @return [type] [description]
  583. */
  584. public function give_take($identity) {
  585. }
  586. /**
  587. * 购买
  588. * @param [type] $account_identity 用户id
  589. * @param [type] $money 金额
  590. * @param [type] $order_id 订单号
  591. * @param [type] $type 购买类型,1,投注 2,追号
  592. * @return [type] [description]
  593. */
  594. public function buy_money($account_identity, $money, $order_id, $type) {
  595. return $this->insertMoney($account_identity, $money, $order_id, $type);
  596. }
  597. /**
  598. * 充值记录
  599. * @param [type] $account_identity 用户id
  600. * @param [type] $money 金额
  601. * @param [type] $type 充值方式
  602. * @return [type] [description]
  603. */
  604. public function recharge_money($account_identity, $money, $type) {
  605. $type = 6;
  606. //获取用户信息
  607. $account = $this->getAccount($account_identity);
  608. //生成订单id
  609. $order_id = OrderID();
  610. //充值记录
  611. $data = array(
  612. 'info_identity' => UUID(),
  613. 'order_id' => $order_id,
  614. 'begin_time' => date('Y-m-d H:i:s', time()),
  615. 'money' => $money,
  616. 'account_name' => $account['account_name'],
  617. 'account_identity' => $account_identity,
  618. 'status' => 1,
  619. 'recharge_type' => $type,
  620. );
  621. $res = lm($this->money_recharge, 'Commons')->insert($data);
  622. if ($res) {
  623. return $this->insertMoney($account_identity, $money, $order_id, 6);
  624. } else {
  625. return -2113;
  626. }
  627. }
  628. /**
  629. * 反水记录增加
  630. * @param string $account_identity 用户id
  631. * @param [type] $money 金额
  632. * @param string $game_name 游戏名
  633. * @param string $buy_id 购买记录id
  634. * @param [type] $ratio 反水比例
  635. * @return [type] [description]
  636. */
  637. public function back_money($account_identity, $money, $game_name, $buy_id, $ratio) {
  638. //获取用户信息
  639. $account = $this->getAccount($account_identity);
  640. //获取游戏信息
  641. $game = new \Biz\Game\GameQuery;
  642. $game_info = $game->getGameInfo($game_name);
  643. //生成订单id
  644. $order_id = OrderID();
  645. //插入反水信息
  646. $data = array(
  647. 'info_identity' => UUID(),
  648. 'order_id' => $order_id,
  649. 'account_name' => $account['account_name'],
  650. 'account_identity' => $account_identity,
  651. 'game_name' => $game_info['name'],
  652. 'game_id' => $game_info['identity'],
  653. 'buy_identity' => $buy_id,
  654. 'money' => $money,
  655. 'ratio' => $ratio,
  656. 'money_time' => date('Y-m-d H:i:s', time()),
  657. );
  658. $res = lm($this->money_back, 'Commons')->insert($data);
  659. if ($res) {
  660. return $this->insertMoney($account_identity, $money, $order_id, 7);
  661. } else {
  662. return -2113;
  663. }
  664. }
  665. /**
  666. * 回水操作
  667. * @param string $account_identity 用户id
  668. * @param string $money 金额
  669. * @param string $ratio 回水比例
  670. * @param string $total_money 亏损总金额
  671. * @return [type] [description]
  672. */
  673. public function return_money($account_identity, $money, $ratio, $total_money) {
  674. //获取用户信息
  675. $account = $this->getAccount($account_identity);
  676. //生成订单id
  677. $order_id = OrderID();
  678. //加入回水记录
  679. $data = array(
  680. 'info_identity' => UUID(),
  681. 'order_id' => $order_id,
  682. 'account_name' => $account['account_name'],
  683. 'account_identity' => $account_identity,
  684. 'money' => $money,
  685. 'ratio' => $ratio,
  686. 'total_money' => $total_money,
  687. 'money_time' => date('Y-m-d H:i:s'),
  688. );
  689. $res = lm($this->money_return, 'Commons')->insert($data);
  690. if ($res) {
  691. return $this->insertMoney($account_identity, $money, $order_id, 8);
  692. } else {
  693. return -2113;
  694. }
  695. }
  696. /**
  697. * 管理员扣款
  698. * @param [type] $account_identity 用户id
  699. * @param [type] $money 金额
  700. * @return [type] [description]
  701. */
  702. public function cut_money($account_identity, $money) {
  703. //生成订单id
  704. $order_id = OrderID();
  705. return $this->insertMoney($account_identity, $money, $order_id, 9);
  706. }
  707. /**
  708. * 资金记录修改
  709. * @param string $account_identity 用户id
  710. * @param string $money 金额
  711. * @param 订单号 $order_id 订单号
  712. * @param int $type 交易类型
  713. * @return [type] [description]
  714. */
  715. public function insertMoney($account_identity, $money, $order_id, $type) {
  716. //获取用户信息
  717. $account = $this->getAccount($account_identity);
  718. //获取money_type
  719. $m_type = $this->getMtype($type);
  720. //总资金记录表
  721. if ($m_type == 1) {
  722. $nowMoney = $account['available_cash'] + $money;
  723. $nowCash = $account['cash'] + $money;
  724. } else {
  725. $nowMoney = $account['available_cash'] - $money;
  726. $nowCash = $account['cash'] - $money;
  727. }
  728. //获取描述信息
  729. $trade_desc = $this->getDesc($account['account_name'], $money, $order_id, $type);
  730. //获取状态
  731. //$status = $this->getStatus($type);
  732. $data2 = array(
  733. 'info_identity' => UUID(),
  734. 'trade_id' => $order_id,
  735. 'account_name' => $account['account_name'],
  736. 'account_identity' => $account_identity,
  737. 'money' => $money,
  738. 'money_time' => date('Y-m-d H:i:s', time()),
  739. 'money_type' => $m_type,
  740. 'money_cash' => $nowMoney,
  741. //'status' => $status,
  742. 'trade_type' => $type,
  743. 'trade_desc' => $trade_desc,
  744. );
  745. $res2 = lm($this->money_details, 'Commons')->insert($data2);
  746. if ($res2) {
  747. //更新用户余额
  748. $update = array(
  749. 'available_cash' => $nowMoney,
  750. 'cash' => $nowCash,
  751. );
  752. $res3 = lm($this->account_detailed, 'Commons')->where('account_identity', $account_identity)->update($update);
  753. if ($res3) {
  754. return 1;
  755. } else {
  756. return -2113;
  757. }
  758. } else {
  759. return -2113;
  760. }
  761. }
  762. /**
  763. * 获取描述信息
  764. * @param string $account_name 用户名
  765. * @param string $money 金额
  766. * @param string $order_id 订单号
  767. * @param int $type 操作类型
  768. * @return [type] [description]
  769. */
  770. public function getDesc($account_name, $money, $order_id, $type) {
  771. switch ($type) {
  772. case 1:
  773. return $account_name . '投注' . $money . '元。' . '订单号' . $order_id;
  774. break;
  775. case 2:
  776. return $account_name . '追号' . $money . '元。' . '订单号' . $order_id;
  777. break;
  778. case 3:
  779. return $account_name . '撤单' . '订单号' . $order_id;
  780. break;
  781. case 4:
  782. return $account_name . '中奖' . $money . '元。' . '订单号' . $order_id;
  783. break;
  784. case 5:
  785. return $account_name . '申请提现' . $money . '元。' . '订单号' . $order_id;
  786. break;
  787. case 6:
  788. return $account_name . '充值' . $money . '元。' . '订单号' . $order_id;
  789. break;
  790. case 7:
  791. return $account_name . '反水' . $money . '元。' . '订单号' . $order_id;
  792. break;
  793. case 8:
  794. return $account_name . '回水' . $money . '元。' . '订单号' . $order_id;
  795. break;
  796. case 9:
  797. return $account_name . '管理员扣款' . $money . '元。' . '订单号' . $order_id;
  798. break;
  799. case 10:
  800. return $account_name . '佣金提成' . $money . '元。' . '订单号' . $order_id;
  801. break;
  802. default:
  803. return '';
  804. break;
  805. }
  806. }
  807. /**
  808. * 获取状态
  809. * @param [type] $type 操作类型
  810. * @return [type] [description]
  811. */
  812. public function getStatus($type) {
  813. $arr = array(
  814. '1' => '投注',
  815. '2' => '追号',
  816. '3' => '撤单',
  817. '4' => '派奖',
  818. '5' => '审核中',
  819. '6' => '待支付',
  820. '7' => '成功',
  821. '8' => '成功',
  822. '9' => '扣款',
  823. '10' => '佣金提成',
  824. );
  825. return $arr[$type];
  826. }
  827. /**
  828. * 返回money_type
  829. * @param [type] $type 类型
  830. * @return [type] [description]
  831. */
  832. public function getMtype($type) {
  833. $arr = array(
  834. '1' => 2,
  835. '2' => 2,
  836. '3' => 1,
  837. '4' => 1,
  838. '5' => 2,
  839. '6' => 1,
  840. '7' => 1,
  841. '8' => 1,
  842. '9' => 2,
  843. '10' => 1,
  844. );
  845. return $arr[$type];
  846. }
  847. /**
  848. * 获取用户绑定银行卡信息
  849. * @param [type] $account_identity 用户唯一id
  850. * @param [type] $bank_no 银行卡号
  851. * @return [type] [description]
  852. */
  853. public function getBankInfo($account_identity, $bank_no) {
  854. $res = lm($this->bank_table, 'Commons')
  855. ->select('bank_number', 'account_name', 'bank_address')
  856. ->where(['account_identity' => $account_identity, 'bank_number' => $bank_no])
  857. ->first();
  858. if ($res) {
  859. $data = $res->toArray();
  860. } else {
  861. return -2114;
  862. }
  863. return $data;
  864. }
  865. }
  866. ?>