Notification.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\Method;
  4. use app\admin\model\Order;
  5. use app\admin\model\UserSubscribeMessage;
  6. use app\common\controller\Api;
  7. use think\Db;
  8. class Notification extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. public function dingyuexiaoxi($type,$tuijian,$yutang_name,$fish,$price,$moshi,$yutang_city,$user_id){
  13. $user_message_model = new UserSubscribeMessage();
  14. $message_model = new \app\admin\model\Message();
  15. $user_model = new \app\admin\model\User();
  16. $sms_number = $user_model->where('id',$user_id)->value('sms_number');
  17. if($type==1){
  18. $type_name = '路亚';
  19. }
  20. else{$type_name='手杆';}
  21. if($moshi==1){
  22. $moshi_name = '欢乐模式';
  23. }
  24. if($moshi==2){
  25. $moshi_name = '黑坑捡漏';
  26. }
  27. if($moshi==3){
  28. $moshi_name='黑坑正钓';
  29. }
  30. $name = $yutang_name.$type_name.$moshi_name;
  31. if($type == 1){
  32. $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();
  33. }
  34. else{
  35. $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();
  36. }
  37. if($tuijian==2){
  38. if($sms_number>count($user_info)){
  39. $user_model->isUpdate('true',['id'=>$user_id])->save(['sms_number'=>$sms_number-count($user_info)]);
  40. }
  41. else{
  42. $this->error('短信包数量不足');
  43. }
  44. }
  45. foreach ($user_info as &$v){
  46. $message_data = [
  47. 'category_id'=>2,
  48. 'user_id'=>$v['user_id'],
  49. 'title'=>$name,
  50. 'name'=>$yutang_name,
  51. 'description'=>$yutang_name.'发布了'.$type_name.$moshi_name,
  52. 'is_read'=>1,
  53. 'createtime'=>time(),
  54. ];
  55. $message_model->insert($message_data);
  56. if($tuijian==2) {
  57. $sms_model = new Sms();
  58. $sms_model->dainyue_xiaoxi($v['mobile'], $yutang_name, $fish, $price, $moshi_name);
  59. }
  60. }
  61. }
  62. public function order_tongzhi(){
  63. $order_model = new Order();
  64. $message_model = new \app\admin\model\Message();
  65. $user_model = new \app\admin\model\User();
  66. $writeoff_model = new Writeoff();
  67. $sms_model =new Sms();
  68. $time = date('H:i');
  69. $order_list = $order_model->where('status',2)->select();
  70. foreach ($order_list as &$v){
  71. $user_info =$user_model->where('id',$v['t_user_id'])->field('sms_number,duanxin')->find();
  72. if($time>$v['end']) {//执行退款发送信息
  73. $type = 'wechat';
  74. if($v['pay_type']=='支付宝支付'){
  75. $type = 'alipay';
  76. }
  77. $re = $writeoff_model->refund_order($v['order_money'],$v['order_no'],$type);
  78. if($re) {
  79. if ($user_info['sms_number'] > 0 && $user_info['duanxin'] == 1) {
  80. $sms_model->order_guoshi($v['phone'], $v['order_no'], $v['order_money'], $v['t_user_id']);
  81. $num = $user_info['sms_number']-1;
  82. $user_model->isUpdate('true', ['id' => $v['t_user_id']])->save(['sms_number' =>$num ]);
  83. }
  84. if ($v['type'] == 1) {
  85. $type_name = '路亚';
  86. } else {
  87. $type_name = '手杆';
  88. }
  89. if ($v['moshi'] == 1) {
  90. $moshi_name = '欢乐模式';
  91. }
  92. if ($v['moshi'] == 2) {
  93. $moshi_name = '黑坑捡漏';
  94. }
  95. if ($v['moshi'] == 3) {
  96. $moshi_name = '黑坑正钓';
  97. }
  98. $name = $v['yutang'] . $type_name . $moshi_name;
  99. $message_data = [
  100. 'category_id' => 2,
  101. 'user_id' => $v['user_id'],
  102. 'title' => $name,
  103. 'order_id' => $v['id'],
  104. 'name' => $v['yutang'],
  105. 'description' => '尊敬的用户,您的' . $v['order_no'] . ' ,订单超时未核销,' . $v['order_money'] . '元商家已退款至您的支付账户',
  106. 'is_read' => 1,
  107. 'createtime' => time(),];
  108. $message_model->insert($message_data);
  109. $order_model->isUpdate('true', ['id' => $v['id']])->save(['status' =>7 ]);
  110. }
  111. }
  112. }
  113. }
  114. public function sta_order(){
  115. $date = date('Y-m-d');
  116. $time = time();
  117. $order_model = new Order();
  118. $message_model = new \app\admin\model\Message();
  119. $user_model = new \app\admin\model\User();
  120. $sms_model =new Sms();
  121. $order_list = $order_model->where('status',2)->where('is_send',1)->select();
  122. foreach ($order_list as &$v) {
  123. $now = strtotime($date . $v['sta'] . ':00');
  124. $tixing = $now-$time;
  125. if ($tixing <= 1800) {
  126. $user_info = $user_model->where('id', $v['t_user_id'])->field('sms_number,duanxin')->find();
  127. $sms_date = $date.$v['sta'].'00';
  128. if ($user_info['sms_number'] > 0 && $user_info['duanxin'] == 1) {
  129. $sms_model->order_sta($v['phone'], $sms_date, $v['t_user_id']);
  130. $num = $user_info['sms_number']-1;
  131. $user_model->isUpdate('true', ['id' => $v['t_user_id']])->save(['sms_number' =>$num ]);
  132. }
  133. $message_data = [
  134. 'category_id' => 2,
  135. 'user_id' => $v['user_id'],
  136. 'title' => '订单消息',
  137. 'order_id' => $v['id'],
  138. 'name' => $v['yutang'],
  139. 'description' => '尊敬的用户,您的订单开始时间为'.$sms_date.',请合理安排时间',
  140. 'is_read' => 1,
  141. 'createtime' => time(),];
  142. $message_model->insert($message_data);
  143. }
  144. $order_model->isUpdate('true', ['id' => $v['id']])->save(['is_send' =>2 ]);
  145. }
  146. }
  147. public function end_order(){
  148. $date = date('Y-m-d');
  149. $time = time();
  150. $order_model = new Order();
  151. $message_model = new \app\admin\model\Message();
  152. $user_model = new \app\admin\model\User();
  153. $sms_model =new Sms();
  154. $order_list = $order_model->where('status',2)->where('is_sendd',1)->select();
  155. foreach ($order_list as &$v) {
  156. $now = strtotime($date . $v['end'] . ':00');
  157. $tixing = $now-$time;
  158. if ($tixing <= 1800) {
  159. $user_info = $user_model->where('id', $v['t_user_id'])->field('sms_number,duanxin')->find();
  160. $sms_date = $date.$v['end'].'00';
  161. if ($user_info['sms_number'] > 0 && $user_info['duanxin'] == 1) {
  162. $sms_model->order_end($v['phone'], $sms_date, $v['t_user_id']);
  163. $num = $user_info['sms_number']-1;
  164. $user_model->isUpdate('true', ['id' => $v['t_user_id']])->save(['sms_number' =>$num ]);
  165. }
  166. $message_data = [
  167. 'category_id' => 2,
  168. 'user_id' => $v['user_id'],
  169. 'title' => '订单消息',
  170. 'order_id' => $v['id'],
  171. 'name' => $v['yutang'],
  172. 'description' => '尊敬的用户,您的订单结束时间为'.$sms_date.',请合理安排时间',
  173. 'is_read' => 1,
  174. 'createtime' => time(),];
  175. $message_model->insert($message_data);
  176. }
  177. $order_model->isUpdate('true', ['id' => $v['id']])->save(['is_sendd' =>2 ]);
  178. }
  179. }
  180. public function method_time(){
  181. $method_model= new Method();
  182. $date_time = time();
  183. $method_list= $method_model->where('status',1)->whereIn('moshi','2,3')->select();
  184. foreach ($method_list as &$v){
  185. $time = $date_time-$v['createtime'];
  186. if($time>48*60*60){
  187. Db::name('method')->where('id',$v['id'])->update(['status'=>2]);
  188. }
  189. }
  190. }
  191. }