MobileMenu.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. namespace app\mobile\model;
  14. use think\model;
  15. use think\facade\Db;
  16. class MobileMenu extends Model
  17. {
  18. /**
  19. * 获取分页列表
  20. * @param $where
  21. * @param $param
  22. */
  23. public function datalist($param=[],$where=[],$whereOr=[])
  24. {
  25. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  26. $order = empty($param['order']) ? 'id desc' : $param['order'];
  27. try {
  28. $list = self::where($where)
  29. ->where(function ($query) use($whereOr) {
  30. if (!empty($whereOr)){
  31. $query->whereOr($whereOr);
  32. }
  33. })->order($order)
  34. ->paginate(['list_rows'=> $rows])
  35. ->each(function ($item, $key){
  36. $item->types_title = Db::name('MobileTypes')->where(['id' => $item->types])->value('title');
  37. });
  38. return $list;
  39. } catch(\Exception $e) {
  40. return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
  41. }
  42. }
  43. /**
  44. * 添加数据
  45. * @param $param
  46. */
  47. public function add($param)
  48. {
  49. $insertId = 0;
  50. try {
  51. $param['create_time'] = time();
  52. $insertId = self::strict(false)->field(true)->insertGetId($param);
  53. //自动为系统超级管理员角色组分配新增的节点
  54. $group = Db::name('AdminGroup')->find(1);
  55. if (!empty($group)) {
  56. $newGroup['id'] = 1;
  57. $newGroup['mobile_menu'] = $group['mobile_menu'] . ',' . $insertId;
  58. Db::name('AdminGroup')->strict(false)->field(true)->update($newGroup);
  59. }
  60. add_log('add', $insertId, $param);
  61. } catch(\Exception $e) {
  62. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  63. }
  64. clear_cache('MobileRules');
  65. return to_assign(0,'操作成功',['return_id'=>$insertId]);
  66. }
  67. /**
  68. * 编辑信息
  69. * @param $param
  70. */
  71. public function edit($param)
  72. {
  73. try {
  74. $param['update_time'] = time();
  75. self::where('id', $param['id'])->strict(false)->field(true)->update($param);
  76. add_log('edit', $param['id'], $param);
  77. } catch(\Exception $e) {
  78. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  79. }
  80. clear_cache('MobileRules');
  81. return to_assign(0,'操作成功',['return_id'=>$param['id']]);
  82. }
  83. /**
  84. * 根据id获取信息
  85. * @param $id
  86. */
  87. public function getById($id)
  88. {
  89. $info = self::find($id);
  90. return $info;
  91. }
  92. /**
  93. * 删除信息
  94. * @param $id
  95. * @param $type
  96. * @return array
  97. */
  98. public function delById($id,$type=0)
  99. {
  100. if($type==0){
  101. //逻辑删除
  102. try {
  103. $param['delete_time'] = time();
  104. self::where('id', $id)->update(['delete_time'=>time()]);
  105. add_log('delete', $id);
  106. } catch(\Exception $e) {
  107. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  108. }
  109. }
  110. else{
  111. //物理删除
  112. try {
  113. self::destroy($id);
  114. add_log('delete', $id);
  115. } catch(\Exception $e) {
  116. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  117. }
  118. }
  119. clear_cache('MobileRules');
  120. return to_assign();
  121. }
  122. }