123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace app\api\controller;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- use AlibabaCloud\Client\Exception\ServerException;
- use think\Db;
- /**
- * @title 定时任务
- * Class Timedtask
- * @controller Timedtask
- * @group base
- */
- class Timedtask
- {
- /**
- * @title 定时取消订单
- * @desc 定时取消订单
- * @author qc
- * @url /api/Timedtask/cancelOrder
- * @method GET
- */
- public function cancelOrder()
- {
- $sel_time = time() - 900;// 十五分钟内未支付的自动取消
- $order_list = Db::table('ticket_order')
- ->field('id,s_id,total_num')
- ->where(['pay_state'=>0,'cancel_state'=>0])
- ->where('create_tamp','<',$sel_time)
- ->select();
- foreach ($order_list as $order_info)
- {
- Db::startTrans();
- try {
- Db::table('ticket_order')
- ->where(['id'=>$order_info['id']])
- ->update(['cancel_state'=>1,'cancel_at'=>date('Y-m-d H:i:s'),'cancel_desc'=>'支付超时!自动取消']);
- Db::table('film_info')->where('id', $order_info['s_id'])
- ->setInc('surplus_num', $order_info['total_num']);//增加场次余票
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- }
- }
- }
- /**
- * @title 电影开场前(30分钟)定时发送消息提醒
- * @desc 电影开场前(30分钟)定时发送消息提醒
- * @author qc
- * @url /api/Timedtask/sendMessage
- * @method GET
- */
- public function sendMessage()
- {
- $order_list = Db::table('ticket_order')
- ->alias('o')
- ->field('o.id,o.s_id,o.tel,l.name,f.show_time')
- ->join('film_info f','o.s_id = f.id','LEFT')
- ->join('film_list l','o.f_id = l.id','LEFT')
- ->where(['o.pay_state'=>1,'o.is_remind'=>1,'o.has_remind'=>0,])
- ->where('show_time','< time',date("Y-m-d H:i:s",time() + 1800))
- ->select();
- AlibabaCloud::accessKeyClient('LTAI5tKATi9QpdtaBpEHeCP4', 'F8B77fPPitlfRScTuPmQxfphLRpt6a')
- ->regionId('cn-hangzhou')->asDefaultClient();
- foreach ($order_list as $order_info)
- {
- if(!$order_info['tel'] || strlen($order_info['tel']) != 11) continue;
- $result = AlibabaCloud::rpc()->product('Dysmsapi')->version('2017-05-25')
- ->action('SendSms')->method('POST')->host('dysmsapi.aliyuncs.com')
- ->options([
- 'query' => [
- 'RegionId' => "cn-hangzhou",
- 'PhoneNumbers' => $order_info['tel'],
- 'SignName' => "火星帝界",
- 'TemplateCode' => "SMS_223197414",
- 'TemplateParam' => json_encode(['film_name'=>$order_info['name'],'show_time'=>$order_info['show_time']]),
- ],
- ])->request();
- $result = $result->toArray();
- if($result['Code'] == "OK") {
- Db::table('ticket_order')->where(['id'=>$order_info['id']])->update(['has_remind'=>1]);
- }
- }
- }
- }
|