UserPartake.php 1.4 KB

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