master
cody 4 months ago
parent 83856f357a
commit 5e1d57324d

@ -189,6 +189,7 @@ class CourseController extends BaseController
* @OA\Parameter(name="content", in="query", @OA\Schema(type="string"), description="课程内容"),
* @OA\Parameter(name="total", in="query", @OA\Schema(type="integer"), description="开课人数"),
* @OA\Parameter(name="class", in="query", @OA\Schema(type="string"), description="所在班级"),
* @OA\Parameter(name="price", in="query", @OA\Schema(type="string"), description="价格"),
* @OA\Parameter(name="is_arrange", in="query", @OA\Schema(type="integer"), description="是否排课-0否1是"),
* @OA\Parameter(name="is_fee", in="query", @OA\Schema(type="integer"), description="是否缴费-0否1是"),
* @OA\Parameter(name="status", in="query", @OA\Schema(type="integer"), description="课程状态0待发布, 1已发布"),

@ -6,6 +6,7 @@
namespace App\Http\Controllers\Mobile;
use App\Helpers\ResponseCode;
use App\Models\AccompanyOrder;
use App\Models\AppointmentTotalLog;
use App\Models\Config;
use App\Models\Course;
@ -13,7 +14,10 @@ use App\Models\CourseAppointmentTotal;
use App\Models\CourseContent;
use App\Models\CourseSign;
use App\Models\Notice;
use App\Models\Order;
use App\Models\User;
use EasyWeChat\Factory;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
class CourseController extends CommonController
@ -185,7 +189,10 @@ class CourseController extends CommonController
'course_id' => $all['course_id'],
'user_id' => $this->getUserId(),
'data' => $all['data'] ?? [],
'change_data' => $all['change_data'] ?? []
'change_data' => $all['change_data'] ?? [],
'no' => getBatchNo(),
'money' => $course->price,
'title' => $course->name
]);
// 发短信
$smsSign = Config::getValueByKey('sms_sign');
@ -511,4 +518,82 @@ class CourseController extends CommonController
return $this->success($detail);
}
/**
* @OA\Get(
* path="/api/mobile/course/pay",
* tags={"小程序-课程"},
* summary="获取支付参数",
* @OA\Parameter(name="no", in="query", @OA\Schema(type="string"), required=false, description="no"),
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response(
* response="200",
* description="暂无"
* )
* )
*/
public function pay()
{
$all = \request()->all();
$messages = [
'no.required' => 'no必填',
];
$validator = Validator::make($all, [
'no' => 'required',
], $messages);
if ($validator->fails()) {
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
}
$courseSign = CourseSign::where('no', $all['no'])->first();
if (!$courseSign) {
return $this->fail([ResponseCode::ERROR_PARAMETER, '订单不存在']);
}
$course = Course::find($courseSign->course_id);
if ($course->fee_type != 2) {
return $this->fail([ResponseCode::ERROR_PARAMETER, '支付类型错误']);
}
// 下单
$config = [
'app_id' => config('app.applet_appid'),
'mch_id' => config('app.applet_mch_id'),
'key' => config('app.applet_key')
];
$app = Factory::payment($config);
$result = $app->order->unify([
'trade_type' => 'NATIVE',
'product_id' => $courseSign->no,
'body' => $courseSign->title,
'out_trade_no' => $courseSign->no,
'total_fee' => $courseSign->money * 100,
'notify_url' => getDomain() . '/api/mobile/course/pay_callback',
]);
return $this->success(compact('result'));
}
public function payCallback()
{
$config = [
'app_id' => config('app.applet_appid'),
'mch_id' => config('app.applet_mch_id'),
'key' => config('app.applet_key')
];
// 获取支付参数
$app = Factory::payment($config);
$response = $app->handlePaidNotify(function ($message, $fail) {
if ($message['return_code'] === 'SUCCESS') {
if ($message['result_code'] === 'SUCCESS') {
$order = CourseSign::where('no', $message['out_trade_no'])->first();
if ($order) {
$order->fee_status = 1;
$order->save();
}
return true;
}
} else {
return $fail('通信失败,请稍后再通知我');
}
return true; // 返回处理完成
});
$response->send();
}
}

@ -4,8 +4,11 @@ use Illuminate\Support\Facades\Facade;
return [
'applet_appid' => env('APPLET_APPID', 'wx55e93f19273ad0a0'),
'applet_secret' => env('APPLET_SECRET', '0510e8239277b49881818b77de18a9d2'),
'applet_appid' => env('APPLET_APPID', ''),
'applet_secret' => env('APPLET_SECRET', ''),
'applet_mch_id' => env('APPLET_MCH_ID', ''),
'applet_key' => env('APPLET_KEY', ''),
'sms_appid' => env('SMS_APPID', 'EUCP-EMY-SMS1-4UWZZ'),
'sms_secretKey' => env('SMS_SECRETKEY', '431BD4F22D176233'),

@ -205,6 +205,8 @@ Route::group(["namespace" => "Mobile", "prefix" => "mobile"], function () {
Route::get('course/news', [\App\Http\Controllers\Mobile\CourseController::class, "news"]);
// 新闻详情
Route::get('course/news-detail', [\App\Http\Controllers\Mobile\CourseController::class, "newsDetail"]);
// 支付回调
Route::any('course/pay_callback', [\App\Http\Controllers\Mobile\CourseController::class, "payCallback"]);
Route::group(['middleware' => ['sanctum.jwt:mobile']], function () {
// 其他
Route::post('upload-file', [\App\Http\Controllers\Mobile\UploadController::class, "uploadFile"]);
@ -225,6 +227,9 @@ Route::group(["namespace" => "Mobile", "prefix" => "mobile"], function () {
Route::get('course/my-course-content', [\App\Http\Controllers\Mobile\CourseController::class, "myCourseContent"]);
Route::get('course/get-sign', [\App\Http\Controllers\Mobile\CourseController::class, "getSign"]);
Route::post('course/update-sign', [\App\Http\Controllers\Mobile\CourseController::class, "updateSign"]);
// 获取缴费二维码
Route::get('course/pay', [\App\Http\Controllers\Mobile\CourseController::class, "pay"]);
Route::get('course/contents', [\App\Http\Controllers\Mobile\CourseController::class, "contents"]);
Route::get('course/user-list', [\App\Http\Controllers\Mobile\CourseController::class, "userList"]);

Loading…
Cancel
Save