|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|