Core.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_create_uid' => $uid, 'option_create_uid' => $drop_uid));
  57. Dever::db('invite/relation')->updates(array('set_to_uid' => $uid, 'option_to_uid' => $drop_uid));
  58. }
  59. private function score($uid, $drop_uid, $table, $col = 'score')
  60. {
  61. $db = Dever::db($table);
  62. $user_score = $db->one(array('uid' => $uid));
  63. $user_drop_score = $db->one(array('uid' => $drop_uid));
  64. if ($user_score && $user_drop_score) {
  65. $score = $user_score[$col] + $user_drop_score[$col];
  66. $update['where_id'] = $user_score['id'];
  67. $update['score'] = $score;
  68. $db->update($update);
  69. $db->delete($user_drop_score['id']);
  70. } elseif (!$user_score && $user_drop_score) {
  71. $score = $user_drop_score[$col];
  72. $update['where_id'] = $user_drop_score['id'];
  73. $update['uid'] = $uid;
  74. $update['score'] = $score;
  75. $db->update($update);
  76. }
  77. }
  78. }