public function actionIndex() { $betime = strtotime(date('Y-m-d' . ' 00:00:00', time())); $endtime = strtotime(date('Y-m-d' . ' 23:59:59', time())); $order = Order::find()->andWhere(['between', 'start_at', $betime, $endtime])->asArray()->count(); $payment = SinaDeposit::find()->andWhere(['status' => SinaDeposit::STATUS_SUCCESS])->andWhere(['between', 'create_at', $betime, $endtime])->asArray()->count(); $withdraw = SinaWithdraw::find()->andWhere(['status' => SinaWithdraw::STATUS_SINA_SUCCESS])->andWhere(['between', 'create_at', $betime, $endtime])->asArray()->count(); $product = Thirdproduct::find()->andWhere(['status' => Thirdproduct::STATUS_ACTIVE])->andWhere(['intent' => Thirdproduct::INTENT_CHECK])->andWhere(['create_user_id' => Yii::$app->user->identity->getId()])->asArray()->all(); $user = UcenterMember::find()->andWhere(['between', 'created_at', $betime, $endtime])->asArray()->count(); $log = TradeLog::find()->orderBy('t_date desc'); $pages = new Pagination(['totalCount' => $log->count(), 'pageSize' => '10']); $log = $log->offset($pages->offset)->limit($pages->limit)->all(); AloneMethod::trade_log(); $cur_recharge = TradeLog::find()->sum('t_recharge'); $cur_invest = TradeLog::find()->sum('t_invest'); $cur_redeem = TradeLog::find()->sum('t_redeem'); $cur_withdraw = TradeLog::find()->sum('t_withdraw'); $cur_profit = TradeLog::find()->sum('t_profit'); $cur_glod = TradeLog::find()->sum('t_gold'); $cur_red = TradeLog::find()->sum('t_red'); $ret_msg = '当前总额: 充值【' . $cur_recharge . '】 投资【' . $cur_invest . '】 赎回【' . $cur_redeem . '】 提现【' . $cur_withdraw . '】 在投【' . $cur_profit . '】 体验金收益【' . $cur_glod . '】 红包【' . $cur_red . '】'; return $this->render('index', ['withdraw' => $withdraw, 'payment' => $payment, 'order' => $order, 'user' => $user, 'product' => $product, 'log' => $log, 'pages' => $pages, 'ret_msg' => $ret_msg]); }
* @time: 2015年7月14日 11:36:26 * */ use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use kartik\file\FileInput; use dosamigos\datetimepicker\DateTimePicker; use common\models\fund\FundProductThirdproduct; use common\models\base\fund\Thirdproduct; $id = $model->id; $thirdfundModel = []; $modelmid = FundProductThirdproduct::find()->where(['product_id' => $id])->asArray()->all(); if ($modelmid) { foreach ($modelmid as $v) { array_push($thirdfundModel, Thirdproduct::find()->select('id')->where(['id' => $v['thirdproduct_id']])->asArray()->one()); } $newth = []; foreach ($thirdfundModel as $k => $v) { array_push($newth, $v['id']); } } /* @var $this yii\web\View */ /* @var $model common\models\base\fund\product */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="product-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
/** * Auther:langxi * 根据赎回债权字典进行赎回操作 * @param $Redeem */ private static function Set_redeem($Redeem) { foreach ($Redeem as $k => $v) { //order表金额赎回 $order = Order::findOne($v['order_id']); $order->money = $order['money'] - $v['thirdmoney']; if ($order['money'] == '0') { $order->status = Order::STATUS_DELETE; } $order = $order->save(); if (!$order) { $result = array('errorNum' => '1', 'errorMsg' => '转让债权赎回失败', 'data' => null); return $result; } //thirdorder表金额赎回 $thirdorder = Thirdorder::findOne($v['thirdorder_id']); $thirdorder->money = $thirdorder['money'] - $v['thirdmoney']; if ($thirdorder['money'] == '0') { $thirdorder->status = Thirdorder::STATUS_DELETED; } $thirdorder->mcmoney = $thirdorder['mcmoney'] + $v['thirdmoney']; //记录最大债权增加 $thirdorder->ocmoney = $thirdorder['ocmoney'] - $v['thirdmoney']; //记录原始债权金额减少 $thirdorder = $thirdorder->save(); if (!$thirdorder) { $result = array('errorNum' => '1', 'errorMsg' => '第三方转让债权失败', 'data' => null); return $result; } //thirdproduct第三方债权已投金额减少 $thirdproduct = Thirdproduct::findOne($v['thirdproduct_id']); $thirdproduct->invest_sum = $thirdproduct['invest_sum'] - $v['thirdmoney']; $thirdproduct->mcmoney = $thirdproduct['mcmoney'] + $v['thirdmoney']; //赎回导致最大债权人金额增加 $thirdproduct = $thirdproduct->save(); if (!$thirdproduct) { $result = array('errorNum' => '1', 'errorMsg' => '赎回第三方债权已投金额失败', 'data' => null); return $result; } //获取债权的最大债权人id,将用户赎回的钱从最大债权人的账户中减去 $maxcreditor = Thirdproduct::find()->select(['maxcreditor'])->where(['id' => $v['thirdproduct_id']])->asArray()->one(); $maxcreditor = $maxcreditor['maxcreditor']; $is_max = Catmiddle::find()->where(['cid' => '1', 'uid' => $maxcreditor])->asArray()->one(); if (!$is_max) { $result = array('errorNum' => '1', 'errorMsg' => '最大债权人异常', 'data' => null); return $result; } $max_info = Info::findOne($maxcreditor); $max_info->balance = $max_info['balance'] - $v['thirdmoney']; $max_info = $max_info->save(); if (!$max_info) { $result = array('errorNum' => '1', 'errorMsg' => '消减最大债权人账户金额失败', 'data' => null); return $result; } //写入职员账户记录表中 $member_id = Order::find()->select(['member_id'])->where(['id' => $v['order_id']])->asArray()->one(); $member_id = $member_id['member_id']; $clerk = new ClerkLog(); $clerk->member_id = $member_id; $clerk->clerk_id = $maxcreditor; $clerk->behav = ClerkLog::CLERK_BEHAV_TWO; $clerk->step = $v['thirdmoney']; $clerk->remark = '最大债权人'; $clerk = $clerk->save(); if (!$clerk) { throw new ErrorException('写入职员账户记录失败'); } } return true; }
/** * Auther:langxi * * 将投资的金额按照生成的债权数据字典,分散加入债权表 */ private static function set_Third($thirdArr, $member_id) { //债权表中无需写入购买人数,没有意义 foreach ($thirdArr as $vo) { //获取thirdproduct中的原始债权人id,最大债权人id,并检查其是否为公司员工,并判断资金应支付给债权人还是原始债权人, $thirdproduct = Thirdproduct::find()->select(['creditor', 'maxcreditor'])->where(['id' => $vo['id']])->asArray()->one(); if ($vo['ocmoney'] > 0) { //将钱支付给原始债权人(网站) $creditor = $thirdproduct['creditor']; $is_yuan = Catmiddle::find()->where(['cid' => '2', 'uid' => $creditor])->asArray()->one(); if (!$is_yuan) { $result = array('errorNum' => '1', 'errorMsg' => '原始债权人异常', 'data' => null); return $result; } $yuan_info = Info::findOne($creditor); $yuan_info->balance = $yuan_info['balance'] + $vo['ocmoney']; $yuan_info = $yuan_info->save(); if (!$yuan_info) { $result = array('errorNum' => '1', 'errorMsg' => '资金放入原始债权人账户失败', 'data' => null); return $result; } //写入职员账户记录表中 $clerk = new ClerkLog(); $clerk->member_id = $member_id; $clerk->clerk_id = $creditor; $clerk->behav = ClerkLog::CLERK_BEHAV_ONE; $clerk->step = $vo['ocmoney']; $clerk->remark = '原始债权人'; $clerk = $clerk->save(); if (!$clerk) { $result = array('errorNum' => '1', 'errorMsg' => '写入职员账户记录失败', 'data' => null); return $result; } } if ($vo['mcmoney'] > 0) { //将钱支付给最大债权人(网站) $maxcreditor = $thirdproduct['maxcreditor']; $is_max = Catmiddle::find()->where(['cid' => '1', 'uid' => $maxcreditor])->asArray()->one(); if (!$is_max) { $result = array('errorNum' => '1', 'errorMsg' => '最大债权人异常', 'data' => null); return $result; } $max_info = Info::findOne($maxcreditor); $max_info->balance = $max_info['balance'] + $vo['mcmoney']; $max_info = $max_info->save(); if (!$max_info) { $result = array('errorNum' => '1', 'errorMsg' => '资金放入最大债权人账户失败', 'data' => null); return $result; } //写入职员账户记录表中 $clerk = new ClerkLog(); $clerk->member_id = $member_id; $clerk->clerk_id = $maxcreditor; $clerk->behav = ClerkLog::CLERK_BEHAV_ONE; $clerk->step = $vo['mcmoney']; $clerk->remark = '最大债权人'; $clerk = $clerk->save(); if (!$clerk) { $result = array('errorNum' => '1', 'errorMsg' => '写入职员账户记录失败', 'data' => null); return $result; } } //按用户id和订单时间获取上面生成的订单id值 $order = Order::find()->where(['member_id' => $member_id])->orderBy('start_at desc')->asArray()->one(); $thirdorder = new Thirdorder(); $thirdorder->member_id = $member_id; $thirdorder->thirdproduct_id = $vo['id']; $thirdorder->order_id = $order['id']; $thirdorder->money = $vo['mcmoney'] + $vo['ocmoney']; $thirdorder->ocmoney = $vo['ocmoney']; $thirdorder->mcmoney = $vo['mcmoney']; $thirdorder->start_money = $vo['mcmoney'] + $vo['ocmoney']; $thirdorder->status = Thirdorder::STATUS_ACTIVE; $thirdorder->start_at = time(); $thirdorder->end_at = $order['end_at']; $thirdorder = $thirdorder->save(); if (!$thirdorder) { $result = array('errorNum' => '1', 'errorMsg' => '债权数据字典写入债权订单表失败', 'data' => null); return $result; } //将资金分配给债权表 $thirdproduct = Thirdproduct::findOne($vo['id']); $thirdproduct->ocmoney = $thirdproduct['ocmoney'] - $vo['ocmoney']; $thirdproduct->mcmoney = $thirdproduct['mcmoney'] - $vo['mcmoney']; $thirdproduct->invest_sum = $thirdproduct['invest_sum'] + $vo['ocmoney'] + $vo['mcmoney']; $thirdproduct = $thirdproduct->save(); if (!$thirdproduct) { $result = array('errorNum' => '1', 'errorMsg' => '资金写入债权表失败', 'data' => null); return $result; } } return false; }
private static function redoc($money) { $num = ceil(mt_rand(3000, 6000) / 1000); //生成随机数 //取已购买、未被使用且未过期的债权项目中的可投资额度 $productthirdproduct = Thirdproduct::find()->andWhere(['process_status' => 0, 'status' => Thirdproduct::STATUS_ACTIVE, 'intent' => Thirdproduct::INTENT_CHECK])->andWhere(['>=', 'end_at', time()])->asArray()->all(); $thirdArr = array(); foreach ($productthirdproduct as $key => $val) { //获取债权项目的id,投资总额,已投资总额 $thirdproduct = Thirdproduct::find()->where(['id' => $val['id']])->asArray()->one(); $thirdArr[$key]['thirdorder_id'] = $thirdproduct['id']; //债权订单id $thirdArr[$key]['k_money'] = $thirdproduct['amount'] - $thirdproduct['invest_sum']; //债权表剩余的可投金额 $thirdArr[$key]['end_at'] = $thirdproduct['end_at']; //债权标结束时间 } //过滤掉可投额度为空的债权标 foreach ($thirdArr as $key => $value) { if (in_array('0', $value)) { unset($thirdArr[$key]); } } sort($thirdArr); //重新生成索引下标 //对数组进行排序处理,让其按照可投金额大小从小到大为主,结束时间从早到晚为辅进行排序 foreach ($thirdArr as $k => $v) { $k_money[$k] = $v['k_money']; $end_at[$k] = $v['end_at']; } array_multisort($k_money, SORT_ASC, $end_at, SORT_ASC, $thirdArr); //生成债权数据字典:比随机生成债权数目少1,生成出可投金额较小的债权项目的对应的投资金额、债权项目id,结束时间。剩余的钱生成给可投金额最大的债权项目,依次类推。 $s_money = $money; $i = 0; $result = array(); foreach ($thirdArr as $key => $val) { $i++; //消除小数,避免投资钱数分配除不尽,导致钱数减少 if ($s_money % ($num - 1) == '0') { $p_money = $s_money / ($num - 1); //取投资钱的平均数 } else { $p_money = ceil($s_money / ($num - 1)); //取投资钱的平均数 } if ($i < $num - 1) { if ($p_money > $val['k_money']) { $result[$key . 'x']['id'] = $val['thirdorder_id']; //投资的债权项目id $result[$key . 'x']['t_money'] = $val['k_money']; //投资的钱数 $result[$key . 'x']['end_at'] = $val['end_at']; //投资项目的结束时间 $s_money = $s_money - $val['k_money']; } else { $result[$key . 'x']['id'] = $val['thirdorder_id']; //投资的债权项目id $result[$key . 'x']['t_money'] = $p_money; //投资的钱数 $result[$key . 'x']['end_at'] = $val['end_at']; //投资项目的结束时间 $s_money = $s_money - $p_money; } } else { break; } } //对数组进行排序处理,让其按照可投金额大小从大到小为主,结束时间从早到晚为辅进行排序 foreach ($thirdArr as $k => $v) { $k_money[$k] = $v['k_money']; $end_at[$k] = $v['end_at']; } array_multisort($k_money, SORT_DESC, $end_at, SORT_ASC, $thirdArr); //生成债权数据字典:将剩余的钱依次分给到可投金额最大的债权项目中,生成债权数据字典 foreach ($thirdArr as $key => $val) { if ($s_money < $val['k_money']) { $result[$key . 'd']['id'] = $val['thirdorder_id']; $result[$key . 'd']['t_money'] = $s_money; $result[$key . 'd']['end_at'] = $val['end_at']; break; } else { $result[$key . 'd']['id'] = $val['thirdorder_id']; $result[$key . 'd']['t_money'] = $val['k_money']; $result[$key . 'd']['end_at'] = $val['end_at']; $s_money = $s_money - $val['k_money']; } } return $result; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function addsearch($params) { $user = User::find()->where(['id' => \App::$app->user->identity->getId()])->one(); if ($user->role == 'admin') { $query = Thirdproduct::find()->orderBy('id DESC'); } else { $query = Thirdproduct::find()->andWhere(['create_user_id' => Yii::$app->user->identity->getId()])->orderBy('id DESC'); } $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $ucmember = new UcenterMember(); $user = new User(); $creditor = $ucmember->find()->andWhere(['username' => $this->creditor])->one(); $maxcreditor = $ucmember->find()->andWhere(['username' => $this->maxcreditor])->one(); $user = $user->find()->andWhere(['username' => $this->create_user_id])->one(); $oid = $creditor ? $creditor->id : ''; $mid = $maxcreditor ? $maxcreditor->id : ''; $uid = $user ? $user->id : ''; $query->andFilterWhere(['id' => $this->id, 'amount' => $this->amount, 'start_at' => $this->start_at, 'end_at' => $this->end_at, 'rate' => $this->rate, 'invest_people' => $this->invest_people, 'invest_sum' => $this->invest_sum, 'create_at' => $this->create_at, 'update_at' => $this->update_at, 'status' => $this->status, 'create_user_id' => $uid, 'check_user_id' => $this->check_user_id, 'ocreditor' => $oid, 'maxcreditor' => $mid]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'source', $this->source])->andFilterWhere(['like', 'creditor', $this->creditor])->andFilterWhere(['like', 'contract', $this->contract])->andFilterWhere(['like', 'remarks', $this->remarks]); return $dataProvider; }