197 lines
8.2 KiB
PHP
197 lines
8.2 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
use think\Config;
|
|
use fast\Random;
|
|
/**
|
|
* 首页接口
|
|
*/
|
|
class Gonghao extends Api
|
|
{
|
|
protected $noNeedLogin = ['init','appver'];
|
|
protected $noNeedRight = ['me','bind','create','clockin','clockin_me','pushlogin'];
|
|
|
|
public function me(){
|
|
$type = $this->auth->worker_type;
|
|
if($type==1){
|
|
$wmsuserModel = new \app\common\model\wms\User;
|
|
$wmsuser = $wmsuserModel->where(['userID'=>$this->auth->wms_userid])->find();
|
|
}
|
|
$name = $this->auth->real_name;
|
|
$phone = $this->auth->mobile;
|
|
$code = $this->auth->tmp_code;
|
|
$zhongjie = $this->auth->zhongjie;
|
|
$this->success('获取成功',['type'=>$type,'code'=>$code,'name'=>$name,'zhongjie'=>$zhongjie,'tel'=>$phone]);
|
|
}
|
|
public function bind(){
|
|
$params=$this->request->post();
|
|
$username = $params['username'];
|
|
$password = $params['password'];
|
|
$wmsuserModel = new \app\common\model\wms\User;
|
|
$wmsuser = $wmsuserModel->where(['username'=>$username])->find();
|
|
$userID = false;
|
|
if(!$wmsuser){
|
|
$this->error('工号不存在');
|
|
}
|
|
if($wmsuser['passwordHash']!=md5($password)){
|
|
$this->error('工号已失效');
|
|
}
|
|
$userModel = new \app\common\model\User;
|
|
$userinfo = $userModel->where(["wms_userid"=>$wmsuser['userID']])->find();
|
|
if($userinfo && $userinfo['id']!=$this->auth->id){
|
|
$this->error('工号已被其他用户绑定');
|
|
}
|
|
$user = $this->auth->getUser();
|
|
$user->worker_type = 1;
|
|
$user->real_name = $wmsuser['name'];
|
|
$user->wms_userid = $wmsuser['userID'];
|
|
$uuid = Random::uuid();
|
|
$user->tmp_code = base64_encode(json_encode(["uuid"=>$uuid]));
|
|
$user->save();
|
|
$this->success('绑定成功');
|
|
}
|
|
public function create(){
|
|
$params=$this->request->post();
|
|
$name = $params['name'];
|
|
$zhongjie = $params['zhongjie'];
|
|
$tel = $params['tel'];
|
|
$user = $this->auth->getUser();
|
|
$user->worker_type = 2;
|
|
$user->real_name = $name;
|
|
$user->mobile = $tel;
|
|
$user->zhongjie = $zhongjie;
|
|
$uuid = Random::uuid();
|
|
$user->tmp_code = base64_encode(json_encode(["uuid"=>$uuid]));
|
|
$user->save();
|
|
$this->success('绑定成功');
|
|
}
|
|
public function token(){
|
|
$params=$this->request->post();
|
|
$WAREHOUSEID = $this->auth->warehouseid;
|
|
$type= $params['type'];
|
|
//print_r(date('Y-m-d ').$params['settime'].':00');
|
|
//print_r($settime);
|
|
$WarehouseModel = new \app\common\model\Warehouse;
|
|
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
|
$workDate = $WAREHOUSE['workDate'];
|
|
$settime= strtotime(date('Y-m-d ',$workDate).$params['settime'].':00');
|
|
$Token = new \app\common\model\workers\clock\in\Token;
|
|
$Token2 = new \app\common\model\workers\clock\in\Token;
|
|
$time = time();
|
|
$token = Random::uuid();
|
|
$data = ["token"=>$token,"type"=>$type,"createtime"=>$time,"expiretime"=>$time+10,"WAREHOUSEID"=>$WAREHOUSEID,"settime"=>$settime];
|
|
$code = $Token->save($data);
|
|
$dellist = $Token2->where("expiretime<".($time))->select();
|
|
foreach($dellist as $item){
|
|
$item->delete();
|
|
}
|
|
$this->success('获取成功',"https://ye4s.wms.gztbyc.com/mini/?spm=0.2.{$token}.1.4");
|
|
}
|
|
public function get_list(){
|
|
$params=$this->request->post();
|
|
$type= $params['type'];
|
|
$clockinModel = new \app\common\model\workers\clock\In;
|
|
$WarehouseModel = new \app\common\model\Warehouse;
|
|
$WAREHOUSEID = $this->auth->warehouseid;
|
|
if($type==1){
|
|
|
|
}else{
|
|
$clockinModel->where('endtime is null');
|
|
}
|
|
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
|
$workDate = $WAREHOUSE['workDate'];
|
|
$list = $clockinModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"workDate"=>$workDate])->with(['name'])->order('endtime,createtime','desc')->select();
|
|
$this->success('获取成功',$list);
|
|
}
|
|
public function clockin(){
|
|
$params=$this->request->post();
|
|
$token= $params['token'];
|
|
$WAREHOUSEID = $this->auth->warehouseid;
|
|
$userid = $this->auth->id;
|
|
$zhongjie = $this->auth->zhongjie;
|
|
$wages = $this->auth->wages;
|
|
$clockinModel = new \app\common\model\workers\clock\In;
|
|
$WarehouseModel = new \app\common\model\Warehouse;
|
|
$Token = new \app\common\model\workers\clock\in\Token;
|
|
$WAREHOUSE = $WarehouseModel->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
|
$workDate = $WAREHOUSE['workDate'];
|
|
$time = time();
|
|
$tokens = $Token->where("expiretime>".($time))->where(["token"=>$token])->where(["WAREHOUSEID"=>$WAREHOUSEID])->find();
|
|
if($tokens){
|
|
switch ($tokens->type) {
|
|
case 1:
|
|
$clockin = $clockinModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"workDate"=>$workDate,"userid"=>$userid])->find();
|
|
if($clockin){
|
|
$this->error('签到失败,上班已签到成功');
|
|
}else{
|
|
$clockinModel->save(["workDate"=>$workDate,"userid"=>$userid,"createtime"=>time(),"stime"=>$tokens['settime'],"zhongjie"=>$zhongjie,"WAREHOUSEID"=>$WAREHOUSEID,"wages"=>$wages]);
|
|
$this->success('签到成功,上班签到成功');
|
|
}
|
|
break;
|
|
case 2:
|
|
$clockin = $clockinModel->where(["WAREHOUSEID"=>$WAREHOUSEID,"workDate"=>$workDate,"userid"=>$userid])->find();
|
|
if($clockin){
|
|
if($clockin->endtime){
|
|
$this->error('签到失败,今日下班已签到');
|
|
}
|
|
$clockin->save(["endtime"=>time(),"xtime"=>$tokens['settime']>$clockin['stime']?$tokens['settime']:$tokens['settime']+86400]);
|
|
$this->error('签到成功,下班签到成功');
|
|
}else{
|
|
$this->error('签到失败,今日没有签到上班');
|
|
}
|
|
// code...
|
|
break;
|
|
}
|
|
}else{
|
|
$this->error('未开启签到码或已失效');
|
|
}
|
|
}
|
|
public function clockin_me(){
|
|
$params=$this->request->post();
|
|
$start = $params['start'];
|
|
$end = $params['end'];
|
|
$userid = $this->auth->id;
|
|
$clockinModel = new \app\common\model\workers\clock\In;
|
|
$list = $clockinModel->where(["userid"=>$userid])->where('workDate','BETWEEN',[strtotime($start),strtotime($end) + 86399])->select();
|
|
foreach ($list as $r){
|
|
$rest = 0;
|
|
$restTime1 = strtotime(date('Y-m-d', $r['stime'])) + 43200;
|
|
$restTime2 = strtotime(date('Y-m-d', $r['stime'])) + 64800;
|
|
if($r['xtime']>$restTime1+3600 && $r['stime']<$restTime1){
|
|
$rest++;
|
|
}
|
|
if($r['xtime']>$restTime2+3600 && $r['stime']<$restTime2){
|
|
$rest++;
|
|
}
|
|
$r['rest'] = $rest;
|
|
if($r['xtime']){
|
|
$r['workingHours'] = number_format((($r['xtime'] - $r['stime'])/3600-$r['rest']),2);
|
|
$r['endtimestr'] = date('H:i', $r['xtime']);
|
|
}else{
|
|
$r['workingHours'] = '-';
|
|
}
|
|
$r['print'] = 0.00;
|
|
if($r['wages'] && $r['workingHours']!='-'){
|
|
$r['print'] = number_format((float)$r['workingHours']*(float)$r['wages'],2);
|
|
}
|
|
$r['createtimestr'] = date('H:i', $r['stime']);
|
|
}
|
|
$this->success('获取成功',$list);
|
|
}
|
|
public function pushlogin(){
|
|
$params=$this->request->post();
|
|
$uuid = $this->auth->tmp_code;
|
|
$token = $params['token'];
|
|
$loginModel = new \app\common\model\Logins;
|
|
$logins = $loginModel->where(["token"=>$token])->find();
|
|
if($logins){
|
|
$logins->save(["uuid"=>$uuid]);
|
|
$this->success('登录成功');
|
|
}else{
|
|
$this->error('登录失败');
|
|
}
|
|
}
|
|
}
|