AssetAreaLists.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\asset;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\enum\asset\AssetEnum;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\article\Article;
  19. use app\common\model\notice\NoticeSetting;
  20. use app\common\model\asset\AssetInfo;
  21. use app\common\model\asset\AssetArea;
  22. use app\common\service\FileService;
  23. /**
  24. * 地址管理
  25. * Class AssetLists
  26. * @package app\adminapi\lists\asset
  27. */
  28. class AssetAreaLists extends BaseAdminDataLists implements ListsSearchInterface
  29. {
  30. /**
  31. * @notes 搜索条件
  32. * @return \string[][]
  33. * @author
  34. * @date 2025/04/12 2:21 下午
  35. */
  36. public function setSearch(): array
  37. {
  38. return [
  39. '=' => [ 'status'],
  40. '%like%'=>['title'],
  41. ];
  42. }
  43. /**
  44. * @notes 地址信息列表
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @author ljj
  50. * @date 2022/2/16 3:18 下午
  51. */
  52. public function lists(): array
  53. {
  54. $lists = (new AssetArea())->field('id,id value ,title , title label,level,pid,create_time')
  55. ->where($this->searchWhere)
  56. ->limit($this->limitOffset, $this->limitLength)
  57. ->Order('sort desc')
  58. ->select()
  59. ->toArray();
  60. if($this->params['is_tree'] ==1){
  61. $treeList = linear_to_tree($lists, 'children');
  62. if (empty($treeList) && !empty($lists)) {
  63. foreach ($lists as &$v) {
  64. $v['children'] = [];
  65. }
  66. return $lists;
  67. }
  68. return $treeList;
  69. }else{
  70. return $lists;
  71. }
  72. //
  73. }
  74. /**
  75. * @notes 地址信息数量
  76. * @return int
  77. * @author ljj
  78. * @date 2022/2/16 3:18 下午
  79. */
  80. public function count(): int
  81. {
  82. return (new AssetArea())->where($this->searchWhere)->count();
  83. }
  84. /**
  85. * @notes 添加地址
  86. * @param array $params
  87. * @author heshihu
  88. * @date 2022/2/22 9:57
  89. */
  90. public static function add(array $params)
  91. {
  92. $pid = $params['pid'];
  93. $level = 1;
  94. $pidInfo = AssetArea::find($pid);
  95. if(!empty($pidInfo)){
  96. $level = $pidInfo['level'] + 1;
  97. }
  98. AssetArea::create([
  99. 'title' => $params['title'],
  100. 'level' => $level,
  101. 'pid' => $pid,
  102. 'sort' => $params['sort']??0
  103. ]);
  104. }
  105. /**
  106. * @notes 编辑地址
  107. * @param array $params
  108. * @return bool
  109. * @author heshihu
  110. * @date 2022/2/22 10:12
  111. */
  112. public static function edit(array $params) : bool
  113. {
  114. try {
  115. AssetArea::update([
  116. 'id' => $params['id'],
  117. 'title' => $params['title'],
  118. 'sort' => $params['sort']??0
  119. ]);
  120. return true;
  121. } catch (\Exception $e) {
  122. self::setError($e->getMessage());
  123. return false;
  124. }
  125. }
  126. /**
  127. * @notes 删除地址
  128. * @param array $params
  129. * @author heshihu
  130. * @date 2022/2/22 10:17
  131. */
  132. public static function delete(array $params)
  133. {
  134. AssetArea::destroy($params['id']);
  135. }
  136. /**
  137. * @notes 查看地址详情
  138. * @param $params
  139. * @return array
  140. * @author heshihu
  141. * @date 2022/2/22 10:15
  142. */
  143. public static function detail($params) : array
  144. {
  145. return AssetArea::findOrEmpty($params['id'])->toArray();
  146. }
  147. public static function updateStatus(array $params)
  148. {
  149. AssetArea::update([
  150. 'id' => $params['id'],
  151. 'status' => $params['status']
  152. ]);
  153. return true;
  154. }
  155. }