obj = new MShopRostering($this->onlineEnterpriseId, $this->onlineUserId); $this->staff = new MStaff($this->onlineEnterpriseId, $this->onlineUserId); $this->Mrostering = new MShopRostering($this->onlineEnterpriseId, $this->onlineUserId); $this->MTem = new MShopTemplate($this->onlineEnterpriseId, $this->onlineUserId); $this->MStaffRewardDesc = ''; $this->objShopCache = new ShopCache(); $this->objTempSaveCache = new TempSaveCache(); $this->MGroup = new MShopGroup($this->onlineEnterpriseId, $this->onlineUserId); } /** * 添加和编辑商铺管理公共字段处理方法 * * @return array */ public function commonFieldFilter(){ $params = $this->request->getRawJson(); if( empty($params) ){ $this->sendOutput('参数为空', ErrorCode::$paramError ); } $shopData = [ 'template_id' => isset($params['template_id']) ? $params['template_id'] : '', 'uid' => isset($params['uid']) ? $params['uid'] : '', ]; //非暂存则验空 if (!isset($params['tempSave']) || $params['tempSave'] == false) { foreach($shopData as $key => $value){ if(empty($value) && $value !== 0){ $this->sendOutput($key.'参数错误', ErrorCode::$paramError ); } } } $shopData['start_time']= isset($params['start_time']) ? $params['start_time'] : false; $shopData['end_time']= isset($params['end_time']) ? $params['end_time'] : false; $shopData['name']= isset($params['name']) ? $params['name'] : false; return $shopData; } /** * 列表 */ public function list() { $params = $this->request->getRawJson(); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $selectParams['shop_id'] = $this->shopId; //昵称 if(isset($params['nickname']) && !empty($params['nickname'])){ $selectParams['nickname'] = $params['nickname']; } //uid if(isset($params['uid']) && !empty($params['uid'])){ $selectParams['uid'] = $params['uid']; } // 时间 if(isset($params['start_time']) && !empty($params['start_time']) and isset($params['end_time']) && !empty($params['end_time'])){ $response = []; $dt_start = strtotime($params['start_time']); $dt_end = strtotime($params['end_time']); while ($dt_start <= $dt_end) { array_push($response, date('Y-m-d', $dt_start)); $dt_start = strtotime('+1 day', $dt_start); } $selectParams['time'] = $response; } $result = $this->obj->list($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } else { parent::sendOutput($result->getData(), ErrorCode::$dberror); } } /** * 添加 * @throws \Exception */ public function add() { $addStaffData = $this->commonFieldFilter(); $response = []; $dt_start = strtotime($addStaffData['start_time']); $dt_end = strtotime($addStaffData['end_time']); while ($dt_start <= $dt_end) { array_push($response, date('Y-m-d', $dt_start)); $dt_start = strtotime('+1 day', $dt_start); } unset($addStaffData['start_time']); unset($addStaffData['end_time']); $addStaffData['times'] = $response; $addStaffData['shop_id'] = $this->shopId; $result = $this->obj->insert($addStaffData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 详情 * @return void */ public function details() { $where = []; $id = $this->request->param('id'); if(!empty($id)){ $where['id'] = $id; } $result = $this->obj->details($where); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 修改 * @return void */ public function update() { $id['id'] = $this->request->param('id'); if (empty($id['id'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $params = $this->commonFieldFilter(); unset($params['start_time']); unset($params['end_time']); unset($params['uid']); $result = $this->obj->update($params, $id); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } public function delete() { $id['id'] = $this->request->param('id'); if (empty($id['id'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $result = $this->obj->delete($id); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 班次添加 * @return void */ public function add_shift() { $param = $this->request->getRawJson(); // $user = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId, 'shopId' => $this->shopId])->getData(); // if (empty($user['userId'])) parent::sendOutput('该账号未绑定钉钉', 1005); // if (!$user) parent::sendOutput('不是该店铺店员', 1005); $url = 'https://oapi.dingtalk.com/topapi/attendance/shift/add?access_token='.$this->voucher(); $param['op_user_id'] = empty($user['userId']) ? '' : $user['userId']; $param['shift']['owner'] = empty($user['userId']) ? '' : $user['userId']; $data = json_encode($param); $time = []; foreach ($param['shift']['sections'] as $item) { $ti = []; foreach ($item['times'] as $vo) { $ti[] = explode(' ', $vo['check_time'])[1]; } $time[] = $ti; } $res = $this->post_json($url, $data); $res = json_decode($res); if ($res->errcode > 0){ parent::sendOutput($res->errmsg, 1); } $template = [ 'shop_id' => $this->shopId, 'name' => $param['shift']['name'], 'shift_id' => $res->result->id, 'time' => json_encode($time), 'single_time' => $param['shift']['single_time'] ]; $this->MTem->insert($template); parent::sendOutput('添加成功'); } /** * 班次列表 * @return void */ public function shift_list() { $params = $this->request->getRawJson(); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; // $param['cursor'] = $this->request->param('cursor'); // $url = 'https://oapi.dingtalk.com/topapi/attendance/shift/list?access_token='.$this->voucher(); // $user = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId, 'shopId' => $this->shopId])->getData(); // $param['op_user_id'] = ''; // $param = json_encode($param); // $res = $this->post_json($url, $param); // $res = json_decode($res); $selectParams['shop_id'] = $this->shopId; $result = $this->MTem->list($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0,$pageData); } else { parent::sendOutput($result->getData(), ErrorCode::$dberror); } } /** * 班次详情 * @return void */ public function shift_details() { $where = []; $id = $this->request->param('id'); if(!empty($id)){ $where['id'] = $id; } $result = $this->MTem->details($where); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } // $url = 'https://oapi.dingtalk.com/topapi/attendance/shift/query?access_token='.$this->voucher(); // // $param['op_user_id'] = ''; // $param['shift_id'] = $id; // $param = json_encode($param); // $res = $this->post_json($url, $param); // $res = json_decode($res); // if ($res->errcode > 0){ // parent::sendOutput($res->errmsg, 1); // } // $res = $res->result; // parent::sendOutput($res); } /** * 删除班次 * @return void */ public function shift_delete() { $id = $this->request->param('id'); $url = 'https://oapi.dingtalk.com/topapi/attendance/shift/delete?access_token='.$this->voucher(); $param['op_user_id'] = ''; $param['shift_id'] = $id; $param = json_encode($param); $res = $this->post_json($url, $param); $res = json_decode($res); if ($res->errcode > 0){ parent::sendOutput($res->errmsg, 1); } $this->MTem->delete(['shop_id' => $this->shopId, 'shift_id' => $id]); parent::sendOutput('删除成功'); } /** * 创建考勤组 * @return void */ public function add_group() { $param = $this->request->getRawJson(); // $user = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId])->getData(); // if (!$user) parent::sendOutput('不是该店铺店员', 1005); $url = 'https://oapi.dingtalk.com/topapi/attendance/group/add?access_token='.$this->voucher(); $data = [ 'op_user_id' => '', 'top_group' => [ 'owner' => '', 'type' => 'TURN', 'enable_face_check' => 'true', 'name' => $param['name'], 'enable_next_day' => 'true', 'enable_position_ble' => 'true', ], ]; foreach (explode(',', $param['shift_vo_list']) as $item){ $data['top_group']['shift_vo_list'][] =[ 'id' => $item ]; } $staff_id_ar = empty($param['staff_id']) ? [] : explode(',',$param['staff_id']); foreach ($staff_id_ar as $item){ $user = $this->staff->getStaffInfo(['id' => $item])->getData(); $data['top_group']['members'][] =[ 'role' => 'Attendance', 'type' => 'StaffMember', 'user_id' => $user['userId'] ]; } $data = json_encode($data); $res = $this->post_json($url, $data); $res = json_decode($res); if ($res->errcode > 0){ if ($res->errcode == 850015){ parent::sendOutput('考勤组名称已存在', 1005); }else{ parent::sendOutput($res->errmsg, 1005); } } $insert = [ 'name' => $param['name'], 'shop_id' => $this->shopId, 'staff_id' => $param['staff_id'], 'shift_vo_list' => $param['shift_vo_list'], 'group_id' => $res->result->id ]; $this->MGroup->insert($insert); parent::sendOutput('添加成功'); } /** * 考勤组列表 * @return void */ public function group_list() { // $url = 'https://oapi.dingtalk.com/topapi/attendance/group/minimalism/list?access_token='.$this->voucher(); // $param['cursor'] = $this->request->param('cursor'); // // $param['op_user_id'] = ''; // $param = json_encode($param); // $res = $this->post_json($url, $param); // // $res = json_decode($res); // // if ($res->errcode > 0){ // parent::sendOutput($res->errmsg, 1); // } // if (isset($res->result->result)){ // $res = $res->result->result; // }else{ // $res = []; // } // parent::sendOutput($res); $params = $this->request->getRawJson(); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; // $param['cursor'] = $this->request->param('cursor'); // $url = 'https://oapi.dingtalk.com/topapi/attendance/shift/list?access_token='.$this->voucher(); // $user = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId, 'shopId' => $this->shopId])->getData(); // $param['op_user_id'] = ''; // $param = json_encode($param); // $res = $this->post_json($url, $param); // $res = json_decode($res); $selectParams['shop_id'] = $this->shopId; $result = $this->MGroup->list($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; foreach ($returnData['data'] as &$item){ $item['group_user'] = $this->staff->getAllStaffDatas([['id', 'in', $item['staff_id']],['shopId', '=',$this->shopId]])->getData(); $item['shift'] = $this->MTem->list([['shift_id', 'in' ,$item['shift_vo_list']], 'limit' => 0, 'offset' => 100])->getData()['data']; } parent::sendOutput($returnData['data'], 0,$pageData); } else { parent::sendOutput($result->getData(), ErrorCode::$dberror); } } /** * 考勤组详情 * @return void */ public function group_details() { $id = $this->request->param('id'); $url = 'https://oapi.dingtalk.com/topapi/attendance/group/query?access_token='.$this->voucher(); $param['op_user_id'] = ''; $param['group_id'] = $id; $param = json_encode($param); $res = $this->post_json($url, $param); $res = json_decode($res); if ($res->errcode > 0){ parent::sendOutput($res->errmsg, 1); } $res = $res->result; foreach ($res->shift_ids as $key => $item) { $url1 = 'https://oapi.dingtalk.com/topapi/attendance/shift/query?access_token='.$this->voucher(); $param1['op_user_id'] = ''; $param1['shift_id'] = $item; $res1 = $this->post_json($url1, json_encode($param1)); $res1 = json_decode($res1); $res->shift_ids[$key] = ['name' => $res1->result->name, 'id' => $res1->result->id]; } $group = $this->MGroup->list(['group_id' => $res->id, 'limit' => 0,'offset' => 10])->getData(); foreach ($group['data'] as &$item){ $res->group_user = $this->staff->getAllStaffDatas([['id', 'in', $item['staff_id']],['shopId', '=',$this->shopId]])->getData(); } parent::sendOutput($res); } /** * 考勤组成员 * @return void */ public function group_user() { $id = $this->request->param('id'); $size = $this->request->param('size'); $cursor = $this->request->param('cursor'); $url = 'https://oapi.dingtalk.com/topapi/attendance/group/member/list?access_token='.$this->voucher(); $param['cursor'] = $cursor; $param['size'] = $size; $param['op_user_id'] = ''; $param['group_id'] = $id; $param = json_encode($param); $res = $this->post_json($url, $param); $res = json_decode($res); if ($res->errcode > 0){ parent::sendOutput($res->errmsg, 1); } $res = $res->result->result; $data = []; foreach ($res as $item){ $user = $this->staff->getStaffInfo(['userId' => $item->member_id, 'shopId' => $this->shopId])->getData(); if ($user){ $data[] = $user; } } parent::sendOutput($data); } /** * 删除考勤组 * @return void */ public function group_delete() { $id = $this->request->param('id'); $url = 'https://oapi.dingtalk.com/topapi/attendance/group/delete?access_token='.$this->voucher(); $group_key = $this->post_json('https://oapi.dingtalk.com/topapi/attendance/groups/idtokey?access_token='.$this->voucher(),json_encode(['group_id' => $id])); $group_key = json_decode($group_key); if ($group_key->errcode > 0){ parent::sendOutput($group_key->errmsg, 1); } $param['op_user_id'] = ''; $param['group_key'] = $group_key->result; $param = json_encode($param); $res = $this->post_json($url, $param); $res = json_decode($res); if ($res->errcode > 0){ parent::sendOutput($res->errmsg, 1); } $DGroupRecord = new DShopGroupRecord('default'); $DGroupRecord->delete(['group_id' => $id]); $this->MGroup->delete(['group_id' => $id]); parent::sendOutput('删除成功'); } /** * 排班 * @return void */ public function rostering() { $param = $this->request->getRawJson(); $dbstaff = new DStaff('default'); $dbstaff->setTable('qianniao_staff_'.$this->onlineEnterpriseId); $user = $dbstaff->get(['userCenterId' => $this->onlineUserId]); if (empty($user)) parent::sendOutput('排班只能员工排盘,总帐号无法排班', 1005); // $user = $user->getData(); if (empty($user['userId'])) parent::sendOutput('该账号未绑定钉钉无法排班', 1005); $url = 'https://oapi.dingtalk.com/topapi/attendance/group/schedule/async?access_token='.$this->voucher(); $data = [ 'op_user_id' => $user['userId'], 'group_id' => $param['group_id'], ]; $DGroupRecord = new DShopGroupRecord('default'); $recordData = []; foreach ($param['rostering'] as $item) { $staff = $this->staff->getStaffInfo(['id' => $item['userId'], 'shopId' => $this->shopId])->getData(); $data['schedules'][] = [ 'shift_id' => $item['shift_id'], 'work_date' => $this->get_data_format($item['work_date']), 'is_rest' => $item['is_rest'], 'userid' => $staff['userId'] ]; $record = $DGroupRecord->get(['group_id' => $param['group_id'], 'time' => strtotime($item['work_date'])]); if (empty($record)){ $recordData = [ 'shop_id' => $this->shopId, 'group_id' => $param['group_id'], 'time' => strtotime($item['work_date']) ]; $DGroupRecord->insert($recordData); } if ($item['shift_id'] > 1){ $time = $this->post_json('https://oapi.dingtalk.com/topapi/attendance/shift/query?access_token='.$this->voucher(), json_encode(['shift_id' => $item['shift_id']])); $time = json_decode($time)->result->sections; $time_slot = []; foreach ($time as $vo) { $time_slot[] = [explode(' ', $vo->punches[0]->check_time)[1], explode(' ', $vo->punches[1]->check_time)[1]]; } $roData[] = [ 'name' => $item['name'], 'shop_id' => $this->shopId, 'template_id' => $item['shift_id'], 'uid' => $staff['id'], 'time' => $item['work_date'], 'time_slot' => json_encode($time_slot) ]; }else{ $roData[] = [ 'name' => $item['name'], 'shop_id' => $this->shopId, 'template_id' => $item['shift_id'], 'uid' => $staff['id'], 'time' => $item['work_date'], 'time_slot' => '' ]; } } $data = json_encode($data); $res = $this->post_json($url, $data); $res = json_decode($res); if ($res->errcode > 0){ parent::sendOutput($res->errmsg, 1); } foreach ($roData as $item) { $res = $this->Mrostering->insert($item); } parent::sendOutput('添加成功'); } /** * 删除考勤组用户 * @return void */ public function remove() { $param = $this->request->getRawJson(); // $user = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId, 'shopId' => $this->shopId])->getData(); // if (!$user) parent::sendOutput('不是该店铺店员', 1); if (!$param['id']) parent::sendOutput('传入考情组id'); if (!$param['staff_id']) parent::sendOutput('请选择删除用户'); $url = 'https://oapi.dingtalk.com/topapi/attendance/group/users/remove?access_token='.$this->voucher(); $uids = []; foreach (explode(',', $param['staff_id']) as $item){ $staff = $this->staff->getStaffInfo(['id' => $item, 'shopId' => $this->shopId])->getData(); if(!empty($staff['userId'])){ $uids[] = $staff['userId']; } } if(empty($uids)){ parent::sendOutput("员工未绑定钉钉账号", 1); } $data = [ 'group_key' => $this->group_key($param['id']), 'user_id_list' => implode(',', $uids), ]; $data = json_encode($data); $res = $this->post_json($url, $data); $res = json_decode($res); if ($res->errcode > 0){ parent::sendOutput($res->errmsg, 1); } $group = $this->MGroup->details(['group_id' => $param['id']])->getData(); if (empty($group)) parent::sendOutput('考勤组不存在', 1005); $staff_id = explode( ',', $group['staff_id']); foreach ($staff_id as $k => $v) { if ($v == $param['staff_id']){ unset($staff_id[$k]); } } $staff_id = implode(',', $staff_id); $this->MGroup->update(['staff_id' => $staff_id], $group['id']); parent::sendOutput('删除成功'); } public function user_add() { $param = $this->request->getRawJson(); if (!$param['id']) parent::sendOutput('传入考情组id'); if (!$param['staff_id']) parent::sendOutput('请选择删除用户'); $url = 'https://oapi.dingtalk.com/topapi/attendance/group/users/add?access_token='.$this->voucher(); $uids = []; foreach (explode(',', $param['staff_id']) as $item){ $staff = $this->staff->getStaffInfo(['id' => $item, 'shopId' => $this->shopId])->getData(); $uids[] = $staff['userId']; } $data = [ 'group_key' => $this->group_key($param['id']), 'user_id_list' => implode(',', $uids), ]; $data = json_encode($data); $res = $this->post_json($url, $data); $res = json_decode($res); if ($res->errcode > 0){ parent::sendOutput($res->errmsg, 1005); } $group = $this->MGroup->details(['group_id' => $param['id']])->getData(); if (empty($group)) parent::sendOutput('考勤组不存在', 1005); $staff_id = explode( ',', $group['staff_id']); foreach (explode(',', $param['staff_id']) as $v) { $staff_id[] = $v; } $staff_id = implode(',', $staff_id); $this->MGroup->update(['staff_id' => $staff_id], $group['id']); parent::sendOutput('新增成功'); } /** *排班详情 * @return void */ public function scheduling_details() { $param = $this->request->getRawJson(); // $user = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId, 'shopId' => $this->shopId])->getData(); // if (!$user) parent::sendOutput('不是该店铺店员', 1); // $staff = $this->staff->getStaffInfo(['userCenterId' => $param['uid'], 'shopId' => $this->shopId])->getData(); if (isset($param['uid'])){ $uid = $param['uid']; } $pageParams = pageToOffset($param['page'] ?: 1, $param['pageSize'] ?: 10); $limit = $pageParams['limit']; $offset = $pageParams['offset']; $month = $param['month'] ? $param['month'] : date('Y-m', time()); $where = []; if (isset($uid) and !empty($uid)){ $where[] = ['uid', '=', $uid]; } if ($month){ $where[] = ['time', 'like', '%'.$month.'%']; } if (isset($param['export']) and !empty($param['export'])){ $where['export'] = $param['export']; } $where[] = ['shop_id', '=', $this->shopId]; $rostering = $this->Mrostering->select($where,'*', 'time DESC', $limit, $offset); if ($rostering->isSuccess()) { $returnData = $rostering->getData(); $pageData = [ 'pageIndex' => $offset, 'pageSize' => $limit, 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } else { parent::sendOutput($rostering->getData(), ErrorCode::$dberror); } } public function obtain_clock() { $data = $this->request->getRawJson(); if ($data['time']){ $today = $data['time']; }else{ $today = date('Y-m-d', strtotime('today')); } $url = 'https://oapi.dingtalk.com/attendance/listRecord?access_token='.$this->voucher(); $rostering = $this->Mrostering->details([['time', 'like', '%'.$today.'%'], ['uid', '=' , $data['uid']]]); if (!$rostering->isSuccess()){ parent::sendOutput('今天未有班次', ErrorCode::$dberror); } $rostering = $rostering->getData(); $staff = $this->staff->getStaffInfo(['id' => $data['uid'], 'shopId' => $this->shopId])->getData(); $data['userIds'] = [$staff['userId']]; $data['checkDateFrom'] = date('Y-m-d H:i:s', strtotime($today)); $data['checkDateTo'] = date('Y-m-d H:i:s', strtotime($today) + 86400); $res = $this->post_json($url, json_encode($data)); $res = json_decode($res); $recordresult = $res->recordresult; $time_slot = json_decode($rostering['time_slot']); $clock = $rostering['clock']? json_decode( $rostering['clock']) : []; $num = 0; foreach ($time_slot as $item) { foreach ($item as $vo) { $times = strtotime($today.' '.$vo) * 1000; $count = count($recordresult); $time = []; for ($i=0;$i < $count; $i++){ if (!isset($recordresult[$i]->invalidRecordType)){ if ($times == $recordresult[$i]->baseCheckTime){ $time = $recordresult[$i]; } } } if ($time){ if (isset($clock[$num])){ if ($clock[$num]->timeResult == 'NotSigned'){ $clock[$num]->userCheckTime = date('Y-m-d H:i:s', $time->userCheckTime/1000); $clock[$num]->timeResult = $time->timeResult; } }else{ $clock[] = json_decode(json_encode(['baseCheckTime' => date('Y-m-d H:i:s', strtotime($today.' '.$vo)),'userCheckTime' => date('Y-m-d H:i:s', $time->userCheckTime/1000), 'timeResult' => $time->timeResult])); } }else{ if (strtotime($vo) < time() and !isset($clock[$num])){ $clock[] = json_decode(json_encode(['baseCheckTime' => date('Y-m-d H:i:s', strtotime($today.' '.$vo)), 'userCheckTime' => '','timeResult' => 'NotSigned'])); } } $num++; } } $status = 0; $price = 0;//打卡金额 if ($num == count($clock)){ foreach ($clock as $item){ if ($rostering['status'] == 0){ if ($item->timeResult == 'Normal'){ $tem_price = $this->MTem->details(['shop_id' => $this->shopId, 'shift_id' => $rostering['template_id']])->getData(); $price += $tem_price['single_time']; } } if ($item->timeResult != 'Normal') $status = -1;// 不正常今天的打卡未完成 } if ($status == 0) $status = 1;// 如果都打卡正常那么打完完成 } if (strtotime($today) < time()){ if (empty($clock)) $status = -1; } if ($price > 0 and $staff['is_clock'] == 1){ $balance = $staff['reward'] + $price; $rewardTotal = $staff['rewardTotal'] + $price; $this->staff->clockReward($price, $balance, $staff['userCenterId'], $staff['id'], $this->shopId, $rewardTotal); } if (empty($clock)){ $res = $this->Mrostering->update(['status' => $status], $rostering['id']); }else{ $res = $this->Mrostering->update(['status' => $status, 'clock' => json_encode($clock)], $rostering['id']); } parent::sendOutput('更新成功'); } public function get_data_format($time) { list($usec) = explode(".", $time); $date = strtotime($usec); $return_data = str_pad($date,13,"0",STR_PAD_RIGHT); //不足13位。右边补0 return $return_data; } /** * 排班记录 * @return void */ public function group_record() { $param = $this->request->getRawJson(); $DGroupRecord = new DShopGroupRecord('default'); $pageParams = pageToOffset($param['page'] ?: 1, $param['pageSize'] ?: 10); $limit = $pageParams['limit']; $offset = $pageParams['offset']; // $monthFirstDay = strtotime(date( 'Y-m-1 00:00:00', strtotime($param['time']))); // $mdays = date( 't', strtotime($param['time']) ); // $monthLastDay = strtotime(date( 'Y-m-' . $mdays . ' 23:59:59', strtotime($param['time']) )); // // $where[] = ['time', '>=', $monthFirstDay]; // $where[] = ['time', '<=', $monthLastDay]; // $where[] = ['a.group_id', '=', $param['group_id']]; $where = []; $where[] = ['a.shop_id', '=', $this->shopId]; if ($param['name']) $where[] = ['b.name', '=', $param['name']]; $join = 'Left Join qianniao_shop_group as b ON a.group_id = b.group_id'; $list = $DGroupRecord->select($where, 'a.*,b.name,b.staff_id,b.shift_vo_list', null, $limit, $offset, [], true, false, $join); $count = $DGroupRecord->count($where, [], $join); foreach ($list as &$item){ $item['time'] = date('Y-m-d', $item['time']); $item['group_user'] = $this->staff->getAllStaffDatas([['id', 'in', $item['staff_id']],['shopId', '=',$this->shopId]])->getData(); $item['shift'] = $this->MTem->list([['shift_id', 'in', $item['shift_vo_list']], 'limit' => 0, 'offset' => 100])->getData()['data']; } $pageData = [ 'pageIndex' => $param['page'], 'pageSize' => $param['pageSize'], 'pageTotal' => $count, ]; parent::sendOutput($list, 0, $pageData); } }