Subscribe.php 975 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\TemplateMsg;
  4. use app\common\model\SubscribeLog;
  5. /**
  6. * 小程序订阅
  7. */
  8. class Subscribe extends Base
  9. {
  10. protected $noNeedLogin = [];
  11. //用户订阅的记录
  12. public function index()
  13. {
  14. $tpl_ids = $this->request->post('tpl_ids/a');
  15. $order_sn = $this->request->post('order_sn');
  16. if (!$order_sn || empty($tpl_ids)) {
  17. $this->error('参数错误,订阅失败');
  18. }
  19. $ids = TemplateMsg::getTplIds();
  20. $data = [];
  21. foreach ($tpl_ids as $key => $item) {
  22. if (in_array($key, $ids)) {
  23. $data[] = [
  24. 'tpl_id' => $key,
  25. 'user_id' => $this->auth->id,
  26. 'order_sn' => $order_sn,
  27. 'status' => 0
  28. ];
  29. }
  30. }
  31. (new SubscribeLog())->saveAll($data);
  32. $this->success('订阅消息成功!');
  33. }
  34. }