sealaplModel.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php
  2. /**
  3. * 模块.印章申请
  4. */
  5. class flow_sealaplClassModel extends flowModel
  6. {
  7. // level1部门领导
  8. // level2办公室
  9. // level3业务主管
  10. // level4法务部
  11. // level5矿分管领导
  12. // level6矿长
  13. protected $examine_dept_dic = ['1'=>"部门领导",'2'=>"办公室",'3'=>"业务主管部门",'4'=>"法律事务部", '5'=>"矿分管领导",'6'=>"矿长党委书记"];
  14. protected function flowinit(){
  15. }
  16. //提交时调用
  17. protected function flowsubmit($na, $sm){
  18. if ($sm = '提交') {
  19. $info = [
  20. "advice_level1_leader"=>$this->flowarr[0]['nowcheckname'],
  21. "advice_level1_leader_id"=>$this->flowarr[0]['nowcheckid']
  22. ];
  23. m('sealapl')->update($info, "id = {$this->id}");
  24. // 给部门领导发短信,提醒审批
  25. $this->sendSealSms($this->id, 0); // 提醒领导审核
  26. }
  27. }
  28. //单据判断条件从写$lx类型,$uid用户Id
  29. protected function flowbillwhere($lx, $uid){
  30. $where = '';
  31. $startDate = $this->rock->post("start_date");
  32. $stopDate = $this->rock->post("stop_date");
  33. if ($uid == 'all') {
  34. $where .= 'and '.$this->adminid.' in (1, 28)';
  35. }
  36. // 开始时间
  37. if (!empty($startDate)) {
  38. $where .= " and office_date > '{$startDate}'";
  39. }
  40. // 结束时间
  41. if (!empty($stopDate)) {
  42. $where .= " and office_date < '{$stopDate}'";
  43. }
  44. return [
  45. 'where' => $where,
  46. 'order'=>'status, office_date desc, id desc'
  47. ];
  48. }
  49. //读取印章保管人来审批
  50. protected function flowcheckname($num)
  51. {
  52. // 自定义审核人
  53. if (strpos($num, 'approve') === 0) {
  54. // $index = substr($num, -1);
  55. // if ($index == 4) {
  56. //// $sid = $this->rs['advice_level'.$index.'_leader_id'];
  57. //// $sna = $this->rs['advice_level'.$index.'_leader'];
  58. // } else {
  59. // $sid = $this->rs['advice_level'.$index.'_leader_id'];
  60. // $sna = $this->rs['advice_level'.$index.'_leader'];
  61. // return array($sid, $sna);
  62. // }
  63. }
  64. }
  65. // 展示时替换一下
  66. public function flowrsreplace($rs, $lx=0)
  67. {
  68. // if (empty($this->id)) $this->id = $rs['id'];
  69. // if (empty($rs['id'])) $rs['id'] = $this->id;
  70. $rs['office_date'] = date("Y-m-d", strtotime($rs['office_date']));
  71. $rs['date'] = empty($rs['office_date']) ? $rs['applydt'] : $rs['office_date'];
  72. $rs['date_index'] = substr($rs['applydt'],0,4);
  73. $sqlStr = "SELECT t.*
  74. FROM (
  75. -- 子查询,为每个step选取最新的时间对应的记录
  76. SELECT step, MAX(optdt) AS max_optdt FROM zqoa_flow_log
  77. WHERE mid = {$rs['id']} AND `status` = 1 AND `table` = 'sealapl'
  78. GROUP BY step
  79. ) AS subquery
  80. JOIN zqoa_flow_log AS t ON subquery.step = t.step
  81. AND subquery.max_optdt = t.optdt
  82. WHERE t.mid = {$rs['id']}
  83. AND t.`status` = 1
  84. AND t.`table` = 'sealapl'";
  85. // 未审核完成时,设定签名为空
  86. $flow_arr = $this->db->getall($sqlStr);
  87. $flow_dict = [];
  88. foreach ($flow_arr as $key=>$value) {
  89. $flow_dict[$value['name']] = $value;
  90. }
  91. if (!isset($flow_dict["部门领导审批"])) {
  92. $rs['advice_level1_leader'] = null;
  93. $rs['advice_level1'] = null;
  94. $rs['advice_level3_leader'] = null;
  95. $rs['advice_level3'] = null;
  96. }
  97. if (!isset($flow_dict["办公室审批"])) {
  98. $rs['advice_level2_leader'] = null;
  99. $rs['advice_level2'] = null;
  100. }
  101. // if (!isset($flow_dict["业务主管部门审批"])) {
  102. // $rs['advice_level3_leader'] = null;
  103. // $rs['advice_level3'] = null;
  104. // }
  105. if (!isset($flow_dict["法律事务部审批"])) {
  106. $rs['advice_level4_leader'] = null;
  107. $rs['advice_level4'] = null;
  108. }
  109. if (!isset($flow_dict["矿分管领导审批"])) {
  110. $rs['advice_level5_leader'] = null;
  111. $rs['advice_level5'] = null;
  112. }
  113. if (!isset($flow_dict["矿长党委书记审批"])) {
  114. $rs['advice_level6_leader'] = null;
  115. $rs['advice_level6'] = null;
  116. }
  117. $rs['advice_leader_max'] = empty($rs['advice_level6_leader']) ? $rs['advice_level5_leader'] : $rs['advice_level6_leader'];
  118. $flow_info = $this->flogmodel->getone("mid={$rs['id']} and step=1 and status=1 and `table` = 'sealapl'", 'checkname', 'id desc');
  119. $rs['dept_manager'] = $flow_info ? $flow_info['checkname'] : null;
  120. if (!empty($rs['opinion_dept'])) {
  121. $dept = $rs['opinion_dept'];
  122. // 自动加需要xx部门审核
  123. // 办公室需要审核部门
  124. /*
  125. $examine_dept_arr = explode(',',$dept);
  126. $examine_info = '';
  127. foreach ($examine_dept_arr as $v) {
  128. $examine_info .= $this->examine_dept_dic[$v].'、';
  129. }
  130. if (!empty($examine_info)) {
  131. $examine_info = substr($examine_info, 0, strlen($examine_info) - 3);
  132. $examine_info = '需要“'.$examine_info.'”审核。';
  133. }
  134. if (!empty($rs['advice_level2'])) {
  135. $rs['advice_level2'] = $rs['advice_level2'].'<br>'.$examine_info;
  136. } else {
  137. $rs['advice_level2'] = $examine_info;
  138. }
  139. */
  140. // 列表-审批人:
  141. // if ($dept == 1) {
  142. // $flow_info = $this->flogmodel->getone("mid={$rs['id']} and step=3 and status=1 and `table` = 'sealapl'", 'checkname', 'id desc');
  143. // $rs['advice_level1_applyer'] = $flow_info ? $flow_info['checkname'] : null;
  144. // } else if ($dept == 2) {
  145. //
  146. // } else if ($dept == 3) {
  147. // $flow_info = $this->flogmodel->getone("mid={$rs['id']} and step=3 and status=1 and `table` = 'sealapl'", 'checkname', 'id desc');
  148. // $rs['advice_level3_applyer'] = $flow_info ? $flow_info['checkname'] : null;
  149. // } else if ($dept == 4) {
  150. // $flow_info = $this->flogmodel->getone("mid={$rs['id']} and step=3 and status=1 and `table` = 'sealapl'", 'checkname', 'id desc');
  151. // $rs['advice_level4_applyer'] = $flow_info ? $flow_info['checkname'] : null;
  152. // }
  153. }
  154. // 办公室审核人
  155. $flow_info = $this->flogmodel->getone("mid={$rs['id']} and step=2 and status=1 and `table` = 'sealapl'", 'checkname', 'id desc');
  156. $rs['advice_level2_leader'] = $flow_info ? $flow_info['checkname'] : null;
  157. // 印章专管人
  158. $seal = m('seal')->getone("id = {$rs['seal_name']}");
  159. $rs['office_applyer'] = $seal['specialized'];
  160. $rs['seal_name'] = $seal['name'];
  161. // 流程状态
  162. $rs['state_info'] = $this->getApproval($rs['nowcheckname'] ?? ''); // 当前审核人
  163. // 详情编号展示
  164. if ($rs['date'] == '1970-01-01') {
  165. $rs['date'] = "";
  166. $date = $rs['applydt'];
  167. } else {
  168. $date = $rs['date'];
  169. }
  170. $year = date("Y", strtotime($date));
  171. $month = date("m", strtotime($date));
  172. $this_month = date("Y-m", strtotime($date));
  173. $last_month = date("Y-m", strtotime("-1 month", strtotime($date)));
  174. $this_month_max_id = $this->getone("DATE_FORMAT(applydt,'%Y-%m') = '{$this_month}'", "max(id) as id")['id'];
  175. $last_month_max_id = $this->getone("DATE_FORMAT(applydt,'%Y-%m') = '{$last_month}'", "max(id) as id")['id'];
  176. $this_month_max_id = empty($last_month_max_id) ? 2 : $this_month_max_id;
  177. $rs['year'] = $year;
  178. $rs['month'] = $month;
  179. $rs['num'] = ($rs['id'] - (empty($last_month_max_id) ? $this_month_max_id - 2: $last_month_max_id));
  180. return $rs;
  181. }
  182. // 审核样式
  183. public function getApproval($names) {
  184. if (empty($names)) {
  185. $html = '<font style="background-color:#00c959; padding: 2px 8px; border-radius: 4px; color: #fff">已审核</font>';
  186. return $html;
  187. } else {
  188. $html = '<font style="background-color:#ff4974; padding: 2px 8px; border-radius: 4px; color: #fff">待审核</font><br /><font style="color: #ff4974">审核人:'.$names.'</font>';
  189. return $html;
  190. }
  191. }
  192. public function inputtitle()
  193. {
  194. return "枣泉煤矿用印审批表";
  195. }
  196. protected function flowdatalog($arr)
  197. {
  198. $arr['title'] = $this->inputtitle();
  199. return $arr;
  200. }
  201. // $ors当前单据操作信息,$crs提交过来的信息
  202. public function flowoptmenu($ors, $crs)
  203. {
  204. if ($ors['num'] == 'dept_process') {
  205. }
  206. }
  207. //审核之前调用$zt 状态, $sm说明
  208. protected function flowcheckbefore($zt, $sm, $ufied) {
  209. if ($zt == 1) {
  210. $nodes_old = $this->rs['notes'];
  211. if (isset($this->nowcourse['step'])) {
  212. if (empty($sm)) $sm = '同意';
  213. $step_name = $this->nowcourse['name'];
  214. $info = "";
  215. if ($step_name == '部门领导审批') {
  216. $info = [
  217. "advice_level1"=>$sm,
  218. "advice_level1_leader"=>$this->rock->adminname,
  219. "advice_level1_leader_id"=>$this->rock->adminid,
  220. "advice_level3"=>$sm,
  221. "advice_level3_leader"=>$this->rock->adminname,
  222. "advice_level3_leader_id"=>$this->rock->adminid,
  223. // "notes"=>'部门领导-'.$this->rock->adminname.":".$sm
  224. ];
  225. } else if ($step_name == '办公室审批') {
  226. $date = date('Y-m-d H:i:s'); // 办公室处理日期
  227. // 获取当月最大id数据
  228. $yearMon = date("Y-m", strtotime($date));
  229. $maxInfo = $this->getone("DATE_FORMAT(office_date,'%Y-%m') = '{$yearMon}' and status = 1 and seal_name = {$this->rs['seal_name']}", "max(year_num) as id");
  230. $max_year_num = 1;
  231. if (isset($maxInfo['id'])) {
  232. $max_year_num = $maxInfo['id'] + 1;
  233. }
  234. $info = [
  235. "advice_level2"=>$sm,
  236. "advice_level2_leader"=>$this->rock->adminname,
  237. "advice_level2_leader_id"=>$this->rock->adminid,
  238. "office_date"=>$date,
  239. "year_num" => $max_year_num
  240. // "notes"=>$nodes_old.(empty($nodes_old) ? "" : "<br>").'办公室-'.$this->rock->adminname.":".$sm
  241. ];
  242. } else if ($step_name == '业务主管部门审批') {
  243. $info = [
  244. "advice_level3"=>$sm,
  245. "advice_level3_leader"=>$this->rock->adminname,
  246. "advice_level3_leader_id"=>$this->rock->adminid,
  247. // "notes"=>$nodes_old.(empty($nodes_old) ? "" : "<br>").'业务主管部门-'.$this->rock->adminname.":".$sm
  248. ];
  249. } else if ($step_name == '法律事务部审批') {
  250. $info = [
  251. "advice_level4"=>$sm,
  252. "advice_level4_leader"=>$this->rock->adminname,
  253. "advice_level4_leader_id"=>$this->rock->adminid,
  254. // "notes"=>$nodes_old.(empty($nodes_old) ? "" : "<br>").'法律事务部-'.$this->rock->adminname.":".$sm
  255. ];
  256. } else if ($step_name == '矿分管领导审批') {
  257. $info = [
  258. "advice_level5"=>$sm,
  259. "advice_level5_leader"=>$this->rock->adminname,
  260. "advice_level5_leader_id"=>$this->rock->adminid,
  261. // "notes"=>$nodes_old.(empty($nodes_old) ? "" : "<br>").'矿分管领导-'.$this->rock->adminname.":".$sm
  262. ];
  263. } else if ($step_name == '矿长党委书记审批') {
  264. $info = [
  265. "advice_level6"=>$sm,
  266. "advice_level6_leader"=>$this->rock->adminname,
  267. "advice_level6_leader_id"=>$this->rock->adminid,
  268. // "notes"=>$nodes_old.(empty($nodes_old) ? "" : "<br>").'矿长党委书记-'.$this->rock->adminname.":".$sm
  269. ];
  270. }
  271. if (!empty($info)) m('sealapl')->update($info,"id={$this->id}");
  272. }
  273. // if ($this->nowcourse['step'] == 3 && $this->nowcourse['name'] == '负责部门审批') {
  274. // $opinion_dept = $this->rs['opinion_dept'];
  275. // if ($opinion_dept == 1) {
  276. // m('sealapl')->update(["advice_level1"=>$sm],"id={$this->id}");
  277. // } else if ($opinion_dept == 2) {
  278. // m('sealapl')->update(["advice_level2"=>$sm],"id={$this->id}");
  279. // } else if ($opinion_dept == 3) {
  280. // m('sealapl')->update(["advice_level3"=>$sm],"id={$this->id}");
  281. // } else if ($opinion_dept == 4) {
  282. // m('sealapl')->update(["advice_level4"=>$sm],"id={$this->id}");
  283. // }
  284. // }
  285. }
  286. // if(isset($this->nowcourse['step']) && !empty($sm)) {
  287. // $info_old = $this->rs['notes'];
  288. // $info = $this->nowcourse['step'].'.'.$this->adminname.":".$sm."\n";
  289. // $info = $info_old.$info;
  290. // $info = substr($info, 0, strlen($info)-1);
  291. // m('sealapl')->update(["notes"=>$info],"id={$this->id}");
  292. // }
  293. }
  294. //审核完成后调用
  295. protected function flowcheckafter($zt, $sm){
  296. if ($zt == 1) {
  297. if ($this->nowcourse['step'] == 2) {
  298. // 给办公室发短信题型审批
  299. $this->sendSealSms($this->id, 1); // 提醒领导审核
  300. }
  301. }
  302. }
  303. protected function sendSealSms($id, $step) {
  304. if (isset($this->rs) && !empty($this->rs)) {
  305. $sealApl = m("sealapl")->getone("id={$id}");
  306. $sealId = $sealApl['seal_name'];
  307. $seal = m("seal")->getone("id = {$sealId}");
  308. $leaderInfo = [];
  309. $smsInfo = [];
  310. $mobile = [];
  311. if ($step == 0) {
  312. $leaderId = $sealApl["advice_level1_leader_id"];
  313. $leaderInfo = m("admin")->getone("id = {$leaderId}");
  314. if (isset($leaderInfo)) {
  315. $mobile[] = $leaderInfo['mobile']; // 领导短信
  316. $dept = $this->rs['apply_dept']; // 申请部门
  317. $name = $this->rs['optname']; // 申请人
  318. $smsInfo[] = [
  319. "username" => $dept."-".$name,
  320. "seqlname" => $seal['name']
  321. ];
  322. }
  323. } else if($step == 1) {
  324. $sealAdmin = $seal['specialized_id'];
  325. $leaderInfo = m("admin")->getall("id in ({$sealAdmin})");
  326. foreach ($leaderInfo as $key=>$value) {
  327. $mobile[] = $value['mobile'];
  328. $dept = $this->rs['apply_dept']; // 申请部门
  329. $name = $this->rs['optname']; // 申请人
  330. $smsInfo[] = [
  331. "username" => $dept."-".$name,
  332. "seqlname" => $seal['name']
  333. ];
  334. }
  335. }
  336. m('send_sms')->sendBatchSms($mobile, $smsInfo, 101);
  337. }
  338. }
  339. }