<?php
/**
 * Created by PhpStorm.
 * User: sicilon_IT
 * Date: 2020/1/13
 * Time: 0:05
 */
namespace app\index\logic;
use app\index\model\gworkermodel;
use app\index\model\prjlocationmodel;
use app\index\model\transfermodel;
use app\index\model\wheadmodel;
use app\index\model\checkoprmodel;
use app\index\model\ginfomodel;
use app\index\model\pwrelationmodel;
use app\index\model\checkinfomodel;
use app\index\model\daycheckinfo;
use app\index\model\pinfomodel;
use app\index\model\gcmodel;
use app\index\model\contactmodel;
use app\index\model\complainmodel;
use app\index\model\daypricerecodemodel;
use app\index\model\workerindaymodel;
use app\index\model\workersignmodel;
use think\Log;

class workercheck {
    public function isheaderbytel($tel) {
        /*
         * 20200304
         * 修改接口
         * 增加返回pid
         * 返回pnaem
         * eidt by 20250209
         *
         */
        $workertable = new gworkermodel();
        $workerid = $workertable->getidbytel($tel);
        if ($workerid === 0) {
            //电话不存在
            $res['r_code'] = 0;
            return $res;
        } else {
            //获取项目id
            $workerinfo = $workertable->getinfobyid($workerid);
            $pid = $workerinfo['cprojectid'];
            if ($pid > 0) {
                $t_prj = new pinfomodel();
                $pinfo = $t_prj->getbyid($pid);
                $pname = $pinfo['pname'];
            } else {
                $pname = '';
            }
            //获取组长ID
            $ghead = new wheadmodel();
            $gid = $ghead->getgidbywid($workerid);
            if ($gid === 0) {
                //不是班组长
                $res['r_code'] = 9902;
                $res['workerData']['wid'] = $workerid;
                $res['workerData']['pid'] = $pid;
                $res['workerData']['pname'] = $pname;
                return $res;
            } else {
                //是班组长，给合同名称
                $t_gc = new gcmodel();
                $gc = $t_gc->selcinfobygid($gid);
                if ($gc) {
                    $t_c = new contactmodel();
                    $cinfo = $t_c->selcinfobycid($gc['cid']);
                }
                $res['r_code'] = 200;
                $res['workerData']['gid'] = $gid;
                $res['workerData']['wid'] = $workerid;
                $res['workerData']['pid'] = $pid;
                if ($gc) {
                    $res['workerData']['pname'] = $cinfo['contactname'];
                } else {
                    $res['workerData']['pname'] = $pname;
                }

                return $res;
            }
        }
    }

