ActivityBackground.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\marketing\activityBackground;
  12. use app\controller\admin\AuthController;
  13. use app\services\activity\activityBackground\ActivityBackgroundServices;
  14. use think\facade\App;
  15. /**
  16. * 活动背景图
  17. * Class ActivityBackground
  18. * @package app\controller\admin\v1\marketing\activityBackground
  19. */
  20. class ActivityBackground extends AuthController
  21. {
  22. /**
  23. * ActivityBackground constructor.
  24. * @param App $app
  25. * @param ActivityBackgroundServices $services
  26. */
  27. public function __construct(App $app, ActivityBackgroundServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 显示资源列表
  34. *
  35. * @return \think\Response
  36. */
  37. public function index()
  38. {
  39. $where = $this->request->getMore([
  40. ['time', '', '', 'activity_time'],
  41. [['status', 's'], '', '', 'start_status'],
  42. [['name', 's'], ''],
  43. ['create_time', '', '', 'time']
  44. ]);
  45. $where['promotions_type'] = 6;
  46. $where['type'] = 1;
  47. $where['store_id'] = 0;
  48. $where['pid'] = 0;
  49. $where['is_del'] = 0;
  50. return $this->success($this->services->systemPage($where));
  51. }
  52. /**
  53. * 详情
  54. * @param $id
  55. * @return mixed
  56. */
  57. public function getInfo($id)
  58. {
  59. $info = $this->services->getInfo((int)$id);
  60. return $this->success(compact('info'));
  61. }
  62. /**
  63. * 保存促销活动
  64. * @param $id
  65. * @return mixed
  66. */
  67. public function save($id)
  68. {
  69. $data = $this->request->postMore([
  70. [['name', 's'], ''],//名称
  71. ['image', ''],//活动图
  72. [['product_partake_type', 'd'], 1],//商品参与类型
  73. ['product_id', []],//关联商品
  74. ['brand_id', []],//关联品牌ID
  75. ['store_label_id', []],//关联商品标签ID
  76. ['section_time', []],//时间
  77. ['status', 1],//状态
  78. [['sort', 'd'], 0],//排序
  79. ]);
  80. $data['promotions_type'] = 6;
  81. if (!$data['name']) {
  82. return $this->fail('请输入活动名称');
  83. }
  84. if (!$data['image']) {
  85. return $this->fail('请选择活动图');
  86. }
  87. if ($data['product_partake_type'] == 2 && !$data['product_id']) {
  88. return $this->fail('请选择要参与活动的商品');
  89. }
  90. if ($data['product_partake_type'] == 4 && !$data['brand_id']) {
  91. return $this->fail('请选择要参与活动的商品品牌');
  92. }
  93. if ($data['product_partake_type'] == 5 && !$data['store_label_id']) {
  94. return $this->fail('请选择要参与活动的商品标签');
  95. }
  96. $this->services->saveData((int)$id, $data);
  97. return $this->success('保存成功');
  98. }
  99. /**
  100. * 删除指定资源
  101. *
  102. * @param int $id
  103. * @return \think\Response
  104. */
  105. public function delete($id)
  106. {
  107. if (!$id) return $this->fail('缺少参数');
  108. $this->services->update(['id|pid' => $id], ['is_del' => 1]);
  109. return $this->success('删除成功!');
  110. }
  111. /**
  112. * 修改状态
  113. * @param $id
  114. * @param $status
  115. * @return mixed
  116. */
  117. public function setStatus($id, $status)
  118. {
  119. $this->services->update($id, ['status' => $status, 'update_time' => time()]);
  120. return $this->success($status == 0 ? '关闭成功' : '开启成功');
  121. }
  122. }