/** * 获取用户绑卡信息 * @param $uid * @return bool */ public static function getBankcard($uid) { $info = Info::findOne($uid); if ($info) { $bank_card = $info->bank_card; $bank_code = $info->bank_card_phone; if ($bank_card != "" && $bank_code != "") { $bank = array('01020000' => "工商银行", '01030000' => '农业银行', '01040000' => '中国银行', '01050000' => '建设银行', '03080000' => '招商银行', '03100000' => '浦发银行', '03030000' => '光大银行', '03070000' => '平安银行', '03040000' => '华夏银行', '03090000' => '兴业银行', '03020000' => '中信银行', '01000000' => '储蓄银行', '03050000' => '民生银行', '03060000' => '广发银行'); $bank_name = $bank[$bank_code]; $data['bank_card'] = $bank_card; $data['bank_name'] = $bank_name; return $data; } else { return false; } } else { return false; } }
<?php use yii\helpers\Html; use common\models\base\fund\Income; use common\models\setting\Setting; use common\models\base\asset\Info; /* @var $this \yii\web\View */ /* @var $content string */ $directoryAsset = Yii::$app->assetManager->getPublishedUrl('@almasaeed/'); //收益数据包 if (!yii::$app->user->isGuest) { $income_array = Income::find()->where("created_at>=" . strtotime(date("Y-m-d")) . " AND member_id=" . yii::$app->user->id)->asArray()->one(); $profit = Info::findOne(['member_id' => yii::$app->user->id])->profit; $income_total = Info::findOne(['member_id' => yii::$app->user->id])->total_revenue; } else { $income_array = ""; $profit = ""; $income_total = ""; } // footer数据表 try { $tel1 = Setting::findOne(['code' => 'phone'])->value; $tel2 = Setting::findOne(['code' => 'tell'])->value; $email = Setting::findOne(['code' => 'email'])->value; $work = Setting::findOne(['code' => 'work'])->value; } catch (ErrorException $e) { $tel1 = ""; $tel2 = ""; $email = ""; $work = ""; }
/** * 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; }
/** * 用户退款 * @return string * @throws NotFoundHttpException */ public function actionRefund() { if (\App::$app->request->post()) { $uid = \App::$app->request->post()['Code']['uid']; $orig_outer_trade_no = \App::$app->request->post()['Code']['out_trade_no']; $refund_amount = \App::$app->request->post()['Code']['money']; $summary = \App::$app->request->post()['Code']['msg']; //获取新浪的账户余额 $sina_balance = sinapay::querySinaBalance($uid); if ($sina_balance['errorNum'] == '0') { $available_balance = $sina_balance['data']['available_balance']; } //获取网站的账户信息 $balance = Info::findOne(['member_id' => $uid]); $site_balabce = $balance['balance']; //调用新浪退款接口 $sina = new sina(); $out_trade_no = date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8) . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT); $refund = $sina->create_hosting_refund($out_trade_no, $orig_outer_trade_no, $refund_amount, $summary); if (!$refund) { throw new NotFoundHttpException('新浪接口错误'); } if ($refund['response_code'] == "APPLY_SUCCESS") { //提交信息成功 if ($refund['refund_status'] == 'SUCCESS' || $refund['refund_status'] == 'PAY_FINISHED') { //更新账户信息 $sina_balance = sinapay::querySinaBalance($uid); if ($sina_balance['errorNum'] == '0') { $available_balance_now = $sina_balance['data']['available_balance']; } //获取网站的账户信息 $balance = Info::findOne(['member_id' => $uid]); $site_balabce_now = $balance['balance']; //返回数据 $data = array('available_balance' => $available_balance, 'site_balabce' => $site_balabce, 'available_balance_now' => $available_balance_now, 'site_balabce_now' => $site_balabce_now); return $this->render('import', compact("data")); } else { throw new NotFoundHttpException($refund['response_message']); } } else { throw new NotFoundHttpException($refund['response_message']); } } else { $data = array('available_balance' => '-1', 'site_balabce' => '-2', 'available_balance_now' => '-3', 'site_balabce_now' => '-4'); return $this->render('import', compact("data")); } }
/** * Finds the Info model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Info the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Info::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 用户签到 * @param $uid * @param $from * @return array */ public static function signIn($uid, $from) { //正式上线再定 $info = Info::findOne(['member_id' => $uid]); if (!$info) { $return = array('errorNum' => '1', 'errorMsg' => "用户不存在", 'data' => null); return $return; } //获取在投资金 $invest = $info->invest; // if ($invest < 1000) { $return = array('errorNum' => '1', 'errorMsg' => "在投金额大于1000的用户才能签到", 'data' => null); return $return; } //获取最新签到记录 $get_sign = SignIn::find()->where(['uid' => $uid])->orderBy('sign_in_time DESC')->one(); if ($get_sign) { $sign_time = $get_sign->sign_in_time; //今日零时时间 $zero_time = strtotime(date("Y-m-d")); //明日零时时间 // $tom_zero_time = $zero_time + 86400; if ($sign_time < $zero_time) { //最后一次签到时间小于当日零时--可以签到 $log = new SignIn(); $log->uid = $uid; $log->sign_in_time = time(); $log->sign_in_money = 0; $log->sign_in_ip = Yii::$app->request->userIp; $log->sign_in_from = $from; $log->status = SignIn::STATUS_ACTIVE; if ($log->save()) { $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null); return $result; } else { $result = array('errorNum' => '1', 'errorMsg' => '签到失败', 'data' => null); return $result; } } else { $result = array('errorNum' => '1', 'errorMsg' => '已经签到', 'data' => null); return $result; } } else { //直接签到 $log = new SignIn(); $log->uid = $uid; $log->sign_in_time = time(); $log->sign_in_money = 0; $log->sign_in_ip = Yii::$app->request->userIp; $log->sign_in_from = $from; $log->status = SignIn::STATUS_ACTIVE; if ($log->save()) { $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null); return $result; } else { $result = array('errorNum' => '1', 'errorMsg' => '签到失败', 'data' => null); return $result; } } }