    public function isheaderbytelV2($uinfo) {
        /*
         * 20200304
         * 修改接口
         * 增加返回pid
         * 返回pnaem
         * eidt by 20250209
         * 修改参数为数组而非电话
         * 增加打卡保存
         * 增加工人坐标在项目位置10公里以内
         * 增加班组长坐标在项目位置10公里以内的检查
         *
         * todo 增加判断是否有坐标参数
         *
         */
        $workertable = new gworkermodel();
        $tel = $uinfo['tel'];
        $paramhaslocation = 0;
        if (!empty($uinfo['gps_lng'])) {
            $paramhaslocation = 1;
        }
        log::info($paramhaslocation);
        $workerid = $workertable->getidbytel($tel);
        if ($workerid === 0) {
            //电话不存在
            $res['r_code'] = 0;
            return $res;
        } else {
            //获取项目id
            $workerinfo = $workertable->getinfobyid($workerid);
            $pid = $workerinfo['cprojectid'];
            if ($pid > 0) {
                $t_prj = new pinfomodel();
                $pinfo = $t_prj->getbyid($pid);
                $pname = $pinfo['pname'];
            } else {
                $pname = '';
            }
            //如果在正式藏在，获取项目地点，进行比较

            $inprjlocation = 0; //预设不在项目内；
            $distance = 0;
            if ($paramhaslocation == 0) {
                $inprjlocation = 1; //如果没有位置参数，则可以继续打卡
            }
            if ($paramhaslocation) {
                if ($pid > 3) {
                    $t_pl = new prjlocationmodel();
                    log::info($ploaction);
                    $ploaction = $t_pl->selinfobyprjid($pid);
                    if (!empty($ploaction)) {
                        log::info('computergps');
                        $checkradius = $ploaction['checkradius'];
                        $p_lng = $ploaction['gps_lng'];
                        $p_lat = $ploaction['gps_lat'];
                        $distance = $this->calculateDistance($p_lat, $p_lng, $uinfo['gps_lat'], $uinfo['gps_lng']);
                        if ($distance < $checkradius) {
                            $inprjlocation = 1;
                        }
                    }
                }
                //保存登录记录
                $singinfo['wid'] = $workerid;
                $singinfo['signdate'] = date('Y-m-d');
                $singinfo['signpid'] = $pid;
                $singinfo['signsuccess'] = $inprjlocation;
                $singinfo['gps_lng'] = $uinfo['gps_lng'];
                $singinfo['gps_lat'] = $uinfo['gps_lat'];
                $t_ws = new workersignmodel();
                $rs = $t_ws->insinfo($singinfo);
            }

            //获取组长ID
            $ghead = new wheadmodel();
            $gid = $ghead->getgidbywid($workerid);
            if ($gid === 0) {
                //不是班组长
                //如果正常项目，如果有位置参数，且不在范围内，移出项目，返回新的项目信息
                if ($paramhaslocation && $pid > 3 && $inprjlocation == 0) {
                    $isleave = $this->transferworerfromprj($workerid, $workerinfo['wname'], $workerinfo['telno']); //移出项目
                    $res['r_code'] = 9902;
                    $res['workerData']['wid'] = $workerid;
                    $res['workerData']['pid'] = 3;
                    $res['workerData']['pname'] = '人才库';
                    $res['workerData']['isleavejobbydistance'] = 1;
                    return $res;

                } else {
                    $res['r_code'] = 9902;
                    $res['workerData']['wid'] = $workerid;
                    $res['workerData']['pid'] = $pid;
                    $res['workerData']['pname'] = $pname;
                    return $res;
                }

            } else {
                //是班组长，给合同名称
                $t_gc = new gcmodel();
                $gc = $t_gc->selcinfobygid($gid);

                if ($gc) {
                    $t_c = new contactmodel();
                    $cinfo = $t_c->selcinfobycid($gc['cid']);
                    $pname = $cinfo['contactname'];
                }
                $res['r_code'] = 200;
                $res['workerData']['gid'] = $gid;
                $res['workerData']['wid'] = $workerid;
                $res['workerData']['pid'] = $pid;

                $res['workerData']['pname'] = $pname;

                $res['workerData']['inproject'] = $inprjlocation;
                $res['workerData']['distance'] = $distance;

                return $res;
            }
        }
    }

    private function createshiftlist() {
        $datenow = date('Y-m-d ');
        $datestart = date('Y-m-d', strtotime('-1 day'));
//        $shift_arr[$datestart][1]=1;
//        $shift_arr[$datestart][2]=1;
//        $shift_arr[$datenow][1]=1;
//        $shift_arr[$datenow][2]=1;
        $shift_arr[0]['date'] = $datestart;
        $shift_arr[0]['shift'] = '1';
        $shift_arr[0]['ischeck'] = '1';
        $shift_arr[0]['index'] = 0;
        $shift_arr[1]['date'] = $datestart;
        $shift_arr[1]['shift'] = '2';
        $shift_arr[1]['ischeck'] = '1';
        $shift_arr[1]['index'] = 1;
        $shift_arr[2]['date'] = $datenow;
        $shift_arr[2]['shift'] = '1';
        $shift_arr[2]['ischeck'] = '1';
        $shift_arr[2]['index'] = 2;
        $shift_arr[3]['date'] = $datenow;
        $shift_arr[3]['shift'] = '2';
        $shift_arr[3]['ischeck'] = '1';
        $shift_arr[3]['index'] = 3;
        return $shift_arr;
    }

