MobileTypes.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 MobileTypes 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)->paginate(['list_rows'=> $rows]);
  34. return $list;
  35. } catch(\Exception $e) {
  36. return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
  37. }
  38. }
  39. /**
  40. * 添加数据
  41. * @param $param
  42. */
  43. public function add($param)
  44. {
  45. $insertId = 0;
  46. try {
  47. $param['create_time'] = time();
  48. $insertId = self::strict(false)->field(true)->insertGetId($param);
  49. //自动为系统超级管理员角色组分配新增的节点
  50. $group = Db::name('AdminGroup')->find(1);
  51. if (!empty($group)) {
  52. $newGroup['id'] = 1;
  53. $newGroup['mobile_menu'] = $group['mobile_menu'] . ',' . $insertId;
  54. Db::name('AdminGroup')->strict(false)->field(true)->update($newGroup);
  55. }
  56. add_log('add', $insertId, $param);
  57. } catch(\Exception $e) {
  58. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  59. }
  60. clear_cache('MobileRules');
  61. return to_assign(0,'操作成功',['return_id'=>$insertId]);
  62. }
  63. /**
  64. * 编辑信息
  65. * @param $param
  66. */
  67. public function edit($param)
  68. {
  69. try {
  70. $param['update_time'] = time();
  71. self::where('id', $param['id'])->strict(false)->field(true)->update($param);
  72. add_log('edit', $param['id'], $param);
  73. } catch(\Exception $e) {
  74. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  75. }
  76. clear_cache('MobileRules');
  77. return to_assign(0,'操作成功',['return_id'=>$param['id']]);
  78. }
  79. /**
  80. * 根据id获取信息
  81. * @param $id
  82. */
  83. public function getById($id)
  84. {
  85. $info = self::find($id);
  86. return $info;
  87. }
  88. /**
  89. * 删除信息
  90. * @param $id
  91. * @param $type
  92. * @return array
  93. */
  94. public function delById($id,$type=0)
  95. {
  96. if($type==0){
  97. //逻辑删除
  98. try {
  99. $param['delete_time'] = time();
  100. self::where('id', $id)->update(['delete_time'=>time()]);
  101. add_log('delete', $id);
  102. } catch(\Exception $e) {
  103. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  104. }
  105. }
  106. else{
  107. //物理删除
  108. try {
  109. self::destroy($id);
  110. add_log('delete', $id);
  111. } catch(\Exception $e) {
  112. return to_assign(1, '操作失败,原因:'.$e->getMessage());
  113. }
  114. }
  115. clear_cache('MobileRules');
  116. return to_assign();
  117. }
  118. }