微信授权

This commit is contained in:
2022-09-14 14:14:56 +08:00
parent 08e90b58e9
commit 59d104f86e

View File

@@ -54,7 +54,8 @@ class Wechat
public function code() public function code()
{ {
$this->initWechat(); $this->initWechat();
$user = $this->app->oauth->user(); $code = Request::get('code');
$user = $this->app->oauth->userFromCode($code);
$callback = Request::get('callback'); $callback = Request::get('callback');
$user = AppUser::where('openid', $user->getId())->find(); $user = AppUser::where('openid', $user->getId())->find();
@@ -94,9 +95,13 @@ class Wechat
$order = \app\model\Order::find($orderId); $order = \app\model\Order::find($orderId);
if(empty($order)) exit('订单信息不存在'); if (empty($order)) {
exit('订单信息不存在');
}
if(\app\model\Order::where(["user_id"=>$order['userid'],"student_id"=>$order['student_id'],"status"=>1])->find()){ if (\app\model\Order::where([
"user_id" => $order['userid'], "student_id" => $order['student_id'], "status" => 1
])->find()) {
exit('已经为该孩子助力过了'); exit('已经为该孩子助力过了');
} }
@@ -147,12 +152,12 @@ class Wechat
$order->paid(); $order->paid();
//订单支付成功。查询用户信息 //订单支付成功。查询用户信息
$order_detail = \app\model\Order::where("id",$order->order_id)->find(); $order_detail = \app\model\Order::where("id", $order->order_id)->find();
//为用户增加助力值 //为用户增加助力值
$zhuLi = env("ZHULI_VALUE")??150; $zhuLi = env("ZHULI_VALUE") ?? 150;
Db::name("student")->inc("hot",$zhuLi)->where("id",$order_detail->id)->update(); Db::name("student")->inc("hot", $zhuLi)->where("id", $order_detail->id)->update();
Db::name("student")->inc("hot_count",1)->where("id",$order_detail->id)->update(); Db::name("student")->inc("hot_count", 1)->where("id", $order_detail->id)->update();
} else { } else {
$fail('Order not exists.'); $fail('Order not exists.');