...
|
...
|
@@ -630,4 +630,74 @@ class Course extends Api |
|
|
|
|
|
$this->success('请求成功',$course);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 课程开始推送
|
|
|
*
|
|
|
* @ApiTitle (课程开始推送)
|
|
|
* @ApiSummary (课程开始推送)
|
|
|
* @ApiMethod (GET)
|
|
|
*
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturnParams (name="data", type="object", sample="{'prepay_id':'123','options':{},'order':{}}", description="扩展数据返回")
|
|
|
* @ApiReturn ({'code':'1','msg':'返回成功'})
|
|
|
*/
|
|
|
public function course_start(){
|
|
|
|
|
|
$template = new Newtmpl(Config::get('weChat'));
|
|
|
|
|
|
$setting = new \app\admin\model\CourseSetting();
|
|
|
$setting = $setting->where(['setting_key'=>'course_start'])->find();
|
|
|
if(empty($setting)){
|
|
|
$time = 3600;
|
|
|
}else{
|
|
|
$time = $setting['setting_value']*3600;
|
|
|
}
|
|
|
|
|
|
$courseStore = new \app\admin\model\CourseStore();
|
|
|
$courseStore = $courseStore->with(['store','course'])->where(['notify'=>false,'status'=>'confirmed','start' => ['<',date('Y-m-d H:i:s',time()+$time)] ])->select();
|
|
|
$notice = new \app\admin\model\UserNotice();
|
|
|
foreach ($courseStore as $k){
|
|
|
$courseStore = new \app\admin\model\CourseStore();
|
|
|
$courseStore->save(['notify'=>true],['id'=>$k['id']]);
|
|
|
$sign = new \app\admin\model\CourseSign();
|
|
|
$sign = $sign->with(['user','CourseStore'])->where(['course_store_id'=>$k['id']])->select();
|
|
|
foreach ($sign as $v){
|
|
|
|
|
|
$insert = [
|
|
|
'user_id' => $v['user_id'],
|
|
|
'type' => 'course_start',
|
|
|
'content_id' => $v['id'],
|
|
|
'time' => date('Y-m-d H:i:s'),
|
|
|
];
|
|
|
$notice->insert($insert);
|
|
|
|
|
|
//小程序通知
|
|
|
$data = [
|
|
|
'touser' => $v['user']['openid'],
|
|
|
'template_id' => config('weChat.course_start_tmp'),
|
|
|
'form_id'=> $v['id'],
|
|
|
'page'=>'pages/classReserve/classReserve',
|
|
|
'data'=>[
|
|
|
"thing2" => ["value" => $k['course']['name']],
|
|
|
"thing4" => ["value" => $k['store']['address']],
|
|
|
"date1" => ["value" => $v['CourseStore']['start']],
|
|
|
"name3" => ["value" => $v['user']['nickname']],
|
|
|
"thing5" => ["value" => "课程即将开始"],
|
|
|
],
|
|
|
];
|
|
|
|
|
|
try {
|
|
|
$template->send($data);
|
|
|
} catch (InvalidResponseException $e) {
|
|
|
echo json_encode($e->getMessage());
|
|
|
} catch (LocalCacheException $e) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$this->success();
|
|
|
}
|
|
|
} |
...
|
...
|
|