Beispiel #1
0
 public function actionDelGoods()
 {
     if (ChargeGoods::getInstance()->delGoods($this->post['id'])) {
         $this->renderAjax(['status' => 1, 'msg' => '删除成功']);
     } else {
         $this->renderAjax(['status' => 0, 'msg' => '删除失败']);
     }
 }
Beispiel #2
0
 public function actionAlipay()
 {
     $orderInfo = ChargeOrder::getInstance()->getOne($this->get['orderId']);
     $goods = ChargeGoods::getInstance()->getOne($orderInfo['charge_goods_id']);
     $parameter = array("service" => $this->alipayConfig()['service'], "partner" => $this->alipayConfig()['partner'], "seller_id" => $this->alipayConfig()['partner'], "payment_type" => $this->alipayConfig()['payment_type'], "notify_url" => $this->alipayConfig()['notify_url'], "return_url" => $this->alipayConfig()['return_url'], "_input_charset" => trim(strtolower($this->alipayConfig()['input_charset'])), "out_trade_no" => $orderInfo['order_id'], "subject" => '嘉瑞百合缘-【' . $goods['name'] . '】', "total_fee" => $orderInfo['money'] / 100, "show_url" => $goods['id'] == '8' ? 'http://wechat.baihey.com/wap/site/main#/main/member/balance' : 'http://wechat.baihey.com/wap/site/main#/main/member/vip', "body" => '');
     //建立请求
     $alipaySubmit = new \AlipaySubmit($this->alipayConfig());
     $html_text = $alipaySubmit->buildRequestForm($parameter, "get", "确认");
     echo $html_text;
 }
Beispiel #3
0
 public function actionCharge()
 {
     if (\Yii::$app->request->post()) {
         $orderId = ChargeOrder::getInstance()->createOrder(\Yii::$app->request->post('user_id'), \Yii::$app->request->post());
         // 创建订单
         $result = ChargeOrder::getInstance()->setOrderStatus($orderId, 1, true);
         $this->renderAjax(['status' => $result]);
         exit;
     }
     $goods = ChargeGoods::getInstance()->getAllList(['status' => 1]);
     $this->assign('goods', $goods);
     return $this->render();
 }
Beispiel #4
0
 /**
  * 开通服务(修改余额,到期时间,等级)
  * @param $user_id
  * @param $orderInfo
  * @param int $level
  * @return bool
  * @throws \yii\db\Exception
  */
 public function changeMatureTime($user_id, $orderInfo, $level = 0, $isAdmin = false)
 {
     $goods = ArrayHelper::toArray(ChargeGoods::getInstance()->findOne($orderInfo['charge_goods_id']));
     $userInfo = $this->getUserById($user_id);
     //  订单金额是否大于余额
     if (!$isAdmin) {
         if ($orderInfo['money'] > $userInfo['balance']) {
             return false;
         }
     }
     $db = $this->getDb();
     $transaction = $db->beginTransaction();
     // 启动事务
     // 计算时间
     $time = $goods['value'] * 30 * 24 * 3600;
     // vip时间(月)
     if (1 == $goods['giveType'] && $goods['give'] > 0) {
         $time += $goods['give'] * 24 * 3600;
         // 赠送的时间(天)
     }
     // 修改余额
     $user = $this->changeBalance($user_id, $goods['price']);
     if ($userInfo['honesty_value'] & 16) {
         $nData['honesty_value'] = intval($userInfo['honesty_value']) - 16;
         UserInformation::getInstance()->updateUserInfo($user_id, $nData);
     }
     // 修改到期时间
     $_user_information_table = $this->tablePrefix . 'user_information';
     // 表名
     $userInfo['mature_time'] = YII_BEGIN_TIME > $userInfo['mature_time'] ? YII_BEGIN_TIME + $time : $userInfo['mature_time'] + $time;
     $level = $goods['level'];
     if ($level != 0) {
         $sql = "UPDATE {$_user_information_table} SET info = JSON_REPLACE(info,'\$.level','" . $level . "'), mature_time = " . $userInfo['mature_time'] . " WHERE user_id={$user_id}";
     } else {
         $sql = "UPDATE {$_user_information_table} SET mature_time = " . $userInfo['mature_time'] . " WHERE user_id={$user_id}";
     }
     $info = $db->createCommand($sql)->execute();
     if ($user && $info) {
         $transaction->commit();
         // 写入用户消费日志表
         $goods['receive_name'] = '嘉瑞百合缘';
         $goods['type'] = 1;
         ConsumptionLog::getInstance()->addConsumptionLog($user_id, $goods);
         return true;
     } else {
         $transaction->rollBack();
         return false;
     }
 }
Beispiel #5
0
 /**
  * 微信支付
  * @param $orderId
  * @return array
  * @throws \WxPayException
  */
 public function weiXinPay($orderId)
 {
     //①、获取用户openid
     $tools = new \JsApiPay();
     $openId = $tools->GetOpenid();
     if ($openId == -1) {
         return false;
     }
     //②、统一下单
     $orderInfo = ChargeOrder::getInstance()->getOne($orderId);
     $goods = ChargeGoods::getInstance()->getOne($orderInfo['charge_goods_id']);
     $input = new \WxPayUnifiedOrder();
     $input->SetBody("嘉瑞百合缘-【" . $goods['name'] . "】");
     $input->SetAttach("手机网站");
     $input->SetOut_trade_no($orderInfo['order_id']);
     $input->SetTotal_fee((string) $orderInfo['money']);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetNotify_url("http://wechat.baihey.com/wap/charge/notify-url");
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     $jsApiParameters = $tools->GetJsApiParameters($order);
     return ['orderInfo' => $orderInfo, 'jsApiParameters' => $jsApiParameters];
 }