MoveDataController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ikeke
  5. * Date: 2018/12/4
  6. * Time: 15:08
  7. */
  8. namespace App\Http\Controllers\Admin;
  9. use App\Http\Controllers\Controller;
  10. use Illuminate\Http\Request as Req;
  11. use Request;
  12. use DB;
  13. class MoveDataController extends Controller
  14. {
  15. public function __construct()
  16. {
  17. }
  18. /*//连接数据库
  19. public function connecDb($host,$port,$dbname,$user,$password){
  20. $host = "host={$host}";
  21. $port = "port={$port}";
  22. $dbname = "dbname={$dbname}";
  23. $credentials = "user={$user} password={$password}";
  24. $db = pg_connect("$host $port $dbname $credentials");
  25. if(!$db)return -4020000202;
  26. return $db;
  27. }
  28. //查询
  29. public function select($db,$sql,$type=1){
  30. $data = @pg_query($db,$sql);
  31. print_r($data);
  32. if($type!=1){
  33. $res = pg_num_rows($data);
  34. return $res;
  35. }
  36. $resdata = array();
  37. $i=0;
  38. while ($row = pg_fetch_array($data,null,PGSQL_ASSOC)){
  39. $resdata[$i] = $row;
  40. $i++;
  41. }
  42. if($resdata)return $resdata;
  43. return array();
  44. }*/
  45. //迁移数据
  46. /*public function MovedataView(Req $req){
  47. $limit = Request::has ('limit') ? Request::get ('limit') : 10;
  48. $page = Request::has ('page') ? Request::get ('page') : 1;
  49. $ids=isset($req->id)?trim($req->id):'all';
  50. $db = $this->connecDb('192.168.2.200','5432','kaiyou2','postgres','qq123456');
  51. $sql = 'select * from account';
  52. $data = $this->select($db,$sql);
  53. $clslog = '\App\Models\Account_list';
  54. $cls = '\App\Models\Account';
  55. $bank = '\App\Models\Account_bank';
  56. $group = '\App\Models\Account_group';
  57. $userpwd = '\App\Models\Account_password';
  58. $usertoken = '\App\Models\Account_Token';
  59. $uservip = '\App\Models\Uservip';
  60. if (!$req->isMethod('post')) {
  61. if($ids=='all'){
  62. $unum = $this->select($db,$sql,2);
  63. $data['unum'] = empty($unum)?0:$unum;
  64. }else{
  65. $data['unum'] = 1;
  66. }
  67. return view('admin.MoveData/index', array('data' => $data));
  68. } else {
  69. echo '<pre>';
  70. $password = Request::has('rpassword') ? Request::get('rpassword') : '';
  71. $allnum = Request::has('allnum') ? Request::get('allnum') : '0';
  72. if (empty($password)) {
  73. return responseToJson(-7010123622); //密码不能为空
  74. }
  75. //验证二级密码
  76. //验证密码
  77. $checkpwdsql = 'select * from system_user where id='.session('adminInfo.admin_id');
  78. $admin_info = $this->select($db,$checkpwdsql);
  79. $admin_info = current($admin_info);
  80. if (!$admin_info) {
  81. return responseToJson(-7010100202);
  82. }
  83. if (!VerPassword($password, $admin_info['encryption_2'], $admin_info['password_2'])) {
  84. return responseToJson(-7010001622);
  85. }
  86. $log = array(
  87. session('adminInfo.admin_name'),
  88. );
  89. //$res = OperationLog(session('adminInfo.admin_id'), 'GameKjcodes', $log);
  90. $identitys = array();
  91. $accounts = array();
  92. if($ids=='all'){
  93. $offset = ($page-1) * $limit;
  94. $uinfosql = 'select * from account_list orderBy id asc limit ' . $limit . ' offset ' . $offset;
  95. }else{
  96. $uinfosql = 'select * from account_list where id=' . $ids;
  97. $allnum = 1;
  98. }
  99. $uinfo = $this->select($db,$uinfosql);
  100. print_r($uinfo);exit;
  101. $curnum = count($uinfo);
  102. if(empty($uinfo) || $curnum<1)return responseToJson(-4020000102);
  103. foreach ($uinfo as $k => $v) {
  104. $identitys[] = $v['account_identity'];
  105. $accounts[] = $v['account'];
  106. $accounts[] = 'vip' . $v['account'];
  107. }
  108. $bankinfo = $bank::whereIn('account_identity',$identitys)->get();
  109. $pwdinfo = $userpwd::whereIn('account_identity',$identitys)->get();
  110. $tokeninfo = $usertoken::whereIn('account_identity',$identitys)->get();
  111. $vipinfo = $uservip::whereIn('account_identity',$identitys)->get();
  112. $data = array(
  113. 'identitys' => $identitys,
  114. 'accounts' => $accounts,
  115. 'uinfo' => $uinfo,
  116. 'bankinfo' => $bankinfo?$bankinfo->toArray() : array(),
  117. 'pwdinfo' => $pwdinfo?$pwdinfo->toArray() : array(),
  118. 'tokeninfo' => $tokeninfo?$tokeninfo->toArray() : array(),
  119. 'vipinfo' => $vipinfo?$vipinfo->toArray() : array(),
  120. );
  121. echo "<pre>";
  122. print_r($data);exit;
  123. return responseToJson(1,'',array('allnum'=>$allnum,'curnum'=>$curnum,'data'=>$data));
  124. }
  125. }*/
  126. //迁移数据
  127. public function MovedataView(Req $req){
  128. $limit = Request::has ('limit') ? Request::get ('limit') : 10;
  129. $page = Request::has ('page') ? Request::get ('page') : 1;
  130. $ids=isset($req->id)?trim($req->id):'all';
  131. $oldDB = DB::connection('pgsql');
  132. $oldcls = $oldDB->table('account');
  133. if (!$req->isMethod('post')) {
  134. if($ids=='all'){
  135. $unum = $oldcls->count('id');
  136. $data['unum'] = empty($unum)?0:$unum;
  137. }else{
  138. $data['unum'] = 1;
  139. }
  140. return view('admin.MoveData/index', array('data' => $data));
  141. } else {
  142. $oldclslog = $oldDB->table('account_list');
  143. $oldbank = $oldDB->table('account_bank');
  144. $oldgroup = $oldDB->table('account_group');
  145. $olduserpwd = $oldDB->table('account_password');
  146. $oldusertoken = $oldDB->table('account_token');
  147. $olduservip = $oldDB->table('user_vip');
  148. $oldadmin = $oldDB->table('system_user');
  149. $oldpay = $oldDB->table('pay_password');
  150. $password = Request::has('rpassword') ? Request::get('rpassword') : '';
  151. $allnum = Request::has('allnum') ? Request::get('allnum') : '0';
  152. if (empty($password)) {
  153. return responseToJson(-7010123622); //密码不能为空
  154. }
  155. //验证二级密码
  156. //验证密码
  157. $admin_info = $oldadmin->where('id', session('adminInfo.admin_id'))->first();
  158. if (!$admin_info) {
  159. return responseToJson(-7010100202);
  160. }
  161. $admin_info = $this->toArray($admin_info);
  162. if (!VerPassword($password, $admin_info['encryption_2'], $admin_info['password_2'])) {
  163. return responseToJson(-7010001622);
  164. }
  165. $log = array(
  166. session('adminInfo.admin_name'),
  167. );
  168. //$res = OperationLog(session('adminInfo.admin_id'), 'GameKjcodes', $log);
  169. $identitys = array();
  170. $accounts = array();
  171. if($ids=='all'){
  172. $offset = ($page-1) * $limit;
  173. $uinfo = $oldclslog->limit($limit)->offset($offset)->orderBy('identity','asc')->get();
  174. }else{
  175. $uinfo = $oldclslog->where('id',$ids)->get();
  176. $allnum = 1;
  177. }
  178. $uinfo = $this->toArray($uinfo);
  179. $curnum = count($uinfo);
  180. if(!$uinfo || $curnum<1)return responseToJson(-4020000102);
  181. foreach ($uinfo as $k => $v) {
  182. $identitys[] = $v['account_identity'];
  183. $accounts[] = $v['account'];
  184. $accounts[] = 'vip' . $v['account'];
  185. }
  186. $bankinfo = $oldbank->whereIn('account_identity',$identitys)->get();
  187. $pwdinfo = $olduserpwd->whereIn('account_identity',$identitys)->get();
  188. $tokeninfo = $oldusertoken->whereIn('account_identity',$identitys)->get();
  189. $vipinfo = $olduservip->whereIn('account_identity',$identitys)->get();
  190. $payinfo = $oldpay->whereIn('account_identity',$identitys)->get();
  191. $data = array(
  192. 'identitys' => $identitys,
  193. 'accounts' => $accounts,
  194. 'uinfo' => $uinfo,
  195. 'bankinfo' => $this->toArray($bankinfo),
  196. 'pwdinfo' => $this->toArray($pwdinfo),
  197. 'tokeninfo' => $this->toArray($tokeninfo),
  198. 'vipinfo' => $this->toArray($vipinfo),
  199. 'payinfo' => $this->toArray($payinfo),
  200. );
  201. $this->AddData($data);
  202. return responseToJson(1,'',array('allnum'=>$allnum,'curnum'=>$curnum,'data'=>$data));
  203. }
  204. }
  205. //迁移数据到新数据库
  206. function AddData($data){
  207. $newDB = DB::connection('pgsql1');
  208. $newcls = $newDB->table('account');
  209. $newclslog = $newDB->table('change_record');
  210. $newdetail = $newDB->table('account_detailed');
  211. $newbank = $newDB->table('account_bank');
  212. $newgroup = $newDB->table('account_group');
  213. $newuserpwd = $newDB->table('account_password');
  214. $newusertoken = $newDB->table('account_token');
  215. $newuservip = $newDB->table('user_vip');
  216. $newpay = $newDB->table('pay_password');
  217. //获取已迁移数据信息,用于避免重复迁移
  218. $hsinfo = $newclslog->select('old_identity')->whereIn('old_identity',$data['identitys'])->get();
  219. $hsids = array();
  220. $hsinfo = $this->toArray($hsinfo);
  221. if($hsinfo && count($hsinfo)>0){
  222. foreach ($hsinfo as $k => $v) {
  223. $hsids[] = $v['old_identity'];
  224. }
  225. }
  226. //获取分组信息
  227. $groupinfo = $this->getGroupinfo($newgroup);
  228. //查询重复用户名
  229. $reaccount = $newcls->select('account')->whereIn('account',$data['accounts'])->get();
  230. $unames = array();
  231. $reaccount = $this->toArray($reaccount);
  232. if($reaccount && count($reaccount)>0){
  233. foreach ($reaccount as $k => $v) {
  234. $unames[] = $v['account'];
  235. }
  236. }
  237. //不迁移数据
  238. $nouser = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/nouser.txt');
  239. $nouser = explode(PHP_EOL, $nouser);
  240. //组装数据
  241. $cashinfo = array();
  242. $account_data = array(); //会员信息
  243. $accountdetail_data = array(); //会员详情数据
  244. $record_data = array(); //迁移记录信息
  245. foreach ($data['uinfo'] as $k => $v) {
  246. if(in_array($v['account_identity'], $hsids))continue;
  247. if(in_array($v['account'], $nouser)){
  248. $hsids[] = $v['account_identity'];
  249. continue;
  250. }
  251. $tuname = !in_array($v['account'], $unames)?$v['account'] : (!in_array('vip'.$v['account'], $unames)?'vip'.$v['account'] : $v['account'].'vip');
  252. $account_data[] = array(
  253. 'identity' => $v['identity'],
  254. 'account' => $tuname,
  255. 'status' => $v['account_status'],
  256. 'fanshui' => $v['fanshui'],
  257. 'remark' => $v['remark'],
  258. );
  259. $record_data[] = array(
  260. 'old_user' => $v['account'],
  261. 'old_identity' => $v['account_identity'],
  262. 'new_user' => $tuname,
  263. 'new_identity' => $v['account_identity'],
  264. 'update_time' => date('Y-m-d H:i:s'),
  265. 'old_id' => $v['id'],
  266. );
  267. $accountdetail_data[] = array(
  268. 'identity' => $v['detail_identity'],
  269. 'account_identity' => $v['account_identity'],
  270. 'register_time' => $v['register_time'],
  271. 'register_ip' => $v['register_ip'],
  272. 'last_time' => $v['last_time'],
  273. 'last_ip' => $v['last_ip'],
  274. 'grade' => $v['grade'],
  275. 'email' => $v['email'],
  276. 'phone' => $v['phone'],
  277. 'invitation' => $v['invitation'],
  278. 'available_cash' => 0,
  279. 'cash' => 0,
  280. 'frozen_cash' => $v['frozen_cash'],
  281. 'open_invitation' => $v['open_invitation'],
  282. 'spread' => $v['spread'],
  283. 'placing' => $v['placing'],
  284. 'token' => $v['token'],
  285. 'statuss' => $v['statuss'],
  286. 'ranking' => $v['ranking'],
  287. 'card' => $v['card'],
  288. 'name' => $v['name'],
  289. 'show' => $v['show'],
  290. 'img_url' => $v['img_url'],
  291. 'qq' => $v['qq'],
  292. 'register_url' => $v['register_url'],
  293. 'last_url' => $v['last_url'],
  294. 'group_code' => $this->getGroupcode($groupinfo,$v['group_code'],$v['group_name']),
  295. 'group_name' => $v['group_name'],
  296. 'parent_id' => $v['parent_id'],
  297. 'parent_path' => $v['parent_path'],
  298. 'level' => $v['level'],
  299. //'finance_cash' => $v['finance_cash'],
  300. );
  301. if($v['cash']<=0)continue;
  302. $cashinfo[$v['account_identity']] = array(
  303. 'identity' => $v['account_identity'],
  304. 'account' => $v['account'],
  305. 'money' => $v['cash'],
  306. 'remark' => '用户活动,账号资金迁移',
  307. );
  308. }
  309. //会员相关数据组装
  310. $bank_data = array(); //会员银行卡信息
  311. $pwd_data = array(); //会员密码数据
  312. $token_data = array(); //会员token信息
  313. $uservip_data = array(); //会员vip信息
  314. $pay_data = array(); //支付密码信息
  315. if(!empty($data['bankinfo']) && count($data['bankinfo'])>0){
  316. foreach ($data['bankinfo'] as $k => $v) {
  317. if(in_array($v['account_identity'], $hsids))continue;
  318. $v['account_name'] = !in_array($v['account_name'], $unames)?$v['account_name'] : (!in_array('vip'.$v['account_name'], $unames)?'vip'.$v['account_name'] : $v['account_name'].'vip');
  319. unset($v['id']);
  320. unset($v['bank_code']);
  321. $bank_data[] = $v;
  322. }
  323. }
  324. if(!empty($data['pwdinfo']) && count($data['pwdinfo'])>0){
  325. foreach ($data['pwdinfo'] as $k => $v) {
  326. if(in_array($v['account_identity'], $hsids))continue;
  327. unset($v['id']);
  328. $pwd_data[] = $v;
  329. }
  330. }
  331. if(!empty($data['tokeninfo']) && count($data['tokeninfo'])>0){
  332. foreach ($data['tokeninfo'] as $k => $v) {
  333. if(in_array($v['account_identity'], $hsids))continue;
  334. unset($v['id']);
  335. $token_data[] = $v;
  336. }
  337. }
  338. if(!empty($data['vipinfo']) && count($data['vipinfo'])>0){
  339. foreach ($data['vipinfo'] as $k => $v) {
  340. if(in_array($v['account_identity'], $hsids))continue;
  341. $v['account_name'] = !in_array($v['account_name'], $unames)?$v['account_name'] : (!in_array('vip'.$v['account_name'], $unames)?'vip'.$v['account_name'] : $v['account_name'].'vip');
  342. unset($v['id']);
  343. $uservip_data[] = $v;
  344. }
  345. }
  346. if(!empty($data['payinfo']) && count($data['payinfo'])>0){
  347. foreach ($data['payinfo'] as $k => $v) {
  348. if(in_array($v['account_identity'], $hsids))continue;
  349. unset($v['id']);
  350. $pay_data[] = $v;
  351. }
  352. }
  353. DB::beginTransaction ();
  354. //添加数据到对应表中
  355. $res = $this->addDataIntable($newcls,$account_data);
  356. if($res<0){
  357. DB::rollback ();
  358. return $res;
  359. }
  360. $res = $this->addDataIntable($newdetail,$accountdetail_data);
  361. if($res<0){
  362. DB::rollback ();
  363. return $res;
  364. }
  365. $res = $this->addDataIntable($newclslog,$record_data);
  366. if($res<0){
  367. DB::rollback ();
  368. return $res;
  369. }
  370. $res = $this->addDataIntable($newbank,$bank_data);
  371. if($res<0){
  372. DB::rollback ();
  373. return $res;
  374. }
  375. $res = $this->addDataIntable($newuserpwd,$pwd_data);
  376. if($res<0){
  377. DB::rollback ();
  378. return $res;
  379. }
  380. $res = $this->addDataIntable($newusertoken,$token_data);
  381. if($res<0){
  382. DB::rollback ();
  383. return $res;
  384. }
  385. $res = $this->addDataIntable($newuservip,$uservip_data);
  386. if($res<0){
  387. DB::rollback ();
  388. return $res;
  389. }
  390. $res = $this->addDataIntable($newpay,$pay_data);
  391. if($res<0){
  392. DB::rollback ();
  393. return $res;
  394. }
  395. //print_r($cashinfo);
  396. //会员加款
  397. //$url = $_SERVER['HTTP_ORIGIN'] . '/admin/Regulation/Edit';
  398. if(count($cashinfo)>0){
  399. foreach ($cashinfo as $k => $v) {
  400. //$res = $this->addMoney($url,$v);
  401. $res = $this->addMoneys($v,$newDB);
  402. if($res<0){
  403. DB::rollback ();
  404. return $res;
  405. }
  406. }
  407. }
  408. DB::commit ();
  409. return 1;
  410. }
  411. //通过用户分组名获取用户分组代码
  412. function getGroupcode($groupinfo,$group_code,$group_name){
  413. if(empty($groupinfo))return $group_code;
  414. $group_name = explode('|', $group_name);
  415. if(count($group_name)<1)return $group_code;
  416. $group_code = '0,';
  417. foreach ($group_name as $k => $v) {
  418. $v = trim($v);
  419. if(isset($groupinfo[$v])){
  420. $group_code .= $groupinfo[$v] . ',';
  421. }
  422. }
  423. return $group_code;
  424. }
  425. //获取本站用户组信息
  426. function getGroupinfo($newgroup){
  427. $data = $newgroup->select('group_name','group_code')->get();
  428. $data = $this->toArray($data);
  429. $resdata = array();
  430. if(count($data)>0){
  431. foreach ($data as $k => $v) {
  432. $resdata[$v['group_name']] = $v['group_code'];
  433. }
  434. }
  435. return $resdata;
  436. }
  437. //加款
  438. function addMoneys($getdata,$newDB)
  439. {
  440. $id = $getdata['identity'];
  441. $money = $getdata['money'];
  442. $remark = $getdata['remark'];
  443. $newcls = $newDB->table('account');
  444. $newrecharge = $newDB->table('money_recharge');
  445. $newwith = $newDB->table('withdraw_rule');
  446. $newmc = $newDB->table('money_count');
  447. $newman = $newDB->table('message');
  448. $newdetail = $newDB->table('account_detailed');
  449. $newmdetail = $newDB->table('money_details');
  450. $newlog = $newDB->table('system_log');
  451. $admin_name = session ('adminInfo.admin_name') ? session ('adminInfo.admin_name') : '来自接口';
  452. //检测提交数据
  453. $res_data = $this->CheckaddMoney ($id, $money,$newrecharge);
  454. if ($res_data < 0)return $res_data;
  455. $data = array(
  456. 'account_name' => $getdata['account'],
  457. 'account_identity' => $id,
  458. 'money' => $money,
  459. 'reason' => $remark,
  460. 'sysetem_user' => $admin_name,
  461. );
  462. //充值处理
  463. //资金统计记录
  464. $cdata = $data;
  465. $cdata['pass_time'] = date ('Y-m-d', time ());
  466. $res = $this->AddCountinfo ($cdata, $newmc);
  467. if ($res < 0)return $res;
  468. //加钱
  469. $data['money_cash'] = $money;
  470. $data['rate'] = 1;
  471. $trade_type = 12;
  472. /***********活动加款**************/
  473. $reason = str_replace ('用于活动', '!@#$', $data['reason']);
  474. $order_id = $this->addMoney ($data, 1, $trade_type,$newdetail,$newman,$newrecharge,$newmdetail);//加钱
  475. if ($order_id < 0)return $order_id;
  476. $prize_money = 0;
  477. $log = array(
  478. session ('adminInfo.admin_name'),
  479. $data['account_name'],
  480. $money,
  481. $prize_money,
  482. $data['reason'],
  483. $order_id,
  484. 1,
  485. );
  486. $this->OperationLog (session ('adminInfo.admin_id'), 'add_money', $log,$newlog);
  487. return 1;
  488. }
  489. function OperationLog($id, $opt, $_data,$newlog)
  490. {
  491. $data = array(
  492. 'identity' => UUID(),
  493. 'status' => 1,
  494. 'ip' => GETIP(),
  495. 'operation_time' => date('Y-m-d H:i:s', time()),
  496. 'system_identity' => $id,
  497. 'operation' => vsprintf(trans('operation.' . $opt), $_data),
  498. );
  499. return $newlog->insert($data);
  500. }
  501. //添加最新金额到统计表
  502. private function AddCountinfo($data,$newmc){
  503. $mtype = 'save';
  504. $ts = GetpartTime($data['pass_time']); //获取统计周期信息
  505. $type = $this->GetcountType(); //获取周期类型
  506. $indata = array(
  507. 'account' => $data['account_name'],
  508. 'account_identity' => $data['account_identity'],
  509. 'ut_time' => $data['pass_time'],
  510. $mtype => $data['money'],
  511. );
  512. for($i=1;$i<6;$i++){
  513. $indata['count_time'] = $ts[$type[$i]];
  514. switch ($i) {
  515. case '1':
  516. $indata['count_alltime'] = $indata['count_time'];
  517. break;
  518. case '3':
  519. $indata['count_alltime'] = $ts['year'] . '-' . $ts['month'] . '-' . $indata['count_time'];
  520. break;
  521. case '4':
  522. $indata['count_alltime'] = $ts['wyear'] . '-' . $indata['count_time'];
  523. break;
  524. default:
  525. $indata['count_alltime'] = $ts['year'] . '-' . $indata['count_time'];
  526. break;
  527. }
  528. $indata['type'] = $i;
  529. $indata['identity'] =$data['account_identity'] . '_' . $i . '_' . $indata['count_alltime'];
  530. $res=$newmc->where('identity',$indata['identity'])->first();
  531. if(!$res){
  532. $res = $newmc->insert($indata);
  533. }else{
  534. $res = $newmc->where('identity',$indata['identity'])->increment($mtype,$data['money']);
  535. }
  536. if($res<1)return -300326;
  537. }
  538. return 1;
  539. }
  540. //周期类型
  541. private function GetcountType(){
  542. return $type = array(
  543. '1' => 'year',
  544. '2' => 'month',
  545. '3' => 'day',
  546. '4' => 'week',
  547. '5' => 'season',
  548. );
  549. }
  550. /**
  551. * 加钱函数
  552. * @param array $data
  553. * @param int $type
  554. * @param int $trade_type
  555. * @param obj $newudetail
  556. * @param obj $newman
  557. * @param obj $newrecharge
  558. * @param obj $newmdetail
  559. * @return int|string
  560. */
  561. private function addMoney(array $data, $type, $trade_type,$newudetail,$newman,$newrecharge,$newmdetail)
  562. {
  563. $order_id = $this->rechargeLog ($data,$newrecharge);//充值记录
  564. if ($order_id < 0)return $order_id;
  565. $detail=$data;
  566. $detail['rate']=1;
  567. $res = $this->dataLog ($detail, $order_id, $type, $trade_type,$newmdetail);
  568. if ($res < 0)return $res;
  569. //添加用户余额
  570. $res1=$newudetail->where('account_identity',$data['account_identity'])->increment('available_cash',$data['money']);
  571. if(!$res1)return -5040022022;//增加约失败
  572. $res2=$newudetail->where('account_identity',$data['account_identity'])->increment('cash',$data['money']);
  573. if(!$res2)return -5040022022;//增加约失败
  574. $this->updateMessage ('admin', $data['account_name'], '加款提示', '加款成功,加款金额:' . $data['money'], $newman);
  575. return $order_id;
  576. }
  577. //添加公告数据
  578. function updateMessage($sender, $reciver, $title, $content, $newman)
  579. {
  580. $data['add_time']=date('Y-m-d H:i:s');
  581. $data['formname']=$sender;
  582. $data['toname']=$reciver;
  583. $data['title'] = $title;
  584. $data['type'] =2;
  585. $data['content'] = $content;
  586. //普通消息
  587. $res = $newman->insertGetId ($data);
  588. if(!$res)return -6030001222;
  589. return 1;
  590. }
  591. /**
  592. * 添加充值/扣款详情记录函数
  593. * @param array $data 详情数据数组
  594. * @param mixed $order_id 充值/扣款订单号
  595. * @param int $type 订单类别[1=>'充值',2=>'扣款'];
  596. * @param int $trade_type 交易类型
  597. * @return int|string 成功返回当前详单号,失败返回错误号
  598. */
  599. private function dataLog(array $data, $order_id, $type, $trade_type,$money_db)
  600. {
  601. $rate = 1;
  602. unset($data['rate']);
  603. $deal_data = $data;
  604. $deal_data['money_type'] = $type;
  605. $deal_data['money_time'] = date ('Y-m-d H:i:s', time ());
  606. $deal_data['trade_id'] = $order_id;
  607. $deal_data['trade_type'] = $trade_type;
  608. $admin_name = session ('adminInfo.admin_name');
  609. $admin_name = isset($admin_name) ? $admin_name : '来自接口' . GETIP ();
  610. $deal_data['sysetem_user'] = $admin_name;
  611. $deal_data['trade_desc'] = sprintf (trans ('trade.admin_active_money'), $admin_name, $data['account_name'], $data['money'], $order_id, $rate);
  612. $deal_data['status'] = 1;
  613. $deal_data['info_identity'] = UUID();
  614. $res = $money_db->insert($deal_data);
  615. if (!$res) {
  616. return -2020072022; //插入资金详情失败
  617. }
  618. return $order_id;
  619. }
  620. /**
  621. * 充值记录
  622. * @param array $data 充值记录数据
  623. * @return int|string 充值成功返回充值订单号
  624. */
  625. private function rechargeLog(array $data,$recharge)
  626. {
  627. $data['recharge_type'] = '活动充值';
  628. $data['status'] = 1;
  629. $data['apply_time'] = date ('Y-m-d H:i:s', time ());
  630. $data['complete_time'] = date ('Y-m-d H:i:s', time ());
  631. $data['rate'] = 1;
  632. $data['order_id'] = OrderID ();
  633. $data['info_identity'] = UUID ();
  634. $data['remark'] = '后台充值';
  635. $res = $recharge->insert($data);
  636. if (!$res)return -3020011322; //加款失败
  637. return $data['order_id'];exit;
  638. }
  639. //调用加款接口
  640. /*function addMoney($url,$data){
  641. $data = json_encode($data);
  642. $ch = curl_init();
  643. //设置选项,包括URL
  644. curl_setopt($ch, CURLOPT_URL,$url);//抓取指定网页
  645. curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); //设置http验证方法
  646. curl_setopt($ch, CURLOPT_TIMEOUT,30);
  647. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  648. curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
  649. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  650. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  651. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  652. 'X-USER-TOKEN: {{ csrf_token() }}'
  653. ));
  654. //执行并获取HTML文档内容
  655. $output = curl_exec($ch);
  656. $cinfo = curl_getinfo($ch);
  657. //释放curl句柄
  658. curl_close($ch);
  659. //返回数据
  660. print_r($cinfo);
  661. print_r($output);
  662. return $output;
  663. }*/
  664. //添加数据到对应表中
  665. function addDataIntable($obj,$data){
  666. if(!empty($data) && count($data)>0){
  667. $res = $obj->insert($data);
  668. if($res>0)return 1;
  669. return -1;
  670. }
  671. return 1;
  672. }
  673. //验证金额
  674. function CheckaddMoney($account_id, $money,$newrecharge)
  675. {
  676. $time = date ('Y-m-d H:i:s', time () - 10);
  677. $res = $newrecharge->where ('account_identity', $account_id)->where ('money', $money)->where ('apply_time', '>', $time)->first ();
  678. if (!$res) {
  679. return 1;
  680. }
  681. return -5023809122;
  682. }
  683. //对象转数组
  684. function toArray($data){
  685. $data = json_encode($data);
  686. $data = json_decode($data,1);
  687. return $data;
  688. }
  689. }