123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace app\models\user;
- use app\admin\model\order\StoreOrder;
- use app\admin\model\user\User;
- use think\Model;
- class UserPartake extends Model
- {
- protected $name = 'user_partake';
- protected $autoWriteTimestamp = true;
- /**
- * 参与累计金额
- * @param $order
- * @return void
- */
- public static function cumulative()
- {
- $user = User::select();
- foreach ($user as $item){
- $partake = UserPartake::where('uid', $item['uid'])->where('status', 0)->find();
- if ($partake){
- $uids = User::where('spread_uid', $item['uid'])->column('uid');
- $money = StoreOrder::where('uid', 'in', $uids)
- ->where('paid', 1)
- ->where('is_participate', 0)
- ->sum('pay_price');
- $out = Out::where('id', $partake['out_id'])->find();
- if ($money >= $out['number']){
- User::where('uid', $item['uid'])->dec('pay_price', $money)->update();
- User::where('uid', $item['uid'])->inc('use_price', $money)->update();
- $partake['status'] = 1;
- $partake['money'] = $money;
- $partake->save();
- StoreOrder::where('uid', 'in', $uids)->where('paid', 1)->where('is_participate', 0)->update(['is_participate' => 1]);
- }
- }
- }
- }
- }
|