    private function subshiltlist($shift_arr) {
        $index = 0;
        $r_list = array();
        foreach ($shift_arr as $k => $v) {
            //var_dump($v);
            if ($v['ischeck'] == 1) {
                $r_list[$index]['index'] = $index;
                $r_list[$index]['date'] = $v['date'];
                $r_list[$index]['shift'] = $v['shift'];
                if ($v['shift'] == 1) {
                    $r_list[$index]['disstr'] = $v['date'] . '日早班(0:00-12:00)';
                } else {
                    $r_list[$index]['disstr'] = $v['date'] . '日晚班(12:00-24:00)';
                }
                $index += 1;
            }
        }
        return $r_list;
    }

    //获得记分班次

    public function getshiftbywid($wid) {
        $shift_arr = $this->createshiftlist();
        //每个班组长可以分次记一个班，避免一个班次人太多，记错的情况
        $r_list = $this->subshiltlist($shift_arr);

        return $r_list;

    }

    /*
     * 20200729
     * 获取班次同时获取班组已考勤人数
     */
    public function getshiftandcountbywid($wid, $gid) {
        $shift_arr = $this->createshiftlist();
        //每个班组长可以分次记一个班，避免一个班次人太多，记错的情况
        $r_list = $this->subshiltlist($shift_arr);
        $t_dc = new daycheckinfo();
        foreach ($r_list as &$kv) {
            $checkdate = $kv['date'];
            $shift = $kv['shift'];
            $count = $t_dc->selcountbygid($gid, $checkdate, $shift);
            $kv['checkcount'] = $count[0]['checkcount'];

        }

        return $r_list;
    }

    //获得记分日期
    /*
     * 20210303 修改成7天
     */
    public function getcheckdate() {
        // $datenow=date('Y-m-d ');
        // $datestart=date('Y-m-d',strtotime('-1 day'));
        //  $datestart_begin=date('Y-m-d',strtotime('-2 day'));
        for ($i = 0; $i < 7; $i++) {
            $shift_arr[$i]['date'] = date('Y-m-d', strtotime('-' . (string) ($i) . ' day'));
            $shift_arr[$i]['shift'] = '1';
            $shift_arr[$i]['disstr'] = $shift_arr[$i]['date'] . '日';
            $shift_arr[$i]['index'] = $i;
        }

        // $shift_arr[0]['date']=$datestart_begin;$shift_arr[0]['shift']='1';$shift_arr[0]['disstr']=$datestart_begin.'日';;$shift_arr[0]['index']=0;
        //  $shift_arr[1]['date']=$datestart;$shift_arr[1]['shift']='1';$shift_arr[1]['disstr']=$datestart.'日';;$shift_arr[1]['index']=1;
        //   $shift_arr[2]['date']=$datenow;$shift_arr[2]['shift']='2';$shift_arr[2]['disstr']=$datenow.'日';$shift_arr[2]['index']=2;
        return $shift_arr;
    }

