Property.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. declare (strict_types = 1);
  14. namespace app\adm\controller;
  15. use app\base\BaseController;
  16. use app\adm\model\Property as PropertyModel;
  17. use app\adm\validate\PropertyCheck;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Property extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new PropertyModel();
  31. }
  32. public function datalist()
  33. {
  34. if (request()->isAjax()) {
  35. $param = get_params();
  36. $where = [];
  37. if (!empty($param['keywords'])) {
  38. $where[] = ['p.title', 'like', '%' . $param['keywords'] . '%'];
  39. }
  40. if (isset($param['status']) && $param['status']!='') {
  41. $where[] = ['p.status', '=', $param['status']];
  42. }
  43. else{
  44. $where[] = ['p.status','>=',0];
  45. }
  46. if (!empty($param['cate_id'])) {
  47. $cate_id_array = get_cate_son('PropertyCate',$param['cate_id']);
  48. $where[] = ['p.cate_id', 'in', $cate_id_array];
  49. }
  50. if (!empty($param['brand_id'])) {
  51. $where[] = ['p.brand_id', '=', $param['brand_id']];
  52. }
  53. $list = $this->model->datalist($where, $param);
  54. return table_assign(0, '', $list);
  55. } else {
  56. View::assign('status', $this->model::$property_status);
  57. return view();
  58. }
  59. }
  60. //新建编辑
  61. public function add()
  62. {
  63. $param = get_params();
  64. if (request()->isAjax()) {
  65. if (isset($param['buy_time'])) {
  66. $param['buy_time'] = strtotime($param['buy_time']);
  67. }
  68. if (isset($param['quality_time'])) {
  69. $param['quality_time'] = strtotime($param['quality_time']);
  70. }
  71. if (!empty($param['id']) && $param['id'] > 0) {
  72. try {
  73. validate(PropertyCheck::class)->scene('edit')->check($param);
  74. } catch (ValidateException $e) {
  75. // 验证失败 输出错误信息
  76. return to_assign(1, $e->getError());
  77. }
  78. $param['update_time'] = time();
  79. $param['update_id'] = $this->uid;
  80. $this->model->edit($param);
  81. } else {
  82. try {
  83. validate(PropertyCheck::class)->scene('add')->check($param);
  84. } catch (ValidateException $e) {
  85. // 验证失败 输出错误信息
  86. return to_assign(1, $e->getError());
  87. }
  88. $param['create_time'] = time();
  89. $param['admin_id'] = $this->uid;
  90. $this->model->add($param);
  91. }
  92. } else {
  93. $id = isset($param['id']) ? $param['id'] : 0;
  94. View::assign('status', $this->model::$property_status);
  95. View::assign('source', $this->model::$property_source);
  96. if($id>0){
  97. $detail = $this->model->getById($id);
  98. if(!empty($detail['user_ids'])){
  99. $users = Db::name('Admin')->where('id','in',$detail['user_ids'])->column('name');
  100. $detail['users_name'] = implode(',',$users);
  101. }
  102. if($detail['file_ids'] !=''){
  103. $fileArray = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  104. $detail['fileArray'] = $fileArray;
  105. }
  106. View::assign('detail', $detail);
  107. return view('edit');
  108. }
  109. return view();
  110. }
  111. }
  112. //查看
  113. public function view()
  114. {
  115. $param = get_params();
  116. $id = isset($param['id']) ? $param['id'] : 0;
  117. $detail = $this->model->getById($id);
  118. if($detail['cate_id']>0){
  119. $detail['cate'] = Db::name('PropertyCate')->where('id',$detail['cate_id'])->value('title');
  120. }
  121. if($detail['unit_id']>0){
  122. $detail['unit'] = Db::name('PropertyUnit')->where('id',$detail['unit_id'])->value('title');
  123. }
  124. if($detail['brand_id']>0){
  125. $detail['brand'] = Db::name('PropertyBrand')->where('id',$detail['brand_id'])->value('title');
  126. }
  127. if(!empty($detail['user_ids'])){
  128. $users = Db::name('Admin')->where('id','in',$detail['user_ids'])->column('name');
  129. $detail['users_name'] = implode(',',$users);
  130. }
  131. if(!empty($detail['user_dids'])){
  132. $titles = Db::name('Department')->where('id','in',$detail['user_dids'])->column('title');
  133. $detail['dids_title'] = implode(',',$titles);
  134. }
  135. if($detail['file_ids'] !=''){
  136. $fileArray = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  137. $detail['fileArray'] = $fileArray;
  138. }
  139. $repair = Db::name('PropertyRepair')
  140. ->field('pr.*,u.name as director_name')
  141. ->alias('pr')
  142. ->join('Admin u', 'u.id = pr.director_id', 'left')
  143. ->where(['pr.delete_time'=>0,'pr.property_id'=>$detail['id']])
  144. ->select()->toArray();
  145. $detail['repair'] = $repair;
  146. View::assign('detail', $detail);
  147. return view();
  148. }
  149. //设置
  150. public function check()
  151. {
  152. $param = get_params();
  153. $res = Db::name('Property')->strict(false)->field('id,status')->update($param);
  154. if ($res) {
  155. add_log('set', $param['id'], $param);
  156. return to_assign();
  157. }
  158. else{
  159. return to_assign(0, '操作失败');
  160. }
  161. }
  162. //维修记录列表
  163. public function repair_list()
  164. {
  165. if (request()->isAjax()) {
  166. $param = get_params();
  167. $where = [];
  168. if (!empty($param['keywords'])) {
  169. $where[] = ['p.title', 'like', '%' . $param['keywords'] . '%'];
  170. }
  171. if (!empty($param['diff_time'])) {
  172. $diff_time =explode('~', $param['diff_time']);
  173. $where[] = ['pr.repair_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1]))]];
  174. }
  175. $where[] = ['pr.delete_time','=',0];
  176. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  177. $list = Db::name('PropertyRepair')
  178. ->field('pr.*,pc.title as cate,pb.title as brand,p.title,p.model,u.name as director_name')
  179. ->alias('pr')
  180. ->join('Property p', 'p.id = pr.property_id', 'left')
  181. ->join('PropertyCate pc', 'pc.id = p.cate_id', 'left')
  182. ->join('PropertyBrand pb', 'pb.id = p.brand_id', 'left')
  183. ->join('Admin u', 'u.id = pr.director_id', 'left')
  184. ->where($where)
  185. ->order('id desc')
  186. ->paginate(['list_rows'=> $rows])
  187. ->each(function ($item, $key){
  188. $item['repair_time'] = date('Y-m-d',$item['repair_time']);
  189. $item['create_time'] = date('Y-m-d H:i',$item['create_time']);
  190. return $item;
  191. });
  192. return table_assign(0, '', $list);
  193. } else {
  194. return view();
  195. }
  196. }
  197. //维修记录添加&编辑
  198. public function repair_add()
  199. {
  200. $param = get_params();
  201. if (request()->isAjax()) {
  202. if (isset($param['repair_time'])) {
  203. $param['repair_time'] = strtotime($param['repair_time']);
  204. }
  205. if (!empty($param['id']) && $param['id'] > 0) {
  206. $param['update_time'] = time();
  207. $res = Db::name('PropertyRepair')->strict(false)->field(true)->update($param);
  208. if($res){
  209. add_log('edit', $param['id'], $param);
  210. return to_assign();
  211. }
  212. } else {
  213. $param['create_time'] = time();
  214. $insertId = Db::name('PropertyRepair')->strict(false)->field(true)->insertGetId($param);
  215. if ($insertId) {
  216. add_log('add', $insertId, $param);
  217. }
  218. return to_assign();
  219. }
  220. } else {
  221. $id = isset($param['id']) ? $param['id'] : 0;
  222. $pid = isset($param['pid']) ? $param['pid'] : 0;
  223. if ($id > 0) {
  224. $detail = Db::name('PropertyRepair')->where(['id' => $id])->find();
  225. $detail['director_name'] = Db::name('Admin')->where('id',$detail['director_id'])->value('name');
  226. $detail['property'] = Db::name('Property')->where('id',$detail['property_id'])->value('title');
  227. if($detail['file_ids'] !=''){
  228. $fileArray = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  229. $detail['fileArray'] = $fileArray;
  230. }
  231. View::assign('detail', $detail);
  232. return view('repair_edit');
  233. }
  234. if($pid>0){
  235. View::assign('property', $this->model->getById($pid));
  236. }
  237. View::assign('pid', $pid);
  238. View::assign('id', $id);
  239. return view();
  240. }
  241. }
  242. //维修记录查看
  243. public function repair_view()
  244. {
  245. $param = get_params();
  246. $id = isset($param['id']) ? $param['id'] : 0;
  247. $detail = Db::name('PropertyRepair')->where(['id' => $id])->find();
  248. $detail['director_name'] = Db::name('Admin')->where('id',$detail['director_id'])->value('name');
  249. $detail['property'] = Db::name('Property')->where('id',$detail['property_id'])->value('title');
  250. if($detail['file_ids'] !=''){
  251. $fileArray = Db::name('File')->where('id','in',$detail['file_ids'])->select();
  252. $detail['fileArray'] = $fileArray;
  253. }
  254. View::assign('detail', $detail);
  255. return view();
  256. }
  257. //维修记录删除
  258. public function repair_del()
  259. {
  260. $param = get_params();
  261. $res = Db::name('PropertyRepair')->where('id',$param['id'])->update(['delete_time'=>time()]);
  262. if ($res) {
  263. add_log('delete', $param['id'], $param);
  264. return to_assign();
  265. }
  266. else{
  267. return to_assign(0, '操作失败');
  268. }
  269. }
  270. }