PromotionMonitor.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\store\controller;
  4. use app\api\model\PromotionMonitorStatistics as PromotionMonitorStatisticsModel;
  5. use app\store\model\PromotionMonitor as PromotionMonitorModel;
  6. /**
  7. * 推广监控
  8. *
  9. * Class PromotionMonitor
  10. * @package app\store\controller
  11. */
  12. class PromotionMonitor extends Controller
  13. {
  14. public function list()
  15. {
  16. $model = new PromotionMonitorModel;
  17. $list = $model->getList($this->request->param());
  18. return $this->renderSuccess(compact('list'));
  19. }
  20. /**
  21. * 刷新数据
  22. */
  23. public function refresh()
  24. {
  25. $date = date('Y-m-d');
  26. PromotionMonitorStatisticsModel::addData($date);
  27. return $this->renderSuccess();
  28. }
  29. /**
  30. * 详情
  31. * @param int $id
  32. * @return array
  33. */
  34. public function detail(int $id)
  35. {
  36. $model = new PromotionMonitorModel;
  37. $detail = $model->detail($id);
  38. return $this->renderSuccess(compact('detail'));
  39. }
  40. /**
  41. * 添加
  42. * @return array|string
  43. */
  44. public function add()
  45. {
  46. // 新增记录
  47. $model = new PromotionMonitorModel;
  48. $post = $this->postForm();
  49. if ($model->add($post)) {
  50. return $this->renderSuccess('添加成功');
  51. }
  52. return $this->renderError($model->getError() ?: '添加失败');
  53. }
  54. /**
  55. * 编辑
  56. * @param int $id
  57. * @return mixed
  58. */
  59. public function edit(int $id)
  60. {
  61. // 详情
  62. $model = PromotionMonitorModel::detail($id);
  63. // 更新记录
  64. if ($model->edit($this->postForm())) {
  65. return $this->renderSuccess('更新成功');
  66. }
  67. return $this->renderError($model->getError() ?: '更新失败');
  68. }
  69. }