    public function getworkerlistbyhead($gid, $checkdate, $shift, $wid) {
        //获取项目工人

        //获取是那个项目的
        $ginfo = new ginfomodel();
        $pid = $ginfo->getpidbygid($gid);
        if ($pid === 0) {
            $res['r_code'] = 9910;
            return $res;
        } else {
            //预判合法性,Gw关系是合法的，因为在实时读取，所以本判断还是坚持原来的作用，对异常进行判定
            if ($wid > 0) {
                //$wid>0,只有传了才检查，
                $t_gworker = new gworkermodel();
                $queryuserinfo = $t_gworker->getinfobyid($wid, $gid);
                if ($queryuserinfo) {
                    //如果返回有值再检查
                    if ($pid != $queryuserinfo['cprojectid']) {
                        $res['r_code'] = 9910;
                        return $res;
                    }
                }
            }

            //根据项目获取工人
            //目前先采用跨表联查获取，人数多了再采用内存中优化 20200113
            $worktable = new pwrelationmodel();
            $workerlist = $worktable->getworkerunlist($pid, $checkdate, $shift);
            // $workerlist=$worktable->getworkerlistbypid($pid);  //20200113 标准方法，先获取班组工人，暂时不用
            if (empty($workerlist)) {
                //没有工人
                $res['r_code'] = 9911;
                $res['pid'] = $pid;
                return $res;
            } else {
                /**
                 *
                这一段原来采用分表查询，但是由于需要对两个数组循环，先直接采用数据表联查方法 20200113
                //去掉已考勤人员
                //获得已考勤人员
                $checktable=new checkinfomodel();
                $c_list=$checktable->getcheckworkerlistbydate($checkdate,$shift,$pid);
                //去掉重复
                // foreach($c_list)
                 */
                $res['r_code'] = 1;
                $res['pid'] = $pid;
                $res['wlist'] = $workerlist;
                return $res;
            }
        }
    }
//20200203日停止使用
    public function oprcheckinfo($checklist, $checkoprinfo) {
        //存入考勤详情数据
        $checktable = new checkinfomodel();
        // var_dump($checklist);
        $savecount = $checktable->savechecklist($checklist);
        //存入考勤
        $oprtable = new checkoprmodel();
        $checkoprinfo['oprtime'] = date('Y:m:d H:i:s');
        $checkoprinfo['wnum'] = $savecount;
//任取一条记录的pid
        $checkoprinfo['pid'] = $checklist[0]['pid'];
        $oprtable->saveOprRecord($checkoprinfo);
        return $savecount;

    }
//20200203后采用，按日记考勤
/*
 * 20200307
 * 修改，有gid时记录gid,没有gid时获取gid
 */
    public function savedaycheckinfo($checklist, $checkoprinfo) {
        $day_table = new daycheckinfo();
        $icount = 0;
        //判断是否有有效gid，没有的话根据班组长id获取
        if ($checkoprinfo['gid'] > 0) {
            $gid = $checkoprinfo['gid'];
        } else {
            $headid = $checkoprinfo['headid'];
            $t_head = new wheadmodel();
            $gid = $t_head->getgidbywid($headid);
            $checkoprinfo['gid'] = $gid;
        }
        //逐条存入考勤详情
        foreach ($checklist as $key => $v) {
            $check = array();
            $check['pid'] = $v['pid'];
            $check['wid'] = $v['wid'];
            $check['wname'] = $v['wname'];
            if (array_key_exists('dayprice', $v)) {
                if (is_numeric($v['dayprice'])) {
                    $check['dayprice'] = $v['dayprice'];
                } else {
                    $check['dayprice'] = 0;
                }
            }

            $check['checkdate'] = $v['checkdate'];
            if ($v['checkorder'] == 1) {
                $check['score_1'] = $v['workscore'];
                $check['headid_1'] = $v['checkheadid'];
                $check['gid_1'] = $gid;
                $check['oprtime_1'] = $v['oprtime'];
            } else {
                $check['score_2'] = $v['workscore'];
                $check['headid_2'] = $v['checkheadid'];
                $check['gid_2'] = $gid;
                $check['oprtime_2'] = $v['oprtime'];
            }

            $id = $day_table->addnewcheck($check);
            if ($id > 0) {
                $icount++;
            };
        }

        $oprtable = new checkoprmodel();
        $checkoprinfo['oprtime'] = date('Y:m:d H:i:s');
        $checkoprinfo['wnum'] = $icount;
//任取一条记录的pid
        $checkoprinfo['pid'] = $checklist[0]['pid'];
        $oprtable->saveOprRecord($checkoprinfo);
        return $icount;

    }

