My.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace addons\cms\controller\api;
  3. use addons\cms\model\Comment;
  4. use addons\cms\model\Page;
  5. /**
  6. * 我的
  7. */
  8. class My extends Base
  9. {
  10. protected $noNeedLogin = ['aboutus', 'agreement'];
  11. /**
  12. * 我发表的评论
  13. */
  14. public function comment()
  15. {
  16. $commentList = Comment::with('archives')
  17. ->where(['user_id' => $this->auth->id])
  18. ->order('id desc')
  19. ->paginate();
  20. foreach ($commentList as $index => $item) {
  21. $item->create_date = human_date($item->createtime);
  22. }
  23. $this->success('', ['commentList' => $commentList]);
  24. }
  25. /**
  26. * 我的消费订单
  27. */
  28. public function order(){
  29. $orderList = \addons\cms\model\Order::with(['archives'])->where('user_id', $this->auth->id)
  30. ->where('status', 'paid')
  31. ->order('id', 'desc')
  32. ->paginate(10, null);
  33. foreach($orderList as $item){
  34. $item->createtime = date('Y-m-d H:i:s',$item->createtime);
  35. }
  36. $this->success('', ['orderList' => $orderList]);
  37. }
  38. /**
  39. * 关于我们
  40. */
  41. public function aboutus()
  42. {
  43. $pageInfo = Page::getByDiyname('aboutus');
  44. if (!$pageInfo || $pageInfo['status'] != 'normal') {
  45. $this->error(__('单页未找到'));
  46. }
  47. $pageInfo = $pageInfo->toArray();
  48. unset($pageInfo['status'], $pageInfo['showtpl']);
  49. $this->success('', ['pageInfo' => $pageInfo]);
  50. }
  51. /**
  52. * 用户协议
  53. */
  54. public function agreement()
  55. {
  56. $pageInfo = Page::getByDiyname('agreement');
  57. if (!$pageInfo || $pageInfo['status'] != 'normal') {
  58. $this->error(__('单页未找到'));
  59. }
  60. $pageInfo = $pageInfo->toArray();
  61. unset($pageInfo['status'], $pageInfo['showtpl']);
  62. $this->success('', ['pageInfo' => $pageInfo]);
  63. }
  64. }