作者 xwp
1 个管道 的构建 通过 耗费 9 秒

推送调试

... ... @@ -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();
}
}
... ...
... ... @@ -5,6 +5,9 @@ namespace app\api\controller;
use app\common\controller\Api;
use fast\Random;
use think\Config;
use WeChat\Exceptions\InvalidResponseException;
use WeChat\Exceptions\LocalCacheException;
use WeMini\Newtmpl;
/**
... ... @@ -12,7 +15,7 @@ use think\Config;
*/
class Order extends Api
{
protected $noNeedLogin = ['notify'];
protected $noNeedLogin = ['notify','order_over'];
protected $noNeedRight = '*';
protected $config;
... ... @@ -196,4 +199,61 @@ class Order extends Api
}
/**
* 订单结束推送
*
* @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 order_over(){
$template = new Newtmpl(Config::get('weChat'));
$order = new \app\admin\model\Order();
$order = $order->where(['status'=>'success','end'=>['<',date('Y-m-d H:i:s'), 'notify'=> false]])->with('user')->select();
$notice = new \app\admin\model\UserNotice();
foreach ($order as $k){
$order = new \app\admin\model\Order();
$order->save(['status'=>'over','notify'=>true],['id'=>$k['id']]);
$insert = [
'user_id' => $k['id'],
'type' => 'order_over',
'content_id' => $k['id'],
'time' => date('Y-m-d H:i:s'),
];
$notice->insert($insert);
//小程序通知
$data = [
'touser' => $k['user']['openid'],
'template_id' => config('weChat.order_over_tmp'),
'form_id'=> $k['id'],
'page'=>'pages/classReserve/classReserve',
'data'=>[
"thing1" => ["value" => "维克猩球"],
"number2" => ["value" => "0"],
"name3" => ["value" => $k['user']['nickname']],
],
];
try {
$template->send($data);
} catch (InvalidResponseException $e) {
echo json_encode($e->getMessage());
} catch (LocalCacheException $e) {
}
}
$this->success();
}
}
... ...
此 diff 太大无法显示。