    public function getworkercheckinfobyid($wid) {
        //20200203后停用班次数据，采用日记录
//        $checkinfo=new checkinfomodel();

        //20200216日起，APP不调用此端口，改为调用按月查询接口

        $checkinfo = new daycheckinfo(); //20200203启用日数据表
        $r_list = $checkinfo->getusercheckinfobywid($wid);
        return $r_list;
    }
    /*
     * 20200216
     * steelxu
     * 按月查询工人的记分记录，提交给APP端
     */
    public function getworkercheckinfobyidwithmonth($wid, $month) {

        $checkinfo = new daycheckinfo();
        $r_list = $checkinfo->getusercheckinfobywidwithmonth($wid, $month);
        return $r_list;
    }

    public function gettotallistbywid($wid) {
        $checkinfo = new daycheckinfo(); //20200203启用日数据表
        $r_list = $checkinfo->totalcheckbymonthwithwid($wid);
        return $r_list;

    }

    /*
     * 20200317
     * 按月度，按班组返回员工考勤分数
     *
     */

    public function getScoreGroupbyWidWithMonth($arr) {
        //准备
        $wid = $arr['wid'];
        $month = $arr['strmonth'];
        $grouplist = array();
        $gidlist = array();
        $checkinfo = new daycheckinfo();
        $t_g = new ginfomodel();
        $t_p = new pinfomodel();
        //获取基础数据
        $r_list = $checkinfo->getusercheckinfobywidwithmonth($wid, $month);
        //汇总班组数据
        foreach ($r_list as $k) {
            $gid = $k['gid_1'];
            if ($gid && (!(in_array($gid, $gidlist)))) {
                //新班组
                $gitem['gid'] = $gid;
                $ginfo = $t_g->selginfobygid($gid);
                $gitem['gname'] = $ginfo['gname'];
                $pid = $ginfo['pid'];
                $pinfo = $t_p->getbyid($pid);
                $gitem['prjname'] = $pinfo['pname'];
                array_push($grouplist, $gitem);
                array_push($gidlist, $gid);
            }
            $gid = $k['gid_2'];
            if ($gid && (!(in_array($gid, $gidlist)))) {
                //新班组
                $gitem['gid'] = $gid;
                $ginfo = $t_g->selginfobygid($gid);
                $gitem['gname'] = $ginfo['gname'];
                $pid = $ginfo['pid'];
                $pinfo = $t_p->getbyid($pid);
                $gitem['prjname'] = $pinfo['pname'];
                array_push($grouplist, $gitem);
                array_push($gidlist, $gid);
            }

        }
        $rlist['grouplist'] = $grouplist;
        $rlist['dayscorelist'] = $r_list;
        //返回总数据
        return $rlist;
    }

    /*
     * 2020531
     * 根据项目，日期，班次，获取未记考勤的员工
     */
    public function getunchecklist($arr) {
        $pid = $arr['pid'];
        $checkdate = $arr['checkdate'];
        $shift = $arr['checkshift'];
        $worktable = new pwrelationmodel();
        $workerlist = $worktable->selunwlistforupdate($pid, $checkdate, $shift);

        return $workerlist;
    }

    /*
     * 20210421
     */
    public function savecomplaininf($arr) {
        $arr['complaindate'] = date('Y-m-d');
        $t_c = new complainmodel();
        if ($arr['complaintype'] == 1) {
            $t_w = new gworkermodel();
            $winfo = $t_w->getinfobyid($arr['complainuser']);
            $arr['complainusername'] = $winfo['wname'];
        }
        $id = $t_c->insinfo($arr);
        return $id;
    }

    /*
     * 20210421
     */
    public function getcomplainlist() {
        $t_c = new complainmodel();
        $list = $t_c->sellistbyunopr();
        return $list;
    }

