BuildingController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <?php
  2. /**
  3. * 建筑激活控制器
  4. *
  5. * User: smartcost
  6. * Date: 2018/9/26
  7. * Time: 11:03
  8. */
  9. class BuildingController extends DooController {
  10. public $staff;
  11. public function beforeRun($resource, $action) {
  12. Doo::loadModel ( 'staff' );
  13. $staff = new staff ();
  14. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  15. $accessModular = 'BUILD';
  16. if (empty ( $detail ['cldAccessArray'] ))
  17. die ( 'illegal request' );
  18. else {
  19. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  20. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  21. $flag = true;
  22. } else {
  23. $flag = false;
  24. }
  25. } else {
  26. die ( 'illegal request' );
  27. }
  28. }
  29. if (! $flag)
  30. die ( 'illegal request' );
  31. }
  32. function __construct() {
  33. if(isset($_COOKIE["staff"])){
  34. if(!empty($_COOKIE["staff"])){
  35. Doo::loadModel ( 'staff' );
  36. $staff = new staff ();
  37. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  38. return "/";
  39. }
  40. }
  41. Doo::loadCore ( 'uri/DooUriRouter' );
  42. $router = new DooUriRouter ();
  43. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  44. if($routeRs['1']!="login"){
  45. header ( 'Content-Type:text/html;charset=utf-8' );
  46. @header ( "Location: /login" );
  47. }
  48. }
  49. public function index() {
  50. Doo::loadModel('buildActivation');
  51. $buildActivation = new BuildActivation();
  52. Doo::loadModel('L_category');
  53. $category = new L_category();
  54. Doo::loadModel('staff');
  55. $staff = new staff();
  56. Doo::loadModel('client');
  57. $client = new client();
  58. $thisyear = date('Y',time());
  59. $num = intval($thisyear)-2018;
  60. $html = '<option value="0" selected>所有年份</option>';
  61. for($i = $num; $i >= 0; $i--){
  62. $html .= '<option value="'.(2018+$i).'">'.(2018+$i).'</option>';
  63. }
  64. $data['year_option'] = $html;
  65. // 获取建筑版本
  66. $data['compilationList'] = $buildActivation->getCompilationList();
  67. $sql = $this->staff[0]['cid'] == 12 ? ' 1' : 'cid='. $this->staff[0]['cid'];
  68. $blist = $buildActivation->getList($sql);
  69. if (!empty($blist)) {
  70. foreach ($blist as $k => $v) {
  71. $blist[$k]['categoryname'] = $category->getCategoryById($v['cid'])[0]['title'];
  72. $blist[$k]['staffname'] = $staff->getStaffBySid($v['sid'])['username'];
  73. if ($v['client_id'] != 0) {
  74. $blist[$k]['clientname'] = $client->getClientByID($v['client_id'])['clientname'];
  75. }
  76. $blist[$k]['addtime'] = date('Y-m-d', $v['addtime']);
  77. }
  78. }
  79. //办事处列表
  80. $data['categoryList'] = $category->getCategory();
  81. //办事处人员列表
  82. $data['staffList'] = $staff->getStaffByCid($this->staff[0]['cid']);
  83. $data['blist'] = $blist;
  84. $data ['memu'] = 'building';
  85. $data ['staff'] = $this->staff;
  86. $this->render ( "/building-index", $data );
  87. }
  88. /**
  89. * 获取办事处员工信息json
  90. */
  91. public function getStaffMsg() {
  92. if (isset($_GET['sid']) && is_numeric($_GET['sid'])) {
  93. Doo::loadModel('staff');
  94. $staff = new staff();
  95. $sid = $_GET['sid'];
  96. $staffInfo = $staff->getStaffBySid($sid);
  97. if (!empty($staffInfo)) {
  98. echo json_encode(array('code' => 200, 'msg' => '', 'data' => $staffInfo));
  99. exit;
  100. }
  101. }
  102. echo json_encode(array('code' => 404, 'msg' => '参数有误'));
  103. exit;
  104. }
  105. /**
  106. * 获取建筑用户信息json
  107. */
  108. public function getBuildMsg() {
  109. if (isset($_GET['id']) && is_numeric($_GET['id'])) {
  110. // Doo::loadModel('staff');
  111. //
  112. // $staff = new staff();
  113. //
  114. // $id = $_GET['id'];
  115. //
  116. // $staffInfo = $staff->getStaffBySid($id);
  117. Doo::loadClass('building');
  118. $building = new Building();
  119. $data = $building->getUsersAndCompilationByID($_GET['id']);
  120. // $data = $building->getUsersAndCompilationByMobile('13726259839');
  121. $clientInfo = '';
  122. if (isset($_GET['cid']) && is_numeric($_GET['cid'])) {
  123. Doo::loadModel('client');
  124. $client = new client();
  125. $clientInfo = $client->getClientByID($_GET['cid']);
  126. }
  127. $data['clientInfo'] = $clientInfo;
  128. Doo::loadModel('buildActivation');
  129. $buildActivation = new BuildActivation();
  130. Doo::loadModel('L_category');
  131. $category = new L_category();
  132. Doo::loadModel('staff');
  133. $staff = new staff();
  134. $buildActivationList = $buildActivation->getListByssoID($_GET['id']);
  135. if (!empty($buildActivationList)) {
  136. foreach ($buildActivationList as $bk => $bv) {
  137. $buildActivationList[$bk]['year'] = date('Y', $bv['addtime']);
  138. $buildActivationList[$bk]['month'] = date('m', $bv['addtime']);
  139. $buildActivationList[$bk]['day'] = date('d', $bv['addtime']);
  140. $buildActivationList[$bk]['categoryname'] = $category->getCategoryById($bv['cid'])[0]['title'];
  141. $buildActivationList[$bk]['staffname'] = $staff->getStaffBySid($bv['sid'])['username'];
  142. }
  143. }
  144. $data['buildActivationList'] = $buildActivationList;
  145. if (!empty($data)) {
  146. echo json_encode(array('code' => 200, 'msg' => '', 'data' => $data));
  147. exit;
  148. } else {
  149. echo json_encode(array('code' => 404, 'msg' => '建筑不存在该用户'));
  150. exit;
  151. }
  152. }
  153. echo json_encode(array('code' => 404, 'msg' => '参数有误'));
  154. exit;
  155. }
  156. /**
  157. * 获取cld客户信息
  158. */
  159. public function getClientMsg() {
  160. if (isset($_GET['cid']) && is_numeric($_GET['cid'])) {
  161. Doo::loadModel('client');
  162. $client = new client();
  163. $cid = $_GET['cid'];
  164. $clientInfo = $client->getClientByID($cid);
  165. if (!empty($clientInfo)) {
  166. Doo::loadModel ( 'client_staff' );
  167. $client_staff = new client_staff ();
  168. Doo::loadModel ( 'company' );
  169. $company = new company ();
  170. Doo::loadModel ( "district" );
  171. $district = new district ();
  172. $companyInfo = $company->getCompanyByCid ( $clientInfo ['companyid'] )[0];
  173. $staffInfo = $client_staff->getClientByCid ( $clientInfo ['cid'] );
  174. $local = $district->getbyidlist ( $clientInfo ['district'] );
  175. if (! isset ( $local [1] ))
  176. $local [1] ['name'] = "";
  177. if (! isset ( $local [2] ))
  178. $local [2] ['name'] = "";
  179. echo json_encode(array('code' => 200, 'msg' => '', 'data' => array('clientInfo' => $clientInfo, 'companyInfo' => $companyInfo, 'staffInfo' => $staffInfo, 'local' => $local)));
  180. exit;
  181. }
  182. }
  183. echo json_encode(array('code' => 404, 'msg' => '参数有误'));
  184. exit;
  185. }
  186. /**
  187. * 搜索手机号,防止由于改号码导致数据不全问题
  188. */
  189. public function checkMobile() {
  190. if (isset($_GET['mobile'])) {
  191. Doo::loadClass('building');
  192. $building = new Building();
  193. $data = $building->getUsersAndCompilationByMobile($_GET['mobile']);
  194. if ($data) {
  195. Doo::loadModel('buildActivation');
  196. $buildActivation = new BuildActivation();
  197. $buildActivationList = $buildActivation->getOneByssoID($data['userInfo']['ssoId']);
  198. $cid = !empty($buildActivationList) && $buildActivationList['client_id'] != 0 ? $buildActivationList['client_id'] : '';
  199. echo json_encode(array('code' => 200, 'msg' => '', 'data' => array('id' => $data['userInfo']['ssoId'], 'cid' => $cid)));
  200. exit;
  201. } else {
  202. echo json_encode(array('code' => 404, 'msg' => '该号码未注册建筑项目'));
  203. exit;
  204. }
  205. }
  206. echo json_encode(array('code' => 404, 'msg' => '参数有误'));
  207. exit;
  208. }
  209. /**
  210. * 修改编办信息
  211. */
  212. public function setUserCompilation() {
  213. if (isset($_POST['id']) && is_numeric($_POST['id']) && isset($_POST['cid'])) {
  214. Doo::loadClass('building');
  215. $building = new Building();
  216. $result = $building->setUserCompilation($_POST['id'], $_POST['cid']);
  217. if($result) {
  218. Doo::loadModel('buildActivation');
  219. $buildActivation = new BuildActivation();
  220. $buildActivation->insertActivation($_POST,$this->staff[0]);
  221. echo json_encode(array('code' => 200, 'msg' => ''));
  222. exit;
  223. } else {
  224. echo json_encode(array('code' => 404, 'msg' => '添加失败'));
  225. exit;
  226. }
  227. }
  228. echo json_encode(array('code' => 404, 'msg' => '参数有误'));
  229. exit;
  230. }
  231. /**
  232. * 绑定cld客户
  233. */
  234. public function setUserClient() {
  235. if (isset($_POST['id']) && is_numeric($_POST['id']) && isset($_POST['cid']) && is_numeric($_POST['cid'])) {
  236. Doo::loadModel('buildActivation');
  237. $buildActivation = new BuildActivation();
  238. $result = $buildActivation->setClientID($_POST['id'], $_POST['cid']);
  239. if ($result) {
  240. echo json_encode(array('code' => 200, 'msg' => ''));
  241. exit;
  242. } else {
  243. echo json_encode(array('code' => 404, 'msg' => '绑定失败'));
  244. exit;
  245. }
  246. }
  247. echo json_encode(array('code' => 404, 'msg' => '参数有误'));
  248. exit;
  249. }
  250. /**
  251. * 获取列表
  252. */
  253. public function getBuildList() {
  254. Doo::loadModel('buildActivation');
  255. $buildActivation = new BuildActivation();
  256. $sql = ' 1';
  257. if (isset($_POST['sso_id']) && is_numeric($_POST['sso_id'])) {
  258. $sql .= ' and sso_id='.$_POST['sso_id'];
  259. }
  260. if (isset($_POST['compilation_id']) && $_POST['compilation_id'] != 0) {
  261. $sql .= ' and compilation_id="'.$_POST['compilation_id'].'"';
  262. }
  263. if (isset($_POST['staff_id']) && is_numeric($_POST['staff_id']) && $_POST['staff_id'] != 0) {
  264. $sql .= ' and sid='.$_POST['staff_id'];
  265. } else if (isset($_POST['category']) && is_numeric($_POST['category']) && $_POST['category'] != 12) {
  266. $sql .= ' and cid='.$_POST['category'];
  267. }
  268. if (isset($_POST['year']) && is_numeric($_POST['year']) && $_POST['year'] != 0) {
  269. $year = intval($_POST['year']);
  270. if (isset($_POST['month']) && is_numeric($_POST['month']) && $_POST['month'] != 0) {
  271. $month = intval($_POST['month']);
  272. $startday = $year.'/'.$month.'/1';
  273. $endday = $month == 12 ? ($year+1).'/1/1' : $year.'/'.($month+1).'/1';
  274. } else {
  275. $startday = $year.'/1/1';
  276. $endday = ($year+1).'/1/1';
  277. }
  278. $sql .= ' and addtime>=UNIX_TIMESTAMP("'.$startday.'") and addtime<UNIX_TIMESTAMP("'.$endday.'")';
  279. }
  280. $blist = $buildActivation->getList($sql);
  281. if (!empty($blist)) {
  282. Doo::loadModel('L_category');
  283. $category = new L_category();
  284. Doo::loadModel('staff');
  285. $staff = new staff();
  286. Doo::loadModel('client');
  287. $client = new client();
  288. foreach ($blist as $k => $v) {
  289. $blist[$k]['categoryname'] = $category->getCategoryById($v['cid'])[0]['title'];
  290. $blist[$k]['staffname'] = $staff->getStaffBySid($v['sid'])['username'];
  291. if ($v['client_id'] != 0) {
  292. $blist[$k]['clientname'] = $client->getClientByID($v['client_id'])['clientname'];
  293. }
  294. $blist[$k]['addtime'] = date('Y-m-d', $v['addtime']);
  295. }
  296. }
  297. echo json_encode(array('code' => 200, 'msg' => '', 'data' => $blist));
  298. exit;
  299. }
  300. }