BuildingController.php 12 KB

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