Import.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace Option\Lib;
  3. use Dever;
  4. include('/share/lib/php/dever_package/excel/src/PHPExcel.php');
  5. class Import
  6. {
  7. # 导入账户
  8. public function get_api()
  9. {
  10. Dever::config('base')->hook = true;
  11. $file = Dever::data() . 'q.xlsx';
  12. $data = Dever::excelImport($file, 1, 5, 'excel');
  13. $result = array();
  14. $result['test'] = array('test', 'bb');
  15. $table = Dever::table($result);
  16. echo $table;die;
  17. if ($data) {
  18. $member = array();
  19. foreach ($data as $k => $v) {
  20. $state = preg_match(Dever::rule('mobile'), $v['C']);
  21. if ($state) {
  22. $key = $v['A'];
  23. $where['key'] = $v['A'];
  24. $where['mobile'] = $v['C'];
  25. $where['clear'] = true;
  26. $info = Dever::db('option/member')->find($where);
  27. $update = $where;
  28. $update['idcard'] = $v['D'];
  29. $update['name'] = $v['B'];
  30. $update['main'] = $v['E'] == 1 ? 1 : 2;
  31. if (!$info) {
  32. $update['status'] = 2;
  33. $id = Dever::db('option/member')->insert($update);
  34. } else {
  35. $update['where_id'] = $info['id'];
  36. $id = Dever::db('option/member')->update($update);
  37. }
  38. if ($id && $update['main'] == 1) {
  39. if (!isset($member[$key])) {
  40. $member[$key] = array();
  41. }
  42. $account = Dever::db('option/member')->find(array('mid' => $id));
  43. if (!$account) {
  44. $member[$key] = Dever::db('option/account')->insert(array('mid' => $id, 'audit' => 1));
  45. } else {
  46. $member[$key] = $account['id'];
  47. }
  48. }
  49. }
  50. }
  51. if ($member) {
  52. foreach ($member as $k => $v) {
  53. $where = array();
  54. $where['option_key'] = $k;
  55. $where['set_aid'] = $v;
  56. Dever::db('option/member')->updates($where);
  57. }
  58. }
  59. }
  60. $table = Dever::table($result);
  61. return $table;
  62. }
  63. # 导入交付记录
  64. public function get_jiaofu_api()
  65. {
  66. Dever::config('base')->hook = true;
  67. $file = Dever::data() . 'qiquan.xlsx';
  68. $data = Dever::excelImport($file, 2, 5, 'excel');
  69. if ($data) {
  70. foreach ($data as $k => $v) {
  71. $state = preg_match(Dever::rule('mobile'), $v['A']);
  72. if ($state && $v['C'] > 0) {
  73. $where['mobile'] = $v['A'];
  74. $type_name = $v['D'];
  75. if ($type_name == '期权') {
  76. $type = 1;
  77. } else {
  78. $type = 4;
  79. }
  80. $info = Dever::db('option/member')->find($where);
  81. if ($info) {
  82. $account = Dever::db('option/account')->find($info['aid']);
  83. if ($account && $account['status'] < 3) {
  84. Dever::load('option/lib/cash')->up($info['id'], $account['id'], $type, $v['C'], $v['E'], false);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. return 'ok';
  91. }
  92. # 导入发放记录
  93. public function get_fafang_api()
  94. {
  95. Dever::config('base')->hook = true;
  96. $file = Dever::data() . 'qiquan.xlsx';
  97. $data = Dever::excelImport($file, 3, 5, 'excel');
  98. if ($data) {
  99. foreach ($data as $k => $v) {
  100. $state = preg_match(Dever::rule('mobile'), $v['A']);
  101. if ($state && $v['C'] > 0) {
  102. $where['mobile'] = $v['A'];
  103. $type_name = $v['D'];
  104. if ($type_name == '期权') {
  105. $type = 2;
  106. } else {
  107. $type = 5;
  108. }
  109. $info = Dever::db('option/member')->find($where);
  110. if ($info) {
  111. $account = Dever::db('option/account')->find($info['aid']);
  112. if ($account && $account['status'] < 3) {
  113. Dever::load('option/lib/cash')->up($info['id'], $account['id'], $type, $v['C'], $v['E'], false);
  114. }
  115. }
  116. }
  117. }
  118. }
  119. return 'ok';
  120. }
  121. }