    /*
     * 20230215
     * 由于原始数据中没有工地数据
     * 采用join方式，数据量巨大，
     * 所以获取所有的投诉之后
     * 轮巡检查是否某公司的项目
     * 经检查 ，只能用daycheckinfo
     */
    public function getcomplainlistbycid($arr) {
        $cid = $arr['companyid'];
        $t_c = new complainmodel();
        $list = $t_c->sellistbyunopr();
        $t_p = new pinfomodel();
        $plist = $t_p->sellistbycid($cid);
        $p_arr = array();
        foreach ($plist as $prj) {
            array_push($p_arr, $prj['id']);
        }
        $t_dc = new daycheckinfo();
        $clist = array();
        foreach ($list as $complain) {
            $coprid = $complain['checkinfoid'];
            $hcinfo = $t_dc->selinfobyid($coprid);
            $cpid = $hcinfo['pid'];
            if (in_array($cpid, $p_arr)) {
                array_push($clist, $complain);
            }
        }
        return $clist;

    }

    /*
     * 20230303
     */
    public function oprinencloseinfo($arr) {
        $nowstauts = $arr['nowstatus'];
        $prjid = $arr['prjid'];
        $wid = $arr['wid'];
        $recdate = $arr['checkdate'];
        $t_wi = new workerindaymodel();
        $lastrec = $t_wi->selinfobywid($wid, $recdate, $prjid);
        $arrreturn['status'] = 0;
        $arrreturn['msg'] = '';
        $arrreturn['data'] = array();
        if (!$lastrec) {
            //当天第一条
            $newrec['nowstatus'] = $nowstauts;
            $newrec['peid'] = $prjid;
            $newrec['wid'] = $wid;
            $newrec['checkdate'] = $recdate;
            $newrec['lastupdatetime'] = $arr['updatetime'];
            /*  需要处理，避免进入围栏后再开机的漏洞
            if($nowstauts==1){
            //如果是一开始不在现场，则增加最开始在现场的时间
            $newhours=substr($arr['updatetime'],12,2);
            $newrec['todayinhours']=$newhours;
            }
             */
            $rid = $t_wi->insinfo($newrec);

            if ($rid) {
                $arrreturn['status'] = '1';
                $arrreturn['msg'] = '新增当日围栏状态成功';
                return $arrreturn;
            } else {
                $arrreturn['msg'] = '新增当日围栏状态失败';
                return $arrreturn;
            }

        } else {
            $oldstatus = $lastrec['nowstatus'];
            if ($oldstatus == $nowstauts) {
                $arrreturn['msg'] = '状态未变更';
                return $arrreturn;
            }
            if ($nowstauts == 1) {
                $updatearr['nowstatus'] = 1;
                $updatearr['lastupdatetime'] = $arr['updatetime'];
                $rec = $t_wi->updateinstatus($wid, $recdate, $prjid, $updatearr);
                if ($rec) {
                    $arrreturn['status'] = '1';
                    $arrreturn['msg'] = '更改为围栏内状态';
                    return $arrreturn;
                } else {
                    $arrreturn['msg'] = '更改为围栏内状态失败';
                    return $arrreturn;
                }
            }
            if ($nowstauts == 2) {
                $updatearr['nowstatus'] = 2;
                $updatearr['lastupdatetime'] = $arr['updatetime'];
                //计算时长
                $oldhours = substr($lastrec['lastupdatetime'], 11, 2);
                log::info($oldhours);
                $newhours = substr($arr['updatetime'], 11, 2);
                log::info($newhours);
                $newhourcount = (int) $newhours - (int) $oldhours;
                $oldhourcount = $lastrec['todayinhours'];
                $newhourcount = $newhourcount + $oldhourcount;
                $updatearr['todayinhours'] = $newhourcount;
                //
                $rec = $t_wi->updateoutstatus($wid, $recdate, $prjid, $updatearr);
                if ($rec) {
                    $arrreturn['status'] = '1';
                    $arrreturn['msg'] = '更改为出围栏状态';
                    return $arrreturn;
                } else {
                    $arrreturn['msg'] = '更改出围栏状态失败';
                    return $arrreturn;
                }

            }
        }

    }

