UpdateMemberLevel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. declare (strict_types = 1);
  13. namespace app\event;
  14. use app\model\member\MemberLevel;
  15. /**
  16. * 会员等级变化(执行会员活跃度变化)
  17. */
  18. class UpdateMemberLevel
  19. {
  20. // 行为扩展的执行入口必须是run
  21. public function handle($data)
  22. {
  23. if($data['account_type'] == 'growth')
  24. {
  25. //活跃度变化等级检测变化
  26. $growth_info = model("member")->getInfo([['member_id', '=', $data['member_id']]], 'growth, member_level');
  27. //查询会员等级
  28. $member_level = new MemberLevel();
  29. $level_list = $member_level->getMemberLevelList([['growth', '<=', $growth_info['growth']]], 'level_id, level_name, sort, growth', 'sort desc');
  30. if(!empty($level_list['data']))
  31. {
  32. //检测升级
  33. if($growth_info['member_level'] == 0)
  34. {
  35. //将用户设置为最大等级
  36. $data_level = [
  37. 'member_level' => $level_list['data'][0]['level_id'],
  38. 'member_level_name' => $level_list['data'][0]['level_name']
  39. ];
  40. model("member")->update($data_level, [['member_id', '=', $data['member_id']]]);
  41. }else{
  42. $level_info = $member_level->getMemberLevelInfo([['level_id', '=', $growth_info['member_level']]]);
  43. if(empty($level_info['data']))
  44. {
  45. //将用户设置为最大等级
  46. $data_level = [
  47. 'member_level' => $level_list['data'][0]['level_id'],
  48. 'member_level_name' => $level_list['data'][0]['level_name']
  49. ];
  50. model("member")->update($data_level, [['member_id', '=', $data['member_id']]]);
  51. }else{
  52. if($level_info['data']['sort'] < $level_list['data'][0]['sort'])
  53. {
  54. //将用户设置为最大等级
  55. $data_level = [
  56. 'member_level' => $level_list['data'][0]['level_id'],
  57. 'member_level_name' => $level_list['data'][0]['level_name']
  58. ];
  59. model("member")->update($data_level, [['member_id', '=', $data['member_id']]]);
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }
  66. }