=', 1]; } else { $where[] = ['b.state', '=', 0]; } $list = Billions::alias('b')->where($where) ->join('order o', 'o.id = b.order_id') ->join('goods g', 'g.id = b.goods_id') ->join('shop s', 's.id = b.shop_id') ->field('b.*, o.order_sn, s.name') ->page($page,$size)->select(); $count = Billions::alias('b')->where($where) ->alias('b') ->join('order o', 'o.id = b.order_id') ->join('goods g', 'g.id = b.goods_id') ->join('shop s', 's.id = b.shop_id') ->count(); // 消费订单笔数 $historyOrder = Billions::where('user_id', $user_id)->count(); // 商家最高补贴 $highSubsidy = Billions::where('user_id', $user_id)->sum('order_price', false); $more = is_more($count, $page, $size); //是否有下一页 $data = [ 'list' => $list, 'page_no' => $page, 'page_size' => $size, 'count' => $count, 'more' => $more, 'historyOrder' => $historyOrder, 'highSubsidy' => $highSubsidy ]; return $data; } // 获取排名 public static function getRanking($billions_id){ $where[] = ['billions_id', '<=', $billions_id]; $where[] = ['state', '=', 0]; return Billions::where($where)->count(); } // 提现进行记录 public static function withdrawRecord($id, $user_id){ Db::startTrans(); try { $billions = Billions::where([ 'billions_id' => $id, 'state' => 0 ])->find(); if ($billions) { Billions::where([ 'billions_id' => $id, 'user_id' => $user_id, ])->update(['state' => 1]); // 查看用户是否有过余额添加记录 $subsidy = SubsidyWithdrawal::where(['user_id' => $user_id])->find(); if ($subsidy) { $subsidy_id = $subsidy->id; SubsidyWithdrawal::where(['user_id' => $user_id])->inc('total_amount', $billions->subsidy_price)->update(); } else { $subsidy_id = SubsidyWithdrawal::insert([ 'user_id' => $user_id, 'total_amount' => $billions->subsidy_price ]); } // 增加余额记录 SubsidyWithdrawalRecord::insert([ 'subsidy_withdrawal_id' => $subsidy_id, 'user_id' => $user_id, 'billions_id' => $id, 'type' => 1, 'way' => 0, 'money' => $billions->subsidy_price, 'create_time' => date('Y-m-d H:i:s') ]); } Db::commit(); return true; } catch (Exception $e) { Db::rollback(); return false; } } public static function getSubsidyWithdraw($user_id) { $data['type'] = array( 0 => [ 'name' => '微信零钱', 'value' => 2, ], // 1 => [ // 'name' => '银行卡', // 'value' => 5, // ], 1 => [ 'name' => '东龙汇余额账户', 'value' => 1, ] ); // 手续费 $data['commission'] = self::COMMISSION . '%'; // 提现规则 $data['rule'] = '提现规则'; // 最小提现金额 $data['min_withdraw'] = self::MINIMUM_WITHDRAWAL; $subsidy = SubsidyWithdrawal::where(['user_id' => $user_id])->find(); $data['able_withdraw'] = $subsidy->total_amount; return $data; } public static function balanceapply($user_id, $post) { dump($post); die; Db::startTrans(); try { // 1.先记录到日志下 SubsidyWithdrawalRecord::insert([ 'subsidy_withdrawal_id' => 0, 'user_id' => $user_id, 'billions_id' => 0, 'type' => 2, 'way' => $post['type'], 'money' => $post['money'], 'create_time' => date('Y-m-d H:i:s') ]); // 2. 减少余额 // 3. 开始提现 //提现手续费 $com = self::COMMISSION; // $poundage = 0; // if ($post['type'] != WithdrawEnum::TYPE_BALANCE) { // $poundage_config = ConfigServer::get('withdraw', 'balancepoundage', 0); // $poundage = $post['money'] * $poundage_config / 100; // } // // $data = [ // 'sn' => createSn('withdraw_apply', 'sn'), // 'batch_no' => createSn('withdraw_apply', 'batch_no','SJZZ'), // 'user_id' => $user_id, // 'type' => $post['type'], // 'account' => $post['account'] ?? '', // 'real_name' => $post['real_name'] ?? '', // 'money' => $post['money'], // 'left_money' => $post['money'] - $poundage, // 'money_qr_code' => $post['money_qr_code'] ?? '', // 'remark' => $post['remark'] ?? '', // 'bank' => $post['bank'] ?? '', // 'subbank' => $post['subbank'] ?? '', // 'poundage' => $poundage, // 'status' => 1, // 待提现 // 'create_time' => time(), // ]; // $withdraw_id = BalanceWithdrawApply::insertGetId($data); // // //提交申请后,扣减用户的佣金 // $user = User::find($user_id); // $user->user_money = ['dec', $post['money']]; // $user->save(); // //增加佣金变动记录 // AccountLogLogic::AccountRecord( // $user_id, // $post['money'], // 2, // AccountLog::withdraw_dec_earnings, // '', // $withdraw_id, // $data['sn'] // ); Db::commit(); return $withdraw_id; } catch (Exception $e) { Db::rollback(); throw new Exception($e->getMessage()); } } }