SystemGroupLevel.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\models\system;
  3. use app\admin\model\system\SystemUserLevel;
  4. use app\models\store\StoreCart;
  5. use app\models\store\StoreOrder;
  6. use app\models\user\User;
  7. use crmeb\basic\BaseModel;
  8. use crmeb\traits\ModelTrait;
  9. /**
  10. * TODO 会员等级Model
  11. * Class UserLevel
  12. * @package app\models\user
  13. */
  14. class SystemGroupLevel extends BaseModel
  15. {
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'system_group_level';
  26. use ModelTrait;
  27. /**
  28. * 获取查询条件
  29. * @param $where
  30. * @param string $alert
  31. * @param null $model
  32. * @return SystemUserLevel|null
  33. */
  34. public static function setWhere($where, $alert = '', $model = null)
  35. {
  36. $model = $model === null ? new self() : $model;
  37. if ($alert) $model = $model->alias($alert);
  38. $alert = $alert ? $alert . '.' : '';
  39. $model = $model->where("{$alert}is_del", 0);
  40. if (isset($where['is_show']) && $where['is_show'] !== '') $model = $model->where("{$alert}is_show", $where['is_show']);
  41. if (isset($where['title']) && $where['title']) $model = $model->where("{$alert}name", 'LIKE', "%$where[title]%");
  42. return $model;
  43. }
  44. public static function getSystemList($where)
  45. {
  46. $data = self::setWhere($where)->order('id asc')->page((int)$where['page'], (int)$where['limit'])->select();
  47. $data = count($data) ? $data->toArray() : [];
  48. $count = self::setWhere($where)->count();
  49. return compact('data', 'count');
  50. }
  51. public static function checkLevel($uid)
  52. {
  53. $spread = User::where('uid', $uid)->find();
  54. // $spread = User::where('uid', $user['spread_uid'])->find();
  55. while ($spread) {
  56. //伞下全员
  57. // $uids = [];
  58. // $sp = [$spread['uid']];
  59. // while ($sp) {
  60. // $sp = User::where('spread_uid', 'in', $sp)->column('uid');
  61. // if (count($sp)) $uids = array_merge($uids, $sp);
  62. // }
  63. // $orders = StoreOrder::where('paid', 1)
  64. // ->where('status', 'in', [2, 3])
  65. // ->where('uid', 'in', $uids)
  66. // ->where('refund_status', 0)
  67. // ->where('is_del', 0)
  68. // ->where('is_system_del', 0)->select();
  69. // $num = 0;
  70. // foreach ($orders as $v) {
  71. // $num += StoreCart::where('id', 'in', $v['cart_id'])->where('is_suit', 1)->sum('cart_num');
  72. // }
  73. $level_info = self::where('id', $spread['group_level'])->find();
  74. $level = self::where('level_num', '>', $level_info['level_num'] ?? 0)->order('level_num', 'desc')->select();
  75. foreach ($level as $v) {
  76. if ($spread['group_suit_num'] >= $v['level_num']) {
  77. User::where('uid', $spread['uid'])->update(['group_level' => $v['id']]);
  78. SystemAwardLevel::sendBackOrderBrokerage($spread['uid'], $spread['award_level'] > $v['id'] ? $v['id'] : $spread['award_level']);
  79. break;
  80. }
  81. }
  82. $spread = User::where('uid', $spread['spread_uid'])->find();
  83. }
  84. return true;
  85. }
  86. }