| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000 |
- <?php
- /**
- * 商铺管理模块
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/10/31
- * Time: 15:02
- */
- namespace JinDouYun\Controller\Shop;
- use AlibabaCloud\Credentials\Providers\ChainProvider;
- use AlibabaCloud\SDK\Dingtalk\Vworkflow_1_0\Models\GetProcessConfigResponseBody\result\handSignConf;
- use AlibabaCloud\SDK\Dingtalk\Vworkflow_1_0\Models\QuerySchemaByProcessCodeResponseBody\result\schemaContent\items\props\push;
- use JinDouYun\Controller\DingController;
- use JinDouYun\Dao\Department\DStaff;
- use JinDouYun\Dao\Shop\DShopGroup;
- use JinDouYun\Dao\Shop\DShopGroupRecord;
- use JinDouYun\Dao\Shop\DShopRostering;
- use JinDouYun\Model\Department\MStaff;
- use JinDouYun\Model\Enterprise\MEnterprise;
- use JinDouYun\Model\Shop\MShopGroup;
- use JinDouYun\Model\Shop\MShopProject;
- use JinDouYun\Model\Shop\MShopRostering;
- use JinDouYun\Model\Shop\MShopTemplate;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Cache\ShopCache;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Shop\MShop;
- use JinDouYun\Cache\TempSaveCache;
- class ShopRostering extends BaseController
- {
- private $obj;
- private $objShopCache;
- private $objTempSaveCache;
- private $Mrostering;
- private $MTem;
- private $MStaffRewardDesc;
- private $MGroup;
- private $staff;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->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();
-
- if(empty($param) || empty($param["shift_vo_list"])){
- parent::sendOutput('参数错误', 1005);
- }
- $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
- ];
- }
- var_dump(explode(',',trim($param['staff_id'])));
- exit;
- foreach (explode(',',$param['staff_id']) 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);
- }
- }
|