This commit is contained in:
knowpia
2022-09-14 09:31:30 +08:00
parent 7cdf9fef70
commit c133d6c830
2 changed files with 31 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
namespace app\controller; namespace app\controller;
use app\model\Student;
use think\response\Json; use think\response\Json;
class Order class Order
@@ -16,10 +17,22 @@ class Order
public function create(): Json public function create(): Json
{ {
$userid = $GLOBALS['data']['userid']; $userid = $GLOBALS['data']['userid'];
$amount = $GLOBALS['data']['amount'] ?? 15; $amount = env("PAY_AMOUNT") ?? 15;
if(env("APP_DEBUG")){
$amount = 0.01;
}
if(empty($GLOBALS['data']['data']['student_id'])){
return show("请正确上传用户信息!", ERROR_CODE,[]);
}
$student_id = $GLOBALS['data']['data']['student_id'];
if(!Student::findOrEmpty($student_id)){
return show("用户信息不存在!", ERROR_CODE,[]);
}
if(\app\model\Order::where(["userid"=>$userid,"student_id"=>$student_id,"status"=>1])->find()){
return show("已经为该孩子助力过了!", ERROR_CODE,[]);
}
$order = \app\model\Order::create([ $order = \app\model\Order::create([
'student_id' => 14, 'student_id' => $student_id,
'user_id' => $userid, 'user_id' => $userid,
'amount' => $amount, 'amount' => $amount,
'status' => 0, 'status' => 0,

View File

@@ -7,6 +7,7 @@ use app\model\Payment;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application; use EasyWeChat\OfficialAccount\Application;
use think\facade\Config; use think\facade\Config;
use think\facade\Db;
use think\facade\Request; use think\facade\Request;
use think\facade\Route; use think\facade\Route;
use think\facade\View; use think\facade\View;
@@ -93,6 +94,12 @@ class Wechat
$order = \app\model\Order::find($orderId); $order = \app\model\Order::find($orderId);
if(empty($order)) exit('订单信息不存在');
if(\app\model\Order::where(["userid"=>$order['userid'],"student_id"=>$order['student_id'],"status"=>1])->find()){
exit('已经为该孩子助力过了');
}
$notifyUrl = Route::buildUrl('wechat/paid') $notifyUrl = Route::buildUrl('wechat/paid')
->suffix(false) ->suffix(false)
->domain(true) ->domain(true)
@@ -138,6 +145,14 @@ class Wechat
if (key_exists('result_code', $message) && $message['result_code'] === 'SUCCESS') { if (key_exists('result_code', $message) && $message['result_code'] === 'SUCCESS') {
$order->paid(); $order->paid();
//订单支付成功。查询用户信息
$order_detail = \app\model\Order::where("id",$order->order_id)->find();
//为用户增加助力值
$zhuLi = env("ZHULI_VALUE")??150;
Db::name("student")->inc("hot",$zhuLi)->where("id",$order_detail->id)->update();
} else { } else {
$fail('Order not exists.'); $fail('Order not exists.');
} }