Core.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Combine\Lib;
  3. use Dever;
  4. class Core
  5. {
  6. # 合并用户数据
  7. public function handle($uid, $drop)
  8. {
  9. $table = array
  10. (
  11. 'passport/app',
  12. 'passport/wechat',
  13. 'act/feedback',
  14. 'act/comment',
  15. 'act/form_id',
  16. 'act/invite',
  17. 'act/like',
  18. 'act/live_comment',
  19. 'act/live_note',
  20. //'act/score',//积分相关的要加上,不能直接修改
  21. 'act/share',
  22. 'act/share_reflux',
  23. 'act/subscribe',
  24. 'act/watch',
  25. //'code/info',
  26. 'source/user',
  27. 'score/action_log',
  28. //'score/user',//积分相关的要加上,不能直接修改
  29. //'score/user_level',//等级,不做合并,保留即可
  30. 'score/user_log',//积分日志
  31. 'message/inbox',
  32. 'invite/relation',
  33. //'pay/order',//支付系统单独建立,如果通过接口会有安全问题,因为数据是独立的,暂时不做合并
  34. 'journal/order',
  35. 'act/order',
  36. );
  37. if (is_string($drop)) {
  38. $drop = explode(',', $drop);
  39. }
  40. foreach ($drop as $k => $v) {
  41. if ($v == $uid) {
  42. continue;
  43. }
  44. foreach ($table as $k1 => $v1) {
  45. Dever::db($v1)->updates(array('set_uid' => $uid, 'option_uid' => $v));
  46. }
  47. # 处理一些特殊的情况
  48. $this->other($uid, $v);
  49. # 积分相关 要把积分加上,再删掉之前的
  50. $this->score($uid, $v, 'score/user');
  51. $this->score($uid, $v, 'act/score');
  52. }
  53. }
  54. private function other($uid, $drop_uid)
  55. {
  56. Dever::db('code/info')->updates(array('set_uid' => $uid, 'option_uid' => $drop_uid));
  57. Dever::db('code/info')->updates(array('set_create_uid' => $uid, 'option_create_uid' => $drop_uid));
  58. $journal = Dever::db('journal/info')->state();
  59. if ($journal) {
  60. foreach ($journal as $k => $v) {
  61. Dever::setInput('set_product_id', $v['id']);
  62. Dever::db('code/info')->updates(array('set_uid' => $uid, 'option_uid' => $drop_uid));
  63. Dever::db('code/info')->updates(array('set_create_uid' => $uid, 'option_create_uid' => $drop_uid));
  64. }
  65. }
  66. Dever::db('invite/relation')->updates(array('set_to_uid' => $uid, 'option_to_uid' => $drop_uid));
  67. }
  68. private function score($uid, $drop_uid, $table, $col = 'score')
  69. {
  70. $db = Dever::db($table);
  71. $user_score = $db->one(array('uid' => $uid));
  72. $user_drop_score = $db->one(array('uid' => $drop_uid));
  73. if ($user_score && $user_drop_score) {
  74. $score = $user_score[$col] + $user_drop_score[$col];
  75. $update['where_id'] = $user_score['id'];
  76. $update['score'] = $score;
  77. $db->update($update);
  78. $db->delete($user_drop_score['id']);
  79. } elseif (!$user_score && $user_drop_score) {
  80. $score = $user_drop_score[$col];
  81. $update['where_id'] = $user_drop_score['id'];
  82. $update['uid'] = $uid;
  83. $update['score'] = $score;
  84. $db->update($update);
  85. }
  86. }
  87. }