Core.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. );
  36. if (is_string($drop)) {
  37. $drop = explode(',', $drop);
  38. }
  39. foreach ($drop as $k => $v) {
  40. if ($v == $uid) {
  41. continue;
  42. }
  43. foreach ($table as $k1 => $v1) {
  44. Dever::db($v1)->updates(array('set_uid' => $uid, 'option_uid' => $v));
  45. }
  46. # 处理一些特殊的情况
  47. $this->other($uid, $v);
  48. # 积分相关 要把积分加上,再删掉之前的
  49. $this->score($uid, $v, 'score/user');
  50. $this->score($uid, $v, 'act/score');
  51. }
  52. }
  53. private function other($uid, $drop_uid)
  54. {
  55. Dever::db('code/info')->updates(array('set_create_uid' => $uid, 'option_create_uid' => $drop_uid));
  56. Dever::db('invite/relation')->updates(array('set_to_uid' => $uid, 'option_to_uid' => $drop_uid));
  57. }
  58. private function score($uid, $drop_uid, $table, $col = 'score')
  59. {
  60. $db = Dever::db($table);
  61. $user_score = $db->one(array('uid' => $uid));
  62. $user_drop_score = $db->one(array('uid' => $drop_uid));
  63. if ($user_score && $user_drop_score) {
  64. $score = $user_score[$col] + $user_drop_score[$col];
  65. $update['where_id'] = $user_score['id'];
  66. $update['score'] = $score;
  67. $db->update($update);
  68. $db->delete($user_drop_score['id']);
  69. } elseif (!$user_score && $user_drop_score) {
  70. $score = $user_drop_score[$col];
  71. $update['where_id'] = $user_drop_score['id'];
  72. $update['uid'] = $uid;
  73. $update['score'] = $score;
  74. $db->update($update);
  75. }
  76. }
  77. }