UserPointPlan.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\models\point_plan;
  3. use app\models\user\User;
  4. use app\models\user\UserBill;
  5. use app\models\user\UserMoney;
  6. use crmeb\basic\BaseModel;
  7. use crmeb\traits\ModelTrait;
  8. use think\Collection;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. class UserPointPlan extends BaseModel
  13. {
  14. /**
  15. * 数据表主键
  16. * @var string
  17. */
  18. protected $pk = 'id';
  19. /**
  20. * 模型名称
  21. * @var string
  22. */
  23. protected $name = 'user_point_plan';
  24. use ModelTrait;
  25. public static function is_point($uid)
  26. {
  27. return self::where('uid', $uid)
  28. ->find();
  29. }
  30. public static function all_point()
  31. {
  32. return self::column('uid');
  33. }
  34. public static function day_release()
  35. {
  36. $list = self::where('last_release_day', '<>', date('Y-m-d'))
  37. ->whereOr('last_release_day', null)
  38. ->select();
  39. // var_dump(self::getLastSql());
  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($v['release_money'], $v['release_time_all'], 8);
  45. // var_dump($day_release);
  46. $day_release = bcmul($day_release, $v['buy_num'], 8);
  47. $res = $res && UserMoney::incomeMoney($v['uid'], $v['release_money_type'], $day_release, 'release', '节点释放', '节点释放' . ' 第' . ($v['release_time_now'] + 1) . '期');
  48. $res = $res && self::where('id', $v['id'])
  49. ->inc('release_time_now', 1)
  50. ->update();
  51. $res = $res && self::where('id', $v['id'])
  52. ->update(['last_release_day' => date('Y-m-d')]);
  53. }
  54. }
  55. BaseModel::checkTrans($res);
  56. return $res;
  57. }
  58. public static function day_release_ticket()
  59. {
  60. if (PointAwardLog::be(['add_date' => date('Y-m-d')])) return true;
  61. //昨日总票数
  62. $res = true;
  63. $plan = PointPlan::get(1);
  64. if (!$plan) return true;
  65. $points = UserPointPlan::sum('buy_num');
  66. $list = UserPointPlan::group('uid')->field('SUM(buy_num) as buys,uid')->select();
  67. BaseModel::beginTrans();
  68. $money_type = sys_data('money_type');
  69. foreach ($money_type as $v) {
  70. $sum_ticket = UserBill::where('status', 1)->where('category', $v['code'])
  71. ->whereTime('add_time', 'yesterday')
  72. ->where('type', 'lala_ticket')->value('SUM(number)');
  73. if ($sum_ticket > 0) {
  74. $brokerageRatio = bcdiv($plan['ticket_ratio'], 100, 4);
  75. $brokeragePrice = bcmul($sum_ticket, $brokerageRatio, 8);
  76. $every_price = bcdiv($brokeragePrice, $points, 8);
  77. foreach ($list as $vv) {
  78. $brokeragePrice = bcmul($vv['buys'], $every_price, 8);
  79. if ($brokeragePrice > 0) {
  80. $mark = '昨日拼购门票' . $v['code'] . '合计' . $sum_ticket . ',获得节点门票分红' . $brokeragePrice . $v['code'];
  81. $res = $res && UserMoney::incomeMoney($vv['uid'], $v['code'], $brokeragePrice, 'lala_point_award', '节点分红', $mark);
  82. }
  83. }
  84. }
  85. }
  86. $res = $res && PointAwardLog::create(['add_date' => date('Y-m-d')]);
  87. BaseModel::checkTrans($res);
  88. return $res;
  89. }
  90. /**
  91. * @param $where
  92. * @return array
  93. * @throws DataNotFoundException
  94. * @throws DbException
  95. * @throws ModelNotFoundException
  96. */
  97. public static function getList($where)
  98. {
  99. $model = new self();
  100. if (isset($where['id']) && $where['id'] != '') {
  101. $model->where('plan_id', $where['id']);
  102. }
  103. $count = $model->count();
  104. $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
  105. $item['_status'] = ($item['status'] == 1) ? "考核成功" : (($item['status'] == 2) ? "考核失败" : "考核中");
  106. $item['user'] = User::getUserInfo($item['uid']);
  107. $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  108. $item['_pass_time'] = $item['pass_time'] ? date('Y-m-d H:i:s', $item['pass_time']) : '--';
  109. $item['_check_end_time'] = date('Y-m-d H:i:s', $item['check_end_time']);
  110. });
  111. return compact('count', 'data');
  112. }
  113. }