123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997 |
- <?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();
-
- $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);
- }
- }
|