123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace app\api\controller;
- use app\admin\model\Method;
- use app\admin\model\Order;
- use app\admin\model\UserSubscribeMessage;
- use app\common\controller\Api;
- use think\Db;
- class Notification extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function dingyuexiaoxi($type,$tuijian,$yutang_name,$fish,$price,$moshi,$yutang_city,$user_id){
- $user_message_model = new UserSubscribeMessage();
- $message_model = new \app\admin\model\Message();
- $user_model = new \app\admin\model\User();
- $sms_number = $user_model->where('id',$user_id)->value('sms_number');
- if($type==1){
- $type_name = '路亚';
- }
- else{$type_name='手杆';}
- if($moshi==1){
- $moshi_name = '欢乐模式';
- }
- if($moshi==2){
- $moshi_name = '黑坑捡漏';
- }
- if($moshi==3){
- $moshi_name='黑坑正钓';
- }
- $name = $yutang_name.$type_name.$moshi_name;
- if($type == 1){
- $user_info = $user_message_model->alias('m')->join('user u','u.id=m.user_id')->where('u.city',$yutang_city)->where('m.lua',1)->field('m.*,u.mobile')->select();
- }
- else{
- $user_info = $user_message_model->alias('m')->join('user u','u.id=m.user_id')->where('u.city',$yutang_city)->where('hand_bar',1)->field('m.*,u.mobile')->select();
- }
- if($tuijian==2){
- if($sms_number>count($user_info)){
- $user_model->isUpdate('true',['id'=>$user_id])->save(['sms_number'=>$sms_number-count($user_info)]);
- }
- else{
- $this->error('短信包数量不足');
- }
- }
- foreach ($user_info as &$v){
- $message_data = [
- 'category_id'=>2,
- 'user_id'=>$v['user_id'],
- 'title'=>$name,
- 'name'=>$yutang_name,
- 'description'=>$yutang_name.'发布了'.$type_name.$moshi_name,
- 'is_read'=>1,
- 'createtime'=>time(),
- ];
- $message_model->insert($message_data);
- if($tuijian==2) {
- $sms_model = new Sms();
- $sms_model->dainyue_xiaoxi($v['mobile'], $yutang_name, $fish, $price, $moshi_name);
- }
- }
- }
- public function order_tongzhi(){
- $order_model = new Order();
- $message_model = new \app\admin\model\Message();
- $user_model = new \app\admin\model\User();
- $writeoff_model = new Writeoff();
- $sms_model =new Sms();
- $time = date('H:i');
- $order_list = $order_model->where('status',2)->select();
- foreach ($order_list as &$v){
- $user_info =$user_model->where('id',$v['t_user_id'])->field('sms_number,duanxin')->find();
- if($time>$v['end']) {//执行退款发送信息
- $type = 'wechat';
- if($v['pay_type']=='支付宝支付'){
- $type = 'alipay';
- }
- $re = $writeoff_model->refund_order($v['order_money'],$v['order_no'],$type);
- if($re) {
- if ($user_info['sms_number'] > 0 && $user_info['duanxin'] == 1) {
- $sms_model->order_guoshi($v['phone'], $v['order_no'], $v['order_money'], $v['t_user_id']);
- $num = $user_info['sms_number']-1;
- $user_model->isUpdate('true', ['id' => $v['t_user_id']])->save(['sms_number' =>$num ]);
- }
- if ($v['type'] == 1) {
- $type_name = '路亚';
- } else {
- $type_name = '手杆';
- }
- if ($v['moshi'] == 1) {
- $moshi_name = '欢乐模式';
- }
- if ($v['moshi'] == 2) {
- $moshi_name = '黑坑捡漏';
- }
- if ($v['moshi'] == 3) {
- $moshi_name = '黑坑正钓';
- }
- $name = $v['yutang'] . $type_name . $moshi_name;
- $message_data = [
- 'category_id' => 2,
- 'user_id' => $v['user_id'],
- 'title' => $name,
- 'order_id' => $v['id'],
- 'name' => $v['yutang'],
- 'description' => '尊敬的用户,您的' . $v['order_no'] . ' ,订单超时未核销,' . $v['order_money'] . '元商家已退款至您的支付账户',
- 'is_read' => 1,
- 'createtime' => time(),];
- $message_model->insert($message_data);
- $order_model->isUpdate('true', ['id' => $v['id']])->save(['status' =>7 ]);
- }
- }
- }
- }
- public function sta_order(){
- $date = date('Y-m-d');
- $time = time();
- $order_model = new Order();
- $message_model = new \app\admin\model\Message();
- $user_model = new \app\admin\model\User();
- $sms_model =new Sms();
- $order_list = $order_model->where('status',2)->where('is_send',1)->select();
- foreach ($order_list as &$v) {
- $now = strtotime($date . $v['sta'] . ':00');
- $tixing = $now-$time;
- if ($tixing <= 1800) {
- $user_info = $user_model->where('id', $v['t_user_id'])->field('sms_number,duanxin')->find();
- $sms_date = $date.$v['sta'].'00';
- if ($user_info['sms_number'] > 0 && $user_info['duanxin'] == 1) {
- $sms_model->order_sta($v['phone'], $sms_date, $v['t_user_id']);
- $num = $user_info['sms_number']-1;
- $user_model->isUpdate('true', ['id' => $v['t_user_id']])->save(['sms_number' =>$num ]);
- }
- $message_data = [
- 'category_id' => 2,
- 'user_id' => $v['user_id'],
- 'title' => '订单消息',
- 'order_id' => $v['id'],
- 'name' => $v['yutang'],
- 'description' => '尊敬的用户,您的订单开始时间为'.$sms_date.',请合理安排时间',
- 'is_read' => 1,
- 'createtime' => time(),];
- $message_model->insert($message_data);
- }
- $order_model->isUpdate('true', ['id' => $v['id']])->save(['is_send' =>2 ]);
- }
- }
- public function end_order(){
- $date = date('Y-m-d');
- $time = time();
- $order_model = new Order();
- $message_model = new \app\admin\model\Message();
- $user_model = new \app\admin\model\User();
- $sms_model =new Sms();
- $order_list = $order_model->where('status',2)->where('is_sendd',1)->select();
- foreach ($order_list as &$v) {
- $now = strtotime($date . $v['end'] . ':00');
- $tixing = $now-$time;
- if ($tixing <= 1800) {
- $user_info = $user_model->where('id', $v['t_user_id'])->field('sms_number,duanxin')->find();
- $sms_date = $date.$v['end'].'00';
- if ($user_info['sms_number'] > 0 && $user_info['duanxin'] == 1) {
- $sms_model->order_end($v['phone'], $sms_date, $v['t_user_id']);
- $num = $user_info['sms_number']-1;
- $user_model->isUpdate('true', ['id' => $v['t_user_id']])->save(['sms_number' =>$num ]);
- }
- $message_data = [
- 'category_id' => 2,
- 'user_id' => $v['user_id'],
- 'title' => '订单消息',
- 'order_id' => $v['id'],
- 'name' => $v['yutang'],
- 'description' => '尊敬的用户,您的订单结束时间为'.$sms_date.',请合理安排时间',
- 'is_read' => 1,
- 'createtime' => time(),];
- $message_model->insert($message_data);
- }
- $order_model->isUpdate('true', ['id' => $v['id']])->save(['is_sendd' =>2 ]);
- }
- }
- public function method_time(){
- $method_model= new Method();
- $date_time = time();
- $method_list= $method_model->where('status',1)->whereIn('moshi','2,3')->select();
- foreach ($method_list as &$v){
- $time = $date_time-$v['createtime'];
- if($time>48*60*60){
- Db::name('method')->where('id',$v['id'])->update(['status'=>2]);
- }
- }
- }
- }
|