UserPointPlan.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\models\point_plan;
  3. use app\models\user\User;
  4. use app\models\user\UserMoney;
  5. use crmeb\basic\BaseModel;
  6. use crmeb\traits\ModelTrait;
  7. use think\Collection;
  8. use think\db\exception\DataNotFoundException;
  9. use think\db\exception\DbException;
  10. use think\db\exception\ModelNotFoundException;
  11. class UserPointPlan extends BaseModel
  12. {
  13. /**
  14. * 数据表主键
  15. * @var string
  16. */
  17. protected $pk = 'id';
  18. /**
  19. * 模型名称
  20. * @var string
  21. */
  22. protected $name = 'user_point_plan';
  23. use ModelTrait;
  24. public static function is_point($uid)
  25. {
  26. return self::where('uid', $uid)
  27. ->where('status', 1)
  28. ->find();
  29. }
  30. public static function all_point()
  31. {
  32. return self::where('status', 1)
  33. ->column('uid');
  34. }
  35. public static function day_release()
  36. {
  37. $list = self::where('status', 1)
  38. ->where('last_release_day', '<>', date('Y-m-d'))
  39. ->select();
  40. $res = true;
  41. BaseModel::beginTrans();
  42. foreach ($list as $v) {
  43. if ($v['release_time_now'] < $v['release_time_all']) {
  44. $day_release = bcdiv(bcmul($v['release_ratio'], $v['buy_num'], 8), $v['release_time_all']);
  45. $res = $res && UserMoney::incomeMoney($v['uid'], $v['release_money_type'], $day_release, 'release', '节点释放', '节点释放' . ' 第' . ($v['release_time_now'] + 1) . '期');
  46. $res = $res && self::where('id', $v['id'])
  47. ->inc('release_time_now', 1)
  48. ->update();
  49. $res = $res && self::where('id', $v['id'])
  50. ->update(['last_release_day' => date('Y-m-d')]);
  51. }
  52. }
  53. BaseModel::checkTrans($res);
  54. return $res;
  55. }
  56. public static function checkPass()
  57. {
  58. $list = self::where('status', 0)->select();
  59. $res = true;
  60. // BaseModel::beginTrans();
  61. foreach ($list as $v) {
  62. $recommend = User::where('spread_uid', $v['uid'])->where('vote_num', '>=', sys_config('vaild_user', 0))->count();
  63. $group = User::getAllLowUid($v['uid'], false, false, true);
  64. $plan = PointPlan::get($v['plan_id']);
  65. if ($recommend >= $plan['recommend_num'] && $group >= $plan['group_num']) {
  66. $res = $res && self::where('id', $v['id'])->update(['status' => 1, 'pass_time' => time()]);
  67. }
  68. }
  69. // BaseModel::checkTrans($res);
  70. return $res;
  71. }
  72. public static function checkFail()
  73. {
  74. $list = self::where('status', 0)->where('exam_time', '<=', time())->select();
  75. $res = true;
  76. BaseModel::beginTrans();
  77. foreach ($list as $v) {
  78. $res = $res && self::where('id', $v['id'])->update(['status' => 2]);
  79. }
  80. BaseModel::checkTrans($res);
  81. return $res;
  82. }
  83. /**
  84. * @param $where
  85. * @return array
  86. */
  87. public static function getList($where)
  88. {
  89. $model = new self();
  90. if (isset($where['id']) && $where['id'] != '') {
  91. $model->where('plan_id', $where['id']);
  92. }
  93. $count = $model->count();
  94. $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
  95. $item['_status'] = ($item['status'] == 1) ? "考核成功" : (($item['status'] == 2) ? "考核失败" : "考核中");
  96. $item['user'] = User::getUserInfo($item['uid']);
  97. $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  98. $item['_pass_time'] = $item['pass_time'] ? date('Y-m-d H:i:s', $item['pass_time']) : '--';
  99. $item['_check_end_time'] = date('Y-m-d H:i:s', $item['check_end_time']);
  100. });
  101. return compact('count', 'data');
  102. }
  103. }