UserPartake.php 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\models\user;
  3. use think\Model;
  4. class UserPartake extends Model
  5. {
  6. protected $name = 'user_partake';
  7. protected $autoWriteTimestamp = true;
  8. /**
  9. * 参与累计金额
  10. * @param $order
  11. * @return void
  12. */
  13. public static function cumulative()
  14. {
  15. $user = User::select();
  16. foreach ($user as $item){
  17. $partake = UserPartake::where('uid', $item['uid'])->where('status', 0)->find();
  18. if ($partake){
  19. $out = Out::where('id', $partake['out_id'])->find();
  20. if ($item['pay_price'] >= $out['number']){
  21. User::where('uid', $item['uid'])->dec('pay_price', $out['number'])->update();
  22. User::where('uid', $item['uid'])->inc('use_price', $out['number'])->update();
  23. $partake['status'] = 1;
  24. $partake['money'] = $out['number'];
  25. $partake->save();
  26. }
  27. }
  28. }
  29. }
  30. }