Import.php 4.4 KB

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