contactlogic.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: sicilon_IT
  5. * Date: 2020/3/8
  6. * Time: 16:54
  7. */
  8. namespace app\index\logic;
  9. use app\index\model\gworkermodel;
  10. use app\index\model\pinfomodel;
  11. use app\index\model\ginfomodel;
  12. use app\index\model\contactmodel;
  13. use app\index\model\gcmodel;
  14. use app\index\model\daycheckinfo;
  15. use app\index\model\recuitmodel;
  16. class contactlogic{
  17. /*
  18. * 20200308 存储新合同
  19. */
  20. public function savecontact($arr){
  21. $t_contact=new contactmodel();
  22. $res=$t_contact->insinfo($arr);
  23. return $res;
  24. }
  25. /*
  26. * 20200308 获取合同清单
  27. */
  28. public function getclistbypid($arr){
  29. $pid=$arr['pid'];
  30. $t_contact=new contactmodel();
  31. $res=$t_contact->selclistbypid($pid);
  32. return $res;
  33. }
  34. /*
  35. * 20200320
  36. * 获取所有合同清单,只为导出服务,该方案中去年验证合同
  37. */
  38. public function getclist(){
  39. $t_contact=new contactmodel();
  40. $clist=$t_contact->selectclistbyacitve();
  41. return $clist;
  42. }
  43. /*
  44. * 20230215
  45. * 获取公司的合同列表
  46. */
  47. public function getcompanyclist($cid){
  48. $t_contact=new contactmodel();
  49. $clist=$t_contact->sellistbycid($cid);
  50. return $clist;
  51. }
  52. /*
  53. * 20200309
  54. * 存入合同关系
  55. */
  56. public function savegcrelation($gcinfo){
  57. $t_gc=new gcmodel();
  58. $newid=$t_gc->insinfo($gcinfo);
  59. return $newid;
  60. }
  61. /*
  62. * 20200310
  63. * 按项目获取合同及各合同的汇总记分
  64. * 当前先实现返回合同,后期加按合同汇总分
  65. */
  66. public function getctotalbypid($arr){
  67. //预留翻页,用$arr可实现controller层不受影响
  68. $pid=$arr['pid'];
  69. $t_contact=new contactmodel();
  70. $res=$t_contact->selclistbypid($pid);
  71. //todo 条件成熟后 加上所有项目的总分
  72. return $res;
  73. }
  74. /*
  75. * 20200310
  76. * 获取合同下的班组考勤
  77. *
  78. */
  79. public function getgroupsumbycid($arr){
  80. $cid=$arr['cid'];
  81. $month=$arr['monthinfo'];
  82. $year=$arr['yearinfo'];
  83. if (strlen($month)==1){
  84. $month='0'.$month;
  85. }
  86. $strmonth=$year.'-'.$month;
  87. $t_gc=new gcmodel();
  88. $t_ginfo=new ginfomodel();
  89. $t_ds=new daycheckinfo();
  90. //获取班组清单
  91. $g_list=$t_gc->selgidbycid($cid);
  92. foreach($g_list as &$v){
  93. //获取班组名称
  94. $gid=$v['gid'];
  95. $g_info=$t_ginfo->selginfobygid($gid);
  96. $v['gname']=$g_info['gname'];
  97. //获取月度计分详情
  98. $score_list=$t_ds->selsuminfobygid($gid,$strmonth);
  99. if ($score_list) {
  100. $summonth = 0;
  101. foreach ($score_list as $k) {
  102. // $day_str = strval(substr(strval($k['checkdate']), -2));
  103. $int_score = intval($k['d_score_1']) + intval($k['d_score_2']);
  104. if ($int_score > 0) {
  105. // $v[$day_str] = $int_score;
  106. $v[$k['checkdate']] = $int_score;
  107. }
  108. $summonth += $int_score;
  109. }
  110. $v['summonth'] = $summonth;
  111. // print_r($v);
  112. }
  113. }
  114. // echo json_encode($g_list);
  115. return $g_list;
  116. }
  117. /*
  118. * 20200315
  119. * 获取同一个合同下班组下所有工人的考勤,
  120. * 另外还可以按个人对考勤一样,给一个分组的考勤
  121. * 20200818 将处理过程改到
  122. */
  123. public function getworkersumbycid($arr){
  124. //准备
  125. $cid=$arr['cid'];
  126. $month=$arr['monthinfo'];
  127. $year=$arr['yearinfo'];
  128. if (strlen($month)==1){
  129. $month='0'.$month;
  130. }
  131. $strmonth=$year.'-'.$month;
  132. $t_gc=new gcmodel();
  133. $t_ginfo=new ginfomodel();
  134. $t_ds=new daycheckinfo();
  135. $t_re=new recuitmodel();
  136. //取出ulist 存储所有的被推荐人,减少每一个用户都要访问数据表的问题,在单独一条记录低于就可以
  137. $ulist=$t_re->seluserlist();
  138. $recuituserlist=array();
  139. foreach($ulist as $kv){
  140. array_push($recuituserlist,$kv['userid']);
  141. }
  142. $gwlist=array();
  143. //先获取班组
  144. $g_list=$t_gc->selgidbycid($cid);
  145. foreach($g_list as &$v) {
  146. //按班组获得员工记分清单
  147. $gid=$v['gid'];
  148. $g_info=$t_ginfo->selginfobygid($gid);
  149. $v['gname']=$g_info['gname'];
  150. $v['wid']='g'.strval($gid);
  151. //再按班组组装员工数据
  152. $workerscore_list=$t_ds->selworksumbygidwithdate($gid,$strmonth);
  153. $newscorelist=$this->countgroupdaysum($workerscore_list);
  154. //获取班组汇总数据
  155. //$score_list=$t_ds->selsuminfobygid($gid,$strmonth);
  156. //20200823 用新方法,不访问数据表,最后再合并
  157. $score_list=$this->countgroupdaysum($workerscore_list);
  158. if($workerscore_list){
  159. //如果该项目日期内有员工记录,则建立员工记录
  160. $summonth = 0;
  161. foreach ($score_list as $k) {
  162. // $day_str = strval(substr(strval($k['checkdate']), -2));
  163. $int_score = intval($k['d_score_1']) + intval($k['d_score_2']);
  164. if ($int_score > 0) {
  165. // $v[$day_str] = $int_score;
  166. $v[$k['checkdate']] = $int_score;
  167. }
  168. $summonth += $int_score;
  169. }
  170. $v['summonth'] = $summonth;
  171. //以上处理班组总数据
  172. //以下处理班组个人数据
  173. $opredwlist=$this->opreworkerlist($workerscore_list,$recuituserlist);
  174. $v['detail']=$opredwlist;
  175. // }
  176. }else{
  177. //没有员工被记工,则返回一条记录,只有组名
  178. $v['summonth']=0;
  179. $v['detail']=array();
  180. }
  181. }
  182. return $g_list;
  183. }
  184. /*
  185. * 20200823
  186. * 根据问题,推动内部获取分组的相关数据
  187. *
  188. */
  189. private function countgroupdaysum($workerlist){
  190. $wlist=array();
  191. $datelist=array();
  192. foreach($workerlist as $kv){
  193. $cdate=$kv['checkdate'];
  194. if (in_array($cdate,$datelist)){
  195. //已存在,取得位置
  196. $dateindex=array_flip($datelist);
  197. $dindex=$dateindex[$cdate];
  198. $wlist[$dindex]['d_score_1']+=$kv['d_score_1'];
  199. $wlist[$dindex]['d_score_2']+=$kv['d_score_2'];
  200. }else{
  201. //不存在,创造一个新元素,同步插入
  202. $nitem=array();
  203. $nitem['checkdate']=$cdate;
  204. $nitem['d_score_1']=$kv['d_score_1'];
  205. $nitem['d_score_2']=$kv['d_score_2'];
  206. array_push($wlist,$nitem);
  207. array_push($datelist,$cdate);
  208. }
  209. }
  210. return $wlist;
  211. }
  212. /*
  213. * edit
  214. * 20200503
  215. * 增加,如果是被推荐的工人,则每天到10分累加5元的成本
  216. * 20200818 被推荐的工人处理到上一级处理,一次处理只访问一次数据表,节约时间
  217. */
  218. private function opreworkerlist($arr,$ulist){
  219. $wlist=array();
  220. //初始化
  221. foreach($arr as $k){
  222. $wname=$k['wname'];
  223. $wlist[$wname]['wid']=$k['wid'];
  224. $wlist[$wname]['gname']=$wname;
  225. $checkdate=$k['checkdate'];
  226. $int_score = intval($k['d_score_1']) + intval($k['d_score_2']);
  227. $wlist[$wname][$checkdate]=$int_score;
  228. if (array_key_exists('summonth',$wlist[$wname])){
  229. $wlist[$wname]['summonth']+=$int_score;
  230. }else{
  231. $wlist[$wname]['summonth']=$int_score;
  232. }
  233. //累加超过10分的天数
  234. if ($int_score>=10){
  235. if (array_key_exists('countdays',$wlist[$wname])){
  236. $wlist[$wname]['countdays']+=1;
  237. }else{
  238. $wlist[$wname]['countdays']=1;
  239. }
  240. }
  241. }
  242. $key_list=array_keys($wlist);
  243. $workertotal=array();
  244. foreach($key_list as $kv){
  245. $wid=$wlist[$kv]['wid'];
  246. //获取是否是推荐关系
  247. // $recuitinfo=$t_re->selrecuitinfobyuserid($wid); //20200817 ,test废弃,比较时间
  248. // if ($recuitinfo){
  249. if (in_array($wid,$ulist)){ //20200817 测试使用
  250. if(array_key_exists('countdays',$wlist[$kv])){
  251. $wlist[$kv]['recuitcost']=5*$wlist[$kv]['countdays'];
  252. }
  253. }
  254. array_push($workertotal,$wlist[$kv]);
  255. }
  256. //补充身份证号
  257. $t_w=new gworkermodel();
  258. foreach($workertotal as &$worker){
  259. $wid=$worker['wid'];
  260. $winfo=$t_w->getinfobyid($wid);
  261. if($winfo){
  262. $worker['sfz']=$winfo['shengfengid'];
  263. }
  264. }
  265. return $workertotal;
  266. }
  267. }