    private function calculateDistance($lat1, $lon1, $lat2, $lon2, $unit = 'km') {
        // 将角度转换为弧度
        $lat1 = deg2rad($lat1);
        $lon1 = deg2rad($lon1);
        $lat2 = deg2rad($lat2);
        $lon2 = deg2rad($lon2);
        log::info($lat1);
        log::info($lat2);
        log::info($lon1);
        log::info($lon2);
        // 计算经纬度差值
        $dLat = $lat2 - $lat1;
        $dLon = $lon2 - $lon1;
        // Haversine 公式的中间计算部分
        $a = sin($dLat / 2) * sin($dLat / 2) +
        cos($lat1) * cos($lat2) *
        sin($dLon / 2) * sin($dLon / 2);
        $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
        log::info($c);
        // 地球半径，单位：千米
        $earthRadius = 6371;
        // 计算距离
        $distance = $earthRadius * $c;
        // 根据单位进行转换
        if ($unit === 'mi') {
            $distance = $distance * 0.621371; // 千米转换为英里
        }
        return $distance;
    }

    /*
     * 调离项目
     */
    public function transferworerfromprj($wid, $wname, $wtel) {
        $newdate = date('Y-m-d ');
        $r_tale = new pwrelationmodel();
        $w_table = new gworkermodel();
        $t_gheader = new wheadmodel();
        $t_trans = new transfermodel();
        $icount = 0;

        //获取名字

        $transoutname = '后台自动调离';

        //var_dump($worker_arr);

        //组织数据
        $relation['pid'] = 3;
        $relation['wid'] = $wid;
        $relation['startdate'] = $newdate;
        $relation['checkstatus'] = 1;
        $w_table->updateprj(3, $wid);
        $rid = $r_tale->addnewrelation($relation);
        if ($rid > 0) {
            $icount = 1;
        }

        //如果是组长去掉组长权限
        $change = $t_gheader->changeghead($wid);
        //插入调动表记录
        $trans['wname'] = $wname;
        $trans['wid'] = $wid;
        $trans['rectime'] = date('Y-m-d H:i:s');
        $trans['telno'] = $wtel;
        $trans['transoutman'] = $transoutname;
        $trans['transoutid'] = 0; //设置 后台调出为0
        $rid = $t_trans->insinfo($trans);

        return $icount;

    }
    /**
     * 获取工人日工资列表
     *
     * @return void
     * @author wj
     * @date 2025-02-17
     */
    public function getdaypricerecodelist($arr) {
        $m_dr = new daypricerecodemodel();
        $where = [];
        if (isset($arr['userid']) && !empty($arr['userid'])) {
            $where['user_id'] = $arr['userid'];
        }
        if (isset($arr['createtime']) && is_array($arr['createtime'])) {
            $times = array_filter($arr['createtime']);
            if (is_array($times) && count($times) == 2) {
                $where['createtime'] = ['between', [$times[0], $times[1]]];
            }
        }
        $page = isset($arr['page']) && !empty($arr['page']) && is_numeric($arr['page']) ? $arr['page'] : 1;
        $size = isset($arr['size']) && !empty($arr['size']) && is_numeric($arr['size']) ? $arr['size'] : 10;
        $count = $m_dr->getList($where, 'count');
        $arrreturn['status'] = 0;
        $arrreturn['msg'] = '无数据';
        $arrreturn['data'] = [];
        if ($count <= 0) {
            return $arrreturn;
        }
        $list = $m_dr->getList($where, "*", $page, $size, "id desc");
        $arrreturn['status'] = 1;
        $arrreturn['msg'] = '查询成功';
        $data = [
            "pageSize" => 10,
            "pageNum" => 1,
            'count' => $count,
            'list' => $list,
        ];
        $arrreturn['data'] = $data;
        return $arrreturn;
    }

}