PageLink.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\system\diy;
  12. use app\common\repositories\article\ArticleRepository;
  13. use app\common\repositories\store\StoreActivityRepository;
  14. use app\common\repositories\store\StoreCategoryRepository;
  15. use app\common\repositories\system\diy\DiyRepository;
  16. use app\common\repositories\system\diy\PageLinkRepository;
  17. use app\common\repositories\system\groupData\GroupDataRepository;
  18. use app\common\repositories\system\merchant\MerchantRepository;
  19. use app\common\repositories\system\diy\PageCategoryRepository;
  20. use crmeb\basic\BaseController;
  21. use think\App;
  22. /**
  23. * 页面链接
  24. */
  25. class PageLink extends BaseController
  26. {
  27. protected $repository;
  28. public function __construct(App $app, PageLinkRepository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. }
  33. /**
  34. * 列表
  35. * @return \think\response\Json
  36. * @author Qinii
  37. */
  38. public function lst()
  39. {
  40. [$page, $limit] = $this->getPage();
  41. //$where = $this->request->params([['status',1]]);
  42. $where['is_mer'] = $this->request->param('type', 0);
  43. return app('json')->success($this->repository->getList($where, $page, $limit));
  44. }
  45. /**
  46. * 添加表单
  47. * @return \think\response\Json
  48. * @author Qinii
  49. */
  50. public function createForm()
  51. {
  52. $isMer = $this->request->param('type', 0);
  53. return app('json')->success(formToData($this->repository->form(0, $isMer)));
  54. }
  55. /**
  56. * 添加
  57. * @return \think\response\Json
  58. * @author Qinii
  59. */
  60. public function create()
  61. {
  62. $data = $this->request->params([
  63. 'cate_id',
  64. 'name',
  65. 'url',
  66. 'param',
  67. 'example',
  68. 'status',
  69. 'sort',
  70. ]);
  71. $data['is_mer'] = $this->request->param('type', 0);
  72. $this->repository->create($data);
  73. return app('json')->success('添加成功');
  74. }
  75. /**
  76. * 修改表单
  77. * @param $id
  78. * @return \think\response\Json
  79. * @author Qinii
  80. */
  81. public function updateForm($id)
  82. {
  83. $isMer = $this->request->param('type', 0);
  84. return app('json')->success(formToData($this->repository->form($id, $isMer)));
  85. }
  86. /**
  87. * 修改
  88. * @param $id
  89. * @return \think\response\Json
  90. * @author Qinii
  91. */
  92. public function update($id)
  93. {
  94. if (!$this->repository->existsWhere(['id' => $id]))
  95. return app('json')->fail('数据不存在');
  96. $data = $this->request->params([
  97. 'cate_id',
  98. 'name',
  99. 'url',
  100. 'param',
  101. 'example',
  102. 'status',
  103. 'sort',
  104. ]);
  105. $this->repository->update($id, $data);
  106. return app('json')->success('编辑成功');
  107. }
  108. /**
  109. * 获取页面链接
  110. * @param $cate_id
  111. * @return mixed
  112. */
  113. public function getLinks($id, PageCategoryRepository $pageCategoryServices)
  114. {
  115. if (!$id) return app('json')->fail('缺少参数');
  116. $category = $pageCategoryServices->get((int)$id);
  117. if (!$category) {
  118. return app('json')->fail('页面分类不存在');
  119. }
  120. $type = $this->request->param('type', 0);
  121. [$page, $limit] = $this->getPage();
  122. switch ($category['type']) {
  123. case 'special':
  124. $diyServices = app()->make(ArticleRepository::class);
  125. $data = $diyServices->search(0, ['status' => 1], $page, $limit);
  126. break;
  127. case 'product_category':
  128. $storeCategoryServices = app()->make(StoreCategoryRepository::class);
  129. $data = $storeCategoryServices->getApiFormatList($this->request->merId(), 1);
  130. break;
  131. case 'merchant':
  132. $data = app()->make(MerchantRepository::class)->lst(['mer_state' => 1, 'status' => 1], $page, $limit);
  133. break;
  134. case 'active':
  135. $groupid = $this->request->merId() ? 95 : 94;
  136. $query = app()->make(GroupDataRepository::class)
  137. ->getGroupDataWhere($this->request->merId(), $groupid)
  138. ->where('status', 1);
  139. $data['count'] = $query->count();
  140. $data['list'] = $query->page($page, $limit)->select()->toArray();
  141. break;
  142. case 'points_cate':
  143. $storeCategoryServices = app()->make(StoreCategoryRepository::class);
  144. $data = $storeCategoryServices->getApiFormatList($this->request->merId(), 1, 1);
  145. break;
  146. case 'micro':
  147. $data = app()->make(DiyRepository::class)->getList(['is_diy' => 0], $page, $limit);
  148. break;
  149. case 'activity_form': //报名活动
  150. $where['activity_type'] = StoreActivityRepository::ACTIVITY_TYPE_FORM;
  151. $where['status'] = 1;
  152. $where['is_show'] = 1;
  153. $data = app()->make(StoreActivityRepository::class)->getList($where, $page, $limit);
  154. break;
  155. default:
  156. $data = $this->repository->getLinkList($id, $type == 1 ? 1 : $this->request->merId());
  157. break;
  158. }
  159. return app('json')->success($data);
  160. }
  161. /**
  162. * 删除链接
  163. * @param $id
  164. * @return mixed
  165. */
  166. public function delete($id)
  167. {
  168. if (!$id) return app('json')->fail('参数错误');
  169. if (!$this->repository->existsWhere(['id' => $id]))
  170. return app('json')->fail('数据不存在');
  171. $this->repository->delete($id);
  172. return app('json')->success('删除成功!');
  173. }
  174. /**
  175. * 状态修改
  176. * @param $id
  177. * @return \think\response\Json
  178. * @author Qinii
  179. */
  180. public function switchStatus($id)
  181. {
  182. $status = $this->request->param('status') == 1 ? 1 : 0;
  183. $this->repository->update($id, ['status' => $status]);
  184. return app('json')->success('修改成功');
  185. }
  186. }